cancel
Showing results for 
Search instead for 
Did you mean: 

Howto make a dashlet listing all folders of a site?

max12
Champ in-the-making
Champ in-the-making
Hi,

I want to make a dashlet, that list all folders from the 'documentLibrary'.
I tried this analog to the 'documentsummary' dashlet, but I dont seem to be able to find out, how to get all folders instead of documents.

'documentsummary.get.js':

// Get the Documents Modified data for this site
var url = args.dod5015 ? "/slingshot/doclib/dod5015/doclist/documents/site/" : "/slingshot/doclib/doclist/documents/site/";
var json = remote.call(url + page.url.templateArgs.site + "/documentLibrary?filter=recentlyModified&max=10");

// Create the model
var docs = eval('(' + json + ')');
model.docs = docs;

now what I tried is the following:
// Get the Folders
var site, container, theUrl, connector, result, lists;
  
   site = page.url.templateArgs.site;
   container = 'documentLibrary';
   theUrl = '/slingshot/doclib/container/' + site + '/' + container;
   connector = remote.connect("alfresco");
   result = connector.get(theUrl);
   var response = null;
   if (result.status == 200)
   {
      response = eval('(' + result.response + ')');
     
   }

model.docs = response;

which only returns the nodeRef of the container 'documentLibrary'

I do have the following situation/folder structure:

documentLibrary
- folder1
   - some subfolders
- folder2
- folder3


What I want to have in my dashlet is a nice list of those folders (folder1, folder2, folder3,… without subfolders) with description etc.

Thanks for your help.
max12
3 REPLIES 3

mrogers
Star Contributor
Star Contributor
There may already be a webscript that does what you want.  I don't know and don't have the service listing in front of me.

What I do know is that there's a method in the java API on the NodeService to list all folders within a space, both deep and shallow.    So it would be fairly easy to add a new script if one does not already exist.

kevinr
Star Contributor
Star Contributor
Thanks for your umm helpful reply Mark…

Anyway, yes there are webscripts that can do this, the simplist choice is probably the one used by the TreeView component in the doclib:

/slingshot/doclib/treenode/site/YOUR-SITE-NAME-HERE/documentLibrary?children=false&max=-1

This returns a simple json structure of all the top-level folders in a site.

Something like this:
{
   "totalResults": 4,
   "resultsTrimmed": false,
   "parent":
   {
      "nodeRef": "workspace://SpacesStore/7512f001-fd8e-4b67-9fa6-31c2b8a8b58e",
      "userAccess":
      {
         "create": true,
         "edit": true,
         "delete": true
      }
   },
   "items":
   [
      {
         "nodeRef": "workspace://SpacesStore/25b959be-4aba-450d-9b79-22f10d0177f3",
         "name": "test folder",
         "description": "some description here",
         "hasChildren": false,
         "userAccess":
         {
            "create": true,
            "edit": true,
            "delete": true
         }
      },
      …

You can also use the doclist webscript to retrieve folder items:
/slingshot/doclib/doclist/folders/site/YOUR-SITE-NAME-HERE/documentLibrary

It returns a more complex json structure with more detail in it - which you might not need.

Thanks,

Kev

max12
Champ in-the-making
Champ in-the-making
Thanks for your replies.

I solved this as follows (in the .get.js of the dashlet):

var url = args.dod5015 ? "/slingshot/doclib/dod5015/doclist/folders/site/" : "/slingshot/doclib/doclist/folders/site/";
var json = remote.call(url + page.url.templateArgs.site + "/documentLibrary/myfolder");

and then using a list in the .get.html.ftl to display the folders.