Commit 8f3678f1 authored by Filipa Lacerda's avatar Filipa Lacerda

Use CJS in environments service

parent 26a951b7
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
window.Vue = require('vue'); window.Vue = require('vue');
window.Vue.use(require('vue-resource')); window.Vue.use(require('vue-resource'));
require('../services/environments_service'); const EnvironmentsService = require('../services/environments_service');
require('./environment_item'); require('./environment_item');
const Store = require('../stores/environments_store'); const Store = require('../stores/environments_store');
...@@ -68,11 +68,11 @@ const Store = require('../stores/environments_store'); ...@@ -68,11 +68,11 @@ const Store = require('../stores/environments_store');
const scope = this.$options.getQueryParameter('scope') || this.visibility; const scope = this.$options.getQueryParameter('scope') || this.visibility;
const endpoint = `${this.endpoint}?scope=${scope}`; const endpoint = `${this.endpoint}?scope=${scope}`;
gl.environmentsService = new EnvironmentsService(endpoint); const service = new EnvironmentsService(endpoint);
this.isLoading = true; this.isLoading = true;
return gl.environmentsService.all() return service.all()
.then(resp => resp.json()) .then(resp => resp.json())
.then((json) => { .then((json) => {
this.store.storeAvailableCount(json.available_count); this.store.storeAvailableCount(json.available_count);
......
/* globals Vue */ const Vue = window.Vue = require('vue');
/* eslint-disable no-unused-vars, no-param-reassign */
class EnvironmentsService { class EnvironmentsService {
constructor(endpoint) {
constructor(root) { this.environments = Vue.resource(endpoint);
Vue.http.options.root = root;
this.environments = Vue.resource(root);
Vue.http.interceptors.push((request, next) => {
// needed in order to not break the tests.
if ($.rails) {
request.headers['X-CSRF-Token'] = $.rails.csrfToken();
}
next();
});
} }
all() { all() {
...@@ -22,4 +10,4 @@ class EnvironmentsService { ...@@ -22,4 +10,4 @@ class EnvironmentsService {
} }
} }
window.EnvironmentsService = EnvironmentsService; module.exports = EnvironmentsService;
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