Starts Vue view for environmnets List
This commit is contained in:
parent
b33791d8b9
commit
4df7c9edef
4 changed files with 89 additions and 0 deletions
|
@ -0,0 +1,49 @@
|
|||
//= require vue
|
||||
//= require vue-resource
|
||||
//= require_tree ./stores
|
||||
//= require_tree ./services
|
||||
|
||||
|
||||
$(() => {
|
||||
|
||||
const $environmentsListApp = document.getElementById('environments-list-view');
|
||||
const Store = gl.environmentsList.EnvironmentsStore;
|
||||
|
||||
window.gl = window.gl || {};
|
||||
|
||||
if (gl.EnvironmentsListApp) {
|
||||
gl.EnvironmentsListApp.$destroy(true);
|
||||
}
|
||||
|
||||
gl.EnvironmentsListApp = new Vue({
|
||||
|
||||
el: $environmentsListApp,
|
||||
|
||||
components: {
|
||||
'tree-view': gl.environmentsList.TreeView
|
||||
},
|
||||
|
||||
data: {
|
||||
endpoint: $environmentsListApp.dataset.endpoint,
|
||||
loading: true
|
||||
},
|
||||
|
||||
init: Store.create.bind(Store),
|
||||
|
||||
created() {
|
||||
gl.environmentsService = new EnvironmentsService(this.endpoint);
|
||||
},
|
||||
|
||||
/**
|
||||
* Fetches all the environmnets and stores them.
|
||||
* Toggles loading property.
|
||||
*/
|
||||
ready() {
|
||||
gl.environmentsService.all().then((resp) => {
|
||||
Store.addEnvironments(resp.json());
|
||||
|
||||
this.loading = false;
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
|
@ -0,0 +1,19 @@
|
|||
class EnvironmentsService {
|
||||
|
||||
constructor (root) {
|
||||
Vue.http.options.root = root;
|
||||
|
||||
debugger;
|
||||
|
||||
this.environments = Vue.resource(root);
|
||||
|
||||
Vue.http.interceptors.push((request, next) => {
|
||||
request.headers['X-CSRF-Token'] = $.rails.csrfToken();
|
||||
next();
|
||||
});
|
||||
}
|
||||
|
||||
all () {
|
||||
return this.environments.get();
|
||||
}
|
||||
};
|
|
@ -0,0 +1,21 @@
|
|||
(() => {
|
||||
window.gl = window.gl || {};
|
||||
window.gl.environmentsList = window.gl.environmentsList || {};
|
||||
|
||||
gl.environmentsList.EnvironmentsStore = {
|
||||
|
||||
create () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Stores the received environmnets.
|
||||
*
|
||||
* @param {Array} environments List of environments
|
||||
* @return {type}
|
||||
*/
|
||||
addEnvironments(environments) {
|
||||
console.log(environments);
|
||||
}
|
||||
}
|
||||
})();
|
Loading…
Reference in a new issue