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

133 lines 5.95 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.PizzagnaService = void 0; const tslib_1 = require("tslib"); const core_1 = require("@angular/core"); const isArray_1 = tslib_1.__importDefault(require("lodash/isArray")); const omit_1 = tslib_1.__importDefault(require("lodash/omit")); const rxjs_1 = require("rxjs"); const bits_1 = require("@nova-ui/bits"); const dynamic_component_creator_service_1 = require("./dynamic-component-creator.service"); const types_1 = require("../../services/types"); const types_2 = require("../../types"); const get_pizzagna_property_path_1 = require("../functions/get-pizzagna-property-path"); /** * This service allows pizzagna sub-components to read data of other components and initiate changes of property values */ let PizzagnaService = class PizzagnaService { constructor(eventBus, dynamicComponentCreator) { this.eventBus = eventBus; this.dynamicComponentCreator = dynamicComponentCreator; this.pizzaChanged = new rxjs_1.ReplaySubject(1); } updatePizzagna(pizzagna) { this.pizzagna = pizzagna; } updateComponents(components) { this.components = components; this.pizzaChanged.next(components); } getComponent(refId) { const component = this.components[refId]; if (!component) { throw new Error("Component '" + refId + "' is not defined!"); } return component; } setProperty(property, value) { const path = typeof property === "string" ? property : (0, get_pizzagna_property_path_1.getPizzagnaPropertyPath)(property); this.eventBus .getStream(types_1.SET_PROPERTY_VALUE) .next({ payload: { path, value } }); } createComponentsFromTemplateWithProperties(parentPath, components) { const componentIds = components.map((c) => c.id); let updatedPizzagna = this.dynamicComponentCreator.getPizzagnaUpdatedWithComponents(this.pizzagna, parentPath, componentIds); for (const component of components) { for (const childId of Object.keys(component.children)) { updatedPizzagna = (0, bits_1.immutableSet)(updatedPizzagna, `${types_2.PizzagnaLayer.Data}.${childId}.properties`, component.children[childId]); } } // this is here to update the pizzagna for other converters that need to access the value immediately this.updatePizzagna(updatedPizzagna); this.eventBus.getStream(types_1.SET_PROPERTY_VALUE).next({ payload: { path: "", value: updatedPizzagna, }, }); } createComponentsFromTemplate(parentPath, componentIds) { const updatedPizzagna = this.dynamicComponentCreator.getPizzagnaUpdatedWithComponents(this.pizzagna, parentPath, componentIds); // this is here to update the pizzagna for other converters that need to access the value immediately this.updatePizzagna(updatedPizzagna); this.eventBus.getStream(types_1.SET_PROPERTY_VALUE).next({ payload: { path: "", value: updatedPizzagna, }, }); } removeComponents(ids) { if ((0, isArray_1.default)(ids)) { ids.forEach((id) => this.removeComponent(id)); } else { this.removeComponent(ids); } } removeComponent(id) { const updatedPizzagna = { ...this.pizzagna }; const componentNodes = this.pizzagna[types_2.PizzagnaLayer.Structure][id].properties?.nodes; const componentsToRemove = [id, ...componentNodes]; const layers = [ types_2.PizzagnaLayer.Structure, types_2.PizzagnaLayer.Configuration, types_2.PizzagnaLayer.Data, ]; for (const layer of layers) { if (!updatedPizzagna[layer]) { continue; } for (const component of componentsToRemove) { updatedPizzagna[layer] = (0, omit_1.default)(updatedPizzagna[layer], component); } } this.eventBus.getStream(types_1.SET_PROPERTY_VALUE).next({ payload: { path: "", value: updatedPizzagna, }, }); this.updatePizzagna(updatedPizzagna); } }; exports.PizzagnaService = PizzagnaService; exports.PizzagnaService = PizzagnaService = tslib_1.__decorate([ (0, core_1.Injectable)(), tslib_1.__param(0, (0, core_1.Inject)(types_2.PIZZAGNA_EVENT_BUS)), tslib_1.__metadata("design:paramtypes", [bits_1.EventBus, dynamic_component_creator_service_1.DynamicComponentCreator]) ], PizzagnaService); //# sourceMappingURL=pizzagna.service.js.map