From 71788e83bf8f43c7c37779d7f734219e012d413d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Wed, 16 Feb 2022 21:21:33 +0100 Subject: [PATCH] MOBILE-3931 grades: Fix navigate to gradeId --- src/core/features/grades/grades.module.ts | 4 +-- .../features/grades/pages/course/course.html | 36 +------------------ .../grades/pages/course/course.page.ts | 34 +++++++++++++++--- .../features/grades/services/grades-helper.ts | 12 ++++--- src/core/features/grades/services/grades.ts | 2 +- .../grades/services/handlers/overview-link.ts | 2 +- .../features/grades/services/handlers/user.ts | 2 +- 7 files changed, 42 insertions(+), 50 deletions(-) diff --git a/src/core/features/grades/grades.module.ts b/src/core/features/grades/grades.module.ts index 6669a9161..8935c6ee8 100644 --- a/src/core/features/grades/grades.module.ts +++ b/src/core/features/grades/grades.module.ts @@ -22,7 +22,7 @@ import { CoreMainMenuTabRoutingModule } from '@features/mainmenu/mainmenu-tab-ro import { CoreUserDelegate } from '@features/user/services/user-delegate'; import { PARTICIPANTS_PAGE_NAME } from '@features/user/user.module'; import { CoreGradesProvider } from './services/grades'; -import { CoreGradesHelperProvider } from './services/grades-helper'; +import { CoreGradesHelperProvider, GRADES_PAGE_NAME } from './services/grades-helper'; import { CoreGradesCourseOptionHandler } from './services/handlers/course-option'; import { CoreGradesOverviewLinkHandler } from './services/handlers/overview-link'; import { CoreGradesUserHandler } from './services/handlers/user'; @@ -33,8 +33,6 @@ export const CORE_GRADES_SERVICES: Type[] = [ CoreGradesHelperProvider, ]; -export const GRADES_PAGE_NAME = 'grades'; - const mainMenuChildrenRoutes: Routes = [ { path: GRADES_PAGE_NAME, diff --git a/src/core/features/grades/pages/course/course.html b/src/core/features/grades/pages/course/course.html index c484de9f0..6cbbae4e4 100644 --- a/src/core/features/grades/pages/course/course.html +++ b/src/core/features/grades/pages/course/course.html @@ -31,7 +31,7 @@ [attr.tabindex]="row.expandable && showSummary && 0" [attr.aria-expanded]="row.expanded" [attr.aria-label]="rowAriaLabel(row)" [attr.aria-controls]="row.detailsid" (ariaButtonClick)="row.expandable && showSummary && toggleRow(row)" [class]="row.rowclass" - [class.core-grades-grade-clickable]="row.expandable && showSummary"> + [class.core-grades-grade-clickable]="row.expandable && showSummary" [id]="'grade-'+row.id"> @@ -71,40 +71,6 @@ - - - - - - - -

- - -

-
-
- - - - - - - - -

- - -

-
-
-

{{ 'core.grades.weight' | translate}}

