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