Merged DEV/SHARE-LINKS to HEAD

11867: Fix issues raised by Mike's code review
  11906: Finish Links Dashlet
  12080: Fix bugs raised by 3d code review
  12142: Missed Dashlet Code
  12405: Final run-through of Links component before merge to HEAD
  12406: Further minor edits to Links

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@12416 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Mike Hatfield
2008-12-16 15:57:57 +00:00
parent 3d700a9f10
commit 704d72a00c
9 changed files with 200 additions and 144 deletions

View File

@@ -1,3 +1,5 @@
<#escape x as jsonUtils.encodeJSONString(x)>
{ {
"message":"deleted" "message":"${message}"
} }
</#escape>

View File

@@ -39,9 +39,14 @@ function getRequestNodes()
for (var i in items) for (var i in items)
{ {
var tmpNode = node.childByNamePath(items[i]); if (i)
if (tmpNode) {
nodes.push(tmpNode); var tmpNode = node.childByNamePath(items[i]);
if (tmpNode)
{
nodes.push(tmpNode);
}
}
} }
return nodes; return nodes;
@@ -58,17 +63,20 @@ function deleteLink(linkNode)
var isDeleted = linkNode.remove(); var isDeleted = linkNode.remove();
if (! isDeleted) if (! isDeleted)
{ {
status.setCode(status.STATUS_INTERNAL_SERVER_ERROR, "Unable to delete node: " + nodeRef); var mes = "Unable to delete node: " + nodeRef;
status.setCode(status.STATUS_INTERNAL_SERVER_ERROR, mes);
model.message = mes;
return; return;
} }
//model.message = "Node " + nodeRef + " deleted"; model.message = "Node " + nodeRef + " deleted";
var siteId = url.templateArgs.site; var siteId = url.templateArgs.site;
var containerId = url.templateArgs.container; var containerId = url.templateArgs.container;
var data = { var data =
title:linkData["title"], {
title:linkData.title,
page: "links" page: "links"
} };
activities.postActivity("org.alfresco.links.link-deleted", siteId, containerId, jsonUtils.toJSONString(data)); activities.postActivity("org.alfresco.links.link-deleted", siteId, containerId, jsonUtils.toJSONString(data));
} }
@@ -82,8 +90,22 @@ function main()
return; return;
} }
for (var i in nodes) for (var i in nodes)
deleteLink(nodes[i]); {
if (i)
{
if (!nodes[i].hasPermission("Delete"))
{
status.code = 403;
var mes = "Permission to delete is denied";
status.message = mes;
model.message = mes;
return;
}
deleteLink(nodes[i]);
}
}
} }

View File

@@ -3,29 +3,29 @@
<import resource="classpath:alfresco/templates/webscripts/org/alfresco/repository/generic-paged-results.lib.js"> <import resource="classpath:alfresco/templates/webscripts/org/alfresco/repository/generic-paged-results.lib.js">
<import resource="classpath:alfresco/templates/webscripts/org/alfresco/repository/links/links.lib.js"> <import resource="classpath:alfresco/templates/webscripts/org/alfresco/repository/links/links.lib.js">
const DEFAULT_NUM_DAYS = 7;
/** /**
* Fetches all links added to the site * Fetches all links added to the site
*/ */
function getLinksList(node,filter,tag,numdays, index, count) function getLinksList(node, filter, tag, numdays, index, count)
{ {
//var fromDate = getTodayMinusXDays(numdays);
// query information // query information
var luceneQuery = " +TYPE:\"{http://www.alfresco.org/model/linksmodel/1.0}link\"" + var luceneQuery = " +TYPE:\"{http://www.alfresco.org/model/linksmodel/1.0}link\" +PATH:\"" + node.qnamePath + "/*\"";
" +PATH:\"" + node.qnamePath + "/*\"";
if (filter == "internal") if (filter == "recent")
{ {
//luceneQuery += " +@cm\\:internal:\"true\""; var fromDate = getTodayMinusXDays(DEFAULT_NUM_DAYS);
luceneQuery += "+ASPECT:\"{http://www.alfresco.org/model/linksmodel/1.0}internal\" "; var toDate = new Date();
luceneQuery += getCreationDateRangeQuery(fromDate, toDate);
} }
else if (filter == "www") else if (filter == "user")
{ {
luceneQuery += "-ASPECT:\"{http://www.alfresco.org/model/linksmodel/1.0}internal\" "; luceneQuery += " +@cm\\:creator:" + person.properties.userName;
} }
if (tag != null) if (tag !== null)
{ {
luceneQuery += " +PATH:\"/cm:taggable/cm:" + search.ISO9075Encode(tag) + "/member\" "; luceneQuery += " +PATH:\"/cm:taggable/cm:" + search.ISO9075Encode(tag) + "/member\" ";
} }
@@ -45,19 +45,18 @@ function main()
return; return;
} }
var pNumber = parseInt(args.page); var pNumber = parseInt(args.page, 10);
var pSize = parseInt(args.pageSize); var pSize = parseInt(args.pageSize, 10);
var filter = args.filter; var filter = args.filter;
var tag = (args["tag"] != undefined && args["tag"].length > 0) ? args["tag"] : null; var tag = (args.tag != undefined && args.tag.length > 0) ? args.tag : null;
if ((pNumber == undefined) || (pSize == undefined)) if ((pNumber === undefined) || (pSize === undefined))
{ {
model.error = "Parameters missing!"; model.error = "Parameters missing!";
return; return;
} }
model.links = node;
model.data = getLinksList(node,filter,tag,7,(pNumber - 1) * pSize,pSize); model.data = getLinksList(node,filter,tag,7,(pNumber - 1) * pSize,pSize);
} }
main(); main();

