MOBILE-3592 user: Implement profile link and mail handlers
parent
a783a89db3
commit
dbec10b9d6
|
@ -275,7 +275,7 @@ export class CoreUserProfilePage implements OnInit, OnDestroy {
|
||||||
*/
|
*/
|
||||||
handlerClicked(event: Event, handler: CoreUserProfileHandlerData): void {
|
handlerClicked(event: Event, handler: CoreUserProfileHandlerData): void {
|
||||||
// @todo: Pass the right navCtrl if this page is in the right pane of split view.
|
// @todo: Pass the right navCtrl if this page is in the right pane of split view.
|
||||||
handler.action(event, this.navCtrl, this.user!, this.courseId);
|
handler.action(event, this.user!, this.courseId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -0,0 +1,76 @@
|
||||||
|
// (C) Copyright 2015 Moodle Pty Ltd.
|
||||||
|
//
|
||||||
|
// 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 { Params } from '@angular/router';
|
||||||
|
|
||||||
|
import { CoreContentLinksHandlerBase } from '@features/contentlinks/classes/base-handler';
|
||||||
|
import { CoreContentLinksAction } from '@features/contentlinks/services/contentlinks-delegate';
|
||||||
|
import { CoreContentLinksHelper } from '@features/contentlinks/services/contentlinks-helper';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handler to treat links to user profiles.
|
||||||
|
*/
|
||||||
|
@Injectable({ providedIn: 'root' })
|
||||||
|
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+)/;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the list of actions for a link (url).
|
||||||
|
*
|
||||||
|
* @param siteIds List of sites the URL belongs to.
|
||||||
|
* @param url The URL to treat.
|
||||||
|
* @param params The params of the URL. E.g. 'mysite.com?id=1' -> {id: 1}
|
||||||
|
* @param courseId Course ID related to the URL. Optional but recommended.
|
||||||
|
* @param data Extra data to handle the URL.
|
||||||
|
* @return List of (or promise resolved with list of) actions.
|
||||||
|
*/
|
||||||
|
getActions(
|
||||||
|
siteIds: string[],
|
||||||
|
url: string,
|
||||||
|
params: Params,
|
||||||
|
courseId?: number, // eslint-disable-line @typescript-eslint/no-unused-vars
|
||||||
|
data?: unknown, // eslint-disable-line @typescript-eslint/no-unused-vars
|
||||||
|
): CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> {
|
||||||
|
return [{
|
||||||
|
action: (siteId): void => {
|
||||||
|
const pageParams = {
|
||||||
|
courseId: params.course,
|
||||||
|
userId: parseInt(params.id, 10),
|
||||||
|
};
|
||||||
|
|
||||||
|
CoreContentLinksHelper.instance.goInSite('/user', pageParams, siteId);
|
||||||
|
},
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the handler is enabled for a certain site (site + user) and a URL.
|
||||||
|
* If not defined, defaults to true.
|
||||||
|
*
|
||||||
|
* @param siteId The site ID.
|
||||||
|
* @param url The URL to treat.
|
||||||
|
* @param params The params of the URL. E.g. 'mysite.com?id=1' -> {id: 1}
|
||||||
|
* @param courseId Course ID related to the URL. Optional but recommended.
|
||||||
|
* @return Whether the handler is enabled for the URL and site.
|
||||||
|
*/
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
isEnabled(siteId: string, url: string, params: Params, courseId?: number): boolean | Promise<boolean> {
|
||||||
|
return url.indexOf('/grade/report/') == -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,75 @@
|
||||||
|
// (C) Copyright 2015 Moodle Pty Ltd.
|
||||||
|
//
|
||||||
|
// 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 { CoreUserDelegate, CoreUserProfileHandler, CoreUserProfileHandlerData } from '../user-delegate';
|
||||||
|
import { CoreSites } from '@services/sites';
|
||||||
|
import { CoreUtils } from '@services/utils/utils';
|
||||||
|
import { CoreUserProfile } from '../user';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handler to send a email to a user.
|
||||||
|
*/
|
||||||
|
@Injectable({ providedIn: 'root' })
|
||||||
|
export class CoreUserProfileMailHandler implements CoreUserProfileHandler {
|
||||||
|
|
||||||
|
name = 'CoreUserProfileMail';
|
||||||
|
priority = 700;
|
||||||
|
type = CoreUserDelegate.TYPE_COMMUNICATION;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if handler is enabled.
|
||||||
|
*
|
||||||
|
* @return Always enabled.
|
||||||
|
*/
|
||||||
|
async isEnabled(): Promise<boolean> {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if handler is enabled for this user in this context.
|
||||||
|
*
|
||||||
|
* @param user User to check.
|
||||||
|
* @param courseId Course ID.
|
||||||
|
* @param navOptions Course navigation options for current user. See CoreCoursesProvider.getUserNavigationOptions.
|
||||||
|
* @param admOptions Course admin options for current user. See CoreCoursesProvider.getUserAdministrationOptions.
|
||||||
|
* @return Promise resolved with true if enabled, resolved with false otherwise.
|
||||||
|
*/
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
async isEnabledForUser(user: CoreUserProfile, courseId: number, navOptions?: unknown, admOptions?: unknown): Promise<boolean> {
|
||||||
|
return user.id != CoreSites.instance.getCurrentSiteUserId() && !!user.email;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the data needed to render the handler.
|
||||||
|
*
|
||||||
|
* @return Data needed to render the handler.
|
||||||
|
*/
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
getDisplayData(user: CoreUserProfile, courseId: number): CoreUserProfileHandlerData {
|
||||||
|
return {
|
||||||
|
icon: 'mail',
|
||||||
|
title: 'core.user.sendemail',
|
||||||
|
class: 'core-user-profile-mail',
|
||||||
|
action: (event: Event, user: CoreUserProfile): void => {
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
|
||||||
|
CoreUtils.instance.openInBrowser('mailto:' + user.email);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -13,7 +13,6 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { NavController } from '@ionic/angular';
|
|
||||||
import { Subject, BehaviorSubject } from 'rxjs';
|
import { Subject, BehaviorSubject } from 'rxjs';
|
||||||
|
|
||||||
import { CoreDelegate, CoreDelegateHandler } from '@classes/delegate';
|
import { CoreDelegate, CoreDelegateHandler } from '@classes/delegate';
|
||||||
|
@ -93,11 +92,10 @@ export interface CoreUserProfileHandlerData {
|
||||||
* Action to do when clicked.
|
* Action to do when clicked.
|
||||||
*
|
*
|
||||||
* @param event Click event.
|
* @param event Click event.
|
||||||
* @param Nav controller to use to navigate.
|
|
||||||
* @param user User object.
|
* @param user User object.
|
||||||
* @param courseId Course ID being viewed. If not defined, site context.
|
* @param courseId Course ID being viewed. If not defined, site context.
|
||||||
*/
|
*/
|
||||||
action(event: Event, navCtrl: NavController, user: CoreUserProfile, courseId?: number): void;
|
action(event: Event, user: CoreUserProfile, courseId?: number): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -12,13 +12,17 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
import { NgModule } from '@angular/core';
|
import { APP_INITIALIZER, NgModule } from '@angular/core';
|
||||||
import { Routes } from '@angular/router';
|
import { Routes } from '@angular/router';
|
||||||
|
|
||||||
import { CoreMainMenuMoreRoutingModule } from '@features/mainmenu/pages/more/more-routing.module';
|
import { CoreMainMenuMoreRoutingModule } from '@features/mainmenu/pages/more/more-routing.module';
|
||||||
import { CORE_SITE_SCHEMAS } from '@services/sites';
|
import { CORE_SITE_SCHEMAS } from '@services/sites';
|
||||||
import { SITE_SCHEMA, OFFLINE_SITE_SCHEMA } from './services/db/user';
|
import { SITE_SCHEMA, OFFLINE_SITE_SCHEMA } from './services/db/user';
|
||||||
import { CoreUserComponentsModule } from './components/components.module';
|
import { CoreUserComponentsModule } from './components/components.module';
|
||||||
|
import { CoreUserDelegate } from './services/user-delegate';
|
||||||
|
import { CoreUserProfileMailHandler } from './services/handlers/profile-mail';
|
||||||
|
import { CoreContentLinksDelegate } from '@features/contentlinks/services/contentlinks-delegate';
|
||||||
|
import { CoreUserProfileLinkHandler } from './services/handlers/profile-link';
|
||||||
|
|
||||||
const routes: Routes = [
|
const routes: Routes = [
|
||||||
{
|
{
|
||||||
|
@ -41,13 +45,22 @@ const routes: Routes = [
|
||||||
],
|
],
|
||||||
multi: true,
|
multi: true,
|
||||||
},
|
},
|
||||||
// { @todo: Uncomment when the init process has been fixed.
|
{
|
||||||
// provide: APP_INITIALIZER,
|
provide: APP_INITIALIZER,
|
||||||
// multi: true,
|
multi: true,
|
||||||
// deps: [CoreCronDelegate, CoreUserSyncCronHandler],
|
deps: [CoreUserDelegate, CoreUserProfileMailHandler, CoreContentLinksDelegate, CoreUserProfileLinkHandler],
|
||||||
// useFactory: (cronDelegate: CoreCronDelegate, syncHandler: CoreUserSyncCronHandler) =>
|
useFactory: (
|
||||||
// () => cronDelegate.register(syncHandler),
|
userDelegate: CoreUserDelegate,
|
||||||
// },
|
mailHandler: CoreUserProfileMailHandler,
|
||||||
|
linksDelegate: CoreContentLinksDelegate,
|
||||||
|
profileLinkHandler: CoreUserProfileLinkHandler,
|
||||||
|
|
||||||
|
) => () => {
|
||||||
|
// @todo: Register sync handler when init process has been fixed.
|
||||||
|
userDelegate.registerHandler(mailHandler);
|
||||||
|
linksDelegate.registerHandler(profileLinkHandler);
|
||||||
|
},
|
||||||
|
},
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class CoreUserModule {}
|
export class CoreUserModule {}
|
||||||
|
|
Loading…
Reference in New Issue