From e698537cf74846b13fba9aabdfbc13ac817e353a Mon Sep 17 00:00:00 2001 From: Albert Gasset Date: Mon, 8 Jul 2019 12:16:41 +0200 Subject: [PATCH] MOBILE-2201 data: Tag area handler for database records --- scripts/langindex.json | 1 + src/addon/mod/data/data.module.ts | 9 ++- src/addon/mod/data/lang/en.json | 1 + .../mod/data/providers/tag-area-handler.ts | 58 +++++++++++++++++++ src/assets/lang/en.json | 1 + 5 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 src/addon/mod/data/providers/tag-area-handler.ts diff --git a/scripts/langindex.json b/scripts/langindex.json index 57c4bf18d..ac7fabe30 100644 --- a/scripts/langindex.json +++ b/scripts/langindex.json @@ -460,6 +460,7 @@ "addon.mod_data.searchbytagsnotsupported": "local_moodlemobileapp", "addon.mod_data.selectedrequired": "data", "addon.mod_data.single": "data", + "addon.mod_data.tagarea_data_records": "data", "addon.mod_data.timeadded": "data", "addon.mod_data.timemodified": "data", "addon.mod_data.usedate": "data", diff --git a/src/addon/mod/data/data.module.ts b/src/addon/mod/data/data.module.ts index 9babfa364..158865aec 100644 --- a/src/addon/mod/data/data.module.ts +++ b/src/addon/mod/data/data.module.ts @@ -33,6 +33,8 @@ import { AddonModDataSyncCronHandler } from './providers/sync-cron-handler'; import { AddonModDataOfflineProvider } from './providers/offline'; import { AddonModDataFieldsDelegate } from './providers/fields-delegate'; import { AddonModDataDefaultFieldHandler } from './providers/default-field-handler'; +import { CoreTagAreaDelegate } from '@core/tag/providers/area-delegate'; +import { AddonModDataTagAreaHandler } from './providers/tag-area-handler'; import { AddonModDataFieldModule } from './fields/field.module'; import { CoreUpdateManagerProvider } from '@providers/update-manager'; @@ -67,7 +69,8 @@ export const ADDON_MOD_DATA_PROVIDERS: any[] = [ AddonModDataEditLinkHandler, AddonModDataListLinkHandler, AddonModDataSyncCronHandler, - AddonModDataDefaultFieldHandler + AddonModDataDefaultFieldHandler, + AddonModDataTagAreaHandler ] }) export class AddonModDataModule { @@ -77,7 +80,8 @@ export class AddonModDataModule { cronDelegate: CoreCronDelegate, syncHandler: AddonModDataSyncCronHandler, updateManager: CoreUpdateManagerProvider, approveLinkHandler: AddonModDataApproveLinkHandler, deleteLinkHandler: AddonModDataDeleteLinkHandler, showLinkHandler: AddonModDataShowLinkHandler, editLinkHandler: AddonModDataEditLinkHandler, - listLinkHandler: AddonModDataListLinkHandler) { + listLinkHandler: AddonModDataListLinkHandler, tagAreaDelegate: CoreTagAreaDelegate, + tagAreaHandler: AddonModDataTagAreaHandler) { moduleDelegate.registerHandler(moduleHandler); prefetchDelegate.registerHandler(prefetchHandler); @@ -88,6 +92,7 @@ export class AddonModDataModule { contentLinksDelegate.registerHandler(editLinkHandler); contentLinksDelegate.registerHandler(listLinkHandler); cronDelegate.register(syncHandler); + tagAreaDelegate.registerHandler(tagAreaHandler); // Allow migrating the tables from the old app to the new schema. updateManager.registerSiteTableMigration({ diff --git a/src/addon/mod/data/lang/en.json b/src/addon/mod/data/lang/en.json index f7c0005dc..219ec090c 100644 --- a/src/addon/mod/data/lang/en.json +++ b/src/addon/mod/data/lang/en.json @@ -38,6 +38,7 @@ "searchbytagsnotsupported": "Sorry, searching by tags is not supported by the app.", "selectedrequired": "All selected required", "single": "View single", + "tagarea_data_records": "Data records", "timeadded": "Time added", "timemodified": "Time modified", "usedate": "Include in search." diff --git a/src/addon/mod/data/providers/tag-area-handler.ts b/src/addon/mod/data/providers/tag-area-handler.ts new file mode 100644 index 000000000..f7fb15098 --- /dev/null +++ b/src/addon/mod/data/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 { AddonModDataProvider } from './data'; + +/** + * Handler to support tags. + */ +@Injectable() +export class AddonModDataTagAreaHandler implements CoreTagAreaHandler { + name = 'AddonModDataTagAreaHandler'; + type = 'mod_data/data_records'; + + constructor(private tagHelper: CoreTagHelperProvider, private dataProvider: AddonModDataProvider) {} + + /** + * 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.dataProvider.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 121bd0dba..ba1bfb778 100644 --- a/src/assets/lang/en.json +++ b/src/assets/lang/en.json @@ -460,6 +460,7 @@ "addon.mod_data.searchbytagsnotsupported": "Sorry, searching by tags is not supported by the app.", "addon.mod_data.selectedrequired": "All selected required", "addon.mod_data.single": "View single", + "addon.mod_data.tagarea_data_records": "Data records", "addon.mod_data.timeadded": "Time added", "addon.mod_data.timemodified": "Time modified", "addon.mod_data.usedate": "Include in search.",