]> git.immae.eu Git - github/bastienwirtz/homer.git/blame - app.js
Add message style option example
[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 () {
8 var that = this;
9 return getConfig().then(function (config) {
10 // Splice services list into groups of 3 for flex column display
11 var size = 3;
12 config.services.forEach(function(service) {
13 service.rows = [];
14 items = service.items;
15 while (items.length) {
16 service.rows.push(items.splice(0, size));
17 }
18
19 if (service.rows.length) {
20 var last = service.rows.length-1;
21 service.rows[last] = service.rows[last].concat(Array(size - service.rows[last].length));
22 }
23 });
24 that.config = config;
25 });
26 }
27});
28
29
30function getConfig() {
31 return new Promise(function (resolve, reject) {
32 var xhr = new XMLHttpRequest();
33 xhr.open('GET', 'config.yml');
34 xhr.onload = function () {
35 if (this.status >= 200 && this.status < 300) {
36 try {
37 var data = jsyaml.load(xhr.response);
38 resolve(data);
39 } catch (e) {
40 console.error('fail to parse config file');
41 reject();
42 }
43 } else {
44 reject({
45 status: this.status,
46 statusText: xhr.statusText
47 });
48 }
49 };
50 xhr.onerror = function () {
51 reject({
52 status: this.status,
53 statusText: xhr.statusText
54 });
55 };
56 xhr.send();
57 });
58}