UNPKG

@nova-ui/dashboards

Version:

Nova Dashboards is a framework designed to provide feature developers with a common solution for presenting data coming from various sources within a single view, as well as a set of predefined widget visualizations that are 100% configuration-driven and

168 lines 7.08 kB
"use strict"; // © 2022 SolarWinds Worldwide, LLC. All rights reserved. // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. Object.defineProperty(exports, "__esModule", { value: true }); exports.GroupingConfigurationComponent = void 0; const tslib_1 = require("tslib"); const core_1 = require("@angular/core"); const forms_1 = require("@angular/forms"); const difference_1 = tslib_1.__importDefault(require("lodash/difference")); const rxjs_1 = require("rxjs"); const operators_1 = require("rxjs/operators"); const bits_1 = require("@nova-ui/bits"); const types_1 = require("../../../../../types"); const types_2 = require("../../../../types"); let GroupingConfigurationComponent = class GroupingConfigurationComponent { static { this.lateLoadKey = "DrilldownConfiguratorComponent"; } constructor(changeDetector, formBuilder, eventBus) { this.changeDetector = changeDetector; this.formBuilder = formBuilder; this.eventBus = eventBus; this.formReady = new core_1.EventEmitter(); this.form = this.formBuilder.group({ groups: [], groupBy: this.formBuilder.array([]), drillstate: [undefined], }); this.destroy$ = new rxjs_1.Subject(); } get getGroupByControl() { return this.form.get("groupBy"); } get getDrillStateControl() { return this.form.get("drillstate"); } get getGroupsControl() { return this.form.get("groups"); } ngOnInit() { this.eventBus .getStream(types_2.DATA_SOURCE_CREATED) .pipe((0, operators_1.takeUntil)(this.destroy$)) .subscribe((provider) => this.onDataSourceCreated(provider)); this.getGroupByControl.valueChanges .pipe((0, operators_1.takeUntil)(this.destroy$)) .subscribe(() => this.fillGroupsOptions()); this.fillGroupsOptions(); this.formReady.emit(this.form); } ngOnChanges(changes) { if (changes.groups) { this.getGroupsControl.setValue(changes.groups.currentValue); } if (changes.groupBy && !changes.groupBy.firstChange) { this.getGroupByControl.clear(); this.groupBy.forEach((group) => this.getGroupByControl.push(this.createControl(group))); this.fillGroupsOptions(); } } createControl(value) { return this.formBuilder.control(value || "", forms_1.Validators.required); } addGrouping() { const control = this.createControl(); this.getGroupByControl.push(control); this.fillGroupsOptions(); const lastControlIndex = this.getGroupByControl.controls.length - 1; control.setValue(this.selectData[lastControlIndex][0]); } removeRule(index) { this.getGroupByControl.removeAt(index); this.fillGroupsOptions(); } isAddRestricted() { return this.selectData.some((i) => i.length === 1); } getSubtitle() { const subtitle = this.getGroupByControl.controls .map((control, index) => `${index === 0 ? "By" : "then"} ${control.value}`) .join(", "); return this.getGroupByControl?.value.length === 0 ? $localize `No groups` : $localize `${subtitle}`; } ngOnDestroy() { this.destroy$.next(); this.destroy$.complete(); } onDataSourceCreated(provider) { provider?.payload?.dataFieldsConfig?.dataFields$ ?.pipe((0, operators_1.takeUntil)(this.destroy$)) .subscribe((dataFields) => { if (dataFields) { const dataFieldIds = dataFields.map((field) => field.id); const dataDiff = (0, difference_1.default)(this.groups, dataFieldIds); if (dataDiff.length || !this.groups?.length) { this.groups = dataFieldIds; this.getGroupsControl.setValue(dataFieldIds); this.getGroupByControl.clear(); this.getDrillStateControl.setValue([]); this.fillGroupsOptions(); } } }); } fillGroupsOptions() { this.selectData = []; const controlValue = this.getGroupByControl.value; this.getGroupByControl.controls.forEach((value, index) => { this.selectData[index] = []; const diff = (0, difference_1.default)(this.groups, controlValue); if (controlValue[index]) { this.selectData[index].push(controlValue[index]); } this.selectData[index] = [...this.selectData[index], ...diff]; }); } }; exports.GroupingConfigurationComponent = GroupingConfigurationComponent; tslib_1.__decorate([ (0, core_1.Input)(), tslib_1.__metadata("design:type", Array) ], GroupingConfigurationComponent.prototype, "groups", void 0); tslib_1.__decorate([ (0, core_1.Input)(), tslib_1.__metadata("design:type", Array) ], GroupingConfigurationComponent.prototype, "groupBy", void 0); tslib_1.__decorate([ (0, core_1.Output)(), tslib_1.__metadata("design:type", Object) ], GroupingConfigurationComponent.prototype, "formReady", void 0); exports.GroupingConfigurationComponent = GroupingConfigurationComponent = tslib_1.__decorate([ (0, core_1.Component)({ selector: "nui-grouping-configuration", templateUrl: "./grouping-configuration.component.html", changeDetection: core_1.ChangeDetectionStrategy.OnPush, styles: [ ` .grouping-configuration__accordion-content { padding: 15px 15px 15px 46px; } `, ], }) // Remember to declare this class in the parent module , tslib_1.__param(2, (0, core_1.Inject)(types_1.PIZZAGNA_EVENT_BUS)), tslib_1.__metadata("design:paramtypes", [core_1.ChangeDetectorRef, forms_1.FormBuilder, bits_1.EventBus]) ], GroupingConfigurationComponent); //# sourceMappingURL=grouping-configuration.component.js.map