Skip to content

Commit

Permalink
#33 Display Images - Folders tree fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
spuliaiev-sfdc committed Jul 26, 2018
1 parent 37e9984 commit b7e14c1
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class FolderStats implements Serializable {
private static final long serialVersionUID = 1L;

String name;
String parentName;
String fullPath;
Long filesCount;
Long foldersCount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,16 @@ private List<AggregationOperation> prepareBasePathPipeline(RequestCriteria sear
}

int selectLevelToExtract = StringUtils.countMatches(sourcePath.replaceAll("\\^\\\\\\/",""),"/");
if (sourcePath.length() > 0) {
selectLevelToExtract++;
}

pipelineBase.add(project()
.and("$filePath").as("filePath")
.and(ArrayOperators.arrayOf(StringOperators.Split.valueOf("$filePath").split("/")).elementAt(selectLevelToExtract)).as("name")
.and(ArrayOperators.arrayOf(StringOperators.Split.valueOf("$filePath").split("/")).elementAt(selectLevelToExtract-1)).as("parentName")
);
pipelineBase.add(group(fields("name").and("filePath")).count().as("count"));
pipelineBase.add(group(fields("name").and("parentName").and("filePath")).count().as("count"));

return pipelineBase;
}
Expand Down Expand Up @@ -291,19 +295,23 @@ public <T extends Information> Page<FolderStats> fetchPathCustom(RequestCriteria
if ("".equals(originalPath)) {
searchCriteria.setPath("[^\\/]+");
} else {
searchCriteria.setPath(originalPath+"/[^\\/]+");
searchCriteria.setPath(originalPath);
}
List<AggregationOperation> pipelineSubChildren = prepareBasePathPipeline(searchCriteria);
searchCriteria.setPath(originalPath);
pipelineSubChildren.add(project().and("$_id.name").as("name").and("$count").as("filesCount").and("$_id.filePath").as("fullPath"));
pipelineSubChildren.add(group(fields("name").and("name")).count().as("foldersCount"));
pipelineSubChildren.add(project()
.and("$_id.name").as("name")
.and("$parentName").as("parentName")
.and("$count").as("filesCount")
.and("$_id.filePath").as("fullPath"));
pipelineSubChildren.add(group(fields("name").and("name").and("parentName")).count().as("foldersCount"));

Aggregation aggregation = newAggregation(clazz, (AggregationOperation[]) pipelineSubChildren.toArray(new AggregationOperation[]{}));
// get distinct path, but before we need to cut the original path - and everything starting from first slash /
AggregationResults<FolderStats> outputSubFolders = template.aggregate(aggregation, clazz, FolderStats.class);

Map<String, FolderStats> subFoldersInfo = new HashMap<>();
outputSubFolders.forEach(fs -> subFoldersInfo.put(fs.getName(), fs));
outputSubFolders.forEach(fs -> subFoldersInfo.put(fs.getParentName(), fs));

output.forEach(fs -> {
if (subFoldersInfo.containsKey(fs.getName())) {
Expand Down
2 changes: 1 addition & 1 deletion ui/web/src/main/resources/static/js/cmp/TreeDates.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ var TreeDates = {
return "/sources/findDates";
},
"data" : function (node, cb, par2) {
var criteria = treeObject.prepareCriteria(this, node);
var criteria = treeObject.prepareCriteria(node);
return JSON.stringify(criteria, null, 2);
},
"postprocessor": function (node, data, par2) {
Expand Down
6 changes: 5 additions & 1 deletion ui/web/src/main/resources/static/js/cmp/TreePath.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ var TreePath = {
return "/sources/findPath";
},
"data" : function (node, cb, par2) {
var criteria = treeObject.prepareCriteria(this, node);
var data = node;
if (node && node.original && node.original.content) {
data = node.original.content;
}
var criteria = treeObject.prepareCriteria(data);
return JSON.stringify(criteria, null, 2);
},
"postprocessor": function (node, data, par2) {
Expand Down
19 changes: 11 additions & 8 deletions ui/web/src/main/resources/static/js/cmp/sourceList.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,11 @@ var SourceList = {
return null;
},
fillBreadcrumb: function (breadcrumbText){
var crumbs = breadcrumbText.split("/");
this.breadcrumb.empty();
if (!validValue(breadcrumbText)) {
return;
}
var crumbs = breadcrumbText.split("/");
for(index in crumbs) {
var cr = crumbs[index];
if (index === (crumbs.length-1)) {
Expand All @@ -128,7 +131,7 @@ var SourceList = {
}
},

prepareCriteria: function (path) {
prepareCriteria: function (data) {
var criteria = {
path: "",
grade: this.grade,
Expand All @@ -139,13 +142,13 @@ var SourceList = {
size: 1000
};

// if (validValue(path)) {
// criteria.path = path;
// }

if (this.criteriaContributor) {
criteria = this.criteriaContributor(this, criteria);
}
if (validValue(data) && validValue(data.fullPath)) {
criteria.path = data.fullPath;
}


return criteria;
},
Expand Down Expand Up @@ -253,13 +256,13 @@ var SourceList = {
if (typeof TreePath != "undefined" && object.options.treePath) {
object.treeFolderPath = TreePath.create($('#folderTree'),
function(e, data, tree) {return object.clickFoldersTreeNode(e, data, tree);},
function (treeElement, node) { return object.prepareCriteria(node);}
function (node) { return object.prepareCriteria(node);}
);
}
if (typeof TreePath != "undefined" && object.options.treeDates) {
object.treeDates = TreeDates.create($('#datesTree'),
function(e, data, tree) {object.clickDatesTreeNode(e, data, tree);},
function (treeElement, node) { return object.prepareCriteria(node);}
function (node) { return object.prepareCriteria(node);}
);
}
if (typeof Gallery != "undefined" && object.options.gallery) {
Expand Down
46 changes: 18 additions & 28 deletions ui/web/src/main/resources/static/js/importRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ var ImportRequestsTree = {
var processId = ImportRequestsTree.getActiveProcessId();
return "/importing/list/"+processId+"/"+id;
},
"postprocessor": function (node, data, par2) {
var dataNew = ImportRequestsTree.preprocessAsNodes(data.list.content, data.result);
"postprocessor": function (node, data) {
var dataNew = ImportRequestsTree.preprocessAsNodes(data.list.content, data.result, node);
// dataNew.id = node.id;
// dataNew.parent = node.parent;
return dataNew;
Expand Down Expand Up @@ -121,36 +121,22 @@ var ImportRequestsTree = {
}).on("select_node.jstree", ImportRequestsTree.onNodeClick);
},

preprocessAsNodes: function (nodesList, nodeParent) {
preprocessAsNodes: function (nodesList, nodeParent, treeNode) {
function prepareNode(nodeData) {
var node = {};
node.text = (nodeData.path === "") ? "Gallery Root" : nodeData.path;
var node = {
text : (nodeData.path === "") ? "Gallery Root" : nodeData.path,
icon : "NODE_STATUS_" + nodeData.status,
parent : nodeData.parent ? nodeData.parent : "#",
content : nodeData,
state : { opened: false },
children: nodeData.foldersCount > 0
};
if (node.rootPath && node.text.startsWith(nodeData.rootPath)) {
node.text = node.text.substr(nodeData.rootPath.length);
}
if (node.text.startsWith("/")) {
node.text = node.text.substr(1);
}
node.icon = "NODE_STATUS_" + nodeData.status;
node.content = nodeData;
node.state = {
opened: false
};
node.parent = nodeData.parent;
if (node.parent === null) {
node.parent = '#';
// node.id = '#';
// } else {
// node.parent = node.id;
}
// if (node.parent === nodeData.rootId) {
// node.parent = '#';
// node.id = '#';
// }
if (nodeData.foldersCount > 0) {
node.children = true;
}

return node;
}

Expand All @@ -161,8 +147,12 @@ var ImportRequestsTree = {
}

if (nodeParent) {
var childrenLoadRequest = treeNode && treeNode.original && treeNode.original.content&&
nodeParent.id === treeNode.original.content.id;
if (childrenLoadRequest) {
return nodes;
}
var parentNode = prepareNode(nodeParent);
// nodesList.push(nodeParent);
if (nodes.length > 0) {
parentNode.children = nodes;
}
Expand Down Expand Up @@ -258,14 +248,14 @@ var ImportRequestsTree = {

criteriaContributor: function(sourceList, criteria) {
criteria.requestId = ImportRequestsTree.getActiveImportId();
criteria.path = "";
criteria.path = null;
return criteria;
},
criteriaContributorMatches: function(sourceList, criteria) {
var block = ImportRequestsTree.getSelectedImportSource();
if (block) {
criteria.matchesOfImportId = block.dataobject.id;
criteria.path = "";
criteria.path = null;
return criteria;
} else {
debugger;
Expand Down

0 comments on commit b7e14c1

Please sign in to comment.