From f1591b1113e74ccb415a0a448686715d720c8f4b Mon Sep 17 00:00:00 2001 From: Albert Gasset Date: Mon, 8 Jul 2019 12:17:47 +0200 Subject: [PATCH] MOBILE-2201 forum: Tag area handler for forum posts --- scripts/langindex.json | 1 + src/addon/mod/forum/forum.module.ts | 9 ++- src/addon/mod/forum/lang/en.json | 1 + .../mod/forum/providers/tag-area-handler.ts | 57 +++++++++++++++++++ src/assets/lang/en.json | 1 + 5 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 src/addon/mod/forum/providers/tag-area-handler.ts diff --git a/scripts/langindex.json b/scripts/langindex.json index ac7fabe30..cb110da9c 100644 --- a/scripts/langindex.json +++ b/scripts/langindex.json @@ -553,6 +553,7 @@ "addon.mod_forum.reply": "forum", "addon.mod_forum.replyplaceholder": "forum", "addon.mod_forum.subject": "forum", + "addon.mod_forum.tagarea_forum_posts": "forum", "addon.mod_forum.thisforumhasduedate": "forum", "addon.mod_forum.thisforumisdue": "forum", "addon.mod_forum.unlockdiscussion": "forum", diff --git a/src/addon/mod/forum/forum.module.ts b/src/addon/mod/forum/forum.module.ts index 94fe30257..b8463c714 100644 --- a/src/addon/mod/forum/forum.module.ts +++ b/src/addon/mod/forum/forum.module.ts @@ -18,6 +18,7 @@ import { CoreCourseModuleDelegate } from '@core/course/providers/module-delegate import { CoreCourseModulePrefetchDelegate } from '@core/course/providers/module-prefetch-delegate'; import { CoreContentLinksDelegate } from '@core/contentlinks/providers/delegate'; import { CorePushNotificationsDelegate } from '@core/pushnotifications/providers/delegate'; +import { CoreTagAreaDelegate } from '@core/tag/providers/area-delegate'; import { AddonModForumProvider } from './providers/forum'; import { AddonModForumOfflineProvider } from './providers/offline'; import { AddonModForumHelperProvider } from './providers/helper'; @@ -30,6 +31,7 @@ import { AddonModForumDiscussionLinkHandler } from './providers/discussion-link- import { AddonModForumListLinkHandler } from './providers/list-link-handler'; import { AddonModForumPostLinkHandler } from './providers/post-link-handler'; import { AddonModForumPushClickHandler } from './providers/push-click-handler'; +import { AddonModForumTagAreaHandler } from './providers/tag-area-handler'; import { AddonModForumComponentsModule } from './components/components.module'; import { CoreUpdateManagerProvider } from '@providers/update-manager'; @@ -59,7 +61,8 @@ export const ADDON_MOD_FORUM_PROVIDERS: any[] = [ AddonModForumListLinkHandler, AddonModForumPostLinkHandler, AddonModForumDiscussionLinkHandler, - AddonModForumPushClickHandler + AddonModForumPushClickHandler, + AddonModForumTagAreaHandler ] }) export class AddonModForumModule { @@ -69,7 +72,8 @@ export class AddonModForumModule { indexHandler: AddonModForumIndexLinkHandler, discussionHandler: AddonModForumDiscussionLinkHandler, updateManager: CoreUpdateManagerProvider, listLinkHandler: AddonModForumListLinkHandler, pushNotificationsDelegate: CorePushNotificationsDelegate, pushClickHandler: AddonModForumPushClickHandler, - postLinkHandler: AddonModForumPostLinkHandler) { + postLinkHandler: AddonModForumPostLinkHandler, tagAreaDelegate: CoreTagAreaDelegate, + tagAreaHandler: AddonModForumTagAreaHandler) { moduleDelegate.registerHandler(moduleHandler); prefetchDelegate.registerHandler(prefetchHandler); @@ -79,6 +83,7 @@ export class AddonModForumModule { linksDelegate.registerHandler(listLinkHandler); linksDelegate.registerHandler(postLinkHandler); pushNotificationsDelegate.registerClickHandler(pushClickHandler); + tagAreaDelegate.registerHandler(tagAreaHandler); // Allow migrating the tables from the old app to the new schema. updateManager.registerSiteTablesMigration([ diff --git a/src/addon/mod/forum/lang/en.json b/src/addon/mod/forum/lang/en.json index 93e72d2c2..dbfac5fd3 100644 --- a/src/addon/mod/forum/lang/en.json +++ b/src/addon/mod/forum/lang/en.json @@ -50,6 +50,7 @@ "reply": "Reply", "replyplaceholder": "Write your reply...", "subject": "Subject", + "tagarea_forum_posts": "Forum posts", "thisforumhasduedate": "The due date for posting to this forum is {{$a}}.", "thisforumisdue": "The due date for posting to this forum was {{$a}}.", "unlockdiscussion": "Unlock this discussion", diff --git a/src/addon/mod/forum/providers/tag-area-handler.ts b/src/addon/mod/forum/providers/tag-area-handler.ts new file mode 100644 index 000000000..02505b31c --- /dev/null +++ b/src/addon/mod/forum/providers/tag-area-handler.ts @@ -0,0 +1,57 @@ +// (C) Copyright 2015 Martin Dougiamas +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import { Injectable, Injector } from '@angular/core'; +import { CoreTagAreaHandler } from '@core/tag/providers/area-delegate'; +import { CoreTagHelperProvider } from '@core/tag/providers/helper'; +import { CoreTagFeedComponent } from '@core/tag/components/feed/feed'; + +/** + * Handler to support tags. + */ +@Injectable() +export class AddonModForumTagAreaHandler implements CoreTagAreaHandler { + name = 'AddonModForumTagAreaHandler'; + type = 'mod_forum/forum_posts'; + + constructor(private tagHelper: CoreTagHelperProvider) {} + + /** + * Whether or not the handler is enabled on a site level. + * @return {boolean|Promise} Whether or not the handler is enabled on a site level. + */ + isEnabled(): boolean | Promise { + return true; + } + + /** + * Parses the rendered content of a tag index and returns the items. + * + * @param {string} content Rendered content. + * @return {any[]|Promise} Area items (or promise resolved with the items). + */ + parseContent(content: string): any[] | Promise { + return this.tagHelper.parseFeedContent(content); + } + + /** + * Get the component to use to display items. + * + * @param {Injector} injector Injector. + * @return {any|Promise} The component (or promise resolved with component) to use, undefined if not found. + */ + getComponent(injector: Injector): any | Promise { + return CoreTagFeedComponent; + } +} diff --git a/src/assets/lang/en.json b/src/assets/lang/en.json index ba1bfb778..cb31d3779 100644 --- a/src/assets/lang/en.json +++ b/src/assets/lang/en.json @@ -553,6 +553,7 @@ "addon.mod_forum.reply": "Reply", "addon.mod_forum.replyplaceholder": "Write your reply...", "addon.mod_forum.subject": "Subject", + "addon.mod_forum.tagarea_forum_posts": "Forum posts", "addon.mod_forum.thisforumhasduedate": "The due date for posting to this forum is {{$a}}.", "addon.mod_forum.thisforumisdue": "The due date for posting to this forum was {{$a}}.", "addon.mod_forum.unlockdiscussion": "Unlock this discussion",