Friday, June 15, 2012

Custom Admin Console groups

If you add alfresco share - admin console components, it is super easy: just provide a webscript-backed component, where the webscript family is set to 'admin-console'. This is the page-id.

See this excelent guide: http://blogs.alfresco.com/wp/wabson/2011/08/12/custom-admin-console-components-in-share/

Now what if you want it, grouped together with other custom components in a section like 'File Management' or 'Search' ... Well First you have to find the hard-code configuration-by-definition in the template controller 'console.js'. Paths are relative to site-webscripts.

It states in a comment, followed by code:


            // identify console tool grouping if any
            // simple convention is used to resolve group - last element of the webscript package path after 'console'
            // for example: org.alfresco.components.console.repository = repository
            //              org.yourcompany.console.mygroup = mygroup
            // package paths not matching the convention will be placed in the default root group
            // the I18N label should be named: tool.group.<yourgroupid>

            var group = "",
                groupLabelId = null,
                paths = tool.scriptPath.split('/');
            if (paths.length > 4 && paths[3] == "console")
            {
               // found webscript package grouping
               group = paths[4];
               groupLabelId = "tool.group." + group;
            }


This means component path 'com/mycomp/project/console/projectcomponents/component' will not be picked up, but 'com/mycomp/console/projectcomponents/component' will!

Side note: A more flexible approach could be to change it to:


            var group = "",
                groupLabelId = null,
                paths = tool.scriptPath.split('/');
            if (paths.length > 1 && paths[paths.length - 2] == "console")
            {
               // found webscript package grouping
               group = paths[paths.length - 1];
               groupLabelId = "tool.group." + group;
            }


This way both examples are valid and group is extracted as 'projectcomponents'.

Any way this gives you a new group after you configure you properties as well, for each group configure a property tool.group.<group>=<Your Group Title>

What you might notice now is a little to hard-coded assumption, that the first group is the default without a group is the first to be rendered in 'console-tools.get.html.ftl'. How ever the new group might be first, so the default group is placed wrong.


This can be fixed by customising the code to find the default group first:
<div id="${args.htmlid?html}-body" class="tool tools-link">
   <h2>${msg("header.tools")}</h2>
   <ul class="toolLink">
      <#list tools as group>
         <#list group as tool>
             <#if tool.group == "">
         <li class="<#if tool_index=0>first-link</#if><#if tool.selected> selected</#if>"><span><a href="${tool.id}" class="tool-link" title="${tool.description?html}">${tool.label?html}</a></span></li>
             </#if>
         </#list>
      </#list>
      <#list tools as group>
         <#list group as tool>
             <#if tool.group != "">
         <#if tool_index = 0></ul><h3>${tool.groupLabel}</h3><ul class="toolLink"></#if>
         <li class="<#if tool_index=0>first-link</#if><#if tool.selected> selected</#if>"><span><a href="${tool.id}" class="tool-link" title="${tool.description?html}">${tool.label?html}</a></span></li>
             </#if>
         </#list>
      </#list>
   </ul>
</div>