diff --git a/config/alfresco/templates/webscripts/org/alfresco/slingshot/docsummary/docsummary.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/slingshot/docsummary/docsummary.get.desc.xml new file mode 100644 index 0000000000..77e4051386 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/slingshot/docsummary/docsummary.get.desc.xml @@ -0,0 +1,8 @@ + + docsummary + Document Summary Component Data Webscript + /slingshot/docsummary?site={site}&filter={filter?} + + user + required + \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/slingshot/docsummary/docsummary.get.html.ftl b/config/alfresco/templates/webscripts/org/alfresco/slingshot/docsummary/docsummary.get.html.ftl new file mode 100644 index 0000000000..57460f8816 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/slingshot/docsummary/docsummary.get.html.ftl @@ -0,0 +1 @@ +<#include "docsummary.get.json.ftl"> \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/slingshot/docsummary/docsummary.get.js b/config/alfresco/templates/webscripts/org/alfresco/slingshot/docsummary/docsummary.get.js new file mode 100644 index 0000000000..58ff8769d8 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/slingshot/docsummary/docsummary.get.js @@ -0,0 +1,81 @@ + +/** + * Document Summary Component: docsummary + * + * Inputs: + * mandatory: site = the site to get documents from + * optional: filter = the filter to apply + * + * Outputs: + * docs - object containing list of documents + */ +model.docs = getDocs(args["site"], args["filter"]); + +/* Create collection of documents */ +function getDocs(siteId, filter) +{ + try + { + /* siteId input */ + var site = siteService.getSite(siteId); + if (site === null) + { + return jsonError("Site not found: " + siteId); + } + + var parentNode = site.getContainer("documentLibrary"); + if (parentNode === null) + { + return jsonError("Document Library container not found in: " + siteId + ". (No write permission?)"); + } + + // build up the query to get documents modified in the last 7 days + var path = parentNode.qnamePath + "//*"; + + var date = new Date(); + var toQuery = date.getFullYear() + "\\-" + (date.getMonth()+1) + "\\-" + date.getDate(); + date.setDate(date.getDate() - 7); + var fromQuery = date.getFullYear() + "\\-" + (date.getMonth()+1) + "\\-" + date.getDate(); + + search.setStoreUrl("workspace://SiteStore"); + var docs = search.luceneSearch("+PATH:\"" + path + "\"" + + " +@cm\\:modified:[" + fromQuery + "T00\\:00\\:00 TO " + toQuery + "T23\\:59\\:59]", + "cm:modified", false); + + var items = null; + + // restrict results to 10 items if necessary + if (docs.length > 10) + { + items = new Array(); + for (var x = 0; x < 10; x++) + { + items.push(docs[x]); + } + } + else + { + items = docs; + } + + return ({ + "items": items + }); + } + catch(e) + { + return jsonError(e.toString()); + } +} + + +/* Format and return error object */ +function jsonError(errorString) +{ + var obj = + { + "error": errorString + }; + + return obj; +} diff --git a/config/alfresco/templates/webscripts/org/alfresco/slingshot/docsummary/docsummary.get.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/slingshot/docsummary/docsummary.get.json.ftl new file mode 100644 index 0000000000..33f3801833 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/slingshot/docsummary/docsummary.get.json.ftl @@ -0,0 +1,23 @@ +{ + <#if docs.error?exists> + "error": "${docs.error}" + <#else> + "items": + [ + <#list docs.items as d> + { + "nodeRef": "${d.nodeRef}", + "icon16": "${d.icon16}", + "icon32": "${d.icon32}", + "name": "${d.name}", + "title": "${d.properties.title!""}", + "description": "${d.properties.description!""}", + "createdOn": "${d.properties.created?datetime}", + "createdBy": "${d.properties.creator}", + "modifiedOn": "${d.properties.modified?datetime}", + "modifiedBy": "${d.properties.modifier}" + }<#if d_has_next>, + + ] + +} \ No newline at end of file