1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-21 22:39:41 +02:00

feat(app): Prevent web editor related views from being accidentally closed (#4715)

* feat(app): when leaving a view with unsaved changed, a modal prompt the user with a confirmation message

feat(app): when leaving a view with unsaved changes, a modal prompt the user with a confirmation message

* feat(app/web-editor): fix the modal behaviour when editing a stack details

* feat(app/web-editor): add a reusable function confirmWebEditorDiscard in modal service

* feat(docker/stack): fix missing dependency
This commit is contained in:
Alice Groux 2021-03-20 22:13:27 +01:00 committed by GitHub
parent d0d38990c7
commit a7ed6222b0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 271 additions and 15 deletions

View file

@ -2,8 +2,8 @@ import _ from 'lodash-es';
export class CreateEdgeStackViewController {
/* @ngInject */
constructor($state, EdgeStackService, EdgeGroupService, EdgeTemplateService, Notifications, FormHelper, $async) {
Object.assign(this, { $state, EdgeStackService, EdgeGroupService, EdgeTemplateService, Notifications, FormHelper, $async });
constructor($state, $window, ModalService, EdgeStackService, EdgeGroupService, EdgeTemplateService, Notifications, FormHelper, $async) {
Object.assign(this, { $state, $window, ModalService, EdgeStackService, EdgeGroupService, EdgeTemplateService, Notifications, FormHelper, $async });
this.formValues = {
Name: '',
@ -24,6 +24,7 @@ export class CreateEdgeStackViewController {
formValidationError: '',
actionInProgress: false,
StackType: null,
isEditorDirty: false,
};
this.edgeGroups = null;
@ -41,6 +42,12 @@ export class CreateEdgeStackViewController {
this.onChangeMethod = this.onChangeMethod.bind(this);
}
async uiCanExit() {
if (this.state.Method === 'editor' && this.formValues.StackFileContent && this.state.isEditorDirty) {
return this.ModalService.confirmWebEditorDiscard();
}
}
async $onInit() {
try {
this.edgeGroups = await this.EdgeGroupService.groups();
@ -55,6 +62,12 @@ export class CreateEdgeStackViewController {
} catch (err) {
this.Notifications.error('Failure', err, 'Unable to retrieve Templates');
}
this.$window.onbeforeunload = () => {
if (this.state.Method === 'editor' && this.formValues.StackFileContent && this.state.isEditorDirty) {
return '';
}
};
}
createStack() {
@ -97,6 +110,7 @@ export class CreateEdgeStackViewController {
await this.createStackByMethod(name, method);
this.Notifications.success('Stack successfully deployed');
this.state.isEditorDirty = false;
this.$state.go('edge.stacks');
} catch (err) {
this.Notifications.error('Deployment error', err, 'Unable to deploy stack');
@ -149,5 +163,6 @@ export class CreateEdgeStackViewController {
editorUpdate(cm) {
this.formValues.StackFileContent = cm.getValue();
this.state.isEditorDirty = true;
}
}