@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
156 lines • 7.04 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.
var WidgetEditorComponent_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.WidgetEditorComponent = void 0;
const tslib_1 = require("tslib");
const core_1 = require("@angular/core");
const forms_1 = require("@angular/forms");
const get_1 = tslib_1.__importDefault(require("lodash/get"));
const rxjs_1 = require("rxjs");
const operators_1 = require("rxjs/operators");
const pizzagna_component_1 = require("../../../pizzagna/components/pizzagna/pizzagna.component");
const types_1 = require("../../../services/types");
const types_2 = require("../../../types");
const preview_service_1 = require("../../services/preview.service");
const configurator_component_1 = require("../configurator/configurator.component");
let WidgetEditorComponent = class WidgetEditorComponent {
static { WidgetEditorComponent_1 = this; }
static { this.lateLoadKey = "WidgetEditorComponent"; }
static { this.TITLE_PATH = "header.properties.title"; }
set formPizzagnaComponent(value) {
value?.eventBus
?.getStream(types_1.PREVIEW_EVENT)
.pipe((0, operators_1.takeUntil)(this.destroy$))
.subscribe((event) => {
const payload = event.payload;
if (payload && payload.id) {
this.configurator?.previewPizzagnaComponent?.eventBus
?.getStream(payload.id)
.next(payload.payload);
}
});
this._formPizzagnaComponent = value;
}
constructor(changeDetector, formBuilder, previewService, configurator) {
this.changeDetector = changeDetector;
this.formBuilder = formBuilder;
this.previewService = previewService;
this.configurator = configurator;
this.navigationControl = new rxjs_1.BehaviorSubject({
busyState: { busy: false },
allowStepChange: true,
});
this.busy = false;
this.destroy$ = new rxjs_1.Subject();
this.form = this.formBuilder.group({});
}
ngOnInit() {
// TODO: Reconsider this
// @ts-ignore: We can depend on preview being undefined somewhere
this.previewService.preview =
this.configurator.previewWidget?.pizzagna[types_2.PizzagnaLayer.Configuration];
this.previewService.previewChanged
.pipe((0, operators_1.takeUntil)(this.destroy$))
.subscribe((pizzagna) => {
this.onPreviewPizzagnaUpdate(pizzagna);
this.changeDetector.detectChanges();
});
this.configurator.submitError
.pipe((0, operators_1.takeUntil)(this.destroy$))
.subscribe(() => {
this.toggleBusy();
});
this.changeDetector.detectChanges();
}
ngOnDestroy() {
this.destroy$.next();
this.destroy$.complete();
}
// --------------------------------------------------------------------------------
onPreviewPizzagnaUpdate(configLayer) {
const previewWidget = {
...this.configurator.previewWidget,
pizzagna: {
...this.configurator.previewWidget?.pizzagna,
[types_2.PizzagnaLayer.Configuration]: configLayer,
},
};
// TODO: Make previewWidget to be assignable to IWidget
// @ts-ignore: Type '{ pizzagna: { configuration: IPizzagnaLayer; }; }' is missing the following properties from type 'IWidget': id, type
this.configurator.updateWidget(previewWidget);
const widgetTitle = (0, get_1.default)(configLayer, WidgetEditorComponent_1.TITLE_PATH, "");
this.configuratorTitle = $localize `Editing ${widgetTitle}`;
}
onFinish() {
if (this.form.invalid) {
this.form.markAllAsTouched();
// is used to trigger valueChanges to detect changes in forms
// as form is invalid and marking as touched doesn't trigger neither statusChanges nor valueChanges
// and validation messages and styles are not applied in that cases
this.form.patchValue(this.form.value);
this.form.updateValueAndValidity({
onlySelf: false,
emitEvent: true,
});
return;
}
this.toggleBusy();
this.configurator.formSubmit();
}
onCancel() {
this.configurator.formCancel();
}
toggleBusy() {
this.busy = !this.busy;
this.navigationControl.next({
busyState: { busy: this.busy },
allowStepChange: !this.busy,
});
}
};
exports.WidgetEditorComponent = WidgetEditorComponent;
tslib_1.__decorate([
(0, core_1.Input)(),
tslib_1.__metadata("design:type", Object)
], WidgetEditorComponent.prototype, "formPizzagna", void 0);
tslib_1.__decorate([
(0, core_1.Input)(),
tslib_1.__metadata("design:type", String)
], WidgetEditorComponent.prototype, "formRoot", void 0);
tslib_1.__decorate([
(0, core_1.ViewChild)("formPizzagnaComponent", { static: false }),
tslib_1.__metadata("design:type", pizzagna_component_1.PizzagnaComponent),
tslib_1.__metadata("design:paramtypes", [pizzagna_component_1.PizzagnaComponent])
], WidgetEditorComponent.prototype, "formPizzagnaComponent", null);
exports.WidgetEditorComponent = WidgetEditorComponent = WidgetEditorComponent_1 = tslib_1.__decorate([
(0, core_1.Component)({
selector: "nui-widget-editor",
templateUrl: "./widget-editor.component.html",
host: { class: "d-flex flex-column h-100" },
changeDetection: core_1.ChangeDetectionStrategy.OnPush,
}),
tslib_1.__metadata("design:paramtypes", [core_1.ChangeDetectorRef,
forms_1.FormBuilder,
preview_service_1.PreviewService,
configurator_component_1.ConfiguratorComponent])
], WidgetEditorComponent);
//# sourceMappingURL=widget-editor.component.js.map