MOBILE-3807 core: Add some delegates to user menu
parent
81fdd00902
commit
806e29ce10
|
@ -16,7 +16,7 @@ import { Injectable } from '@angular/core';
|
||||||
import { CoreBlockHandlerData } from '@features/block/services/block-delegate';
|
import { CoreBlockHandlerData } from '@features/block/services/block-delegate';
|
||||||
import { CoreBlockOnlyTitleComponent } from '@features/block/components/only-title-block/only-title-block';
|
import { CoreBlockOnlyTitleComponent } from '@features/block/components/only-title-block/only-title-block';
|
||||||
import { CoreBlockBaseHandler } from '@features/block/classes/base-block-handler';
|
import { CoreBlockBaseHandler } from '@features/block/classes/base-block-handler';
|
||||||
import { AddonPrivateFilesMainMenuHandlerService } from '@/addons/privatefiles/services/handlers/mainmenu';
|
import { AddonPrivateFilesUserHandlerService } from '@addons/privatefiles/services/handlers/user';
|
||||||
import { makeSingleton } from '@singletons';
|
import { makeSingleton } from '@singletons';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -39,7 +39,7 @@ export class AddonBlockPrivateFilesHandlerService extends CoreBlockBaseHandler {
|
||||||
title: 'addon.block_privatefiles.pluginname',
|
title: 'addon.block_privatefiles.pluginname',
|
||||||
class: 'addon-block-private-files',
|
class: 'addon-block-private-files',
|
||||||
component: CoreBlockOnlyTitleComponent,
|
component: CoreBlockOnlyTitleComponent,
|
||||||
link: AddonPrivateFilesMainMenuHandlerService.PAGE_NAME,
|
link: AddonPrivateFilesUserHandlerService.PAGE_NAME,
|
||||||
linkParams: { root: 'my' },
|
linkParams: { root: 'my' },
|
||||||
navOptions: {
|
navOptions: {
|
||||||
preferCurrentTab: false,
|
preferCurrentTab: false,
|
||||||
|
|
|
@ -16,14 +16,14 @@ import { Injector, NgModule } from '@angular/core';
|
||||||
import { RouterModule, ROUTES, Routes } from '@angular/router';
|
import { RouterModule, ROUTES, Routes } from '@angular/router';
|
||||||
|
|
||||||
import { buildTabMainRoutes } from '@features/mainmenu/mainmenu-tab-routing.module';
|
import { buildTabMainRoutes } from '@features/mainmenu/mainmenu-tab-routing.module';
|
||||||
import { AddonPrivateFilesMainMenuHandlerService } from './services/handlers/mainmenu';
|
import { AddonPrivateFilesUserHandlerService } from './services/handlers/user';
|
||||||
|
|
||||||
function buildRoutes(injector: Injector): Routes {
|
function buildRoutes(injector: Injector): Routes {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
path: 'root',
|
path: 'root',
|
||||||
data: {
|
data: {
|
||||||
mainMenuTabRoot: AddonPrivateFilesMainMenuHandlerService.PAGE_NAME,
|
mainMenuTabRoot: AddonPrivateFilesUserHandlerService.PAGE_NAME,
|
||||||
},
|
},
|
||||||
loadChildren: () => import('./pages/index/index.module').then(m => m.AddonPrivateFilesIndexPageModule),
|
loadChildren: () => import('./pages/index/index.module').then(m => m.AddonPrivateFilesIndexPageModule),
|
||||||
},
|
},
|
||||||
|
|
|
@ -15,12 +15,12 @@
|
||||||
import { APP_INITIALIZER, NgModule, Type } from '@angular/core';
|
import { APP_INITIALIZER, NgModule, Type } from '@angular/core';
|
||||||
import { Routes } from '@angular/router';
|
import { Routes } from '@angular/router';
|
||||||
|
|
||||||
import { CoreMainMenuDelegate } from '@features/mainmenu/services/mainmenu-delegate';
|
|
||||||
import { CoreMainMenuRoutingModule } from '@features/mainmenu/mainmenu-routing.module';
|
import { CoreMainMenuRoutingModule } from '@features/mainmenu/mainmenu-routing.module';
|
||||||
import { AddonPrivateFilesMainMenuHandler, AddonPrivateFilesMainMenuHandlerService } from './services/handlers/mainmenu';
|
|
||||||
import { CoreMainMenuTabRoutingModule } from '@features/mainmenu/mainmenu-tab-routing.module';
|
import { CoreMainMenuTabRoutingModule } from '@features/mainmenu/mainmenu-tab-routing.module';
|
||||||
import { AddonPrivateFilesProvider } from './services/privatefiles';
|
import { AddonPrivateFilesProvider } from './services/privatefiles';
|
||||||
import { AddonPrivateFilesHelperProvider } from './services/privatefiles-helper';
|
import { AddonPrivateFilesHelperProvider } from './services/privatefiles-helper';
|
||||||
|
import { CoreUserDelegate } from '@features/user/services/user-delegate';
|
||||||
|
import { AddonPrivateFilesUserHandler, AddonPrivateFilesUserHandlerService } from './services/handlers/user';
|
||||||
|
|
||||||
export const ADDON_PRIVATEFILES_SERVICES: Type<unknown>[] = [
|
export const ADDON_PRIVATEFILES_SERVICES: Type<unknown>[] = [
|
||||||
AddonPrivateFilesProvider,
|
AddonPrivateFilesProvider,
|
||||||
|
@ -29,7 +29,7 @@ export const ADDON_PRIVATEFILES_SERVICES: Type<unknown>[] = [
|
||||||
|
|
||||||
const routes: Routes = [
|
const routes: Routes = [
|
||||||
{
|
{
|
||||||
path: AddonPrivateFilesMainMenuHandlerService.PAGE_NAME,
|
path: AddonPrivateFilesUserHandlerService.PAGE_NAME,
|
||||||
loadChildren: () => import('@/addons/privatefiles/privatefiles-lazy.module').then(m => m.AddonPrivateFilesLazyModule),
|
loadChildren: () => import('@/addons/privatefiles/privatefiles-lazy.module').then(m => m.AddonPrivateFilesLazyModule),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
@ -45,7 +45,7 @@ const routes: Routes = [
|
||||||
provide: APP_INITIALIZER,
|
provide: APP_INITIALIZER,
|
||||||
multi: true,
|
multi: true,
|
||||||
useValue: () => {
|
useValue: () => {
|
||||||
CoreMainMenuDelegate.registerHandler(AddonPrivateFilesMainMenuHandler.instance);
|
CoreUserDelegate.registerHandler(AddonPrivateFilesUserHandler.instance);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
|
@ -14,44 +14,57 @@
|
||||||
|
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
import { CoreMainMenuHandler, CoreMainMenuHandlerData } from '@features/mainmenu/services/mainmenu-delegate';
|
|
||||||
import { AddonPrivateFiles } from '@/addons/privatefiles/services/privatefiles';
|
import { AddonPrivateFiles } from '@/addons/privatefiles/services/privatefiles';
|
||||||
import { makeSingleton } from '@singletons';
|
import { makeSingleton } from '@singletons';
|
||||||
|
import { CoreUserDelegateService, CoreUserProfileHandler, CoreUserProfileHandlerData } from '@features/user/services/user-delegate';
|
||||||
|
import { CoreUserProfile } from '@features/user/services/user';
|
||||||
|
import { CoreNavigator } from '@services/navigator';
|
||||||
|
import { CoreSites } from '@services/sites';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler to inject an option into main menu.
|
* Handler to inject an option into user menu.
|
||||||
*/
|
*/
|
||||||
@Injectable({ providedIn: 'root' })
|
@Injectable({ providedIn: 'root' })
|
||||||
export class AddonPrivateFilesMainMenuHandlerService implements CoreMainMenuHandler {
|
export class AddonPrivateFilesUserHandlerService implements CoreUserProfileHandler {
|
||||||
|
|
||||||
static readonly PAGE_NAME = 'private';
|
static readonly PAGE_NAME = 'private';
|
||||||
|
|
||||||
name = 'AddonPrivateFiles';
|
name = 'AddonPrivateFiles';
|
||||||
priority = 400;
|
priority = 300;
|
||||||
|
type = CoreUserDelegateService.TYPE_NEW_PAGE;
|
||||||
|
cacheEnabled = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the handler is enabled on a site level.
|
* @inheritdoc
|
||||||
*
|
|
||||||
* @return Whether or not the handler is enabled on a site level.
|
|
||||||
*/
|
*/
|
||||||
async isEnabled(): Promise<boolean> {
|
async isEnabled(): Promise<boolean> {
|
||||||
return AddonPrivateFiles.isPluginEnabled();
|
return AddonPrivateFiles.isPluginEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the data needed to render the handler.
|
* @inheritdoc
|
||||||
*
|
|
||||||
* @return Data needed to render the handler.
|
|
||||||
*/
|
*/
|
||||||
getDisplayData(): CoreMainMenuHandlerData {
|
async isEnabledForUser(user: CoreUserProfile): Promise<boolean> {
|
||||||
|
// Private files only available for the current user.
|
||||||
|
return user.id == CoreSites.getCurrentSiteUserId();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
getDisplayData(): CoreUserProfileHandlerData {
|
||||||
return {
|
return {
|
||||||
icon: 'fas-folder',
|
icon: 'fas-folder',
|
||||||
title: 'addon.privatefiles.files',
|
title: 'addon.privatefiles.files',
|
||||||
page: AddonPrivateFilesMainMenuHandlerService.PAGE_NAME,
|
|
||||||
class: 'addon-privatefiles-handler',
|
class: 'addon-privatefiles-handler',
|
||||||
|
action: (event): void => {
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
CoreNavigator.navigateToSitePath(AddonPrivateFilesUserHandlerService.PAGE_NAME);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const AddonPrivateFilesMainMenuHandler = makeSingleton(AddonPrivateFilesMainMenuHandlerService);
|
export const AddonPrivateFilesUserHandler = makeSingleton(AddonPrivateFilesUserHandlerService);
|
|
@ -23,13 +23,13 @@ import { CoreGradesCoursePage } from './pages/course/course.page';
|
||||||
import { CoreGradesCoursePageModule } from './pages/course/course.module';
|
import { CoreGradesCoursePageModule } from './pages/course/course.module';
|
||||||
import { CoreGradesCoursesPage } from './pages/courses/courses.page';
|
import { CoreGradesCoursesPage } from './pages/courses/courses.page';
|
||||||
import { CoreGradesGradePage } from './pages/grade/grade.page';
|
import { CoreGradesGradePage } from './pages/grade/grade.page';
|
||||||
import { CoreGradesMainMenuHandlerService } from './services/handlers/mainmenu';
|
import { CoreGradesUserHandlerService } from './services/handlers/user';
|
||||||
|
|
||||||
const mobileRoutes: Routes = [
|
const mobileRoutes: Routes = [
|
||||||
{
|
{
|
||||||
path: '',
|
path: '',
|
||||||
data: {
|
data: {
|
||||||
mainMenuTabRoot: CoreGradesMainMenuHandlerService.PAGE_NAME,
|
mainMenuTabRoot: CoreGradesUserHandlerService.PAGE_NAME,
|
||||||
},
|
},
|
||||||
component: CoreGradesCoursesPage,
|
component: CoreGradesCoursesPage,
|
||||||
},
|
},
|
||||||
|
@ -47,7 +47,7 @@ const tabletRoutes: Routes = [
|
||||||
{
|
{
|
||||||
path: '',
|
path: '',
|
||||||
data: {
|
data: {
|
||||||
mainMenuTabRoot: CoreGradesMainMenuHandlerService.PAGE_NAME,
|
mainMenuTabRoot: CoreGradesUserHandlerService.PAGE_NAME,
|
||||||
},
|
},
|
||||||
component: CoreGradesCoursesPage,
|
component: CoreGradesCoursesPage,
|
||||||
children: [
|
children: [
|
||||||
|
|
|
@ -19,14 +19,12 @@ import { CoreCourseIndexRoutingModule } from '@features/course/pages/index/index
|
||||||
import { CoreCourseOptionsDelegate } from '@features/course/services/course-options-delegate';
|
import { CoreCourseOptionsDelegate } from '@features/course/services/course-options-delegate';
|
||||||
import { CoreMainMenuRoutingModule } from '@features/mainmenu/mainmenu-routing.module';
|
import { CoreMainMenuRoutingModule } from '@features/mainmenu/mainmenu-routing.module';
|
||||||
import { CoreMainMenuTabRoutingModule } from '@features/mainmenu/mainmenu-tab-routing.module';
|
import { CoreMainMenuTabRoutingModule } from '@features/mainmenu/mainmenu-tab-routing.module';
|
||||||
import { CoreMainMenuDelegate } from '@features/mainmenu/services/mainmenu-delegate';
|
|
||||||
import { CoreUserDelegate } from '@features/user/services/user-delegate';
|
import { CoreUserDelegate } from '@features/user/services/user-delegate';
|
||||||
import { CoreGradesProvider } from './services/grades';
|
import { CoreGradesProvider } from './services/grades';
|
||||||
import { CoreGradesHelperProvider } from './services/grades-helper';
|
import { CoreGradesHelperProvider } from './services/grades-helper';
|
||||||
import { CoreGradesCourseOptionHandler } from './services/handlers/course-option';
|
import { CoreGradesCourseOptionHandler } from './services/handlers/course-option';
|
||||||
import { CoreGradesMainMenuHandler, CoreGradesMainMenuHandlerService } from './services/handlers/mainmenu';
|
|
||||||
import { CoreGradesOverviewLinkHandler } from './services/handlers/overview-link';
|
import { CoreGradesOverviewLinkHandler } from './services/handlers/overview-link';
|
||||||
import { CoreGradesUserHandler } from './services/handlers/user';
|
import { CoreGradesUserHandler, CoreGradesUserHandlerService } from './services/handlers/user';
|
||||||
import { CoreGradesUserLinkHandler } from './services/handlers/user-link';
|
import { CoreGradesUserLinkHandler } from './services/handlers/user-link';
|
||||||
|
|
||||||
export const CORE_GRADES_SERVICES: Type<unknown>[] = [
|
export const CORE_GRADES_SERVICES: Type<unknown>[] = [
|
||||||
|
@ -36,7 +34,7 @@ export const CORE_GRADES_SERVICES: Type<unknown>[] = [
|
||||||
|
|
||||||
const routes: Routes = [
|
const routes: Routes = [
|
||||||
{
|
{
|
||||||
path: CoreGradesMainMenuHandlerService.PAGE_NAME,
|
path: CoreGradesUserHandlerService.PAGE_NAME,
|
||||||
loadChildren: () => import('@features/grades/grades-lazy.module').then(m => m.CoreGradesLazyModule),
|
loadChildren: () => import('@features/grades/grades-lazy.module').then(m => m.CoreGradesLazyModule),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -63,7 +61,6 @@ const courseIndexRoutes: Routes = [
|
||||||
provide: APP_INITIALIZER,
|
provide: APP_INITIALIZER,
|
||||||
multi: true,
|
multi: true,
|
||||||
useValue: () => {
|
useValue: () => {
|
||||||
CoreMainMenuDelegate.registerHandler(CoreGradesMainMenuHandler.instance);
|
|
||||||
CoreUserDelegate.registerHandler(CoreGradesUserHandler.instance);
|
CoreUserDelegate.registerHandler(CoreGradesUserHandler.instance);
|
||||||
CoreContentLinksDelegate.registerHandler(CoreGradesUserLinkHandler.instance);
|
CoreContentLinksDelegate.registerHandler(CoreGradesUserLinkHandler.instance);
|
||||||
CoreContentLinksDelegate.registerHandler(CoreGradesOverviewLinkHandler.instance);
|
CoreContentLinksDelegate.registerHandler(CoreGradesOverviewLinkHandler.instance);
|
||||||
|
|
|
@ -1,56 +0,0 @@
|
||||||
// (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 { CoreGrades } from '@features/grades/services/grades';
|
|
||||||
import { CoreMainMenuHandler, CoreMainMenuHandlerData } from '@features/mainmenu/services/mainmenu-delegate';
|
|
||||||
import { makeSingleton } from '@singletons';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handler to inject an option into main menu.
|
|
||||||
*/
|
|
||||||
@Injectable({ providedIn: 'root' })
|
|
||||||
export class CoreGradesMainMenuHandlerService implements CoreMainMenuHandler {
|
|
||||||
|
|
||||||
static readonly PAGE_NAME = 'grades';
|
|
||||||
|
|
||||||
name = 'CoreGrades';
|
|
||||||
priority = 600;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if the handler is enabled on a site level.
|
|
||||||
*
|
|
||||||
* @return Whether or not the handler is enabled on a site level.
|
|
||||||
*/
|
|
||||||
isEnabled(): Promise<boolean> {
|
|
||||||
return CoreGrades.isCourseGradesEnabled();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the data needed to render the handler.
|
|
||||||
*
|
|
||||||
* @return Data needed to render the handler.
|
|
||||||
*/
|
|
||||||
getDisplayData(): CoreMainMenuHandlerData {
|
|
||||||
return {
|
|
||||||
icon: 'fas-chart-bar',
|
|
||||||
title: 'core.grades.grades',
|
|
||||||
page: CoreGradesMainMenuHandlerService.PAGE_NAME,
|
|
||||||
class: 'core-grades-coursesgrades-handler',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export const CoreGradesMainMenuHandler = makeSingleton(CoreGradesMainMenuHandlerService);
|
|
|
@ -22,6 +22,7 @@ import {
|
||||||
CoreUserProfileHandlerData,
|
CoreUserProfileHandlerData,
|
||||||
} from '@features/user/services/user-delegate';
|
} from '@features/user/services/user-delegate';
|
||||||
import { CoreNavigator } from '@services/navigator';
|
import { CoreNavigator } from '@services/navigator';
|
||||||
|
import { CoreSites } from '@services/sites';
|
||||||
import { CoreUtils } from '@services/utils/utils';
|
import { CoreUtils } from '@services/utils/utils';
|
||||||
import { makeSingleton } from '@singletons';
|
import { makeSingleton } from '@singletons';
|
||||||
|
|
||||||
|
@ -31,6 +32,8 @@ import { makeSingleton } from '@singletons';
|
||||||
@Injectable({ providedIn: 'root' })
|
@Injectable({ providedIn: 'root' })
|
||||||
export class CoreGradesUserHandlerService implements CoreUserProfileHandler {
|
export class CoreGradesUserHandlerService implements CoreUserProfileHandler {
|
||||||
|
|
||||||
|
static readonly PAGE_NAME = 'grades';
|
||||||
|
|
||||||
name = 'CoreGrades:viewGrades';
|
name = 'CoreGrades:viewGrades';
|
||||||
priority = 400;
|
priority = 400;
|
||||||
type = CoreUserDelegateService.TYPE_NEW_PAGE;
|
type = CoreUserDelegateService.TYPE_NEW_PAGE;
|
||||||
|
@ -47,32 +50,54 @@ export class CoreGradesUserHandlerService implements CoreUserProfileHandler {
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
async isEnabledForCourse(courseId?: number): Promise<boolean> {
|
async isEnabledForCourse(courseId?: number): Promise<boolean> {
|
||||||
return CoreUtils.ignoreErrors(CoreGrades.isPluginEnabledForCourse(courseId), false);
|
if (courseId) {
|
||||||
|
return CoreUtils.ignoreErrors(CoreGrades.isPluginEnabledForCourse(courseId), false);
|
||||||
|
} else {
|
||||||
|
return CoreGrades.isCourseGradesEnabled();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
async isEnabledForUser(user: CoreUserProfile, courseId?: number): Promise<boolean> {
|
async isEnabledForUser(user: CoreUserProfile, courseId?: number): Promise<boolean> {
|
||||||
return CoreUtils.promiseWorks(CoreGrades.getCourseGradesTable(courseId!, user.id));
|
if (courseId) {
|
||||||
|
return CoreUtils.promiseWorks(CoreGrades.getCourseGradesTable(courseId, user.id));
|
||||||
|
}
|
||||||
|
|
||||||
|
// All course grades only available for the current user.
|
||||||
|
return user.id == CoreSites.getCurrentSiteUserId();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
getDisplayData(): CoreUserProfileHandlerData {
|
getDisplayData(user: CoreUserProfile, courseId?: number): CoreUserProfileHandlerData {
|
||||||
return {
|
if (courseId) {
|
||||||
icon: 'fas-chart-bar',
|
return {
|
||||||
title: 'core.grades.grades',
|
icon: 'fas-chart-bar',
|
||||||
class: 'core-grades-user-handler',
|
title: 'core.grades.grades',
|
||||||
action: (event, user, courseId): void => {
|
class: 'core-grades-user-handler',
|
||||||
event.preventDefault();
|
action: (event, user, courseId): void => {
|
||||||
event.stopPropagation();
|
event.preventDefault();
|
||||||
CoreNavigator.navigateToSitePath(`/user-grades/${courseId}`, {
|
event.stopPropagation();
|
||||||
params: { userId: user.id },
|
CoreNavigator.navigateToSitePath(`/user-grades/${courseId}`, {
|
||||||
});
|
params: { userId: user.id },
|
||||||
},
|
});
|
||||||
};
|
},
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
icon: 'fas-chart-bar',
|
||||||
|
title: 'core.grades.grades',
|
||||||
|
class: 'core-grades-coursesgrades-handler',
|
||||||
|
action: (event): void => {
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
CoreNavigator.navigateToSitePath(CoreGradesUserHandlerService.PAGE_NAME);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue