Skip to content

Commit 3b5f364

Browse files
authored
Merge pull request #909 from dpalou/MOBILE-2000
MOBILE-2000 course: Treat course/index and dashboard links
2 parents 08b6294 + e33c638 commit 3b5f364

File tree

2 files changed

+43
-5
lines changed

2 files changed

+43
-5
lines changed

www/core/components/courses/main.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ angular.module('mm.core.courses', ['mm.core.contentlinks'])
8787
})
8888

8989
.config(function($mmContentLinksDelegateProvider) {
90-
$mmContentLinksDelegateProvider.registerLinkHandler('mmCourses:myCourses', '$mmCoursesHandlers.myCoursesLinksHandler');
90+
$mmContentLinksDelegateProvider.registerLinkHandler('mmCourses:courses', '$mmCoursesHandlers.coursesLinksHandler');
9191
$mmContentLinksDelegateProvider.registerLinkHandler('mmCourses:course', '$mmCoursesHandlers.courseLinksHandler');
92+
$mmContentLinksDelegateProvider.registerLinkHandler('mmCourses:dashboard', '$mmCoursesHandlers.dashboardLinksHandler');
9293
})
9394

9495
.run(function($mmEvents, mmCoreEventLogin, mmCoreEventSiteUpdated, mmCoreEventLogout, $mmCoursesDelegate, $mmCourses,

www/core/components/courses/services/handlers.js

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,37 @@ angular.module('mm.core.courses')
2727
var self = {};
2828

2929
/**
30-
* Content links handler for My Courses.
30+
* Content links handler for list of courses.
31+
* It can show the list of available courses or in a certain category. It will show My Courses in old sites.
3132
*
3233
* @module mm.core.courses
3334
* @ngdoc method
3435
* @name $mmCoursesHandlers#myCoursesLinksHandler
3536
*/
36-
self.myCoursesLinksHandler = $mmContentLinkHandlerFactory.createChild(
37+
self.coursesLinksHandler = $mmContentLinkHandlerFactory.createChild(
3738
/\/course\/?(index\.php.*)?$/, '$mmSideMenuDelegate_mmCourses');
3839

3940
// Get actions to perform with the link. See $mmContentLinkHandlerFactory#getActions.
40-
self.myCoursesLinksHandler.getActions = function(siteIds, url, params, courseId) {
41+
self.coursesLinksHandler.getActions = function(siteIds, url, params, courseId) {
4142
return [{
4243
action: function(siteId) {
44+
var state = 'site.mm_courses', // By default, go to My Courses (old Moodles).
45+
stateParams = {};
46+
47+
if ($mmCourses.isGetCoursesByFieldAvailable()) {
48+
if (params.categoryid && $mmCourses.isGetCategoriesAvailable()) {
49+
state = 'site.mm_coursescategories';
50+
stateParams.categoryid = parseInt(params.categoryid, 10);
51+
} else {
52+
state = 'site.mm_availablecourses';
53+
}
54+
}
55+
4356
// Always use redirect to make it the new history root (to avoid "loops" in history).
4457
$state.go('redirect', {
4558
siteid: siteId || $mmSite.getId(),
46-
state: 'site.mm_courses'
59+
state: state,
60+
params: stateParams
4761
});
4862
}
4963
}];
@@ -228,5 +242,28 @@ angular.module('mm.core.courses')
228242
});
229243
}
230244

245+
/**
246+
* Content links handler for Dashboard. For now, it will always go to My Courses.
247+
*
248+
* @module mm.core.courses
249+
* @ngdoc method
250+
* @name $mmCoursesHandlers#dashboardLinksHandler
251+
*/
252+
self.dashboardLinksHandler = $mmContentLinkHandlerFactory.createChild(
253+
/\/my\/?$/, '$mmSideMenuDelegate_mmCourses');
254+
255+
// Get actions to perform with the link. See $mmContentLinkHandlerFactory#getActions.
256+
self.dashboardLinksHandler.getActions = function(siteIds, url, params, courseId) {
257+
return [{
258+
action: function(siteId) {
259+
// Always use redirect to make it the new history root (to avoid "loops" in history).
260+
$state.go('redirect', {
261+
siteid: siteId || $mmSite.getId(),
262+
state: 'site.mm_courses'
263+
});
264+
}
265+
}];
266+
};
267+
231268
return self;
232269
});

0 commit comments

Comments
 (0)