diff --git a/src/addon/mod/forum/providers/module-handler.ts b/src/addon/mod/forum/providers/module-handler.ts index be911f52d..0b42c9a51 100644 --- a/src/addon/mod/forum/providers/module-handler.ts +++ b/src/addon/mod/forum/providers/module-handler.ts @@ -14,9 +14,11 @@ import { Injectable } from '@angular/core'; import { NavController, NavOptions } from 'ionic-angular'; +import { TranslateService } from '@ngx-translate/core'; import { AddonModForumIndexComponent } from '../components/index/index'; import { CoreCourseModuleHandler, CoreCourseModuleHandlerData } from '@core/course/providers/module-delegate'; import { CoreCourseProvider } from '@core/course/providers/course'; +import { AddonModForumProvider } from './forum'; /** * Handler to support forum modules. @@ -26,7 +28,8 @@ export class AddonModForumModuleHandler implements CoreCourseModuleHandler { name = 'AddonModForum'; modName = 'forum'; - constructor(private courseProvider: CoreCourseProvider) { } + constructor(private courseProvider: CoreCourseProvider, private forumProvider: AddonModForumProvider, + private translate: TranslateService) { } /** * Check if the handler is enabled on a site level. @@ -46,7 +49,7 @@ export class AddonModForumModuleHandler implements CoreCourseModuleHandler { * @return {CoreCourseModuleHandlerData} Data to render the module. */ getData(module: any, courseId: number, sectionId: number): CoreCourseModuleHandlerData { - return { + const data: CoreCourseModuleHandlerData = { icon: this.courseProvider.getModuleIconSrc('forum'), title: module.name, class: 'addon-mod_forum-handler', @@ -55,6 +58,16 @@ export class AddonModForumModuleHandler implements CoreCourseModuleHandler { navCtrl.push('AddonModForumIndexPage', {module: module, courseId: courseId}, options); } }; + + // Handle unread posts. + this.forumProvider.getForum(courseId, module.id).then((forumData) => { + data.extraBadge = forumData.unreadpostscount ? this.translate.instant('addon.mod_forum.unreadpostsnumber', + {$a : forumData.unreadpostscount }) : ''; + }).catch(() => { + // Ignore errors. + }); + + return data; } /** diff --git a/src/core/course/components/module/core-course-module.html b/src/core/course/components/module/core-course-module.html index b42669557..9aa9ff37c 100644 --- a/src/core/course/components/module/core-course-module.html +++ b/src/core/course/components/module/core-course-module.html @@ -30,7 +30,8 @@ -
+
+ {{ 'core.course.hiddenfromstudents' | translate }}
diff --git a/src/core/course/providers/module-delegate.ts b/src/core/course/providers/module-delegate.ts index b4981020e..a61f3dbda 100644 --- a/src/core/course/providers/module-delegate.ts +++ b/src/core/course/providers/module-delegate.ts @@ -85,6 +85,12 @@ export interface CoreCourseModuleHandlerData { */ class?: string; + /** + * The text to show in an extra badge. + * @type {string} + */ + extraBadge?: string; + /** * Whether to display a button to download/refresh the module if it's downloadable. * If it's set to true, the app will show a download/refresh button when needed and will handle the download of the