-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e0492a6
commit 21c2cec
Showing
6 changed files
with
127 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
client/app/components/request-workflow/tags-tree.component.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
(function() { | ||
'use strict'; | ||
|
||
angular.module('app.components') | ||
.component('tagsTree', { | ||
bindings: { | ||
allowedTags: '=?', | ||
vmTags: '=?', | ||
}, | ||
controller: tagsTreeController, | ||
controllerAs: 'vm', | ||
templateUrl: 'app/components/request-workflow/tags-tree.html', | ||
}); | ||
|
||
/** @ngInject */ | ||
function tagsTreeController(API_BASE, lodash) { | ||
var vm = this; | ||
vm.customizedAllowedTags = lodash.cloneDeep(vm.allowedTags); | ||
vm.$onInit = link; | ||
|
||
vm.API_BASE = API_BASE; | ||
|
||
function link(scope, element, attrs) { | ||
angular.element('#tagsTree').treeview({ | ||
collapseIcon: "fa fa-angle-down", | ||
data: getTreeNodes(), | ||
levels: 2, | ||
expandIcon: "fa fa-angle-right", | ||
nodeIcon: "fa fa-folder", | ||
showBorder: false, | ||
}); | ||
} | ||
|
||
// Private functions | ||
function getTreeNodes() { | ||
lodash.forEach(vm.customizedAllowedTags, function(obj, key) { | ||
obj.text = obj.description + " *"; | ||
obj.nodes = []; | ||
lodash.forEach(obj.children, function(child, key) { | ||
var id = child[0]; | ||
child = lodash.reduce(child, function(collection, current) { | ||
return lodash.extend(collection, current) | ||
}, {}); | ||
|
||
child.id = id; | ||
child.text = child.description; | ||
delete child.description; | ||
obj.nodes.push(child); | ||
}); | ||
|
||
adjustVmTagMatchedNodes(obj, vm.vmTags); | ||
}); | ||
|
||
lodash.remove(vm.customizedAllowedTags, function(obj) { | ||
return obj.markedForDeletion === true; | ||
}); | ||
|
||
return vm.customizedAllowedTags; | ||
} | ||
|
||
function adjustVmTagMatchedNodes(object, vmTags) { | ||
var childIds = lodash.map(object.nodes, 'id'); | ||
var commonNode = lodash.intersection(childIds, vmTags); | ||
|
||
if (commonNode.length === 0) { | ||
object.markedForDeletion = true; | ||
} else { | ||
object.nodes = [lodash.find(object.nodes, {id: commonNode[0]})]; | ||
} | ||
} | ||
|
||
function onNodeExpanded(event, node) { | ||
if (node.nodes) { | ||
var nodeToExpand = onlyOneExpandableChild(node.nodes); | ||
if (nodeToExpand) { | ||
angular.element('#tagsTree').treeview('expandNode', [nodeToExpand]); | ||
} | ||
} | ||
} | ||
|
||
function onlyOneExpandableChild(nodes) { | ||
var expandableNodeCount = 0; | ||
var lastExpandableNode; | ||
|
||
for (var i = 0; i < nodes.length; i++) { | ||
var node = nodes[i]; | ||
if (node.nodes) { | ||
expandableNodeCount++; | ||
lastExpandableNode = node; | ||
} | ||
} | ||
|
||
if (expandableNodeCount === 1) { | ||
return lastExpandableNode; | ||
} else { | ||
return null; | ||
} | ||
} | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<style> | ||
.treeview .list-group-item { | ||
cursor: pointer !important; | ||
} | ||
.treeview .list-group-item.node-selected { | ||
background-color: #428bca !important; | ||
} | ||
</style> | ||
<div> | ||
<div id="tagsTree"></div> | ||
</div> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters