Page tree
Skip to end of metadata
Go to start of metadata

The gadget looks like:

This is a kind of a more complex sample so here is short explanation of the code:

  • util.js - util methods.

  • eventsProvider.js - code responsible for fetching worklog data from JIRA. It relies on /rest/api/2/issue/{issueIdOrKey}/worklog and /rest/api/2/search JIRA REST methods.
    EventsProvider.getEvents(dataParams, callBackFunction) method is an entry point. dataParams is object with input parameters and has following format: 
      dataParams.end - end date exclusively. Please be aware of time part and null it if you want to retrieve worklogs till specific date. To retrieve worklogs including current date, you need to set dataParams.end to midnight of tomorrow. You can have a code like this:

    dataParams.end = new Date((new Date()).getTime() + (24 * 60 * 60 * 1000));
    dataParams.end.setHours(0, 0, 0, 0);

      dataParams.start - start date inclusively. You can use following code to set it 2 weeks back from the end date:

    dataParams.start = new Date(dataParams.end.getTime() - (14 * 24 * 60 * 60 * 1000));

      dataParams.jql - jql to filter issues. You can omit it to pick all issues. It's better to test it in JIRA issues search before putting here. Sample:

    dataParams.jql = "status = \"In Progress\"";

      dataParams.allUsers - Pass true value to get worklogs of all users. Overrides dataParams.usernames.

      dataParams.usernames - Array with usernames. You can call API.getCurrentUser().username to get username of the currently logged user:

    dataParams.usernames = [API.getCurrentUser().username];

      callBackFunction function is called with parameter that is an array of objects that represent worklog entries. Each object has format:

    {
      "self": "http://www.example.com/jira/rest/api/2/issue/10010/worklog/10000",
      "author": {
        "self": "http://www.example.com/jira/rest/api/2/user?username=fred",
        "name": "fred",
        "displayName": "Fred F. User",
        "active": true
      },
      "updateAuthor": {
        "self": "http://www.example.com/jira/rest/api/2/user?username=fred",
        "name": "fred",
        "displayName": "Fred F. User",
        "active": true
      },
      "comment": "I did some work here.",
      "visibility": {
        "type": "group",
        "value": "jira-developers"
      },
      "started": "2015-07-16T10:12:04.149+0000",
      "startedDate": Date,
      "timeSpent": "3h 20m",
      "timeSpentSeconds": 12000,
      "issueKey": "DEMO-1",
      "id": "100028"
    }
  • tableDrawer.js - draws the timesheet table based on data from eventsProvider.js The entry method is tableDrawer.drawByIssue(dataParams, eventsArr, container).
      dataParams - the same object as for eventsProvider.getEvents.
      eventsArr - the array of worklog entries.
      container - jQuery element to which timesheet table is appended.
    tableDrawer.js can be easily replaced by script that draws some charts based on worklog records.

Please note that User Timesheet gadget can be slow when many issues with many worklogs have to be fetched from JIRA.

  • No labels