organizationchart.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. "use strict";
  2. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  3. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  4. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  5. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  6. return c > 3 && r && Object.defineProperty(target, key, r), r;
  7. };
  8. var __metadata = (this && this.__metadata) || function (k, v) {
  9. if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
  10. };
  11. var __param = (this && this.__param) || function (paramIndex, decorator) {
  12. return function (target, key) { decorator(target, key, paramIndex); }
  13. };
  14. Object.defineProperty(exports, "__esModule", { value: true });
  15. var core_1 = require("@angular/core");
  16. var animations_1 = require("@angular/animations");
  17. var common_1 = require("@angular/common");
  18. var shared_1 = require("../common/shared");
  19. var shared_2 = require("../common/shared");
  20. var OrganizationChartNode = /** @class */ (function () {
  21. function OrganizationChartNode(chart) {
  22. this.chart = chart;
  23. }
  24. Object.defineProperty(OrganizationChartNode.prototype, "leaf", {
  25. get: function () {
  26. return this.node.leaf == false ? false : !(this.node.children && this.node.children.length);
  27. },
  28. enumerable: true,
  29. configurable: true
  30. });
  31. Object.defineProperty(OrganizationChartNode.prototype, "colspan", {
  32. get: function () {
  33. return (this.node.children && this.node.children.length) ? this.node.children.length * 2 : null;
  34. },
  35. enumerable: true,
  36. configurable: true
  37. });
  38. OrganizationChartNode.prototype.onNodeClick = function (event, node) {
  39. this.chart.onNodeClick(event, node);
  40. };
  41. OrganizationChartNode.prototype.toggleNode = function (event, node) {
  42. node.expanded = !node.expanded;
  43. if (node.expanded)
  44. this.chart.onNodeExpand.emit({ originalEvent: event, node: this.node });
  45. else
  46. this.chart.onNodeCollapse.emit({ originalEvent: event, node: this.node });
  47. event.preventDefault();
  48. };
  49. OrganizationChartNode.prototype.isSelected = function () {
  50. return this.chart.isSelected(this.node);
  51. };
  52. __decorate([
  53. core_1.Input(),
  54. __metadata("design:type", Object)
  55. ], OrganizationChartNode.prototype, "node", void 0);
  56. __decorate([
  57. core_1.Input(),
  58. __metadata("design:type", Boolean)
  59. ], OrganizationChartNode.prototype, "root", void 0);
  60. __decorate([
  61. core_1.Input(),
  62. __metadata("design:type", Boolean)
  63. ], OrganizationChartNode.prototype, "first", void 0);
  64. __decorate([
  65. core_1.Input(),
  66. __metadata("design:type", Boolean)
  67. ], OrganizationChartNode.prototype, "last", void 0);
  68. OrganizationChartNode = __decorate([
  69. core_1.Component({
  70. selector: '[pOrganizationChartNode]',
  71. template: "\n <tr *ngIf=\"node\">\n <td [attr.colspan]=\"colspan\">\n <div class=\"ui-organizationchart-node-content ui-widget-content ui-corner-all {{node.styleClass}}\" \n [ngClass]=\"{'ui-organizationchart-selectable-node': chart.selectionMode && node.selectable !== false,'ui-state-highlight':isSelected()}\"\n (click)=\"onNodeClick($event,node)\">\n <div *ngIf=\"!chart.getTemplateForNode(node)\">{{node.label}}</div>\n <div *ngIf=\"chart.getTemplateForNode(node)\">\n <ng-container *ngTemplateOutlet=\"chart.getTemplateForNode(node); context: {$implicit: node}\"></ng-container>\n </div>\n <a *ngIf=\"!leaf\" tabindex=\"0\" class=\"ui-node-toggler\" (click)=\"toggleNode($event, node)\" (keydown.enter)=\"toggleNode($event, node)\">\n <i class=\"ui-node-toggler-icon pi\" [ngClass]=\"{'pi-chevron-down': node.expanded, 'pi-chevron-up': !node.expanded}\"></i>\n </a>\n </div>\n </td>\n </tr>\n <tr [style.visibility]=\"!leaf&&node.expanded ? 'inherit' : 'hidden'\" class=\"ui-organizationchart-lines\" [@childState]=\"'in'\">\n <td [attr.colspan]=\"colspan\">\n <div class=\"ui-organizationchart-line-down\"></div>\n </td>\n </tr>\n <tr [style.visibility]=\"!leaf&&node.expanded ? 'inherit' : 'hidden'\" class=\"ui-organizationchart-lines\" [@childState]=\"'in'\">\n <ng-container *ngIf=\"node.children && node.children.length === 1\">\n <td [attr.colspan]=\"colspan\">\n <div class=\"ui-organizationchart-line-down\"></div>\n </td>\n </ng-container>\n <ng-container *ngIf=\"node.children && node.children.length > 1\">\n <ng-template ngFor let-child [ngForOf]=\"node.children\" let-first=\"first\" let-last=\"last\">\n <td class=\"ui-organizationchart-line-left\" [ngClass]=\"{'ui-organizationchart-line-top':!first}\">&nbsp;</td>\n <td class=\"ui-organizationchart-line-right\" [ngClass]=\"{'ui-organizationchart-line-top':!last}\">&nbsp;</td>\n </ng-template>\n </ng-container>\n </tr>\n <tr [style.visibility]=\"!leaf&&node.expanded ? 'inherit' : 'hidden'\" class=\"ui-organizationchart-nodes\" [@childState]=\"'in'\">\n <td *ngFor=\"let child of node.children\" colspan=\"2\">\n <table class=\"ui-organizationchart-table\" pOrganizationChartNode [node]=\"child\"></table>\n </td>\n </tr>\n ",
  72. animations: [
  73. animations_1.trigger('childState', [
  74. animations_1.state('in', animations_1.style({ opacity: 1 })),
  75. animations_1.transition('void => *', [
  76. animations_1.style({ opacity: 0 }),
  77. animations_1.animate(150)
  78. ]),
  79. animations_1.transition('* => void', [
  80. animations_1.animate(150, animations_1.style({ opacity: 0 }))
  81. ])
  82. ])
  83. ]
  84. }),
  85. __param(0, core_1.Inject(core_1.forwardRef(function () { return OrganizationChart; }))),
  86. __metadata("design:paramtypes", [Object])
  87. ], OrganizationChartNode);
  88. return OrganizationChartNode;
  89. }());
  90. exports.OrganizationChartNode = OrganizationChartNode;
  91. var OrganizationChart = /** @class */ (function () {
  92. function OrganizationChart(el) {
  93. this.el = el;
  94. this.selectionChange = new core_1.EventEmitter();
  95. this.onNodeSelect = new core_1.EventEmitter();
  96. this.onNodeUnselect = new core_1.EventEmitter();
  97. this.onNodeExpand = new core_1.EventEmitter();
  98. this.onNodeCollapse = new core_1.EventEmitter();
  99. }
  100. Object.defineProperty(OrganizationChart.prototype, "root", {
  101. get: function () {
  102. return this.value && this.value.length ? this.value[0] : null;
  103. },
  104. enumerable: true,
  105. configurable: true
  106. });
  107. OrganizationChart.prototype.ngAfterContentInit = function () {
  108. var _this = this;
  109. if (this.templates.length) {
  110. this.templateMap = {};
  111. }
  112. this.templates.forEach(function (item) {
  113. _this.templateMap[item.getType()] = item.template;
  114. });
  115. };
  116. OrganizationChart.prototype.getTemplateForNode = function (node) {
  117. if (this.templateMap)
  118. return node.type ? this.templateMap[node.type] : this.templateMap['default'];
  119. else
  120. return null;
  121. };
  122. OrganizationChart.prototype.onNodeClick = function (event, node) {
  123. var eventTarget = event.target;
  124. if (eventTarget.className && (eventTarget.className.indexOf('ui-node-toggler') !== -1 || eventTarget.className.indexOf('ui-node-toggler-icon') !== -1)) {
  125. return;
  126. }
  127. else if (this.selectionMode) {
  128. if (node.selectable === false) {
  129. return;
  130. }
  131. var index_1 = this.findIndexInSelection(node);
  132. var selected = (index_1 >= 0);
  133. if (this.selectionMode === 'single') {
  134. if (selected) {
  135. this.selection = null;
  136. this.onNodeUnselect.emit({ originalEvent: event, node: node });
  137. }
  138. else {
  139. this.selection = node;
  140. this.onNodeSelect.emit({ originalEvent: event, node: node });
  141. }
  142. }
  143. else if (this.selectionMode === 'multiple') {
  144. if (selected) {
  145. this.selection = this.selection.filter(function (val, i) { return i != index_1; });
  146. this.onNodeUnselect.emit({ originalEvent: event, node: node });
  147. }
  148. else {
  149. this.selection = (this.selection || []).concat([node]);
  150. this.onNodeSelect.emit({ originalEvent: event, node: node });
  151. }
  152. }
  153. this.selectionChange.emit(this.selection);
  154. }
  155. };
  156. OrganizationChart.prototype.findIndexInSelection = function (node) {
  157. var index = -1;
  158. if (this.selectionMode && this.selection) {
  159. if (this.selectionMode === 'single') {
  160. index = (this.selection == node) ? 0 : -1;
  161. }
  162. else if (this.selectionMode === 'multiple') {
  163. for (var i = 0; i < this.selection.length; i++) {
  164. if (this.selection[i] == node) {
  165. index = i;
  166. break;
  167. }
  168. }
  169. }
  170. }
  171. return index;
  172. };
  173. OrganizationChart.prototype.isSelected = function (node) {
  174. return this.findIndexInSelection(node) != -1;
  175. };
  176. __decorate([
  177. core_1.Input(),
  178. __metadata("design:type", Array)
  179. ], OrganizationChart.prototype, "value", void 0);
  180. __decorate([
  181. core_1.Input(),
  182. __metadata("design:type", Object)
  183. ], OrganizationChart.prototype, "style", void 0);
  184. __decorate([
  185. core_1.Input(),
  186. __metadata("design:type", String)
  187. ], OrganizationChart.prototype, "styleClass", void 0);
  188. __decorate([
  189. core_1.Input(),
  190. __metadata("design:type", String)
  191. ], OrganizationChart.prototype, "selectionMode", void 0);
  192. __decorate([
  193. core_1.Input(),
  194. __metadata("design:type", Object)
  195. ], OrganizationChart.prototype, "selection", void 0);
  196. __decorate([
  197. core_1.Output(),
  198. __metadata("design:type", core_1.EventEmitter)
  199. ], OrganizationChart.prototype, "selectionChange", void 0);
  200. __decorate([
  201. core_1.Output(),
  202. __metadata("design:type", core_1.EventEmitter)
  203. ], OrganizationChart.prototype, "onNodeSelect", void 0);
  204. __decorate([
  205. core_1.Output(),
  206. __metadata("design:type", core_1.EventEmitter)
  207. ], OrganizationChart.prototype, "onNodeUnselect", void 0);
  208. __decorate([
  209. core_1.Output(),
  210. __metadata("design:type", core_1.EventEmitter)
  211. ], OrganizationChart.prototype, "onNodeExpand", void 0);
  212. __decorate([
  213. core_1.Output(),
  214. __metadata("design:type", core_1.EventEmitter)
  215. ], OrganizationChart.prototype, "onNodeCollapse", void 0);
  216. __decorate([
  217. core_1.ContentChildren(shared_2.PrimeTemplate),
  218. __metadata("design:type", core_1.QueryList)
  219. ], OrganizationChart.prototype, "templates", void 0);
  220. OrganizationChart = __decorate([
  221. core_1.Component({
  222. selector: 'p-organizationChart',
  223. template: "\n <div [ngStyle]=\"style\" [class]=\"styleClass\" [ngClass]=\"'ui-organizationchart ui-widget'\">\n <table class=\"ui-organizationchart-table\" pOrganizationChartNode [node]=\"root\" *ngIf=\"root\"></table>\n </div>\n "
  224. }),
  225. __metadata("design:paramtypes", [core_1.ElementRef])
  226. ], OrganizationChart);
  227. return OrganizationChart;
  228. }());
  229. exports.OrganizationChart = OrganizationChart;
  230. var OrganizationChartModule = /** @class */ (function () {
  231. function OrganizationChartModule() {
  232. }
  233. OrganizationChartModule = __decorate([
  234. core_1.NgModule({
  235. imports: [common_1.CommonModule],
  236. exports: [OrganizationChart, shared_1.SharedModule],
  237. declarations: [OrganizationChart, OrganizationChartNode]
  238. })
  239. ], OrganizationChartModule);
  240. return OrganizationChartModule;
  241. }());
  242. exports.OrganizationChartModule = OrganizationChartModule;
  243. //# sourceMappingURL=organizationchart.js.map