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

140 lines 6.15 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.PizzagnaComponent = void 0; const tslib_1 = require("tslib"); const core_1 = require("@angular/core"); const bits_1 = require("@nova-ui/bits"); const merge_changes_1 = require("../../../functions/merge-changes"); const types_1 = require("../../../services/types"); const types_2 = require("../../../types"); const dynamic_component_creator_service_1 = require("../../services/dynamic-component-creator.service"); const pizzagna_service_1 = require("../../services/pizzagna.service"); let PizzagnaComponent = class PizzagnaComponent { get pizzagna() { return this._pizzagnaBuffer || this._pizzagna; } set pizzagna(value) { this._pizzagna = value; this._pizzagnaBuffer = null; } constructor(pizzagnaService, logger, eventBus) { this.pizzagnaService = pizzagnaService; this.logger = logger; this.eventBus = eventBus; this.rootNode = types_1.DEFAULT_PIZZAGNA_ROOT; this.pizzagnaChange = new core_1.EventEmitter(); this.output = new core_1.EventEmitter(); eventBus .getStream(types_1.SET_PROPERTY_VALUE) .subscribe((event) => { // TODO: Ensure that payload is defined const p = (0, bits_1.immutableSet)(this.pizzagna, // @ts-ignore: Object is possibly 'undefined'. event.payload.path, // @ts-ignore: Object is possibly 'undefined'. event.payload.value); this._pizzagnaBuffer = p; this.pizzagnaChange.emit(p); }); } ngOnChanges(changes) { if (changes.pizzagna) { const previousPizzagna = changes.pizzagna .previousValue; this.pizzagnaService.updatePizzagna(this.pizzagna); this.pizza = this.mergePizzagnaIntoPizza(this.pizza, previousPizzagna, this.pizzagna); if (this.pizza && !this.pizza[this.rootNode]) { this.logger.warn("Pizzagna doesn't contain root node '" + this.rootNode + "'. Pizzagna = ", this.pizzagna); } this.pizzagnaService.updateComponents(this.pizza); } } onOutput(event) { this.output.emit(event); } /** * This takes all the pizzagna layers and merges them into one component pizza * * @param pizza * @param previousPizzagna * @param currentPizzagna */ mergePizzagnaIntoPizza(pizza, previousPizzagna, currentPizzagna) { return (0, merge_changes_1.mergeChanges)(pizza, // These are merged in reverse priority order so that values in higher priority layers // override the corresponding values in lower priority layers this.getLayerChanges(previousPizzagna, currentPizzagna, types_2.PizzagnaLayer.Structure), this.getLayerChanges(previousPizzagna, currentPizzagna, types_2.PizzagnaLayer.Configuration), this.getLayerChanges(previousPizzagna, currentPizzagna, types_2.PizzagnaLayer.Data)); } getLayerChanges(previous, current, overlayKey) { return { previousValue: this.getLayerSafe(previous, overlayKey), currentValue: this.getLayerSafe(current, overlayKey), }; } getLayerSafe(pizzagna, overlayKey) { return pizzagna && pizzagna[overlayKey]; } }; exports.PizzagnaComponent = PizzagnaComponent; tslib_1.__decorate([ (0, core_1.Input)(), tslib_1.__metadata("design:type", Object) ], PizzagnaComponent.prototype, "rootNode", void 0); tslib_1.__decorate([ (0, core_1.Input)(), tslib_1.__metadata("design:type", Object), tslib_1.__metadata("design:paramtypes", [Object]) ], PizzagnaComponent.prototype, "pizzagna", null); tslib_1.__decorate([ (0, core_1.Input)(), tslib_1.__metadata("design:type", Array) ], PizzagnaComponent.prototype, "outputs", void 0); tslib_1.__decorate([ (0, core_1.Output)(), tslib_1.__metadata("design:type", Object) ], PizzagnaComponent.prototype, "pizzagnaChange", void 0); tslib_1.__decorate([ (0, core_1.Output)(), tslib_1.__metadata("design:type", Object) ], PizzagnaComponent.prototype, "output", void 0); exports.PizzagnaComponent = PizzagnaComponent = tslib_1.__decorate([ (0, core_1.Component)({ selector: "nui-pizzagna", templateUrl: "./pizzagna.component.html", providers: [ pizzagna_service_1.PizzagnaService, dynamic_component_creator_service_1.DynamicComponentCreator, { provide: types_2.PIZZAGNA_EVENT_BUS, useClass: bits_1.EventBus, }, ], standalone: false, }), tslib_1.__param(2, (0, core_1.Inject)(types_2.PIZZAGNA_EVENT_BUS)), tslib_1.__metadata("design:paramtypes", [pizzagna_service_1.PizzagnaService, bits_1.LoggerService, bits_1.EventBus]) ], PizzagnaComponent); //# sourceMappingURL=pizzagna.component.js.map