Duration Template

This tutorial is targeting Add On version 5.1.3.

Requirements:

You have completed the 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 specified in the gadget configuration screen).

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())

 

 

$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

Like

#foreach($user in $item.getItems())
	$user.getName()
#end

 

 

Get time spent for a user

$item.getTimeSpent($user)

 

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.getItemUser())
<table>
 #foreach ($user in $item.getItems())
 <tr><td>$textutils.htmlEncode($user.getDisplayName())</td>
 <td>$tools.getTimePretty($item.getTimeSpent($user))</td>
 </tr>
 #end
 <tr>
 <td >$i18n.getText("common.words.total"):</td>
 <td >$tools.getTimePretty($itemHolder.getItemWorklog().getTimeSpent())</td>
 </tr>
</table>