@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
104 lines • 5.38 kB
JavaScript
"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.WidgetEditorDirective = void 0;
const tslib_1 = require("tslib");
const core_1 = require("@angular/core");
const cloneDeep_1 = tslib_1.__importDefault(require("lodash/cloneDeep"));
const rxjs_1 = require("rxjs");
// eslint-disable-next-line import/no-deprecated
const operators_1 = require("rxjs/operators");
const dashboard_component_1 = require("../../components/dashboard/dashboard.component");
const widget_editor_service_1 = require("../../configurator/services/widget-editor.service");
const types_1 = require("../../services/types");
const widget_removal_service_1 = require("../../services/widget-removal.service");
const widget_types_service_1 = require("../../services/widget-types.service");
let WidgetEditorDirective = class WidgetEditorDirective {
constructor(dashboardComponent, widgetEditorService, widgetRemovalService, widgetTypesService) {
this.dashboardComponent = dashboardComponent;
this.widgetEditorService = widgetEditorService;
this.widgetRemovalService = widgetRemovalService;
this.widgetTypesService = widgetTypesService;
this.destroy$ = new rxjs_1.Subject();
}
ngOnInit() {
this.dashboardComponent.eventBus
.getStream(types_1.WIDGET_EDIT)
.pipe(
// eslint-disable-next-line import/no-deprecated
(0, operators_1.switchMap)((event) => {
const widget = this.dashboardComponent.dashboard.widgets[event.widgetId];
const widgetType = this.widgetTypesService.getWidgetType(widget.type, widget.version);
// TODO: Ensure that widgetType is defined;
const widgetEditor = {
dashboardComponent: this.dashboardComponent,
// @ts-ignore: Configurator is possibly undefined and is not assignable to IPizzagna type
formPizzagna: widgetType.configurator,
// @ts-ignore: Type 'undefined' is not assignable to type 'Record<string, string>'.
paths: widgetType.paths.configurator,
widget,
trySubmit: this.dashboardPersistenceHandler &&
this.dashboardPersistenceHandler.trySubmit,
};
return this.widgetEditorService.open(widgetEditor);
}), (0, operators_1.takeUntil)(this.destroy$))
.subscribe();
this.dashboardComponent.eventBus
.getStream(types_1.WIDGET_REMOVE)
.pipe(
// eslint-disable-next-line import/no-deprecated
(0, operators_1.switchMap)((event) => {
if (!event.widgetId) {
throw new Error(`event has to have widgetId`);
}
const widgetId = event.widgetId;
const tryRemove = this.dashboardPersistenceHandler &&
this.dashboardPersistenceHandler.tryRemove;
const configuratorSource = {
dashboardComponent: this.dashboardComponent,
widget: (0, cloneDeep_1.default)(this.dashboardComponent.dashboard.widgets[widgetId]),
};
return this.widgetRemovalService.handleRemove(this.dashboardComponent, widgetId, configuratorSource, tryRemove);
}), (0, operators_1.takeUntil)(this.destroy$))
.subscribe();
}
ngOnDestroy() {
this.destroy$.next();
this.destroy$.complete();
}
};
exports.WidgetEditorDirective = WidgetEditorDirective;
tslib_1.__decorate([
(0, core_1.Input)("nuiWidgetEditor"),
tslib_1.__metadata("design:type", Object)
], WidgetEditorDirective.prototype, "dashboardPersistenceHandler", void 0);
exports.WidgetEditorDirective = WidgetEditorDirective = tslib_1.__decorate([
(0, core_1.Directive)({
selector: "[nuiWidgetEditor]",
}),
tslib_1.__param(0, (0, core_1.Host)()),
tslib_1.__param(0, (0, core_1.Self)()),
tslib_1.__metadata("design:paramtypes", [dashboard_component_1.DashboardComponent,
widget_editor_service_1.WidgetEditorService,
widget_removal_service_1.WidgetRemovalService,
widget_types_service_1.WidgetTypesService])
], WidgetEditorDirective);
//# sourceMappingURL=widget-editor.directive.js.map