From 02c2a5e508d915deae6813d58fe26eba92dae328 Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Thu, 17 Mar 2022 15:40:14 +0100 Subject: [PATCH 1/4] MOBILE-3833 feedback: Fix attempts pagination --- .../mod/feedback/classes/feedback-attempts-source.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/addons/mod/feedback/classes/feedback-attempts-source.ts b/src/addons/mod/feedback/classes/feedback-attempts-source.ts index 4ef92a857..62410098d 100644 --- a/src/addons/mod/feedback/classes/feedback-attempts-source.ts +++ b/src/addons/mod/feedback/classes/feedback-attempts-source.ts @@ -135,8 +135,14 @@ export class AddonModFeedbackAttemptsSource extends CoreRoutedItemsManagerSource const totalItemsLoaded = this.getPageLength() * (page + 1); const pageAttempts: AddonModFeedbackAttemptItem[] = [ - ...result.attempts, - ...result.anonattempts, + // The page argument is ignored in the webservice when there is only one page, + // so we should ignore the responses of pages beyond the first if that's the case. + ...(page === 0 || result.totalattempts > AddonModFeedbackProvider.PER_PAGE) + ? result.attempts + : [], + ...(page === 0 || result.totalanonattempts > AddonModFeedbackProvider.PER_PAGE) + ? result.anonattempts + : [], ]; return { From 67fd2a23b16f8063f4235c4fc6e47bf5554cee39 Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Thu, 17 Mar 2022 16:13:43 +0100 Subject: [PATCH 2/4] MOBILE-3833 messages: Fix route conflicts --- src/addons/messages/messages-lazy.module.ts | 2 +- .../pages/group-conversations/group-conversations.page.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/addons/messages/messages-lazy.module.ts b/src/addons/messages/messages-lazy.module.ts index 061f8f1e1..47a4d5d15 100644 --- a/src/addons/messages/messages-lazy.module.ts +++ b/src/addons/messages/messages-lazy.module.ts @@ -52,7 +52,7 @@ function buildRoutes(injector: Injector): Routes { .then(m => m.AddonMessagesContactsPageModule), }, { - path: 'preferences', + path: 'message-settings', loadChildren: () => import('./pages/settings/settings.module').then(m => m.AddonMessagesSettingsPageModule), }, ...buildTabMainRoutes(injector, { diff --git a/src/addons/messages/pages/group-conversations/group-conversations.page.ts b/src/addons/messages/pages/group-conversations/group-conversations.page.ts index f2d572663..73ff7d7e1 100644 --- a/src/addons/messages/pages/group-conversations/group-conversations.page.ts +++ b/src/addons/messages/pages/group-conversations/group-conversations.page.ts @@ -538,7 +538,7 @@ export class AddonMessagesGroupConversationsPage implements OnInit, OnDestroy { * Navigate to message settings. */ gotoSettings(): void { - CoreNavigator.navigateToSitePath('../preferences'); + CoreNavigator.navigateToSitePath('../message-settings'); } /** From a11ca3726b7365b0f37ed56a1c63a9f5875529a5 Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Thu, 17 Mar 2022 16:14:01 +0100 Subject: [PATCH 3/4] MOBILE-3833 calendar: Fix route conflicts --- src/addons/calendar/calendar-lazy.module.ts | 2 +- src/addons/calendar/pages/index/index.page.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/addons/calendar/calendar-lazy.module.ts b/src/addons/calendar/calendar-lazy.module.ts index d675bf134..c01e053cc 100644 --- a/src/addons/calendar/calendar-lazy.module.ts +++ b/src/addons/calendar/calendar-lazy.module.ts @@ -28,7 +28,7 @@ function buildRoutes(injector: Injector): Routes { loadChildren: () => import('@addons/calendar/pages/index/index.module').then(m => m.AddonCalendarIndexPageModule), }, { - path: 'settings', + path: 'calendar-settings', loadChildren: () => import('@addons/calendar/pages/settings/settings.module').then(m => m.AddonCalendarSettingsPageModule), }, diff --git a/src/addons/calendar/pages/index/index.page.ts b/src/addons/calendar/pages/index/index.page.ts index c0ac2fb1c..9b9fd080b 100644 --- a/src/addons/calendar/pages/index/index.page.ts +++ b/src/addons/calendar/pages/index/index.page.ts @@ -360,7 +360,7 @@ export class AddonCalendarIndexPage implements OnInit, OnDestroy { * Open calendar events settings. */ openSettings(): void { - CoreNavigator.navigateToSitePath('/calendar/settings'); + CoreNavigator.navigateToSitePath('/calendar/calendar-settings'); } /** From 8ccd5aae81ee02b67fb3c8c4a1f8030ed01f68cd Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Thu, 17 Mar 2022 17:06:49 +0100 Subject: [PATCH 4/4] MOBILE-3833 grades: Support additional link --- src/core/features/grades/grades.module.ts | 2 + .../grades/services/handlers/report-link.ts | 82 +++++++++++++++++++ .../grades/services/handlers/user-link.ts | 4 +- 3 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 src/core/features/grades/services/handlers/report-link.ts diff --git a/src/core/features/grades/grades.module.ts b/src/core/features/grades/grades.module.ts index 8935c6ee8..9b6ae6251 100644 --- a/src/core/features/grades/grades.module.ts +++ b/src/core/features/grades/grades.module.ts @@ -26,6 +26,7 @@ import { CoreGradesHelperProvider, GRADES_PAGE_NAME } from './services/grades-he import { CoreGradesCourseOptionHandler } from './services/handlers/course-option'; import { CoreGradesOverviewLinkHandler } from './services/handlers/overview-link'; import { CoreGradesUserHandler } from './services/handlers/user'; +import { CoreGradesReportLinkHandler } from './services/handlers/report-link'; import { CoreGradesUserLinkHandler } from './services/handlers/user-link'; export const CORE_GRADES_SERVICES: Type[] = [ @@ -62,6 +63,7 @@ const courseIndexRoutes: Routes = [ multi: true, useValue: () => { CoreUserDelegate.registerHandler(CoreGradesUserHandler.instance); + CoreContentLinksDelegate.registerHandler(CoreGradesReportLinkHandler.instance); CoreContentLinksDelegate.registerHandler(CoreGradesUserLinkHandler.instance); CoreContentLinksDelegate.registerHandler(CoreGradesOverviewLinkHandler.instance); CoreCourseOptionsDelegate.registerHandler(CoreGradesCourseOptionHandler.instance); diff --git a/src/core/features/grades/services/handlers/report-link.ts b/src/core/features/grades/services/handlers/report-link.ts new file mode 100644 index 000000000..1efed0df7 --- /dev/null +++ b/src/core/features/grades/services/handlers/report-link.ts @@ -0,0 +1,82 @@ +// (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 { CoreContentLinksAction } from '@features/contentlinks/services/contentlinks-delegate'; +import { CoreContentLinksHandlerBase } from '@features/contentlinks/classes/base-handler'; +import { CoreGrades } from '@features/grades/services/grades'; +import { CoreGradesHelper } from '@features/grades/services/grades-helper'; +import { makeSingleton } from '@singletons'; + +/** + * Handler to treat links to user grades. + */ +@Injectable({ providedIn: 'root' }) +export class CoreGradesReportLinkHandlerService extends CoreContentLinksHandlerBase { + + name = 'CoreGradesReportLinkHandler'; + pattern = /\/grade\/report(\/user)?\/index.php/; + + /** + * 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: Record, + courseId?: number, + data?: { cmid?: string }, + ): CoreContentLinksAction[] | Promise { + courseId = courseId || Number(params.id); + data = data || {}; + + return [{ + action: (siteId): void => { + const userId = params.userid ? parseInt(params.userid, 10) : undefined; + const moduleId = data?.cmid && parseInt(data.cmid, 10) || undefined; + + CoreGradesHelper.goToGrades(courseId!, userId, moduleId, 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. + */ + async isEnabled(siteId: string, url: string, params: Record, courseId?: number): Promise { + if (!courseId && !params.id) { + return false; + } + + return CoreGrades.isPluginEnabledForCourse(courseId || Number(params.id), siteId); + } + +} + +export const CoreGradesReportLinkHandler = makeSingleton(CoreGradesReportLinkHandlerService); diff --git a/src/core/features/grades/services/handlers/user-link.ts b/src/core/features/grades/services/handlers/user-link.ts index 432ff1937..1f1ba4008 100644 --- a/src/core/features/grades/services/handlers/user-link.ts +++ b/src/core/features/grades/services/handlers/user-link.ts @@ -27,7 +27,7 @@ import { makeSingleton } from '@singletons'; export class CoreGradesUserLinkHandlerService extends CoreContentLinksHandlerBase { name = 'CoreGradesUserLinkHandler'; - pattern = /\/grade\/report(\/user)?\/index.php/; + pattern = /\/course\/user\.php.*[?&]mode=grade/; /** * Get the list of actions for a link (url). @@ -51,7 +51,7 @@ export class CoreGradesUserLinkHandlerService extends CoreContentLinksHandlerBas return [{ action: (siteId): void => { - const userId = params.userid ? parseInt(params.userid, 10) : undefined; + const userId = params.user ? parseInt(params.user, 10) : undefined; const moduleId = data?.cmid && parseInt(data.cmid, 10) || undefined; CoreGradesHelper.goToGrades(courseId!, userId, moduleId, siteId);