MOBILE-3931 grades: Fix navigate to gradeId
parent
6dcd37234f
commit
71788e83bf
|
@ -22,7 +22,7 @@ import { CoreMainMenuTabRoutingModule } from '@features/mainmenu/mainmenu-tab-ro
|
||||||
import { CoreUserDelegate } from '@features/user/services/user-delegate';
|
import { CoreUserDelegate } from '@features/user/services/user-delegate';
|
||||||
import { PARTICIPANTS_PAGE_NAME } from '@features/user/user.module';
|
import { PARTICIPANTS_PAGE_NAME } from '@features/user/user.module';
|
||||||
import { CoreGradesProvider } from './services/grades';
|
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 { CoreGradesCourseOptionHandler } from './services/handlers/course-option';
|
||||||
import { CoreGradesOverviewLinkHandler } from './services/handlers/overview-link';
|
import { CoreGradesOverviewLinkHandler } from './services/handlers/overview-link';
|
||||||
import { CoreGradesUserHandler } from './services/handlers/user';
|
import { CoreGradesUserHandler } from './services/handlers/user';
|
||||||
|
@ -33,8 +33,6 @@ export const CORE_GRADES_SERVICES: Type<unknown>[] = [
|
||||||
CoreGradesHelperProvider,
|
CoreGradesHelperProvider,
|
||||||
];
|
];
|
||||||
|
|
||||||
export const GRADES_PAGE_NAME = 'grades';
|
|
||||||
|
|
||||||
const mainMenuChildrenRoutes: Routes = [
|
const mainMenuChildrenRoutes: Routes = [
|
||||||
{
|
{
|
||||||
path: GRADES_PAGE_NAME,
|
path: GRADES_PAGE_NAME,
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
[attr.tabindex]="row.expandable && showSummary && 0" [attr.aria-expanded]="row.expanded"
|
[attr.tabindex]="row.expandable && showSummary && 0" [attr.aria-expanded]="row.expanded"
|
||||||
[attr.aria-label]="rowAriaLabel(row)" [attr.aria-controls]="row.detailsid"
|
[attr.aria-label]="rowAriaLabel(row)" [attr.aria-controls]="row.detailsid"
|
||||||
(ariaButtonClick)="row.expandable && showSummary && toggleRow(row)" [class]="row.rowclass"
|
(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">
|
||||||
<ng-container *ngIf="row.itemtype">
|
<ng-container *ngIf="row.itemtype">
|
||||||
<td *ngIf="row.itemtype == 'category'" class="core-grades-table-category" [attr.rowspan]="row.rowspan">
|
<td *ngIf="row.itemtype == 'category'" class="core-grades-table-category" [attr.rowspan]="row.rowspan">
|
||||||
</td>
|
</td>
|
||||||
|
@ -71,40 +71,6 @@
|
||||||
<tr *ngIf="row.expandable" [id]="row.detailsid" [class]="row.rowclass" [hidden]="!row.expanded">
|
<tr *ngIf="row.expandable" [id]="row.detailsid" [class]="row.rowclass" [hidden]="!row.expanded">
|
||||||
<td [attr.colspan]="totalColumnsSpan">
|
<td [attr.colspan]="totalColumnsSpan">
|
||||||
<ion-list>
|
<ion-list>
|
||||||
<ion-item *ngIf="row.itemname && row.link" class="ion-text-wrap" detail="true" [href]="row.link"
|
|
||||||
core-link capture="true">
|
|
||||||
<ion-icon *ngIf="row.icon" name="{{row.icon}}" slot="start" [attr.aria-label]="row.iconAlt">
|
|
||||||
</ion-icon>
|
|
||||||
<img *ngIf="row.image && !row.itemmodule" [src]="row.image && row.itemmodule" slot="start"
|
|
||||||
[alt]="row.iconAlt" />
|
|
||||||
<core-mod-icon *ngIf="row.image && row.itemmodule" [modicon]="row.image" slot="start"
|
|
||||||
[modname]="row.itemmodule">
|
|
||||||
</core-mod-icon>
|
|
||||||
<ion-label>
|
|
||||||
<h2>
|
|
||||||
<core-format-text [text]="row.itemname" contextLevel="course"
|
|
||||||
[contextInstanceId]="courseId">
|
|
||||||
</core-format-text>
|
|
||||||
</h2>
|
|
||||||
</ion-label>
|
|
||||||
</ion-item>
|
|
||||||
|
|
||||||
<ion-item *ngIf="row.itemname && !row.link" class="ion-text-wrap">
|
|
||||||
<ion-icon *ngIf="row.icon" name="{{row.icon}}" slot="start" [attr.aria-label]="row.iconAlt">
|
|
||||||
</ion-icon>
|
|
||||||
<img *ngIf="row.image && !row.itemmodule" [src]="row.image" slot="start" [alt]="row.iconAlt" />
|
|
||||||
<core-mod-icon *ngIf="row.image && row.itemmodule" [modicon]="row.image" slot="start"
|
|
||||||
[modname]="row.itemmodule">
|
|
||||||
</core-mod-icon>
|
|
||||||
<ion-label>
|
|
||||||
<h2>
|
|
||||||
<core-format-text [text]="row.itemname" contextLevel="course"
|
|
||||||
[contextInstanceId]="courseId">
|
|
||||||
</core-format-text>
|
|
||||||
</h2>
|
|
||||||
</ion-label>
|
|
||||||
</ion-item>
|
|
||||||
|
|
||||||
<ion-item class="ion-text-wrap" *ngIf="row.weight">
|
<ion-item class="ion-text-wrap" *ngIf="row.weight">
|
||||||
<ion-label>
|
<ion-label>
|
||||||
<h2>{{ 'core.grades.weight' | translate}}</h2>
|
<h2>{{ 'core.grades.weight' | translate}}</h2>
|
||||||
|
|
|
@ -13,8 +13,8 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
import { ActivatedRoute } from '@angular/router';
|
import { ActivatedRoute } from '@angular/router';
|
||||||
import { AfterViewInit, Component, ElementRef, OnDestroy } from '@angular/core';
|
import { AfterViewInit, Component, ElementRef, OnDestroy, Optional } from '@angular/core';
|
||||||
import { IonRefresher } from '@ionic/angular';
|
import { IonContent, IonRefresher } from '@ionic/angular';
|
||||||
|
|
||||||
import { CoreDomUtils } from '@services/utils/dom';
|
import { CoreDomUtils } from '@services/utils/dom';
|
||||||
import { CoreGrades } from '@features/grades/services/grades';
|
import { CoreGrades } from '@features/grades/services/grades';
|
||||||
|
@ -44,6 +44,7 @@ export class CoreGradesCoursePage implements AfterViewInit, OnDestroy {
|
||||||
|
|
||||||
courseId!: number;
|
courseId!: number;
|
||||||
userId!: number;
|
userId!: number;
|
||||||
|
gradeId?: number;
|
||||||
expandLabel!: string;
|
expandLabel!: string;
|
||||||
collapseLabel!: string;
|
collapseLabel!: string;
|
||||||
title?: string;
|
title?: string;
|
||||||
|
@ -53,10 +54,16 @@ export class CoreGradesCoursePage implements AfterViewInit, OnDestroy {
|
||||||
totalColumnsSpan?: number;
|
totalColumnsSpan?: number;
|
||||||
withinSplitView?: boolean;
|
withinSplitView?: boolean;
|
||||||
|
|
||||||
constructor(protected route: ActivatedRoute, protected element: ElementRef<HTMLElement>) {
|
constructor(
|
||||||
|
protected route: ActivatedRoute,
|
||||||
|
protected element: ElementRef<HTMLElement>,
|
||||||
|
@Optional() protected content?: IonContent,
|
||||||
|
) {
|
||||||
try {
|
try {
|
||||||
this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId', { route });
|
this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId', { route });
|
||||||
this.userId = CoreNavigator.getRouteNumberParam('userId', { route }) ?? CoreSites.getCurrentSiteUserId();
|
this.userId = CoreNavigator.getRouteNumberParam('userId', { route }) ?? CoreSites.getCurrentSiteUserId();
|
||||||
|
this.gradeId = CoreNavigator.getRouteNumberParam('gradeId', { route });
|
||||||
|
|
||||||
this.expandLabel = Translate.instant('core.expand');
|
this.expandLabel = Translate.instant('core.expand');
|
||||||
this.collapseLabel = Translate.instant('core.collapse');
|
this.collapseLabel = Translate.instant('core.collapse');
|
||||||
|
|
||||||
|
@ -116,13 +123,14 @@ export class CoreGradesCoursePage implements AfterViewInit, OnDestroy {
|
||||||
* Toggle whether a row is expanded or collapsed.
|
* Toggle whether a row is expanded or collapsed.
|
||||||
*
|
*
|
||||||
* @param row Row.
|
* @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) {
|
if (!this.rows || !this.columns) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
row.expanded = !row.expanded;
|
row.expanded = expand ?? !row.expanded;
|
||||||
|
|
||||||
let colspan: number = this.columns.length + (row.colspan ?? 0) - 1;
|
let colspan: number = this.columns.length + (row.colspan ?? 0) - 1;
|
||||||
for (let i = this.rows.indexOf(row) - 1; i >= 0; i--) {
|
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<void> {
|
private async fetchInitialGrades(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
await this.fetchGrades();
|
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) {
|
} catch (error) {
|
||||||
CoreDomUtils.showErrorModalDefault(error, 'Error loading course');
|
CoreDomUtils.showErrorModalDefault(error, 'Error loading course');
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,8 @@ import { CoreNavigator } from '@services/navigator';
|
||||||
import { makeSingleton, Translate } from '@singletons';
|
import { makeSingleton, Translate } from '@singletons';
|
||||||
import { CoreError } from '@classes/errors/error';
|
import { CoreError } from '@classes/errors/error';
|
||||||
import { CoreCourseHelper } from '@features/course/services/course-helper';
|
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.
|
* Service that provides some features regarding grades information.
|
||||||
|
@ -497,9 +498,12 @@ export class CoreGradesHelperProvider {
|
||||||
const gradeId = item.id;
|
const gradeId = item.id;
|
||||||
|
|
||||||
await CoreUtils.ignoreErrors(
|
await CoreUtils.ignoreErrors(
|
||||||
CoreNavigator.navigateToSitePath(`/${GRADES_PAGE_NAME}/${courseId}/${gradeId}`, { siteId }),
|
CoreNavigator.navigateToSitePath(
|
||||||
|
`/${GRADES_PAGE_NAME}/${courseId}`,
|
||||||
|
{ params: { gradeId }, siteId },
|
||||||
|
),
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch {
|
||||||
try {
|
try {
|
||||||
// Cannot get grade items or there's no need to.
|
// Cannot get grade items or there's no need to.
|
||||||
if (userId && userId != currentUserId) {
|
if (userId && userId != currentUserId) {
|
||||||
|
@ -519,7 +523,7 @@ export class CoreGradesHelperProvider {
|
||||||
|
|
||||||
// Open the course with the grades tab selected.
|
// Open the course with the grades tab selected.
|
||||||
await CoreCourseHelper.getAndOpenCourse(courseId, { selectedTab: 'CoreGrades' }, siteId);
|
await CoreCourseHelper.getAndOpenCourse(courseId, { selectedTab: 'CoreGrades' }, siteId);
|
||||||
} catch (error) {
|
} catch {
|
||||||
// Cannot get course for some reason, just open the grades page.
|
// Cannot get course for some reason, just open the grades page.
|
||||||
await CoreNavigator.navigateToSitePath(`/${GRADES_PAGE_NAME}/${courseId}`, { siteId });
|
await CoreNavigator.navigateToSitePath(`/${GRADES_PAGE_NAME}/${courseId}`, { siteId });
|
||||||
}
|
}
|
||||||
|
|
|
@ -199,7 +199,7 @@ export class CoreGradesProvider {
|
||||||
const table = await site.read<CoreGradesGetUserGradesTableWSResponse>('gradereport_user_get_grades_table', params, preSets);
|
const table = await site.read<CoreGradesGetUserGradesTableWSResponse>('gradereport_user_get_grades_table', params, preSets);
|
||||||
|
|
||||||
if (!table?.tables?.[0]) {
|
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];
|
return table.tables[0];
|
||||||
|
|
|
@ -15,10 +15,10 @@
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { CoreContentLinksHandlerBase } from '@features/contentlinks/classes/base-handler';
|
import { CoreContentLinksHandlerBase } from '@features/contentlinks/classes/base-handler';
|
||||||
import { CoreContentLinksAction } from '@features/contentlinks/services/contentlinks-delegate';
|
import { CoreContentLinksAction } from '@features/contentlinks/services/contentlinks-delegate';
|
||||||
import { GRADES_PAGE_NAME } from '@features/grades/grades.module';
|
|
||||||
import { CoreNavigator } from '@services/navigator';
|
import { CoreNavigator } from '@services/navigator';
|
||||||
import { makeSingleton } from '@singletons';
|
import { makeSingleton } from '@singletons';
|
||||||
import { CoreGrades } from '../grades';
|
import { CoreGrades } from '../grades';
|
||||||
|
import { GRADES_PAGE_NAME } from '../grades-helper';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler to treat links to overview courses grades.
|
* Handler to treat links to overview courses grades.
|
||||||
|
|
|
@ -14,7 +14,6 @@
|
||||||
|
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { COURSE_PAGE_NAME } from '@features/course/course.module';
|
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 { CoreGrades } from '@features/grades/services/grades';
|
||||||
import { CoreUserProfile } from '@features/user/services/user';
|
import { CoreUserProfile } from '@features/user/services/user';
|
||||||
|
@ -29,6 +28,7 @@ import { CoreNavigator } from '@services/navigator';
|
||||||
import { CoreSites } from '@services/sites';
|
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';
|
||||||
|
import { GRADES_PAGE_NAME } from '../grades-helper';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Profile grades handler.
|
* Profile grades handler.
|
||||||
|
|
Loading…
Reference in New Issue