Skip to content

Commit

Permalink
Merge pull request moodlehq#949 from dpalou/MOBILE-1987-pau
Browse files Browse the repository at this point in the history
MOBILE-1987 assign: Use real lastattempt on reopenned submissions
  • Loading branch information
jleyva authored Feb 28, 2017
2 parents 9901e76 + d7a1b24 commit 97bb648
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
29 changes: 19 additions & 10 deletions www/addons/mod/assign/directives/submission.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@ angular.module('mm.addons.mod_assign')
var isBlind = !!blindId,
assign;

scope.previousAttempt = false;

if (!submitId) {
submitId = $mmSite.getUserId();
isBlind = false;
Expand Down Expand Up @@ -352,7 +354,13 @@ angular.module('mm.addons.mod_assign')
scope.submissionStatusAvailable = true;

scope.lastAttempt = response.lastattempt;
scope.previousAttempts = response.previousattempts;
if (response.previousattempts && response.previousattempts.length > 0) {
var previousAttempts = response.previousattempts.sort(function(a, b) {
return a.attemptnumber - b.attemptnumber;
});
scope.previousAttempt = previousAttempts[previousAttempts.length - 1];
}

scope.membersToSubmit = [];
if (response.lastattempt) {
scope.canSubmit = !scope.isSubmittedForGrading && !scope.submittedOffline &&
Expand Down Expand Up @@ -427,7 +435,13 @@ angular.module('mm.addons.mod_assign')
if (scope.userSubmission) {
if (!assign.teamsubmission || !response.lastattempt.submissiongroup ||
!assign.preventsubmissionnotingroup) {
scope.submissionPlugins = scope.userSubmission.plugins;
if (scope.previousAttempt && scope.previousAttempt.submission.plugins &&
scope.userSubmission.status == mmaModAssignSubmissionStatusReopened) {
// Get latest attempt if avalaible.
scope.submissionPlugins = scope.previousAttempt.submission.plugins;
} else {
scope.submissionPlugins = scope.userSubmission.plugins;
}
}
}
}
Expand Down Expand Up @@ -516,11 +530,7 @@ angular.module('mm.addons.mod_assign')
});
});
}).catch(function(message) {
if (message) {
$mmUtil.showErrorModal(message);
} else {
$mmUtil.showErrorModal('Error getting assigment data.');
}
$mmUtil.showErrorModalDefault(message, 'Error getting assigment data.');
return $q.reject();
}).finally(function() {
scope.loaded = true;
Expand Down Expand Up @@ -614,15 +624,14 @@ angular.module('mm.addons.mod_assign')
return;
}

if (!scope.previousAttempts || !scope.previousAttempts.length) {
if (!scope.previousAttempt) {
// Cannot access previous attempts, just go to edit.
scope.goToEdit();
return;
}

var modal = $mmUtil.showModalLoading(),
previousAttempt = scope.previousAttempts[scope.previousAttempts.length - 1],
previousSubmission = $mmaModAssign.getSubmissionObjectFromAttempt(scope.assign, previousAttempt);
previousSubmission = $mmaModAssign.getSubmissionObjectFromAttempt(scope.assign, scope.previousAttempt);

$mmaModAssignHelper.getSubmissionSizeForCopy(scope.assign, previousSubmission).catch(function() {
// Error calculating size, return -1.
Expand Down
5 changes: 3 additions & 2 deletions www/addons/mod/assign/services/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ angular.module('mm.addons.mod_assign')
* @name $mmaModAssignHelper
*/
.factory('$mmaModAssignHelper', function($mmUtil, $mmaModAssignSubmissionDelegate, $q, $mmSite, $mmFS, $mmaModAssign, $mmGroups,
$mmFileUploader, mmaModAssignComponent, $mmaModAssignOffline, $mmaModAssignFeedbackDelegate) {
$mmFileUploader, mmaModAssignComponent, $mmaModAssignOffline, $mmaModAssignFeedbackDelegate,
mmaModAssignSubmissionStatusNew, mmaModAssignSubmissionStatusReopened) {

var self = {};

Expand All @@ -41,7 +42,7 @@ angular.module('mm.addons.mod_assign')
return false;
}

if (submission.status == 'new' || submission.status == 'reopened') {
if (submission.status == mmaModAssignSubmissionStatusNew || submission.status == mmaModAssignSubmissionStatusReopened) {
// It's a new submission, allow creating it in offline.
return true;
}
Expand Down

0 comments on commit 97bb648

Please sign in to comment.