UI: Fix widget container tooltip crash on destroy. Fix raise condition on dashboard page destroy.

This commit is contained in:
Igor Kulikov 2024-09-19 19:47:25 +03:00
parent 7cb785bc78
commit 312aa5220b
2 changed files with 39 additions and 30 deletions

View File

@ -169,6 +169,8 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC
LayoutType = LayoutType; LayoutType = LayoutType;
private destroyed = false;
private forcePristine = false; private forcePristine = false;
get isDirty(): boolean { get isDirty(): boolean {
@ -594,6 +596,7 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC
} }
ngOnDestroy(): void { ngOnDestroy(): void {
this.destroyed = true;
this.cleanupDashboardCss(); this.cleanupDashboardCss();
if (this.isMobileApp && this.syncStateWithQueryParam) { if (this.isMobileApp && this.syncStateWithQueryParam) {
this.mobileService.unregisterToggleLayoutFunction(); this.mobileService.unregisterToggleLayoutFunction();
@ -1106,6 +1109,7 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC
} }
public openDashboardState(state: string, openRightLayout?: boolean) { public openDashboardState(state: string, openRightLayout?: boolean) {
if (!this.destroyed) {
const layoutsData = this.dashboardUtils.getStateLayoutsData(this.dashboard, state); const layoutsData = this.dashboardUtils.getStateLayoutsData(this.dashboard, state);
if (layoutsData) { if (layoutsData) {
this.dashboardCtx.state = state; this.dashboardCtx.state = state;
@ -1117,6 +1121,7 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC
this.mobileService.onDashboardLoaded(this.layouts.right.show, this.isRightLayoutOpened); this.mobileService.onDashboardLoaded(this.layouts.right.show, this.isRightLayoutOpened);
}); });
} }
}
private updateLayouts(layoutsData?: DashboardLayoutsInfo) { private updateLayouts(layoutsData?: DashboardLayoutsInfo) {
if (!layoutsData) { if (!layoutsData) {

View File

@ -18,11 +18,11 @@ import {
AfterViewInit, AfterViewInit,
ChangeDetectionStrategy, ChangeDetectionStrategy,
ChangeDetectorRef, ChangeDetectorRef,
Component, Component, ComponentRef,
ElementRef, ElementRef,
EventEmitter, EventEmitter,
HostBinding, HostBinding,
Input, OnChanges, Input, NgZone, OnChanges,
OnDestroy, OnDestroy,
OnInit, OnInit,
Output, Output,
@ -134,7 +134,8 @@ export class WidgetContainerComponent extends PageComponent implements OnInit, O
private renderer: Renderer2, private renderer: Renderer2,
private container: ViewContainerRef, private container: ViewContainerRef,
private dashboardUtils: DashboardUtilsService, private dashboardUtils: DashboardUtilsService,
private utils: UtilsService) { private utils: UtilsService,
private zone: NgZone) {
super(store); super(store);
} }
@ -173,7 +174,7 @@ export class WidgetContainerComponent extends PageComponent implements OnInit, O
if (this.cssClass) { if (this.cssClass) {
this.utils.clearCssElement(this.renderer, this.cssClass); this.utils.clearCssElement(this.renderer, this.cssClass);
} }
if (this.editWidgetActionsTooltip) { if (this.editWidgetActionsTooltip && !this.editWidgetActionsTooltip.status().destroyed) {
this.editWidgetActionsTooltip.destroy(); this.editWidgetActionsTooltip.destroy();
} }
} }
@ -255,6 +256,7 @@ export class WidgetContainerComponent extends PageComponent implements OnInit, O
} }
private initEditWidgetActionTooltip(parent: HTMLElement) { private initEditWidgetActionTooltip(parent: HTMLElement) {
let componentRef: ComponentRef<EditWidgetActionsTooltipComponent>;
from(import('tooltipster')).subscribe(() => { from(import('tooltipster')).subscribe(() => {
$(this.gridsterItem.el).tooltipster({ $(this.gridsterItem.el).tooltipster({
parent: $(parent), parent: $(parent),
@ -305,7 +307,8 @@ export class WidgetContainerComponent extends PageComponent implements OnInit, O
} }
}); });
this.editWidgetActionsTooltip = $(this.gridsterItem.el).tooltipster('instance'); this.editWidgetActionsTooltip = $(this.gridsterItem.el).tooltipster('instance');
const componentRef = this.container.createComponent(EditWidgetActionsTooltipComponent); this.zone.run(() => {
componentRef = this.container.createComponent(EditWidgetActionsTooltipComponent);
componentRef.instance.container = this; componentRef.instance.container = this;
componentRef.instance.viewInited.subscribe(() => { componentRef.instance.viewInited.subscribe(() => {
if (this.editWidgetActionsTooltip.status().open) { if (this.editWidgetActionsTooltip.status().open) {
@ -324,6 +327,7 @@ export class WidgetContainerComponent extends PageComponent implements OnInit, O
this.widget.onSelected((selected) => this.widget.onSelected((selected) =>
this.updateEditWidgetActionsTooltipSelectedState(selected)); this.updateEditWidgetActionsTooltipSelectedState(selected));
}); });
});
} }
private updateEditWidgetActionsTooltipSelectedState(selected: boolean) { private updateEditWidgetActionsTooltipSelectedState(selected: boolean) {