From 26a1fad8c8e1009f1a20f39f8005890e3e3d504d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Wed, 8 May 2019 11:33:58 +0200 Subject: [PATCH 1/9] MOBILE-3014 block: Support for only title block type --- .../providers/block-handler.ts | 2 +- .../myoverview/providers/block-handler.ts | 2 +- .../providers/block-handler.ts | 2 +- .../providers/block-handler.ts | 2 +- .../sitemainmenu/providers/block-handler.ts | 2 +- .../starredcourses/providers/block-handler.ts | 2 +- .../block/timeline/providers/block-handler.ts | 2 +- .../block/classes/base-block-component.ts | 9 +++- src/core/block/classes/base-block-handler.ts | 2 +- src/core/block/components/block/block.ts | 5 +- .../block/components/components.module.ts | 12 ++++- .../core-block-only-title.html | 3 ++ .../only-title-block/only-title-block.ts | 50 +++++++++++++++++++ src/core/block/providers/delegate.ts | 15 +++++- 14 files changed, 96 insertions(+), 14 deletions(-) create mode 100644 src/core/block/components/only-title-block/core-block-only-title.html create mode 100644 src/core/block/components/only-title-block/only-title-block.ts diff --git a/src/addon/block/activitymodules/providers/block-handler.ts b/src/addon/block/activitymodules/providers/block-handler.ts index 0024324c9..752d23a47 100644 --- a/src/addon/block/activitymodules/providers/block-handler.ts +++ b/src/addon/block/activitymodules/providers/block-handler.ts @@ -38,7 +38,7 @@ export class AddonBlockActivityModulesHandler extends CoreBlockBaseHandler { * @param {number} instanceId The instance ID associated with the context level. * @return {CoreBlockHandlerData|Promise} Data or promise resolved with the data. */ - getDisplayData?(injector: Injector, block: any, contextLevel: string, instanceId: number) + getDisplayData(injector: Injector, block: any, contextLevel: string, instanceId: number) : CoreBlockHandlerData | Promise { return { diff --git a/src/addon/block/myoverview/providers/block-handler.ts b/src/addon/block/myoverview/providers/block-handler.ts index 5f723467c..e0a593b9a 100644 --- a/src/addon/block/myoverview/providers/block-handler.ts +++ b/src/addon/block/myoverview/providers/block-handler.ts @@ -50,7 +50,7 @@ export class AddonBlockMyOverviewHandler extends CoreBlockBaseHandler { * @param {number} instanceId The instance ID associated with the context level. * @return {CoreBlockHandlerData|Promise} Data or promise resolved with the data. */ - getDisplayData?(injector: Injector, block: any, contextLevel: string, instanceId: number) + getDisplayData(injector: Injector, block: any, contextLevel: string, instanceId: number) : CoreBlockHandlerData | Promise { return { diff --git a/src/addon/block/recentlyaccessedcourses/providers/block-handler.ts b/src/addon/block/recentlyaccessedcourses/providers/block-handler.ts index a1117bd5d..3af9cf0dd 100644 --- a/src/addon/block/recentlyaccessedcourses/providers/block-handler.ts +++ b/src/addon/block/recentlyaccessedcourses/providers/block-handler.ts @@ -38,7 +38,7 @@ export class AddonBlockRecentlyAccessedCoursesHandler extends CoreBlockBaseHandl * @param {number} instanceId The instance ID associated with the context level. * @return {CoreBlockHandlerData|Promise} Data or promise resolved with the data. */ - getDisplayData?(injector: Injector, block: any, contextLevel: string, instanceId: number) + getDisplayData(injector: Injector, block: any, contextLevel: string, instanceId: number) : CoreBlockHandlerData | Promise { return { diff --git a/src/addon/block/recentlyaccesseditems/providers/block-handler.ts b/src/addon/block/recentlyaccesseditems/providers/block-handler.ts index 2963017e8..dfadcc542 100644 --- a/src/addon/block/recentlyaccesseditems/providers/block-handler.ts +++ b/src/addon/block/recentlyaccesseditems/providers/block-handler.ts @@ -38,7 +38,7 @@ export class AddonBlockRecentlyAccessedItemsHandler extends CoreBlockBaseHandler * @param {number} instanceId The instance ID associated with the context level. * @return {CoreBlockHandlerData|Promise} Data or promise resolved with the data. */ - getDisplayData?(injector: Injector, block: any, contextLevel: string, instanceId: number) + getDisplayData(injector: Injector, block: any, contextLevel: string, instanceId: number) : CoreBlockHandlerData | Promise { return { diff --git a/src/addon/block/sitemainmenu/providers/block-handler.ts b/src/addon/block/sitemainmenu/providers/block-handler.ts index 8c699aff0..dcaf4fe01 100644 --- a/src/addon/block/sitemainmenu/providers/block-handler.ts +++ b/src/addon/block/sitemainmenu/providers/block-handler.ts @@ -38,7 +38,7 @@ export class AddonBlockSiteMainMenuHandler extends CoreBlockBaseHandler { * @param {number} instanceId The instance ID associated with the context level. * @return {CoreBlockHandlerData|Promise} Data or promise resolved with the data. */ - getDisplayData?(injector: Injector, block: any, contextLevel: string, instanceId: number) + getDisplayData(injector: Injector, block: any, contextLevel: string, instanceId: number) : CoreBlockHandlerData | Promise { return { diff --git a/src/addon/block/starredcourses/providers/block-handler.ts b/src/addon/block/starredcourses/providers/block-handler.ts index 7675876b1..c7abc3485 100644 --- a/src/addon/block/starredcourses/providers/block-handler.ts +++ b/src/addon/block/starredcourses/providers/block-handler.ts @@ -38,7 +38,7 @@ export class AddonBlockStarredCoursesHandler extends CoreBlockBaseHandler { * @param {number} instanceId The instance ID associated with the context level. * @return {CoreBlockHandlerData|Promise} Data or promise resolved with the data. */ - getDisplayData?(injector: Injector, block: any, contextLevel: string, instanceId: number) + getDisplayData(injector: Injector, block: any, contextLevel: string, instanceId: number) : CoreBlockHandlerData | Promise { return { diff --git a/src/addon/block/timeline/providers/block-handler.ts b/src/addon/block/timeline/providers/block-handler.ts index 2e89d60fb..8973fbc5d 100644 --- a/src/addon/block/timeline/providers/block-handler.ts +++ b/src/addon/block/timeline/providers/block-handler.ts @@ -55,7 +55,7 @@ export class AddonBlockTimelineHandler extends CoreBlockBaseHandler { * @param {number} instanceId The instance ID associated with the context level. * @return {CoreBlockHandlerData|Promise} Data or promise resolved with the data. */ - getDisplayData?(injector: Injector, block: any, contextLevel: string, instanceId: number) + getDisplayData(injector: Injector, block: any, contextLevel: string, instanceId: number) : CoreBlockHandlerData | Promise { return { diff --git a/src/core/block/classes/base-block-component.ts b/src/core/block/classes/base-block-component.ts index 56cbad4f6..46dc2c33b 100644 --- a/src/core/block/classes/base-block-component.ts +++ b/src/core/block/classes/base-block-component.ts @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { Injector, OnInit } from '@angular/core'; +import { Injector, OnInit, Input } from '@angular/core'; import { CoreLoggerProvider } from '@providers/logger'; import { CoreDomUtilsProvider } from '@providers/utils/dom'; @@ -20,6 +20,13 @@ import { CoreDomUtilsProvider } from '@providers/utils/dom'; * Template class to easily create components for blocks. */ export class CoreBlockBaseComponent implements OnInit { + @Input() title: string; // The block title. + @Input() block: any; // The block to render. + @Input() contextLevel: string; // The context where the block will be used. + @Input() instanceId: number; // The instance ID associated with the context level. + @Input() link: string; // Link to go when clicked. + @Input() linkParams: string; // Link params to go when clicked. + loaded: boolean; // If the component has been loaded. protected fetchContentDefaultError: string; // Default error to show when loading contents. diff --git a/src/core/block/classes/base-block-handler.ts b/src/core/block/classes/base-block-handler.ts index 85fe49995..695d8182e 100644 --- a/src/core/block/classes/base-block-handler.ts +++ b/src/core/block/classes/base-block-handler.ts @@ -47,7 +47,7 @@ export class CoreBlockBaseHandler implements CoreBlockHandler { * @param {number} instanceId The instance ID associated with the context level. * @return {CoreBlockHandlerData|Promise} Data or promise resolved with the data. */ - getDisplayData?(injector: Injector, block: any, contextLevel: string, instanceId: number) + getDisplayData(injector: Injector, block: any, contextLevel: string, instanceId: number) : CoreBlockHandlerData | Promise { // To be overridden. diff --git a/src/core/block/components/block/block.ts b/src/core/block/components/block/block.ts index fffba5683..faf8aa3be 100644 --- a/src/core/block/components/block/block.ts +++ b/src/core/block/components/block/block.ts @@ -33,7 +33,6 @@ export class CoreBlockComponent implements OnInit, OnDestroy { @Input() instanceId: number; // The instance ID associated with the context level. @Input() extraData: any; // Any extra data to be passed to the block. - title: string; // The title of the block. componentClass: any; // The class of the component to render. data: any = {}; // Data to pass to the component. class: string; // CSS class to apply to the block. @@ -80,15 +79,17 @@ export class CoreBlockComponent implements OnInit, OnDestroy { return; } - this.title = data.title; this.class = data.class; this.componentClass = data.component; // Set up the data needed by the block component. this.data = Object.assign({ + title: data.title, block: this.block, contextLevel: this.contextLevel, instanceId: this.instanceId, + link: data.link || null, + linkParams: data.linkParams || null, }, this.extraData || {}, data.componentData || {}); }).catch(() => { // Ignore errors. diff --git a/src/core/block/components/components.module.ts b/src/core/block/components/components.module.ts index 512729b8e..896804473 100644 --- a/src/core/block/components/components.module.ts +++ b/src/core/block/components/components.module.ts @@ -16,23 +16,31 @@ import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; import { IonicModule } from 'ionic-angular'; import { TranslateModule } from '@ngx-translate/core'; +import { CoreDirectivesModule } from '@directives/directives.module'; import { CoreBlockComponent } from './block/block'; +import { CoreBlockOnlyTitleComponent } from './only-title-block/only-title-block'; import { CoreComponentsModule } from '@components/components.module'; @NgModule({ declarations: [ - CoreBlockComponent + CoreBlockComponent, + CoreBlockOnlyTitleComponent ], imports: [ CommonModule, IonicModule, + CoreDirectivesModule, TranslateModule.forChild(), CoreComponentsModule ], providers: [ ], exports: [ - CoreBlockComponent + CoreBlockComponent, + CoreBlockOnlyTitleComponent + ], + entryComponents: [ + CoreBlockOnlyTitleComponent ] }) export class CoreBlockComponentsModule {} diff --git a/src/core/block/components/only-title-block/core-block-only-title.html b/src/core/block/components/only-title-block/core-block-only-title.html new file mode 100644 index 000000000..287592371 --- /dev/null +++ b/src/core/block/components/only-title-block/core-block-only-title.html @@ -0,0 +1,3 @@ + +

{{ title | translate }}

+
\ No newline at end of file diff --git a/src/core/block/components/only-title-block/only-title-block.ts b/src/core/block/components/only-title-block/only-title-block.ts new file mode 100644 index 000000000..a128c44d1 --- /dev/null +++ b/src/core/block/components/only-title-block/only-title-block.ts @@ -0,0 +1,50 @@ +// (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 { Injector, OnInit, Component } from '@angular/core'; +import { CoreBlockBaseComponent } from '../../classes/base-block-component'; +import { CoreLoginHelperProvider } from '@core/login/providers/helper'; + +/** + * Component to render blocks with only a title and link. + */ +@Component({ + selector: 'core-block-only-title', + templateUrl: 'core-block-only-title.html' +}) +export class CoreBlockOnlyTitleComponent extends CoreBlockBaseComponent implements OnInit { + + protected loginHelper: CoreLoginHelperProvider; + + constructor(injector: Injector) { + super(injector, 'CoreBlockOnlyTitleComponent'); + this.loginHelper = injector.get(CoreLoginHelperProvider); + } + + /** + * Component being initialized. + */ + ngOnInit(): void { + super.ngOnInit(); + + this.fetchContentDefaultError = 'Error getting ' + this.block.contents.title + ' data.'; + } + + /** + * Go to the block page. + */ + gotoBlock(): void { + this.loginHelper.redirect(this.link, this.linkParams); + } +} diff --git a/src/core/block/providers/delegate.ts b/src/core/block/providers/delegate.ts index 47b90ecda..b4e6fcf40 100644 --- a/src/core/block/providers/delegate.ts +++ b/src/core/block/providers/delegate.ts @@ -73,6 +73,18 @@ export interface CoreBlockHandlerData { * @type {any} */ componentData?: any; + + /** + * Link to go when showing only title. + * @type {string} + */ + link?: string; + + /** + * Params of the link. + * @type {[type]} + */ + linkParams?: any; } /** @@ -127,7 +139,8 @@ export class CoreBlockDelegate extends CoreDelegate { * @return {Promise} Promise resolved with the display data. */ getBlockDisplayData(injector: Injector, block: any, contextLevel: string, instanceId: number): Promise { - return Promise.resolve(this.executeFunctionOnEnabled(block.name, 'getDisplayData', [injector, block])); + return Promise.resolve(this.executeFunctionOnEnabled(block.name, 'getDisplayData', + [injector, block, contextLevel, instanceId])); } /** From 9a5f56738746b142678e7355451fa822758d5619 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Mon, 6 May 2019 10:51:45 +0200 Subject: [PATCH 2/9] MOBILE-3014 course: Add course blocks tab --- scripts/langindex.json | 1 + src/assets/lang/en.json | 1 + src/core/block/block.module.ts | 14 ++- .../block/components/components.module.ts | 10 +- .../core-block-course-blocks.html | 15 +++ .../components/course-blocks/course-blocks.ts | 100 ++++++++++++++++++ src/core/block/lang/en.json | 3 + .../block/providers/course-option-handler.ts | 88 +++++++++++++++ 8 files changed, 227 insertions(+), 5 deletions(-) create mode 100644 src/core/block/components/course-blocks/core-block-course-blocks.html create mode 100644 src/core/block/components/course-blocks/course-blocks.ts create mode 100644 src/core/block/lang/en.json create mode 100644 src/core/block/providers/course-option-handler.ts diff --git a/scripts/langindex.json b/scripts/langindex.json index 7381c6fc8..5abbddcb4 100644 --- a/scripts/langindex.json +++ b/scripts/langindex.json @@ -1231,6 +1231,7 @@ "core.answered": "quiz", "core.areyousure": "moodle", "core.back": "moodle", + "core.block.blocks": "moodle", "core.cancel": "moodle", "core.cannotconnect": "local_moodlemobileapp", "core.cannotdownloadfiles": "local_moodlemobileapp", diff --git a/src/assets/lang/en.json b/src/assets/lang/en.json index 7ed0d4812..7608fe277 100644 --- a/src/assets/lang/en.json +++ b/src/assets/lang/en.json @@ -1231,6 +1231,7 @@ "core.answered": "Answered", "core.areyousure": "Are you sure?", "core.back": "Back", + "core.block.blocks": "Blocks", "core.cancel": "Cancel", "core.cannotconnect": "Cannot connect: Verify that you have correctly typed the URL and that your site uses Moodle 2.4 or later.", "core.cannotdownloadfiles": "File downloading is disabled. Please contact your site administrator.", diff --git a/src/core/block/block.module.ts b/src/core/block/block.module.ts index 2448c6e1d..764d27fb9 100644 --- a/src/core/block/block.module.ts +++ b/src/core/block/block.module.ts @@ -15,6 +15,9 @@ import { NgModule } from '@angular/core'; import { CoreBlockDelegate } from './providers/delegate'; import { CoreBlockDefaultHandler } from './providers/default-block-handler'; +import { CoreCourseOptionsDelegate } from '@core/course/providers/options-delegate'; +import { CoreBlockCourseBlocksCourseOptionHandler } from './providers/course-option-handler'; +import { CoreBlockComponentsModule } from './components/components.module'; // List of providers (without handlers). export const CORE_BLOCK_PROVIDERS: any[] = [ @@ -24,11 +27,18 @@ export const CORE_BLOCK_PROVIDERS: any[] = [ @NgModule({ declarations: [], imports: [ + CoreBlockComponentsModule ], providers: [ CoreBlockDelegate, - CoreBlockDefaultHandler + CoreBlockDefaultHandler, + CoreBlockCourseBlocksCourseOptionHandler ], exports: [] }) -export class CoreBlockModule {} +export class CoreBlockModule { + constructor(courseOptionHandler: CoreBlockCourseBlocksCourseOptionHandler, + courseOptionsDelegate: CoreCourseOptionsDelegate) { + courseOptionsDelegate.registerHandler(courseOptionHandler); + } +} diff --git a/src/core/block/components/components.module.ts b/src/core/block/components/components.module.ts index 896804473..33c80abcf 100644 --- a/src/core/block/components/components.module.ts +++ b/src/core/block/components/components.module.ts @@ -19,12 +19,14 @@ import { TranslateModule } from '@ngx-translate/core'; import { CoreDirectivesModule } from '@directives/directives.module'; import { CoreBlockComponent } from './block/block'; import { CoreBlockOnlyTitleComponent } from './only-title-block/only-title-block'; +import { CoreBlockCourseBlocksComponent } from './course-blocks/course-blocks'; import { CoreComponentsModule } from '@components/components.module'; @NgModule({ declarations: [ CoreBlockComponent, - CoreBlockOnlyTitleComponent + CoreBlockOnlyTitleComponent, + CoreBlockCourseBlocksComponent ], imports: [ CommonModule, @@ -37,10 +39,12 @@ import { CoreComponentsModule } from '@components/components.module'; ], exports: [ CoreBlockComponent, - CoreBlockOnlyTitleComponent + CoreBlockOnlyTitleComponent, + CoreBlockCourseBlocksComponent ], entryComponents: [ - CoreBlockOnlyTitleComponent + CoreBlockOnlyTitleComponent, + CoreBlockCourseBlocksComponent ] }) export class CoreBlockComponentsModule {} diff --git a/src/core/block/components/course-blocks/core-block-course-blocks.html b/src/core/block/components/course-blocks/core-block-course-blocks.html new file mode 100644 index 000000000..cf9457d58 --- /dev/null +++ b/src/core/block/components/course-blocks/core-block-course-blocks.html @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/src/core/block/components/course-blocks/course-blocks.ts b/src/core/block/components/course-blocks/course-blocks.ts new file mode 100644 index 000000000..8adbb5e4e --- /dev/null +++ b/src/core/block/components/course-blocks/course-blocks.ts @@ -0,0 +1,100 @@ +// (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 { Component, ViewChildren, Input, OnInit, QueryList } from '@angular/core'; +import { CoreDomUtilsProvider } from '@providers/utils/dom'; +import { CoreBlockComponent } from '../block/block'; +import { CoreBlockDelegate } from '../../providers/delegate'; +import { CoreCourseProvider } from '@core/course/providers/course'; + +/** + * Component that displays the list of course blocks. + */ +@Component({ + selector: 'core-block-course-blocks', + templateUrl: 'core-block-course-blocks.html', +}) +export class CoreBlockCourseBlocksComponent implements OnInit { + + @Input() courseId: number; + + @ViewChildren(CoreBlockComponent) blocksComponents: QueryList; + + dataLoaded = false; + hasContent: boolean; + hasSupportedBlock: boolean; + blocks = []; + + constructor(private domUtils: CoreDomUtilsProvider, private courseProvider: CoreCourseProvider, + private blockDelegate: CoreBlockDelegate) { + } + + /** + * Component being initialized. + */ + ngOnInit(): void { + this.loadContent().finally(() => { + this.dataLoaded = true; + }); + } + + /** + * Refresh the data. + * + * @param {any} refresher Refresher. + */ + doRefresh(refresher: any): void { + const promises = []; + + if (this.courseProvider.canGetCourseBlocks()) { + promises.push(this.courseProvider.invalidateCourseBlocks(this.courseId)); + } + + // Invalidate the blocks. + this.blocksComponents.forEach((blockComponent) => { + promises.push(blockComponent.invalidate().catch(() => { + // Ignore errors. + })); + }); + + Promise.all(promises).finally(() => { + this.loadContent().finally(() => { + refresher.complete(); + }); + }); + } + + /** + * Convenience function to fetch the data. + * + * @return {Promise} Promise resolved when done. + */ + protected loadContent(): Promise { + // Get site home blocks. + const canGetBlocks = this.courseProvider.canGetCourseBlocks(), + promise = canGetBlocks ? this.courseProvider.getCourseBlocks(this.courseId) : Promise.reject(null); + + return promise.then((blocks) => { + this.blocks = blocks; + this.hasSupportedBlock = this.blockDelegate.hasSupportedBlock(blocks); + + }).catch((error) => { + if (canGetBlocks) { + this.domUtils.showErrorModal(error); + } + this.blocks = []; + }); + + } +} diff --git a/src/core/block/lang/en.json b/src/core/block/lang/en.json new file mode 100644 index 000000000..9b136b8ee --- /dev/null +++ b/src/core/block/lang/en.json @@ -0,0 +1,3 @@ +{ + "blocks": "Blocks" +} \ No newline at end of file diff --git a/src/core/block/providers/course-option-handler.ts b/src/core/block/providers/course-option-handler.ts new file mode 100644 index 000000000..c7e298c9c --- /dev/null +++ b/src/core/block/providers/course-option-handler.ts @@ -0,0 +1,88 @@ +// (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 { CoreCourseOptionsHandler, CoreCourseOptionsHandlerData } from '@core/course/providers/options-delegate'; +import { CoreCourseProvider } from '@core/course/providers/course'; +import { CoreBlockCourseBlocksComponent } from '../components/course-blocks/course-blocks'; + +/** + * Course nav handler. + */ +@Injectable() +export class CoreBlockCourseBlocksCourseOptionHandler implements CoreCourseOptionsHandler { + name = 'CoreCourseBlocks'; + priority = 700; + + constructor(private courseProvider: CoreCourseProvider) {} + + /** + * Should invalidate the data to determine if the handler is enabled for a certain course. + * + * @param {number} courseId The course ID. + * @param {any} [navOptions] Course navigation options for current user. See CoreCoursesProvider.getUserNavigationOptions. + * @param {any} [admOptions] Course admin options for current user. See CoreCoursesProvider.getUserAdministrationOptions. + * @return {Promise} Promise resolved when done. + */ + invalidateEnabledForCourse(courseId: number, navOptions?: any, admOptions?: any): Promise { + return this.courseProvider.invalidateCourseBlocks(courseId); + } + + /** + * 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 this.courseProvider.canGetCourseBlocks(); + } + + /** + * Whether or not the handler is enabled for a certain course. + * + * @param {number} courseId The course ID. + * @param {any} accessData Access type and data. Default, guest, ... + * @param {any} [navOptions] Course navigation options for current user. See CoreCoursesProvider.getUserNavigationOptions. + * @param {any} [admOptions] Course admin options for current user. See CoreCoursesProvider.getUserAdministrationOptions. + * @return {boolean|Promise} True or promise resolved with true if enabled. + */ + isEnabledForCourse(courseId: number, accessData: any, navOptions?: any, admOptions?: any): boolean | Promise { + return true; + } + + /** + * Returns the data needed to render the handler. + * + * @param {Injector} injector Injector. + * @param {number} courseId The course ID. + * @return {CoreCourseOptionsHandlerData|Promise} Data or promise resolved with the data. + */ + getDisplayData(injector: Injector, courseId: number): CoreCourseOptionsHandlerData | Promise { + return { + title: 'core.block.blocks', + class: 'core-course-blocks-handler', + component: CoreBlockCourseBlocksComponent + }; + } + + /** + * Called when a course is downloaded. It should prefetch all the data to be able to see the addon in offline. + * + * @param {any} course The course. + * @return {Promise} Promise resolved when done. + */ + prefetch(course: any): Promise { + return this.courseProvider.getCourseBlocks(course.id); + } +} From 2ad5daec1c0392204d1495ef55ef66118c272d30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Tue, 7 May 2019 13:31:48 +0200 Subject: [PATCH 3/9] MOBILE-3014 block: Add Calendar block feature --- scripts/langindex.json | 1 + .../calendarmonth/calendarmonth.module.ts | 38 ++++++++++++++ src/addon/block/calendarmonth/lang/en.json | 3 ++ .../calendarmonth/providers/block-handler.ts | 52 +++++++++++++++++++ src/addon/calendar/pages/list/list.ts | 8 +++ src/app/app.module.ts | 2 + src/assets/lang/en.json | 1 + 7 files changed, 105 insertions(+) create mode 100644 src/addon/block/calendarmonth/calendarmonth.module.ts create mode 100644 src/addon/block/calendarmonth/lang/en.json create mode 100644 src/addon/block/calendarmonth/providers/block-handler.ts diff --git a/scripts/langindex.json b/scripts/langindex.json index 5abbddcb4..548a3173f 100644 --- a/scripts/langindex.json +++ b/scripts/langindex.json @@ -27,6 +27,7 @@ "addon.badges.version": "badges", "addon.badges.warnexpired": "badges", "addon.block_activitymodules.pluginname": "block_activity_modules", + "addon.block_calendarmonth.pluginname": "block_calendar_month", "addon.block_myoverview.all": "block_myoverview", "addon.block_myoverview.favourites": "block_myoverview", "addon.block_myoverview.future": "block_myoverview", diff --git a/src/addon/block/calendarmonth/calendarmonth.module.ts b/src/addon/block/calendarmonth/calendarmonth.module.ts new file mode 100644 index 000000000..e3204ae8f --- /dev/null +++ b/src/addon/block/calendarmonth/calendarmonth.module.ts @@ -0,0 +1,38 @@ +// (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 { IonicModule } from 'ionic-angular'; +import { TranslateModule } from '@ngx-translate/core'; +import { CoreBlockDelegate } from '@core/block/providers/delegate'; +import { AddonBlockCalendarMonthHandler } from './providers/block-handler'; + +@NgModule({ + declarations: [ + ], + imports: [ + IonicModule, + TranslateModule.forChild() + ], + exports: [ + ], + providers: [ + AddonBlockCalendarMonthHandler + ] +}) +export class AddonBlockCalendarMonthModule { + constructor(blockDelegate: CoreBlockDelegate, blockHandler: AddonBlockCalendarMonthHandler) { + blockDelegate.registerHandler(blockHandler); + } +} diff --git a/src/addon/block/calendarmonth/lang/en.json b/src/addon/block/calendarmonth/lang/en.json new file mode 100644 index 000000000..86a476c29 --- /dev/null +++ b/src/addon/block/calendarmonth/lang/en.json @@ -0,0 +1,3 @@ +{ + "pluginname": "Calendar" +} \ No newline at end of file diff --git a/src/addon/block/calendarmonth/providers/block-handler.ts b/src/addon/block/calendarmonth/providers/block-handler.ts new file mode 100644 index 000000000..9dc4ce2ab --- /dev/null +++ b/src/addon/block/calendarmonth/providers/block-handler.ts @@ -0,0 +1,52 @@ +// (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 { CoreBlockHandlerData } from '@core/block/providers/delegate'; +import { CoreBlockOnlyTitleComponent } from '@core/block/components/only-title-block/only-title-block'; +import { CoreBlockBaseHandler } from '@core/block/classes/base-block-handler'; + +/** + * Block handler. + */ +@Injectable() +export class AddonBlockCalendarMonthHandler extends CoreBlockBaseHandler { + name = 'AddonBlockCalendarMonth'; + blockName = 'calendar_month'; + + constructor() { + super(); + } + + /** + * Returns the data needed to render the block. + * + * @param {Injector} injector Injector. + * @param {any} block The block to render. + * @param {string} contextLevel The context where the block will be used. + * @param {number} instanceId The instance ID associated with the context level. + * @return {CoreBlockHandlerData|Promise} Data or promise resolved with the data. + */ + getDisplayData(injector: Injector, block: any, contextLevel: string, instanceId: number) + : CoreBlockHandlerData | Promise { + + return { + title: 'addon.block_calendarmonth.pluginname', + class: 'addon-block-calendar-month', + component: CoreBlockOnlyTitleComponent, + link: 'AddonCalendarListPage', + linkParams: contextLevel == 'course' ? { courseId: instanceId } : null + }; + } +} diff --git a/src/addon/calendar/pages/list/list.ts b/src/addon/calendar/pages/list/list.ts index cd8523d90..7722dc1c4 100644 --- a/src/addon/calendar/pages/list/list.ts +++ b/src/addon/calendar/pages/list/list.ts @@ -53,6 +53,7 @@ export class AddonCalendarListPage implements OnDestroy { protected siteHomeId: number; protected obsDefaultTimeChange: any; protected eventId: number; + protected preSelectedCourseId: number; courses: any[]; eventsLoaded = false; @@ -81,6 +82,7 @@ export class AddonCalendarListPage implements OnDestroy { } this.eventId = navParams.get('eventId') || false; + this.preSelectedCourseId = navParams.get('courseId') || null; } /** @@ -118,6 +120,12 @@ export class AddonCalendarListPage implements OnDestroy { courses.unshift(this.allCourses); this.courses = courses; + if (this.preSelectedCourseId) { + this.filter.course = courses.find((course) => { + return course.id == this.preSelectedCourseId; + }); + } + return this.fetchEvents(refresh); }); } diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 4a174e542..e3b734267 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -91,6 +91,7 @@ import { AddonCourseCompletionModule } from '@addon/coursecompletion/coursecompl import { AddonUserProfileFieldModule } from '@addon/userprofilefield/userprofilefield.module'; import { AddonFilesModule } from '@addon/files/files.module'; import { AddonBlockActivityModulesModule } from '@addon/block/activitymodules/activitymodules.module'; +import { AddonBlockCalendarMonthModule } from '@addon/block/calendarmonth/calendarmonth.module'; import { AddonBlockMyOverviewModule } from '@addon/block/myoverview/myoverview.module'; import { AddonBlockSiteMainMenuModule } from '@addon/block/sitemainmenu/sitemainmenu.module'; import { AddonBlockTimelineModule } from '@addon/block/timeline/timeline.module'; @@ -213,6 +214,7 @@ export const CORE_PROVIDERS: any[] = [ AddonUserProfileFieldModule, AddonFilesModule, AddonBlockActivityModulesModule, + AddonBlockCalendarMonthModule, AddonBlockMyOverviewModule, AddonBlockSiteMainMenuModule, AddonBlockTimelineModule, diff --git a/src/assets/lang/en.json b/src/assets/lang/en.json index 7608fe277..cfe806f1d 100644 --- a/src/assets/lang/en.json +++ b/src/assets/lang/en.json @@ -27,6 +27,7 @@ "addon.badges.version": "Version", "addon.badges.warnexpired": "(This badge has expired!)", "addon.block_activitymodules.pluginname": "Activities", + "addon.block_calendarmonth.pluginname": "Calendar", "addon.block_myoverview.all": "All", "addon.block_myoverview.favourites": "Starred", "addon.block_myoverview.future": "Future", From ea7050104fea900c11afeddfbae3c7ae5b1ffd1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Tue, 7 May 2019 14:15:45 +0200 Subject: [PATCH 4/9] MOBILE-3014 block: Add Upcoming events block feature --- scripts/langindex.json | 1 + .../calendarupcoming.module.ts | 38 ++++++++++++++ src/addon/block/calendarupcoming/lang/en.json | 3 ++ .../providers/block-handler.ts | 52 +++++++++++++++++++ src/app/app.module.ts | 2 + src/assets/lang/en.json | 1 + 6 files changed, 97 insertions(+) create mode 100644 src/addon/block/calendarupcoming/calendarupcoming.module.ts create mode 100644 src/addon/block/calendarupcoming/lang/en.json create mode 100644 src/addon/block/calendarupcoming/providers/block-handler.ts diff --git a/scripts/langindex.json b/scripts/langindex.json index 548a3173f..e95ca8279 100644 --- a/scripts/langindex.json +++ b/scripts/langindex.json @@ -28,6 +28,7 @@ "addon.badges.warnexpired": "badges", "addon.block_activitymodules.pluginname": "block_activity_modules", "addon.block_calendarmonth.pluginname": "block_calendar_month", + "addon.block_calendarupcoming.pluginname": "block_calendar_upcoming", "addon.block_myoverview.all": "block_myoverview", "addon.block_myoverview.favourites": "block_myoverview", "addon.block_myoverview.future": "block_myoverview", diff --git a/src/addon/block/calendarupcoming/calendarupcoming.module.ts b/src/addon/block/calendarupcoming/calendarupcoming.module.ts new file mode 100644 index 000000000..345d17672 --- /dev/null +++ b/src/addon/block/calendarupcoming/calendarupcoming.module.ts @@ -0,0 +1,38 @@ +// (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 { IonicModule } from 'ionic-angular'; +import { TranslateModule } from '@ngx-translate/core'; +import { CoreBlockDelegate } from '@core/block/providers/delegate'; +import { AddonBlockCalendarUpcomingHandler } from './providers/block-handler'; + +@NgModule({ + declarations: [ + ], + imports: [ + IonicModule, + TranslateModule.forChild() + ], + exports: [ + ], + providers: [ + AddonBlockCalendarUpcomingHandler + ] +}) +export class AddonBlockCalendarUpcomingModule { + constructor(blockDelegate: CoreBlockDelegate, blockHandler: AddonBlockCalendarUpcomingHandler) { + blockDelegate.registerHandler(blockHandler); + } +} diff --git a/src/addon/block/calendarupcoming/lang/en.json b/src/addon/block/calendarupcoming/lang/en.json new file mode 100644 index 000000000..4faba6dd2 --- /dev/null +++ b/src/addon/block/calendarupcoming/lang/en.json @@ -0,0 +1,3 @@ +{ + "pluginname": " Upcoming events" +} \ No newline at end of file diff --git a/src/addon/block/calendarupcoming/providers/block-handler.ts b/src/addon/block/calendarupcoming/providers/block-handler.ts new file mode 100644 index 000000000..b7f4e8acd --- /dev/null +++ b/src/addon/block/calendarupcoming/providers/block-handler.ts @@ -0,0 +1,52 @@ +// (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 { CoreBlockHandlerData } from '@core/block/providers/delegate'; +import { CoreBlockOnlyTitleComponent } from '@core/block/components/only-title-block/only-title-block'; +import { CoreBlockBaseHandler } from '@core/block/classes/base-block-handler'; + +/** + * Block handler. + */ +@Injectable() +export class AddonBlockCalendarUpcomingHandler extends CoreBlockBaseHandler { + name = 'AddonBlockCalendarUpcoming'; + blockName = 'calendar_upcoming'; + + constructor() { + super(); + } + + /** + * Returns the data needed to render the block. + * + * @param {Injector} injector Injector. + * @param {any} block The block to render. + * @param {string} contextLevel The context where the block will be used. + * @param {number} instanceId The instance ID associated with the context level. + * @return {CoreBlockHandlerData|Promise} Data or promise resolved with the data. + */ + getDisplayData(injector: Injector, block: any, contextLevel: string, instanceId: number) + : CoreBlockHandlerData | Promise { + + return { + title: 'addon.block_calendarupcoming.pluginname', + class: 'addon-block-calendar-upcoming', + component: CoreBlockOnlyTitleComponent, + link: 'AddonCalendarListPage', + linkParams: contextLevel == 'course' ? { courseId: instanceId } : null + }; + } +} diff --git a/src/app/app.module.ts b/src/app/app.module.ts index e3b734267..42dfd82d9 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -92,6 +92,7 @@ import { AddonUserProfileFieldModule } from '@addon/userprofilefield/userprofile import { AddonFilesModule } from '@addon/files/files.module'; import { AddonBlockActivityModulesModule } from '@addon/block/activitymodules/activitymodules.module'; import { AddonBlockCalendarMonthModule } from '@addon/block/calendarmonth/calendarmonth.module'; +import { AddonBlockCalendarUpcomingModule } from '@addon/block/calendarupcoming/calendarupcoming.module'; import { AddonBlockMyOverviewModule } from '@addon/block/myoverview/myoverview.module'; import { AddonBlockSiteMainMenuModule } from '@addon/block/sitemainmenu/sitemainmenu.module'; import { AddonBlockTimelineModule } from '@addon/block/timeline/timeline.module'; @@ -215,6 +216,7 @@ export const CORE_PROVIDERS: any[] = [ AddonFilesModule, AddonBlockActivityModulesModule, AddonBlockCalendarMonthModule, + AddonBlockCalendarUpcomingModule, AddonBlockMyOverviewModule, AddonBlockSiteMainMenuModule, AddonBlockTimelineModule, diff --git a/src/assets/lang/en.json b/src/assets/lang/en.json index cfe806f1d..d59c86895 100644 --- a/src/assets/lang/en.json +++ b/src/assets/lang/en.json @@ -28,6 +28,7 @@ "addon.badges.warnexpired": "(This badge has expired!)", "addon.block_activitymodules.pluginname": "Activities", "addon.block_calendarmonth.pluginname": "Calendar", + "addon.block_calendarupcoming.pluginname": " Upcoming events", "addon.block_myoverview.all": "All", "addon.block_myoverview.favourites": "Starred", "addon.block_myoverview.future": "Future", From e434b2a298e26a5331395bcd528c735f5f1cb46b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Tue, 7 May 2019 17:26:08 +0200 Subject: [PATCH 5/9] MOBILE-3014 block: Add Private files block feature --- scripts/langindex.json | 1 + src/addon/block/privatefiles/lang/en.json | 3 ++ .../block/privatefiles/privatefiles.module.ts | 38 ++++++++++++++ .../privatefiles/providers/block-handler.ts | 52 +++++++++++++++++++ src/app/app.module.ts | 2 + src/assets/lang/en.json | 1 + 6 files changed, 97 insertions(+) create mode 100644 src/addon/block/privatefiles/lang/en.json create mode 100644 src/addon/block/privatefiles/privatefiles.module.ts create mode 100644 src/addon/block/privatefiles/providers/block-handler.ts diff --git a/scripts/langindex.json b/scripts/langindex.json index e95ca8279..b286cb6b5 100644 --- a/scripts/langindex.json +++ b/scripts/langindex.json @@ -40,6 +40,7 @@ "addon.block_myoverview.past": "block_myoverview", "addon.block_myoverview.pluginname": "block_myoverview", "addon.block_myoverview.title": "block_myoverview", + "addon.block_privatefiles.pluginname": "block_private_files", "addon.block_recentlyaccessedcourses.nocourses": "block_recentlyaccessedcourses", "addon.block_recentlyaccessedcourses.pluginname": "block_recentlyaccessedcourses", "addon.block_recentlyaccesseditems.noitems": "block_recentlyaccesseditems", diff --git a/src/addon/block/privatefiles/lang/en.json b/src/addon/block/privatefiles/lang/en.json new file mode 100644 index 000000000..bba9d4bc0 --- /dev/null +++ b/src/addon/block/privatefiles/lang/en.json @@ -0,0 +1,3 @@ +{ + "pluginname": "Private files" +} \ No newline at end of file diff --git a/src/addon/block/privatefiles/privatefiles.module.ts b/src/addon/block/privatefiles/privatefiles.module.ts new file mode 100644 index 000000000..c9617c372 --- /dev/null +++ b/src/addon/block/privatefiles/privatefiles.module.ts @@ -0,0 +1,38 @@ +// (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 { IonicModule } from 'ionic-angular'; +import { TranslateModule } from '@ngx-translate/core'; +import { CoreBlockDelegate } from '@core/block/providers/delegate'; +import { AddonBlockPrivateFilesHandler } from './providers/block-handler'; + +@NgModule({ + declarations: [ + ], + imports: [ + IonicModule, + TranslateModule.forChild() + ], + exports: [ + ], + providers: [ + AddonBlockPrivateFilesHandler + ] +}) +export class AddonBlockPrivateFilesModule { + constructor(blockDelegate: CoreBlockDelegate, blockHandler: AddonBlockPrivateFilesHandler) { + blockDelegate.registerHandler(blockHandler); + } +} diff --git a/src/addon/block/privatefiles/providers/block-handler.ts b/src/addon/block/privatefiles/providers/block-handler.ts new file mode 100644 index 000000000..f0284df97 --- /dev/null +++ b/src/addon/block/privatefiles/providers/block-handler.ts @@ -0,0 +1,52 @@ +// (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 { CoreBlockHandlerData } from '@core/block/providers/delegate'; +import { CoreBlockOnlyTitleComponent } from '@core/block/components/only-title-block/only-title-block'; +import { CoreBlockBaseHandler } from '@core/block/classes/base-block-handler'; + +/** + * Block handler. + */ +@Injectable() +export class AddonBlockPrivateFilesHandler extends CoreBlockBaseHandler { + name = 'AddonBlockPrivateFiles'; + blockName = 'private_files'; + + constructor() { + super(); + } + + /** + * Returns the data needed to render the block. + * + * @param {Injector} injector Injector. + * @param {any} block The block to render. + * @param {string} contextLevel The context where the block will be used. + * @param {number} instanceId The instance ID associated with the context level. + * @return {CoreBlockHandlerData|Promise} Data or promise resolved with the data. + */ + getDisplayData(injector: Injector, block: any, contextLevel: string, instanceId: number) + : CoreBlockHandlerData | Promise { + + return { + title: 'addon.block_privatefiles.pluginname', + class: 'addon-block-private-files', + component: CoreBlockOnlyTitleComponent, + link: 'AddonFilesListPage', + linkParams: {root: 'my'} + }; + } +} diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 42dfd82d9..8fd2e06d1 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -94,6 +94,7 @@ import { AddonBlockActivityModulesModule } from '@addon/block/activitymodules/ac import { AddonBlockCalendarMonthModule } from '@addon/block/calendarmonth/calendarmonth.module'; import { AddonBlockCalendarUpcomingModule } from '@addon/block/calendarupcoming/calendarupcoming.module'; import { AddonBlockMyOverviewModule } from '@addon/block/myoverview/myoverview.module'; +import { AddonBlockPrivateFilesModule } from '@addon/block/privatefiles/privatefiles.module'; import { AddonBlockSiteMainMenuModule } from '@addon/block/sitemainmenu/sitemainmenu.module'; import { AddonBlockTimelineModule } from '@addon/block/timeline/timeline.module'; import { AddonBlockRecentlyAccessedCoursesModule } from '@addon/block/recentlyaccessedcourses/recentlyaccessedcourses.module'; @@ -217,6 +218,7 @@ export const CORE_PROVIDERS: any[] = [ AddonBlockActivityModulesModule, AddonBlockCalendarMonthModule, AddonBlockCalendarUpcomingModule, + AddonBlockPrivateFilesModule, AddonBlockMyOverviewModule, AddonBlockSiteMainMenuModule, AddonBlockTimelineModule, diff --git a/src/assets/lang/en.json b/src/assets/lang/en.json index d59c86895..93cf84463 100644 --- a/src/assets/lang/en.json +++ b/src/assets/lang/en.json @@ -40,6 +40,7 @@ "addon.block_myoverview.past": "Past", "addon.block_myoverview.pluginname": "Course overview", "addon.block_myoverview.title": "Course name", + "addon.block_privatefiles.pluginname": "Private files", "addon.block_recentlyaccessedcourses.nocourses": "No recent courses", "addon.block_recentlyaccessedcourses.pluginname": "Recently accessed courses", "addon.block_recentlyaccesseditems.noitems": "No recent items", From 29537504d01c8149b3f9b8173e9ea7b8dfb9303e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Wed, 8 May 2019 11:33:53 +0200 Subject: [PATCH 6/9] MOBILE-3014 block: Add Learning plans block feature --- scripts/langindex.json | 1 + src/addon/block/learningplans/lang/en.json | 3 ++ .../learningplans/learningplans.module.ts | 40 +++++++++++++++ .../learningplans/providers/block-handler.ts | 51 +++++++++++++++++++ src/app/app.module.ts | 4 +- src/assets/lang/en.json | 1 + 6 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 src/addon/block/learningplans/lang/en.json create mode 100644 src/addon/block/learningplans/learningplans.module.ts create mode 100644 src/addon/block/learningplans/providers/block-handler.ts diff --git a/scripts/langindex.json b/scripts/langindex.json index b286cb6b5..84401eb7f 100644 --- a/scripts/langindex.json +++ b/scripts/langindex.json @@ -29,6 +29,7 @@ "addon.block_activitymodules.pluginname": "block_activity_modules", "addon.block_calendarmonth.pluginname": "block_calendar_month", "addon.block_calendarupcoming.pluginname": "block_calendar_upcoming", + "addon.block_learningplans.pluginname": "block_lp", "addon.block_myoverview.all": "block_myoverview", "addon.block_myoverview.favourites": "block_myoverview", "addon.block_myoverview.future": "block_myoverview", diff --git a/src/addon/block/learningplans/lang/en.json b/src/addon/block/learningplans/lang/en.json new file mode 100644 index 000000000..0a7f81e22 --- /dev/null +++ b/src/addon/block/learningplans/lang/en.json @@ -0,0 +1,3 @@ +{ + "pluginname": "Learning plans" +} \ No newline at end of file diff --git a/src/addon/block/learningplans/learningplans.module.ts b/src/addon/block/learningplans/learningplans.module.ts new file mode 100644 index 000000000..167178d70 --- /dev/null +++ b/src/addon/block/learningplans/learningplans.module.ts @@ -0,0 +1,40 @@ +// (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 { IonicModule } from 'ionic-angular'; +import { TranslateModule } from '@ngx-translate/core'; +import { CoreBlockDelegate } from '@core/block/providers/delegate'; +import { AddonBlockLearningPlansHandler } from './providers/block-handler'; +import { CoreBlockComponentsModule } from '@core/block/components/components.module'; + +@NgModule({ + declarations: [ + ], + imports: [ + IonicModule, + CoreBlockComponentsModule, + TranslateModule.forChild() + ], + exports: [ + ], + providers: [ + AddonBlockLearningPlansHandler + ] +}) +export class AddonBlockLearningPlansModule { + constructor(blockDelegate: CoreBlockDelegate, blockHandler: AddonBlockLearningPlansHandler) { + blockDelegate.registerHandler(blockHandler); + } +} diff --git a/src/addon/block/learningplans/providers/block-handler.ts b/src/addon/block/learningplans/providers/block-handler.ts new file mode 100644 index 000000000..fa98be638 --- /dev/null +++ b/src/addon/block/learningplans/providers/block-handler.ts @@ -0,0 +1,51 @@ +// (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 { CoreBlockHandlerData } from '@core/block/providers/delegate'; +import { CoreBlockOnlyTitleComponent } from '@core/block/components/only-title-block/only-title-block'; +import { CoreBlockBaseHandler } from '@core/block/classes/base-block-handler'; + +/** + * Block handler. + */ +@Injectable() +export class AddonBlockLearningPlansHandler extends CoreBlockBaseHandler { + name = 'AddonBlockLearningPlans'; + blockName = 'lp'; + + constructor() { + super(); + } + + /** + * Returns the data needed to render the block. + * + * @param {Injector} injector Injector. + * @param {any} block The block to render. + * @param {string} contextLevel The context where the block will be used. + * @param {number} instanceId The instance ID associated with the context level. + * @return {CoreBlockHandlerData|Promise} Data or promise resolved with the data. + */ + getDisplayData(injector: Injector, block: any, contextLevel: string, instanceId: number) + : CoreBlockHandlerData | Promise { + + return { + title: 'addon.block_learningplans.pluginname', + class: 'addon-block-learning-plans', + component: CoreBlockOnlyTitleComponent, + link: 'AddonCompetencyPlanListPage' + }; + } +} diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 8fd2e06d1..6203c9b38 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -94,6 +94,7 @@ import { AddonBlockActivityModulesModule } from '@addon/block/activitymodules/ac import { AddonBlockCalendarMonthModule } from '@addon/block/calendarmonth/calendarmonth.module'; import { AddonBlockCalendarUpcomingModule } from '@addon/block/calendarupcoming/calendarupcoming.module'; import { AddonBlockMyOverviewModule } from '@addon/block/myoverview/myoverview.module'; +import { AddonBlockLearningPlansModule } from '@addon/block/learningplans/learningplans.module'; import { AddonBlockPrivateFilesModule } from '@addon/block/privatefiles/privatefiles.module'; import { AddonBlockSiteMainMenuModule } from '@addon/block/sitemainmenu/sitemainmenu.module'; import { AddonBlockTimelineModule } from '@addon/block/timeline/timeline.module'; @@ -218,8 +219,9 @@ export const CORE_PROVIDERS: any[] = [ AddonBlockActivityModulesModule, AddonBlockCalendarMonthModule, AddonBlockCalendarUpcomingModule, - AddonBlockPrivateFilesModule, + AddonBlockLearningPlansModule, AddonBlockMyOverviewModule, + AddonBlockPrivateFilesModule, AddonBlockSiteMainMenuModule, AddonBlockTimelineModule, AddonBlockRecentlyAccessedCoursesModule, diff --git a/src/assets/lang/en.json b/src/assets/lang/en.json index 93cf84463..0ac3f2045 100644 --- a/src/assets/lang/en.json +++ b/src/assets/lang/en.json @@ -29,6 +29,7 @@ "addon.block_activitymodules.pluginname": "Activities", "addon.block_calendarmonth.pluginname": "Calendar", "addon.block_calendarupcoming.pluginname": " Upcoming events", + "addon.block_learningplans.pluginname": "Learning plans", "addon.block_myoverview.all": "All", "addon.block_myoverview.favourites": "Starred", "addon.block_myoverview.future": "Future", From c20a158525627e268e15482a725e5c5f05af4dc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Wed, 8 May 2019 12:22:37 +0200 Subject: [PATCH 7/9] MOBILE-3014 block: Add Course completion status block feature --- scripts/langindex.json | 1 + .../completionstatus.module.ts | 38 ++++++++++++++ src/addon/block/completionstatus/lang/en.json | 3 ++ .../providers/block-handler.ts | 52 +++++++++++++++++++ src/app/app.module.ts | 2 + src/assets/lang/en.json | 1 + 6 files changed, 97 insertions(+) create mode 100644 src/addon/block/completionstatus/completionstatus.module.ts create mode 100644 src/addon/block/completionstatus/lang/en.json create mode 100644 src/addon/block/completionstatus/providers/block-handler.ts diff --git a/scripts/langindex.json b/scripts/langindex.json index 84401eb7f..332609914 100644 --- a/scripts/langindex.json +++ b/scripts/langindex.json @@ -29,6 +29,7 @@ "addon.block_activitymodules.pluginname": "block_activity_modules", "addon.block_calendarmonth.pluginname": "block_calendar_month", "addon.block_calendarupcoming.pluginname": "block_calendar_upcoming", + "addon.block_completionstatus.pluginname": "block_completionstatus", "addon.block_learningplans.pluginname": "block_lp", "addon.block_myoverview.all": "block_myoverview", "addon.block_myoverview.favourites": "block_myoverview", diff --git a/src/addon/block/completionstatus/completionstatus.module.ts b/src/addon/block/completionstatus/completionstatus.module.ts new file mode 100644 index 000000000..37d448a93 --- /dev/null +++ b/src/addon/block/completionstatus/completionstatus.module.ts @@ -0,0 +1,38 @@ +// (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 { IonicModule } from 'ionic-angular'; +import { TranslateModule } from '@ngx-translate/core'; +import { CoreBlockDelegate } from '@core/block/providers/delegate'; +import { AddonBlockCompletionStatusHandler } from './providers/block-handler'; + +@NgModule({ + declarations: [ + ], + imports: [ + IonicModule, + TranslateModule.forChild() + ], + exports: [ + ], + providers: [ + AddonBlockCompletionStatusHandler + ] +}) +export class AddonBlockCompletionStatusModule { + constructor(blockDelegate: CoreBlockDelegate, blockHandler: AddonBlockCompletionStatusHandler) { + blockDelegate.registerHandler(blockHandler); + } +} diff --git a/src/addon/block/completionstatus/lang/en.json b/src/addon/block/completionstatus/lang/en.json new file mode 100644 index 000000000..fe57356da --- /dev/null +++ b/src/addon/block/completionstatus/lang/en.json @@ -0,0 +1,3 @@ +{ + "pluginname": "Course completion status" +} \ No newline at end of file diff --git a/src/addon/block/completionstatus/providers/block-handler.ts b/src/addon/block/completionstatus/providers/block-handler.ts new file mode 100644 index 000000000..88fca4ec8 --- /dev/null +++ b/src/addon/block/completionstatus/providers/block-handler.ts @@ -0,0 +1,52 @@ +// (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 { CoreBlockHandlerData } from '@core/block/providers/delegate'; +import { CoreBlockOnlyTitleComponent } from '@core/block/components/only-title-block/only-title-block'; +import { CoreBlockBaseHandler } from '@core/block/classes/base-block-handler'; + +/** + * Block handler. + */ +@Injectable() +export class AddonBlockCompletionStatusHandler extends CoreBlockBaseHandler { + name = 'AddonBlockCompletionStatus'; + blockName = 'completionstatus'; + + constructor() { + super(); + } + + /** + * Returns the data needed to render the block. + * + * @param {Injector} injector Injector. + * @param {any} block The block to render. + * @param {string} contextLevel The context where the block will be used. + * @param {number} instanceId The instance ID associated with the context level. + * @return {CoreBlockHandlerData|Promise} Data or promise resolved with the data. + */ + getDisplayData(injector: Injector, block: any, contextLevel: string, instanceId: number) + : CoreBlockHandlerData | Promise { + + return { + title: 'addon.block_completionstatus.pluginname', + class: 'addon-block-completion-status', + component: CoreBlockOnlyTitleComponent, + link: 'AddonCourseCompletionReportPage', + linkParams: { courseId: instanceId } + }; + } +} diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 6203c9b38..0244cbc2c 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -93,6 +93,7 @@ import { AddonFilesModule } from '@addon/files/files.module'; import { AddonBlockActivityModulesModule } from '@addon/block/activitymodules/activitymodules.module'; import { AddonBlockCalendarMonthModule } from '@addon/block/calendarmonth/calendarmonth.module'; import { AddonBlockCalendarUpcomingModule } from '@addon/block/calendarupcoming/calendarupcoming.module'; +import { AddonBlockCompletionStatusModule } from '@addon/block/completionstatus/completionstatus.module'; import { AddonBlockMyOverviewModule } from '@addon/block/myoverview/myoverview.module'; import { AddonBlockLearningPlansModule } from '@addon/block/learningplans/learningplans.module'; import { AddonBlockPrivateFilesModule } from '@addon/block/privatefiles/privatefiles.module'; @@ -219,6 +220,7 @@ export const CORE_PROVIDERS: any[] = [ AddonBlockActivityModulesModule, AddonBlockCalendarMonthModule, AddonBlockCalendarUpcomingModule, + AddonBlockCompletionStatusModule, AddonBlockLearningPlansModule, AddonBlockMyOverviewModule, AddonBlockPrivateFilesModule, diff --git a/src/assets/lang/en.json b/src/assets/lang/en.json index 0ac3f2045..d6b15d48c 100644 --- a/src/assets/lang/en.json +++ b/src/assets/lang/en.json @@ -29,6 +29,7 @@ "addon.block_activitymodules.pluginname": "Activities", "addon.block_calendarmonth.pluginname": "Calendar", "addon.block_calendarupcoming.pluginname": " Upcoming events", + "addon.block_completionstatus.pluginname": "Course completion status", "addon.block_learningplans.pluginname": "Learning plans", "addon.block_myoverview.all": "All", "addon.block_myoverview.favourites": "Starred", From 1c82edce2f558a2f557672c1013a23b71b1dc72e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Wed, 8 May 2019 12:35:21 +0200 Subject: [PATCH 8/9] MOBILE-3014 block: Add Self completion block feature --- scripts/langindex.json | 1 + src/addon/block/selfcompletion/lang/en.json | 3 ++ .../selfcompletion/providers/block-handler.ts | 52 +++++++++++++++++++ .../selfcompletion/selfcompletion.module.ts | 38 ++++++++++++++ src/app/app.module.ts | 2 + src/assets/lang/en.json | 1 + 6 files changed, 97 insertions(+) create mode 100644 src/addon/block/selfcompletion/lang/en.json create mode 100644 src/addon/block/selfcompletion/providers/block-handler.ts create mode 100644 src/addon/block/selfcompletion/selfcompletion.module.ts diff --git a/scripts/langindex.json b/scripts/langindex.json index 332609914..34a760445 100644 --- a/scripts/langindex.json +++ b/scripts/langindex.json @@ -47,6 +47,7 @@ "addon.block_recentlyaccessedcourses.pluginname": "block_recentlyaccessedcourses", "addon.block_recentlyaccesseditems.noitems": "block_recentlyaccesseditems", "addon.block_recentlyaccesseditems.pluginname": "block_recentlyaccesseditems", + "addon.block_selfcompletion.pluginname": "block_selfcompletion", "addon.block_sitemainmenu.pluginname": "block_site_main_menu", "addon.block_starredcourses.nocourses": "block_starredcourses", "addon.block_starredcourses.pluginname": "block_starredcourses", diff --git a/src/addon/block/selfcompletion/lang/en.json b/src/addon/block/selfcompletion/lang/en.json new file mode 100644 index 000000000..32521695a --- /dev/null +++ b/src/addon/block/selfcompletion/lang/en.json @@ -0,0 +1,3 @@ +{ + "pluginname": "Self completion" +} \ No newline at end of file diff --git a/src/addon/block/selfcompletion/providers/block-handler.ts b/src/addon/block/selfcompletion/providers/block-handler.ts new file mode 100644 index 000000000..57d716e5a --- /dev/null +++ b/src/addon/block/selfcompletion/providers/block-handler.ts @@ -0,0 +1,52 @@ +// (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 { CoreBlockHandlerData } from '@core/block/providers/delegate'; +import { CoreBlockOnlyTitleComponent } from '@core/block/components/only-title-block/only-title-block'; +import { CoreBlockBaseHandler } from '@core/block/classes/base-block-handler'; + +/** + * Block handler. + */ +@Injectable() +export class AddonBlockSelfCompletionHandler extends CoreBlockBaseHandler { + name = 'AddonBlockSelfCompletion'; + blockName = 'selfcompletion'; + + constructor() { + super(); + } + + /** + * Returns the data needed to render the block. + * + * @param {Injector} injector Injector. + * @param {any} block The block to render. + * @param {string} contextLevel The context where the block will be used. + * @param {number} instanceId The instance ID associated with the context level. + * @return {CoreBlockHandlerData|Promise} Data or promise resolved with the data. + */ + getDisplayData(injector: Injector, block: any, contextLevel: string, instanceId: number) + : CoreBlockHandlerData | Promise { + + return { + title: 'addon.block_selfcompletion.pluginname', + class: 'addon-block-self-completion', + component: CoreBlockOnlyTitleComponent, + link: 'AddonCourseCompletionReportPage', + linkParams: { courseId: instanceId } + }; + } +} diff --git a/src/addon/block/selfcompletion/selfcompletion.module.ts b/src/addon/block/selfcompletion/selfcompletion.module.ts new file mode 100644 index 000000000..b101210b2 --- /dev/null +++ b/src/addon/block/selfcompletion/selfcompletion.module.ts @@ -0,0 +1,38 @@ +// (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 { IonicModule } from 'ionic-angular'; +import { TranslateModule } from '@ngx-translate/core'; +import { CoreBlockDelegate } from '@core/block/providers/delegate'; +import { AddonBlockSelfCompletionHandler } from './providers/block-handler'; + +@NgModule({ + declarations: [ + ], + imports: [ + IonicModule, + TranslateModule.forChild() + ], + exports: [ + ], + providers: [ + AddonBlockSelfCompletionHandler + ] +}) +export class AddonBlockSelfCompletionModule { + constructor(blockDelegate: CoreBlockDelegate, blockHandler: AddonBlockSelfCompletionHandler) { + blockDelegate.registerHandler(blockHandler); + } +} diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 0244cbc2c..594416b75 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -102,6 +102,7 @@ import { AddonBlockTimelineModule } from '@addon/block/timeline/timeline.module' import { AddonBlockRecentlyAccessedCoursesModule } from '@addon/block/recentlyaccessedcourses/recentlyaccessedcourses.module'; import { AddonBlockRecentlyAccessedItemsModule } from '@addon/block/recentlyaccesseditems/recentlyaccesseditems.module'; import { AddonBlockStarredCoursesModule } from '@addon/block/starredcourses/starredcourses.module'; +import { AddonBlockSelfCompletionModule } from '@addon/block/selfcompletion/selfcompletion.module'; import { AddonModAssignModule } from '@addon/mod/assign/assign.module'; import { AddonModBookModule } from '@addon/mod/book/book.module'; import { AddonModChatModule } from '@addon/mod/chat/chat.module'; @@ -229,6 +230,7 @@ export const CORE_PROVIDERS: any[] = [ AddonBlockRecentlyAccessedCoursesModule, AddonBlockRecentlyAccessedItemsModule, AddonBlockStarredCoursesModule, + AddonBlockSelfCompletionModule, AddonModAssignModule, AddonModBookModule, AddonModChatModule, diff --git a/src/assets/lang/en.json b/src/assets/lang/en.json index d6b15d48c..8bc1efe9b 100644 --- a/src/assets/lang/en.json +++ b/src/assets/lang/en.json @@ -47,6 +47,7 @@ "addon.block_recentlyaccessedcourses.pluginname": "Recently accessed courses", "addon.block_recentlyaccesseditems.noitems": "No recent items", "addon.block_recentlyaccesseditems.pluginname": "Recently accessed items", + "addon.block_selfcompletion.pluginname": "Self completion", "addon.block_sitemainmenu.pluginname": "Main menu", "addon.block_starredcourses.nocourses": "No starred courses", "addon.block_starredcourses.pluginname": "Starred courses", From f368333ca148bf796c9ab698fc9860c3372bc87c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Wed, 8 May 2019 12:55:22 +0200 Subject: [PATCH 9/9] MOBILE-3014 block: Add Comments block feature --- scripts/langindex.json | 1 + src/addon/block/comments/comments.module.ts | 38 +++++++++++++ src/addon/block/comments/lang/en.json | 3 ++ .../block/comments/providers/block-handler.ts | 53 +++++++++++++++++++ src/app/app.module.ts | 2 + src/assets/lang/en.json | 1 + 6 files changed, 98 insertions(+) create mode 100644 src/addon/block/comments/comments.module.ts create mode 100644 src/addon/block/comments/lang/en.json create mode 100644 src/addon/block/comments/providers/block-handler.ts diff --git a/scripts/langindex.json b/scripts/langindex.json index 34a760445..1d142fd09 100644 --- a/scripts/langindex.json +++ b/scripts/langindex.json @@ -29,6 +29,7 @@ "addon.block_activitymodules.pluginname": "block_activity_modules", "addon.block_calendarmonth.pluginname": "block_calendar_month", "addon.block_calendarupcoming.pluginname": "block_calendar_upcoming", + "addon.block_comments.pluginname": "block_comments", "addon.block_completionstatus.pluginname": "block_completionstatus", "addon.block_learningplans.pluginname": "block_lp", "addon.block_myoverview.all": "block_myoverview", diff --git a/src/addon/block/comments/comments.module.ts b/src/addon/block/comments/comments.module.ts new file mode 100644 index 000000000..dce565e7d --- /dev/null +++ b/src/addon/block/comments/comments.module.ts @@ -0,0 +1,38 @@ +// (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 { IonicModule } from 'ionic-angular'; +import { TranslateModule } from '@ngx-translate/core'; +import { CoreBlockDelegate } from '@core/block/providers/delegate'; +import { AddonBlockCommentsHandler } from './providers/block-handler'; + +@NgModule({ + declarations: [ + ], + imports: [ + IonicModule, + TranslateModule.forChild() + ], + exports: [ + ], + providers: [ + AddonBlockCommentsHandler + ] +}) +export class AddonBlockCommentsModule { + constructor(blockDelegate: CoreBlockDelegate, blockHandler: AddonBlockCommentsHandler) { + blockDelegate.registerHandler(blockHandler); + } +} diff --git a/src/addon/block/comments/lang/en.json b/src/addon/block/comments/lang/en.json new file mode 100644 index 000000000..adcbcabae --- /dev/null +++ b/src/addon/block/comments/lang/en.json @@ -0,0 +1,3 @@ +{ + "pluginname": "Comments" +} \ No newline at end of file diff --git a/src/addon/block/comments/providers/block-handler.ts b/src/addon/block/comments/providers/block-handler.ts new file mode 100644 index 000000000..81e5b2c15 --- /dev/null +++ b/src/addon/block/comments/providers/block-handler.ts @@ -0,0 +1,53 @@ +// (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 { CoreBlockHandlerData } from '@core/block/providers/delegate'; +import { CoreBlockOnlyTitleComponent } from '@core/block/components/only-title-block/only-title-block'; +import { CoreBlockBaseHandler } from '@core/block/classes/base-block-handler'; + +/** + * Block handler. + */ +@Injectable() +export class AddonBlockCommentsHandler extends CoreBlockBaseHandler { + name = 'AddonBlockComments'; + blockName = 'comments'; + + constructor() { + super(); + } + + /** + * Returns the data needed to render the block. + * + * @param {Injector} injector Injector. + * @param {any} block The block to render. + * @param {string} contextLevel The context where the block will be used. + * @param {number} instanceId The instance ID associated with the context level. + * @return {CoreBlockHandlerData|Promise} Data or promise resolved with the data. + */ + getDisplayData(injector: Injector, block: any, contextLevel: string, instanceId: number) + : CoreBlockHandlerData | Promise { + + return { + title: 'addon.block_comments.pluginname', + class: 'addon-block-comments', + component: CoreBlockOnlyTitleComponent, + link: 'CoreCommentsViewerPage', + linkParams: { contextLevel: contextLevel, instanceId: instanceId, + component: 'block_comments', area: 'page_comments', itemId: 0 } + }; + } +} diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 594416b75..3086286a1 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -93,6 +93,7 @@ import { AddonFilesModule } from '@addon/files/files.module'; import { AddonBlockActivityModulesModule } from '@addon/block/activitymodules/activitymodules.module'; import { AddonBlockCalendarMonthModule } from '@addon/block/calendarmonth/calendarmonth.module'; import { AddonBlockCalendarUpcomingModule } from '@addon/block/calendarupcoming/calendarupcoming.module'; +import { AddonBlockCommentsModule } from '@addon/block/comments/comments.module'; import { AddonBlockCompletionStatusModule } from '@addon/block/completionstatus/completionstatus.module'; import { AddonBlockMyOverviewModule } from '@addon/block/myoverview/myoverview.module'; import { AddonBlockLearningPlansModule } from '@addon/block/learningplans/learningplans.module'; @@ -221,6 +222,7 @@ export const CORE_PROVIDERS: any[] = [ AddonBlockActivityModulesModule, AddonBlockCalendarMonthModule, AddonBlockCalendarUpcomingModule, + AddonBlockCommentsModule, AddonBlockCompletionStatusModule, AddonBlockLearningPlansModule, AddonBlockMyOverviewModule, diff --git a/src/assets/lang/en.json b/src/assets/lang/en.json index 8bc1efe9b..c28b1240e 100644 --- a/src/assets/lang/en.json +++ b/src/assets/lang/en.json @@ -29,6 +29,7 @@ "addon.block_activitymodules.pluginname": "Activities", "addon.block_calendarmonth.pluginname": "Calendar", "addon.block_calendarupcoming.pluginname": " Upcoming events", + "addon.block_comments.pluginname": "Comments", "addon.block_completionstatus.pluginname": "Course completion status", "addon.block_learningplans.pluginname": "Learning plans", "addon.block_myoverview.all": "All",