Confluence user macro: "Popular labels" (with new label-filter) -> why is this not working on the "current" space?

Sven
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 18, 2011

Hello,

the below usermacro is working fine on all spaces which I enter as parameters. But it does not work if I enter the current space as parameter. What's going wrong? Something wrong with "containerContext" ?

Thanks for any hint.

Bye

Sven

BTW: If someone knows how to pass in the labels as a parameter (list separated with ",") and how to check in the if-condition against this list, you are welcome, too...

## @param spacekey:title=Spacename|type=spacekey|required=true|desc=Spacename|default=template
## @param maxresults:title=Maximale Anzahl|type=string|required=true|default=30
  
#set($containerManagerClass=$action.class.forName('com.atlassian.spring.container.ContainerManager'))
#set($getInstanceMethod=$containerManagerClass.getDeclaredMethod('getInstance',null))
#set($containerManager=$getInstanceMethod.invoke(null,null))
#set($containerContext=$containerManager.containerContext)
   
##com.atlassian.confluence.labels.actions.RankedNameComparator
#set($RankingComparator=$action.class.forName('com.atlassian.confluence.labels.actions.RankedNameComparator').newInstance())
   
 
#set($labelManager=$containerContext.getComponent('labelManager'))

#requireResource("confluence.macros.advanced:popular-labels-resources")
<div class="heatmap">
	<ul> 
	#foreach( $pLR in $labelManager.getMostPopularLabelsWithRanksInSpace($paramspacekey, 30, $RankingComparator) )

	    #set( $n = $pLR.label )
        #if ( !($n == "sv") && !($n == "hometab") && !($n == "metatocheck") && !($n == "prio1") && !($n == "prio2") && !($n == "prio3") && !($n == "prio4") && !($n == "prio5") && !($n == "s_init") && !($n == "s_30") && !($n == "s_60") && !($n == "s_done") )
		
			#set ($size = 12 + $pLR.rank * 2)
			<li style="font-size:${size}px;">#labelLink($pLR.label)</li>
		#end

    #end
    </ul>
</div>

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
Tilmann Prautzsch January 2, 2012

Hello,

your code is working for me also with current space as parameter! I have no spaces or special chars in my space name.

Additional, I have tried this adaption to take empty spacekey (required=false and no default value) as current space and it is working for me too:

#set($spacekey=$space.key)
#if($paramspacekey)
#set($spacekey=$paramspacekey)
#end

Labels as parameter list (one suggestion):

## @param labels:tilte=Labels|type=string

#foreach($label in $paramlabels.split(","))
$labelManager.getContentCount($labelManager.getLabel($label)))
#end

Thank you for your example with using LabelManager!

Bye,

Tilmann

Sven
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 9, 2012

Thanks a lot for trying.

Strange thing: On another space it is working for me, too ;-)

TAGS
AUG Leaders

Atlassian Community Events