Skip to content

Commit

Permalink
Merge pull request #4130 from dpalou/MOBILE-4623
Browse files Browse the repository at this point in the history
Mobile 4623
  • Loading branch information
crazyserver authored Jul 25, 2024
2 parents cefe0e4 + 2e09325 commit 0c3dfc6
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 50 deletions.
4 changes: 3 additions & 1 deletion src/addons/mod/forum/pages/discussion/discussion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -316,7 +318,7 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes
}

if (this.splitView?.outletActivated) {
CoreNavigator.navigate('../');
CoreNavigator.navigate((this.courseContentsPage ? '../' : '') + '../');
} else {
CoreNavigator.back();
}
Expand Down
9 changes: 7 additions & 2 deletions src/addons/mod/forum/pages/new-discussion/new-discussion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
}
Expand Down
6 changes: 1 addition & 5 deletions src/addons/mod/glossary/components/index/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
}

/**
Expand Down
24 changes: 5 additions & 19 deletions src/addons/mod/glossary/pages/edit/edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand All @@ -109,8 +108,7 @@ export class AddonModGlossaryEditPage implements OnInit, CanLeave {
}
} catch (error) {
CoreDomUtils.showErrorModal(error);

this.goBack();
CoreNavigator.back();

return;
}
Expand Down Expand Up @@ -144,8 +142,7 @@ export class AddonModGlossaryEditPage implements OnInit, CanLeave {
});
} catch (error) {
CoreDomUtils.showErrorModalDefault(error, 'addon.mod_glossary.errorloadingglossary', true);

this.goBack();
CoreNavigator.back();
}
}

Expand Down Expand Up @@ -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 {
Expand All @@ -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();
}
}

}

/**
Expand Down
44 changes: 29 additions & 15 deletions src/addons/mod/glossary/pages/entry/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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;
}
Expand Down Expand Up @@ -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`,
);
}

/**
Expand Down Expand Up @@ -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 {
Expand All @@ -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);
}
Expand Down Expand Up @@ -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();
}
}

}

/**
Expand Down
19 changes: 11 additions & 8 deletions src/addons/mod/imscp/components/index/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 0c3dfc6

Please sign in to comment.