diff --git a/src/core/user/providers/helper.ts b/src/core/user/providers/helper.ts
index e4d6eeb05..ba62a3f00 100644
--- a/src/core/user/providers/helper.ts
+++ b/src/core/user/providers/helper.ts
@@ -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 + " ");
}
}
diff --git a/src/core/user/providers/user-link-handler.ts b/src/core/user/providers/user-link-handler.ts
new file mode 100644
index 000000000..bd2515783
--- /dev/null
+++ b/src/core/user/providers/user-link-handler.ts
@@ -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} List of (or promise resolved with list of) actions.
+ */
+ getActions(siteIds: string[], url: string, params: any, courseId?: number) :
+ CoreContentLinksAction[]|Promise {
+ 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} Whether the handler is enabled for the URL and site.
+ */
+ isEnabled(siteId: string, url: string, params: any, courseId?: number) : boolean|Promise {
+ return url.indexOf('/grade/report/') == -1;
+ }
+}
diff --git a/src/core/user/user.module.ts b/src/core/user/user.module.ts
index 89f35804b..62fb1af70 100644
--- a/src/core/user/user.module.ts
+++ b/src/core/user/user.module.ts
@@ -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.