Menu

Calendar Script

2017-06-20
2020-12-28
  • Ferdinand Mravenec

    Hello everybody,

    I made for myself Calendar script, which I found useful, if you use Freeplane for project managing, maybe it can somebody else helps. And also I am not very experienced programmer, espetially in Groovy/Java (I spent last few years by "holiday" programming in Python only :) ), so maybe somebody should have an idea, how to improve/rewrite them in clearer way.

    Calendar script asks for year, for which should be calendar generated, create a new node with calendar and split all days of generated calendars to structure in week order. For better overview it colors months. It could be useful for diary, or workflow tracking, or for settings reminders etc.

    I tested it for few years, seems everything works as expected.

    Installation:
    - Installation is common: Copy & paste script below, paste it in new file, called e.g. Calendar.groovy, put the file into freeplane_dir/scripts and restart Freeplane. Script will appear in Tools->Scripts.

    Features:
    - You can use your own translations to generate localized calendar. Days are named according to your localization of Freeplane automatically
    - You can pick your own favorit color to colorize calendar :)

    Known problems:
    - Few days, which can belong to previous week (last week of previous year) is not neccessary on their right spot (monday over monday grid).
    - Translations should be solved in better way: If you use translations with diacritics (ěščřžřý...), it will be broken during create calendar from "external" script - means installed script. If you put these script straight into some node of your map, everything seems well.

    Possible improvement: Split nodes also in accordance to month.

    Hope it helps :)

    Testing, reporting, improvement, some feedback, will be welcome.

    // "Universal calendar"
    // ====================
    // 
    // Generates node structure, divided by weeks of year, with one node per day.
    // It is suggested for example for create journal of work - in other words
    // to manage your day schedule.
    // 
    // If you wish to change colors of calendar, or comments, change lines above in your own.
    // 
    // Created by: (c) Ferdinand Mravenec, 2017
    //
    // If the localization dont work properly, load script into node in Freeplane. Then it 
    // will work correctly. Problems are caused only during run this script external.
    
    //Translations
    def input_year = "Input year" //en_EN
    //def input_year = "Zadej rok" //cs_CZ
    
    def valid_year = "Input is not valid (probably letter?)" // en_EN
    //def valid_year = "Chyba v zadání (možná písmeno?)" // cs_CZ
    
    def calendar_name = "Calendar" //en_EN
    //def calendar_name = "Kalendář" //cs_CZ
    
    def week_name = "Week" //en_EN
    //def week_name = "Týden" //cs_CZ
    
    // Color
    def clr = "#F0E68C" // default is khaki - "#F0E68C"
    
    // Ask user for year
    def user_input = ui.showInputDialog(node.delegate, input_year, "")
    def year
    
    try {
        year = user_input.toInteger() // if it is not year...
    } catch (Exception ex) {
        ui.informationMessage(valid_year) //... then stop
        return
    } finally {
    }
    
    //Node with calendar
    def outnode = node.map.root.createChild(calendar_name + " " + year.toString())
    
    def childnode = outnode
    def monthnode = outnode
    def first_week = true
    
    // Iterating through whole year (note, year can be irregulate)
    for (i = 0; i <= 366; i++){
        def caldate = new Date().copyWith(year: year, month: Calendar.JANUARY, dayOfMonth: 1) + i //init calendar for first day of year
    
        if (caldate.format("yyyy") == year + 1) break // Stop when year changes
    
        // Week numbering
        def week = round(i / 7) + 1 // first week is really first
        if (week > 52) week -= 52 // if it goes over week 52, normalize it
    
        // Initial conditions for rests of previous year
        // (First week of year begins with first monday in year. It means, that if 1.1. is Sunday, first week will begin at Monday 2.1.)
        if (i <= 7 && first_week)
        {
            childnode = outnode.createChild(week_name + " 52") // create node for rests of previous year
            first_week = false // do it only for once
        }
    
        // For each new monday create new week
        if (caldate[Calendar.DAY_OF_WEEK] == Calendar.MONDAY){
            childnode = outnode.createChild(week_name + " " + week.toString())
        }
    
        // Create node for each day...
        childnode = childnode.createChild(caldate.format("EEEE dd.MM."))
    
        //... and add some eye-candy
        if (caldate.format("MM").toInteger() % 2 == 0) childnode.style.backgroundColorCode = "#F0E68C"    
    
    }
    
    outnode.setFolded(true) // set it folded ...
    c.select(outnode) // ... and set focus on results node
    
     

    Last edit: Ferdinand Mravenec 2017-06-21
    • zipizap

      zipizap - 2017-06-20

      Well done Ferdinand ;)

      Consider putting it into the wiki, to the "incubator scripts page"

       
      • Ferdinand Mravenec

        Thanks :)

        I didnt post it to incubator scripts page, because I expected, that exists better way, how to solve similar issue (whenever I see yours "xxx.each{...}" stuff :) ), maybe there is some problem, what I overview and, of course, I havent access yet :) So maybe a bit later :)

         
  • Alexandre

    Alexandre - 2017-06-21

    I did one also some time ago, I still use it.
    https://github.com/viaa/FreeplaneScripts/blob/master/Calendar.groovy

     
    • Ferdinand Mravenec

      Seems heavy :)

       
      • Alexandre

        Alexandre - 2017-07-04

        Hi Ferdinand,

        It displays the calendars with the usual format as tables and by quarters and months.

        A screenshot is in attachment.

        Best regards,

        Alexandre

         

        Last edit: Alexandre 2017-07-04
  • Leo Staley

    Leo Staley - 2018-01-25

    I'd like to try out both of these calendar scripts simultaneously for comparison purposes, (and heck, I might like both and have a use case for both of them on different occasions) but they both have to be named "calendar.groovy" in my scripts folder, which is problematic.

    Do you guys have a suggested solution?

     

    Last edit: Leo Staley 2018-01-25
    • Alexandre

      Alexandre - 2018-01-26

      Seems calendars as mind maps are not very popular. But I do use mine to put some things like vacations, sick days for me and other people I work with or things to do at a specific date sometimes.

       
  • Leo Staley

    Leo Staley - 2018-01-25

    I have a bigger problem @Ferdinand Mravenec:

    I created the Calendar.groovy file in my scripts folder, I restarted freeplane, and then, in my map, I right clicked on my node, "Test Calendar," and freeplane gave me an error:

    Error executing the script:
    No such property: JANUARY for class: Calendar at line -1
    
     
  • bepolymathe

    bepolymathe - 2020-12-27

    Hi,

    I want to try this script and i have the same problem.
    Any idea ?

     
  • bepolymathe

    bepolymathe - 2020-12-28

    Hello everyone,

    Looking at the scripts you've developed I think freeplane is a very interesting tool for a diary + calendar.

    With a template system, you can imagine keeping a diary that includes meeting notes, references (readings, sites) but also events (calendar). However, I see a major obstacle: export. Would some of you have ideas on the best solutions for a possible export. An export in .ics would obviously be ideal but it would surely require standardizing attributes like for calendar events ("date", "location", "description", etc).

    Does this inspire you?

     
    • Alexandre

      Alexandre - 2020-12-28

      Can you check again the calendar script, I think I needed to
      explicitly declare some variables with def. It worked on my comp but it
      seems to give an error on yours.

      About what you suggested. I do that already I keep notes, references to
      sites (all my bookmarks), todo lists, etc.

      It is possible to export using scripts, so to select the data you need and
      create a csv file.

      Le lun. 28 déc. 2020 à 16:44, bepolymathe bepolymathe@users.sourceforge.net
      a écrit :

      Hello everyone,

      Looking at the scripts you've developed I think freeplane is a very
      interesting tool for a diary + calendar.

      With a template system, you can imagine keeping a diary that includes
      meeting notes, references (readings, sites) but also events (calendar).
      However, I see a major obstacle: export. Would some of you have ideas on
      the best solutions for a possible export. An export in .ics would obviously
      be ideal but it would surely require standardizing attributes like for
      calendar events ("date", "location", "description", etc).

      Does this inspire you?

      Calendar Script
      https://sourceforge.net/p/freeplane/discussion/758437/thread/d55a3447/?limit=25#9a04


      Sent from sourceforge.net because you indicated interest in
      https://sourceforge.net/p/freeplane/discussion/758437/

      To unsubscribe from further messages, please visit
      https://sourceforge.net/auth/subscriptions/

       
  • bepolymathe

    bepolymathe - 2020-12-28

    Look, I don't want to bother you with this. I wanted to test it with the prospect of documenting my notes in time. I'll try to solve the problem myself. I would be more seriously interested in the prospect of exporting the events... I'll see if anyone can develop that.