Skip to content

Commit d038cc0

Browse files
committed
MOBILE-2178 lesson: Support lesson grade links
1 parent 127e88e commit d038cc0

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

www/addons/mod/lesson/main.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ angular.module('mm.addons.mod_lesson', ['mm.core'])
8383
$mmCoursePrefetchDelegateProvider.registerPrefetchHandler('mmaModLesson', 'lesson', '$mmaModLessonPrefetchHandler');
8484
$mmContentLinksDelegateProvider.registerLinkHandler('mmaModLesson:view', '$mmaModLessonHandlers.viewLinksHandler');
8585
$mmContentLinksDelegateProvider.registerLinkHandler('mmaModLesson:overview', '$mmaModLessonHandlers.overviewLinksHandler');
86+
$mmContentLinksDelegateProvider.registerLinkHandler('mmaModLesson:grade', '$mmaModLessonHandlers.gradeLinksHandler');
8687
})
8788

8889
.run(function($mmCronDelegate) {

www/addons/mod/lesson/services/handlers.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,5 +364,60 @@ angular.module('mm.addons.mod_lesson')
364364
});
365365
}
366366

367+
/**
368+
* Content links handler for lesson grade link.
369+
*
370+
* @module mm.addons.mod_lesson
371+
* @ngdoc method
372+
* @name $mmaModLessonHandlers#gradeLinksHandler
373+
*/
374+
self.gradeLinksHandler = $mmContentLinksHelper.createModuleGradeLinkHandler('mmaModLesson', 'lesson', $mmaModLesson, viewGrade);
375+
376+
/**
377+
* Treat a grade link to a user different than current one.
378+
*
379+
* @param {String} url URL to treat.
380+
* @param {Object} params Params of the URL.
381+
* @param {Number} [courseId] Course ID related to the URL.
382+
* @param {String} siteId Site ID.
383+
* @return {[type]} [description]
384+
*/
385+
function viewGrade(url, params, courseId, siteId) {
386+
siteId = siteId || $mmSite.getId();
387+
388+
var moduleId = parseInt(params.id, 10),
389+
modal = $mmUtil.showModalLoading(),
390+
module;
391+
392+
return $mmCourse.getModuleBasicInfo(moduleId, siteId).then(function(mod) {
393+
module = mod;
394+
courseId = module.course || courseId || params.courseid || params.cid;
395+
396+
// Check if the user can see the user reports in the lesson.
397+
return $mmaModLesson.getAccessInformation(module.instance);
398+
}).then(function(info) {
399+
if (info.canviewreports) {
400+
// User can view reports, go to view the report.
401+
return $state.go('redirect', {
402+
siteid: siteId,
403+
state: 'site.mod_lesson-userretake',
404+
params: {
405+
courseid: courseId,
406+
lessonid: module.instance,
407+
userid: parseInt(params.userid, 10)
408+
}
409+
});
410+
} else {
411+
// User cannot view the report, go to lesson index.
412+
return $mmCourseHelper.navigateToModule(moduleId, siteId, courseId, module.section);
413+
}
414+
}).catch(function(error) {
415+
$mmUtil.showErrorModalDefault(error, 'mm.course.errorgetmodule', true);
416+
return $q.reject();
417+
}).finally(function() {
418+
modal.dismiss();
419+
});
420+
}
421+
367422
return self;
368423
});

0 commit comments

Comments
 (0)