MOBILE-2201 data: Tag area handler for database records

main
Albert Gasset 2019-07-08 12:16:41 +02:00
parent 82611bcf3a
commit e698537cf7
5 changed files with 68 additions and 2 deletions

View File

@ -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",

View File

@ -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({

View File

@ -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."

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 { 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<boolean>} Whether or not the handler is enabled on a site level.
*/
isEnabled(): boolean | Promise<boolean> {
return this.dataProvider.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

@ -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.",