forked from CIT/Vmeda.Online
		
	MOBILE-3014 block: Support for only title block type
This commit is contained in:
		
							parent
							
								
									6557793227
								
							
						
					
					
						commit
						26a1fad8c8
					
				| @ -38,7 +38,7 @@ export class AddonBlockActivityModulesHandler extends CoreBlockBaseHandler { | |||||||
|      * @param {number} instanceId The instance ID associated with the context level. |      * @param {number} instanceId The instance ID associated with the context level. | ||||||
|      * @return {CoreBlockHandlerData|Promise<CoreBlockHandlerData>} Data or promise resolved with the data. |      * @return {CoreBlockHandlerData|Promise<CoreBlockHandlerData>} 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<CoreBlockHandlerData> { |             : CoreBlockHandlerData | Promise<CoreBlockHandlerData> { | ||||||
| 
 | 
 | ||||||
|         return { |         return { | ||||||
|  | |||||||
| @ -50,7 +50,7 @@ export class AddonBlockMyOverviewHandler extends CoreBlockBaseHandler { | |||||||
|      * @param {number} instanceId The instance ID associated with the context level. |      * @param {number} instanceId The instance ID associated with the context level. | ||||||
|      * @return {CoreBlockHandlerData|Promise<CoreBlockHandlerData>} Data or promise resolved with the data. |      * @return {CoreBlockHandlerData|Promise<CoreBlockHandlerData>} 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<CoreBlockHandlerData> { |             : CoreBlockHandlerData | Promise<CoreBlockHandlerData> { | ||||||
| 
 | 
 | ||||||
|         return { |         return { | ||||||
|  | |||||||
| @ -38,7 +38,7 @@ export class AddonBlockRecentlyAccessedCoursesHandler extends CoreBlockBaseHandl | |||||||
|      * @param {number} instanceId The instance ID associated with the context level. |      * @param {number} instanceId The instance ID associated with the context level. | ||||||
|      * @return {CoreBlockHandlerData|Promise<CoreBlockHandlerData>} Data or promise resolved with the data. |      * @return {CoreBlockHandlerData|Promise<CoreBlockHandlerData>} 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<CoreBlockHandlerData> { |             : CoreBlockHandlerData | Promise<CoreBlockHandlerData> { | ||||||
| 
 | 
 | ||||||
|         return { |         return { | ||||||
|  | |||||||
| @ -38,7 +38,7 @@ export class AddonBlockRecentlyAccessedItemsHandler extends CoreBlockBaseHandler | |||||||
|      * @param {number} instanceId The instance ID associated with the context level. |      * @param {number} instanceId The instance ID associated with the context level. | ||||||
|      * @return {CoreBlockHandlerData|Promise<CoreBlockHandlerData>} Data or promise resolved with the data. |      * @return {CoreBlockHandlerData|Promise<CoreBlockHandlerData>} 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<CoreBlockHandlerData> { |             : CoreBlockHandlerData | Promise<CoreBlockHandlerData> { | ||||||
| 
 | 
 | ||||||
|         return { |         return { | ||||||
|  | |||||||
| @ -38,7 +38,7 @@ export class AddonBlockSiteMainMenuHandler extends CoreBlockBaseHandler { | |||||||
|      * @param {number} instanceId The instance ID associated with the context level. |      * @param {number} instanceId The instance ID associated with the context level. | ||||||
|      * @return {CoreBlockHandlerData|Promise<CoreBlockHandlerData>} Data or promise resolved with the data. |      * @return {CoreBlockHandlerData|Promise<CoreBlockHandlerData>} 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<CoreBlockHandlerData> { |             : CoreBlockHandlerData | Promise<CoreBlockHandlerData> { | ||||||
| 
 | 
 | ||||||
|         return { |         return { | ||||||
|  | |||||||
| @ -38,7 +38,7 @@ export class AddonBlockStarredCoursesHandler extends CoreBlockBaseHandler { | |||||||
|      * @param {number} instanceId The instance ID associated with the context level. |      * @param {number} instanceId The instance ID associated with the context level. | ||||||
|      * @return {CoreBlockHandlerData|Promise<CoreBlockHandlerData>} Data or promise resolved with the data. |      * @return {CoreBlockHandlerData|Promise<CoreBlockHandlerData>} 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<CoreBlockHandlerData> { |             : CoreBlockHandlerData | Promise<CoreBlockHandlerData> { | ||||||
| 
 | 
 | ||||||
|         return { |         return { | ||||||
|  | |||||||
| @ -55,7 +55,7 @@ export class AddonBlockTimelineHandler extends CoreBlockBaseHandler { | |||||||
|      * @param {number} instanceId The instance ID associated with the context level. |      * @param {number} instanceId The instance ID associated with the context level. | ||||||
|      * @return {CoreBlockHandlerData|Promise<CoreBlockHandlerData>} Data or promise resolved with the data. |      * @return {CoreBlockHandlerData|Promise<CoreBlockHandlerData>} 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<CoreBlockHandlerData> { |             : CoreBlockHandlerData | Promise<CoreBlockHandlerData> { | ||||||
| 
 | 
 | ||||||
|         return { |         return { | ||||||
|  | |||||||
| @ -12,7 +12,7 @@ | |||||||
| // See the License for the specific language governing permissions and
 | // See the License for the specific language governing permissions and
 | ||||||
| // limitations under the License.
 | // limitations under the License.
 | ||||||
| 
 | 
 | ||||||
| import { Injector, OnInit } from '@angular/core'; | import { Injector, OnInit, Input } from '@angular/core'; | ||||||
| import { CoreLoggerProvider } from '@providers/logger'; | import { CoreLoggerProvider } from '@providers/logger'; | ||||||
| import { CoreDomUtilsProvider } from '@providers/utils/dom'; | import { CoreDomUtilsProvider } from '@providers/utils/dom'; | ||||||
| 
 | 
 | ||||||
| @ -20,6 +20,13 @@ import { CoreDomUtilsProvider } from '@providers/utils/dom'; | |||||||
|  * Template class to easily create components for blocks. |  * Template class to easily create components for blocks. | ||||||
|  */ |  */ | ||||||
| export class CoreBlockBaseComponent implements OnInit { | 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.
 |     loaded: boolean; // If the component has been loaded.
 | ||||||
|     protected fetchContentDefaultError: string; // Default error to show when loading contents.
 |     protected fetchContentDefaultError: string; // Default error to show when loading contents.
 | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -47,7 +47,7 @@ export class CoreBlockBaseHandler implements CoreBlockHandler { | |||||||
|      * @param {number} instanceId The instance ID associated with the context level. |      * @param {number} instanceId The instance ID associated with the context level. | ||||||
|      * @return {CoreBlockHandlerData|Promise<CoreBlockHandlerData>} Data or promise resolved with the data. |      * @return {CoreBlockHandlerData|Promise<CoreBlockHandlerData>} 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<CoreBlockHandlerData> { |             : CoreBlockHandlerData | Promise<CoreBlockHandlerData> { | ||||||
| 
 | 
 | ||||||
|         // To be overridden.
 |         // To be overridden.
 | ||||||
|  | |||||||
| @ -33,7 +33,6 @@ export class CoreBlockComponent implements OnInit, OnDestroy { | |||||||
|     @Input() instanceId: number; // The instance ID associated with the context level.
 |     @Input() instanceId: number; // The instance ID associated with the context level.
 | ||||||
|     @Input() extraData: any; // Any extra data to be passed to the block.
 |     @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.
 |     componentClass: any; // The class of the component to render.
 | ||||||
|     data: any = {}; // Data to pass to the component.
 |     data: any = {}; // Data to pass to the component.
 | ||||||
|     class: string; // CSS class to apply to the block.
 |     class: string; // CSS class to apply to the block.
 | ||||||
| @ -80,15 +79,17 @@ export class CoreBlockComponent implements OnInit, OnDestroy { | |||||||
|                 return; |                 return; | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             this.title = data.title; |  | ||||||
|             this.class = data.class; |             this.class = data.class; | ||||||
|             this.componentClass = data.component; |             this.componentClass = data.component; | ||||||
| 
 | 
 | ||||||
|             // Set up the data needed by the block component.
 |             // Set up the data needed by the block component.
 | ||||||
|             this.data = Object.assign({ |             this.data = Object.assign({ | ||||||
|  |                     title: data.title, | ||||||
|                     block: this.block, |                     block: this.block, | ||||||
|                     contextLevel: this.contextLevel, |                     contextLevel: this.contextLevel, | ||||||
|                     instanceId: this.instanceId, |                     instanceId: this.instanceId, | ||||||
|  |                     link: data.link || null, | ||||||
|  |                     linkParams: data.linkParams || null, | ||||||
|                 }, this.extraData || {}, data.componentData || {}); |                 }, this.extraData || {}, data.componentData || {}); | ||||||
|         }).catch(() => { |         }).catch(() => { | ||||||
|             // Ignore errors.
 |             // Ignore errors.
 | ||||||
|  | |||||||
| @ -16,23 +16,31 @@ import { NgModule } from '@angular/core'; | |||||||
| import { CommonModule } from '@angular/common'; | import { CommonModule } from '@angular/common'; | ||||||
| import { IonicModule } from 'ionic-angular'; | import { IonicModule } from 'ionic-angular'; | ||||||
| import { TranslateModule } from '@ngx-translate/core'; | import { TranslateModule } from '@ngx-translate/core'; | ||||||
|  | import { CoreDirectivesModule } from '@directives/directives.module'; | ||||||
| import { CoreBlockComponent } from './block/block'; | import { CoreBlockComponent } from './block/block'; | ||||||
|  | import { CoreBlockOnlyTitleComponent } from './only-title-block/only-title-block'; | ||||||
| import { CoreComponentsModule } from '@components/components.module'; | import { CoreComponentsModule } from '@components/components.module'; | ||||||
| 
 | 
 | ||||||
| @NgModule({ | @NgModule({ | ||||||
|     declarations: [ |     declarations: [ | ||||||
|         CoreBlockComponent |         CoreBlockComponent, | ||||||
|  |         CoreBlockOnlyTitleComponent | ||||||
|     ], |     ], | ||||||
|     imports: [ |     imports: [ | ||||||
|         CommonModule, |         CommonModule, | ||||||
|         IonicModule, |         IonicModule, | ||||||
|  |         CoreDirectivesModule, | ||||||
|         TranslateModule.forChild(), |         TranslateModule.forChild(), | ||||||
|         CoreComponentsModule |         CoreComponentsModule | ||||||
|     ], |     ], | ||||||
|     providers: [ |     providers: [ | ||||||
|     ], |     ], | ||||||
|     exports: [ |     exports: [ | ||||||
|         CoreBlockComponent |         CoreBlockComponent, | ||||||
|  |         CoreBlockOnlyTitleComponent | ||||||
|  |     ], | ||||||
|  |     entryComponents: [ | ||||||
|  |         CoreBlockOnlyTitleComponent | ||||||
|     ] |     ] | ||||||
| }) | }) | ||||||
| export class CoreBlockComponentsModule {} | export class CoreBlockComponentsModule {} | ||||||
|  | |||||||
| @ -0,0 +1,3 @@ | |||||||
|  | <ion-item-divider text-wrap detail-push (click)="gotoBlock($event)"> | ||||||
|  |     <h2>{{ title | translate }}</h2> | ||||||
|  | </ion-item-divider> | ||||||
| @ -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); | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -73,6 +73,18 @@ export interface CoreBlockHandlerData { | |||||||
|      * @type {any} |      * @type {any} | ||||||
|      */ |      */ | ||||||
|     componentData?: 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<CoreBlockHandlerData>} Promise resolved with the display data. |      * @return {Promise<CoreBlockHandlerData>} Promise resolved with the display data. | ||||||
|      */ |      */ | ||||||
|     getBlockDisplayData(injector: Injector, block: any, contextLevel: string, instanceId: number): Promise<CoreBlockHandlerData> { |     getBlockDisplayData(injector: Injector, block: any, contextLevel: string, instanceId: number): Promise<CoreBlockHandlerData> { | ||||||
|         return Promise.resolve(this.executeFunctionOnEnabled(block.name, 'getDisplayData', [injector, block])); |         return Promise.resolve(this.executeFunctionOnEnabled(block.name, 'getDisplayData', | ||||||
|  |             [injector, block, contextLevel, instanceId])); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user