Merge pull request #2821 from dpalou/MOBILE-3320

Mobile 3320
main
Pau Ferrer Ocaña 2021-06-09 16:24:05 +02:00 committed by GitHub
commit 84973e901c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 59 additions and 21 deletions

View File

@ -48,6 +48,14 @@ export const ADDON_MOD_GLOSSARY_SERVICES: Type<unknown>[] = [
]; ];
const mainMenuRoutes: Routes = [ const mainMenuRoutes: Routes = [
{
path: `${AddonModGlossaryModuleHandlerService.PAGE_NAME}/entry/:entryId`,
loadChildren: () => import('./pages/entry/entry.module').then(m => m.AddonModGlossaryEntryPageModule),
},
{
path: `${AddonModGlossaryModuleHandlerService.PAGE_NAME}/edit/:timecreated`,
loadChildren: () => import('./pages/edit/edit.module').then(m => m.AddonModGlossaryEditPageModule),
},
{ {
path: AddonModGlossaryModuleHandlerService.PAGE_NAME, path: AddonModGlossaryModuleHandlerService.PAGE_NAME,
loadChildren: () => import('./glossary-lazy.module').then(m => m.AddonModGlossaryLazyModule), loadChildren: () => import('./glossary-lazy.module').then(m => m.AddonModGlossaryLazyModule),

View File

@ -47,8 +47,12 @@ export class AddonModGlossaryEditLinkHandlerService extends CoreContentLinksHand
const module = await CoreCourse.getModuleBasicInfo(cmId, siteId); const module = await CoreCourse.getModuleBasicInfo(cmId, siteId);
await CoreNavigator.navigateToSitePath( await CoreNavigator.navigateToSitePath(
AddonModGlossaryModuleHandlerService.PAGE_NAME + `/${module.course}/${module.id}/edit/0`, AddonModGlossaryModuleHandlerService.PAGE_NAME + '/edit/0',
{ {
params: {
courseId: module.course,
cmId: module.id,
},
siteId, siteId,
}, },
); );

View File

@ -52,8 +52,12 @@ export class AddonModGlossaryEntryLinkHandlerService extends CoreContentLinksHan
); );
await CoreNavigator.navigateToSitePath( await CoreNavigator.navigateToSitePath(
AddonModGlossaryModuleHandlerService.PAGE_NAME + `/${module.course}/${module.id}/entry/${entryId}`, AddonModGlossaryModuleHandlerService.PAGE_NAME + `/entry/${entryId}`,
{ {
params: {
courseId: module.course,
cmId: module.id,
},
siteId, siteId,
}, },
); );

View File

@ -89,7 +89,7 @@ export class AddonModUrlModuleHandlerService implements CoreCourseModuleHandler
const modal = await CoreDomUtils.showModalLoading(); const modal = await CoreDomUtils.showModalLoading();
try { try {
const shouldOpen = this.shouldOpenLink(module, courseId); const shouldOpen = await this.shouldOpenLink(module, courseId);
if (shouldOpen) { if (shouldOpen) {
openUrl(module, courseId); openUrl(module, courseId);

View File

@ -42,8 +42,8 @@ export class AddonModWikiEditPage implements OnInit, OnDestroy, CanLeave {
@ViewChild('editPageForm') formElement?: ElementRef; @ViewChild('editPageForm') formElement?: ElementRef;
cmId!: number; // Course module ID. cmId?: number; // Course module ID.
courseId!: number; // Course the wiki belongs to. courseId?: number; // Course the wiki belongs to.
title?: string; // Title to display. title?: string; // Title to display.
pageForm?: FormGroup; // The form group. pageForm?: FormGroup; // The form group.
contentControl?: FormControl; // The FormControl for the page content. contentControl?: FormControl; // The FormControl for the page content.
@ -77,8 +77,8 @@ export class AddonModWikiEditPage implements OnInit, OnDestroy, CanLeave {
* @inheritdoc * @inheritdoc
*/ */
async ngOnInit(): Promise<void> { async ngOnInit(): Promise<void> {
this.cmId = CoreNavigator.getRouteNumberParam('cmId')!; this.cmId = CoreNavigator.getRouteNumberParam('cmId') || undefined;
this.courseId = CoreNavigator.getRouteNumberParam('courseId')!; this.courseId = CoreNavigator.getRouteNumberParam('courseId') || undefined;
this.subwikiId = CoreNavigator.getRouteNumberParam('subwikiId'); this.subwikiId = CoreNavigator.getRouteNumberParam('subwikiId');
this.wikiId = CoreNavigator.getRouteNumberParam('wikiId'); this.wikiId = CoreNavigator.getRouteNumberParam('wikiId');
this.pageId = CoreNavigator.getRouteNumberParam('pageId'); this.pageId = CoreNavigator.getRouteNumberParam('pageId');
@ -162,6 +162,8 @@ export class AddonModWikiEditPage implements OnInit, OnDestroy, CanLeave {
this.userId = pageContents.userid; this.userId = pageContents.userid;
canEdit = pageContents.caneditpage; canEdit = pageContents.caneditpage;
await this.fetchModuleAndCourseId();
// Get subwiki files, needed to replace URLs for rich text editor. // Get subwiki files, needed to replace URLs for rich text editor.
this.subwikiFiles = await AddonModWiki.getSubwikiFiles(this.wikiId, { this.subwikiFiles = await AddonModWiki.getSubwikiFiles(this.wikiId, {
groupId: this.groupId, groupId: this.groupId,
@ -190,8 +192,10 @@ export class AddonModWikiEditPage implements OnInit, OnDestroy, CanLeave {
this.editing = false; this.editing = false;
canEdit = !!this.blockId; // If no blockId, the user cannot edit the page. canEdit = !!this.blockId; // If no blockId, the user cannot edit the page.
// Make sure we have the wiki ID. await this.fetchModuleAndCourseId();
if (!this.wikiId) {
// Try to get wikiId.
if (!this.wikiId && this.cmId && this.courseId) {
const module = await CoreCourse.getModule(this.cmId, this.courseId, undefined, true); const module = await CoreCourse.getModule(this.cmId, this.courseId, undefined, true);
this.wikiId = module.instance; this.wikiId = module.instance;
@ -248,6 +252,22 @@ export class AddonModWikiEditPage implements OnInit, OnDestroy, CanLeave {
} }
} }
/**
* Load cmId and courseId if they aren't set.
*
* @return Promise.
*/
protected async fetchModuleAndCourseId(): Promise<void> {
if (!this.wikiId || (this.cmId && this.courseId)) {
return;
}
const module = await CoreCourse.getModuleBasicInfoByInstance(this.wikiId, 'wiki');
this.cmId = module.id;
this.courseId = module.course;
}
/** /**
* Force leaving the page, without checking for changes. * Force leaving the page, without checking for changes.
*/ */

View File

@ -14,7 +14,6 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { ActivatedRoute } from '@angular/router'; import { ActivatedRoute } from '@angular/router';
import { CoreError } from '@classes/errors/error';
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 { CoreCourse } from '@features/course/services/course'; import { CoreCourse } from '@features/course/services/course';
@ -106,29 +105,27 @@ export class AddonModWikiCreateLinkHandlerService extends CoreContentLinksHandle
const route = CoreNavigator.getCurrentRoute({ pageComponent: AddonModWikiIndexPage }); const route = CoreNavigator.getCurrentRoute({ pageComponent: AddonModWikiIndexPage });
const subwikiId = parseInt(params.swid, 10); const subwikiId = parseInt(params.swid, 10);
const wikiId = parseInt(params.wid, 10); const wikiId = parseInt(params.wid, 10);
let moduleId: number; let path = AddonModWikiModuleHandlerService.PAGE_NAME;
// Check if the link is inside the same wiki. // Check if the link is inside the same wiki.
const isSameWiki = await this.currentStateIsSameWiki(route, subwikiId, siteId); const isSameWiki = await this.currentStateIsSameWiki(route, subwikiId, siteId);
if (isSameWiki) { if (isSameWiki) {
// User is seeing the wiki, we can get the module from the wiki params. // User is seeing the wiki, we can get the module from the wiki params.
moduleId = route!.snapshot.params.cmId; path = path + `/${route!.snapshot.params.courseId}/${route!.snapshot.params.cmId}/edit`;
courseId = route!.snapshot.params.courseId;
} else if (wikiId) { } else if (wikiId) {
// The URL specifies which wiki it belongs to. Get the module. // The URL specifies which wiki it belongs to. Get the module.
const module = await CoreCourse.getModuleBasicInfoByInstance(wikiId, 'wiki', siteId); const module = await CoreCourse.getModuleBasicInfoByInstance(wikiId, 'wiki', siteId);
moduleId = module.id; path = path + `/${module.course}/${module.id}/edit`;
courseId = module.course;
} else { } else {
// Not enough data. // Cannot get module ID.
throw new CoreError(); path = path + `/${courseId || 0}/0/edit`;
} }
// Open the page. // Open the page.
CoreNavigator.navigateToSitePath( CoreNavigator.navigateToSitePath(
AddonModWikiModuleHandlerService.PAGE_NAME + `/${courseId}/${moduleId}/edit`, path,
{ {
params: { params: {
pageTitle: params.title, pageTitle: params.title,

View File

@ -70,6 +70,7 @@ export class AddonModWikiPageOrMapLinkHandlerService extends CoreContentLinksHan
AddonModWikiModuleHandlerService.PAGE_NAME + `/${courseId}/${module.id}/page/${hash}`, AddonModWikiModuleHandlerService.PAGE_NAME + `/${courseId}/${module.id}/page/${hash}`,
{ {
params: { params: {
module,
pageId: page.id, pageId: page.id,
pageTitle: page.title, pageTitle: page.title,
subwikiId: page.subwikiid, subwikiId: page.subwikiid,

View File

@ -1216,8 +1216,8 @@ export type AddonModWikiPageCreatedData = {
* Data about a page that was just edited. * Data about a page that was just edited.
*/ */
export type AddonModWikiEditedPageData = { export type AddonModWikiEditedPageData = {
cmId: number; cmId?: number;
courseId: number; courseId?: number;
wikiId: number; wikiId: number;
pageTitle: string; pageTitle: string;
subwikiId?: number; subwikiId?: number;

View File

@ -1409,7 +1409,11 @@ export class CoreDomUtilsProvider {
errorMessage = CoreTextUtils.getErrorMessageFromError(error); errorMessage = CoreTextUtils.getErrorMessageFromError(error);
} }
return this.showErrorModal(typeof errorMessage == 'string' ? error! : defaultError, needsTranslate, autocloseTime); return this.showErrorModal(
typeof errorMessage == 'string' && errorMessage ? error! : defaultError,
needsTranslate,
autocloseTime,
);
} }
/** /**