mirror of
https://github.com/bastienwirtz/homer.git
synced 2024-12-29 10:08:50 +01:00
Use fetch API instead of xhr.
This commit is contained in:
parent
e3212743b9
commit
9ca12a40f4
43
app.js
43
app.js
@ -5,10 +5,11 @@ var app = new Vue({
|
|||||||
filter: ''
|
filter: ''
|
||||||
},
|
},
|
||||||
beforeCreate () {
|
beforeCreate () {
|
||||||
var that = this;
|
let that = this;
|
||||||
|
|
||||||
return getConfig().then(function (config) {
|
return getConfig().then(function (config) {
|
||||||
// Splice services list into groups of 3 for flex column display
|
console.log(config);
|
||||||
var size = 3;
|
const size = 3;
|
||||||
config.services.forEach(function(service) {
|
config.services.forEach(function(service) {
|
||||||
service.rows = [];
|
service.rows = [];
|
||||||
items = service.items;
|
items = service.items;
|
||||||
@ -17,42 +18,26 @@ var app = new Vue({
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (service.rows.length) {
|
if (service.rows.length) {
|
||||||
var last = service.rows.length-1;
|
let last = service.rows.length-1;
|
||||||
service.rows[last] = service.rows[last].concat(Array(size - service.rows[last].length));
|
service.rows[last] = service.rows[last].concat(Array(size - service.rows[last].length));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
that.config = config;
|
that.config = config;
|
||||||
|
}).catch(function () {
|
||||||
|
console.error('Fail to get config');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
function getConfig() {
|
function getConfig() {
|
||||||
return new Promise(function (resolve, reject) {
|
return fetch('config.yml').then(function(response) {
|
||||||
var xhr = new XMLHttpRequest();
|
if (response.status !== 200) {
|
||||||
xhr.open('GET', 'config.yml');
|
return;
|
||||||
xhr.onload = function () {
|
|
||||||
if (this.status >= 200 && this.status < 300) {
|
|
||||||
try {
|
|
||||||
var data = jsyaml.load(xhr.response);
|
|
||||||
resolve(data);
|
|
||||||
} catch (e) {
|
|
||||||
console.error('fail to parse config file');
|
|
||||||
reject();
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
reject({
|
return response.text().then(function(body){
|
||||||
status: this.status,
|
return jsyaml.load(body);
|
||||||
statusText: xhr.statusText
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
xhr.onerror = function () {
|
|
||||||
reject({
|
|
||||||
status: this.status,
|
|
||||||
statusText: xhr.statusText
|
|
||||||
});
|
|
||||||
};
|
|
||||||
xhr.send();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user