MOBILE-2201 user: Tag area handler for users
This commit is contained in:
		
							parent
							
								
									df423b640e
								
							
						
					
					
						commit
						b0b1c2f7c9
					
				| @ -1798,6 +1798,7 @@ | |||||||
|   "core.tag.tagarea_course": "moodle", |   "core.tag.tagarea_course": "moodle", | ||||||
|   "core.tag.tagarea_course_modules": "moodle", |   "core.tag.tagarea_course_modules": "moodle", | ||||||
|   "core.tag.tagarea_post": "moodle", |   "core.tag.tagarea_post": "moodle", | ||||||
|  |   "core.tag.tagarea_user": "moodle", | ||||||
|   "core.tag.tags": "moodle", |   "core.tag.tags": "moodle", | ||||||
|   "core.teachers": "moodle", |   "core.teachers": "moodle", | ||||||
|   "core.thereisdatatosync": "local_moodlemobileapp", |   "core.thereisdatatosync": "local_moodlemobileapp", | ||||||
|  | |||||||
| @ -1798,6 +1798,7 @@ | |||||||
|     "core.tag.tagarea_course": "Courses", |     "core.tag.tagarea_course": "Courses", | ||||||
|     "core.tag.tagarea_course_modules": "Activities and resources", |     "core.tag.tagarea_course_modules": "Activities and resources", | ||||||
|     "core.tag.tagarea_post": "Blog posts", |     "core.tag.tagarea_post": "Blog posts", | ||||||
|  |     "core.tag.tagarea_user": "User interests", | ||||||
|     "core.tag.tags": "Tags", |     "core.tag.tags": "Tags", | ||||||
|     "core.teachers": "Teachers", |     "core.teachers": "Teachers", | ||||||
|     "core.thereisdatatosync": "There are offline {{$a}} to be synchronised.", |     "core.thereisdatatosync": "There are offline {{$a}} to be synchronised.", | ||||||
|  | |||||||
| @ -2,5 +2,6 @@ | |||||||
|     "tagarea_course": "Courses", |     "tagarea_course": "Courses", | ||||||
|     "tagarea_course_modules": "Activities and resources", |     "tagarea_course_modules": "Activities and resources", | ||||||
|     "tagarea_post": "Blog posts", |     "tagarea_post": "Blog posts", | ||||||
|  |     "tagarea_user": "User interests", | ||||||
|     "tags": "Tags" |     "tags": "Tags" | ||||||
| } | } | ||||||
|  | |||||||
| @ -18,6 +18,7 @@ import { IonicModule } from 'ionic-angular'; | |||||||
| import { TranslateModule } from '@ngx-translate/core'; | import { TranslateModule } from '@ngx-translate/core'; | ||||||
| import { CoreUserParticipantsComponent } from './participants/participants'; | import { CoreUserParticipantsComponent } from './participants/participants'; | ||||||
| import { CoreUserProfileFieldComponent } from './user-profile-field/user-profile-field'; | import { CoreUserProfileFieldComponent } from './user-profile-field/user-profile-field'; | ||||||
|  | import { CoreUserTagAreaComponent } from './tag-area/tag-area'; | ||||||
| import { CoreComponentsModule } from '@components/components.module'; | import { CoreComponentsModule } from '@components/components.module'; | ||||||
| import { CoreDirectivesModule } from '@directives/directives.module'; | import { CoreDirectivesModule } from '@directives/directives.module'; | ||||||
| import { CorePipesModule } from '@pipes/pipes.module'; | import { CorePipesModule } from '@pipes/pipes.module'; | ||||||
| @ -25,7 +26,8 @@ import { CorePipesModule } from '@pipes/pipes.module'; | |||||||
| @NgModule({ | @NgModule({ | ||||||
|     declarations: [ |     declarations: [ | ||||||
|         CoreUserParticipantsComponent, |         CoreUserParticipantsComponent, | ||||||
|         CoreUserProfileFieldComponent |         CoreUserProfileFieldComponent, | ||||||
|  |         CoreUserTagAreaComponent | ||||||
|     ], |     ], | ||||||
|     imports: [ |     imports: [ | ||||||
|         CommonModule, |         CommonModule, | ||||||
| @ -39,10 +41,12 @@ import { CorePipesModule } from '@pipes/pipes.module'; | |||||||
|     ], |     ], | ||||||
|     exports: [ |     exports: [ | ||||||
|         CoreUserParticipantsComponent, |         CoreUserParticipantsComponent, | ||||||
|         CoreUserProfileFieldComponent |         CoreUserProfileFieldComponent, | ||||||
|  |         CoreUserTagAreaComponent | ||||||
|     ], |     ], | ||||||
|     entryComponents: [ |     entryComponents: [ | ||||||
|         CoreUserParticipantsComponent |         CoreUserParticipantsComponent, | ||||||
|  |         CoreUserTagAreaComponent | ||||||
|     ] |     ] | ||||||
| }) | }) | ||||||
| export class CoreUserComponentsModule {} | export class CoreUserComponentsModule {} | ||||||
|  | |||||||
| @ -0,0 +1,4 @@ | |||||||
|  | <a ion-item text-wrap *ngFor="let item of items" core-user-link [userId]="item.id"> | ||||||
|  |     <ion-avatar core-user-avatar [user]="item" item-start></ion-avatar> | ||||||
|  |     <h2>{{ item.fullname }}</h2> | ||||||
|  | </a> | ||||||
							
								
								
									
										26
									
								
								src/core/user/components/tag-area/tag-area.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								src/core/user/components/tag-area/tag-area.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,26 @@ | |||||||
