Merge pull request #4130 from dpalou/MOBILE-4623

Mobile 4623
main
Pau Ferrer Ocaña 2024-07-25 12:08:00 +02:00 committed by GitHub
commit 0c3dfc6061
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 56 additions and 50 deletions

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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`);
}
/**

View File

@ -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();
}
}
}
/**

View File

@ -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<string>('entrySlug');
const entrySlug = CoreNavigator.getRequiredRouteParam<string>('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<void> {
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<string>('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<void> {
if (this.splitView?.outletActivated) {
await CoreNavigator.navigate((this.courseContentsPage ? '../' : '') + '../../');
} else {
await CoreNavigator.back();
}
}
}
/**

View File

@ -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<void> {
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;
}