Widget:Autorenbox: Unterschied zwischen den Versionen
Aus ZUM-Unterrichten
KKeine Bearbeitungszusammenfassung Markierung: 2017-Quelltext-Bearbeitung |
KKeine Bearbeitungszusammenfassung Markierung: 2017-Quelltext-Bearbeitung |
||
Zeile 54: | Zeile 54: | ||
const response = $.Deferred(); | const response = $.Deferred(); | ||
function continueQueryOrResolve(result, query, pages, lastContinue) { | function continueQueryOrResolve(result, query, pages, lastContinue) { | ||
api.get({...query, ...lastContinue}) | |||
.then((response) => { | |||
const newPages = Object.values(response.query.pages).reduce((pages, page) => { | |||
pages[page.pageid] = {...pages[page.pageid], ...page}; | |||
return pages; | |||
}, pages); | |||
if (response.continue !== undefined) { | |||
continueQueryOrResolve(result, query, newPages, response.continue); | |||
} else if (response.batchcomplete !== undefined) { | |||
result.resolve(newPages); | |||
} | |||
}); | |||
} | } | ||
queries.reduce((result, query) => { | queries.reduce((result, query) => { | ||
const newResult = $.Deferred(); | const newResult = $.Deferred(); | ||
continueQueryOrResolve(newResult, query, {}, null); | continueQueryOrResolve(newResult, query, {}, null); | ||
return newResult.then((b) => { | return newResult.then((b) => { | ||
return result.then((a) => ([...a, ...b])); | return result.then((a) => ([...a, ...b])); | ||
Zeile 76: | Zeile 75: | ||
}, jQuery.Deferred()) | }, jQuery.Deferred()) | ||
.then((data) => { response.resolve(data);}); | .then((data) => { response.resolve(data);}); | ||
response | response | ||
.then((pages) => Object.values(pages)) | .then((pages) => Object.values(pages)) |