## Copy/Paste this code block in the Template Text area
## Macro Name: pivot-values-rendering
## Visibility: Visible only to system administrators in the Macro Browser
## Macro Title: Pivot Values Rendering
## Macro Body Processing: No macro body
##
## Developed by: xavier.arques@seuqra.com
## Date created: 08/05/2016
## Installed by:
## @param typeOfRendering:title=Rendering Type|type=enum|enumValues=tick,star,list,min,max|required=true|desc=The rendering types this macro supports
## Retrieve the List<String> for the cell to render
#set ($bodyTableValues = $conversionContext.getProperty("bodyTableValues"))
## list macro
## Return the $bodyTableValues values separated by a comma
#macro (list)
#set ($listValue = "")
#foreach ($value in $bodyTableValues)
#if ($listValue.length() > 0)
#set ($listValue = $listValue +", " + $value)
#else
#set ($listValue = $value)
#end
#end
$listValue
#end
## min macro
## Return the min value of the $bodyTableValues list
#macro (min)
#set ($minValue = $textUtil.parseFloat($bodyTableValues.get(0)))
#foreach ($value in $bodyTableValues)
#if ($textUtil.parseFloat($value) < $minValue)
#set ($minValue = $value)
#end
#end
$minValue
#end
## max macro
## Return the max value of the $bodyTableValues list
#macro (max)
#set ($maxValue = $textUtil.parseFloat($bodyTableValues.get(0)))
#foreach ($value in $bodyTableValues)
#if ($textUtil.parseFloat($value) > $maxValue)
#set ($maxValue = $value)
#end
#end
$maxValue
#end
## emoticon macro
## Display the emoticon given as parameter
#macro (emoticon $icon)
<ac:emoticon ac:name="$icon"/>
#end
#macro (stars)
#if ($bodyTableValues.size() == 1)
#emoticon("yellow-star")
#end
#if ($bodyTableValues.size() > 1)
#emoticon("yellow-star")
#end
#if ($bodyTableValues.size() > 2)
#emoticon("yellow-star")
#end
#if ($bodyTableValues.size() > 3)
#emoticon("yellow-star")
#end
#if ($bodyTableValues.size() > 4)
#emoticon("yellow-star")
#end
#end
## You can now define your own internal macro rendering and declare them below by adding the #elseif clause
## Here is the code executed when this macro is used
#if ($bodyTableValues.size() > 0)
#if ($paramtypeOfRendering.equals("tick"))
## No calculation: Display a green tick if there is at least one value on the cell
#emoticon("tick")
#elseif ($paramtypeOfRendering.equals("star"))
## No calculation: Display one too five 5 depending on the number of values
#stars()
#elseif ($paramtypeOfRendering.equals("list"))
## No calculation: Display all the body table values on the cell
#list()
#elseif ($paramtypeOfRendering.equals("min"))
## Display the smallest value of the list
#min()
#elseif ($paramtypeOfRendering.equals("max"))
## Display the largest value of the list
#max()
#end
#end |