What I'm attempting to do is assign Space Categories to all my spaces, then generate lists on different pages to list spaces that have the corresponding category assigned.
I understand there is a Spaces List macro that will allow me to provide a View Spaces with Category dropdown where users can select the category they want to view by, but I'd like to avoid user input and instead provide a list using the category label.
I recently wrote a simple user macro that lists spaces by category:
## @param Label:title=Space Category|type=string|required=true|desc=The category you want to list spaces from. ## try to get space category #set ( $spaceLabel = $action.labelManager.getLabel( "team:${paramLabel}" ) ) ## check if space category exists #if ( $!spaceLabel ) ## try to get spaces by category #set ( $spaces = $action.labelManager.getSpacesWithLabel( $spaceLabel ) ) <ul> #foreach ( $space in $spaces ) ## check if current user can view space #if ( $permissionHelper.canView( $action.remoteUser, $space ) ) <li><a href="$!space.urlPath">$!space.name</a></li> #end #end </ul> #else <div class="aui-message warning"> <p class="title"> <span class="aui-icon icon-warning">Warning</span> <strong>Space category not found</strong> </p> <p>Couldn't find space category <strong>$paramLabel</strong>!</p> </div> #end
Hope this helps
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Awesome … I'm trying to additionally sort the list alphabetically before output. Unfortunately Velocity SortTool seems not to be available within user macros and installing the required Velocity libraries is not an option at the moment. Anyone having another way of sorting the space list?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can check if a space is archived with: {code} $space.isArchived() {code} The full version of the macro excluding archived spaces would be: {code} ## @param Label:title=Space Category|type=string|required=true|desc=The category you want to list spaces from. ## try to get space category #set ( $spaceLabel = $action.labelManager.getLabel( "team:${paramLabel}" ) ) ## check if space category exists #if ( $!spaceLabel ) ## try to get spaces by category #set ( $spaces = $action.labelManager.getSpacesWithLabel( $spaceLabel ) ) <ul> #foreach ( $space in $spaces ) ## check if current user can view space and space is not archived #if ( $permissionHelper.canView( $action.remoteUser, $space ) && !$space.isArchived() ) <li><a href="$!space.urlPath">$!space.name</a></li> #end #end </ul> #else <div class="aui-message warning"> <p class="title"> <span class="aui-icon icon-warning">Warning</span> <strong>Space category not found</strong> </p> <p>Couldn't find space category <strong>$paramLabel</strong>!</p> </div> #end {code}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Iterating further on the version of Remo Siegwart, I've added:
It's not the prettiest code, but it works. Further improvements could be: selecting AND/OR operator for second category, showing space icon instead of bullet point, etc.
## Macro title: List Spaces by Category
## Macro has a body: N
## @param Label1:title=Category|type=string|required=true|desc=The category you want to list spaces from. Only non-archived spaces will be listed.
## @param Label2:title=Category2|type=string|required=false|desc=Optional second category. Only spaces that have BOTH categories will be listed.
## try to get space categories
#set ( $spaceLabel1 = $action.labelManager.getLabel( "team:${paramLabel1}" ) )
#set ( $spaceLabel2 = $action.labelManager.getLabel( "team:${paramLabel2}" ) )
## check if space category exists
#if ( $!spaceLabel1 )
## try to get spaces by category
#set ( $spaces1 = $action.labelManager.getSpacesWithLabel( $spaceLabel1 ) )
## sort spaces alphabetically
#set($size=$spaces1.size())
#foreach($junk in $spaces1) ##Bubble sort takes n^2 passes
#set($actual=-1)##Having trouble with math on $velocityCount -- keeping my own count
#foreach($line in $spaces1)
#set($actual=$actual+1)
#if($velocityCount<$size) ##Preventing bad array access
## Compare this and previous
## If this is smaller, swap
#if ($line.name.compareToIgnoreCase($spaces1.get($velocityCount).name) > 0 )
#set ($tmp=$spaces1.get($velocityCount))
#set ($junk=$spaces1.set($velocityCount,$line))
#set ($junk=$spaces1.set($actual,$tmp))
#end
#end
#end
#end
<ul>
#foreach ( $space in $spaces1 )
## check if current user can view space and space is not archived
#if ( $permissionHelper.canView( $action.remoteUser, $space ) && !$space.isArchived() )
## check if there is a second category that the space should have to be listed
#if ($!spaceLabel2)
#set ( $spaces2 = $action.labelManager.getSpacesWithLabel( $spaceLabel2 ) )
#if($spaces2.contains($space))
<li><a href="$!space.urlPath">$!space.name</a></li>
#end
#else
<li><a href="$!space.urlPath">$!space.name</a></li>
#end
#end
#end
</ul>
#else
<div class="aui-message warning"> <p class="title"> <span class="aui-icon icon-warning">Warning</span> <p>Couldn't find space category <strong>$paramLabel1</strong>!</p> </div>
#end
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
So I made some modifications to this user macro that I think you may find useful Jo.
Please note, you'll need to update urls with your site and provide the image being called on, browse.png. This is something I used for users to click on to access space permissions (as in the Space Inventory List currently available).
Let me know if you have additional questions
## @param Header:title=Table Header|type=string|required=true|desc=The title for table results. ## @param Label:title=Space Category|type=string|required=true|desc=The category you want to list spaces from. ## try to get space category #set ( $spaceLabel = $action.labelManager.getLabel( "team:${paramLabel}" ) ) ## check if space category exists #if ( $!spaceLabel ) ## try to get spaces by category #set ( $spaces = $action.labelManager.getSpacesWithLabel( $spaceLabel ) ) <STYLE TYPE="text/css"> <!-- .spaceTable { background-color:#F2F2F2;border-collapse:collapse;color:#000;font-size:14px; } .spaceTable th { background-color:#FFFFFF;color:white;width:auto; } .spaceTable td, .spaceTable th { padding:5px;border:0; } .spaceTable td { border-bottom:1px solid #A4A4A4; } --> </STYLE> <TABLE BORDER CLASS="spaceTable"> <TR> <TH border="5" cellpadding="15" width="300px" STYLE="background-color: "><P ALIGN="center"> ${paramHeader} </P> </TH> </TR> #foreach ( $space in $spaces ) ## check if current user can view space #if ( $permissionHelper.canView( $action.remoteUser, $space ) ) <TR> <TD border="5" cellpadding="15" width="auto" STYLE="background-color: #FFFFFF"> <a href="$!space.urlPath">$!space.name</a></TD> <TD border="5" cellpadding="15" width="auto" STYLE="background-color: #FFFFFF"> </a><a href="https://**yoursite**/spaces/spacepermissions.action?key=$!space.key"><DIV TITLE="View Space Permissions"><img src="https://**yoursite**/download/attachments/browse.png"></DIV></a></TD> </TR> #end #end </table> #else <div class="aui-message warning"> <p class="title"> <span class="aui-icon icon-warning">Warning</span> <strong>No spaces in this category</strong> </p> <p>Couldn't find space category <strong>$paramLabel</strong>!</p> </div> #end
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Interesting … didn't think of the possibility of sorting by using a table!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It doesn't work for me, I'm using Confluence 5.5
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Is it possible to force the table to be pre-sorted so I don't need to click on the column header?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Do anyone here know if I can reference space categories in a CQL or if it is only possible using macros?
I could only find page labels usable when composing a CQL..
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey, I try it but i get some HTML looking stuff .... can someone give me the other settings i have to setup on the Makro creation Thing
Thanks :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Same here. It's displaying the script content in html format. I wonder if it needs to be inserted into an html interpreter script.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Has anyone found out why these just show HTML for the results? I can tell my results are correct but it is not rendering correctly
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
For the 1st example (Remo Siegwart) and 3rd example (Jason Muzzarelli) in this feed just replace some code:
< --> <
> --> >
Then the user macro will create valid HTML code.
And: Use the "render"-function when you create the user macro in confluence administration to render the HTML code when the user macro is placed on a confluence site.
Then the 1st and 3rd example works fine :)
For sorting the HTML table in the 3rd example just use the "table filter and charts" macro from the app marketplace to use the full possibilities of filters and sorting in this user macro. On your confluence site you just have to wrap your user macro into the table macro by drag and drop and then configure filters and sorting.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.