From 8f3678f1dea1134ebc41f0d519424db673b5f764 Mon Sep 17 00:00:00 2001 From: Filipa Lacerda Date: Thu, 9 Feb 2017 11:38:59 +0000 Subject: [PATCH] Use CJS in environments service --- .../components/environment.js.es6 | 6 +++--- .../services/environments_service.js.es6 | 20 ++++--------------- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/app/assets/javascripts/environments/components/environment.js.es6 b/app/assets/javascripts/environments/components/environment.js.es6 index f07b650ca9f..6f84cc625ac 100644 --- a/app/assets/javascripts/environments/components/environment.js.es6 +++ b/app/assets/javascripts/environments/components/environment.js.es6 @@ -5,7 +5,7 @@ window.Vue = require('vue'); window.Vue.use(require('vue-resource')); -require('../services/environments_service'); +const EnvironmentsService = require('../services/environments_service'); require('./environment_item'); 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 endpoint = `${this.endpoint}?scope=${scope}`; - gl.environmentsService = new EnvironmentsService(endpoint); + const service = new EnvironmentsService(endpoint); this.isLoading = true; - return gl.environmentsService.all() + return service.all() .then(resp => resp.json()) .then((json) => { this.store.storeAvailableCount(json.available_count); diff --git a/app/assets/javascripts/environments/services/environments_service.js.es6 b/app/assets/javascripts/environments/services/environments_service.js.es6 index fab8d977f58..9b33fd02c53 100644 --- a/app/assets/javascripts/environments/services/environments_service.js.es6 +++ b/app/assets/javascripts/environments/services/environments_service.js.es6 @@ -1,20 +1,8 @@ -/* globals Vue */ -/* eslint-disable no-unused-vars, no-param-reassign */ +const Vue = window.Vue = require('vue'); class EnvironmentsService { - - constructor(root) { - 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(); - }); + constructor(endpoint) { + this.environments = Vue.resource(endpoint); } all() { @@ -22,4 +10,4 @@ class EnvironmentsService { } } -window.EnvironmentsService = EnvironmentsService; +module.exports = EnvironmentsService;