Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions assets/js/scancode.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,33 @@ $(document).ready(function () {

var jstree = $('#jstree').jstree({
"types": {
"folder": {
"directory": {
"icon": "glyphicon glyphicon-folder-close"
},
"file": {
"icon": "glyphicon glyphicon-file"
}
},
"plugins": [ "types"]
"plugins": [ "types" , "sort"],
//A sort function to sort the tree so that folders come first
"sort": function(a,b){
x = this.get_node(a)
y = this.get_node(b)
if(x.type == "directory"){
if(y.type == "directory"){
//if both the nodes are directory, alphabetic wise priority is given
return (x.text>y.text) ? 1 : -1
}else{
return -1
}
}else{
if(y.type == "directory"){
return 1
}else{
return (x.text>y.text) ? 1 : -1
}
}
}
})
.on('open_node.jstree', function (evt, data) {
data.instance.set_icon(
Expand Down Expand Up @@ -289,6 +308,11 @@ $(document).ready(function () {
// The xhr.dt event occurs whenever new json data is loaded
.on('xhr.dt', function (event, settings, json, xhr) {
scanData = new ScanData(json);
//Fixing jsTreeData
for(var i=0;i<scanData.jsTreeData.length;i++){
scanData.jsTreeData[i].type = scanData.jsTreeData[i].scanData.type
}
//Sorting the nodes so files come on top

// loading data into jstree
jstree.jstree(true).settings.core.data = scanData.jsTreeData;
Expand Down Expand Up @@ -418,4 +442,4 @@ $(document).ready(function () {
// Make node view modal box draggable
$("#nodeModal").draggable({ handle: ".modal-header" });

});
});