diff --git a/www/addons/mod/assign/controllers/index.js b/www/addons/mod/assign/controllers/index.js index 2006a438cb1..6cbca19e300 100644 --- a/www/addons/mod/assign/controllers/index.js +++ b/www/addons/mod/assign/controllers/index.js @@ -25,7 +25,7 @@ angular.module('mm.addons.mod_assign') mmaModAssignComponent, $q, $state, mmaModAssignSubmissionInvalidatedEvent, $mmEvents, $mmSite, mmaModAssignGradedEvent, mmaModAssignSubmissionSavedEvent, $mmCourse, $mmApp, mmaModAssignSubmittedForGradingEvent, $mmaModAssignSync, $mmText, mmaModAssignEventAutomSynced, $ionicScrollDelegate, mmCoreEventOnlineStatusChanged, mmaModAssignEventManualSynced, - mmaModAssignSubmissionStatusSubmitted, mmaModAssignSubmissionStatusDraft, mmaModAssignNeedGrading, $translate) { + mmaModAssignSubmissionStatusSubmitted, mmaModAssignSubmissionStatusDraft, mmaModAssignNeedGrading, $translate, $mmGroups) { var module = $stateParams.module || {}, courseId = $stateParams.courseid, siteId = $mmSite.getId(), @@ -44,6 +44,7 @@ angular.module('mm.addons.mod_assign') $scope.mmaModAssignSubmissionStatusSubmitted = mmaModAssignSubmissionStatusSubmitted; $scope.mmaModAssignSubmissionStatusDraft = mmaModAssignSubmissionStatusDraft; $scope.mmaModAssignNeedGrading = mmaModAssignNeedGrading; + $scope.showNumbers = true; // Check if submit through app is supported. $mmaModAssign.isSaveAndSubmitSupported().then(function(enabled) { @@ -53,7 +54,7 @@ angular.module('mm.addons.mod_assign') $scope.gotoSubmissionList = function(status, count) { if (typeof status == 'undefined') { $state.go('site.mod_assign-submission-list', {courseid: courseId, moduleid: module.id, modulename: module.name}); - } else if (count) { + } else if (count || !$scope.showNumbers) { $state.go('site.mod_assign-submission-list', {status: status, courseid: courseId, moduleid: module.id, modulename: module.name}); } }; @@ -107,14 +108,19 @@ angular.module('mm.addons.mod_assign') } } - return $mmaModAssign.getSubmissionStatus(assign.id).then(function(response) { - $scope.summary = response.gradingsummary; + // Check if groupmode is enabled to avoid showing wrong numbers. + return $mmGroups.activityHasGroups(assign.cmid).then(function(hasGroups) { + $scope.showNumbers = !hasGroups; - $scope.needsGradingAvalaible = response.gradingsummary.submissionsneedgradingcount > 0 && - $mmSite.isVersionGreaterEqualThan('3.2'); - }).catch(function() { - // Fail silently (WS is not available, fallback). - return $q.when(); + return $mmaModAssign.getSubmissionStatus(assign.id).then(function(response) { + $scope.summary = response.gradingsummary; + + $scope.needsGradingAvalaible = response.gradingsummary.submissionsneedgradingcount > 0 && + $mmSite.isVersionGreaterEqualThan('3.2'); + }).catch(function() { + // Fail silently (WS is not available, fallback). + return $q.when(); + }); }); } }); @@ -127,11 +133,7 @@ angular.module('mm.addons.mod_assign') return refreshAllData(sync, showErrors); } - if (message) { - $mmUtil.showErrorModal(message); - } else { - $mmUtil.showErrorModal('Error getting assigment data.'); - } + $mmUtil.showErrorModalDefault(message, 'Error getting assigment data.'); return $q.reject(); }); } diff --git a/www/addons/mod/assign/controllers/submissionlist.js b/www/addons/mod/assign/controllers/submissionlist.js index 72316f55ca9..b8393c57ee5 100644 --- a/www/addons/mod/assign/controllers/submissionlist.js +++ b/www/addons/mod/assign/controllers/submissionlist.js @@ -23,7 +23,7 @@ angular.module('mm.addons.mod_assign') */ .controller('mmaModAssignSubmissionListCtrl', function($scope, $stateParams, $mmaModAssign, $mmUtil, $translate, $q, $mmEvents, mmaModAssignComponent, mmaModAssignSubmissionInvalidatedEvent, mmaModAssignSubmissionStatusSubmitted, $mmaModAssignOffline, - mmaModAssignNeedGrading, mmaModAssignGradedEvent, $mmSite) { + mmaModAssignNeedGrading, mmaModAssignGradedEvent, $mmSite, $mmaModAssignHelper) { var courseId = $stateParams.courseid, selectedStatus = $stateParams.status, @@ -60,9 +60,9 @@ angular.module('mm.addons.mod_assign') } // We want to show the user data on each submission. - return $mmaModAssign.listParticipants(assign.id).then(function(p) { - participants = p; + return $mmaModAssignHelper.getParticipants(assign).then(function(p) { $scope.haveAllParticipants = true; + participants = p; }).catch(function() { $scope.haveAllParticipants = false; return $q.when(); @@ -133,11 +133,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(); }); } diff --git a/www/addons/mod/assign/services/assign.js b/www/addons/mod/assign/services/assign.js index de7d9ce88d1..9f8e5036a62 100644 --- a/www/addons/mod/assign/services/assign.js +++ b/www/addons/mod/assign/services/assign.js @@ -380,6 +380,11 @@ angular.module('mm.addons.mod_assign') var promises = [], subs = []; + // Empty participants list will be treated as no list. + if (participants && participants.length == 0) { + participants = false; + } + angular.forEach(submissions, function(submission) { submission.submitid = submission.userid > 0 ? submission.userid : submission.blindid; if (submission.submitid <= 0) { @@ -506,7 +511,7 @@ angular.module('mm.addons.mod_assign') return $q.reject(); } - groupId = 0; + groupId = groupId || 0; var params = { "assignid": assignId, "groupid": groupId, diff --git a/www/addons/mod/assign/services/helper.js b/www/addons/mod/assign/services/helper.js index 675d603fab1..d994c5c6b25 100644 --- a/www/addons/mod/assign/services/helper.js +++ b/www/addons/mod/assign/services/helper.js @@ -21,7 +21,7 @@ angular.module('mm.addons.mod_assign') * @ngdoc service * @name $mmaModAssignHelper */ -.factory('$mmaModAssignHelper', function($mmUtil, $mmaModAssignSubmissionDelegate, $q, $mmSite, $mmFS, $mmaModAssign, +.factory('$mmaModAssignHelper', function($mmUtil, $mmaModAssignSubmissionDelegate, $q, $mmSite, $mmFS, $mmaModAssign, $mmGroups, $mmFileUploader, mmaModAssignComponent, $mmaModAssignOffline, $mmaModAssignFeedbackDelegate) { var self = {}; @@ -479,5 +479,43 @@ angular.module('mm.addons.mod_assign') return configs; }; + /** + * List the participants for a single assignment, with some summary info about their submissions. + * + * @module mm.addons.mod_assign + * @ngdoc method + * @name $mmaModAssignHelper#getParticipants + * @param {Object} assign Assignment object + * @param {String} [siteId] Site ID. If not defined, current site. + * @return {Promise} Promise resolved with the list of participants and summary of submissions. + */ + self.getParticipants = function(assign, siteId) { + siteId = siteId || $mmSite.getId(); + + return $mmaModAssign.listParticipants(assign.id, undefined, siteId).then(function(participants) { + if (participants && participants.length > 0) { + return participants; + } + + // If no participants returned, get participants by groups. + return $mmGroups.getActivityAllowedGroupsIfEnabled(assign.cmid, undefined, siteId).then(function(userGroups) { + var promises = [], + particips = {}; + + angular.forEach(userGroups, function(userGroup) { + promises.push($mmaModAssign.listParticipants(assign.id, userGroup.id, siteId).then(function(parts) { + // Do not get repeated users. + angular.forEach(parts, function(p) { + particips[p.id] = p; + }); + })); + }); + return $q.all(promises).then(function() { + return $mmUtil.objectToArray(particips); + }); + }); + }); + }; + return self; }); diff --git a/www/addons/mod/assign/services/prefetch_handler.js b/www/addons/mod/assign/services/prefetch_handler.js index 7eac2c46144..8ae1fbc3cd0 100644 --- a/www/addons/mod/assign/services/prefetch_handler.js +++ b/www/addons/mod/assign/services/prefetch_handler.js @@ -23,7 +23,7 @@ angular.module('mm.addons.mod_assign') */ .factory('$mmaModAssignPrefetchHandler', function($mmaModAssign, mmaModAssignComponent, $mmSite, $mmFilepool, $q, $mmCourseHelper, $mmCourse, $mmGroups, $mmUser, $mmaModAssignSubmissionDelegate, $mmaModAssignFeedbackDelegate, $mmPrefetchFactory, - $mmGrades, $mmSitesManager) { + $mmGrades, $mmSitesManager, $mmaModAssignHelper) { var self = $mmPrefetchFactory.createPrefetchHandler(mmaModAssignComponent, false); @@ -479,7 +479,7 @@ angular.module('mm.addons.mod_assign') })); // Get list participants. - promises.push($mmaModAssign.listParticipants(assign.id, 0, siteId).then(function (participants) { + promises.push($mmaModAssignHelper.getParticipants(assign, siteId).then(function (participants) { angular.forEach(participants, function(participant) { if (participant.profileimageurl) { $mmFilepool.addToQueueByUrl(siteId, participant.profileimageurl); @@ -495,6 +495,7 @@ angular.module('mm.addons.mod_assign') })); } + promises.push($mmGroups.activityHasGroups(assign.cmid)); promises.push($mmGroups.getActivityAllowedGroups(assign.cmid, false, siteId)); return $q.all(promises); diff --git a/www/addons/mod/assign/templates/index.html b/www/addons/mod/assign/templates/index.html index 63441f4c530..6e872b68b29 100644 --- a/www/addons/mod/assign/templates/index.html +++ b/www/addons/mod/assign/templates/index.html @@ -37,22 +37,22 @@
{{lateSubmissions
-{{ 'mma.mod_assign.submissionstatus_' | translate }}
+