homer/app.js

43 lines
1.1 KiB
JavaScript
Raw Normal View History

2018-06-14 07:14:05 +02:00
var app = new Vue({
el: '#app',
data: {
config: null,
filter: ''
},
beforeCreate () {
2018-06-17 00:48:28 +02:00
let that = this;
2018-06-14 07:14:05 +02:00
return getConfig().then(function (config) {
2018-06-17 00:48:28 +02:00
console.log(config);
const size = 3;
2018-06-14 07:14:05 +02:00
config.services.forEach(function(service) {
service.rows = [];
items = service.items;
while (items.length) {
service.rows.push(items.splice(0, size));
}
if (service.rows.length) {
2018-06-17 00:48:28 +02:00
let last = service.rows.length-1;
2018-06-14 07:14:05 +02:00
service.rows[last] = service.rows[last].concat(Array(size - service.rows[last].length));
}
});
that.config = config;
2018-06-17 00:48:28 +02:00
}).catch(function () {
console.error('Fail to get config');
2018-06-14 07:14:05 +02:00
});
}
});
function getConfig() {
2018-06-17 00:48:28 +02:00
return fetch('config.yml').then(function(response) {
if (response.status !== 200) {
return;
}
return response.text().then(function(body){
return jsyaml.load(body);
});
2018-06-14 07:14:05 +02:00
});
}