cancel
Showing results for 
Search instead for 
Did you mean: 

Hide Dashlet when customize dashboard *SOLVED*

alexcipr
Champ in-the-making
Champ in-the-making
My need was to hide some dashlet from view to all user, when they customize share dasboard. I obtain this result modifying customise-dashlets.get.js in ${tomcat_home}/webapps/share/WEB-INF/classes/alfresco/site-webscripts/org/alfresco/components/dashboard

I've added this function:


function isAvalaibleDashlet(dashletName){
        /*this array contains the script name of dashlet we want to see*/
   var enabledDashlet=["alfresco-network","cmisfeed","my-documents","my-profile","webview"];
        /*————————————————————————————————————————————*/
   for(var j = 0; j < enabledDashlet.length; j++){
      if(enabledDashlet[j] == dashletName){
         return true;
      }
   }
   return false;
}


and modified those two:


// Transform the webscripts to easy-to-access dashlet items for the template
var availableDashlets = [];
for (var i = 0; i < webscripts.length; i++)
{
   var webscript = webscripts[i];
   var uris = webscript.getURIs();
   var scriptId, scriptName, shortNameId, descriptionId;
   if (uris !== null && uris.length > 0 && webscript.shortName !== null)
   {
      // Use the webscript ID to generate a message bundle ID
      //
      // This should really be retrieved from an explicit value but the web scripts framework does not provide
      // a means for storing message bundle IDs, and the web framework is not being used here.
     scriptId = webscript.id;
     scriptName = scriptId.substring(scriptId.lastIndexOf("/") + 1, scriptId.lastIndexOf("."));

        logger.log("******************************  "+scriptName);
        shortNameId = "dashlet." + scriptName + ".shortName";
        descriptionId = "dashlet." + scriptName + ".description";
        if(isAvalaibleDashlet(scriptName)){
         availableDashlets[i] =
           {
             url: uris[0],
             // msg.get(key) returns key if no matching value
             shortName: (msg.get(shortNameId) != shortNameId ? msg.get(shortNameId) : webscript.shortName),
             description: (msg.get(descriptionId) != descriptionId ? msg.get(descriptionId) : webscript.description)
           };
        }
      
   }
  // else skip this webscript since it lacks uri or shortName
}
           logger.log("****************************** END FOR");

[…]


// Transform the webscripts to easy-to-access dashlet items for the template
var columns = [[], [], [], []];
for (i = 0; i < components.length; i++)
{
   var comp = components[i];

   var regionId = comp.properties["region-id"],
      theUrl = comp.properties.url;
   if (regionId !== null && theUrl !== null)
   {
      // Create dashlet
      var shortName, description, d;
      for (var j = 0; j < availableDashlets.length; j++)
      {
         d = availableDashlets[j];
       if(d !== undefined){
          if (d.url == theUrl)
          {
            shortName = d.shortName;
            description = d.description;
            break;
          }
       }
      }
      var dashlet =
      {
         url: theUrl,
         shortName: shortName,
         description: description,
         originalRegionId: regionId
      };

      // Place it in correct column and in a temporary row literal
      if (regionId.match("^component-\\d+-\\d+$"))
      {
         var column = parseInt(regionId.substring(regionId.indexOf("-") + 1, regionId.lastIndexOf("-"))),
            row = parseInt(regionId.substring(regionId.lastIndexOf("-") + 1));
         columns[column-1][row-1] = dashlet;
      }
   }
   // else skip this component since it lacks regionId or shortName
}

[…]


I hope it could be usefull for you

Regards

Alessandro
6 REPLIES 6

zladuric
Champ on-the-rise
Champ on-the-rise
Alessandro,

I don't think anything depends on those dashlets. Why didn't you just remove them? Or at least, just rename the declaration xml file to something like "alfresco-network.get.desc.xml.DISABLED"?

That way they wouldn't show up either.

Except if you really want them be shown somewhere on some sites where you have set them, but not to be added to others?

chrisokelly
Champ on-the-rise
Champ on-the-rise
Sorry to be a thread necromancer here, just wanted to point out this code is still useful and working in community 4.0.d. I made one change to your code, that being -
function isAvalaibleDashlet(dashletName){
        /*this array contains the script name of dashlet we want to see*/
   var enabledDashlet=["alfresco-network","cmisfeed","my-documents","my-profile","webview"];
        /*————————————————————————————————————————————*/

   // My change - Allow admins to add any dashlet
   if (user.isAdmin) return true;


   for(var j = 0; j < enabledDashlet.length; j++){
      if(enabledDashlet[j] == dashletName){
         return true;
      }
   }
   return false;
}

The only difference (and the code works with or without my change btw) is that this shows all dashlets to admins, but the restricted list to others.

zladuric
Champ on-the-rise
Champ on-the-rise
Very smart and elegant solution Smiley Happy

jpfi
Champ in-the-making
Champ in-the-making
well, there are more elegant ways to check if an array contains a specific value, e.g.:
!!~enabledDashlet.indexOf(dashletName)
cheers, jan

zladuric
Champ on-the-rise
Champ on-the-rise
I agree that it's shorter, but I think Douglas Crockford would disapprove Smiley Happy

jpfi
Champ in-the-making
Champ in-the-making
😉