mirror of https://github.com/portainer/portainer
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 dependencypull/4935/head
parent
d0d38990c7
commit
a7ed6222b0
|
@ -5,9 +5,11 @@ import angular from 'angular';
|
||||||
|
|
||||||
class CreateConfigController {
|
class CreateConfigController {
|
||||||
/* @ngInject */
|
/* @ngInject */
|
||||||
constructor($async, $state, $transition$, Notifications, ConfigService, Authentication, FormValidator, ResourceControlService) {
|
constructor($async, $state, $transition$, $window, ModalService, Notifications, ConfigService, Authentication, FormValidator, ResourceControlService) {
|
||||||
this.$state = $state;
|
this.$state = $state;
|
||||||
this.$transition$ = $transition$;
|
this.$transition$ = $transition$;
|
||||||
|
this.$window = $window;
|
||||||
|
this.ModalService = ModalService;
|
||||||
this.Notifications = Notifications;
|
this.Notifications = Notifications;
|
||||||
this.ConfigService = ConfigService;
|
this.ConfigService = ConfigService;
|
||||||
this.Authentication = Authentication;
|
this.Authentication = Authentication;
|
||||||
|
@ -24,6 +26,7 @@ class CreateConfigController {
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
formValidationError: '',
|
formValidationError: '',
|
||||||
|
isEditorDirty: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
this.editorUpdate = this.editorUpdate.bind(this);
|
this.editorUpdate = this.editorUpdate.bind(this);
|
||||||
|
@ -31,6 +34,12 @@ class CreateConfigController {
|
||||||
}
|
}
|
||||||
|
|
||||||
async $onInit() {
|
async $onInit() {
|
||||||
|
this.$window.onbeforeunload = () => {
|
||||||
|
if (this.formValues.displayCodeEditor && this.formValues.ConfigContent && this.state.isEditorDirty) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if (!this.$transition$.params().id) {
|
if (!this.$transition$.params().id) {
|
||||||
this.formValues.displayCodeEditor = true;
|
this.formValues.displayCodeEditor = true;
|
||||||
return;
|
return;
|
||||||
|
@ -53,6 +62,12 @@ class CreateConfigController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async uiCanExit() {
|
||||||
|
if (this.formValues.displayCodeEditor && this.formValues.ConfigContent && this.state.isEditorDirty) {
|
||||||
|
return this.ModalService.confirmWebEditorDiscard();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
addLabel() {
|
addLabel() {
|
||||||
this.formValues.Labels.push({ name: '', value: '' });
|
this.formValues.Labels.push({ name: '', value: '' });
|
||||||
}
|
}
|
||||||
|
@ -122,6 +137,7 @@ class CreateConfigController {
|
||||||
const userId = userDetails.ID;
|
const userId = userDetails.ID;
|
||||||
await this.ResourceControlService.applyResourceControl(userId, accessControlData, resourceControl);
|
await this.ResourceControlService.applyResourceControl(userId, accessControlData, resourceControl);
|
||||||
this.Notifications.success('Config successfully created');
|
this.Notifications.success('Config successfully created');
|
||||||
|
this.state.isEditorDirty = false;
|
||||||
this.$state.go('docker.configs', {}, { reload: true });
|
this.$state.go('docker.configs', {}, { reload: true });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.Notifications.error('Failure', err, 'Unable to create config');
|
this.Notifications.error('Failure', err, 'Unable to create config');
|
||||||
|
@ -130,6 +146,7 @@ class CreateConfigController {
|
||||||
|
|
||||||
editorUpdate(cm) {
|
editorUpdate(cm) {
|
||||||
this.formValues.ConfigContent = cm.getValue();
|
this.formValues.ConfigContent = cm.getValue();
|
||||||
|
this.state.isEditorDirty = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,16 @@
|
||||||
angular.module('portainer.docker').controller('BuildImageController', [
|
angular.module('portainer.docker').controller('BuildImageController', [
|
||||||
'$scope',
|
'$scope',
|
||||||
'$state',
|
'$window',
|
||||||
|
'ModalService',
|
||||||
'BuildService',
|
'BuildService',
|
||||||
'Notifications',
|
'Notifications',
|
||||||
'HttpRequestHelper',
|
'HttpRequestHelper',
|
||||||
function ($scope, $state, BuildService, Notifications, HttpRequestHelper) {
|
function ($scope, $window, ModalService, BuildService, Notifications, HttpRequestHelper) {
|
||||||
$scope.state = {
|
$scope.state = {
|
||||||
BuildType: 'editor',
|
BuildType: 'editor',
|
||||||
actionInProgress: false,
|
actionInProgress: false,
|
||||||
activeTab: 0,
|
activeTab: 0,
|
||||||
|
isEditorDirty: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.formValues = {
|
$scope.formValues = {
|
||||||
|
@ -20,6 +22,12 @@ angular.module('portainer.docker').controller('BuildImageController', [
|
||||||
NodeName: null,
|
NodeName: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$window.onbeforeunload = () => {
|
||||||
|
if ($scope.state.BuildType === 'editor' && $scope.formValues.DockerFileContent && $scope.state.isEditorDirty) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
$scope.addImageName = function () {
|
$scope.addImageName = function () {
|
||||||
$scope.formValues.ImageNames.push({ Name: '' });
|
$scope.formValues.ImageNames.push({ Name: '' });
|
||||||
};
|
};
|
||||||
|
@ -93,6 +101,13 @@ angular.module('portainer.docker').controller('BuildImageController', [
|
||||||
|
|
||||||
$scope.editorUpdate = function (cm) {
|
$scope.editorUpdate = function (cm) {
|
||||||
$scope.formValues.DockerFileContent = cm.getValue();
|
$scope.formValues.DockerFileContent = cm.getValue();
|
||||||
|
$scope.state.isEditorDirty = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.uiCanExit = async function () {
|
||||||
|
if ($scope.state.BuildType === 'editor' && $scope.formValues.DockerFileContent && $scope.state.isEditorDirty) {
|
||||||
|
return ModalService.confirmWebEditorDiscard();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -72,6 +72,7 @@ export class EdgeJobFormController {
|
||||||
|
|
||||||
editorUpdate(cm) {
|
editorUpdate(cm) {
|
||||||
this.model.FileContent = cm.getValue();
|
this.model.FileContent = cm.getValue();
|
||||||
|
this.isEditorDirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
associateEndpoint(endpoint) {
|
associateEndpoint(endpoint) {
|
||||||
|
|
|
@ -14,5 +14,6 @@ angular.module('portainer.edge').component('edgeJobForm', {
|
||||||
formAction: '<',
|
formAction: '<',
|
||||||
formActionLabel: '@',
|
formActionLabel: '@',
|
||||||
actionInProgress: '<',
|
actionInProgress: '<',
|
||||||
|
isEditorDirty: '=',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -6,5 +6,6 @@ export class EditEdgeStackFormController {
|
||||||
|
|
||||||
editorUpdate(cm) {
|
editorUpdate(cm) {
|
||||||
this.model.StackFileContent = cm.getValue();
|
this.model.StackFileContent = cm.getValue();
|
||||||
|
this.isEditorDirty = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,5 +10,6 @@ angular.module('portainer.edge').component('editEdgeStackForm', {
|
||||||
actionInProgress: '<',
|
actionInProgress: '<',
|
||||||
submitAction: '<',
|
submitAction: '<',
|
||||||
edgeGroups: '<',
|
edgeGroups: '<',
|
||||||
|
isEditorDirty: '=',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
form-action="$ctrl.create"
|
form-action="$ctrl.create"
|
||||||
form-action-label="Create edge job"
|
form-action-label="Create edge job"
|
||||||
action-in-progress="$ctrl.state.actionInProgress"
|
action-in-progress="$ctrl.state.actionInProgress"
|
||||||
|
is-editor-dirty="$ctrl.state.isEditorDirty"
|
||||||
></edge-job-form>
|
></edge-job-form>
|
||||||
</rd-widget-body>
|
</rd-widget-body>
|
||||||
</rd-widget>
|
</rd-widget>
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
export class CreateEdgeJobViewController {
|
export class CreateEdgeJobViewController {
|
||||||
/* @ngInject */
|
/* @ngInject */
|
||||||
constructor($async, $q, $state, EdgeJobService, GroupService, Notifications, TagService) {
|
constructor($async, $q, $state, $window, ModalService, EdgeJobService, GroupService, Notifications, TagService) {
|
||||||
this.state = {
|
this.state = {
|
||||||
actionInProgress: false,
|
actionInProgress: false,
|
||||||
|
isEditorDirty: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
this.model = {
|
this.model = {
|
||||||
|
@ -17,6 +18,8 @@ export class CreateEdgeJobViewController {
|
||||||
this.$async = $async;
|
this.$async = $async;
|
||||||
this.$q = $q;
|
this.$q = $q;
|
||||||
this.$state = $state;
|
this.$state = $state;
|
||||||
|
this.$window = $window;
|
||||||
|
this.ModalService = ModalService;
|
||||||
this.Notifications = Notifications;
|
this.Notifications = Notifications;
|
||||||
this.GroupService = GroupService;
|
this.GroupService = GroupService;
|
||||||
this.EdgeJobService = EdgeJobService;
|
this.EdgeJobService = EdgeJobService;
|
||||||
|
@ -37,6 +40,7 @@ export class CreateEdgeJobViewController {
|
||||||
try {
|
try {
|
||||||
await this.createEdgeJob(method, this.model);
|
await this.createEdgeJob(method, this.model);
|
||||||
this.Notifications.success('Edge job successfully created');
|
this.Notifications.success('Edge job successfully created');
|
||||||
|
this.state.isEditorDirty = false;
|
||||||
this.$state.go('edge.jobs', {}, { reload: true });
|
this.$state.go('edge.jobs', {}, { reload: true });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.Notifications.error('Failure', err, 'Unable to create Edge job');
|
this.Notifications.error('Failure', err, 'Unable to create Edge job');
|
||||||
|
@ -52,6 +56,12 @@ export class CreateEdgeJobViewController {
|
||||||
return this.EdgeJobService.createEdgeJobFromFileUpload(model);
|
return this.EdgeJobService.createEdgeJobFromFileUpload(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async uiCanExit() {
|
||||||
|
if (this.model.FileContent && this.state.isEditorDirty) {
|
||||||
|
return this.ModalService.confirmWebEditorDiscard();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async $onInit() {
|
async $onInit() {
|
||||||
try {
|
try {
|
||||||
const [groups, tags] = await Promise.all([this.GroupService.groups(), this.TagService.tags()]);
|
const [groups, tags] = await Promise.all([this.GroupService.groups(), this.TagService.tags()]);
|
||||||
|
@ -60,5 +70,11 @@ export class CreateEdgeJobViewController {
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.Notifications.error('Failure', err, 'Unable to retrieve page data');
|
this.Notifications.error('Failure', err, 'Unable to retrieve page data');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.$window.onbeforeunload = () => {
|
||||||
|
if (this.model.FileContent && this.state.isEditorDirty) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
form-action="$ctrl.update"
|
form-action="$ctrl.update"
|
||||||
form-action-label="Update Edge job"
|
form-action-label="Update Edge job"
|
||||||
action-in-progress="$ctrl.state.actionInProgress"
|
action-in-progress="$ctrl.state.actionInProgress"
|
||||||
|
is-editor-dirty="$ctrl.state.isEditorDirty"
|
||||||
></edge-job-form>
|
></edge-job-form>
|
||||||
</uib-tab>
|
</uib-tab>
|
||||||
|
|
||||||
|
|
|
@ -2,15 +2,18 @@ import _ from 'lodash-es';
|
||||||
|
|
||||||
export class EdgeJobController {
|
export class EdgeJobController {
|
||||||
/* @ngInject */
|
/* @ngInject */
|
||||||
constructor($async, $q, $state, EdgeJobService, EndpointService, FileSaver, GroupService, HostBrowserService, Notifications, TagService) {
|
constructor($async, $q, $state, $window, ModalService, EdgeJobService, EndpointService, FileSaver, GroupService, HostBrowserService, Notifications, TagService) {
|
||||||
this.state = {
|
this.state = {
|
||||||
actionInProgress: false,
|
actionInProgress: false,
|
||||||
showEditorTab: false,
|
showEditorTab: false,
|
||||||
|
isEditorDirty: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
this.$async = $async;
|
this.$async = $async;
|
||||||
this.$q = $q;
|
this.$q = $q;
|
||||||
this.$state = $state;
|
this.$state = $state;
|
||||||
|
this.$window = $window;
|
||||||
|
this.ModalService = ModalService;
|
||||||
this.EdgeJobService = EdgeJobService;
|
this.EdgeJobService = EdgeJobService;
|
||||||
this.EndpointService = EndpointService;
|
this.EndpointService = EndpointService;
|
||||||
this.FileSaver = FileSaver;
|
this.FileSaver = FileSaver;
|
||||||
|
@ -43,6 +46,7 @@ export class EdgeJobController {
|
||||||
try {
|
try {
|
||||||
await this.EdgeJobService.updateEdgeJob(model);
|
await this.EdgeJobService.updateEdgeJob(model);
|
||||||
this.Notifications.success('Edge job successfully updated');
|
this.Notifications.success('Edge job successfully updated');
|
||||||
|
this.state.isEditorDirty = false;
|
||||||
this.$state.go('edge.jobs', {}, { reload: true });
|
this.$state.go('edge.jobs', {}, { reload: true });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.Notifications.error('Failure', err, 'Unable to update Edge job');
|
this.Notifications.error('Failure', err, 'Unable to update Edge job');
|
||||||
|
@ -121,6 +125,12 @@ export class EdgeJobController {
|
||||||
this.state.showEditorTab = true;
|
this.state.showEditorTab = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async uiCanExit() {
|
||||||
|
if (this.edgeJob.FileContent !== this.oldFileContent && this.state.isEditorDirty) {
|
||||||
|
return this.ModalService.confirmWebEditorDiscard();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async $onInit() {
|
async $onInit() {
|
||||||
const { id, tab } = this.$state.params;
|
const { id, tab } = this.$state.params;
|
||||||
this.state.activeTab = tab;
|
this.state.activeTab = tab;
|
||||||
|
@ -138,6 +148,7 @@ export class EdgeJobController {
|
||||||
]);
|
]);
|
||||||
|
|
||||||
edgeJob.FileContent = file.FileContent;
|
edgeJob.FileContent = file.FileContent;
|
||||||
|
this.oldFileContent = edgeJob.FileContent;
|
||||||
this.edgeJob = edgeJob;
|
this.edgeJob = edgeJob;
|
||||||
this.groups = groups;
|
this.groups = groups;
|
||||||
this.tags = tags;
|
this.tags = tags;
|
||||||
|
@ -152,5 +163,11 @@ export class EdgeJobController {
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.Notifications.error('Failure', err, 'Unable to retrieve endpoint list');
|
this.Notifications.error('Failure', err, 'Unable to retrieve endpoint list');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.$window.onbeforeunload = () => {
|
||||||
|
if (this.edgeJob.FileContent !== this.oldFileContent && this.state.isEditorDirty) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,8 @@ import _ from 'lodash-es';
|
||||||
|
|
||||||
export class CreateEdgeStackViewController {
|
export class CreateEdgeStackViewController {
|
||||||
/* @ngInject */
|
/* @ngInject */
|
||||||
constructor($state, EdgeStackService, EdgeGroupService, EdgeTemplateService, Notifications, FormHelper, $async) {
|
constructor($state, $window, ModalService, EdgeStackService, EdgeGroupService, EdgeTemplateService, Notifications, FormHelper, $async) {
|
||||||
Object.assign(this, { $state, EdgeStackService, EdgeGroupService, EdgeTemplateService, Notifications, FormHelper, $async });
|
Object.assign(this, { $state, $window, ModalService, EdgeStackService, EdgeGroupService, EdgeTemplateService, Notifications, FormHelper, $async });
|
||||||
|
|
||||||
this.formValues = {
|
this.formValues = {
|
||||||
Name: '',
|
Name: '',
|
||||||
|
@ -24,6 +24,7 @@ export class CreateEdgeStackViewController {
|
||||||
formValidationError: '',
|
formValidationError: '',
|
||||||
actionInProgress: false,
|
actionInProgress: false,
|
||||||
StackType: null,
|
StackType: null,
|
||||||
|
isEditorDirty: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
this.edgeGroups = null;
|
this.edgeGroups = null;
|
||||||
|
@ -41,6 +42,12 @@ export class CreateEdgeStackViewController {
|
||||||
this.onChangeMethod = this.onChangeMethod.bind(this);
|
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() {
|
async $onInit() {
|
||||||
try {
|
try {
|
||||||
this.edgeGroups = await this.EdgeGroupService.groups();
|
this.edgeGroups = await this.EdgeGroupService.groups();
|
||||||
|
@ -55,6 +62,12 @@ export class CreateEdgeStackViewController {
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.Notifications.error('Failure', err, 'Unable to retrieve Templates');
|
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() {
|
createStack() {
|
||||||
|
@ -97,6 +110,7 @@ export class CreateEdgeStackViewController {
|
||||||
await this.createStackByMethod(name, method);
|
await this.createStackByMethod(name, method);
|
||||||
|
|
||||||
this.Notifications.success('Stack successfully deployed');
|
this.Notifications.success('Stack successfully deployed');
|
||||||
|
this.state.isEditorDirty = false;
|
||||||
this.$state.go('edge.stacks');
|
this.$state.go('edge.stacks');
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.Notifications.error('Deployment error', err, 'Unable to deploy stack');
|
this.Notifications.error('Deployment error', err, 'Unable to deploy stack');
|
||||||
|
@ -149,5 +163,6 @@ export class CreateEdgeStackViewController {
|
||||||
|
|
||||||
editorUpdate(cm) {
|
editorUpdate(cm) {
|
||||||
this.formValues.StackFileContent = cm.getValue();
|
this.formValues.StackFileContent = cm.getValue();
|
||||||
|
this.state.isEditorDirty = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
model="$ctrl.formValues"
|
model="$ctrl.formValues"
|
||||||
action-in-progress="$ctrl.state.actionInProgress"
|
action-in-progress="$ctrl.state.actionInProgress"
|
||||||
submit-action="$ctrl.deployStack"
|
submit-action="$ctrl.deployStack"
|
||||||
|
is-editor-dirty="$ctrl.state.isEditorDirty"
|
||||||
></edit-edge-stack-form>
|
></edit-edge-stack-form>
|
||||||
</div>
|
</div>
|
||||||
</uib-tab>
|
</uib-tab>
|
||||||
|
|
|
@ -2,9 +2,11 @@ import _ from 'lodash-es';
|
||||||
|
|
||||||
export class EditEdgeStackViewController {
|
export class EditEdgeStackViewController {
|
||||||
/* @ngInject */
|
/* @ngInject */
|
||||||
constructor($async, $state, EdgeGroupService, EdgeStackService, EndpointService, Notifications) {
|
constructor($async, $state, $window, ModalService, EdgeGroupService, EdgeStackService, EndpointService, Notifications) {
|
||||||
this.$async = $async;
|
this.$async = $async;
|
||||||
this.$state = $state;
|
this.$state = $state;
|
||||||
|
this.$window = $window;
|
||||||
|
this.ModalService = ModalService;
|
||||||
this.EdgeGroupService = EdgeGroupService;
|
this.EdgeGroupService = EdgeGroupService;
|
||||||
this.EdgeStackService = EdgeStackService;
|
this.EdgeStackService = EdgeStackService;
|
||||||
this.EndpointService = EndpointService;
|
this.EndpointService = EndpointService;
|
||||||
|
@ -16,6 +18,7 @@ export class EditEdgeStackViewController {
|
||||||
this.state = {
|
this.state = {
|
||||||
actionInProgress: false,
|
actionInProgress: false,
|
||||||
activeTab: 0,
|
activeTab: 0,
|
||||||
|
isEditorDirty: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
this.deployStack = this.deployStack.bind(this);
|
this.deployStack = this.deployStack.bind(this);
|
||||||
|
@ -38,9 +41,22 @@ export class EditEdgeStackViewController {
|
||||||
EdgeGroups: this.stack.EdgeGroups,
|
EdgeGroups: this.stack.EdgeGroups,
|
||||||
Prune: this.stack.Prune,
|
Prune: this.stack.Prune,
|
||||||
};
|
};
|
||||||
|
this.oldFileContent = this.formValues.StackFileContent;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.Notifications.error('Failure', err, 'Unable to retrieve stack data');
|
this.Notifications.error('Failure', err, 'Unable to retrieve stack data');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.$window.onbeforeunload = () => {
|
||||||
|
if (this.formValues.StackFileContent !== this.oldFileContent && this.state.isEditorDirty) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
async uiCanExit() {
|
||||||
|
if (this.formValues.StackFileContent !== this.oldFileContent && this.state.isEditorDirty) {
|
||||||
|
return this.ModalService.confirmWebEditorDiscard();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
filterStackEndpoints(groupIds, groups) {
|
filterStackEndpoints(groupIds, groups) {
|
||||||
|
@ -64,6 +80,7 @@ export class EditEdgeStackViewController {
|
||||||
}
|
}
|
||||||
await this.EdgeStackService.updateStack(this.stack.Id, this.formValues);
|
await this.EdgeStackService.updateStack(this.stack.Id, this.formValues);
|
||||||
this.Notifications.success('Stack successfully deployed');
|
this.Notifications.success('Stack successfully deployed');
|
||||||
|
this.state.isEditorDirty = false;
|
||||||
this.$state.go('edge.stacks');
|
this.$state.go('edge.stacks');
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.Notifications.error('Deployment error', err, 'Unable to deploy stack');
|
this.Notifications.error('Deployment error', err, 'Unable to deploy stack');
|
||||||
|
|
|
@ -5,5 +5,6 @@ angular.module('portainer.kubernetes').component('kubernetesConfigurationData',
|
||||||
formValues: '=',
|
formValues: '=',
|
||||||
isValid: '=',
|
isValid: '=',
|
||||||
isCreation: '=',
|
isCreation: '=',
|
||||||
|
isEditorDirty: '=',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -44,6 +44,7 @@ class KubernetesConfigurationDataController {
|
||||||
|
|
||||||
async editorUpdateAsync(cm) {
|
async editorUpdateAsync(cm) {
|
||||||
this.formValues.DataYaml = cm.getValue();
|
this.formValues.DataYaml = cm.getValue();
|
||||||
|
this.isEditorDirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
editorUpdate(cm) {
|
editorUpdate(cm) {
|
||||||
|
|
|
@ -114,11 +114,13 @@
|
||||||
<a href="https://kubernetes.io/docs/concepts/configuration/secret/#secret-types" target="_blank">official documentation</a>.
|
<a href="https://kubernetes.io/docs/concepts/configuration/secret/#secret-types" target="_blank">official documentation</a>.
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<kubernetes-configuration-data
|
<kubernetes-configuration-data
|
||||||
ng-if="ctrl.formValues"
|
ng-if="ctrl.formValues"
|
||||||
form-values="ctrl.formValues"
|
form-values="ctrl.formValues"
|
||||||
is-valid="ctrl.state.isDataValid"
|
is-valid="ctrl.state.isDataValid"
|
||||||
is-creation="true"
|
is-creation="true"
|
||||||
|
is-editor-dirty="ctrl.state.isEditorDirty"
|
||||||
></kubernetes-configuration-data>
|
></kubernetes-configuration-data>
|
||||||
|
|
||||||
<!-- actions -->
|
<!-- actions -->
|
||||||
|
|
|
@ -6,9 +6,11 @@ import KubernetesConfigurationHelper from 'Kubernetes/helpers/configurationHelpe
|
||||||
|
|
||||||
class KubernetesCreateConfigurationController {
|
class KubernetesCreateConfigurationController {
|
||||||
/* @ngInject */
|
/* @ngInject */
|
||||||
constructor($async, $state, Notifications, Authentication, KubernetesConfigurationService, KubernetesResourcePoolService, KubernetesNamespaceHelper) {
|
constructor($async, $state, $window, ModalService, Notifications, Authentication, KubernetesConfigurationService, KubernetesResourcePoolService, KubernetesNamespaceHelper) {
|
||||||
this.$async = $async;
|
this.$async = $async;
|
||||||
this.$state = $state;
|
this.$state = $state;
|
||||||
|
this.$window = $window;
|
||||||
|
this.ModalService = ModalService;
|
||||||
this.Notifications = Notifications;
|
this.Notifications = Notifications;
|
||||||
this.Authentication = Authentication;
|
this.Authentication = Authentication;
|
||||||
this.KubernetesConfigurationService = KubernetesConfigurationService;
|
this.KubernetesConfigurationService = KubernetesConfigurationService;
|
||||||
|
@ -47,6 +49,7 @@ class KubernetesCreateConfigurationController {
|
||||||
}
|
}
|
||||||
await this.KubernetesConfigurationService.create(this.formValues);
|
await this.KubernetesConfigurationService.create(this.formValues);
|
||||||
this.Notifications.success('Configuration succesfully created');
|
this.Notifications.success('Configuration succesfully created');
|
||||||
|
this.state.isEditorDirty = false;
|
||||||
this.$state.go('kubernetes.configurations');
|
this.$state.go('kubernetes.configurations');
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.Notifications.error('Failure', err, 'Unable to create configuration');
|
this.Notifications.error('Failure', err, 'Unable to create configuration');
|
||||||
|
@ -71,12 +74,19 @@ class KubernetesCreateConfigurationController {
|
||||||
return this.$async(this.getConfigurationsAsync);
|
return this.$async(this.getConfigurationsAsync);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async uiCanExit() {
|
||||||
|
if (!this.formValues.IsSimple && this.formValues.DataYaml && this.state.isEditorDirty) {
|
||||||
|
return this.ModalService.confirmWebEditorDiscard();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async onInit() {
|
async onInit() {
|
||||||
this.state = {
|
this.state = {
|
||||||
actionInProgress: false,
|
actionInProgress: false,
|
||||||
viewReady: false,
|
viewReady: false,
|
||||||
alreadyExist: false,
|
alreadyExist: false,
|
||||||
isDataValid: true,
|
isDataValid: true,
|
||||||
|
isEditorDirty: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
this.formValues = new KubernetesConfigurationFormValues();
|
this.formValues = new KubernetesConfigurationFormValues();
|
||||||
|
@ -93,6 +103,12 @@ class KubernetesCreateConfigurationController {
|
||||||
} finally {
|
} finally {
|
||||||
this.state.viewReady = true;
|
this.state.viewReady = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.$window.onbeforeunload = () => {
|
||||||
|
if (!this.formValues.IsSimple && this.formValues.DataYaml && this.state.isEditorDirty) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
$onInit() {
|
$onInit() {
|
||||||
|
|
|
@ -82,6 +82,7 @@
|
||||||
form-values="ctrl.formValues"
|
form-values="ctrl.formValues"
|
||||||
is-valid="ctrl.state.isDataValid"
|
is-valid="ctrl.state.isDataValid"
|
||||||
is-creation="false"
|
is-creation="false"
|
||||||
|
is-editor-dirty="ctrl.state.isEditorDirty"
|
||||||
></kubernetes-configuration-data>
|
></kubernetes-configuration-data>
|
||||||
|
|
||||||
<!-- actions -->
|
<!-- actions -->
|
||||||
|
|
|
@ -11,6 +11,7 @@ class KubernetesConfigurationController {
|
||||||
constructor(
|
constructor(
|
||||||
$async,
|
$async,
|
||||||
$state,
|
$state,
|
||||||
|
$window,
|
||||||
clipboard,
|
clipboard,
|
||||||
Notifications,
|
Notifications,
|
||||||
LocalStorage,
|
LocalStorage,
|
||||||
|
@ -25,6 +26,7 @@ class KubernetesConfigurationController {
|
||||||
) {
|
) {
|
||||||
this.$async = $async;
|
this.$async = $async;
|
||||||
this.$state = $state;
|
this.$state = $state;
|
||||||
|
this.$window = $window;
|
||||||
this.clipboard = clipboard;
|
this.clipboard = clipboard;
|
||||||
this.Notifications = Notifications;
|
this.Notifications = Notifications;
|
||||||
this.LocalStorage = LocalStorage;
|
this.LocalStorage = LocalStorage;
|
||||||
|
@ -143,6 +145,7 @@ class KubernetesConfigurationController {
|
||||||
this.formValues.Id = this.configuration.Id;
|
this.formValues.Id = this.configuration.Id;
|
||||||
this.formValues.Name = this.configuration.Name;
|
this.formValues.Name = this.configuration.Name;
|
||||||
this.formValues.Type = this.configuration.Type;
|
this.formValues.Type = this.configuration.Type;
|
||||||
|
this.oldDataYaml = this.formValues.DataYaml;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.Notifications.error('Failure', err, 'Unable to retrieve configuration');
|
this.Notifications.error('Failure', err, 'Unable to retrieve configuration');
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -221,6 +224,12 @@ class KubernetesConfigurationController {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async uiCanExit() {
|
||||||
|
if (!this.formValues.IsSimple && this.formValues.DataYaml !== this.oldDataYaml && this.state.isEditorDirty) {
|
||||||
|
return this.ModalService.confirmWebEditorDiscard();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async onInit() {
|
async onInit() {
|
||||||
try {
|
try {
|
||||||
this.state = {
|
this.state = {
|
||||||
|
@ -234,6 +243,7 @@ class KubernetesConfigurationController {
|
||||||
activeTab: 0,
|
activeTab: 0,
|
||||||
currentName: this.$state.$current.name,
|
currentName: this.$state.$current.name,
|
||||||
isDataValid: true,
|
isDataValid: true,
|
||||||
|
isEditorDirty: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
this.state.activeTab = this.LocalStorage.getActiveTab('configuration');
|
this.state.activeTab = this.LocalStorage.getActiveTab('configuration');
|
||||||
|
@ -252,6 +262,12 @@ class KubernetesConfigurationController {
|
||||||
} finally {
|
} finally {
|
||||||
this.state.viewReady = true;
|
this.state.viewReady = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.$window.onbeforeunload = () => {
|
||||||
|
if (!this.formValues.IsSimple && this.formValues.DataYaml !== this.oldDataYaml && this.state.isEditorDirty) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
$onInit() {
|
$onInit() {
|
||||||
|
|
|
@ -5,9 +5,11 @@ import { KubernetesDeployManifestTypes } from 'Kubernetes/models/deploy';
|
||||||
|
|
||||||
class KubernetesDeployController {
|
class KubernetesDeployController {
|
||||||
/* @ngInject */
|
/* @ngInject */
|
||||||
constructor($async, $state, Notifications, EndpointProvider, KubernetesResourcePoolService, StackService) {
|
constructor($async, $state, $window, ModalService, Notifications, EndpointProvider, KubernetesResourcePoolService, StackService) {
|
||||||
this.$async = $async;
|
this.$async = $async;
|
||||||
this.$state = $state;
|
this.$state = $state;
|
||||||
|
this.$window = $window;
|
||||||
|
this.ModalService = ModalService;
|
||||||
this.Notifications = Notifications;
|
this.Notifications = Notifications;
|
||||||
this.EndpointProvider = EndpointProvider;
|
this.EndpointProvider = EndpointProvider;
|
||||||
this.KubernetesResourcePoolService = KubernetesResourcePoolService;
|
this.KubernetesResourcePoolService = KubernetesResourcePoolService;
|
||||||
|
@ -26,6 +28,7 @@ class KubernetesDeployController {
|
||||||
|
|
||||||
async editorUpdateAsync(cm) {
|
async editorUpdateAsync(cm) {
|
||||||
this.formValues.EditorContent = cm.getValue();
|
this.formValues.EditorContent = cm.getValue();
|
||||||
|
this.state.isEditorDirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
editorUpdate(cm) {
|
editorUpdate(cm) {
|
||||||
|
@ -46,6 +49,7 @@ class KubernetesDeployController {
|
||||||
const compose = this.state.DeployType === this.ManifestDeployTypes.COMPOSE;
|
const compose = this.state.DeployType === this.ManifestDeployTypes.COMPOSE;
|
||||||
await this.StackService.kubernetesDeploy(this.endpointId, this.formValues.Namespace, this.formValues.EditorContent, compose);
|
await this.StackService.kubernetesDeploy(this.endpointId, this.formValues.Namespace, this.formValues.EditorContent, compose);
|
||||||
this.Notifications.success('Manifest successfully deployed');
|
this.Notifications.success('Manifest successfully deployed');
|
||||||
|
this.state.isEditorDirty = false;
|
||||||
this.$state.go('kubernetes.applications');
|
this.$state.go('kubernetes.applications');
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.Notifications.error('Unable to deploy manifest', err, 'Unable to deploy resources');
|
this.Notifications.error('Unable to deploy manifest', err, 'Unable to deploy resources');
|
||||||
|
@ -73,12 +77,19 @@ class KubernetesDeployController {
|
||||||
return this.$async(this.getNamespacesAsync);
|
return this.$async(this.getNamespacesAsync);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async uiCanExit() {
|
||||||
|
if (this.formValues.EditorContent && this.state.isEditorDirty) {
|
||||||
|
return this.ModalService.confirmWebEditorDiscard();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async onInit() {
|
async onInit() {
|
||||||
this.state = {
|
this.state = {
|
||||||
DeployType: KubernetesDeployManifestTypes.KUBERNETES,
|
DeployType: KubernetesDeployManifestTypes.KUBERNETES,
|
||||||
tabLogsDisabled: true,
|
tabLogsDisabled: true,
|
||||||
activeTab: 0,
|
activeTab: 0,
|
||||||
viewReady: false,
|
viewReady: false,
|
||||||
|
isEditorDirty: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
this.formValues = {};
|
this.formValues = {};
|
||||||
|
@ -88,6 +99,12 @@ class KubernetesDeployController {
|
||||||
await this.getNamespaces();
|
await this.getNamespaces();
|
||||||
|
|
||||||
this.state.viewReady = true;
|
this.state.viewReady = true;
|
||||||
|
|
||||||
|
this.$window.onbeforeunload = () => {
|
||||||
|
if (this.formValues.EditorContent && this.state.isEditorDirty) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
$onInit() {
|
$onInit() {
|
||||||
|
|
|
@ -37,6 +37,23 @@ angular.module('portainer.app').factory('ModalService', [
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
service.confirmWebEditorDiscard = confirmWebEditorDiscard;
|
||||||
|
function confirmWebEditorDiscard() {
|
||||||
|
const options = {
|
||||||
|
title: 'Are you sure ?',
|
||||||
|
message: 'You currently have unsaved changes in the editor. Are you sure you want to leave?',
|
||||||
|
buttons: {
|
||||||
|
confirm: {
|
||||||
|
label: 'Yes',
|
||||||
|
className: 'btn-danger',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
service.confirm({ ...options, callback: (confirmed) => resolve(confirmed) });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
service.confirmAsync = confirmAsync;
|
service.confirmAsync = confirmAsync;
|
||||||
function confirmAsync(options) {
|
function confirmAsync(options) {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
|
|
|
@ -3,8 +3,20 @@ import { AccessControlFormData } from 'Portainer/components/accessControlForm/po
|
||||||
|
|
||||||
class CreateCustomTemplateViewController {
|
class CreateCustomTemplateViewController {
|
||||||
/* @ngInject */
|
/* @ngInject */
|
||||||
constructor($async, $state, Authentication, CustomTemplateService, FormValidator, Notifications, ResourceControlService, StackService, StateManager) {
|
constructor($async, $state, $window, Authentication, ModalService, CustomTemplateService, FormValidator, Notifications, ResourceControlService, StackService, StateManager) {
|
||||||
Object.assign(this, { $async, $state, Authentication, CustomTemplateService, FormValidator, Notifications, ResourceControlService, StackService, StateManager });
|
Object.assign(this, {
|
||||||
|
$async,
|
||||||
|
$state,
|
||||||
|
$window,
|
||||||
|
Authentication,
|
||||||
|
ModalService,
|
||||||
|
CustomTemplateService,
|
||||||
|
FormValidator,
|
||||||
|
Notifications,
|
||||||
|
ResourceControlService,
|
||||||
|
StackService,
|
||||||
|
StateManager,
|
||||||
|
});
|
||||||
|
|
||||||
this.formValues = {
|
this.formValues = {
|
||||||
Title: '',
|
Title: '',
|
||||||
|
@ -29,6 +41,7 @@ class CreateCustomTemplateViewController {
|
||||||
actionInProgress: false,
|
actionInProgress: false,
|
||||||
fromStack: false,
|
fromStack: false,
|
||||||
loading: true,
|
loading: true,
|
||||||
|
isEditorDirty: false,
|
||||||
};
|
};
|
||||||
this.templates = [];
|
this.templates = [];
|
||||||
|
|
||||||
|
@ -73,6 +86,7 @@ class CreateCustomTemplateViewController {
|
||||||
await this.ResourceControlService.applyResourceControl(userId, accessControlData, customTemplate.ResourceControl);
|
await this.ResourceControlService.applyResourceControl(userId, accessControlData, customTemplate.ResourceControl);
|
||||||
|
|
||||||
this.Notifications.success('Custom template successfully created');
|
this.Notifications.success('Custom template successfully created');
|
||||||
|
this.state.isEditorDirty = false;
|
||||||
this.$state.go('docker.templates.custom');
|
this.$state.go('docker.templates.custom');
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.Notifications.error('Failure', err, 'A template with the same name already exists');
|
this.Notifications.error('Failure', err, 'A template with the same name already exists');
|
||||||
|
@ -133,6 +147,7 @@ class CreateCustomTemplateViewController {
|
||||||
|
|
||||||
editorUpdate(cm) {
|
editorUpdate(cm) {
|
||||||
this.formValues.FileContent = cm.getValue();
|
this.formValues.FileContent = cm.getValue();
|
||||||
|
this.state.isEditorDirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
async $onInit() {
|
async $onInit() {
|
||||||
|
@ -161,6 +176,18 @@ class CreateCustomTemplateViewController {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.state.loading = false;
|
this.state.loading = false;
|
||||||
|
|
||||||
|
this.$window.onbeforeunload = () => {
|
||||||
|
if (this.state.Method === 'editor' && this.formValues.FileContent && this.state.isEditorDirty) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
async uiCanExit() {
|
||||||
|
if (this.state.Method === 'editor' && this.formValues.FileContent && this.state.isEditorDirty) {
|
||||||
|
return this.ModalService.confirmWebEditorDiscard();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,12 +5,13 @@ import { ResourceControlViewModel } from 'Portainer/models/resourceControl/resou
|
||||||
|
|
||||||
class EditCustomTemplateViewController {
|
class EditCustomTemplateViewController {
|
||||||
/* @ngInject */
|
/* @ngInject */
|
||||||
constructor($async, $state, Authentication, CustomTemplateService, FormValidator, Notifications, ResourceControlService) {
|
constructor($async, $state, $window, ModalService, Authentication, CustomTemplateService, FormValidator, Notifications, ResourceControlService) {
|
||||||
Object.assign(this, { $async, $state, Authentication, CustomTemplateService, FormValidator, Notifications, ResourceControlService });
|
Object.assign(this, { $async, $state, $window, ModalService, Authentication, CustomTemplateService, FormValidator, Notifications, ResourceControlService });
|
||||||
|
|
||||||
this.formValues = null;
|
this.formValues = null;
|
||||||
this.state = {
|
this.state = {
|
||||||
formValidationError: '',
|
formValidationError: '',
|
||||||
|
isEditorDirty: false,
|
||||||
};
|
};
|
||||||
this.templates = [];
|
this.templates = [];
|
||||||
|
|
||||||
|
@ -32,6 +33,7 @@ class EditCustomTemplateViewController {
|
||||||
]);
|
]);
|
||||||
template.FileContent = file;
|
template.FileContent = file;
|
||||||
this.formValues = template;
|
this.formValues = template;
|
||||||
|
this.oldFileContent = this.formValues.FileContent;
|
||||||
this.formValues.ResourceControl = new ResourceControlViewModel(template.ResourceControl);
|
this.formValues.ResourceControl = new ResourceControlViewModel(template.ResourceControl);
|
||||||
this.formValues.AccessControlData = new AccessControlFormData();
|
this.formValues.AccessControlData = new AccessControlFormData();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -84,6 +86,7 @@ class EditCustomTemplateViewController {
|
||||||
await this.ResourceControlService.applyResourceControl(userId, this.formValues.AccessControlData, this.formValues.ResourceControl);
|
await this.ResourceControlService.applyResourceControl(userId, this.formValues.AccessControlData, this.formValues.ResourceControl);
|
||||||
|
|
||||||
this.Notifications.success('Custom template successfully updated');
|
this.Notifications.success('Custom template successfully updated');
|
||||||
|
this.state.isEditorDirty = false;
|
||||||
this.$state.go('docker.templates.custom');
|
this.$state.go('docker.templates.custom');
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.Notifications.error('Failure', err, 'Unable to update custom template');
|
this.Notifications.error('Failure', err, 'Unable to update custom template');
|
||||||
|
@ -93,7 +96,14 @@ class EditCustomTemplateViewController {
|
||||||
}
|
}
|
||||||
|
|
||||||
editorUpdate(cm) {
|
editorUpdate(cm) {
|
||||||
this.formValues.fileContent = cm.getValue();
|
this.formValues.FileContent = cm.getValue();
|
||||||
|
this.state.isEditorDirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
async uiCanExit() {
|
||||||
|
if (this.formValues.FileContent !== this.oldFileContent && this.state.isEditorDirty) {
|
||||||
|
return this.ModalService.confirmWebEditorDiscard();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async $onInit() {
|
async $onInit() {
|
||||||
|
@ -104,6 +114,12 @@ class EditCustomTemplateViewController {
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.Notifications.error('Failure loading', err, 'Failed loading custom templates');
|
this.Notifications.error('Failure loading', err, 'Failed loading custom templates');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.$window.onbeforeunload = () => {
|
||||||
|
if (this.formValues.FileContent !== this.oldFileContent && this.state.isEditorDirty) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,8 @@ angular
|
||||||
$scope,
|
$scope,
|
||||||
$state,
|
$state,
|
||||||
$async,
|
$async,
|
||||||
|
$window,
|
||||||
|
ModalService,
|
||||||
StackService,
|
StackService,
|
||||||
Authentication,
|
Authentication,
|
||||||
Notifications,
|
Notifications,
|
||||||
|
@ -42,6 +44,13 @@ angular
|
||||||
StackType: null,
|
StackType: null,
|
||||||
editorYamlValidationError: '',
|
editorYamlValidationError: '',
|
||||||
uploadYamlValidationError: '',
|
uploadYamlValidationError: '',
|
||||||
|
isEditorDirty: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
$window.onbeforeunload = () => {
|
||||||
|
if ($scope.state.Method === 'editor' && $scope.formValues.StackFileContent && $scope.state.isEditorDirty) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.addEnvironmentVariable = function () {
|
$scope.addEnvironmentVariable = function () {
|
||||||
|
@ -148,6 +157,7 @@ angular
|
||||||
})
|
})
|
||||||
.then(function success() {
|
.then(function success() {
|
||||||
Notifications.success('Stack successfully deployed');
|
Notifications.success('Stack successfully deployed');
|
||||||
|
$scope.state.isEditorDirty = false;
|
||||||
$state.go('docker.stacks');
|
$state.go('docker.stacks');
|
||||||
})
|
})
|
||||||
.catch(function error(err) {
|
.catch(function error(err) {
|
||||||
|
@ -161,6 +171,7 @@ angular
|
||||||
$scope.editorUpdate = function (cm) {
|
$scope.editorUpdate = function (cm) {
|
||||||
$scope.formValues.StackFileContent = cm.getValue();
|
$scope.formValues.StackFileContent = cm.getValue();
|
||||||
$scope.state.editorYamlValidationError = StackHelper.validateYAML($scope.formValues.StackFileContent, $scope.containerNames);
|
$scope.state.editorYamlValidationError = StackHelper.validateYAML($scope.formValues.StackFileContent, $scope.containerNames);
|
||||||
|
$scope.state.isEditorDirty = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
async function onFileLoadAsync(event) {
|
async function onFileLoadAsync(event) {
|
||||||
|
@ -221,5 +232,11 @@ angular
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.uiCanExit = async function () {
|
||||||
|
if ($scope.state.Method === 'editor' && $scope.formValues.StackFileContent && $scope.state.isEditorDirty) {
|
||||||
|
return ModalService.confirmWebEditorDiscard();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
initView();
|
initView();
|
||||||
});
|
});
|
||||||
|
|
|
@ -3,6 +3,7 @@ angular.module('portainer.app').controller('StackController', [
|
||||||
'$q',
|
'$q',
|
||||||
'$scope',
|
'$scope',
|
||||||
'$state',
|
'$state',
|
||||||
|
'$window',
|
||||||
'$transition$',
|
'$transition$',
|
||||||
'StackService',
|
'StackService',
|
||||||
'NodeService',
|
'NodeService',
|
||||||
|
@ -18,11 +19,13 @@ angular.module('portainer.app').controller('StackController', [
|
||||||
'GroupService',
|
'GroupService',
|
||||||
'ModalService',
|
'ModalService',
|
||||||
'StackHelper',
|
'StackHelper',
|
||||||
|
'ContainerHelper',
|
||||||
function (
|
function (
|
||||||
$async,
|
$async,
|
||||||
$q,
|
$q,
|
||||||
$scope,
|
$scope,
|
||||||
$state,
|
$state,
|
||||||
|
$window,
|
||||||
$transition$,
|
$transition$,
|
||||||
StackService,
|
StackService,
|
||||||
NodeService,
|
NodeService,
|
||||||
|
@ -46,6 +49,7 @@ angular.module('portainer.app').controller('StackController', [
|
||||||
externalStack: false,
|
externalStack: false,
|
||||||
showEditorTab: false,
|
showEditorTab: false,
|
||||||
yamlError: false,
|
yamlError: false,
|
||||||
|
isEditorDirty: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.formValues = {
|
$scope.formValues = {
|
||||||
|
@ -53,6 +57,12 @@ angular.module('portainer.app').controller('StackController', [
|
||||||
Endpoint: null,
|
Endpoint: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$window.onbeforeunload = () => {
|
||||||
|
if ($scope.stackFileContent && $scope.state.isEditorDirty) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
$scope.duplicateStack = function duplicateStack(name, endpointId) {
|
$scope.duplicateStack = function duplicateStack(name, endpointId) {
|
||||||
var stack = $scope.stack;
|
var stack = $scope.stack;
|
||||||
var env = FormHelper.removeInvalidEnvVars(stack.Env);
|
var env = FormHelper.removeInvalidEnvVars(stack.Env);
|
||||||
|
@ -171,6 +181,7 @@ angular.module('portainer.app').controller('StackController', [
|
||||||
StackService.updateStack(stack, stackFile, env, prune)
|
StackService.updateStack(stack, stackFile, env, prune)
|
||||||
.then(function success() {
|
.then(function success() {
|
||||||
Notifications.success('Stack successfully deployed');
|
Notifications.success('Stack successfully deployed');
|
||||||
|
$scope.state.isEditorDirty = false;
|
||||||
$state.reload();
|
$state.reload();
|
||||||
})
|
})
|
||||||
.catch(function error(err) {
|
.catch(function error(err) {
|
||||||
|
@ -190,8 +201,12 @@ angular.module('portainer.app').controller('StackController', [
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.editorUpdate = function (cm) {
|
$scope.editorUpdate = function (cm) {
|
||||||
|
if ($scope.stackFileContent !== cm.getValue()) {
|
||||||
|
$scope.state.isEditorDirty = true;
|
||||||
|
}
|
||||||
$scope.stackFileContent = cm.getValue();
|
$scope.stackFileContent = cm.getValue();
|
||||||
$scope.state.yamlError = StackHelper.validateYAML($scope.stackFileContent, $scope.containerNames);
|
$scope.state.yamlError = StackHelper.validateYAML($scope.stackFileContent, $scope.containerNames);
|
||||||
|
$scope.state.isEditorDirty = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.stopStack = stopStack;
|
$scope.stopStack = stopStack;
|
||||||
|
@ -369,6 +384,12 @@ angular.module('portainer.app').controller('StackController', [
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.uiCanExit = async function () {
|
||||||
|
if ($scope.stackFileContent && $scope.state.isEditorDirty) {
|
||||||
|
return ModalService.confirmWebEditorDiscard();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
async function initView() {
|
async function initView() {
|
||||||
var stackName = $transition$.params().name;
|
var stackName = $transition$.params().name;
|
||||||
$scope.stackName = stackName;
|
$scope.stackName = stackName;
|
||||||
|
|
Loading…
Reference in New Issue