diff --git a/scripts/langindex.json b/scripts/langindex.json
index c40287ac5..a0dbf92e1 100644
--- a/scripts/langindex.json
+++ b/scripts/langindex.json
@@ -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",
diff --git a/src/assets/lang/en.json b/src/assets/lang/en.json
index 344ae3a2c..f48252c14 100644
--- a/src/assets/lang/en.json
+++ b/src/assets/lang/en.json
@@ -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.",
diff --git a/src/core/tag/lang/en.json b/src/core/tag/lang/en.json
index ce6aec9f1..02e288849 100644
--- a/src/core/tag/lang/en.json
+++ b/src/core/tag/lang/en.json
@@ -2,5 +2,6 @@
"tagarea_course": "Courses",
"tagarea_course_modules": "Activities and resources",
"tagarea_post": "Blog posts",
+ "tagarea_user": "User interests",
"tags": "Tags"
}
diff --git a/src/core/user/components/components.module.ts b/src/core/user/components/components.module.ts
index 7e7427c17..e741ad964 100644
--- a/src/core/user/components/components.module.ts
+++ b/src/core/user/components/components.module.ts
@@ -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 {}
diff --git a/src/core/user/components/tag-area/core-user-tag-area.html b/src/core/user/components/tag-area/core-user-tag-area.html
new file mode 100644
index 000000000..8ca11b857
--- /dev/null
+++ b/src/core/user/components/tag-area/core-user-tag-area.html
@@ -0,0 +1,4 @@
+
+
+ {{ item.fullname }}
+
diff --git a/src/core/user/components/tag-area/tag-area.ts b/src/core/user/components/tag-area/tag-area.ts
new file mode 100644
index 000000000..8c4f01612
--- /dev/null
+++ b/src/core/user/components/tag-area/tag-area.ts
@@ -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.
+}
diff --git a/src/core/user/providers/tag-area-handler.ts b/src/core/user/providers/tag-area-handler.ts
new file mode 100644
index 000000000..ab2d167cf
--- /dev/null
+++ b/src/core/user/providers/tag-area-handler.ts
@@ -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} Whether or not the handler is enabled on a site level.
+ */
+ isEnabled(): boolean | Promise {
+ return true;
+ }
+
+ /**
+ * Parses the rendered content of a tag index and returns the items.
+ *
+ * @param {string} content Rendered content.
+ * @return {any[]|Promise} Area items (or promise resolved with the items).
+ */
+ parseContent(content: string): any[] | Promise {
+ 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} The component (or promise resolved with component) to use, undefined if not found.
+ */
+ getComponent(injector: Injector): any | Promise {
+ return CoreUserTagAreaComponent;
+ }
+}
diff --git a/src/core/user/user.module.ts b/src/core/user/user.module.ts
index 845f2179e..0370243a6 100644
--- a/src/core/user/user.module.ts
+++ b/src/core/user/user.module.ts
@@ -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.