From 46c305b56350d1f2539c370531ee6bfe59428878 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Mon, 8 Jul 2024 08:35:20 +0200 Subject: [PATCH 1/3] MOBILE-4623 imscp: Fix issue with single activity format --- .../mod/imscp/components/index/index.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/addons/mod/imscp/components/index/index.ts b/src/addons/mod/imscp/components/index/index.ts index 9cd2303af..d8ccbc578 100644 --- a/src/addons/mod/imscp/components/index/index.ts +++ b/src/addons/mod/imscp/components/index/index.ts @@ -19,7 +19,7 @@ import { CoreCourse } from '@features/course/services/course'; import { CoreNavigator } from '@services/navigator'; import { AddonModImscp, AddonModImscpTocItem } from '../../services/imscp'; import { CoreUtils } from '@services/utils/utils'; -import { ADDON_MOD_IMSCP_COMPONENT } from '../../constants'; +import { ADDON_MOD_IMSCP_COMPONENT, ADDON_MOD_IMSCP_PAGE_NAME } from '../../constants'; /** * Component that displays a IMSCP. @@ -113,14 +113,17 @@ export class AddonModImscpIndexComponent extends CoreCourseModuleMainResourceCom * * @param href Item href to open, undefined for last item seen. */ - openImscp(href?: string): void { - CoreNavigator.navigate('view', { - params: { - cmId: this.module.id, - courseId: this.courseId, - initialHref: href, + async openImscp(href?: string): Promise { + await CoreNavigator.navigateToSitePath( + `${ADDON_MOD_IMSCP_PAGE_NAME}/${this.courseId}/${this.module.id}/view`, + { + params: { + cmId: this.module.id, + courseId: this.courseId, + initialHref: href, + }, }, - }); + ); this.hasStarted = true; } From 5643e89c959a1bd91f9f2cddd24f3385369bd0bc Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Thu, 25 Jul 2024 10:40:04 +0200 Subject: [PATCH 2/3] MOBILE-4623 glossary: Fix issues with single activity format --- .../mod/glossary/components/index/index.ts | 6 +-- src/addons/mod/glossary/pages/edit/edit.ts | 24 +++------- src/addons/mod/glossary/pages/entry/entry.ts | 44 ++++++++++++------- 3 files changed, 35 insertions(+), 39 deletions(-) diff --git a/src/addons/mod/glossary/components/index/index.ts b/src/addons/mod/glossary/components/index/index.ts index 7209c2ba8..d8c4aca59 100644 --- a/src/addons/mod/glossary/components/index/index.ts +++ b/src/addons/mod/glossary/components/index/index.ts @@ -427,11 +427,7 @@ export class AddonModGlossaryIndexComponent extends CoreCourseModuleMainActivity * Opens new entry editor. */ openNewEntry(): void { - CoreNavigator.navigate( - this.splitView.outletActivated - ? '../new' - : './entry/new', - ); + CoreNavigator.navigateToSitePath(`${ADDON_MOD_GLOSSARY_PAGE_NAME}/${this.courseId}/${this.module.id}/entry/new`); } /** diff --git a/src/addons/mod/glossary/pages/edit/edit.ts b/src/addons/mod/glossary/pages/edit/edit.ts index 0edecc377..edd81fd92 100644 --- a/src/addons/mod/glossary/pages/edit/edit.ts +++ b/src/addons/mod/glossary/pages/edit/edit.ts @@ -12,12 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { Component, OnInit, ViewChild, ElementRef, Optional } from '@angular/core'; +import { Component, OnInit, ViewChild, ElementRef } from '@angular/core'; import { FormControl } from '@angular/forms'; import { ActivatedRoute } from '@angular/router'; import { CoreError } from '@classes/errors/error'; import { CoreNetworkError } from '@classes/errors/network-error'; -import { CoreSplitViewComponent } from '@components/split-view/split-view'; import { CoreFileUploader, CoreFileUploaderStoreFilesResult } from '@features/fileuploader/services/fileuploader'; import { CanLeave } from '@guards/can-leave'; import { CoreFileEntry } from '@services/file-helper'; @@ -83,7 +82,7 @@ export class AddonModGlossaryEditPage implements OnInit, CanLeave { protected isDestroyed = false; protected saved = false; - constructor(protected route: ActivatedRoute, @Optional() protected splitView: CoreSplitViewComponent) {} + constructor(protected route: ActivatedRoute) {} /** * @inheritdoc @@ -109,8 +108,7 @@ export class AddonModGlossaryEditPage implements OnInit, CanLeave { } } catch (error) { CoreDomUtils.showErrorModal(error); - - this.goBack(); + CoreNavigator.back(); return; } @@ -144,8 +142,7 @@ export class AddonModGlossaryEditPage implements OnInit, CanLeave { }); } catch (error) { CoreDomUtils.showErrorModalDefault(error, 'addon.mod_glossary.errorloadingglossary', true); - - this.goBack(); + CoreNavigator.back(); } } @@ -223,7 +220,7 @@ export class AddonModGlossaryEditPage implements OnInit, CanLeave { CoreForms.triggerFormSubmittedEvent(this.formElement, savedOnline, CoreSites.getCurrentSiteId()); - this.goBack(); + CoreNavigator.back(); } catch (error) { CoreDomUtils.showErrorModalDefault(error, 'addon.mod_glossary.cannoteditentry', true); } finally { @@ -249,17 +246,6 @@ export class AddonModGlossaryEditPage implements OnInit, CanLeave { return CoreFileUploader.areFileListDifferent(this.data.attachments, this.originalData.attachments); } - /** - * Helper function to go back. - */ - protected goBack(): void { - if (this.splitView?.outletActivated) { - CoreNavigator.navigate('../../'); - } else { - CoreNavigator.back(); - } - } - } /** diff --git a/src/addons/mod/glossary/pages/entry/entry.ts b/src/addons/mod/glossary/pages/entry/entry.ts index e0da0fc1c..7b55531ff 100644 --- a/src/addons/mod/glossary/pages/entry/entry.ts +++ b/src/addons/mod/glossary/pages/entry/entry.ts @@ -38,7 +38,8 @@ import { } from '../../services/glossary'; import { CoreTime } from '@singletons/time'; import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics'; -import { ADDON_MOD_GLOSSARY_COMPONENT, ADDON_MOD_GLOSSARY_ENTRY_UPDATED } from '../../constants'; +import { ADDON_MOD_GLOSSARY_COMPONENT, ADDON_MOD_GLOSSARY_ENTRY_UPDATED, ADDON_MOD_GLOSSARY_PAGE_NAME } from '../../constants'; +import { CoreCourseContentsPage } from '@features/course/pages/contents/contents'; /** * Page that displays a glossary entry. @@ -70,9 +71,14 @@ export class AddonModGlossaryEntryPage implements OnInit, OnDestroy { courseId!: number; cmId!: number; + protected entrySlug!: string; protected logView: () => void; - constructor(@Optional() protected splitView: CoreSplitViewComponent, protected route: ActivatedRoute) { + constructor( + @Optional() protected splitView: CoreSplitViewComponent, + protected route: ActivatedRoute, + @Optional() protected courseContentsPage?: CoreCourseContentsPage, + ) { this.logView = CoreTime.once(async () => { if (!this.onlineEntry || !this.glossary || !this.componentId) { return; @@ -100,8 +106,8 @@ export class AddonModGlossaryEntryPage implements OnInit, OnDestroy { this.tagsEnabled = CoreTag.areTagsAvailableInSite(); this.commentsEnabled = CoreComments.areCommentsEnabledInSite(); this.cmId = CoreNavigator.getRequiredRouteNumberParam('cmId'); + this.entrySlug = CoreNavigator.getRequiredRouteParam('entrySlug'); - const entrySlug = CoreNavigator.getRequiredRouteParam('entrySlug'); const routeData = CoreNavigator.getRouteData(this.route); const source = CoreRoutedItemsManagerSourcesTracker.getOrCreateSource( AddonModGlossaryEntriesSource, @@ -112,14 +118,14 @@ export class AddonModGlossaryEntryPage implements OnInit, OnDestroy { await this.entries.start(); - if (entrySlug.startsWith('new-')) { - offlineEntryTimeCreated = Number(entrySlug.slice(4)); + if (this.entrySlug.startsWith('new-')) { + offlineEntryTimeCreated = Number(this.entrySlug.slice(4)); } else { - onlineEntryId = Number(entrySlug); + onlineEntryId = Number(this.entrySlug); } } catch (error) { CoreDomUtils.showErrorModal(error); - CoreNavigator.back(); + this.goBack(); return; } @@ -160,7 +166,9 @@ export class AddonModGlossaryEntryPage implements OnInit, OnDestroy { * Edit entry. */ async editEntry(): Promise { - await CoreNavigator.navigate('./edit'); + await CoreNavigator.navigateToSitePath( + `${ADDON_MOD_GLOSSARY_PAGE_NAME}/${this.courseId}/${this.cmId}/entry/${this.entrySlug}/edit`, + ); } /** @@ -208,11 +216,7 @@ export class AddonModGlossaryEntryPage implements OnInit, OnDestroy { CoreDomUtils.showToast('addon.mod_glossary.entrydeleted', true, ToastDuration.LONG); - if (this.splitView?.outletActivated) { - await CoreNavigator.navigate('../../'); - } else { - await CoreNavigator.back(); - } + await this.goBack(); } catch (error) { CoreDomUtils.showErrorModalDefault(error, 'addon.mod_glossary.errordeleting', true); } finally { @@ -237,8 +241,7 @@ export class AddonModGlossaryEntryPage implements OnInit, OnDestroy { await CoreUtils.ignoreErrors(AddonModGlossary.invalidateEntry(this.onlineEntry.id)); await this.loadOnlineEntry(this.onlineEntry.id); } else if (this.offlineEntry) { - const entrySlug = CoreNavigator.getRequiredRouteParam('entrySlug'); - const timecreated = Number(entrySlug.slice(4)); + const timecreated = Number(this.entrySlug.slice(4)); await this.loadOfflineEntry(timecreated); } @@ -355,6 +358,17 @@ export class AddonModGlossaryEntryPage implements OnInit, OnDestroy { }); } + /** + * Helper function to go back. + */ + protected async goBack(): Promise { + if (this.splitView?.outletActivated) { + await CoreNavigator.navigate((this.courseContentsPage ? '../' : '') + '../../'); + } else { + await CoreNavigator.back(); + } + } + } /** From 2e09325eef94db42d2f2e645c49f3d6cff68fb0b Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Thu, 25 Jul 2024 10:40:22 +0200 Subject: [PATCH 3/3] MOBILE-4623 forum: Fix issues with single activity format --- src/addons/mod/forum/pages/discussion/discussion.ts | 4 +++- .../mod/forum/pages/new-discussion/new-discussion.ts | 9 +++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/addons/mod/forum/pages/discussion/discussion.ts b/src/addons/mod/forum/pages/discussion/discussion.ts index e4d69c9fd..522ec6a07 100644 --- a/src/addons/mod/forum/pages/discussion/discussion.ts +++ b/src/addons/mod/forum/pages/discussion/discussion.ts @@ -58,6 +58,7 @@ import { ADDON_MOD_FORUM_MARK_READ_EVENT, ADDON_MOD_FORUM_REPLY_DISCUSSION_EVENT, } from '../../constants'; +import { CoreCourseContentsPage } from '@features/course/pages/contents/contents'; type SortType = 'flat-newest' | 'flat-oldest' | 'nested'; @@ -133,6 +134,7 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes @Optional() protected splitView: CoreSplitViewComponent, protected elementRef: ElementRef, protected route: ActivatedRoute, + @Optional() protected courseContentsPage?: CoreCourseContentsPage, ) {} get isMobile(): boolean { @@ -316,7 +318,7 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes } if (this.splitView?.outletActivated) { - CoreNavigator.navigate('../'); + CoreNavigator.navigate((this.courseContentsPage ? '../' : '') + '../'); } else { CoreNavigator.back(); } diff --git a/src/addons/mod/forum/pages/new-discussion/new-discussion.ts b/src/addons/mod/forum/pages/new-discussion/new-discussion.ts index a3ae2f2d4..7c798803a 100644 --- a/src/addons/mod/forum/pages/new-discussion/new-discussion.ts +++ b/src/addons/mod/forum/pages/new-discussion/new-discussion.ts @@ -51,6 +51,7 @@ import { ADDON_MOD_FORUM_COMPONENT, ADDON_MOD_FORUM_NEW_DISCUSSION_EVENT, } from '../../constants'; +import { CoreCourseContentsPage } from '@features/course/pages/contents/contents'; type NewDiscussionData = { subject: string; @@ -114,7 +115,11 @@ export class AddonModForumNewDiscussionPage implements OnInit, OnDestroy, CanLea protected initialGroupId?: number; protected logView: () => void; - constructor(protected route: ActivatedRoute, @Optional() protected splitView: CoreSplitViewComponent) { + constructor( + protected route: ActivatedRoute, + @Optional() protected splitView: CoreSplitViewComponent, + @Optional() protected courseContentsPage?: CoreCourseContentsPage, + ) { this.logView = CoreTime.once(() => { CoreAnalytics.logEvent({ type: CoreAnalyticsEventType.VIEW_ITEM, @@ -678,7 +683,7 @@ export class AddonModForumNewDiscussionPage implements OnInit, OnDestroy, CanLea */ protected goBack(): void { if (this.splitView?.outletActivated) { - CoreNavigator.navigate('../../'); + CoreNavigator.navigate((this.courseContentsPage ? '../' : '') + '../../'); } else { CoreNavigator.back(); }