mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Improved doc lib extensibility
* doclist.lib.js now has an overridable "doclist_getAllNodes" function that makes it easier to reuse doclist.lib.js and its "doclist_main" method * DefaultDoclistDataUrlResolver now has a basePath parameter so its possible to redirect doclib rest calls to a custom repo webscript using only config git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@42652 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1,5 +1,94 @@
|
|||||||
const REQUEST_MAX = 1000;
|
const REQUEST_MAX = 1000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method that performs the actual loading of the nodes.
|
||||||
|
*
|
||||||
|
* Note!
|
||||||
|
* Will optimize performance by using ScriptNode.childFileFolders for directory listings
|
||||||
|
* In other words when the "path" filter is used.
|
||||||
|
*
|
||||||
|
* @method doclist_getAllNodes
|
||||||
|
* @param parsedArgs {Object}
|
||||||
|
* @param filterParams {Object}
|
||||||
|
* @param query {String}
|
||||||
|
* @param totalItemCount {int}
|
||||||
|
* @return {object} Returns the node and corresponding pagination metadata
|
||||||
|
* {
|
||||||
|
* allNodes: {Array}
|
||||||
|
* totalRecords: {int}
|
||||||
|
* requestTotalCountMax: {int}
|
||||||
|
* paged: {boolean}
|
||||||
|
* query: {String}
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
function doclist_getAllNodes(parsedArgs, filterParams, query, totalItemCount)
|
||||||
|
{
|
||||||
|
var filter = args.filter,
|
||||||
|
totalRecords = 0,
|
||||||
|
requestTotalCountMax = 0,
|
||||||
|
paged = false,
|
||||||
|
allNodes = [];
|
||||||
|
if ((filter || "path") == "path")
|
||||||
|
{
|
||||||
|
// TODO also add DB filter by "node" (in addition to "path")
|
||||||
|
var parentNode = parsedArgs.pathNode;
|
||||||
|
if (parentNode !== null)
|
||||||
|
{
|
||||||
|
var skip = -1,
|
||||||
|
max = -1;
|
||||||
|
|
||||||
|
if (args.size != null)
|
||||||
|
{
|
||||||
|
max = args.size;
|
||||||
|
|
||||||
|
if (args.pos > 0)
|
||||||
|
{
|
||||||
|
skip = (args.pos - 1) * max;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var sortField = (args.sortField == null ? "cm:name" : args.sortField),
|
||||||
|
sortAsc = (((args.sortAsc == null) || (args.sortAsc == "true")) ? true : false);
|
||||||
|
|
||||||
|
// Get paged set
|
||||||
|
requestTotalCountMax = skip + REQUEST_MAX;
|
||||||
|
var pagedResult = parentNode.childFileFolders(true, true, filterParams.ignoreTypes, skip, max, requestTotalCountMax, sortField, sortAsc, "TODO");
|
||||||
|
|
||||||
|
allNodes = pagedResult.page;
|
||||||
|
totalRecords = pagedResult.totalResultCountUpper;
|
||||||
|
paged = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Query the nodes - passing in sort and result limit parameters
|
||||||
|
if (query !== "")
|
||||||
|
{
|
||||||
|
allNodes = search.query(
|
||||||
|
{
|
||||||
|
query: query,
|
||||||
|
language: filterParams.language,
|
||||||
|
page:
|
||||||
|
{
|
||||||
|
maxItems: totalItemCount
|
||||||
|
},
|
||||||
|
sort: filterParams.sort,
|
||||||
|
templates: filterParams.templates,
|
||||||
|
namespace: (filterParams.namespace ? filterParams.namespace : null)
|
||||||
|
});
|
||||||
|
|
||||||
|
totalRecords = allNodes.length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
allNodes: allNodes,
|
||||||
|
totalRecords: totalRecords,
|
||||||
|
requestTotalCountMax: requestTotalCountMax,
|
||||||
|
paged: paged,
|
||||||
|
query: query
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main entry point: Create collection of documents and folders in the given space
|
* Main entry point: Create collection of documents and folders in the given space
|
||||||
*
|
*
|
||||||
@@ -37,59 +126,16 @@ function doclist_main()
|
|||||||
// For all sites documentLibrary query we pull in all available results and post filter
|
// For all sites documentLibrary query we pull in all available results and post filter
|
||||||
if (totalItemCount === 0) totalItemCount = -1;
|
if (totalItemCount === 0) totalItemCount = -1;
|
||||||
else if (allSites) totalItemCount = (totalItemCount > 0 ? totalItemCount * 10 : 500);
|
else if (allSites) totalItemCount = (totalItemCount > 0 ? totalItemCount * 10 : 500);
|
||||||
|
|
||||||
if ((filter || "path") == "path")
|
|
||||||
{
|
|
||||||
// TODO also add DB filter by "node" (in addition to "path")
|
|
||||||
var parentNode = parsedArgs.pathNode;
|
|
||||||
if (parentNode !== null)
|
|
||||||
{
|
|
||||||
var skip = -1,
|
|
||||||
max = -1;
|
|
||||||
|
|
||||||
if (args.size != null)
|
|
||||||
{
|
|
||||||
max = args.size;
|
|
||||||
|
|
||||||
if (args.pos > 0)
|
|
||||||
{
|
|
||||||
skip = (args.pos - 1) * max;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var sortField = (args.sortField == null ? "cm:name" : args.sortField),
|
|
||||||
sortAsc = (((args.sortAsc == null) || (args.sortAsc == "true")) ? true : false);
|
|
||||||
|
|
||||||
// Get paged set
|
|
||||||
requestTotalCountMax = skip + REQUEST_MAX;
|
|
||||||
var pagedResult = parentNode.childFileFolders(true, true, filterParams.ignoreTypes, skip, max, requestTotalCountMax, sortField, sortAsc, "TODO");
|
|
||||||
|
|
||||||
allNodes = pagedResult.page;
|
var allNodesResult = doclist_getAllNodes(parsedArgs, filterParams, query, totalItemCount);
|
||||||
totalRecords = pagedResult.totalResultCountUpper;
|
allNodes = allNodesResult.allNodes;
|
||||||
paged = true;
|
totalRecords = allNodesResult.totalRecords;
|
||||||
}
|
requestTotalCountMax = allNodesResult.requestTotalCountMax;
|
||||||
}
|
paged = allNodesResult.paged;
|
||||||
else
|
query = allNodesResult.query;
|
||||||
{
|
|
||||||
// Query the nodes - passing in sort and result limit parameters
|
|
||||||
if (query !== "")
|
|
||||||
{
|
|
||||||
allNodes = search.query(
|
|
||||||
{
|
|
||||||
query: query,
|
|
||||||
language: filterParams.language,
|
|
||||||
page:
|
|
||||||
{
|
|
||||||
maxItems: totalItemCount
|
|
||||||
},
|
|
||||||
sort: filterParams.sort,
|
|
||||||
templates: filterParams.templates,
|
|
||||||
namespace: (filterParams.namespace ? filterParams.namespace : null)
|
|
||||||
});
|
|
||||||
|
|
||||||
totalRecords = allNodes.length;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (logger.isLoggingEnabled())
|
if (logger.isLoggingEnabled())
|
||||||
logger.log("doclist.lib.js - query results: " + allNodes.length);
|
logger.log("doclist.lib.js - query results: " + allNodes.length);
|
||||||
// Generate the qname path match regex required for all sites 'documentLibrary' results match
|
// Generate the qname path match regex required for all sites 'documentLibrary' results match
|
||||||
|
Reference in New Issue
Block a user