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. | ||||
|      * @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> { | ||||
| 
 | ||||
|         return { | ||||
|  | ||||
| @ -50,7 +50,7 @@ export class AddonBlockMyOverviewHandler extends CoreBlockBaseHandler { | ||||
|      * @param {number} instanceId The instance ID associated with the context level. | ||||
|      * @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> { | ||||
| 
 | ||||
|         return { | ||||
|  | ||||
| @ -38,7 +38,7 @@ export class AddonBlockRecentlyAccessedCoursesHandler extends CoreBlockBaseHandl | ||||
|      * @param {number} instanceId The instance ID associated with the context level. | ||||
|      * @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> { | ||||
| 
 | ||||
|         return { | ||||
|  | ||||
| @ -38,7 +38,7 @@ export class AddonBlockRecentlyAccessedItemsHandler extends CoreBlockBaseHandler | ||||
|      * @param {number} instanceId The instance ID associated with the context level. | ||||
|      * @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> { | ||||
| 
 | ||||
|         return { | ||||
|  | ||||
| @ -38,7 +38,7 @@ export class AddonBlockSiteMainMenuHandler extends CoreBlockBaseHandler { | ||||
|      * @param {number} instanceId The instance ID associated with the context level. | ||||
|      * @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> { | ||||
| 
 | ||||
|         return { | ||||
|  | ||||
| @ -38,7 +38,7 @@ export class AddonBlockStarredCoursesHandler extends CoreBlockBaseHandler { | ||||
|      * @param {number} instanceId The instance ID associated with the context level. | ||||
|      * @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> { | ||||
| 
 | ||||
|         return { | ||||
|  | ||||
| @ -55,7 +55,7 @@ export class AddonBlockTimelineHandler extends CoreBlockBaseHandler { | ||||
|      * @param {number} instanceId The instance ID associated with the context level. | ||||
|      * @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> { | ||||
| 
 | ||||
|         return { | ||||
|  | ||||
| @ -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.
 | ||||
| 
 | ||||
|  | ||||
| @ -47,7 +47,7 @@ export class CoreBlockBaseHandler implements CoreBlockHandler { | ||||
|      * @param {number} instanceId The instance ID associated with the context level. | ||||
|      * @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> { | ||||
| 
 | ||||
|         // 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() 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.
 | ||||
|  | ||||
| @ -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 {} | ||||
|  | ||||
| @ -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} | ||||
|      */ | ||||
|     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. | ||||
|      */ | ||||
|     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