From 602d375a5310a5568b9d8768fb161ea390f8d2d9 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Wed, 31 Jan 2018 11:38:16 +0100 Subject: [PATCH] MOBILE-2344 label: Implement label addon --- src/addon/mod/label/label.module.ts | 37 ++++++++++ src/addon/mod/label/providers/link-handler.ts | 29 ++++++++ .../mod/label/providers/module-handler.ts | 68 +++++++++++++++++++ src/app/app.module.ts | 4 +- 4 files changed, 137 insertions(+), 1 deletion(-) create mode 100644 src/addon/mod/label/label.module.ts create mode 100644 src/addon/mod/label/providers/link-handler.ts create mode 100644 src/addon/mod/label/providers/module-handler.ts diff --git a/src/addon/mod/label/label.module.ts b/src/addon/mod/label/label.module.ts new file mode 100644 index 000000000..f35ee2eaa --- /dev/null +++ b/src/addon/mod/label/label.module.ts @@ -0,0 +1,37 @@ +// (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 { NgModule } from '@angular/core'; +import { AddonModLabelModuleHandler } from './providers/module-handler'; +import { AddonModLabelLinkHandler } from './providers/link-handler'; +import { CoreCourseModuleDelegate } from '../../../core/course/providers/module-delegate'; +import { CoreContentLinksDelegate } from '../../../core/contentlinks/providers/delegate'; + +@NgModule({ + declarations: [ + ], + imports: [ + ], + providers: [ + AddonModLabelModuleHandler, + AddonModLabelLinkHandler + ] +}) +export class AddonModLabelModule { + constructor(moduleDelegate: CoreCourseModuleDelegate, moduleHandler: AddonModLabelModuleHandler, + contentLinksDelegate: CoreContentLinksDelegate, linkHandler: AddonModLabelLinkHandler) { + moduleDelegate.registerHandler(moduleHandler); + contentLinksDelegate.registerHandler(linkHandler); + } +} diff --git a/src/addon/mod/label/providers/link-handler.ts b/src/addon/mod/label/providers/link-handler.ts new file mode 100644 index 000000000..5dc547d8c --- /dev/null +++ b/src/addon/mod/label/providers/link-handler.ts @@ -0,0 +1,29 @@ +// (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 } from '@angular/core'; +import { CoreContentLinksModuleIndexHandler } from '../../../../core/contentlinks/classes/module-index-handler'; +import { CoreCourseHelperProvider } from '../../../../core/course/providers/helper'; + +/** + * Handler to treat links to label. + */ +@Injectable() +export class AddonModLabelLinkHandler extends CoreContentLinksModuleIndexHandler { + name = 'AddonModLabelLinkHandler'; + + constructor(courseHelper: CoreCourseHelperProvider) { + super(courseHelper, 'mmaModLabel', 'label'); + } +} diff --git a/src/addon/mod/label/providers/module-handler.ts b/src/addon/mod/label/providers/module-handler.ts new file mode 100644 index 000000000..a32b9474a --- /dev/null +++ b/src/addon/mod/label/providers/module-handler.ts @@ -0,0 +1,68 @@ +// (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 } from '@angular/core'; +import { CoreCourseModuleHandler, CoreCourseModuleHandlerData } from '../../../../core/course/providers/module-delegate'; + +/** + * Handler to support label modules. + */ +@Injectable() +export class AddonModLabelModuleHandler implements CoreCourseModuleHandler { + name = 'label'; + + constructor() { + // Nothing to do. + } + + /** + * Check if the handler is enabled on a site level. + * + * @return {boolean} Whether or not the handler is enabled on a site level. + */ + isEnabled(): boolean | Promise { + return true; + } + + /** + * Get the data required to display the module in the course contents view. + * + * @param {any} module The module object. + * @param {number} courseId The course ID. + * @param {number} sectionId The section ID. + * @return {CoreCourseModuleHandlerData} Data to render the module. + */ + getData(module: any, courseId: number, sectionId: number): CoreCourseModuleHandlerData { + // Remove the description from the module so it isn't rendered twice. + const title = module.description; + module.description = ''; + + return { + icon: '', + title: title, + class: 'addon-mod-label-handler' + }; + } + + /** + * Get the component to render the module. This is needed to support singleactivity course format. + * + * @param {any} course The course object. + * @param {any} module The module object. + * @return {any} The component to use, undefined if not found. + */ + getMainComponent(course: any, module: any): any { + // There's no need to implement this because label cannot be used in singleactivity course format. + } +} diff --git a/src/app/app.module.ts b/src/app/app.module.ts index d96ef144c..5da362ffc 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -66,6 +66,7 @@ import { CoreUserModule } from '../core/user/user.module'; import { AddonCalendarModule } from '../addon/calendar/calendar.module'; import { AddonUserProfileFieldModule } from '../addon/userprofilefield/userprofilefield.module'; import { AddonFilesModule } from '../addon/files/files.module'; +import { AddonModLabelModule } from '../addon/mod/label/label.module'; // For translate loader. AoT requires an exported function for factories. export function createTranslateLoader(http: HttpClient): TranslateHttpLoader { @@ -103,7 +104,8 @@ export function createTranslateLoader(http: HttpClient): TranslateHttpLoader { CoreUserModule, AddonCalendarModule, AddonUserProfileFieldModule, - AddonFilesModule + AddonFilesModule, + AddonModLabelModule ], bootstrap: [IonicApp], entryComponents: [