Merge pull request #1465 from crazyserver/MOBILE-2080

Mobile 2080
main
Juan Leyva 2018-08-22 13:09:16 +01:00 committed by GitHub
commit 2e47c9484d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 107 additions and 10 deletions

View File

@ -84,7 +84,7 @@ export class AddonModForumIndexComponent extends CoreCourseModuleMainActivityCom
this.newDiscObserver = this.eventsProvider.on(AddonModForumProvider.NEW_DISCUSSION_EVENT, this.eventReceived.bind(this));
this.replyObserver = this.eventsProvider.on(AddonModForumProvider.REPLY_DISCUSSION_EVENT, this.eventReceived.bind(this));
// Select the curren opened discussion.
// Select the current opened discussion.
this.viewDiscObserver = this.eventsProvider.on(AddonModForumProvider.VIEW_DISCUSSION_EVENT, (data) => {
if (this.forum && this.forum.id == data.forumId) {
this.selectedDiscussion = this.splitviewCtrl.isOn() ? data.discussion : 0;

View File

@ -145,7 +145,7 @@ export class AddonModForumDiscussionPage implements OnDestroy {
// Trigger view event, to highlight the current opened discussion in the split view.
this.eventsProvider.trigger(AddonModForumProvider.VIEW_DISCUSSION_EVENT, {
forumId: this.forumId,
discussion: this.discussionId,
discussion: this.discussionId
}, this.sitesProvider.getCurrentSiteId());
}
@ -297,6 +297,12 @@ export class AddonModForumDiscussionPage implements OnDestroy {
// // Add log in Moodle and mark unread posts as readed.
this.forumProvider.logDiscussionView(this.discussionId).catch(() => {
// Ignore errors.
}).finally(() => {
// Trigger mark read posts.
this.eventsProvider.trigger(AddonModForumProvider.MARK_READ_EVENT, {
courseId: this.courseId,
moduleId: this.cmId
}, this.sitesProvider.getCurrentSiteId());
});
}
});

View File

@ -117,7 +117,7 @@ export class AddonModForumNewDiscussionPage implements OnDestroy {
// Trigger view event, to highlight the current opened discussion in the split view.
this.eventsProvider.trigger(AddonModForumProvider.VIEW_DISCUSSION_EVENT, {
forumId: this.forumId,
discussion: -this.timeCreated,
discussion: -this.timeCreated
}, this.sitesProvider.getCurrentSiteId());
}
@ -378,7 +378,7 @@ export class AddonModForumNewDiscussionPage implements OnDestroy {
// Trigger view event, to highlight the current opened discussion in the split view.
this.eventsProvider.trigger(AddonModForumProvider.VIEW_DISCUSSION_EVENT, {
forumId: this.forumId,
discussion: 0,
discussion: 0
}, this.sitesProvider.getCurrentSiteId());
} else {
this.originalData = null; // Avoid asking for confirmation.

View File

@ -32,6 +32,7 @@ export class AddonModForumProvider {
static NEW_DISCUSSION_EVENT = 'addon_mod_forum_new_discussion';
static REPLY_DISCUSSION_EVENT = 'addon_mod_forum_reply_discussion';
static VIEW_DISCUSSION_EVENT = 'addon_mod_forum_view_discussion';
static MARK_READ_EVENT = 'addon_mod_forum_mark_read';
protected ROOT_CACHE_KEY = 'mmaModForum:';

View File

@ -14,9 +14,13 @@
import { Injectable } from '@angular/core';
import { NavController, NavOptions } from 'ionic-angular';
import { AddonModForumIndexComponent } from '../components/index/index';
import { TranslateService } from '@ngx-translate/core';
import { CoreEventsProvider } from '@providers/events';
import { CoreSitesProvider } from '@providers/sites';
import { CoreCourseModuleHandler, CoreCourseModuleHandlerData } from '@core/course/providers/module-delegate';
import { CoreCourseProvider } from '@core/course/providers/course';
import { AddonModForumProvider } from './forum';
import { AddonModForumIndexComponent } from '../components/index/index';
/**
* Handler to support forum modules.
@ -26,7 +30,9 @@ export class AddonModForumModuleHandler implements CoreCourseModuleHandler {
name = 'AddonModForum';
modName = 'forum';
constructor(private courseProvider: CoreCourseProvider) { }
constructor(private courseProvider: CoreCourseProvider, private forumProvider: AddonModForumProvider,
private translate: TranslateService, private eventsProvider: CoreEventsProvider,
private sitesProvider: CoreSitesProvider) {}
/**
* Check if the handler is enabled on a site level.
@ -46,7 +52,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 +61,20 @@ export class AddonModForumModuleHandler implements CoreCourseModuleHandler {
navCtrl.push('AddonModForumIndexPage', {module: module, courseId: courseId}, options);
}
};
this.updateExtraBadge(data, courseId, module.id);
const event = this.eventsProvider.on(AddonModForumProvider.MARK_READ_EVENT, (eventData) => {
if (eventData.courseId == courseId && eventData.moduleId == module.id) {
this.updateExtraBadge(data, eventData.courseId, eventData.moduleId, eventData.siteId);
}
}, this.sitesProvider.getCurrentSiteId());
data.onDestroy = (): void => {
event && event.off();
};
return data;
}
/**
@ -78,4 +98,35 @@ export class AddonModForumModuleHandler implements CoreCourseModuleHandler {
displayRefresherInSingleActivity(): boolean {
return false;
}
/**
* Triggers an update for the extra badge text.
*
* @param {CoreCourseModuleHandlerData} data Course Module Handler data.
* @param {number} courseId Course ID.
* @param {number} moduleId Course module ID.
* @param {string} [siteId] Site ID. If not defined, current site.
*/
updateExtraBadge(data: CoreCourseModuleHandlerData, courseId: number, moduleId: number, siteId?: string): void {
siteId = siteId || this.sitesProvider.getCurrentSiteId();
if (!siteId) {
return;
}
data.extraBadge = this.translate.instant('core.loading');
data.extraBadgeColor = 'light';
this.forumProvider.invalidateForumData(courseId).finally(() => {
// Handle unread posts.
this.forumProvider.getForum(courseId, moduleId, siteId).then((forumData) => {
data.extraBadgeColor = '';
data.extraBadge = forumData.unreadpostscount ? this.translate.instant('addon.mod_forum.unreadpostsnumber',
{$a : forumData.unreadpostscount }) : '';
}).catch(() => {
data.extraBadgeColor = '';
data.extraBadge = '';
// Ignore errors.
});
});
}
}

View File

@ -132,6 +132,24 @@ export class AddonModForumPrefetchHandler extends CoreCourseActivityPrefetchHand
return this.forumProvider.invalidateContent(moduleId, courseId);
}
/**
* Invalidate WS calls needed to determine module status (usually, to check if module is downloadable).
* It doesn't need to invalidate check updates. It should NOT invalidate files nor all the prefetched data.
*
* @param {any} module Module.
* @param {number} courseId Course ID the module belongs to.
* @return {Promise<any>} Promise resolved when invalidated.
*/
invalidateModule(module: any, courseId: number): Promise<any> {
// Invalidate forum data to recalculate unread message count badge.
const promises = [];
promises.push(this.forumProvider.invalidateForumData(courseId));
promises.push(this.courseProvider.invalidateModule(module.id));
return Promise.all(promises);
}
/**
* Prefetch a module.
*

View File

@ -1,6 +1,6 @@
<ion-row *ngIf="actions && actions.length > 0">
<ion-row *ngIf="actions && actions.length > 0" justify-content-around>
<ion-col *ngFor="let action of actions">
<button ion-button icon-left clear small (click)="action.action()">
<button ion-button icon-left clear small block (click)="action.action()">
<ion-icon name="{{action.icon}}"></ion-icon>
{{ action.message | translate }}
</button>

View File

@ -30,7 +30,10 @@
</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" [color]="module.handlerData.extraBadgeColor">
<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>

View File

@ -173,6 +173,7 @@ export class CoreCourseModuleComponent implements OnInit, OnDestroy {
*/
ngOnDestroy(): void {
this.statusObserver && this.statusObserver.off();
this.module && this.module.handlerData && this.module.handlerData.onDestroy && this.module.handlerData.onDestroy();
this.isDestroyed = true;
}
}

View File

@ -85,6 +85,18 @@ export interface CoreCourseModuleHandlerData {
*/
class?: string;
/**
* The text to show in an extra badge.
* @type {string}
*/
extraBadge?: string;
/**
* The color of the extra badge. Default: primary.
* @type {string}
*/
extraBadgeColor?: 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
@ -122,6 +134,11 @@ export interface CoreCourseModuleHandlerData {
* @param {string} status Module status.
*/
updateStatus?(status: string): void;
/**
* On Destroy function in case it's needed.
*/
onDestroy?(): void;
}
/**