@c8y/ngx-components 1017.0.329 → 1017.0.332

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -306,11 +306,16 @@ class ContextDashboardService {
306
306
  }
307
307
  async pasteDashboard(newContext) {
308
308
  if (this.copyClipboard) {
309
- if (this.canPasteDashboard(this.copyClipboard, newContext.context)) {
310
- const dashboardToPaste = this.createContextDashboardCopy(this.copyClipboard.dashboard, newContext.contextData, this.copyClipboard.context.contextData);
311
- const dashboard = await this.create(this.clean(dashboardToPaste), newContext);
312
- this.copyClipboard = undefined;
313
- this.navigateToDashboard(dashboard);
309
+ try {
310
+ if (this.canPasteDashboard(this.copyClipboard, newContext.context)) {
311
+ const dashboardToPaste = this.createContextDashboardCopy(this.copyClipboard.dashboard, newContext.contextData, this.copyClipboard.context.contextData);
312
+ const dashboard = await this.create(this.clean(dashboardToPaste), newContext);
313
+ this.copyClipboard = undefined;
314
+ this.navigateToDashboard(dashboard);
315
+ }
316
+ }
317
+ catch {
318
+ this.alert.warning(gettext('Insufficient permissions for this action.'));
314
319
  }
315
320
  }
316
321
  }
@@ -1339,21 +1344,19 @@ class ContextDashboardComponent {
1339
1344
  */
1340
1345
  async copyDashboard() {
1341
1346
  const viewContext = this.route.parent.snapshot.data?.context;
1342
- if (this.canCopyDashboard(viewContext)) {
1343
- this.contextDashboardService.copyClipboard = {
1344
- dashboard: cloneDeep(this.mo.c8y_Dashboard),
1345
- context: cloneDeep({
1346
- context: viewContext,
1347
- contextData: this.context
1348
- })
1349
- };
1350
- if (viewContext) {
1351
- const ctx = viewContext.split('/').shift();
1352
- const msg = this.translateService.instant('Dashboard copied. Navigate to the desired {{ ctx }} and select "Paste dashboard"', { ctx });
1353
- this.alert.success(msg);
1354
- }
1355
- this.actionBarService.refresh();
1347
+ this.contextDashboardService.copyClipboard = {
1348
+ dashboard: cloneDeep(this.mo.c8y_Dashboard),
1349
+ context: cloneDeep({
1350
+ context: viewContext,
1351
+ contextData: this.context
1352
+ })
1353
+ };
1354
+ if (viewContext) {
1355
+ const ctx = viewContext.split('/').shift();
1356
+ const msg = this.translateService.instant('Dashboard copied. Navigate to the desired {{ ctx }} and select "Paste dashboard"', { ctx });
1357
+ this.alert.success(msg);
1356
1358
  }
1359
+ this.actionBarService.refresh();
1357
1360
  }
1358
1361
  /**
1359
1362
  * Remove the complete dashboard and navigate away.
@@ -1607,6 +1610,7 @@ class ContextDashboardComponent {
1607
1610
  dashboard: true,
1608
1611
  ...this.dashboard.classes
1609
1612
  };
1613
+ this.isCopyDisabled = !this.canCopyDashboard();
1610
1614
  this.widgets = await Promise.all(values(dashboardChildren).map(widget => {
1611
1615
  widget.classes = this.mergeWidgetClasses(widget);
1612
1616
  if (isDeviceType) {
@@ -1658,26 +1662,18 @@ class ContextDashboardComponent {
1658
1662
  };
1659
1663
  this.canDelete = false;
1660
1664
  }
1661
- canCopyDashboard(viewContext) {
1662
- if (!this.validDashboardChildren() && viewContext) {
1663
- const ctx = viewContext.split('/').shift();
1664
- const msg = this.translateService.instant('Only dashboards with widgets referencing the current {{ ctx }} can be copied.', { ctx });
1665
- this.alert.warning(msg);
1666
- return false;
1667
- }
1668
- return true;
1669
- }
1670
- validDashboardChildren() {
1671
- return every(this.mo.c8y_Dashboard.children, child => {
1665
+ canCopyDashboard() {
1666
+ const allDashboardChildrenAreValid = every(this.mo.c8y_Dashboard.children, child => {
1672
1667
  const config = child.config || {};
1673
1668
  const dataPoints = config.datapoints || [];
1674
1669
  return !((config.device && config.device.id !== this.context.id) ||
1675
1670
  some(dataPoints, dataPoint => dataPoint.__target.id !== this.context.id));
1676
1671
  });
1672
+ return allDashboardChildrenAreValid;
1677
1673
  }
1678
1674
  }
1679
1675
  ContextDashboardComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.6", ngImport: i0, type: ContextDashboardComponent, deps: [{ token: i1$1.ActivatedRoute }, { token: i1$1.Router }, { token: ContextDashboardService }, { token: i2.AlertService }, { token: i0.Renderer2 }, { token: CONTEXT_DASHBOARD_CONFIG }, { token: WidgetService }, { token: i3$1.BsModalService }, { token: i1.InventoryService }, { token: i2.GainsightService }, { token: i2.ActionBarService }, { token: i3.TranslateService }, { token: i2.ModalService }], target: i0.ɵɵFactoryTarget.Component });
1680
- ContextDashboardComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.0.6", type: ContextDashboardComponent, selector: "c8y-context-dashboard", inputs: { name: "name", childrenClasses: "childrenClasses", context: "context", setTitle: "setTitle", disabled: "disabled", defaultWidgets: "defaultWidgets", canCopy: "canCopy", canDelete: "canDelete", isLoading: "isLoading", breadcrumbSettings: "breadcrumbSettings" }, host: { properties: { "class": "this.class" }, styleAttribute: "\n display: block;\n ", classAttribute: "dashboard c8y-grid-dashboard" }, ngImport: i0, template: "<c8y-title *ngIf=\"title\">\n {{ title }}\n</c8y-title>\n\n<c8y-action-bar-item [placement]=\"'more'\" *ngIf=\"defaultWidgets.length > 0\">\n <button\n type=\"button\"\n title=\"{{ 'Reset dashboard' | translate }}\"\n class=\"btn btn-clean\"\n px-event=\"Reset dashboard\"\n (click)=\"restore()\"\n [disabled]=\"dashboard?.isFrozen || disabled\"\n >\n <i c8yIcon=\"reset\" class=\"m-r-4\"></i>\n {{ 'Reset dashboard' | translate }}\n </button>\n</c8y-action-bar-item>\n\n<c8y-widgets-dashboard\n [context]=\"context\"\n [contextDashboard]=\"dashboard\"\n [widgets]=\"widgets\"\n [settings]=\"{\n isLoading: isLoading,\n isFrozen: dashboard?.isFrozen,\n isDisabled: disabled,\n canDelete: canDelete,\n translateWidgetTitle: dashboard?.translateWidgetTitle,\n allowFullscreen: moduleConfig.allowFullscreen,\n title: setTitle ? dashboard.name || title : undefined,\n widgetMargin: dashboard?.widgetMargin,\n canCopy: canCopy,\n columns: dashboard?.columns || 12\n }\"\n [breadcrumb]=\"breadcrumbSettings\"\n (onFreeze)=\"toggleFreeze($event)\"\n (onChangeDashboard)=\"updateDashboardChildren($event)\"\n (onAddWidget)=\"addWidget()\"\n (onEditWidget)=\"editWidget($event)\"\n (onDeleteWidget)=\"deleteWidget($event)\"\n (onChangeStart)=\"addDashboardClassToBody()\"\n (onChangeEnd)=\"removeDashboardClassFromBody()\"\n (onEditDashboard)=\"editDashboard()\"\n (onCopyDashboard)=\"copyDashboard()\"\n (onDeleteDashboard)=\"deleteDashboard()\"\n></c8y-widgets-dashboard>\n", dependencies: [{ kind: "component", type: i2.ActionBarItemComponent, selector: "c8y-action-bar-item", inputs: ["placement", "priority", "itemClass", "injector", "groupId"] }, { kind: "directive", type: i2.IconDirective, selector: "[c8yIcon]", inputs: ["c8yIcon"] }, { kind: "directive", type: i5.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: i2.TitleComponent, selector: "c8y-title", inputs: ["pageTitleUpdate"] }, { kind: "component", type: i2.WidgetsDashboardComponent, selector: "c8y-widgets-dashboard", inputs: ["widgets", "context", "contextDashboard", "settings", "breadcrumb"], outputs: ["onAddWidget", "onEditWidget", "onDeleteWidget", "onChangeDashboard", "onEditDashboard", "onCopyDashboard", "onDeleteDashboard", "onFreeze", "onChangeStart", "onChangeEnd"] }, { kind: "pipe", type: i2.C8yTranslatePipe, name: "translate" }] });
1676
+ ContextDashboardComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.0.6", type: ContextDashboardComponent, selector: "c8y-context-dashboard", inputs: { name: "name", childrenClasses: "childrenClasses", context: "context", setTitle: "setTitle", disabled: "disabled", defaultWidgets: "defaultWidgets", canCopy: "canCopy", canDelete: "canDelete", isLoading: "isLoading", breadcrumbSettings: "breadcrumbSettings" }, host: { properties: { "class": "this.class" }, styleAttribute: "\n display: block;\n ", classAttribute: "dashboard c8y-grid-dashboard" }, ngImport: i0, template: "<c8y-title *ngIf=\"title\">\n {{ title }}\n</c8y-title>\n\n<c8y-action-bar-item [placement]=\"'more'\" *ngIf=\"defaultWidgets.length > 0\">\n <button\n type=\"button\"\n title=\"{{ 'Reset dashboard' | translate }}\"\n class=\"btn btn-clean\"\n px-event=\"Reset dashboard\"\n (click)=\"restore()\"\n [disabled]=\"dashboard?.isFrozen || disabled\"\n >\n <i c8yIcon=\"reset\" class=\"m-r-4\"></i>\n {{ 'Reset dashboard' | translate }}\n </button>\n</c8y-action-bar-item>\n\n<c8y-widgets-dashboard\n [context]=\"context\"\n [contextDashboard]=\"dashboard\"\n [widgets]=\"widgets\"\n [settings]=\"{\n isLoading: isLoading,\n isFrozen: dashboard?.isFrozen,\n isDisabled: disabled,\n canDelete: canDelete,\n translateWidgetTitle: dashboard?.translateWidgetTitle,\n allowFullscreen: moduleConfig.allowFullscreen,\n title: setTitle ? dashboard.name || title : undefined,\n widgetMargin: dashboard?.widgetMargin,\n canCopy: canCopy,\n isCopyDisabled: isCopyDisabled,\n columns: dashboard?.columns || 12\n }\"\n [breadcrumb]=\"breadcrumbSettings\"\n (onFreeze)=\"toggleFreeze($event)\"\n (onChangeDashboard)=\"updateDashboardChildren($event)\"\n (onAddWidget)=\"addWidget()\"\n (onEditWidget)=\"editWidget($event)\"\n (onDeleteWidget)=\"deleteWidget($event)\"\n (onChangeStart)=\"addDashboardClassToBody()\"\n (onChangeEnd)=\"removeDashboardClassFromBody()\"\n (onEditDashboard)=\"editDashboard()\"\n (onCopyDashboard)=\"copyDashboard()\"\n (onDeleteDashboard)=\"deleteDashboard()\"\n></c8y-widgets-dashboard>\n", dependencies: [{ kind: "component", type: i2.ActionBarItemComponent, selector: "c8y-action-bar-item", inputs: ["placement", "priority", "itemClass", "injector", "groupId"] }, { kind: "directive", type: i2.IconDirective, selector: "[c8yIcon]", inputs: ["c8yIcon"] }, { kind: "directive", type: i5.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: i2.TitleComponent, selector: "c8y-title", inputs: ["pageTitleUpdate"] }, { kind: "component", type: i2.WidgetsDashboardComponent, selector: "c8y-widgets-dashboard", inputs: ["widgets", "context", "contextDashboard", "settings", "breadcrumb"], outputs: ["onAddWidget", "onEditWidget", "onDeleteWidget", "onChangeDashboard", "onEditDashboard", "onCopyDashboard", "onDeleteDashboard", "onFreeze", "onChangeStart", "onChangeEnd"] }, { kind: "pipe", type: i2.C8yTranslatePipe, name: "translate" }] });
1681
1677
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.6", ngImport: i0, type: ContextDashboardComponent, decorators: [{
1682
1678
  type: Component,
1683
1679
  args: [{ selector: 'c8y-context-dashboard', host: {
@@ -1685,7 +1681,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.6", ngImpor
1685
1681
  display: block;
1686
1682
  `,
1687
1683
  class: 'dashboard c8y-grid-dashboard'
1688
- }, template: "<c8y-title *ngIf=\"title\">\n {{ title }}\n</c8y-title>\n\n<c8y-action-bar-item [placement]=\"'more'\" *ngIf=\"defaultWidgets.length > 0\">\n <button\n type=\"button\"\n title=\"{{ 'Reset dashboard' | translate }}\"\n class=\"btn btn-clean\"\n px-event=\"Reset dashboard\"\n (click)=\"restore()\"\n [disabled]=\"dashboard?.isFrozen || disabled\"\n >\n <i c8yIcon=\"reset\" class=\"m-r-4\"></i>\n {{ 'Reset dashboard' | translate }}\n </button>\n</c8y-action-bar-item>\n\n<c8y-widgets-dashboard\n [context]=\"context\"\n [contextDashboard]=\"dashboard\"\n [widgets]=\"widgets\"\n [settings]=\"{\n isLoading: isLoading,\n isFrozen: dashboard?.isFrozen,\n isDisabled: disabled,\n canDelete: canDelete,\n translateWidgetTitle: dashboard?.translateWidgetTitle,\n allowFullscreen: moduleConfig.allowFullscreen,\n title: setTitle ? dashboard.name || title : undefined,\n widgetMargin: dashboard?.widgetMargin,\n canCopy: canCopy,\n columns: dashboard?.columns || 12\n }\"\n [breadcrumb]=\"breadcrumbSettings\"\n (onFreeze)=\"toggleFreeze($event)\"\n (onChangeDashboard)=\"updateDashboardChildren($event)\"\n (onAddWidget)=\"addWidget()\"\n (onEditWidget)=\"editWidget($event)\"\n (onDeleteWidget)=\"deleteWidget($event)\"\n (onChangeStart)=\"addDashboardClassToBody()\"\n (onChangeEnd)=\"removeDashboardClassFromBody()\"\n (onEditDashboard)=\"editDashboard()\"\n (onCopyDashboard)=\"copyDashboard()\"\n (onDeleteDashboard)=\"deleteDashboard()\"\n></c8y-widgets-dashboard>\n" }]
1684
+ }, template: "<c8y-title *ngIf=\"title\">\n {{ title }}\n</c8y-title>\n\n<c8y-action-bar-item [placement]=\"'more'\" *ngIf=\"defaultWidgets.length > 0\">\n <button\n type=\"button\"\n title=\"{{ 'Reset dashboard' | translate }}\"\n class=\"btn btn-clean\"\n px-event=\"Reset dashboard\"\n (click)=\"restore()\"\n [disabled]=\"dashboard?.isFrozen || disabled\"\n >\n <i c8yIcon=\"reset\" class=\"m-r-4\"></i>\n {{ 'Reset dashboard' | translate }}\n </button>\n</c8y-action-bar-item>\n\n<c8y-widgets-dashboard\n [context]=\"context\"\n [contextDashboard]=\"dashboard\"\n [widgets]=\"widgets\"\n [settings]=\"{\n isLoading: isLoading,\n isFrozen: dashboard?.isFrozen,\n isDisabled: disabled,\n canDelete: canDelete,\n translateWidgetTitle: dashboard?.translateWidgetTitle,\n allowFullscreen: moduleConfig.allowFullscreen,\n title: setTitle ? dashboard.name || title : undefined,\n widgetMargin: dashboard?.widgetMargin,\n canCopy: canCopy,\n isCopyDisabled: isCopyDisabled,\n columns: dashboard?.columns || 12\n }\"\n [breadcrumb]=\"breadcrumbSettings\"\n (onFreeze)=\"toggleFreeze($event)\"\n (onChangeDashboard)=\"updateDashboardChildren($event)\"\n (onAddWidget)=\"addWidget()\"\n (onEditWidget)=\"editWidget($event)\"\n (onDeleteWidget)=\"deleteWidget($event)\"\n (onChangeStart)=\"addDashboardClassToBody()\"\n (onChangeEnd)=\"removeDashboardClassFromBody()\"\n (onEditDashboard)=\"editDashboard()\"\n (onCopyDashboard)=\"copyDashboard()\"\n (onDeleteDashboard)=\"deleteDashboard()\"\n></c8y-widgets-dashboard>\n" }]
1689
1685
  }], ctorParameters: function () { return [{ type: i1$1.ActivatedRoute }, { type: i1$1.Router }, { type: ContextDashboardService }, { type: i2.AlertService }, { type: i0.Renderer2 }, { type: undefined, decorators: [{
1690
1686
  type: Inject,
1691
1687
  args: [CONTEXT_DASHBOARD_CONFIG]