diff --git a/src/core/features/grades/pages/course/course.page.ts b/src/core/features/grades/pages/course/course.page.ts index fe22fc527..22fadfa71 100644 --- a/src/core/features/grades/pages/course/course.page.ts +++ b/src/core/features/grades/pages/course/course.page.ts @@ -13,8 +13,8 @@ // limitations under the License. import { ActivatedRoute } from '@angular/router'; -import { AfterViewInit, Component, ElementRef, OnDestroy } from '@angular/core'; -import { IonRefresher } from '@ionic/angular'; +import { AfterViewInit, Component, ElementRef, OnDestroy, Optional } from '@angular/core'; +import { IonContent, IonRefresher } from '@ionic/angular'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreGrades } from '@features/grades/services/grades'; @@ -44,6 +44,7 @@ export class CoreGradesCoursePage implements AfterViewInit, OnDestroy { courseId!: number; userId!: number; + gradeId?: number; expandLabel!: string; collapseLabel!: string; title?: string; @@ -53,10 +54,16 @@ export class CoreGradesCoursePage implements AfterViewInit, OnDestroy { totalColumnsSpan?: number; withinSplitView?: boolean; - constructor(protected route: ActivatedRoute, protected element: ElementRef) { + constructor( + protected route: ActivatedRoute, + protected element: ElementRef, + @Optional() protected content?: IonContent, + ) { try { this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId', { route }); this.userId = CoreNavigator.getRouteNumberParam('userId', { route }) ?? CoreSites.getCurrentSiteUserId(); + this.gradeId = CoreNavigator.getRouteNumberParam('gradeId', { route }); + this.expandLabel = Translate.instant('core.expand'); this.collapseLabel = Translate.instant('core.collapse'); @@ -116,13 +123,14 @@ export class CoreGradesCoursePage implements AfterViewInit, OnDestroy { * Toggle whether a row is expanded or collapsed. * * @param row Row. + * @param expand If defined, force expand or collapse. */ - toggleRow(row: CoreGradesFormattedTableRow): void { + toggleRow(row: CoreGradesFormattedTableRow, expand?: boolean): void { if (!this.rows || !this.columns) { return; } - row.expanded = !row.expanded; + row.expanded = expand ?? !row.expanded; let colspan: number = this.columns.length + (row.colspan ?? 0) - 1; for (let i = this.rows.indexOf(row) - 1; i >= 0; i--) { @@ -155,6 +163,22 @@ export class CoreGradesCoursePage implements AfterViewInit, OnDestroy { private async fetchInitialGrades(): Promise { try { await this.fetchGrades(); + + if (this.gradeId && this.rows) { + const row = this.rows.find((row) => row.id == this.gradeId); + + if (row) { + this.toggleRow(row, true); + await CoreUtils.nextTick(); + + CoreDomUtils.scrollToElementBySelector( + this.element.nativeElement, + this.content, + '#grade-' + row.id, + ); + this.gradeId = undefined; + } + } } catch (error) { CoreDomUtils.showErrorModalDefault(error, 'Error loading course'); diff --git a/src/core/features/grades/services/grades-helper.ts b/src/core/features/grades/services/grades-helper.ts index c343c2c71..942f46895 100644 --- a/src/core/features/grades/services/grades-helper.ts +++ b/src/core/features/grades/services/grades-helper.ts @@ -35,7 +35,8 @@ import { CoreNavigator } from '@services/navigator'; import { makeSingleton, Translate } from '@singletons'; import { CoreError } from '@classes/errors/error'; import { CoreCourseHelper } from '@features/course/services/course-helper'; -import { GRADES_PAGE_NAME } from '../grades.module'; + +export const GRADES_PAGE_NAME = 'grades'; /** * Service that provides some features regarding grades information. @@ -497,9 +498,12 @@ export class CoreGradesHelperProvider { const gradeId = item.id; await CoreUtils.ignoreErrors( - CoreNavigator.navigateToSitePath(`/${GRADES_PAGE_NAME}/${courseId}/${gradeId}`, { siteId }), + CoreNavigator.navigateToSitePath( + `/${GRADES_PAGE_NAME}/${courseId}`, + { params: { gradeId }, siteId }, + ), ); - } catch (error) { + } catch { try { // Cannot get grade items or there's no need to. if (userId && userId != currentUserId) { @@ -519,7 +523,7 @@ export class CoreGradesHelperProvider { // Open the course with the grades tab selected. await CoreCourseHelper.getAndOpenCourse(courseId, { selectedTab: 'CoreGrades' }, siteId); - } catch (error) { + } catch { // Cannot get course for some reason, just open the grades page. await CoreNavigator.navigateToSitePath(`/${GRADES_PAGE_NAME}/${courseId}`, { siteId }); } diff --git a/src/core/features/grades/services/grades.ts b/src/core/features/grades/services/grades.ts index 80b588e8a..c7aa1aa7c 100644 --- a/src/core/features/grades/services/grades.ts +++ b/src/core/features/grades/services/grades.ts @@ -199,7 +199,7 @@ export class CoreGradesProvider { const table = await site.read('gradereport_user_get_grades_table', params, preSets); if (!table?.tables?.[0]) { - throw new CoreError('Coudln\'t get course grades table'); + throw new CoreError('Couldn\'t get course grades table'); } return table.tables[0]; diff --git a/src/core/features/grades/services/handlers/overview-link.ts b/src/core/features/grades/services/handlers/overview-link.ts index 241e2fc19..2205e29ea 100644 --- a/src/core/features/grades/services/handlers/overview-link.ts +++ b/src/core/features/grades/services/handlers/overview-link.ts @@ -15,10 +15,10 @@ import { Injectable } from '@angular/core'; import { CoreContentLinksHandlerBase } from '@features/contentlinks/classes/base-handler'; import { CoreContentLinksAction } from '@features/contentlinks/services/contentlinks-delegate'; -import { GRADES_PAGE_NAME } from '@features/grades/grades.module'; import { CoreNavigator } from '@services/navigator'; import { makeSingleton } from '@singletons'; import { CoreGrades } from '../grades'; +import { GRADES_PAGE_NAME } from '../grades-helper'; /** * Handler to treat links to overview courses grades. diff --git a/src/core/features/grades/services/handlers/user.ts b/src/core/features/grades/services/handlers/user.ts index 945972f4e..ade60adf5 100644 --- a/src/core/features/grades/services/handlers/user.ts +++ b/src/core/features/grades/services/handlers/user.ts @@ -14,7 +14,6 @@ import { Injectable } from '@angular/core'; import { COURSE_PAGE_NAME } from '@features/course/course.module'; -import { GRADES_PAGE_NAME } from '@features/grades/grades.module'; import { CoreGrades } from '@features/grades/services/grades'; import { CoreUserProfile } from '@features/user/services/user'; @@ -29,6 +28,7 @@ import { CoreNavigator } from '@services/navigator'; import { CoreSites } from '@services/sites'; import { CoreUtils } from '@services/utils/utils'; import { makeSingleton } from '@singletons'; +import { GRADES_PAGE_NAME } from '../grades-helper'; /** * Profile grades handler.