Merge pull request #2627 from dpalou/MOBILE-3523

MOBILE-3523 tags: Fix click tags in forum
main
Dani Palou 2020-11-27 12:21:49 +01:00 committed by GitHub
commit 8620535d7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 10 deletions

View File

@ -25,6 +25,7 @@ import { CoreCourseLogHelperProvider } from '@core/course/providers/log-helper';
import { AddonModForumOfflineProvider } from './offline'; import { AddonModForumOfflineProvider } from './offline';
import { CoreRatingInfo } from '@core/rating/providers/rating'; import { CoreRatingInfo } from '@core/rating/providers/rating';
import { CoreCourseCommonModWSOptions } from '@core/course/providers/course'; import { CoreCourseCommonModWSOptions } from '@core/course/providers/course';
import { CoreUrlUtils } from '@providers/utils/url';
/** /**
* Service that provides some features for forums. * Service that provides some features for forums.
@ -539,15 +540,7 @@ export class AddonModForumProvider {
unread: !post.postread, unread: !post.postread,
isprivatereply: !!post.isprivatereply, isprivatereply: !!post.isprivatereply,
tags: (post.tags || []).map((tag) => { tags: post.tags,
return {
id: tag.taginstanceid,
tagid: tag.id,
isstandard: tag.isstandard,
displayname: tag.rawname,
flag: !!tag.flag,
};
}),
}; };
if (post.groupname) { if (post.groupname) {
@ -557,6 +550,29 @@ export class AddonModForumProvider {
return newPost; return newPost;
}); });
}; };
// For some reason, the new WS doesn't use the tags exporter so it returns a different format than other WebServices.
// Convert the new format to the exporter one so it's the same as in other WebServices.
const translateTagsFormatToLegacy = (posts: any[]): any[] => {
posts.forEach((post) => {
post.tags = post.tags.map((tag) => {
const viewUrl = (tag.urls && tag.urls.view) || '';
const params = CoreUrlUtils.instance.extractUrlParams(viewUrl);
return {
id: tag.tagid,
taginstanceid: tag.id,
flag: tag.flag ? 1 : 0,
isstandard: tag.isstandard,
rawname: tag.displayname,
name: tag.displayname,
tagcollid: params.tc ? Number(params.tc) : undefined,
taginstancecontextid: params.from ? Number(params.from) : undefined,
};
});
});
return posts;
};
const params = { const params = {
discussionid: discussionId, discussionid: discussionId,
@ -577,6 +593,8 @@ export class AddonModForumProvider {
if (wsName == 'mod_forum_get_forum_discussion_posts') { if (wsName == 'mod_forum_get_forum_discussion_posts') {
response.posts = translateLegacyPostsFormat(response.posts); response.posts = translateLegacyPostsFormat(response.posts);
} else {
response.posts = translateTagsFormatToLegacy(response.posts);
} }
this.storeUserData(response.posts); this.storeUserData(response.posts);

View File

@ -1,3 +1,3 @@
<ng-container *ngFor="let tag of tags"> <ng-container *ngFor="let tag of tags">
<ion-badge (click)="openTag(tag)" class="core-tag-list-tag">{{ tag.displayname }}</ion-badge> <ion-badge (click)="openTag(tag)" class="core-tag-list-tag">{{ tag.rawname }}</ion-badge>
</ng-container> </ng-container>