MOBILE-2080 forum: Display number of unread posts
parent
1e987c6f09
commit
19c9a7e70e
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -30,7 +30,8 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div *ngIf="module.visible === 0 || module.availabilityinfo">
|
||||
<div *ngIf="module.visible === 0 || module.availabilityinfo || module.handlerData.extraBadge">
|
||||
<ion-badge item-end *ngIf="module.handlerData.extraBadge"><core-format-text [text]="module.handlerData.extraBadge"></core-format-text></ion-badge>
|
||||
<ion-badge item-end *ngIf="module.visible === 0">{{ 'core.course.hiddenfromstudents' | translate }}</ion-badge>
|
||||
<ion-badge item-end *ngIf="module.availabilityinfo"><core-format-text [text]="module.availabilityinfo"></core-format-text></ion-badge>
|
||||
</div>
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue