commit
84973e901c
|
@ -48,6 +48,14 @@ export const ADDON_MOD_GLOSSARY_SERVICES: Type<unknown>[] = [
|
|||
];
|
||||
|
||||
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,
|
||||
loadChildren: () => import('./glossary-lazy.module').then(m => m.AddonModGlossaryLazyModule),
|
||||
|
|
|
@ -47,8 +47,12 @@ export class AddonModGlossaryEditLinkHandlerService extends CoreContentLinksHand
|
|||
const module = await CoreCourse.getModuleBasicInfo(cmId, siteId);
|
||||
|
||||
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,
|
||||
},
|
||||
);
|
||||
|
|
|
@ -52,8 +52,12 @@ export class AddonModGlossaryEntryLinkHandlerService extends CoreContentLinksHan
|
|||
);
|
||||
|
||||
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,
|
||||
},
|
||||
);
|
||||
|
|
|
@ -89,7 +89,7 @@ export class AddonModUrlModuleHandlerService implements CoreCourseModuleHandler
|
|||
const modal = await CoreDomUtils.showModalLoading();
|
||||
|
||||
try {
|
||||
const shouldOpen = this.shouldOpenLink(module, courseId);
|
||||
const shouldOpen = await this.shouldOpenLink(module, courseId);
|
||||
|
||||
if (shouldOpen) {
|
||||
openUrl(module, courseId);
|
||||
|
|
|
@ -42,8 +42,8 @@ export class AddonModWikiEditPage implements OnInit, OnDestroy, CanLeave {
|
|||
|
||||
@ViewChild('editPageForm') formElement?: ElementRef;
|
||||
|
||||
cmId!: number; // Course module ID.
|
||||
courseId!: number; // Course the wiki belongs to.
|
||||
cmId?: number; // Course module ID.
|
||||
courseId?: number; // Course the wiki belongs to.
|
||||
title?: string; // Title to display.
|
||||
pageForm?: FormGroup; // The form group.
|
||||
contentControl?: FormControl; // The FormControl for the page content.
|
||||
|
@ -77,8 +77,8 @@ export class AddonModWikiEditPage implements OnInit, OnDestroy, CanLeave {
|
|||
* @inheritdoc
|
||||
*/
|
||||
async ngOnInit(): Promise<void> {
|
||||
this.cmId = CoreNavigator.getRouteNumberParam('cmId')!;
|
||||
this.courseId = CoreNavigator.getRouteNumberParam('courseId')!;
|
||||
this.cmId = CoreNavigator.getRouteNumberParam('cmId') || undefined;
|
||||
this.courseId = CoreNavigator.getRouteNumberParam('courseId') || undefined;
|
||||
this.subwikiId = CoreNavigator.getRouteNumberParam('subwikiId');
|
||||
this.wikiId = CoreNavigator.getRouteNumberParam('wikiId');
|
||||
this.pageId = CoreNavigator.getRouteNumberParam('pageId');
|
||||
|
@ -162,6 +162,8 @@ export class AddonModWikiEditPage implements OnInit, OnDestroy, CanLeave {
|
|||
this.userId = pageContents.userid;
|
||||
canEdit = pageContents.caneditpage;
|
||||
|
||||
await this.fetchModuleAndCourseId();
|
||||
|
||||
// Get subwiki files, needed to replace URLs for rich text editor.
|
||||
this.subwikiFiles = await AddonModWiki.getSubwikiFiles(this.wikiId, {
|
||||
groupId: this.groupId,
|
||||
|
@ -190,8 +192,10 @@ export class AddonModWikiEditPage implements OnInit, OnDestroy, CanLeave {
|
|||
this.editing = false;
|
||||
canEdit = !!this.blockId; // If no blockId, the user cannot edit the page.
|
||||
|
||||
// Make sure we have the wiki ID.
|
||||
if (!this.wikiId) {
|
||||
await this.fetchModuleAndCourseId();
|
||||
|
||||
// Try to get wikiId.
|
||||
if (!this.wikiId && this.cmId && this.courseId) {
|
||||
const module = await CoreCourse.getModule(this.cmId, this.courseId, undefined, true);
|
||||
|
||||
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.
|
||||
*/
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { CoreError } from '@classes/errors/error';
|
||||
import { CoreContentLinksHandlerBase } from '@features/contentlinks/classes/base-handler';
|
||||
import { CoreContentLinksAction } from '@features/contentlinks/services/contentlinks-delegate';
|
||||
import { CoreCourse } from '@features/course/services/course';
|
||||
|
@ -106,29 +105,27 @@ export class AddonModWikiCreateLinkHandlerService extends CoreContentLinksHandle
|
|||
const route = CoreNavigator.getCurrentRoute({ pageComponent: AddonModWikiIndexPage });
|
||||
const subwikiId = parseInt(params.swid, 10);
|
||||
const wikiId = parseInt(params.wid, 10);
|
||||
let moduleId: number;
|
||||
let path = AddonModWikiModuleHandlerService.PAGE_NAME;
|
||||
|
||||
// Check if the link is inside the same wiki.
|
||||
const isSameWiki = await this.currentStateIsSameWiki(route, subwikiId, siteId);
|
||||
|
||||
if (isSameWiki) {
|
||||
// User is seeing the wiki, we can get the module from the wiki params.
|
||||
moduleId = route!.snapshot.params.cmId;
|
||||
courseId = route!.snapshot.params.courseId;
|
||||
path = path + `/${route!.snapshot.params.courseId}/${route!.snapshot.params.cmId}/edit`;
|
||||
} else if (wikiId) {
|
||||
// The URL specifies which wiki it belongs to. Get the module.
|
||||
const module = await CoreCourse.getModuleBasicInfoByInstance(wikiId, 'wiki', siteId);
|
||||
|
||||
moduleId = module.id;
|
||||
courseId = module.course;
|
||||
path = path + `/${module.course}/${module.id}/edit`;
|
||||
} else {
|
||||
// Not enough data.
|
||||
throw new CoreError();
|
||||
// Cannot get module ID.
|
||||
path = path + `/${courseId || 0}/0/edit`;
|
||||
}
|
||||
|
||||
// Open the page.
|
||||
CoreNavigator.navigateToSitePath(
|
||||
AddonModWikiModuleHandlerService.PAGE_NAME + `/${courseId}/${moduleId}/edit`,
|
||||
path,
|
||||
{
|
||||
params: {
|
||||
pageTitle: params.title,
|
||||
|
|
|
@ -70,6 +70,7 @@ export class AddonModWikiPageOrMapLinkHandlerService extends CoreContentLinksHan
|
|||
AddonModWikiModuleHandlerService.PAGE_NAME + `/${courseId}/${module.id}/page/${hash}`,
|
||||
{
|
||||
params: {
|
||||
module,
|
||||
pageId: page.id,
|
||||
pageTitle: page.title,
|
||||
subwikiId: page.subwikiid,
|
||||
|
|
|
@ -1216,8 +1216,8 @@ export type AddonModWikiPageCreatedData = {
|
|||
* Data about a page that was just edited.
|
||||
*/
|
||||
export type AddonModWikiEditedPageData = {
|
||||
cmId: number;
|
||||
courseId: number;
|
||||
cmId?: number;
|
||||
courseId?: number;
|
||||
wikiId: number;
|
||||
pageTitle: string;
|
||||
subwikiId?: number;
|
||||
|
|
|
@ -1409,7 +1409,11 @@ export class CoreDomUtilsProvider {
|
|||
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,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue