aboutsummaryrefslogtreecommitdiffhomepage
path: root/app.js
blob: ffb50076897bbc6cea23abac1d47d0533e26c7c0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
var app = new Vue({
    el: '#app',
    data: {
        config: null,
        filter: ''
    },
    beforeCreate () {
        let that = this;

        return getConfig().then(function (config) {
            console.log(config);
            const size = 3;
            config.services.forEach(function(service) {
                service.rows = [];
                items = service.items;
                while (items.length) {
                    service.rows.push(items.splice(0, size));
                }

                if (service.rows.length) {
                    let last = service.rows.length-1;
                    service.rows[last] = service.rows[last].concat(Array(size - service.rows[last].length));
                }
            });
            that.config = config;
        }).catch(function () {
            console.error('Fail to get config');
        });
    }
});


function getConfig() {
    return fetch('config.yml').then(function(response) {
        if (response.status !== 200) {
            return;
        }

        return response.text().then(function(body){
            return jsyaml.load(body);
        });
    });
}