Skip to content

Commit

Permalink
Merge pull request #946 from crazyserver/MOBILE-1987
Browse files Browse the repository at this point in the history
Mobile 1987
  • Loading branch information
jleyva authored Feb 28, 2017
2 parents 36fa03f + 56501a8 commit 20c3fa2
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 55 deletions.
30 changes: 16 additions & 14 deletions www/addons/mod/assign/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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) {
Expand All @@ -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});
}
};
Expand Down Expand Up @@ -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();
});
});
}
});
Expand All @@ -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();
});
}
Expand Down
12 changes: 4 additions & 8 deletions www/addons/mod/assign/controllers/submissionlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
});
}
Expand Down
7 changes: 6 additions & 1 deletion www/addons/mod/assign/services/assign.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -506,7 +511,7 @@ angular.module('mm.addons.mod_assign')
return $q.reject();
}

groupId = 0;
groupId = groupId || 0;
var params = {
"assignid": assignId,
"groupid": groupId,
Expand Down
40 changes: 39 additions & 1 deletion www/addons/mod/assign/services/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down Expand Up @@ -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;
});
5 changes: 3 additions & 2 deletions www/addons/mod/assign/services/prefetch_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
16 changes: 8 additions & 8 deletions www/addons/mod/assign/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,22 @@ <h2>{{ 'mma.mod_assign.latesubmissions' | translate }}</h2> <p>{{lateSubmissions
<div ng-if="summary.participantcount" class="item item-text-wrap item-icon-right" ng-click="gotoSubmissionList()">
<h2 ng-if="assign.teamsubmission">{{ 'mma.mod_assign.numberofteams' | translate }}</h2>
<h2 ng-if="!assign.teamsubmission">{{ 'mma.mod_assign.numberofparticipants' | translate }}</h2>
<span class="badge badge-positive">{{summary.participantcount}}</span>
<span ng-if="showNumbers" class="badge badge-positive">{{summary.participantcount}}</span>
<i class="icon icon-accessory ion-chevron-right"></i>
</div>

<div ng-if="assign.submissiondrafts && summary.submissionsenabled" class="item item-text-wrap" ng-class="{'item-icon-right': summary.submissiondraftscount}" ng-click="gotoSubmissionList(mmaModAssignSubmissionStatusDraft, summary.submissiondraftscount)">
<div ng-if="assign.submissiondrafts && summary.submissionsenabled" class="item item-text-wrap" ng-class="{'item-icon-right': !showNumbers || summary.submissiondraftscount}" ng-click="gotoSubmissionList(mmaModAssignSubmissionStatusDraft, summary.submissiondraftscount)">
<h2>{{ 'mma.mod_assign.numberofdraftsubmissions' | translate }}</h2>
<span class="badge badge-positive">{{summary.submissiondraftscount}}</span>
<i class="icon icon-accessory ion-chevron-right" ng-if="summary.submissiondraftscount"></i>
<span ng-if="showNumbers" class="badge badge-positive">{{summary.submissiondraftscount}}</span>
<i class="icon icon-accessory ion-chevron-right" ng-if="!showNumbers || summary.submissiondraftscount"></i>
</div>

<div ng-if="summary.submissionsenabled" class="item item-text-wrap" ng-class="{'item-icon-right': summary.submissionssubmittedcount}" ng-click="gotoSubmissionList(mmaModAssignSubmissionStatusSubmitted, summary.submissionssubmittedcount)">
<div ng-if="summary.submissionsenabled" class="item item-text-wrap" ng-class="{'item-icon-right': !showNumbers || summary.submissionssubmittedcount}" ng-click="gotoSubmissionList(mmaModAssignSubmissionStatusSubmitted, summary.submissionssubmittedcount)">
<h2>{{ 'mma.mod_assign.numberofsubmittedassignments' | translate }}</h2>
<span class="badge badge-positive">{{summary.submissionssubmittedcount}}</span>
<i class="icon icon-accessory ion-chevron-right" ng-if="summary.submissionssubmittedcount"></i>
<span ng-if="showNumbers" class="badge badge-positive">{{summary.submissionssubmittedcount}}</span>
<i class="icon icon-accessory ion-chevron-right" ng-if="!showNumbers || summary.submissionssubmittedcount"></i>
</div>
<div ng-if="summary.submissionsenabled && !assign.teamsubmission" class="item item-text-wrap" ng-class="{'item-icon-right': needsGradingAvalaible}" ng-click="gotoSubmissionList(mmaModAssignNeedGrading, needsGradingAvalaible)">
<div ng-if="summary.submissionsenabled && !assign.teamsubmission && showNumbers" class="item item-text-wrap" ng-class="{'item-icon-right': needsGradingAvalaible}" ng-click="gotoSubmissionList(mmaModAssignNeedGrading, needsGradingAvalaible)">
<h2>{{ 'mma.mod_assign.numberofsubmissionsneedgrading' | translate }}</h2>
<span class="badge badge-positive">{{summary.submissionsneedgradingcount}}</span>
<i class="icon icon-accessory ion-chevron-right" ng-if="needsGradingAvalaible"></i>
Expand Down
3 changes: 3 additions & 0 deletions www/addons/mod/assign/templates/submissionlist.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ <h2 ng-if="!submission.userfullname">{{ 'mma.mod_assign.hiddenuser' | translate
<li class="mm-warning item item-text-wrap" ng-if="!haveAllParticipants">
<i class="icon ion-alert-circled padding"></i> {{ 'mma.mod_assign.notallparticipantsareshown' | translate }}
</li>
<li class="padding" ng-if="!submissions || submissions.length == 0">
<p>{{ 'mma.mod_assign.submissionstatus_' | translate }}</p>
</li>
</ul>
</mm-loading>
</ion-content>
Expand Down
78 changes: 57 additions & 21 deletions www/core/lib/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}

/**
Expand All @@ -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) {
Expand All @@ -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.
*
Expand Down Expand Up @@ -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 = {
Expand Down

0 comments on commit 20c3fa2

Please sign in to comment.