Browse Source

UI: Improved show confirm on exit dialog in widget editor

pull/9472/head
Vladyslav_Prykhodko 3 years ago
parent
commit
35d40a88eb
  1. 11
      ui-ngx/src/app/core/guards/confirm-on-exit.guard.ts
  2. 11
      ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.component.ts
  3. 33
      ui-ngx/src/app/modules/home/pages/widget/widget-editor.component.ts
  4. 3
      ui-ngx/src/app/shared/models/window-message.model.ts
  5. 1
      ui-ngx/src/assets/locale/locale.constant-en_US.json

11
ui-ngx/src/app/core/guards/confirm-on-exit.guard.ts

@ -28,10 +28,12 @@ import { isDefined } from '../utils';
export interface HasConfirmForm { export interface HasConfirmForm {
confirmForm(): UntypedFormGroup; confirmForm(): UntypedFormGroup;
confirmOnExitMessage?: string;
} }
export interface HasDirtyFlag { export interface HasDirtyFlag {
isDirty: boolean; isDirty: boolean;
confirmOnExitMessage?: string;
} }
@Injectable({ @Injectable({
@ -66,9 +68,10 @@ export class ConfirmOnExitGuard implements CanDeactivate<HasConfirmForm & HasDir
isDirty = component.isDirty; isDirty = component.isDirty;
} }
if (isDirty) { if (isDirty) {
const message = this.getMessage(component);
return this.dialogService.confirm( return this.dialogService.confirm(
this.translate.instant('confirm-on-exit.title'), this.translate.instant('confirm-on-exit.title'),
this.translate.instant('confirm-on-exit.html-message') message
).pipe( ).pipe(
map((dialogResult) => { map((dialogResult) => {
if (dialogResult) { if (dialogResult) {
@ -85,4 +88,10 @@ export class ConfirmOnExitGuard implements CanDeactivate<HasConfirmForm & HasDir
} }
return true; return true;
} }
private getMessage(component: HasConfirmForm & HasDirtyFlag): string {
return component.confirmOnExitMessage
? component.confirmOnExitMessage
: this.translate.instant('confirm-on-exit.html-message');
}
} }

11
ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.component.ts

@ -956,6 +956,7 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC
public toggleDashboardEditMode() { public toggleDashboardEditMode() {
this.setEditMode(!this.isEdit, true); this.setEditMode(!this.isEdit, true);
this.notifyDashboardToggleEditMode();
} }
public saveDashboard() { public saveDashboard() {
@ -1063,6 +1064,16 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC
this.dashboardCtx.aliasController.updateFilters(this.dashboard.configuration.filters); this.dashboardCtx.aliasController.updateFilters(this.dashboard.configuration.filters);
} }
private notifyDashboardToggleEditMode() {
if (this.widgetEditMode) {
const message: WindowMessage = {
type: 'widgetEditModeToggle',
data: this.isEdit
};
this.window.parent.postMessage(JSON.stringify(message), '*');
}
}
private notifyDashboardUpdated() { private notifyDashboardUpdated() {
if (this.widgetEditMode) { if (this.widgetEditMode) {
const widget = this.layouts.main.layoutCtx.widgets.widgetByIndex(0); const widget = this.layouts.main.layoutCtx.widgets.widgetByIndex(0);

33
ui-ngx/src/app/modules/home/pages/widget/widget-editor.component.ts

@ -122,7 +122,19 @@ export class WidgetEditorComponent extends PageComponent implements OnInit, OnDe
widget: WidgetInfo; widget: WidgetInfo;
origWidget: WidgetInfo; origWidget: WidgetInfo;
isDirty = false; private isEditModeWidget = false;
private _isDirty = false;
get isDirty(): boolean {
return this._isDirty || this.isEditModeWidget;
}
set isDirty(value: boolean) {
if (!value) {
this.isEditModeWidget = false;
}
this._isDirty = value;
}
fullscreen = false; fullscreen = false;
htmlFullscreen = false; htmlFullscreen = false;
@ -450,6 +462,10 @@ export class WidgetEditorComponent extends PageComponent implements OnInit, OnDe
break; break;
case 'widgetEditUpdated': case 'widgetEditUpdated':
this.onWidgetEditUpdated(message.data); this.onWidgetEditUpdated(message.data);
this.onWidgetEditModeToggled(false);
break;
case 'widgetEditModeToggle':
this.onWidgetEditModeToggled(message.data);
break; break;
} }
} }
@ -486,6 +502,10 @@ export class WidgetEditorComponent extends PageComponent implements OnInit, OnDe
this.isDirty = true; this.isDirty = true;
} }
private onWidgetEditModeToggled(mode: boolean) {
this.isEditModeWidget = mode;
}
private onWidgetException(details: ExceptionData) { private onWidgetException(details: ExceptionData) {
if (!this.gotError) { if (!this.gotError) {
this.gotError = true; this.gotError = true;
@ -639,7 +659,7 @@ export class WidgetEditorComponent extends PageComponent implements OnInit, OnDe
} }
undoDisabled(): boolean { undoDisabled(): boolean {
return !this.isDirty return !this._isDirty
|| !this.iframeWidgetEditModeInited || !this.iframeWidgetEditModeInited
|| this.saveWidgetPending || this.saveWidgetPending
|| this.saveWidgetAsPending; || this.saveWidgetAsPending;
@ -647,7 +667,7 @@ export class WidgetEditorComponent extends PageComponent implements OnInit, OnDe
saveDisabled(): boolean { saveDisabled(): boolean {
return this.isReadOnly return this.isReadOnly
|| !this.isDirty || !this._isDirty
|| !this.iframeWidgetEditModeInited || !this.iframeWidgetEditModeInited
|| this.saveWidgetPending || this.saveWidgetPending
|| this.saveWidgetAsPending; || this.saveWidgetAsPending;
@ -799,4 +819,11 @@ export class WidgetEditorComponent extends PageComponent implements OnInit, OnDe
this.widget.defaultConfig = JSON.stringify(config); this.widget.defaultConfig = JSON.stringify(config);
this.isDirty = true; this.isDirty = true;
} }
get confirmOnExitMessage(): string {
if (this.isEditModeWidget && !this._isDirty) {
return this.translate.instant('widget.confirm-to-exit-editor-html');
}
return '';
}
} }

3
ui-ngx/src/app/shared/models/window-message.model.ts

@ -14,7 +14,8 @@
/// limitations under the License. /// limitations under the License.
/// ///
export type WindowMessageType = 'widgetException' | 'widgetEditModeInited' | 'widgetEditUpdated' | 'openDashboardMessage' | 'reloadUserMessage' | 'toggleDashboardLayout'; export type WindowMessageType = 'widgetException' | 'widgetEditModeInited' | 'widgetEditUpdated' | 'openDashboardMessage'
| 'reloadUserMessage' | 'toggleDashboardLayout' | 'widgetEditModeToggle';
export interface WindowMessage { export interface WindowMessage {
type: WindowMessageType; type: WindowMessageType;

1
ui-ngx/src/assets/locale/locale.constant-en_US.json

@ -4759,6 +4759,7 @@
"no-widgets-text": "No widgets found", "no-widgets-text": "No widgets found",
"management": "Widget management", "management": "Widget management",
"editor": "Widget Editor", "editor": "Widget Editor",
"confirm-to-exit-editor-html": "You have unsaved default widget settings.<br>Are you sure you want to leave this page?",
"widget-type-not-found": "Problem loading widget configuration.<br>Probably associated\n widget type was removed.", "widget-type-not-found": "Problem loading widget configuration.<br>Probably associated\n widget type was removed.",
"widget-type-load-error": "Widget wasn't loaded due to the following errors:", "widget-type-load-error": "Widget wasn't loaded due to the following errors:",
"remove": "Remove widget", "remove": "Remove widget",

Loading…
Cancel
Save