cancel
Showing results for 
Search instead for 
Did you mean: 

Tag sorting

roblloyd
Champ in-the-making
Champ in-the-making
I am using the community version running on Centos 5.5. I did search first but couldn't find what I was looking for so here's my question.

Under document library we have a lot of tags. How do I change the tags to sort alphanumerically instead of by how many results there are? I'm using this to do instant searched by part# so having the part numbers jump around isn't helpful.

Thanks,
Rob
9 REPLIES 9

marco_altieri
Star Contributor
Star Contributor
The webscript that returns the list of tags in the "document list" page is:
org/alfresco/repository/tagging/tagscope-tags.get.desc.xml

You should override in your extension folder the file org/alfresco/repository/tagging/tagscope-tags.get.json.ftl
adding a sort_by:

<#if (noscopefound?? && noscopefound)>
{
   "tags" : []
}
<#else>
   {
      "tags" : [
         <#import "tagging.lib.ftl" as taggingLib/>
         <#list tags?sort_by("name") as item>
            <@taggingLib.tagJSON item=item />
            <#if item_has_next>,</#if>
         </#list>
      ]
   }
</#if>

This is the easiest way to do it, but it could be better to avoid a double sort of the list. To do it,  you should modify the services used by this script…

roblloyd
Champ in-the-making
Champ in-the-making
Thank you! That worked perfectly. It's a very small install (5 users) so this double sort works fine for them.

ataylor
Champ in-the-making
Champ in-the-making
Where exactly is this 'extension directory'? I assume it is under <alfresco-dir>/tomcat/shared/classes but I have made several attempts to put the ftl script in a logical directory there and then 'refresh scripts' but it did not work. I was able to put the ftl script in the alfresco directory under <alfresco-dir>/tomcat/webapps/alfresco (I know - I should not - I would rather not) and was able to make that work, but I would prefer to learn where these scripts should be located under the 'extensions' directory. I am using version 4.0.c.

mikeh
Star Contributor
Star Contributor
Where exactly is this 'extension directory'? I assume it is under <alfresco-dir>/tomcat/shared/classes but I have made several attempts to put the ftl script in a logical directory there and then 'refresh scripts' but it did not work. I was able to put the ftl script in the alfresco directory under <alfresco-dir>/tomcat/webapps/alfresco (I know - I should not - I would rather not) and was able to make that work, but I would prefer to learn where these scripts should be located under the 'extensions' directory. I am using version 4.0.c.

Please see http://docs.alfresco.com/4.0/topic/com.alfresco.enterprise.doc/concepts/ws-component-place.html

Thanks,
Mike

ataylor
Champ in-the-making
Champ in-the-making
Are these extension/override directories read during a webscript refresh, or are they only read on system startup?

boiss007
Champ on-the-rise
Champ on-the-rise
I needed to do the same on a community 4.2.e and 5.0 so i give here my dirty solution, the alfresco's mechanism to deal with tag- or other datalist has changed…. i needed a quick fix, it's certainly not the best solution…

In tomcat/webapps/share/components/tag-filter :
_save tag-filter-min.js and tag-filter.js to tag-filter-min.js.original and tag-filter.js.original
_modify tag-filter.js :

diff tag-filter.js tag-filter.js.original
38,47d37
< /**
< * We need a sorting function for our array of tag Objects
< **/
< function sortByKey(array, key) {
<     return array.sort(function(a, b) {
<         var x = a[key]; var y = b[key];
<         return ((x < y) ? -1 : ((x > y) ? 1 : 0));
<     });
< };
<
218,219d207
<    // We need to sort the tags array by name….
<       tags = sortByKey(tags, 'name');

_create the tag-filter-min.js (with yuicompressor)

Ideally the sorting could b done on the server side, but it works and doesn't seems to impact alfresco's performance :°)

ioudas
Champ in-the-making
Champ in-the-making
This doesnt really match up with 5.0 A code wise.

Do you have a whole file you could share?

talleyrand
Champ in-the-making
Champ in-the-making
Did you try tag sorting with Community 5.0.d version?

daballiemo
Champ in-the-making
Champ in-the-making

still works for 201707 Community Edition:

create directory

/opt/alfresco/tomcat/shared/classes/alfresco/extension/templates/webscripts/org/alfresco/repository/tagging

 

In this directory create the file tagscope-tags.get.json.ftl with the following contents:

 

<#if (noscopefound?? && noscopefound)>

{

   "tags" : []

}

<#else>

   {

      "tags" : [

         <#import "tagging.lib.ftl" as taggingLib/>

         <#list tags?sort_by("name") as item>

            <@taggingLib.tagJSON item=item />

            <#if item_has_next>,</#if>

         </#list>

      ]

   }

</#if>

 

stop and start Alfresco and tags are sorted alfabetically