|  | // (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, Input } from '@angular/core'; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * Component to render the user tag area. | ||||||
|  |  */ | ||||||
|  | @Component({ | ||||||
|  |     selector: 'core-user-tag-area', | ||||||
|  |     templateUrl: 'core-user-tag-area.html' | ||||||
|  | }) | ||||||
|  | export class CoreUserTagAreaComponent { | ||||||
|  |     @Input() items: any[]; // Area items to render.
 | ||||||
|  | } | ||||||
							
								
								
									
										82
									
								
								src/core/user/providers/tag-area-handler.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										82
									
								
								src/core/user/providers/tag-area-handler.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,82 @@ | |||||||
|  | // (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 { CoreDomUtilsProvider } from '@providers/utils/dom'; | ||||||
|  | import { CoreTagAreaHandler } from '@core/tag/providers/area-delegate'; | ||||||
|  | import { CoreUserTagAreaComponent } from '../components/tag-area/tag-area'; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * Handler to support tags. | ||||||
|  |  */ | ||||||
|  | @Injectable() | ||||||
|  | export class CoreUserTagAreaHandler implements CoreTagAreaHandler { | ||||||
|  |     name = 'CoreUserTagAreaHandler'; | ||||||
|  |     type = 'core/user'; | ||||||
|  | 
 | ||||||
|  |     constructor(private domUtils: CoreDomUtilsProvider) {} | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Whether or not the handler is enabled on a site level. | ||||||
|  |      * @return {boolean|Promise<boolean>} Whether or not the handler is enabled on a site level. | ||||||
|  |      */ | ||||||
|  |     isEnabled(): boolean | Promise<boolean> { | ||||||
|  |         return true; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Parses the rendered content of a tag index and returns the items. | ||||||
|  |      * | ||||||
|  |      * @param {string} content Rendered content. | ||||||
|  |      * @return {any[]|Promise<any[]>} Area items (or promise resolved with the items). | ||||||
|  |      */ | ||||||
|  |     parseContent(content: string): any[] | Promise<any[]> { | ||||||
|  |         const items = []; | ||||||
|  |         const element = this.domUtils.convertToElement(content); | ||||||
|  | 
 | ||||||
|  |         Array.from(element.querySelectorAll('div.user-box')).forEach((userbox: HTMLElement) => { | ||||||
|  |             const item: any = {}; | ||||||
|  | 
 | ||||||
|  |             const avatarLink = userbox.querySelector('a:first-child'); | ||||||
|  |             if (!avatarLink) { | ||||||
|  |                 return; | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             const profileUrl = avatarLink.getAttribute('href') || ''; | ||||||
|  |             const match = profileUrl.match(/.*\/user\/(?:profile|view)\.php\?id=(\d+)/); | ||||||
|  |             if (!match) { | ||||||
|  |                 return; | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             item.id = parseInt(match[1], 10); | ||||||
|  |             const avatarImg = avatarLink.querySelector('img.userpicture'); | ||||||
|  |             item.profileimageurl = avatarImg ? avatarImg.getAttribute('src') : ''; | ||||||
|  |             item.fullname = userbox.innerText; | ||||||
|  | 
 | ||||||
|  |             items.push(item); | ||||||
|  |         }); | ||||||
|  | 
 | ||||||
|  |         return items; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Get the component to use to display items. | ||||||
|  |      * | ||||||
|  |      * @param {Injector} injector Injector. | ||||||
|  |      * @return {any|Promise<any>} The component (or promise resolved with component) to use, undefined if not found. | ||||||
|  |      */ | ||||||
|  |     getComponent(injector: Injector): any | Promise<any> { | ||||||
|  |         return CoreUserTagAreaComponent; | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -30,6 +30,8 @@ import { CoreCronDelegate } from '@providers/cron'; | |||||||
| import { CoreUserOfflineProvider } from './providers/offline'; | import { CoreUserOfflineProvider } from './providers/offline'; | ||||||
| import { CoreUserSyncProvider } from './providers/sync'; | import { CoreUserSyncProvider } from './providers/sync'; | ||||||
| import { CoreUserSyncCronHandler } from './providers/sync-cron-handler'; | import { CoreUserSyncCronHandler } from './providers/sync-cron-handler'; | ||||||
|  | import { CoreTagAreaDelegate } from '@core/tag/providers/area-delegate'; | ||||||
|  | import { CoreUserTagAreaHandler } from './providers/tag-area-handler'; | ||||||
| 
 | 
 | ||||||
| // List of providers (without handlers).
 | // List of providers (without handlers).
 | ||||||
| export const CORE_USER_PROVIDERS: any[] = [ | export const CORE_USER_PROVIDERS: any[] = [ | ||||||
| @ -59,6 +61,7 @@ export const CORE_USER_PROVIDERS: any[] = [ | |||||||
|         CoreUserParticipantsCourseOptionHandler, |         CoreUserParticipantsCourseOptionHandler, | ||||||
|         CoreUserParticipantsLinkHandler, |         CoreUserParticipantsLinkHandler, | ||||||
|         CoreUserSyncCronHandler, |         CoreUserSyncCronHandler, | ||||||
|  |         CoreUserTagAreaHandler | ||||||
|     ] |     ] | ||||||
| }) | }) | ||||||
| export class CoreUserModule { | export class CoreUserModule { | ||||||
| @ -67,13 +70,14 @@ export class CoreUserModule { | |||||||
|             contentLinksDelegate: CoreContentLinksDelegate, userLinkHandler: CoreUserProfileLinkHandler, |             contentLinksDelegate: CoreContentLinksDelegate, userLinkHandler: CoreUserProfileLinkHandler, | ||||||
|             courseOptionHandler: CoreUserParticipantsCourseOptionHandler, linkHandler: CoreUserParticipantsLinkHandler, |             courseOptionHandler: CoreUserParticipantsCourseOptionHandler, linkHandler: CoreUserParticipantsLinkHandler, | ||||||
|             courseOptionsDelegate: CoreCourseOptionsDelegate, cronDelegate: CoreCronDelegate, |             courseOptionsDelegate: CoreCourseOptionsDelegate, cronDelegate: CoreCronDelegate, | ||||||
|             syncHandler: CoreUserSyncCronHandler) { |             syncHandler: CoreUserSyncCronHandler, tagAreaDelegate: CoreTagAreaDelegate, tagAreaHandler: CoreUserTagAreaHandler) { | ||||||
| 
 | 
 | ||||||
|         userDelegate.registerHandler(userProfileMailHandler); |         userDelegate.registerHandler(userProfileMailHandler); | ||||||
|         courseOptionsDelegate.registerHandler(courseOptionHandler); |         courseOptionsDelegate.registerHandler(courseOptionHandler); | ||||||
|         contentLinksDelegate.registerHandler(userLinkHandler); |         contentLinksDelegate.registerHandler(userLinkHandler); | ||||||
|         contentLinksDelegate.registerHandler(linkHandler); |         contentLinksDelegate.registerHandler(linkHandler); | ||||||
|         cronDelegate.register(syncHandler); |         cronDelegate.register(syncHandler); | ||||||
|  |         tagAreaDelegate.registerHandler(tagAreaHandler); | ||||||
| 
 | 
 | ||||||
|         eventsProvider.on(CoreEventsProvider.USER_DELETED, (data) => { |         eventsProvider.on(CoreEventsProvider.USER_DELETED, (data) => { | ||||||
|             // Search for userid in params.
 |             // Search for userid in params.
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user