Extract the generate_url(..) function from node.js, and collection.js

This commit is contained in:
Violet Cheng
2017-08-17 21:43:07 +05:30
committed by Ashesh Vashi
parent e9b80dae9c
commit d527769bf8
4 changed files with 147 additions and 71 deletions

View File

@@ -0,0 +1,23 @@
import _ from 'underscore';
function generate_url(baseUrl, treeInfo, actionType, nodeType, pickFunction, itemDataID) {
let ref = '';
_.each(
_.sortBy(
_.pick(treeInfo, pickFunction),
function (treeInfoItems) {
return treeInfoItems.priority;
}
),
function (treeInfoItems) {
ref = `${ref}/${encodeURI(treeInfoItems._id)}`;
}
);
ref = itemDataID ? `${ref}/${itemDataID}` : `${ref}/`;
return `${baseUrl}${nodeType}/${actionType}${ref}`;
}
module.exports = {
generate_url: generate_url,
};