From fdae95d2946f593b120d78f46880d24a2a63655d Mon Sep 17 00:00:00 2001 From: Albert Gasset Date: Mon, 8 Jul 2019 12:07:18 +0200 Subject: [PATCH] MOBILE-2201 course: Tag area handler for activities and resources --- scripts/langindex.json | 1 + src/assets/lang/en.json | 1 + src/core/course/course.module.ts | 7 ++- .../providers/modules-tag-area-handler.ts | 57 +++++++++++++++++++ src/core/tag/lang/en.json | 1 + 5 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 src/core/course/providers/modules-tag-area-handler.ts diff --git a/scripts/langindex.json b/scripts/langindex.json index b9db7a280..f36b31fdf 100644 --- a/scripts/langindex.json +++ b/scripts/langindex.json @@ -1796,6 +1796,7 @@ "core.success": "moodle", "core.tablet": "local_moodlemobileapp", "core.tag.tagarea_course": "moodle", + "core.tag.tagarea_course_modules": "moodle", "core.tag.tags": "moodle", "core.teachers": "moodle", "core.thereisdatatosync": "local_moodlemobileapp", diff --git a/src/assets/lang/en.json b/src/assets/lang/en.json index 1174b5e6a..3dc88e71c 100644 --- a/src/assets/lang/en.json +++ b/src/assets/lang/en.json @@ -1796,6 +1796,7 @@ "core.success": "Success", "core.tablet": "Tablet", "core.tag.tagarea_course": "Courses", + "core.tag.tagarea_course_modules": "Activities and resources", "core.tag.tags": "Tags", "core.teachers": "Teachers", "core.thereisdatatosync": "There are offline {{$a}} to be synchronised.", diff --git a/src/core/course/course.module.ts b/src/core/course/course.module.ts index 4e8206abf..d14844582 100644 --- a/src/core/course/course.module.ts +++ b/src/core/course/course.module.ts @@ -35,6 +35,7 @@ import { CoreCourseSyncCronHandler } from './providers/sync-cron-handler'; import { CoreCourseLogCronHandler } from './providers/log-cron-handler'; import { CoreTagAreaDelegate } from '@core/tag/providers/area-delegate'; import { CoreCourseTagAreaHandler } from './providers/course-tag-area-handler'; +import { CoreCourseModulesTagAreaHandler } from './providers/modules-tag-area-handler'; // List of providers (without handlers). export const CORE_COURSE_PROVIDERS: any[] = [ @@ -71,17 +72,19 @@ export const CORE_COURSE_PROVIDERS: any[] = [ CoreCourseModuleDefaultHandler, CoreCourseSyncCronHandler, CoreCourseLogCronHandler, - CoreCourseTagAreaHandler + CoreCourseTagAreaHandler, + CoreCourseModulesTagAreaHandler ], exports: [] }) export class CoreCourseModule { constructor(cronDelegate: CoreCronDelegate, syncHandler: CoreCourseSyncCronHandler, logHandler: CoreCourseLogCronHandler, platform: Platform, eventsProvider: CoreEventsProvider, tagAreaDelegate: CoreTagAreaDelegate, - courseTagAreaHandler: CoreCourseTagAreaHandler) { + courseTagAreaHandler: CoreCourseTagAreaHandler, modulesTagAreaHandler: CoreCourseModulesTagAreaHandler) { cronDelegate.register(syncHandler); cronDelegate.register(logHandler); tagAreaDelegate.registerHandler(courseTagAreaHandler); + tagAreaDelegate.registerHandler(modulesTagAreaHandler); platform.resume.subscribe(() => { // Log the app is open to keep user in online status. diff --git a/src/core/course/providers/modules-tag-area-handler.ts b/src/core/course/providers/modules-tag-area-handler.ts new file mode 100644 index 000000000..4b7dcfc0a --- /dev/null +++ b/src/core/course/providers/modules-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 CoreCourseModulesTagAreaHandler implements CoreTagAreaHandler { + name = 'CoreCourseModulesTagAreaHandler'; + type = 'core/course_modules'; + + constructor(protected 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/core/tag/lang/en.json b/src/core/tag/lang/en.json index c8303131c..3275d27af 100644 --- a/src/core/tag/lang/en.json +++ b/src/core/tag/lang/en.json @@ -1,4 +1,5 @@ { "tagarea_course": "Courses", + "tagarea_course_modules": "Activities and resources", "tags": "Tags" }