From df423b640e45a3115debd2e7573a0f291ece839d Mon Sep 17 00:00:00 2001 From: Albert Gasset Date: Mon, 8 Jul 2019 12:09:57 +0200 Subject: [PATCH] MOBILE-2201 blog: Tag area handler for blog posts --- scripts/langindex.json | 1 + src/addon/blog/blog.module.ts | 9 ++- src/addon/blog/providers/tag-area-handler.ts | 58 ++++++++++++++++++++ src/assets/lang/en.json | 1 + src/core/tag/lang/en.json | 1 + 5 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 src/addon/blog/providers/tag-area-handler.ts diff --git a/scripts/langindex.json b/scripts/langindex.json index f36b31fdf..c40287ac5 100644 --- a/scripts/langindex.json +++ b/scripts/langindex.json @@ -1797,6 +1797,7 @@ "core.tablet": "local_moodlemobileapp", "core.tag.tagarea_course": "moodle", "core.tag.tagarea_course_modules": "moodle", + "core.tag.tagarea_post": "moodle", "core.tag.tags": "moodle", "core.teachers": "moodle", "core.thereisdatatosync": "local_moodlemobileapp", diff --git a/src/addon/blog/blog.module.ts b/src/addon/blog/blog.module.ts index f31372745..b697ba27a 100644 --- a/src/addon/blog/blog.module.ts +++ b/src/addon/blog/blog.module.ts @@ -17,12 +17,14 @@ import { CoreMainMenuDelegate } from '@core/mainmenu/providers/delegate'; import { CoreUserDelegate } from '@core/user/providers/user-delegate'; import { CoreCourseOptionsDelegate } from '@core/course/providers/options-delegate'; import { CoreContentLinksDelegate } from '@core/contentlinks/providers/delegate'; +import { CoreTagAreaDelegate } from '@core/tag/providers/area-delegate'; import { AddonBlogProvider } from './providers/blog'; import { AddonBlogMainMenuHandler } from './providers/mainmenu-handler'; import { AddonBlogUserHandler } from './providers/user-handler'; import { AddonBlogCourseOptionHandler } from './providers/course-option-handler'; import { AddonBlogComponentsModule } from './components/components.module'; import { AddonBlogIndexLinkHandler } from './providers/index-link-handler'; +import { AddonBlogTagAreaHandler } from './providers/tag-area-handler'; @NgModule({ declarations: [ @@ -35,17 +37,20 @@ import { AddonBlogIndexLinkHandler } from './providers/index-link-handler'; AddonBlogMainMenuHandler, AddonBlogUserHandler, AddonBlogCourseOptionHandler, - AddonBlogIndexLinkHandler + AddonBlogIndexLinkHandler, + AddonBlogTagAreaHandler ] }) export class AddonBlogModule { constructor(mainMenuDelegate: CoreMainMenuDelegate, menuHandler: AddonBlogMainMenuHandler, userHandler: AddonBlogUserHandler, userDelegate: CoreUserDelegate, courseOptionHandler: AddonBlogCourseOptionHandler, courseOptionsDelegate: CoreCourseOptionsDelegate, - linkHandler: AddonBlogIndexLinkHandler, contentLinksDelegate: CoreContentLinksDelegate) { + linkHandler: AddonBlogIndexLinkHandler, contentLinksDelegate: CoreContentLinksDelegate, + tagAreaDelegate: CoreTagAreaDelegate, tagAreaHandler: AddonBlogTagAreaHandler) { mainMenuDelegate.registerHandler(menuHandler); userDelegate.registerHandler(userHandler); courseOptionsDelegate.registerHandler(courseOptionHandler); contentLinksDelegate.registerHandler(linkHandler); + tagAreaDelegate.registerHandler(tagAreaHandler); } } diff --git a/src/addon/blog/providers/tag-area-handler.ts b/src/addon/blog/providers/tag-area-handler.ts new file mode 100644 index 000000000..41413d824 --- /dev/null +++ b/src/addon/blog/providers/tag-area-handler.ts @@ -0,0 +1,58 @@ +// (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'; +import { AddonBlogProvider } from './blog'; + +/** + * Handler to support tags. + */ +@Injectable() +export class AddonBlogTagAreaHandler implements CoreTagAreaHandler { + name = 'AddonBlogTagAreaHandler'; + type = 'core/post'; + + constructor(private tagHelper: CoreTagHelperProvider, private blogProvider: AddonBlogProvider) {} + + /** + * 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 this.blogProvider.isPluginEnabled(); + } + + /** + * 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 3dc88e71c..344ae3a2c 100644 --- a/src/assets/lang/en.json +++ b/src/assets/lang/en.json @@ -1797,6 +1797,7 @@ "core.tablet": "Tablet", "core.tag.tagarea_course": "Courses", "core.tag.tagarea_course_modules": "Activities and resources", + "core.tag.tagarea_post": "Blog posts", "core.tag.tags": "Tags", "core.teachers": "Teachers", "core.thereisdatatosync": "There are offline {{$a}} to be synchronised.", diff --git a/src/core/tag/lang/en.json b/src/core/tag/lang/en.json index 3275d27af..ce6aec9f1 100644 --- a/src/core/tag/lang/en.json +++ b/src/core/tag/lang/en.json @@ -1,5 +1,6 @@ { "tagarea_course": "Courses", "tagarea_course_modules": "Activities and resources", + "tagarea_post": "Blog posts", "tags": "Tags" }