From ed00cefbae41d3c2fa90d6350aa96f7f61bc4c03 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Wed, 9 Jun 2021 12:31:30 +0200 Subject: [PATCH 1/3] MOBILE-3320 url: Fix embedded URLs --- src/addons/mod/url/services/handlers/module.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/addons/mod/url/services/handlers/module.ts b/src/addons/mod/url/services/handlers/module.ts index 9e4cd9571..61d2cd90d 100644 --- a/src/addons/mod/url/services/handlers/module.ts +++ b/src/addons/mod/url/services/handlers/module.ts @@ -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); From 287496c8ecdf28a5a7e490448b1074484ba441af Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Wed, 9 Jun 2021 13:38:02 +0200 Subject: [PATCH 2/3] MOBILE-3320 glossary: Fix link clicks in tablet --- src/addons/mod/glossary/glossary.module.ts | 8 ++++++++ src/addons/mod/glossary/services/handlers/edit-link.ts | 6 +++++- src/addons/mod/glossary/services/handlers/entry-link.ts | 6 +++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/addons/mod/glossary/glossary.module.ts b/src/addons/mod/glossary/glossary.module.ts index a6037fd5f..ee78aa70c 100644 --- a/src/addons/mod/glossary/glossary.module.ts +++ b/src/addons/mod/glossary/glossary.module.ts @@ -48,6 +48,14 @@ export const ADDON_MOD_GLOSSARY_SERVICES: Type[] = [ ]; 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), diff --git a/src/addons/mod/glossary/services/handlers/edit-link.ts b/src/addons/mod/glossary/services/handlers/edit-link.ts index 503220fef..f72ea2667 100644 --- a/src/addons/mod/glossary/services/handlers/edit-link.ts +++ b/src/addons/mod/glossary/services/handlers/edit-link.ts @@ -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, }, ); diff --git a/src/addons/mod/glossary/services/handlers/entry-link.ts b/src/addons/mod/glossary/services/handlers/entry-link.ts index 85b427bfd..9bf86e895 100644 --- a/src/addons/mod/glossary/services/handlers/entry-link.ts +++ b/src/addons/mod/glossary/services/handlers/entry-link.ts @@ -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, }, ); From 8f4ae0adc774f889b0dbe090cbba59e67a5fee4b Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Wed, 9 Jun 2021 15:53:10 +0200 Subject: [PATCH 3/3] MOBILE-3320 wiki: Fix wiki links --- src/addons/mod/wiki/pages/edit/edit.ts | 32 +++++++++++++++---- .../mod/wiki/services/handlers/create-link.ts | 15 ++++----- .../services/handlers/page-or-map-link.ts | 1 + src/addons/mod/wiki/services/wiki.ts | 4 +-- src/core/services/utils/dom.ts | 6 +++- 5 files changed, 40 insertions(+), 18 deletions(-) diff --git a/src/addons/mod/wiki/pages/edit/edit.ts b/src/addons/mod/wiki/pages/edit/edit.ts index ab1497894..3777fbb3b 100644 --- a/src/addons/mod/wiki/pages/edit/edit.ts +++ b/src/addons/mod/wiki/pages/edit/edit.ts @@ -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 { - 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 { + 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. */ diff --git a/src/addons/mod/wiki/services/handlers/create-link.ts b/src/addons/mod/wiki/services/handlers/create-link.ts index 3b63f51de..90a3c5aaa 100644 --- a/src/addons/mod/wiki/services/handlers/create-link.ts +++ b/src/addons/mod/wiki/services/handlers/create-link.ts @@ -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, diff --git a/src/addons/mod/wiki/services/handlers/page-or-map-link.ts b/src/addons/mod/wiki/services/handlers/page-or-map-link.ts index 0aea30fbf..78bf94f5f 100644 --- a/src/addons/mod/wiki/services/handlers/page-or-map-link.ts +++ b/src/addons/mod/wiki/services/handlers/page-or-map-link.ts @@ -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, diff --git a/src/addons/mod/wiki/services/wiki.ts b/src/addons/mod/wiki/services/wiki.ts index e51324cc0..3bdfcf796 100644 --- a/src/addons/mod/wiki/services/wiki.ts +++ b/src/addons/mod/wiki/services/wiki.ts @@ -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; diff --git a/src/core/services/utils/dom.ts b/src/core/services/utils/dom.ts index ffc7464f3..a5fefb235 100644 --- a/src/core/services/utils/dom.ts +++ b/src/core/services/utils/dom.ts @@ -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, + ); } /**