@@ -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 / \/ c o u r s e \/ ? ( i n d e x \. p h p .* ) ? $ / , '$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+ / \/ m y \/ ? $ / , '$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