Skip to content

Commit a7d5c76

Browse files
committed
MOBILE-1576 quiz: Show download icon after finishing offline attempt
1 parent 2177aeb commit a7d5c76

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-12
lines changed

www/addons/mod_quiz/controllers/index.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,15 @@ angular.module('mm.addons.mod_quiz')
6464
}
6565
});
6666
}).then(function() {
67-
// Try to sync the quiz.
68-
return syncQuiz(!refresh, false).catch(function() {
69-
// Ignore errors, keep getting data even if sync fails.
67+
if ($mmaModQuiz.isQuizOffline(quiz)) {
68+
// Try to sync the quiz.
69+
return syncQuiz(!refresh, false).catch(function() {
70+
// Ignore errors, keep getting data even if sync fails.
71+
autoReview = undefined;
72+
});
73+
} else {
7074
autoReview = undefined;
71-
});
75+
}
7276
}).then(function() {
7377

7478
if ($mmaModQuiz.isQuizOffline(quiz)) {

www/addons/mod_quiz/services/quiz.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ angular.module('mm.addons.mod_quiz')
2323
*/
2424
.factory('$mmaModQuiz', function($log, $mmSite, $mmSitesManager, $q, $translate, $mmUtil, $mmText, $mmQuestionDelegate,
2525
$mmaModQuizAccessRulesDelegate, $mmQuestionHelper, $mmFilepool, $mmaModQuizOnline, $mmaModQuizOffline, $state,
26-
mmaModQuizComponent, mmCoreDownloaded, mmCoreDownloading) {
26+
mmaModQuizComponent, mmCoreDownloaded, mmCoreDownloading, mmCoreNotDownloaded) {
2727

2828
$log = $log.getInstance('$mmaModQuiz');
2929

@@ -1996,7 +1996,10 @@ angular.module('mm.addons.mod_quiz')
19961996
siteId = siteId || $mmSite.getId();
19971997

19981998
var attempts,
1999-
promises = [];
1999+
promises = [],
2000+
component = mmaModQuizComponent,
2001+
revision,
2002+
timemod;
20002003

20012004
// Get quiz data.
20022005
promises.push(self.getQuizAccessInformation(quiz.id, false, true, siteId));
@@ -2019,11 +2022,19 @@ angular.module('mm.addons.mod_quiz')
20192022
return self.prefetchAttempt(quiz, attempts[attempts.length - 1], siteId);
20202023
}
20212024
}).then(function() {
2022-
// Prefetch finished, mark as downloaded.
2023-
var revision = self.getQuizRevisionFromAttempts(attempts),
2024-
timemod = self.getQuizTimemodifiedFromAttempts(attempts);
2025-
return $mmFilepool.storePackageStatus(siteId, mmaModQuizComponent,
2026-
quiz.coursemodule, mmCoreDownloaded, revision, timemod);
2025+
// Prefetch finished, get current status to determine if we need to change it.
2026+
revision = self.getQuizRevisionFromAttempts(attempts);
2027+
timemod = self.getQuizTimemodifiedFromAttempts(attempts);
2028+
2029+
return $mmFilepool.getPackageStatus(siteId, component, quiz.coursemodule, revision, timemod);
2030+
}).then(function(status) {
2031+
if (status !== mmCoreNotDownloaded) {
2032+
// Quiz was downloaded, set the new status.
2033+
// If no attempts or last is finished we'll mark it as not downloaded to show download icon.
2034+
var isLastFinished = !attempts.length || self.isAttemptFinished(attempts[attempts.length - 1].state),
2035+
newStatus = isLastFinished ? mmCoreNotDownloaded : mmCoreDownloaded;
2036+
return $mmFilepool.storePackageStatus(siteId, component, quiz.coursemodule, newStatus, revision, timemod);
2037+
}
20272038
});
20282039
};
20292040

www/addons/mod_quiz/services/quiz_sync.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,8 @@ angular.module('mm.addons.mod_quiz')
371371
}
372372
}
373373

374-
return $mmaModQuiz.processAttempt(quiz, onlineAttempt, answers, preflightData, finish, false, false, siteId);
374+
return $mmaModQuiz.processAttempt(quiz, onlineAttempt, answers,
375+
preflightData, finish, false, false, siteId);
375376
}).then(function() {
376377
// Data sent. Finish the sync.
377378
return finishSync(lastAttemptId, true);

0 commit comments

Comments
 (0)