MOBILE-2201 blog: Tag area handler for blog posts

main
Albert Gasset 2019-07-08 12:09:57 +02:00
parent fdae95d294
commit df423b640e
5 changed files with 68 additions and 2 deletions

View File

@ -1797,6 +1797,7 @@
"core.tablet": "local_moodlemobileapp", "core.tablet": "local_moodlemobileapp",
"core.tag.tagarea_course": "moodle", "core.tag.tagarea_course": "moodle",
"core.tag.tagarea_course_modules": "moodle", "core.tag.tagarea_course_modules": "moodle",
"core.tag.tagarea_post": "moodle",
"core.tag.tags": "moodle", "core.tag.tags": "moodle",
"core.teachers": "moodle", "core.teachers": "moodle",
"core.thereisdatatosync": "local_moodlemobileapp", "core.thereisdatatosync": "local_moodlemobileapp",

View File

@ -17,12 +17,14 @@ import { CoreMainMenuDelegate } from '@core/mainmenu/providers/delegate';
import { CoreUserDelegate } from '@core/user/providers/user-delegate'; import { CoreUserDelegate } from '@core/user/providers/user-delegate';
import { CoreCourseOptionsDelegate } from '@core/course/providers/options-delegate'; import { CoreCourseOptionsDelegate } from '@core/course/providers/options-delegate';
import { CoreContentLinksDelegate } from '@core/contentlinks/providers/delegate'; import { CoreContentLinksDelegate } from '@core/contentlinks/providers/delegate';
import { CoreTagAreaDelegate } from '@core/tag/providers/area-delegate';
import { AddonBlogProvider } from './providers/blog'; import { AddonBlogProvider } from './providers/blog';
import { AddonBlogMainMenuHandler } from './providers/mainmenu-handler'; import { AddonBlogMainMenuHandler } from './providers/mainmenu-handler';
import { AddonBlogUserHandler } from './providers/user-handler'; import { AddonBlogUserHandler } from './providers/user-handler';
import { AddonBlogCourseOptionHandler } from './providers/course-option-handler'; import { AddonBlogCourseOptionHandler } from './providers/course-option-handler';
import { AddonBlogComponentsModule } from './components/components.module'; import { AddonBlogComponentsModule } from './components/components.module';
import { AddonBlogIndexLinkHandler } from './providers/index-link-handler'; import { AddonBlogIndexLinkHandler } from './providers/index-link-handler';
import { AddonBlogTagAreaHandler } from './providers/tag-area-handler';
@NgModule({ @NgModule({
declarations: [ declarations: [
@ -35,17 +37,20 @@ import { AddonBlogIndexLinkHandler } from './providers/index-link-handler';
AddonBlogMainMenuHandler, AddonBlogMainMenuHandler,
AddonBlogUserHandler, AddonBlogUserHandler,
AddonBlogCourseOptionHandler, AddonBlogCourseOptionHandler,
AddonBlogIndexLinkHandler AddonBlogIndexLinkHandler,
AddonBlogTagAreaHandler
] ]
}) })
export class AddonBlogModule { export class AddonBlogModule {
constructor(mainMenuDelegate: CoreMainMenuDelegate, menuHandler: AddonBlogMainMenuHandler, constructor(mainMenuDelegate: CoreMainMenuDelegate, menuHandler: AddonBlogMainMenuHandler,
userHandler: AddonBlogUserHandler, userDelegate: CoreUserDelegate, userHandler: AddonBlogUserHandler, userDelegate: CoreUserDelegate,
courseOptionHandler: AddonBlogCourseOptionHandler, courseOptionsDelegate: CoreCourseOptionsDelegate, courseOptionHandler: AddonBlogCourseOptionHandler, courseOptionsDelegate: CoreCourseOptionsDelegate,
linkHandler: AddonBlogIndexLinkHandler, contentLinksDelegate: CoreContentLinksDelegate) { linkHandler: AddonBlogIndexLinkHandler, contentLinksDelegate: CoreContentLinksDelegate,
tagAreaDelegate: CoreTagAreaDelegate, tagAreaHandler: AddonBlogTagAreaHandler) {
mainMenuDelegate.registerHandler(menuHandler); mainMenuDelegate.registerHandler(menuHandler);
userDelegate.registerHandler(userHandler); userDelegate.registerHandler(userHandler);
courseOptionsDelegate.registerHandler(courseOptionHandler); courseOptionsDelegate.registerHandler(courseOptionHandler);
contentLinksDelegate.registerHandler(linkHandler); contentLinksDelegate.registerHandler(linkHandler);
tagAreaDelegate.registerHandler(tagAreaHandler);
} }
} }

View File

@ -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<boolean>} Whether or not the handler is enabled on a site level.
*/
isEnabled(): boolean | Promise<boolean> {
return this.blogProvider.isPluginEnabled();
}
/**
* Parses the rendered content of a tag index and returns the items.
*
* @param {string} content Rendered content.
* @return {any[]|Promise<any[]>} Area items (or promise resolved with the items).
*/
parseContent(content: string): any[] | Promise<any[]> {
return this.tagHelper.parseFeedContent(content);
}
/**
* Get the component to use to display items.
*
* @param {Injector} injector Injector.
* @return {any|Promise<any>} The component (or promise resolved with component) to use, undefined if not found.
*/
getComponent(injector: Injector): any | Promise<any> {
return CoreTagFeedComponent;
}
}

View File

@ -1797,6 +1797,7 @@
"core.tablet": "Tablet", "core.tablet": "Tablet",
"core.tag.tagarea_course": "Courses", "core.tag.tagarea_course": "Courses",
"core.tag.tagarea_course_modules": "Activities and resources", "core.tag.tagarea_course_modules": "Activities and resources",
"core.tag.tagarea_post": "Blog posts",
"core.tag.tags": "Tags", "core.tag.tags": "Tags",
"core.teachers": "Teachers", "core.teachers": "Teachers",
"core.thereisdatatosync": "There are offline {{$a}} to be synchronised.", "core.thereisdatatosync": "There are offline {{$a}} to be synchronised.",

View File

@ -1,5 +1,6 @@
{ {
"tagarea_course": "Courses", "tagarea_course": "Courses",
"tagarea_course_modules": "Activities and resources", "tagarea_course_modules": "Activities and resources",
"tagarea_post": "Blog posts",
"tags": "Tags" "tags": "Tags"
} }