From 2f18f2eb8752cfb2f86aa4edfcd3626f3c53c100 Mon Sep 17 00:00:00 2001
From: fhanportainer <79428273+fhanportainer@users.noreply.github.com>
Date: Wed, 1 Sep 2021 10:48:02 +1200
Subject: [PATCH] fix(stack): git form validation improvement. EE-1291 EE-1292
(#5440)
* fix(stack): git form validation improvement. EE-1291 EE-1292
* feedback update
* moved comparison function to OnChange
* fixed on change method in environment variable panel.
* using angularJs.ToJson to strip out $$haskey in formValues
---
.../stack-redeploy-git-form.controller.js | 36 ++++++++++++++-----
.../stack-redeploy-git-form.html | 8 ++---
2 files changed, 31 insertions(+), 13 deletions(-)
diff --git a/app/portainer/components/forms/stack-redeploy-git-form/stack-redeploy-git-form.controller.js b/app/portainer/components/forms/stack-redeploy-git-form/stack-redeploy-git-form.controller.js
index 717c15333..1d21ae75c 100644
--- a/app/portainer/components/forms/stack-redeploy-git-form/stack-redeploy-git-form.controller.js
+++ b/app/portainer/components/forms/stack-redeploy-git-form/stack-redeploy-git-form.controller.js
@@ -1,4 +1,5 @@
import uuidv4 from 'uuid/v4';
+
class StackRedeployGitFormController {
/* @ngInject */
constructor($async, $state, StackService, ModalService, Notifications, WebhookHelper, FormHelper) {
@@ -15,6 +16,7 @@ class StackRedeployGitFormController {
redeployInProgress: false,
showConfig: false,
isEdit: false,
+ hasUnsavedChanges: false,
};
this.formValues = {
@@ -34,11 +36,8 @@ class StackRedeployGitFormController {
this.onChange = this.onChange.bind(this);
this.onChangeRef = this.onChangeRef.bind(this);
- this.handleEnvVarChange = this.handleEnvVarChange.bind(this);
- }
-
- onChangeRef(value) {
- this.onChange({ RefName: value });
+ this.onChangeAutoUpdate = this.onChangeAutoUpdate.bind(this);
+ this.onChangeEnvVar = this.onChangeEnvVar.bind(this);
}
onChange(values) {
@@ -46,6 +45,25 @@ class StackRedeployGitFormController {
...this.formValues,
...values,
};
+
+ this.state.hasUnsavedChanges = angular.toJson(this.savedFormValues) !== angular.toJson(this.formValues);
+ }
+
+ onChangeRef(value) {
+ this.onChange({ RefName: value });
+ }
+
+ onChangeAutoUpdate(values) {
+ this.onChange({
+ AutoUpdate: {
+ ...this.formValues.AutoUpdate,
+ ...values,
+ },
+ });
+ }
+
+ onChangeEnvVar(value) {
+ this.onChange({ Env: value });
}
async submit() {
@@ -83,6 +101,8 @@ class StackRedeployGitFormController {
try {
this.state.inProgress = true;
await this.StackService.updateGitStackSettings(this.stack.Id, this.stack.EndpointId, this.FormHelper.removeInvalidEnvVars(this.formValues.Env), this.formValues);
+ this.savedFormValues = angular.copy(this.formValues);
+ this.state.hasUnsavedChanges = false;
this.Notifications.success('Save stack settings successfully');
} catch (err) {
this.Notifications.error('Failure', err, 'Unable to save stack settings');
@@ -96,10 +116,6 @@ class StackRedeployGitFormController {
return this.state.inProgress || this.state.redeployInProgress;
}
- handleEnvVarChange(value) {
- this.formValues.Env = value;
- }
-
$onInit() {
this.formValues.RefName = this.model.ReferenceName;
this.formValues.Env = this.stack.Env;
@@ -125,6 +141,8 @@ class StackRedeployGitFormController {
this.formValues.RepositoryAuthentication = true;
this.state.isEdit = true;
}
+
+ this.savedFormValues = angular.copy(this.formValues);
}
}
diff --git a/app/portainer/components/forms/stack-redeploy-git-form/stack-redeploy-git-form.html b/app/portainer/components/forms/stack-redeploy-git-form/stack-redeploy-git-form.html
index 340400573..07b85c51f 100644
--- a/app/portainer/components/forms/stack-redeploy-git-form/stack-redeploy-git-form.html
+++ b/app/portainer/components/forms/stack-redeploy-git-form/stack-redeploy-git-form.html
@@ -18,7 +18,7 @@
-
@@ -40,14 +40,14 @@