summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/environments/mixins
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-25 09:08:11 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-25 09:08:11 +0000
commit5064bf8c5647d4c4430cbb4d097cf1592416de29 (patch)
treed051bf2abe2cc7061b3a7facb6669a56ccb9cf54 /app/assets/javascripts/environments/mixins
parent9c83aadd2604e7e6cb1f84683f951e6b12872618 (diff)
downloadgitlab-ce-5064bf8c5647d4c4430cbb4d097cf1592416de29.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/environments/mixins')
-rw-r--r--app/assets/javascripts/environments/mixins/environments_mixin.js86
1 files changed, 65 insertions, 21 deletions
diff --git a/app/assets/javascripts/environments/mixins/environments_mixin.js b/app/assets/javascripts/environments/mixins/environments_mixin.js
index 1c5884b541c..4fadecdd3e9 100644
--- a/app/assets/javascripts/environments/mixins/environments_mixin.js
+++ b/app/assets/javascripts/environments/mixins/environments_mixin.js
@@ -27,6 +27,10 @@ export default {
data() {
const store = new EnvironmentsStore();
+ const isDetailView = document.body.contains(
+ document.getElementById('environments-detail-view'),
+ );
+
return {
store,
state: store.state,
@@ -36,7 +40,9 @@ export default {
page: getParameterByName('page') || '1',
requestData: {},
environmentInStopModal: {},
+ environmentInDeleteModal: {},
environmentInRollbackModal: {},
+ isDetailView,
};
},
@@ -121,6 +127,10 @@ export default {
this.environmentInStopModal = environment;
},
+ updateDeleteModal(environment) {
+ this.environmentInDeleteModal = environment;
+ },
+
updateRollbackModal(environment) {
this.environmentInRollbackModal = environment;
},
@@ -133,6 +143,30 @@ export default {
this.postAction({ endpoint, errorMessage });
},
+ deleteEnvironment(environment) {
+ const endpoint = environment.delete_path;
+ const mountedToShow = environment.mounted_to_show;
+ const errorMessage = s__(
+ 'Environments|An error occurred while deleting the environment. Check if the environment stopped; if not, stop it and try again.',
+ );
+
+ this.service
+ .deleteAction(endpoint)
+ .then(() => {
+ if (!mountedToShow) {
+ // Reload as a first solution to bust the ETag cache
+ window.location.reload();
+ return;
+ }
+ const url = window.location.href.split('/');
+ url.pop();
+ window.location.href = url.join('/');
+ })
+ .catch(() => {
+ Flash(errorMessage);
+ });
+ },
+
rollbackEnvironment(environment) {
const { retryUrl, isLastDeployment } = environment;
const errorMessage = isLastDeployment
@@ -178,36 +212,42 @@ export default {
this.service = new EnvironmentsService(this.endpoint);
this.requestData = { page: this.page, scope: this.scope, nested: true };
- this.poll = new Poll({
- resource: this.service,
- method: 'fetchEnvironments',
- data: this.requestData,
- successCallback: this.successCallback,
- errorCallback: this.errorCallback,
- notificationCallback: isMakingRequest => {
- this.isMakingRequest = isMakingRequest;
- },
- });
-
- if (!Visibility.hidden()) {
- this.isLoading = true;
- this.poll.makeRequest();
- } else {
- this.fetchEnvironments();
- }
+ if (!this.isDetailView) {
+ this.poll = new Poll({
+ resource: this.service,
+ method: 'fetchEnvironments',
+ data: this.requestData,
+ successCallback: this.successCallback,
+ errorCallback: this.errorCallback,
+ notificationCallback: isMakingRequest => {
+ this.isMakingRequest = isMakingRequest;
+ },
+ });
- Visibility.change(() => {
if (!Visibility.hidden()) {
- this.poll.restart();
+ this.isLoading = true;
+ this.poll.makeRequest();
} else {
- this.poll.stop();
+ this.fetchEnvironments();
}
- });
+
+ Visibility.change(() => {
+ if (!Visibility.hidden()) {
+ this.poll.restart();
+ } else {
+ this.poll.stop();
+ }
+ });
+ }
eventHub.$on('postAction', this.postAction);
+
eventHub.$on('requestStopEnvironment', this.updateStopModal);
eventHub.$on('stopEnvironment', this.stopEnvironment);
+ eventHub.$on('requestDeleteEnvironment', this.updateDeleteModal);
+ eventHub.$on('deleteEnvironment', this.deleteEnvironment);
+
eventHub.$on('requestRollbackEnvironment', this.updateRollbackModal);
eventHub.$on('rollbackEnvironment', this.rollbackEnvironment);
@@ -216,9 +256,13 @@ export default {
beforeDestroy() {
eventHub.$off('postAction', this.postAction);
+
eventHub.$off('requestStopEnvironment', this.updateStopModal);
eventHub.$off('stopEnvironment', this.stopEnvironment);
+ eventHub.$off('requestDeleteEnvironment', this.updateDeleteModal);
+ eventHub.$off('deleteEnvironment', this.deleteEnvironment);
+
eventHub.$off('requestRollbackEnvironment', this.updateRollbackModal);
eventHub.$off('rollbackEnvironment', this.rollbackEnvironment);