Use Promises for Osmose issue detail requests

Also ES6ify the details script
This commit is contained in:
SilentSpike
2020-02-04 21:05:40 +00:00
parent 02f088e5a9
commit 087867d5c8
2 changed files with 185 additions and 181 deletions
+13 -17
View File
@@ -160,30 +160,26 @@ export default {
});
},
loadErrorDetail(d, callback) {
loadErrorDetail(d) {
// Error details only need to be fetched once
if (d.elems !== undefined) {
if (callback) callback(null, d);
return;
return Promise.resolve(d);
}
let url = `${_osmoseUrlRoot}/issue/${d.identifier}?langs=${currentLocale}`;
const url = `${_osmoseUrlRoot}/issue/${d.identifier}?langs=${currentLocale}`;
const cacheDetails = data => {
// Associated elements used for highlighting
// Assign directly for immediate use in the callback
d.elems = data.elems.map(e => e.type.substring(0,1) + e.id);
d3_json(url)
.then(data => {
// Associated elements used for highlighting
// Assign directly for immediate use in the callback
d.elems = data.elems.map(e => e.type.substring(0,1) + e.id);
// Some issues have instance specific detail in a subtitle
d.detail = data.subtitle;
// Some issues have instance specific detail in a subtitle
d.detail = data.subtitle;
this.replaceError(d);
};
this.replaceError(d);
if (callback) callback(null, d);
})
.catch(err => {
if (callback) callback(err.message);
});
return jsonPromise(url, cacheDetails)
.then(() => d);
},
loadStrings(callback, locale=currentLocale) {