I'm investigating to find out if it is possible to create a date counter for Confluence for when a page has been created and modified (see example below). We are on a tight budget so we can't fork out money to pay for such feature. I was wondering if it possible to achieve this with User Macro?
PageCounter.jpg
Obviously the Archiving Plugin would be more robust, but here's a user macro that would fulfill your requirements:
## @param LimitDays:title=# of days until outdated|required=true|type=int|default=30|desc=This is the number of days until the info box will show as a warning box #set ( $limitDays = 30) #set ( $daysSinceCreated = ($action.dateFormatter.calendar.timeInMillis - $content.creationDate.time ) / (1000*60*60*24) ) #set ( $daysSinceLastModified = ($action.dateFormatter.calendar.timeInMillis - $content.lastModificationDate.time ) / (1000*60*60*24) ) #set ( $limitDays = $generalUtil.convertToInteger($paramLimitDays).intValue() ) #if ( $generalUtil.isInLastDays($content.lastModificationDate, $limitDays) ) #set ( $macroType = "info" ) #else #set ( $macroType = "warning") #end #if ( $daysSinceCreated >= 21 ) #set ( $sinceCreatedString = ($daysSinceCreated / 7) + " weeks" ) #else #set ( $sinceCreatedString = $daysSinceCreated + " days" ) #end #if ( $daysSinceLastModified >= 21 ) #set ( $sinceLastModifiedString = ($daysSinceLastModified / 7) + " weeks" ) #else #set ( $sinceLastModifiedString = $daysSinceLastModified + " days" ) #end <ac:structured-macro ac:name="$macroType"> <ac:rich-text-body> <p> <span>This page was created </span><b>$sinceCreatedString</b><span> ago. </span> </p> <p> <span>This page hasn&#39;t been updated for </span><b>$sinceLastModifiedString</b><span>. </span> </p> </ac:rich-text-body> </ac:structured-macro>
Seems possible. What should the limit be for when a # of days is displayed as # of weeks? Above it shows 9 days ago, which is more than 1 week. Would the cutoff be at 2 weeks or something?
I would say give it 21 days which is 3 weeks. Thanks for your time helping me with this
I have been trying to find a solution for a while now but everything I try doesn't seem to work.
I don't know about your budget, but the Archiving Plugin has this feature.
46dfb7cd-76f7-4117-b269-2f23361fc426.png
Right now the default # of days is 30, but you can change that in lines 1 and 2 if you wish (you need to change both to the same value).
This is absolutely spot on. I am really grateful of the time you have spent putting this together for me. I still have such a long way to go before I master velocity. Where did you learn all this from?
Thanks for the suggestion. I did demo this a while ago and it seems really good. I would definatly look at this in the future.
Basically a ton of trial and error and looking at the work that others have done, specifically the other prolific user macro writers:
Andrew FraylingMatthew HornSteve GoldbergDavin StuderSandro Herrmann(apologies if I missed someone)
Beyond this, take a look at these pages:
https://confluence.atlassian.com/doc/user-macro-template-syntax-223906130.html
https://developer.atlassian.com/confdev/development-resources/confluence-architecture/confluence-internals/velocity-template-overview/confluence-objects-accessible-from-velocity
Take a look at the Javadoc for the objects accessible in Velocity (and some that aren't, since it's possible to import some extra classes), including Page/ContentEntityObject.
Also, it's good to look at the documentation for version 1.6 of Velocity (the one that's included in most versions of Confluence):
http://velocity.apache.org/engine/1.6/user-guide.html
For some extra ideas, I have a bunch of user macros in my Bitbucket repository:
https://bitbucket.org/stephendeutsch/confluence-user-macros
They're getting a bit old, but you should be able to get at least a few ideas
Hi,
i try to create a table macro in which two current report values can be displayed together."Metadata report" and "View of contributors" - see attachmend.
Unfortunately, I do not succeed. I also have to admit that my programming experience is not very good.
The table should have 4 columns.Page, process owner (metadata "prozessver"), date of last modify, counter "Last change before 30 days".
Can someone help me or give a tip on this?
I have tried this code, without success : (
## @param daysSinceLastModified:title=# of days until outdated|required=true|type=int|default=30|desc=This is the number of days until the page was modified#set ( $daysSinceLastModified = ($action.dateFormatter.calendar.timeInMillis - $content.lastModificationDate.time ) / (1000*60*60*24) )#set ( $descendantPages = $pageManager.getDescendents($content) )#set( $prozessverantwortlicher = $metadataService.getMetadataValue(prozessver ) $!value<table> <tr> <th>Page</th> <th>Geändert von</th> <th>Änderungsdatum</th> <th>Geändert seit < 7d?</th> </tr> #foreach ( $page in $descendantPages ) <tr> <td><a href="${req.contextPath}$page.urlPath"> $page.title </a></td> <td> $prozessverantwortlicher </td> <td> $action.dateFormatter.format($page.lastModificationDate) </td> <td> $daysSinceLastModified </td> </tr> #end</table>
It looks like you're new here. Sign in or register to get started.