MOBILE-3708 lesson: Use similar routes as other modules

main
Dani Palou 2021-03-05 09:51:43 +01:00
parent c887e8f0a9
commit b211919f38
7 changed files with 43 additions and 42 deletions

View File

@ -424,7 +424,7 @@ export class AddonModLessonIndexComponent extends CoreCourseModuleMainActivityCo
pageId = continueLast ? this.accessInfo.lastpageseen : this.accessInfo.firstpageid;
}
await CoreNavigator.navigate(`../player/${this.courseId}/${this.lesson.id}`, {
await CoreNavigator.navigate('player', {
params: {
pageId: pageId,
password: this.password,
@ -472,7 +472,7 @@ export class AddonModLessonIndexComponent extends CoreCourseModuleMainActivityCo
return;
}
CoreNavigator.navigate(`../player/${this.courseId}/${this.lesson.id}`, {
CoreNavigator.navigate('player', {
params: {
pageId: this.retakeToReview.pageid,
password: this.password,
@ -695,7 +695,7 @@ export class AddonModLessonIndexComponent extends CoreCourseModuleMainActivityCo
* @return Promise resolved when done.
*/
async openRetake(userId: number): Promise<void> {
await CoreNavigator.navigate(`../user-retake/${this.courseId}/${this.lesson!.id}`, {
await CoreNavigator.navigate('user-retake', {
params: {
userId,
},

View File

@ -26,11 +26,11 @@ const routes: Routes = [
component: AddonModLessonIndexPage,
},
{
path: 'player/:courseId/:lessonId',
path: ':courseId/:cmId/player',
loadChildren: () => import('./pages/player/player.module').then( m => m.AddonModLessonPlayerPageModule),
},
{
path: 'user-retake/:courseId/:lessonId',
path: ':courseId/:cmId/user-retake',
loadChildren: () => import('./pages/user-retake/user-retake.module').then( m => m.AddonModLessonUserRetakePageModule),
},
];

View File

@ -98,7 +98,7 @@ export class AddonModLessonPlayerPage implements OnInit, OnDestroy, CanLeave {
mediaFile?: CoreWSExternalFile; // Media file of the lesson.
activityLink?: AddonModLessonActivityLink; // Next activity link data.
protected lessonId!: number; // Lesson ID.
protected cmId!: number; // Course module ID.
protected password?: string; // Lesson password (if any).
protected forceLeave = false; // If true, don't perform any check when leaving the view.
protected offline?: boolean; // Whether we are in offline mode.
@ -118,22 +118,19 @@ export class AddonModLessonPlayerPage implements OnInit, OnDestroy, CanLeave {
* Component being initialized.
*/
async ngOnInit(): Promise<void> {
this.lessonId = CoreNavigator.getRouteNumberParam('lessonId')!;
this.cmId = CoreNavigator.getRouteNumberParam('cmId')!;
this.courseId = CoreNavigator.getRouteNumberParam('courseId')!;
this.password = CoreNavigator.getRouteParam('password');
this.review = !!CoreNavigator.getRouteBooleanParam('review');
this.currentPage = CoreNavigator.getRouteNumberParam('pageId');
this.retakeToReview = CoreNavigator.getRouteNumberParam('retake');
// Block the lesson so it cannot be synced.
CoreSync.blockOperation(this.component, this.lessonId);
try {
// Fetch the Lesson data.
const success = await this.fetchLessonData();
if (success) {
// Review data loaded or new retake started, remove any retake being finished in sync.
AddonModLessonSync.deleteRetakeFinishedInSync(this.lessonId);
AddonModLessonSync.deleteRetakeFinishedInSync(this.lesson!.id);
}
} finally {
this.loaded = true;
@ -144,8 +141,10 @@ export class AddonModLessonPlayerPage implements OnInit, OnDestroy, CanLeave {
* Component being destroyed.
*/
ngOnDestroy(): void {
// Unblock the lesson so it can be synced.
CoreSync.unblockOperation(this.component, this.lessonId);
if (this.lesson) {
// Unblock the lesson so it can be synced.
CoreSync.unblockOperation(this.component, this.lesson.id);
}
}
/**
@ -214,7 +213,7 @@ export class AddonModLessonPlayerPage implements OnInit, OnDestroy, CanLeave {
// Get the possible jumps now.
this.jumps = await AddonModLesson.getPagesPossibleJumps(this.lesson!.id, {
cmId: this.lesson!.coursemodule,
cmId: this.cmId,
readingStrategy: CoreSitesReadingStrategy.PreferCache,
});
@ -259,14 +258,18 @@ export class AddonModLessonPlayerPage implements OnInit, OnDestroy, CanLeave {
*/
protected async fetchLessonData(): Promise<boolean> {
try {
// Wait for any ongoing sync to finish. We won't sync a lesson while it's being played.
await AddonModLessonSync.waitForSync(this.lessonId);
this.lesson = await AddonModLesson.getLesson(this.courseId, this.cmId);
this.lesson = await AddonModLesson.getLessonById(this.courseId, this.lessonId);
this.title = this.lesson.name; // Temporary title.
// Block the lesson so it cannot be synced.
CoreSync.blockOperation(this.component, this.lesson.id);
// Wait for any ongoing sync to finish. We won't sync a lesson while it's being played.
await AddonModLessonSync.waitForSync(this.lesson.id);
// If lesson has offline data already, use offline mode.
this.offline = await AddonModLessonOffline.hasOfflineData(this.lessonId);
this.offline = await AddonModLessonOffline.hasOfflineData(this.lesson.id);
if (!this.offline && !CoreApp.isOnline() && AddonModLesson.isLessonOffline(this.lesson) &&
!this.review) {
@ -275,7 +278,7 @@ export class AddonModLessonPlayerPage implements OnInit, OnDestroy, CanLeave {
}
const options = {
cmId: this.lesson.coursemodule,
cmId: this.cmId,
readingStrategy: this.offline ? CoreSitesReadingStrategy.PreferCache : CoreSitesReadingStrategy.OnlyNetwork,
};
this.accessInfo = await this.callFunction<AddonModLessonGetAccessInformationWSResponse>(
@ -306,7 +309,7 @@ export class AddonModLessonPlayerPage implements OnInit, OnDestroy, CanLeave {
// Lesson uses password, get the whole lesson object.
const options = {
password: this.password,
cmId: this.lesson.coursemodule,
cmId: this.cmId,
readingStrategy: this.offline ? CoreSitesReadingStrategy.PreferCache : CoreSitesReadingStrategy.OnlyNetwork,
};
promises.push(this.callFunction<AddonModLessonLessonWSData>(
@ -322,7 +325,7 @@ export class AddonModLessonPlayerPage implements OnInit, OnDestroy, CanLeave {
if (this.offline) {
// Offline mode, get the list of possible jumps to allow navigation.
promises.push(AddonModLesson.getPagesPossibleJumps(this.lesson.id, {
cmId: this.lesson.coursemodule,
cmId: this.cmId,
readingStrategy: CoreSitesReadingStrategy.PreferCache,
}).then((jumpList) => {
this.jumps = jumpList;
@ -344,7 +347,7 @@ export class AddonModLessonPlayerPage implements OnInit, OnDestroy, CanLeave {
if (this.review && this.retakeToReview && CoreUtils.isWebServiceError(error)) {
// The user cannot review the retake. Unmark the retake as being finished in sync.
await AddonModLessonSync.deleteRetakeFinishedInSync(this.lessonId);
await AddonModLessonSync.deleteRetakeFinishedInSync(this.lesson!.id);
}
CoreDomUtils.showErrorModalDefault(error, 'core.course.errorgetmodule', true);
@ -373,7 +376,7 @@ export class AddonModLessonPlayerPage implements OnInit, OnDestroy, CanLeave {
if (result?.warnings?.length) {
// Some data was deleted. Check if the retake has changed.
const info = await AddonModLesson.getAccessInformation(this.lesson!.id, {
cmId: this.lesson!.coursemodule,
cmId: this.cmId,
});
if (info.attemptscount != this.accessInfo!.attemptscount) {
@ -485,7 +488,7 @@ export class AddonModLessonPlayerPage implements OnInit, OnDestroy, CanLeave {
if (this.lesson!.timelimit && !this.accessInfo!.canmanage) {
// Get the last lesson timer.
const timers = await AddonModLesson.getTimers(this.lesson!.id, {
cmId: this.lesson!.coursemodule,
cmId: this.cmId,
readingStrategy: CoreSitesReadingStrategy.OnlyNetwork,
});
@ -510,12 +513,12 @@ export class AddonModLessonPlayerPage implements OnInit, OnDestroy, CanLeave {
this.loadingMenu = true;
const options = {
password: this.password,
cmId: this.lesson!.coursemodule,
cmId: this.cmId,
readingStrategy: this.offline ? CoreSitesReadingStrategy.PreferCache : CoreSitesReadingStrategy.OnlyNetwork,
};
const pages = await this.callFunction<AddonModLessonGetPagesPageWSData[]>(
AddonModLesson.getPages.bind(AddonModLesson.instance, this.lessonId, options),
AddonModLesson.getPages.bind(AddonModLesson.instance, this.lesson!.id, options),
options,
);
@ -543,7 +546,7 @@ export class AddonModLessonPlayerPage implements OnInit, OnDestroy, CanLeave {
password: this.password,
review: this.review,
includeContents: true,
cmId: this.lesson!.coursemodule,
cmId: this.cmId,
readingStrategy: this.offline ? CoreSitesReadingStrategy.PreferCache : CoreSitesReadingStrategy.OnlyNetwork,
accessInfo: this.accessInfo,
jumps: this.jumps,
@ -638,15 +641,15 @@ export class AddonModLessonPlayerPage implements OnInit, OnDestroy, CanLeave {
// Lesson allows offline and the user changed some data in server. Update cached data.
const retake = this.accessInfo!.attemptscount;
const options = {
cmId: this.lesson!.coursemodule,
cmId: this.cmId,
readingStrategy: CoreSitesReadingStrategy.OnlyNetwork,
};
// Update in background the list of content pages viewed or question attempts.
if (AddonModLesson.isQuestionPage(this.pageData?.page?.type || -1)) {
AddonModLesson.getQuestionsAttemptsOnline(this.lessonId, retake, options);
AddonModLesson.getQuestionsAttemptsOnline(this.lesson!.id, retake, options);
} else {
AddonModLesson.getContentPagesViewedOnline(this.lessonId, retake, options);
AddonModLesson.getContentPagesViewedOnline(this.lesson!.id, retake, options);
}
}

View File

@ -55,7 +55,7 @@ export class AddonModLessonUserRetakePage implements OnInit {
loaded?: boolean; // Whether the data has been loaded.
timeTakenReadable?: string; // Time taken in a readable format.
protected lessonId!: number; // The lesson ID the retake belongs to.
protected cmId!: number; // The lesson ID the retake belongs to.
protected userId?: number; // User ID to see the retakes.
protected retakeNumber?: number; // Number of the initial retake to see.
protected previousSelectedRetake?: number; // To be able to detect the previous selected retake when it has changed.
@ -64,7 +64,7 @@ export class AddonModLessonUserRetakePage implements OnInit {
* Component being initialized.
*/
ngOnInit(): void {
this.lessonId = CoreNavigator.getRouteNumberParam('lessonId')!;
this.cmId = CoreNavigator.getRouteNumberParam('cmId')!;
this.courseId = CoreNavigator.getRouteNumberParam('courseId')!;
this.userId = CoreNavigator.getRouteNumberParam('userId') || CoreSites.getCurrentSiteUserId();
this.retakeNumber = CoreNavigator.getRouteNumberParam('retake');
@ -111,11 +111,11 @@ export class AddonModLessonUserRetakePage implements OnInit {
*/
protected async fetchData(): Promise<void> {
try {
this.lesson = await AddonModLesson.getLessonById(this.courseId, this.lessonId);
this.lesson = await AddonModLesson.getLesson(this.courseId, this.cmId);
// Get the retakes overview for all participants.
const data = await AddonModLesson.getRetakesOverview(this.lesson.id, {
cmId: this.lesson.coursemodule,
cmId: this.cmId,
});
// Search the student.
@ -185,8 +185,8 @@ export class AddonModLessonUserRetakePage implements OnInit {
protected async setRetake(retakeNumber: number): Promise<void> {
this.selectedRetake = retakeNumber;
const retakeData = await AddonModLesson.getUserRetake(this.lessonId, retakeNumber, {
cmId: this.lesson!.coursemodule,
const retakeData = await AddonModLesson.getUserRetake(this.lesson!.id, retakeNumber, {
cmId: this.cmId,
userId: this.userId,
});

View File

@ -65,7 +65,7 @@ export class AddonModLessonGradeLinkHandlerService extends CoreContentLinksModul
if (accessInfo.canviewreports) {
// User can view reports, go to view the report.
CoreNavigator.navigateToSitePath(
AddonModLessonModuleHandlerService.PAGE_NAME + `/user-retake/${courseId}/${module.instance}`,
AddonModLessonModuleHandlerService.PAGE_NAME + `/${courseId}/${module.id}/user-retake`,
{
params: { userId: Number(params.userid) },
siteId,

View File

@ -122,11 +122,9 @@ export class AddonModLessonReportLinkHandlerService extends CoreContentLinksHand
*
* @param moduleId Module ID.
* @param userId User ID.
* @param courseId Course ID.
* @param retake Retake to open.
* @param groupId Group ID.
* @param siteId Site ID.
* @param navCtrl The NavController to use to navigate.
* @param courseId Course ID.
* @return Promise resolved when done.
*/
protected async openUserRetake(
@ -150,7 +148,7 @@ export class AddonModLessonReportLinkHandlerService extends CoreContentLinksHand
};
CoreNavigator.navigateToSitePath(
AddonModLessonModuleHandlerService.PAGE_NAME + `/user-retake/${courseId}/${module.instance}`,
AddonModLessonModuleHandlerService.PAGE_NAME + `/${courseId}/${module.id}/user-retake`,
{ params, siteId },
);
} catch (error) {

View File

@ -1486,7 +1486,7 @@ export class AddonModLessonProvider {
const response = await site.read<AddonModLessonGetLessonWSResponse>('mod_lesson_get_lesson', params, preSets);
if (typeof response.lesson.ongoing != 'undefined') {
if (typeof response.lesson.ongoing == 'undefined') {
// Basic data not received, password is wrong. Remove stored password.
this.removeStoredPassword(lessonId, site.id);