forked from CIT/Vmeda.Online
		
	MOBILE-2317 user: Add user links handler
This commit is contained in:
		
							parent
							
								
									09e07c31fe
								
							
						
					
					
						commit
						96d548e706
					
				| @ -21,19 +21,20 @@ | ||||
|                 <core-format-text [text]="course.summary" maxHeight="120"></core-format-text> | ||||
|             </ion-item> | ||||
| 
 | ||||
|             <a ion-item text-wrap *ngIf="course.contacts && course.contacts.length" detail-none> | ||||
|                 <p class="item-heading">{{ 'core.teachers' | translate }}</p> | ||||
|                 <p *ngFor="let contact of course.contacts">{{contact.fullname}}</p> | ||||
|             </a> | ||||
|             <ng-container text-wrap *ngIf="course.contacts && course.contacts.length"> | ||||
|                 <ion-item-divider color="light">{{ 'core.teachers' | translate }}</ion-item-divider> | ||||
|                 <a ion-item text-wrap *ngFor="let contact of course.contacts" core-user-link userId="{{contact.id}}" courseId="{{isEnrolled ? course.id : null}}" [attr.aria-label]="'core.viewprofile' | translate">{{contact.fullname}}</a> | ||||
|                 <ion-item-divider color="light"></ion-item-divider> | ||||
|             </ng-container> | ||||
|             <core-file *ngFor="let file of course.overviewfiles" [file]="file" [component]="component" [componentId]="course.id"></core-file> | ||||
|             <div *ngIf="!isEnrolled" detail-none> | ||||
|                 <ion-item text-wrap *ngFor="let instance of selfEnrolInstances"> | ||||
|                     <p class="item-heading">{{ instance.name }}</p> | ||||
|                     <h2>{{ instance.name }}</h2> | ||||
|                     <button ion-button block margin-top (click)="selfEnrolClicked(instance.id)">{{ 'core.courses.enrolme' | translate }}</button> | ||||
|                 </ion-item> | ||||
|             </div> | ||||
|             <ion-item text-wrap *ngIf="!isEnrolled && paypalEnabled" detail-none> | ||||
|                 <p class="item-heading">{{ 'core.courses.paypalaccepted' | translate }}</p> | ||||
|                 <h2>{{ 'core.courses.paypalaccepted' | translate }}</h2> | ||||
|                 <p>{{ 'core.paymentinstant' | translate }}</p> | ||||
|                 <button ion-button block margin-top (click)="paypalEnrol()">{{ 'core.courses.sendpaymentbutton' | translate }}</button> | ||||
|             </ion-item> | ||||
|  | ||||
| @ -59,11 +59,9 @@ export class CoreUserHelperProvider { | ||||
| 
 | ||||
|         let separator = this.translate.instant('core.listsep'); | ||||
| 
 | ||||
|         roles.map((value) => { | ||||
|         return roles.map((value) => { | ||||
|             let translation = this.translate.instant('core.user.' + value.shortname); | ||||
|             return translation.indexOf('core.user.') < 0 ? translation : value.shortname; | ||||
|         }); | ||||
| 
 | ||||
|         return roles.join(separator + " "); | ||||
|         }).join(separator + " "); | ||||
|     } | ||||
| } | ||||
|  | ||||
							
								
								
									
										69
									
								
								src/core/user/providers/user-link-handler.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										69
									
								
								src/core/user/providers/user-link-handler.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,69 @@ | ||||
| // (C) Copyright 2015 Martin Dougiamas
 | ||||
| //
 | ||||
| // Licensed under the Apache License, Version 2.0 (the "License");
 | ||||
| // you may not use this file except in compliance with the License.
 | ||||
| // You may obtain a copy of the License at
 | ||||
| //
 | ||||
| //     http://www.apache.org/licenses/LICENSE-2.0
 | ||||
| //
 | ||||
| // Unless required by applicable law or agreed to in writing, software
 | ||||
| // distributed under the License is distributed on an "AS IS" BASIS,
 | ||||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | ||||
| // See the License for the specific language governing permissions and
 | ||||
| // limitations under the License.
 | ||||
| 
 | ||||
| import { Injectable } from '@angular/core'; | ||||
| import { CoreContentLinksHandlerBase } from '../../contentlinks/classes/base-handler'; | ||||
| import { CoreContentLinksAction } from '../../contentlinks/providers/delegate'; | ||||
| import { CoreLoginHelperProvider } from '../../login/providers/helper'; | ||||
| 
 | ||||
