MOBILE-2429 feedback: Use responses of the last submission

main
Albert Gasset 2019-01-23 13:29:48 +01:00
parent 8436162fb6
commit 2bd79fd954
1 changed files with 15 additions and 16 deletions

View File

@ -135,18 +135,6 @@ export class AddonModFeedbackProvider {
*/
protected fillValues(feedbackId: number, items: any[], offline: boolean, ignoreCache: boolean, siteId: string): Promise<any> {
return this.getCurrentValues(feedbackId, offline, ignoreCache, siteId).then((valuesArray) => {
if (valuesArray.length == 0) {
// Try sending empty values to get the last completed attempt values.
return this.processPageOnline(feedbackId, 0, {}, undefined, siteId).then(() => {
return this.getCurrentValues(feedbackId, offline, ignoreCache, siteId);
}).catch(() => {
// Ignore errors
});
}
return valuesArray;
}).then((valuesArray) => {
const values = {};
valuesArray.forEach((value) => {
@ -440,7 +428,7 @@ export class AddonModFeedbackProvider {
}
/**
* Returns the temporary completion record for the current user.
* Returns the temporary responses or responses of the last submission for the current user.
*
* @param {number} feedbackId Feedback ID.
* @param {boolean} [offline=false] True if it should return cached data. Has priority over ignoreCache.
@ -465,11 +453,22 @@ export class AddonModFeedbackProvider {
}
return site.read('mod_feedback_get_unfinished_responses', params, preSets).then((response) => {
if (response && typeof response.responses != 'undefined') {
return response.responses;
if (!response || typeof response.responses == 'undefined') {
return Promise.reject(null);
}
return Promise.reject(null);
if (response.responses.length == 0) {
// No unfinished responses, fetch responses of the last submission.
return site.read('mod_feedback_get_finished_responses', params, preSets).then((response) => {
if (!response || typeof response.responses == 'undefined') {
return Promise.reject(null);
}
return response.responses;
});
}
return response.responses;
});
});
}