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.83 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.TimeframeSelectionComponent = void 0; const tslib_1 = require("tslib"); const core_1 = require("@angular/core"); const moment_1 = tslib_1.__importDefault(require("moment/moment")); const bits_1 = require("@nova-ui/bits"); const timeframe_serialization_service_1 = require("../../configurator/services/timeframe-serialization.service"); const pizzagna_service_1 = require("../../pizzagna/services/pizzagna.service"); const types_1 = require("../../services/types"); const types_2 = require("../../types"); let TimeframeSelectionComponent = class TimeframeSelectionComponent { static { this.lateLoadKey = "TimeframeSelectionComponent"; } constructor(pizzagnaService, timeframeService, tfSerialization, history, dataSource, eventBus, changeDetector) { this.pizzagnaService = pizzagnaService; this.timeframeService = timeframeService; this.tfSerialization = tfSerialization; this.history = history; this.dataSource = dataSource; this.eventBus = eventBus; this.changeDetector = changeDetector; // just setting the timeframe to some reasonable default value this.currentTimeframe = this.timeframeService.getTimeframeByPresetId("last7Days"); } ngOnChanges(changes) { if (changes.timeframe) { let timeframe = this.tfSerialization.convertFromSerializable(this.timeframe); timeframe = this.timeframeService.reconcileTimeframe(timeframe); if (timeframe.selectedPresetId) { // populate the title timeframe = this.timeframeService.getTimeframeByPresetId(timeframe.selectedPresetId); } this.currentTimeframe = timeframe; if (!changes.timeframe.isFirstChange()) { this.eventBus.getStream(types_1.REFRESH).next({}); } } if (changes.minDate) { this.minDateAsMoment = (0, moment_1.default)(this.minDate, moment_1.default.defaultFormat); } if (changes.maxDate) { this.maxDateAsMoment = (0, moment_1.default)(this.maxDate, moment_1.default.defaultFormat); } } ngOnInit() { this.history.restart(this.currentTimeframe); this.eventBus.getStream(types_1.SET_TIMEFRAME).subscribe((event) => { if (!event.payload) { throw new Error("Unable to set timeframe. Event payload is undefined"); } this.onTimeframeChange(this.history.save(this.tfSerialization.convertFromSerializable(event.payload))); }); if (this.dataSource) { this.dataSource.registerComponent({ timeframe: { componentInstance: { getFilters: () => { const timeframe = this.timeframeService.reconcileTimeframe(this.currentTimeframe); return { type: "timeframe", value: timeframe, }; }, }, }, }); } } onTimeframeChange(timeframe) { const newTimeframe = this.timeframeService.reconcileTimeframe(timeframe); // replace undefined preset value with empty string to explicitly override any value on the pizzagna's config layer newTimeframe.selectedPresetId = newTimeframe.selectedPresetId || ""; if (!this.timeframeService.isEqual(newTimeframe, this.currentTimeframe)) { this.pizzagnaService.setProperty({ pizzagnaKey: types_2.PizzagnaLayer.Data, componentId: this.componentId, propertyPath: ["timeframe"], }, this.tfSerialization.convertToSerializable(newTimeframe)); } } }; exports.TimeframeSelectionComponent = TimeframeSelectionComponent; tslib_1.__decorate([ (0, core_1.Input)(), tslib_1.__metadata("design:type", String) ], TimeframeSelectionComponent.prototype, "componentId", void 0); tslib_1.__decorate([ (0, core_1.Input)(), tslib_1.__metadata("design:type", String) ], TimeframeSelectionComponent.prototype, "minDate", void 0); tslib_1.__decorate([ (0, core_1.Input)(), tslib_1.__metadata("design:type", String) ], TimeframeSelectionComponent.prototype, "maxDate", void 0); tslib_1.__decorate([ (0, core_1.Input)(), tslib_1.__metadata("design:type", Object) ], TimeframeSelectionComponent.prototype, "timeframe", void 0); tslib_1.__decorate([ (0, core_1.HostBinding)("class"), tslib_1.__metadata("design:type", String) ], TimeframeSelectionComponent.prototype, "elementClass", void 0); exports.TimeframeSelectionComponent = TimeframeSelectionComponent = tslib_1.__decorate([ (0, core_1.Component)({ selector: "nui-timeframe-selection", templateUrl: "./timeframe-selection.component.html", styleUrls: ["./timeframe-selection.component.less"], providers: [bits_1.HistoryStorage], standalone: false, }), tslib_1.__param(4, (0, core_1.Optional)()), tslib_1.__param(4, (0, core_1.Inject)(types_2.DATA_SOURCE)), tslib_1.__param(5, (0, core_1.Inject)(types_2.PIZZAGNA_EVENT_BUS)), tslib_1.__metadata("design:paramtypes", [pizzagna_service_1.PizzagnaService, bits_1.TimeframeService, timeframe_serialization_service_1.TimeframeSerializationService, bits_1.HistoryStorage, Object, bits_1.EventBus, core_1.ChangeDetectorRef]) ], TimeframeSelectionComponent); //# sourceMappingURL=timeframe-selection.component.js.map