| /** | ||||
|  * Handler to treat links to user profiles. | ||||
|  */ | ||||
| @Injectable() | ||||
| export class CoreUserProfileLinkHandler extends CoreContentLinksHandlerBase { | ||||
|     name = 'CoreUserProfileLinkHandler'; | ||||
|     // Match user/view.php and user/profile.php but NOT grade/report/user/.
 | ||||
|     pattern = /((\/user\/view\.php)|(\/user\/profile\.php)).*([\?\&]id=\d+)/; | ||||
| 
 | ||||
|     constructor(private loginHelper: CoreLoginHelperProvider) { | ||||
|         super(); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Get the list of actions for a link (url). | ||||
|      * | ||||
|      * @param {string[]} siteIds List of sites the URL belongs to. | ||||
|      * @param {string} url The URL to treat. | ||||
|      * @param {any} params The params of the URL. E.g. 'mysite.com?id=1' -> {id: 1} | ||||
|      * @param {number} [courseId] Course ID related to the URL. Optional but recommended. | ||||
|      * @return {CoreContentLinksAction[]|Promise<CoreContentLinksAction[]>} List of (or promise resolved with list of) actions. | ||||
|      */ | ||||
|     getActions(siteIds: string[], url: string, params: any, courseId?: number) : | ||||
|             CoreContentLinksAction[]|Promise<CoreContentLinksAction[]> { | ||||
|         return [{ | ||||
|             action: (siteId, navCtrl?) => { | ||||
|                 let stateParams = { | ||||
|                     courseId: params.course, | ||||
|                     userId: parseInt(params.id, 10) | ||||
|                 }; | ||||
|                 // Always use redirect to make it the new history root (to avoid "loops" in history).
 | ||||
|                 this.loginHelper.redirect('CoreUserProfilePage', stateParams, siteId); | ||||
|             } | ||||
|         }]; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Check if the handler is enabled for a certain site (site + user) and a URL. | ||||
|      * If not defined, defaults to true. | ||||
|      * | ||||
|      * @param {string} siteId The site ID. | ||||
|      * @param {string} url The URL to treat. | ||||
|      * @param {any} params The params of the URL. E.g. 'mysite.com?id=1' -> {id: 1} | ||||
|      * @param {number} [courseId] Course ID related to the URL. Optional but recommended. | ||||
|      * @return {boolean|Promise<boolean>} Whether the handler is enabled for the URL and site. | ||||
|      */ | ||||
|     isEnabled(siteId: string, url: string, params: any, courseId?: number) : boolean|Promise<boolean> { | ||||
|         return url.indexOf('/grade/report/') == -1; | ||||
|     } | ||||
| } | ||||
| @ -20,6 +20,8 @@ import { CoreUserHelperProvider } from './providers/helper'; | ||||
| import { CoreUserProfileMailHandler } from './providers/user-handler'; | ||||
| import { CoreEventsProvider } from '../../providers/events'; | ||||
| import { CoreSitesProvider } from '../../providers/sites'; | ||||
| import { CoreContentLinksDelegate } from '../contentlinks/providers/delegate'; | ||||
| import { CoreUserProfileLinkHandler } from './providers/user-link-handler'; | ||||
| 
 | ||||
| @NgModule({ | ||||
|     declarations: [ | ||||
| @ -31,13 +33,16 @@ import { CoreSitesProvider } from '../../providers/sites'; | ||||
|         CoreUserProfileFieldDelegate, | ||||
|         CoreUserProfileMailHandler, | ||||
|         CoreUserProvider, | ||||
|         CoreUserHelperProvider | ||||
|         CoreUserHelperProvider, | ||||
|         CoreUserProfileLinkHandler | ||||
|     ] | ||||
| }) | ||||
| export class CoreUserModule { | ||||
|     constructor(userDelegate: CoreUserDelegate, userProfileMailHandler: CoreUserProfileMailHandler, | ||||
|             eventsProvider: CoreEventsProvider, sitesProvider: CoreSitesProvider, userProvider: CoreUserProvider) { | ||||
|             eventsProvider: CoreEventsProvider, sitesProvider: CoreSitesProvider, userProvider: CoreUserProvider, | ||||
|             contentLinksDelegate: CoreContentLinksDelegate, userLinkHandler: CoreUserProfileLinkHandler) { | ||||
|         userDelegate.registerHandler(userProfileMailHandler); | ||||
|         contentLinksDelegate.registerHandler(userLinkHandler); | ||||
| 
 | ||||
|         eventsProvider.on(CoreEventsProvider.USER_DELETED, (data) => { | ||||
|             // Search for userid in params.
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user