View File

@@ -1,57 +1,66 @@
<#import "../generic-paged-results.lib.ftl" as gen/> <#import "../generic-paged-results.lib.ftl" as gen>
<#macro renderPerson person fieldName> <#macro renderPerson person fieldName>
<#escape x as jsonUtils.encodeJSONString(x)> "${fieldName}":
"${fieldName}" : { {
<#if person.assocs["cm:avatar"]??> <#if person.assocs["cm:avatar"]??>
"avatarRef" : "${person.assocs["cm:avatar"][0].nodeRef?string}", "avatarRef": "${person.assocs["cm:avatar"][0].nodeRef?string}",
</#if> </#if>
"username" : "${person.properties["cm:userName"]}", "username": "${person.properties["cm:userName"]}",
"firstName" : "${person.properties["cm:firstName"]}", "firstName": "${person.properties["cm:firstName"]}",
"lastName" : "${person.properties["cm:lastName"]}" "lastName": "${person.properties["cm:lastName"]}"
}, },
</#escape>
</#macro> </#macro>
<#-- <#--
This template renders a link. This template renders a link.
--> -->
<#macro linkJSON item> <#macro linkJSON item>
<#escape x as jsonUtils.encodeJSONString(x)> <#escape x as jsonUtils.encodeJSONString(x)>
{ {
"url" : "${item.url!''}", "url": "${item.url!''}",
"commentsUrl" : "/node/${item.node.nodeRef?replace('://','/')}/comments", "commentsUrl": "/node/${item.node.nodeRef?replace('://','/')}/comments",
"description" : "${item.description!''}", "description": "${item.description!''}",
"nodeRef" : "${item.node.nodeRef}", "nodeRef": "${item.node.nodeRef}",
"name" : "${item.name!''}", "name": "${item.name!''}",
"title" : "${item.title!''}", "title": "${item.title!''}",
"internal" : "${item.internal!'false'}", "internal": ${(item.internal!false)?string},
"isUpdated" : "${item.isUpdated!'false'}", "createdOn": "${item.createdOn?string("MMM dd yyyy HH:mm:ss 'GMT'Z '('zzz')'")}",
<#if item.author??> <#if item.creator??>
<@renderPerson person=item.author fieldName="author" /> <@renderPerson person=item.creator fieldName="author" />
<#else> <#else>
"author" : { "username" : "${item.node.properties.creator}" }, "author":
</#if> {
"permissions" : { "username": "${item.node.properties.creator}"
"edit" : ${item.node.hasPermission("Write")?string},
"delete" : ${item.node.hasPermission("Delete")?string}
}, },
"tags" : [<#list item.tags as x>"${x}"<#if x_has_next>, </#if></#list>] </#if>
"permissions":
{
"edit": ${item.node.hasPermission("Write")?string},
"delete": ${item.node.hasPermission("Delete")?string}
},
"tags": [<#list item.tags as x>"${x}"<#if x_has_next>, </#if></#list>]
} }
</#escape> </#escape>
</#macro> </#macro>
<#macro renderLinkList> <#macro renderLinkList>
{ {
<@gen.pagedResults data=data ; item> "metadata":
<@linkJSON item=item /> {
</@gen.pagedResults> "linkPermissions":
{
"create": "${links.hasPermission("CreateChildren")?string}"
}
},
<@gen.pagedResults data=data ; item>
<@linkJSON item=item />
</@gen.pagedResults>
} }
</#macro> </#macro>
<#macro renderLink> <#macro renderLink>
{ {
"item" : <@linkJSON item=item /> "item": <@linkJSON item=item />
} }
</#macro> </#macro>

View File

@@ -2,25 +2,22 @@
const LINK_INTERNAL_ASPECT = "lnk:internal"; const LINK_INTERNAL_ASPECT = "lnk:internal";
const ASPECT_INTERNAL = "lnk:isInternal"; const ASPECT_INTERNAL = "lnk:isInternal";
function getLinksData(node) function getLinksData(node)
{ {
var itm = {}; var itm = {};
itm.node = node; itm.node = node;
itm.name = node.name||""; itm.name = node.name || "";
itm.title = node.properties["lnk:linkTitle"]||""; itm.title = node.properties["lnk:title"] || "";
itm.description = node.properties["lnk:description"]||""; itm.description = node.properties["lnk:description"] || "";
itm.url = node.properties["lnk:url"]||""; itm.url = node.properties["lnk:url"] || "";
itm.createdOn = node.properties.created || "";
itm.modifiedOn = node.properties.modified || "";
itm.creator = people.getPerson(node.properties["cm:creator"]);
// get the tags JSONArray and copy it into a real javascript array object itm.tags = node.tags;
itm.tags = node.tags; itm.internal = node.hasAspect("lnk:internal");
itm.internal = (node.hasAspect("lnk:internal")?"true":"false");
itm.author = people.getPerson(node.properties["cm:creator"]); return itm;
// (re-)enable permission
node.setInheritsPermissions(true);
/*itm.isUpdated = node.properties.isUpdated || "false";*/
return itm;
} }
/** /**
@@ -34,17 +31,17 @@ function getLinkProperties()
if (json.has("title")) if (json.has("title"))
{ {
data["lnk:linkTitle"] = json.get("title"); data["lnk:title"] = json.get("title");
} }
if (json.has("url")) if (json.has("url"))
{ {
data["lnk:url"] = json.get("url"); data["lnk:url"] = json.get("url");
} }
if (json.has("description")) if (json.has("description"))
{ {
data["lnk:description"] = json.get("description"); data["lnk:description"] = json.get("description");
} }
return data; return data;
@@ -52,5 +49,5 @@ function getLinkProperties()
function isLinkInternal() function isLinkInternal()
{ {
return (json.has("isinternal")?true:false); return (json.has("internal") ? true : false);
} }

View File

@@ -1,3 +1,7 @@
<#escape x as jsonUtils.encodeJSONString(x)>
{ {
"name" : "${item.name}" "message": "${message}"<#if item??>,
"name": "${item.name?string}"
</#if>
} }
</#escape>

View File

@@ -2,16 +2,15 @@
<import resource="classpath:alfresco/templates/webscripts/org/alfresco/repository/nodenameutils.lib.js"> <import resource="classpath:alfresco/templates/webscripts/org/alfresco/repository/nodenameutils.lib.js">
<import resource="classpath:alfresco/templates/webscripts/org/alfresco/repository/links/links.lib.js"> <import resource="classpath:alfresco/templates/webscripts/org/alfresco/repository/links/links.lib.js">
function ensureTagScope(node) function ensureTagScope(node)
{ {
if (! node.isTagScope) if (!node.isTagScope)
{ {
node.isTagScope = true; node.isTagScope = true;
} }
// also check the parent (the site!) // also check the parent (the site!)
if (! node.parent.isTagScope) if (!node.parent.isTagScope)
{ {
node.parent.isTagScope = true; node.parent.isTagScope = true;
} }
@@ -27,22 +26,22 @@ function createLink(linkNode)
{ {
// get the tags JSONArray and copy it into a real javascript array object // get the tags JSONArray and copy it into a real javascript array object
var tmp = json.get("tags"); var tmp = json.get("tags");
for (var x=0; x < tmp.length(); x++) for (var x = 0; x < tmp.length(); x++)
{ {
tags.push(tmp.get(x)); tags.push(tmp.get(x));
} }
} }
// get a unique name // get a unique name
var nodeName = getUniqueChildName(linkNode, "link"); var nodeName = getUniqueChildName(linkNode, "link");
linkNode = linkNode.createNode(nodeName, "lnk:link",getLinkProperties());
var linkNode = linkNode.createNode(nodeName, "lnk:link",getLinkProperties()); if (isLinkInternal())
{
if (isLinkInternal()) { var pr = [];
var pr = []; pr["lnk:isInternal"] = "true";
pr["lnk:isInternal"] = "true"; linkNode.addAspect("lnk:internal", pr);
linkNode.addAspect("lnk:internal", pr); }
}
linkNode.tags = tags; linkNode.tags = tags;
linkNode.mimetype = "text/html"; linkNode.mimetype = "text/html";
@@ -51,11 +50,14 @@ function createLink(linkNode)
var siteId = url.templateArgs.site; var siteId = url.templateArgs.site;
var containerId = url.templateArgs.container; var containerId = url.templateArgs.container;
var data = { var data =
{
title: json.get("title"), title: json.get("title"),
page: json.get("page") + "?container=links&linkId=" + nodeName page: json.get("page") + "?linkId=" + nodeName
} };
var mes = linkNode.properties["name"];
model.message = mes;
activities.postActivity("org.alfresco.links.link-created", siteId, containerId, jsonUtils.toJSONString(data)); activities.postActivity("org.alfresco.links.link-created", siteId, containerId, jsonUtils.toJSONString(data));
return linkNode; return linkNode;
@@ -70,6 +72,15 @@ function main()
return; return;
} }
if (!node.hasPermission("CreateChildren"))
{
status.code = 403;
var mes = "Permission to create is denied";
status.message = mes;
model.message = mes;
return;
}
ensureTagScope(node); ensureTagScope(node);
var link = createLink(node); var link = createLink(node);

View File

@@ -1,3 +1,5 @@
<#escape x as jsonUtils.encodeJSONString(x)>
{ {
"message":"update" "message": "${message}"
} }
</#escape>

View File

@@ -6,46 +6,50 @@
*/ */
function updateLink(linkNode) function updateLink(linkNode)
{ {
var tags = []; var tags = [];
if (json.has("tags")) if (json.has("tags"))
{ {
// get the tags JSONArray and copy it into a real javascript array object // get the tags JSONArray and copy it into a real javascript array object
var tmp = json.get("tags"); var tmp = json.get("tags");
for (var x = 0; x < tmp.length(); x++) for (var x = 0; x < tmp.length(); x++)
{ {
tags.push(tmp.get(x)); tags.push(tmp.get(x));
} }
} }
var isInternal = isLinkInternal(); var isInternal = isLinkInternal();
if (!linkNode.hasAspect("lnk:internal") && isInternal) if (!linkNode.hasAspect("lnk:internal") && isInternal)
{ {
var pr = []; var pr = [];
pr["lnk:isInternal"] = "true"; pr["lnk:isInternal"] = "true";
linkNode.addAspect("lnk:internal", pr); linkNode.addAspect("lnk:internal", pr);
}
else if (linkNode.hasAspect("lnk:internal") && !isInternal)
{
linkNode.removeAspect("lnk:internal");
}
} else if (linkNode.hasAspect("lnk:internal") && !isInternal) var prs = getLinkProperties();
{ for (var propName in prs)
linkNode.removeAspect("lnk:internal"); {
} if (propName)
{
linkNode.properties[propName] = prs[propName];
}
}
var prs = getLinkProperties(); linkNode.mimetype = "text/html";
for (var propName in prs) linkNode.content = linkNode.properties["lnk:url"];
{ linkNode.tags = tags;
linkNode.properties[propName] = prs[propName]; linkNode.save();
} model.message = "Node " + linkNode.nodeRef + " updated";
var siteId = url.templateArgs.site;
linkNode.mimetype = "text/html"; var containerId = url.templateArgs.container;
linkNode.content = linkNode.properties["lnk:url"]; var data =
linkNode.tags = tags; {
linkNode.save();
var siteId = url.templateArgs.site;
var containerId = url.templateArgs.container;
var data = {
title: json.get("title"), title: json.get("title"),
page: json.get("page") + "?container=links&linkId=" + linkNode.name page: json.get("page") + "?linkId=" + linkNode.name
} };
activities.postActivity("org.alfresco.links.link-updated", siteId, containerId, jsonUtils.toJSONString(data)); activities.postActivity("org.alfresco.links.link-updated", siteId, containerId, jsonUtils.toJSONString(data));
@@ -56,9 +60,15 @@ function main()
{ {
// get requested node // get requested node
var node = getRequestNode(); var node = getRequestNode();
if (!node.hasPermission("WriteProperties") || !node.hasPermission("WriteContent"))
var link = updateLink(node); {
status.code = 403;
var mes = "Permission to update is denied";
status.message = mes;
model.message = mes;
return;
}
updateLink(node);
} }
main(); main();