Commit 6077dea7 authored by Filipa Lacerda's avatar Filipa Lacerda

Remove store from global namespace, use CSJ instead

parent acb68ae6
...@@ -7,18 +7,12 @@ window.Vue = require('vue'); ...@@ -7,18 +7,12 @@ window.Vue = require('vue');
window.Vue.use(require('vue-resource')); window.Vue.use(require('vue-resource'));
require('../services/environments_service'); require('../services/environments_service');
require('./environment_item'); require('./environment_item');
const Store = require('../stores/environments_store');
(() => { (() => {
window.gl = window.gl || {}; window.gl = window.gl || {};
gl.environmentsList.EnvironmentsComponent = Vue.component('environment-component', { gl.environmentsList.EnvironmentsComponent = Vue.component('environment-component', {
props: {
store: {
type: Object,
required: true,
default: () => ({}),
},
},
components: { components: {
'environment-item': gl.environmentsList.EnvironmentItem, 'environment-item': gl.environmentsList.EnvironmentItem,
...@@ -26,9 +20,11 @@ require('./environment_item'); ...@@ -26,9 +20,11 @@ require('./environment_item');
data() { data() {
const environmentsData = document.querySelector('#environments-list-view').dataset; const environmentsData = document.querySelector('#environments-list-view').dataset;
const store = new Store();
return { return {
state: this.store.state, store,
state: store.state,
visibility: 'available', visibility: 'available',
isLoading: false, isLoading: false,
cssContainerClass: environmentsData.cssClass, cssContainerClass: environmentsData.cssClass,
......
window.Vue = require('vue'); window.Vue = require('vue');
require('./stores/environments_store');
require('./components/environment'); require('./components/environment');
require('../vue_shared/vue_resource_interceptor'); require('../vue_shared/vue_resource_interceptor');
...@@ -9,14 +8,8 @@ $(() => { ...@@ -9,14 +8,8 @@ $(() => {
if (gl.EnvironmentsListApp) { if (gl.EnvironmentsListApp) {
gl.EnvironmentsListApp.$destroy(true); gl.EnvironmentsListApp.$destroy(true);
} }
const Store = gl.environmentsList.EnvironmentsStore;
gl.EnvironmentsListApp = new gl.environmentsList.EnvironmentsComponent({ gl.EnvironmentsListApp = new gl.environmentsList.EnvironmentsComponent({
el: document.querySelector('#environments-list-view'), el: document.querySelector('#environments-list-view'),
propsData: {
store: Store.create(),
},
}); });
}); });
/* eslint-disable no-param-reassign */ /**
(() => { * Environments Store.
window.gl = window.gl || {}; *
window.gl.environmentsList = window.gl.environmentsList || {}; * Stores received environments, count of stopped environments and count of
* available environments.
gl.environmentsList.EnvironmentsStore = { */
state: {}, class EnvironmentsStore {
constructor() {
create() { this.state = {};
this.state.environments = []; this.state.environments = [];
this.state.stoppedCounter = 0; this.state.stoppedCounter = 0;
this.state.availableCounter = 0; this.state.availableCounter = 0;
this.state.filteredEnvironments = []; this.state.filteredEnvironments = [];
return this; return this;
}, }
/** /**
* *
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
this.state.environments = filteredEnvironments; this.state.environments = filteredEnvironments;
return filteredEnvironments; return filteredEnvironments;
}, }
/** /**
* Stores the number of available environments. * Stores the number of available environments.
...@@ -51,7 +51,7 @@ ...@@ -51,7 +51,7 @@
storeAvailableCount(count = 0) { storeAvailableCount(count = 0) {
this.state.availableCounter = count; this.state.availableCounter = count;
return count; return count;
}, }
/** /**
* Stores the number of closed environments. * Stores the number of closed environments.
...@@ -62,7 +62,7 @@ ...@@ -62,7 +62,7 @@
storeStoppedCount(count = 0) { storeStoppedCount(count = 0) {
this.state.stoppedCounter = count; this.state.stoppedCounter = count;
return count; return count;
}, }
}
}; module.exports = EnvironmentsStore;
})();
...@@ -6,7 +6,7 @@ Vue.http.interceptors.push((request, next) => { ...@@ -6,7 +6,7 @@ Vue.http.interceptors.push((request, next) => {
Vue.activeResources = Vue.activeResources ? Vue.activeResources + 1 : 1; Vue.activeResources = Vue.activeResources ? Vue.activeResources + 1 : 1;
next((response) => { next((response) => {
if (typeof response.data === 'string' && response.status !== 500) { if (typeof response.data === 'string') {
response.data = JSON.parse(response.data); response.data = JSON.parse(response.data);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment