Merge pull request #9472 from vvlladd28/improvement/widget-editor/confirm-to-exit
Improved show confirm on exit dialog in widget editor
This commit is contained in:
commit
c32b638be5
@ -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');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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);
|
||||||
|
|||||||
@ -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 '';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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;
|
||||||
|
|||||||
@ -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…
x
Reference in New Issue
Block a user