MOBILE-2201 user: Tag area handler for users

main
Albert Gasset 2019-07-08 12:13:59 +02:00
parent df423b640e
commit b0b1c2f7c9
8 changed files with 127 additions and 4 deletions

View File

@ -1798,6 +1798,7 @@
"core.tag.tagarea_course": "moodle",
"core.tag.tagarea_course_modules": "moodle",
"core.tag.tagarea_post": "moodle",
"core.tag.tagarea_user": "moodle",
"core.tag.tags": "moodle",
"core.teachers": "moodle",
"core.thereisdatatosync": "local_moodlemobileapp",

View File

@ -1798,6 +1798,7 @@
"core.tag.tagarea_course": "Courses",
"core.tag.tagarea_course_modules": "Activities and resources",
"core.tag.tagarea_post": "Blog posts",
"core.tag.tagarea_user": "User interests",
"core.tag.tags": "Tags",
"core.teachers": "Teachers",
"core.thereisdatatosync": "There are offline {{$a}} to be synchronised.",

View File

@ -2,5 +2,6 @@
"tagarea_course": "Courses",
"tagarea_course_modules": "Activities and resources",
"tagarea_post": "Blog posts",
"tagarea_user": "User interests",
"tags": "Tags"
}

View File

@ -18,6 +18,7 @@ import { IonicModule } from 'ionic-angular';
import { TranslateModule } from '@ngx-translate/core';
import { CoreUserParticipantsComponent } from './participants/participants';
import { CoreUserProfileFieldComponent } from './user-profile-field/user-profile-field';
import { CoreUserTagAreaComponent } from './tag-area/tag-area';
import { CoreComponentsModule } from '@components/components.module';
import { CoreDirectivesModule } from '@directives/directives.module';
import { CorePipesModule } from '@pipes/pipes.module';
@ -25,7 +26,8 @@ import { CorePipesModule } from '@pipes/pipes.module';
@NgModule({
declarations: [
CoreUserParticipantsComponent,
CoreUserProfileFieldComponent
CoreUserProfileFieldComponent,
CoreUserTagAreaComponent
],
imports: [
CommonModule,
@ -39,10 +41,12 @@ import { CorePipesModule } from '@pipes/pipes.module';
],
exports: [
CoreUserParticipantsComponent,
CoreUserProfileFieldComponent
CoreUserProfileFieldComponent,
CoreUserTagAreaComponent
],
entryComponents: [
CoreUserParticipantsComponent
CoreUserParticipantsComponent,
CoreUserTagAreaComponent
]
})
export class CoreUserComponentsModule {}

View File

@ -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>

View 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.
}

View 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;
}
}

View File

@ -30,6 +30,8 @@ import { CoreCronDelegate } from '@providers/cron';
import { CoreUserOfflineProvider } from './providers/offline';
import { CoreUserSyncProvider } from './providers/sync';
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).
export const CORE_USER_PROVIDERS: any[] = [
@ -59,6 +61,7 @@ export const CORE_USER_PROVIDERS: any[] = [
CoreUserParticipantsCourseOptionHandler,
CoreUserParticipantsLinkHandler,
CoreUserSyncCronHandler,
CoreUserTagAreaHandler
]
})
export class CoreUserModule {
@ -67,13 +70,14 @@ export class CoreUserModule {
contentLinksDelegate: CoreContentLinksDelegate, userLinkHandler: CoreUserProfileLinkHandler,
courseOptionHandler: CoreUserParticipantsCourseOptionHandler, linkHandler: CoreUserParticipantsLinkHandler,
courseOptionsDelegate: CoreCourseOptionsDelegate, cronDelegate: CoreCronDelegate,
syncHandler: CoreUserSyncCronHandler) {
syncHandler: CoreUserSyncCronHandler, tagAreaDelegate: CoreTagAreaDelegate, tagAreaHandler: CoreUserTagAreaHandler) {
userDelegate.registerHandler(userProfileMailHandler);
courseOptionsDelegate.registerHandler(courseOptionHandler);
contentLinksDelegate.registerHandler(userLinkHandler);
contentLinksDelegate.registerHandler(linkHandler);
cronDelegate.register(syncHandler);
tagAreaDelegate.registerHandler(tagAreaHandler);
eventsProvider.on(CoreEventsProvider.USER_DELETED, (data) => {
// Search for userid in params.