MOBILE-2669 resource: Don't get activity data to render after link

main
Pau Ferrer Ocaña 2018-10-31 11:40:01 +01:00
parent 9d0a9ef746
commit 9a405065cb
3 changed files with 41 additions and 13 deletions

View File

@ -77,7 +77,13 @@ export class AddonModForumModuleHandler implements CoreCourseModuleHandler {
} }
}; };
this.updateExtraBadge(data, courseId, module.id); if (typeof module.afterlink != 'undefined') {
data.extraBadgeColor = '';
const match = />(\d+)[^<]+/.exec(module.afterlink);
data.extraBadge = match ? this.translate.instant('addon.mod_forum.unreadpostsnumber', {$a : match[1] }) : '';
} else {
this.updateExtraBadge(data, courseId, module.id);
}
const event = this.eventsProvider.on(AddonModForumProvider.MARK_READ_EVENT, (eventData) => { const event = this.eventsProvider.on(AddonModForumProvider.MARK_READ_EVENT, (eventData) => {
if (eventData.courseId == courseId && eventData.moduleId == module.id) { if (eventData.courseId == courseId && eventData.moduleId == module.id) {

View File

@ -134,27 +134,30 @@ export class AddonModResourceModuleHandler implements CoreCourseModuleHandler {
*/ */
protected getResourceData(module: any, courseId: number, handlerData: CoreCourseModuleHandlerData): Promise<any> { protected getResourceData(module: any, courseId: number, handlerData: CoreCourseModuleHandlerData): Promise<any> {
const promises = []; const promises = [];
let resourceInfo; let infoFiles = [],
options: any = {};
// Check if the button needs to be shown or not. This also loads the module contents. // Check if the button needs to be shown or not. This also loads the module contents.
promises.push(this.hideOpenButton(module, courseId).then((hideOpenButton) => { promises.push(this.hideOpenButton(module, courseId).then((hideOpenButton) => {
handlerData.buttons[0].hidden = hideOpenButton; handlerData.buttons[0].hidden = hideOpenButton;
})); }));
if (this.resourceProvider.isGetResourceWSAvailable()) { if (typeof module.customdata != 'undefined') {
options = this.textUtils.unserialize(this.textUtils.parseJSON(module.customdata));
} else if (this.resourceProvider.isGetResourceWSAvailable()) {
// Get the resource data. // Get the resource data.
promises.push(this.resourceProvider.getResourceData(courseId, module.id).then((info) => { promises.push(this.resourceProvider.getResourceData(courseId, module.id).then((info) => {
resourceInfo = info; infoFiles = info.contentfiles;
options = this.textUtils.unserialize(info.displayoptions);
})); }));
} }
return Promise.all(promises).then(() => { return Promise.all(promises).then(() => {
const files = module.contents && module.contents.length ? module.contents : resourceInfo && resourceInfo.contentfiles, const files = module.contents && module.contents.length ? module.contents : infoFiles,
resourceData = { resourceData = {
icon: '', icon: '',
extra: '' extra: ''
}, },
options = (resourceInfo && this.textUtils.unserialize(resourceInfo.displayoptions)) || {},
extra = []; extra = [];
if (files && files.length) { if (files && files.length) {
@ -162,19 +165,32 @@ export class AddonModResourceModuleHandler implements CoreCourseModuleHandler {
resourceData.icon = this.mimetypeUtils.getFileIcon(file.filename); resourceData.icon = this.mimetypeUtils.getFileIcon(file.filename);
if (options.showsize) { if (options.showsize) {
const size = files.reduce((result, file) => { let size;
return result + file.filesize; if (options.filedetails) {
}, 0); size = options.filedetails.size;
} else {
size = files.reduce((result, file) => {
return result + file.filesize;
}, 0);
}
extra.push(this.textUtils.bytesToSize(size, 1)); extra.push(this.textUtils.bytesToSize(size, 1));
} }
if (options.showtype) { if (options.showtype) {
// We should take it from options.filedetails.size if avalaible ∫but it's already translated.
extra.push(this.mimetypeUtils.getMimetypeDescription(file)); extra.push(this.mimetypeUtils.getMimetypeDescription(file));
} }
if (options.showdate) { if (options.showdate) {
/* Modified date may be up to several minutes later than uploaded date just because if (options.filedetails && options.filedetails.modifieddate) {
teacher did not submit the form promptly. Give teacher up to 5 minutes to do it. */ extra.push(this.translate.instant('addon.mod_resource.modifieddate',
if (file.timemodified > file.timecreated + CoreConstants.SECONDS_MINUTE * 5) { {$a: moment(options.filedetails.modifieddate * 1000).format('LLL')}));
} else if (options.filedetails && options.filedetails.uploadeddate) {
extra.push(this.translate.instant('addon.mod_resource.uploadeddate',
{$a: moment(options.filedetails.uploadeddate * 1000).format('LLL')}));
} else if (file.timemodified > file.timecreated + CoreConstants.SECONDS_MINUTE * 5) {
/* Modified date may be up to several minutes later than uploaded date just because
teacher did not submit the form promptly. Give teacher up to 5 minutes to do it. */
extra.push(this.translate.instant('addon.mod_resource.modifieddate', extra.push(this.translate.instant('addon.mod_resource.modifieddate',
{$a: moment(file.timemodified * 1000).format('LLL')})); {$a: moment(file.timemodified * 1000).format('LLL')}));
} else { } else {

View File

@ -152,11 +152,17 @@ export class CoreCourseHelperProvider {
module.completiondata.courseName = courseName; module.completiondata.courseName = courseName;
module.completiondata.tracking = module.completion; module.completiondata.tracking = module.completion;
module.completiondata.cmid = module.id; module.completiondata.cmid = module.id;
// Use of completionstatus is deprecated, use completiondata instead.
module.completionstatus = module.completiondata;
} else if (completionStatus && typeof completionStatus[module.id] != 'undefined') { } else if (completionStatus && typeof completionStatus[module.id] != 'undefined') {
// Not in use > 3.6. Check if activity has completions and if it's marked. // Should not happen on > 3.6. Check if activity has completions and if it's marked.
module.completiondata = completionStatus[module.id]; module.completiondata = completionStatus[module.id];
module.completiondata.courseId = courseId; module.completiondata.courseId = courseId;
module.completiondata.courseName = courseName; module.completiondata.courseName = courseName;
// Use of completionstatus is deprecated, use completiondata instead.
module.completionstatus = module.completiondata;
} }
// Check if the module is stealth. // Check if the module is stealth.