summaryrefslogtreecommitdiff
path: root/app/assets/javascripts
diff options
context:
space:
mode:
authorFilipa Lacerda <filipa@gitlab.com>2017-10-04 12:48:34 +0100
committerFilipa Lacerda <filipa@gitlab.com>2017-10-04 12:49:04 +0100
commit5a2b43fcc6490847fae39a1dce38ce13d5860da3 (patch)
treea559397938e09ae131d1475b8244e78b5b5d5f09 /app/assets/javascripts
parent8cff79bc1dd8802843f977177b433838f0ba76b0 (diff)
downloadgitlab-ce-5a2b43fcc6490847fae39a1dce38ce13d5860da3.tar.gz
Adjustments to polling & forms
Diffstat (limited to 'app/assets/javascripts')
-rw-r--r--app/assets/javascripts/clusters.js72
1 files changed, 28 insertions, 44 deletions
diff --git a/app/assets/javascripts/clusters.js b/app/assets/javascripts/clusters.js
index 81daa97a938..5a381a5322a 100644
--- a/app/assets/javascripts/clusters.js
+++ b/app/assets/javascripts/clusters.js
@@ -4,74 +4,58 @@ import axios from 'axios';
import Poll from './lib/utils/poll';
import { s__ } from './locale';
import './flash';
-import { convertPermissionToBoolean } from './lib/utils/common_utils';
-class ClusterService {
- constructor(options = {}) {
- this.options = options;
- }
-
- fetchData() {
- return axios.get(this.options.endpoints.checkStatus);
- }
-
- updateData(value) {
- return axios.put(this.options.endpoints.editPath,
- {
- cluster: {
- enabled: value,
- },
- },
- );
- }
-}
/**
* Cluster page has 2 separate parts:
- * - Update form with toggle button
- * -- Check initial state and set the toggle button
- * -- Listen to changes
- * -- Check permissions in order to disable
- * -- Update cluster based on toggle status
+ * Toggle button
*
* - Polling status while creating or scheduled
* -- Update status area with the response result
*
*/
+
+class ClusterService {
+ constructor(options = {}) {
+ this.options = options;
+ }
+ fetchData() {
+ return axios.get(this.options.endpoint);
+ }
+}
+
export default class ClusterEdit {
constructor() {
const dataset = document.querySelector('.js-edit-cluster-form').dataset;
this.state = {
- endpoints: {
- checkStatus: dataset.checkStatus,
- editPath: dataset.editPath,
- },
- canUpdate: convertPermissionToBoolean(dataset.canUpdate),
+ statusPath: dataset.statusPath,
clusterStatus: dataset.clusterStatus,
+ clusterStatusReason: dataset.clusterStatusReason,
toggleStatus: dataset.toggleStatus,
};
- this.service = new ClusterService({ endpoints: this.state.endpoints });
+ this.service = new ClusterService({ endpoint: this.state.statusPath });
this.toggleButton = document.querySelector('.js-toggle-cluster');
+ this.toggleInput = document.querySelector('.js-toggle-input');
this.errorContainer = document.querySelector('.js-cluster-error');
this.successContainer = document.querySelector('.js-cluster-success');
this.creatingContainer = document.querySelector('.js-cluster-creating');
- this.initEditForm();
+ this.toggleButton.addEventListener('click', this.toggle.bind(this));
- if (this.clusterStatus === 'scheduled' || this.clusterStatus === 'creating') {
- this.initPoling();
+ if (this.state.clusterStatus !== 'created') {
+ this.updateContainer(this.state.clusterStatus, this.state.clusterStatusReason);
}
- }
- initEditForm() {
- this.toggleButton.addEventListener('click', this.toggle.bind(this));
- document.querySelector('.js-edit-cluster-button').addEventListener('click', this.updateData.bind(this));
+ if (this.state.statusPath) {
+ this.initPoling();
+ }
}
toggle() {
this.toggleButton.classList.toggle('checked');
this.state.toggleStatus = this.toggleButton.classList.contains('checked').toString();
+ this.toggleInput.setAttribute('value', this.state.toggleStatus);
}
updateData() {
@@ -83,11 +67,10 @@ export default class ClusterEdit {
resource: this.service,
method: 'fetchData',
successCallback: (data) => {
- const { status } = data.data;
- this.updateContainer(status);
+ const { status, status_reason } = data.data;
+ this.updateContainer(status, status_reason);
},
- errorCallback: (error) => {
- this.updateContainer('error', error);
+ errorCallback: () => {
Flash(s__('ClusterIntegration|Something went wrong on our end.'));
},
});
@@ -119,12 +102,13 @@ export default class ClusterEdit {
case 'created':
this.successContainer.classList.remove('hidden');
break;
- case 'error':
+ case 'errored':
this.errorContainer.classList.remove('hidden');
this.errorContainer.querySelector('.js-error-reason').textContent = error.status_reason;
break;
+ case 'scheduled':
case 'creating':
- this.creatingContainer.classList.add('hidden');
+ this.creatingContainer.classList.remove('hidden');
break;
default:
this.hideAll();