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 @@

{{ 'mma.mod_assign.latesubmissions' | translate }}

{{lateSubmissions

{{ 'mma.mod_assign.numberofteams' | translate }}

{{ 'mma.mod_assign.numberofparticipants' | translate }}

- {{summary.participantcount}} + {{summary.participantcount}}
-
+

{{ 'mma.mod_assign.numberofdraftsubmissions' | translate }}

- {{summary.submissiondraftscount}} - + {{summary.submissiondraftscount}} +
-
+

{{ 'mma.mod_assign.numberofsubmittedassignments' | translate }}

- {{summary.submissionssubmittedcount}} - + {{summary.submissionssubmittedcount}} +
-
+

{{ 'mma.mod_assign.numberofsubmissionsneedgrading' | translate }}

{{summary.submissionsneedgradingcount}} diff --git a/www/addons/mod/assign/templates/submissionlist.html b/www/addons/mod/assign/templates/submissionlist.html index 6a285f986da..35988a853ec 100644 --- a/www/addons/mod/assign/templates/submissionlist.html +++ b/www/addons/mod/assign/templates/submissionlist.html @@ -23,6 +23,9 @@

{{ 'mma.mod_assign.hiddenuser' | translate
  • {{ 'mma.mod_assign.notallparticipantsareshown' | translate }}
  • +
  • +

    {{ 'mma.mod_assign.submissionstatus_' | translate }}

    +
  • diff --git a/www/core/lib/groups.js b/www/core/lib/groups.js index df509edf29c..0c5ffaac698 100644 --- a/www/core/lib/groups.js +++ b/www/core/lib/groups.js @@ -50,22 +50,20 @@ angular.module('mm.core') * @module mm.core.groups * @ngdoc method * @name $mmGroups#getActivityAllowedGroups - * @param {Number} cmid Course module ID. - * @param {Number} [userid] User ID. If not defined, use current user. + * @param {Number} cmId Course module ID. + * @param {Number} [userId] User ID. If not defined, use current user. * @param {String} [siteId] Site ID. If not defined, current site. * @return {Promise} Promise resolved when the groups are retrieved. */ - self.getActivityAllowedGroups = function(cmid, userid, siteId) { - userid = userid || $mmSite.getUserId(); - siteId = siteId || $mmSite.getId(); - + self.getActivityAllowedGroups = function(cmId, userId, siteId) { return $mmSitesManager.getSite(siteId).then(function(site) { + userId = userId || site.getUserId(); var params = { - cmid: cmid, - userid: userid + cmid: cmId, + userid: userId }, preSets = { - cacheKey: getActivityAllowedGroupsCacheKey(cmid, userid) + cacheKey: getActivityAllowedGroupsCacheKey(cmId, userId) }; return site.read('core_group_get_activity_allowed_groups', params, preSets).then(function(response) { @@ -80,11 +78,11 @@ angular.module('mm.core') /** * Get cache key for group mode WS calls. * - * @param {Number} cmid Course module ID. + * @param {Number} cmId Course module ID. * @return {String} Cache key. */ - function getActivityAllowedGroupsCacheKey(cmid, userid) { - return 'mmGroups:allowedgroups:' + cmid + ':' + userid; + function getActivityAllowedGroupsCacheKey(cmId, userId) { + return 'mmGroups:allowedgroups:' + cmId + ':' + userId; } /** @@ -93,19 +91,17 @@ angular.module('mm.core') * @module mm.core.groups * @ngdoc method * @name $mmGroups#getActivityGroupMode - * @param {Number} cmid Course module ID. + * @param {Number} cmId Course module ID. * @param {String} [siteId] Site ID. If not defined, current site. - * @return {Promise} Promise resolved when the group mode is retrieved. + * @return {Promise} Promise resolved when the group mode is retrieved. */ - self.getActivityGroupMode = function(cmid, siteId) { - siteId = siteId || $mmSite.getId(); - + self.getActivityGroupMode = function(cmId, siteId) { return $mmSitesManager.getSite(siteId).then(function(site) { var params = { - cmid: cmid + cmid: cmId }, preSets = { - cacheKey: getActivityGroupModeCacheKey(cmid) + cacheKey: getActivityGroupModeCacheKey(cmId) }; return site.read('core_group_get_activity_groupmode', params, preSets).then(function(response) { @@ -117,6 +113,48 @@ angular.module('mm.core') }); }; + /** + * Get if group mode of an activity is enabled. + * + * @module mm.core.groups + * @ngdoc method + * @name $mmGroups#activityHasGroups + * @param {Number} cmId Course module ID. + * @param {String} [siteId] Site ID. If not defined, current site. + * @return {Promise} Promise resolved with true if the group mode is retrieved and enabled. + */ + self.activityHasGroups = function(cmId, siteId) { + return self.getActivityGroupMode(cmId, siteId).then(function(groupmode) { + return groupmode === self.SEPARATEGROUPS || groupmode === self.VISIBLEGROUPS; + }).catch(function() { + return false; + }); + }; + + /** + * Get the groups allowed in an activity if they are allowed. + * + * @module mm.core.groups + * @ngdoc method + * @name $mmGroups#getActivityAllowedGroupsIfEnabled + * @param {Number} cmId Course module ID. + * @param {Number} [userId] User ID. If not defined, use current user. + * @param {String} [siteId] Site ID. If not defined, current site. + * @return {Promise} Promise resolved when the groups are retrieved. If not allowed, empty array will be returned. + */ + self.getActivityAllowedGroupsIfEnabled = function(cmId, userId, siteId) { + siteId = siteId || $mmSite.getId(); + + // Get real groupmode, in case it's forced by the course. + return self.activityHasGroups(cmId, siteId).then(function(hasGroups) { + if (hasGroups) { + // Get the groups available for the user. + return self.getActivityAllowedGroups(cmId, userId, siteId); + } + return []; + }); + }; + /** * Get cache key for group mode WS calls. * @@ -178,8 +216,6 @@ angular.module('mm.core') * @return {Promise} Promise to be resolved when the groups are retrieved. */ self.getUserGroupsInCourse = function(courseid, refresh, siteid, userid) { - siteid = siteid || $mmSite.getId(); - return $mmSitesManager.getSite(siteid).then(function(site) { var presets = {}, data = {