├── .gitignore ├── bower.json ├── dist ├── tree-view.js └── tree-view.min.js ├── example ├── index.html ├── script.js ├── style.css └── style.scss ├── gruntfile.js ├── package.json ├── readme.md ├── tree-view-directive.js └── tree-view-service.js /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/* 2 | node_modules 3 | .plugin 4 | .metadata/* -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bootstrap-ui-treeview", 3 | "version": "3.0.2", 4 | "homepage": "https://github.com/Gillardo/bootstrap-ui-treeview", 5 | "authors": [ 6 | "Gillardo " 7 | ], 8 | "description": "AngularJs directive to show a treeview like structure of an item. Uses the bootstrap-UI collapse directive for a nice sliding animation, also includes a TreeViewService to access the treeview from another controller/directive/service", 9 | "main": [ 10 | "dist/tree-view.min.js" 11 | ], 12 | "keywords": [ 13 | "tree-view", 14 | "angular", 15 | "bootstrap", 16 | "angular-ui" 17 | ], 18 | "license": "MIT", 19 | "ignore": [ 20 | "**/.*", 21 | "node_modules", 22 | "bower_components", 23 | "test", 24 | "template", 25 | "/tree-view-directive.js", 26 | "/tree-view-service.js", 27 | "gruntfile.js", 28 | "package.json", 29 | "tests" 30 | ] 31 | } 32 | -------------------------------------------------------------------------------- /dist/tree-view.js: -------------------------------------------------------------------------------- 1 | // https://github.com/Gillardo/bootstrap-ui-treeview 2 | // Version: 3.0.2 3 | // Released: 2016-05-19 4 | angular.module('ui.bootstrap.treeview', []).factory('TreeViewService', function () { 5 | function TreeViewService() { 6 | var that = this; 7 | 8 | this.nodes = []; 9 | this.selectedNode = undefined; 10 | this.collapsed = []; 11 | 12 | // will search all nodes for this node, and expand each parent node 13 | this.collapseTo = function(node) { 14 | 15 | function iterate(list) { 16 | 17 | for (var i = 0; i < list.length; i++) { 18 | var found = false; 19 | 20 | if (list[i] == node) { 21 | found = true; 22 | } else if (angular.isDefined(list[i].children)) { 23 | found = iterate(list[i].children); 24 | } 25 | 26 | if (found == true) { 27 | that.collapsed.push(list[i]); 28 | return true; 29 | } 30 | } 31 | 32 | return false; 33 | } 34 | 35 | iterate(that.nodes); 36 | }; 37 | } 38 | 39 | return TreeViewService; 40 | }); 41 | 42 | angular.module('ui.bootstrap.treeview').directive('treeView', ['$compile', '$templateCache', function ($compile, $templateCache) { 43 | return { 44 | restrict: 'E', 45 | scope: {}, 46 | bindToController: { 47 | treeService: '=' 48 | }, 49 | controller: function () { 50 | 51 | var that = this; 52 | 53 | this.isCollapsed = function(node) { 54 | return that.treeService.collapsed.indexOf(node) > -1; 55 | }; 56 | 57 | // toggle when icon clicked 58 | this.toggleNode = function (node) { 59 | 60 | if (!node.children) return; 61 | 62 | // collapse / expand 63 | if (node.children && node.children.length > 0) { 64 | // add the node to our collapsed array 65 | var index = that.treeService.collapsed.indexOf(node); 66 | 67 | if (index == -1) 68 | that.treeService.collapsed.push(node); 69 | else 70 | that.treeService.collapsed.splice(index, 1); 71 | } 72 | }; 73 | 74 | // select when name clicked 75 | this.selectNode = function (e, node) { 76 | that.treeService.selectedNode = node; 77 | 78 | e.stopPropagation(); 79 | e.preventDefault(); 80 | }; 81 | }, 82 | controllerAs: 'ctrl', 83 | link: function (scope, element, attrs, ctrl) { 84 | var isRoot = (!attrs.treeRoot ? true : false); 85 | var nodeLabel = attrs.nodeLabel || 'label'; 86 | var itemClass = attrs.itemClass || ''; 87 | var itemInclude = attrs.itemNgInclude || ''; 88 | var itemIncludeHtml = ''; 89 | var emptyTreeMessage = attrs.emptyTreeMessage || 'No items to display'; 90 | var emptyTreeClass = attrs.emptyTreeClass || 'alert alert-info'; 91 | 92 | if (itemInclude && itemInclude.length > 0) { 93 | itemIncludeHtml = $templateCache.get(attrs.itemNgInclude); 94 | } 95 | 96 | // remove attributes 97 | element.removeAttr('node-label'); 98 | element.removeAttr('item-class'); 99 | element.removeAttr('item-ng-include'); 100 | element.removeAttr('tree-root'); 101 | 102 | // template 103 | var template = ''; 104 | 105 | if (!isRoot) 106 | template = '