UNPKG

fabric8-planner

Version:
106 lines 3.8 kB
import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output } from '@angular/core'; import { sortBy } from 'lodash'; var TableConfigComponent = /** @class */ (function () { function TableConfigComponent() { this.onMovetoAvailable = new EventEmitter(); this.onMovetoDisplay = new EventEmitter(); } /** * set selected prop true of checked column * @param event native event of checkbox * @param col column object */ TableConfigComponent.prototype.toggleCheckbox = function (event, col) { if (event.target.checked) { col.selected = true; } else { col.selected = false; } }; /** * set display property true of selected cols * shows these column in table */ TableConfigComponent.prototype.moveToDisplay = function () { this.columns.filter(function (col) { return col.selected; }).forEach(function (col) { if (col.display === true) { return; } col.selected = false; col.display = true; col.showInDisplay = true; col.available = false; }); this.updateColumnIndex(); this.onMovetoDisplay.emit(this.columns); }; /** * set available property true and display property false of selected columns * dont show these col in table */ TableConfigComponent.prototype.moveToAvailable = function () { this.columns.filter(function (col) { return col.selected; }).forEach(function (col) { if (col.available === true) { return; } col.selected = false; col.display = false; col.showInDisplay = false; col.available = true; }); this.updateColumnIndex(); this.onMovetoAvailable.emit(this.columns); }; /** * update the index of column with prop display: true * set index undefined for col with prop display: false * i.e. hidden columns */ TableConfigComponent.prototype.updateColumnIndex = function () { var index = 0; this.columns.forEach(function (col) { if (col.display === true) { col.index = index + 1; index += 1; } else { col.index = undefined; } }); this.columns = sortBy(this.columns, 'index'); }; // toggle dropdown based on isTableConfigOpen TableConfigComponent.prototype.tableConfigChange = function (value) { this.isTableConfigOpen = value; }; TableConfigComponent.prototype.tableConfigToggle = function (event) { event.preventDefault(); event.stopPropagation(); this.isTableConfigOpen = false; }; // close dropdown when clicked outside TableConfigComponent.prototype.clickOut = function () { if (this.isTableConfigOpen) { this.isTableConfigOpen = false; } }; TableConfigComponent.decorators = [ { type: Component, args: [{ selector: 'table-config', template: require('./table-config.component.html'), styles: [require('./table-config.component.css').toString()], changeDetection: ChangeDetectionStrategy.OnPush },] }, ]; /** @nocollapse */ TableConfigComponent.ctorParameters = function () { return []; }; TableConfigComponent.propDecorators = { 'columns': [{ type: Input },], 'onMovetoAvailable': [{ type: Output },], 'onMovetoDisplay': [{ type: Output },], }; return TableConfigComponent; }()); export { TableConfigComponent }; //# sourceMappingURL=table-config.component.js.map