UNPKG

primeng

Version:

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![npm version](https://badge.fury.io/js/primeng.svg)](https://badge.fury.io/js/primeng) [![Build Status](https://travis-ci.org/primefaces/primeng.

261 lines (257 loc) 10.8 kB
import { Inject, forwardRef, Input, Component, EventEmitter, ElementRef, Output, ContentChildren, ChangeDetectionStrategy, NgModule } from '@angular/core'; import { trigger, state, style, transition, animate } from '@angular/animations'; import { CommonModule } from '@angular/common'; import { PrimeTemplate, SharedModule } from 'primeng/api'; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 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; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; let OrganizationChartNode = class OrganizationChartNode { constructor(chart) { this.chart = chart; } get leaf() { return this.node.leaf == false ? false : !(this.node.children && this.node.children.length); } get colspan() { return (this.node.children && this.node.children.length) ? this.node.children.length * 2 : null; } onNodeClick(event, node) { this.chart.onNodeClick(event, node); } toggleNode(event, node) { node.expanded = !node.expanded; if (node.expanded) this.chart.onNodeExpand.emit({ originalEvent: event, node: this.node }); else this.chart.onNodeCollapse.emit({ originalEvent: event, node: this.node }); event.preventDefault(); } isSelected() { return this.chart.isSelected(this.node); } }; OrganizationChartNode.ctorParameters = () => [ { type: undefined, decorators: [{ type: Inject, args: [forwardRef(() => OrganizationChart),] }] } ]; __decorate([ Input() ], OrganizationChartNode.prototype, "node", void 0); __decorate([ Input() ], OrganizationChartNode.prototype, "root", void 0); __decorate([ Input() ], OrganizationChartNode.prototype, "first", void 0); __decorate([ Input() ], OrganizationChartNode.prototype, "last", void 0); OrganizationChartNode = __decorate([ Component({ selector: '[pOrganizationChartNode]', template: ` <tr *ngIf="node"> <td [attr.colspan]="colspan"> <div class="ui-organizationchart-node-content ui-widget-content ui-corner-all {{node.styleClass}}" [ngClass]="{'ui-organizationchart-selectable-node': chart.selectionMode && node.selectable !== false,'ui-state-highlight':isSelected()}" (click)="onNodeClick($event,node)"> <div *ngIf="!chart.getTemplateForNode(node)">{{node.label}}</div> <div *ngIf="chart.getTemplateForNode(node)"> <ng-container *ngTemplateOutlet="chart.getTemplateForNode(node); context: {$implicit: node}"></ng-container> </div> <a *ngIf="!leaf" tabindex="0" class="ui-node-toggler" (click)="toggleNode($event, node)" (keydown.enter)="toggleNode($event, node)"> <i class="ui-node-toggler-icon pi" [ngClass]="{'pi-chevron-down': node.expanded, 'pi-chevron-up': !node.expanded}"></i> </a> </div> </td> </tr> <tr [ngClass]="!leaf&&node.expanded ? 'ui-organizationchart-node-visible' : 'ui-organizationchart-node-hidden'" class="ui-organizationchart-lines" [@childState]="'in'"> <td [attr.colspan]="colspan"> <div class="ui-organizationchart-line-down"></div> </td> </tr> <tr [ngClass]="!leaf&&node.expanded ? 'ui-organizationchart-node-visible' : 'ui-organizationchart-node-hidden'" class="ui-organizationchart-lines" [@childState]="'in'"> <ng-container *ngIf="node.children && node.children.length === 1"> <td [attr.colspan]="colspan"> <div class="ui-organizationchart-line-down"></div> </td> </ng-container> <ng-container *ngIf="node.children && node.children.length > 1"> <ng-template ngFor let-child [ngForOf]="node.children" let-first="first" let-last="last"> <td class="ui-organizationchart-line-left" [ngClass]="{'ui-organizationchart-line-top':!first}">&nbsp;</td> <td class="ui-organizationchart-line-right" [ngClass]="{'ui-organizationchart-line-top':!last}">&nbsp;</td> </ng-template> </ng-container> </tr> <tr [ngClass]="!leaf&&node.expanded ? 'ui-organizationchart-node-visible' : 'ui-organizationchart-node-hidden'" class="ui-organizationchart-nodes" [@childState]="'in'"> <td *ngFor="let child of node.children" colspan="2"> <table class="ui-organizationchart-table" pOrganizationChartNode [node]="child"></table> </td> </tr> `, animations: [ trigger('childState', [ state('in', style({ opacity: 1 })), transition('void => *', [ style({ opacity: 0 }), animate(150) ]), transition('* => void', [ animate(150, style({ opacity: 0 })) ]) ]) ] }), __param(0, Inject(forwardRef(() => OrganizationChart))) ], OrganizationChartNode); let OrganizationChart = class OrganizationChart { constructor(el) { this.el = el; this.preserveSpace = true; this.selectionChange = new EventEmitter(); this.onNodeSelect = new EventEmitter(); this.onNodeUnselect = new EventEmitter(); this.onNodeExpand = new EventEmitter(); this.onNodeCollapse = new EventEmitter(); } get root() { return this.value && this.value.length ? this.value[0] : null; } ngAfterContentInit() { if (this.templates.length) { this.templateMap = {}; } this.templates.forEach((item) => { this.templateMap[item.getType()] = item.template; }); } getTemplateForNode(node) { if (this.templateMap) return node.type ? this.templateMap[node.type] : this.templateMap['default']; else return null; } onNodeClick(event, node) { let eventTarget = event.target; if (eventTarget.className && (eventTarget.className.indexOf('ui-node-toggler') !== -1 || eventTarget.className.indexOf('ui-node-toggler-icon') !== -1)) { return; } else if (this.selectionMode) { if (node.selectable === false) { return; } let index = this.findIndexInSelection(node); let selected = (index >= 0); if (this.selectionMode === 'single') { if (selected) { this.selection = null; this.onNodeUnselect.emit({ originalEvent: event, node: node }); } else { this.selection = node; this.onNodeSelect.emit({ originalEvent: event, node: node }); } } else if (this.selectionMode === 'multiple') { if (selected) { this.selection = this.selection.filter((val, i) => i != index); this.onNodeUnselect.emit({ originalEvent: event, node: node }); } else { this.selection = [...this.selection || [], node]; this.onNodeSelect.emit({ originalEvent: event, node: node }); } } this.selectionChange.emit(this.selection); } } findIndexInSelection(node) { let index = -1; if (this.selectionMode && this.selection) { if (this.selectionMode === 'single') { index = (this.selection == node) ? 0 : -1; } else if (this.selectionMode === 'multiple') { for (let i = 0; i < this.selection.length; i++) { if (this.selection[i] == node) { index = i; break; } } } } return index; } isSelected(node) { return this.findIndexInSelection(node) != -1; } }; OrganizationChart.ctorParameters = () => [ { type: ElementRef } ]; __decorate([ Input() ], OrganizationChart.prototype, "value", void 0); __decorate([ Input() ], OrganizationChart.prototype, "style", void 0); __decorate([ Input() ], OrganizationChart.prototype, "styleClass", void 0); __decorate([ Input() ], OrganizationChart.prototype, "selectionMode", void 0); __decorate([ Input() ], OrganizationChart.prototype, "selection", void 0); __decorate([ Input() ], OrganizationChart.prototype, "preserveSpace", void 0); __decorate([ Output() ], OrganizationChart.prototype, "selectionChange", void 0); __decorate([ Output() ], OrganizationChart.prototype, "onNodeSelect", void 0); __decorate([ Output() ], OrganizationChart.prototype, "onNodeUnselect", void 0); __decorate([ Output() ], OrganizationChart.prototype, "onNodeExpand", void 0); __decorate([ Output() ], OrganizationChart.prototype, "onNodeCollapse", void 0); __decorate([ ContentChildren(PrimeTemplate) ], OrganizationChart.prototype, "templates", void 0); OrganizationChart = __decorate([ Component({ selector: 'p-organizationChart', template: ` <div [ngStyle]="style" [class]="styleClass" [ngClass]="{'ui-organizationchart ui-widget': true, 'ui-organizationchart-preservespace': preserveSpace}"> <table class="ui-organizationchart-table" pOrganizationChartNode [node]="root" *ngIf="root"></table> </div> `, changeDetection: ChangeDetectionStrategy.Default }) ], OrganizationChart); let OrganizationChartModule = class OrganizationChartModule { }; OrganizationChartModule = __decorate([ NgModule({ imports: [CommonModule], exports: [OrganizationChart, SharedModule], declarations: [OrganizationChart, OrganizationChartNode] }) ], OrganizationChartModule); /** * Generated bundle index. Do not edit. */ export { OrganizationChart, OrganizationChartModule, OrganizationChartNode }; //# sourceMappingURL=primeng-organizationchart.js.map