Period Template
This tutorial is targeting Add On version 5.1.3.
Requirements:
You have completed the Duration Template and Hello World tutorial.
You have a basic knowledge about Java, Velocity Template Language (VTL), html and the Jira java API.
For javadoc references, see http://jplugs.bitbucket.org/ttb/5.1.3/
Result
We will create a template that will display total time logged for each user with logged worklogs (or users specified in the gadget configuration screen).
Logged time will be displayed in intervals like day, week, month or year.
Tutorial
The main entry to the Add On model is the TimeTrackingItemHolder class (see http://jplugs.bitbucket.org/ttb/5.1.3/com/ja/jira/plugin/ttb/model/TimeTrackingItemHolder.html).
Use $itemHolder in a template to obtain an instance of the class.
With TimeTrackingItemHolder you can obtain TimeTrackingItemUser class.
(See http://jplugs.bitbucket.org/ttb/5.1.3/com/ja/jira/plugin/ttb/model/worklog/package-summary.html)
Like
#set( $item = $itemHolder.getItemUser())
Get the Periods/Intervals to iterate over
#set($periods = $item.getTimeSpentRollOnDateUnit($calendarConstant))
You can iterate over the period objects to add a header row.
Like
#foreach ($period in $periods) $tools.getCalendarConstantPretty($calendarConstant,$period.getStartDate()) #end
$item.getItems() returns a map of items, where the map values are the unique items - in this case ApplicationUser objects.
Use the foreach statement to iterate over the map values.
Add an inner loop that iterates over the Period objects.
Like
#foreach($user in $item.getItems()) $user.getName() #foreach ($period in $periods) $period.getSumTimeSpent($user) #end #end
Get the total time spent in this period (for all users)
$itemHolder.getItemWorklog().getTimeSpent()
Get the total time spent for a user
$tools.getTimePretty($period.getSumTimeSpent())
Get the total time spent in this duration
$itemHolder.getItemWorklog().getTimeSpent()
Putting it all together with a little mark up as well.
#set( $item = $itemHolder.getItemWorklog()) #set( $users = $itemHolder.getItemUser()) #set($periods = $item.getTimeSpentRollOnDateUnit($calendarConstant)) <table class="grid" style="width:100%"> <tr> <th>$i18n.getText("common.words.user")</th> #foreach ($period in $periods) <th>$tools.getCalendarConstantPretty($calendarConstant,$period.getStartDate())</th> #end <th>$i18n.getText("common.words.total")</th> </tr> #foreach ($user in $users.getItems()) <tr> <td>$user.getDisplayName() <small>($user.getName())</small>:</td> #foreach ($period in $periods) <td class="ttbright">$tools.getTimePretty($period.getSumTimeSpent($user))</td> #end <td class="ttbright">$tools.getTimePretty($users.getTimeSpent($user))</td> </tr> #end <tr> <td class="ttbright">$i18n.getText("common.words.total"):</td> #foreach ($period in $periods) <td class="ttbright"><b>$tools.getTimePretty($period.getSumTimeSpent())</td> #end <td class="ttbright">$tools.getTimePretty($itemHolder.getItemWorklog().getTimeSpent())</td> </tr> </table>