]> git.immae.eu Git - github/bastienwirtz/homer.git/blame - app.js
Use fetch API instead of xhr.
[github/bastienwirtz/homer.git] / app.js
CommitLineData
09763dbf
BW
1var app = new Vue({
2 el: '#app',
3 data: {
4 config: null,
5 filter: ''
6 },
7 beforeCreate () {
9ca12a40
BW
8 let that = this;
9
09763dbf 10 return getConfig().then(function (config) {
9ca12a40
BW
11 console.log(config);
12 const size = 3;
09763dbf
BW
13 config.services.forEach(function(service) {
14 service.rows = [];
15 items = service.items;
16 while (items.length) {
17 service.rows.push(items.splice(0, size));
18 }
19
20 if (service.rows.length) {
9ca12a40 21 let last = service.rows.length-1;
09763dbf
BW
22 service.rows[last] = service.rows[last].concat(Array(size - service.rows[last].length));
23 }
24 });
25 that.config = config;
9ca12a40
BW
26 }).catch(function () {
27 console.error('Fail to get config');
09763dbf
BW
28 });
29 }
30});
31
32
33function getConfig() {
9ca12a40
BW
34 return fetch('config.yml').then(function(response) {
35 if (response.status !== 200) {
36 return;
37 }
38
39 return response.text().then(function(body){
40 return jsyaml.load(body);
41 });
09763dbf
BW
42 });
43}