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_MARK_READ_EVENT,
ADDON_MOD_FORUM_REPLY_DISCUSSION_EVENT, ADDON_MOD_FORUM_REPLY_DISCUSSION_EVENT,
} from '../../constants'; } from '../../constants';
import { CoreCourseContentsPage } from '@features/course/pages/contents/contents';
type SortType = 'flat-newest' | 'flat-oldest' | 'nested'; type SortType = 'flat-newest' | 'flat-oldest' | 'nested';
@ -133,6 +134,7 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes
@Optional() protected splitView: CoreSplitViewComponent, @Optional() protected splitView: CoreSplitViewComponent,
protected elementRef: ElementRef, protected elementRef: ElementRef,
protected route: ActivatedRoute, protected route: ActivatedRoute,
@Optional() protected courseContentsPage?: CoreCourseContentsPage,
) {} ) {}
get isMobile(): boolean { get isMobile(): boolean {
@ -316,7 +318,7 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes
} }
if (this.splitView?.outletActivated) { if (this.splitView?.outletActivated) {
CoreNavigator.navigate('../'); CoreNavigator.navigate((this.courseContentsPage ? '../' : '') + '../');
} else { } else {
CoreNavigator.back(); CoreNavigator.back();
} }

View File

@ -51,6 +51,7 @@ import {
ADDON_MOD_FORUM_COMPONENT, ADDON_MOD_FORUM_COMPONENT,
ADDON_MOD_FORUM_NEW_DISCUSSION_EVENT, ADDON_MOD_FORUM_NEW_DISCUSSION_EVENT,
} from '../../constants'; } from '../../constants';
import { CoreCourseContentsPage } from '@features/course/pages/contents/contents';
type NewDiscussionData = { type NewDiscussionData = {
subject: string; subject: string;
@ -114,7 +115,11 @@ export class AddonModForumNewDiscussionPage implements OnInit, OnDestroy, CanLea
protected initialGroupId?: number; protected initialGroupId?: number;
protected logView: () => void; 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(() => { this.logView = CoreTime.once(() => {
CoreAnalytics.logEvent({ CoreAnalytics.logEvent({
type: CoreAnalyticsEventType.VIEW_ITEM, type: CoreAnalyticsEventType.VIEW_ITEM,
@ -678,7 +683,7 @@ export class AddonModForumNewDiscussionPage implements OnInit, OnDestroy, CanLea
*/ */
protected goBack(): void { protected goBack(): void {
if (this.splitView?.outletActivated) { if (this.splitView?.outletActivated) {
CoreNavigator.navigate('../../'); CoreNavigator.navigate((this.courseContentsPage ? '../' : '') + '../../');
} else { } else {
CoreNavigator.back(); CoreNavigator.back();
} }

View File

@ -427,11 +427,7 @@ export class AddonModGlossaryIndexComponent extends CoreCourseModuleMainActivity
* Opens new entry editor. * Opens new entry editor.
*/ */
openNewEntry(): void { openNewEntry(): void {
CoreNavigator.navigate( CoreNavigator.navigateToSitePath(`${ADDON_MOD_GLOSSARY_PAGE_NAME}/${this.courseId}/${this.module.id}/entry/new`);
this.splitView.outletActivated
? '../new'
: './entry/new',
);
} }
/** /**

View File

@ -12,12 +12,11 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // 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 { FormControl } from '@angular/forms';
import { ActivatedRoute } from '@angular/router'; import { ActivatedRoute } from '@angular/router';
import { CoreError } from '@classes/errors/error'; import { CoreError } from '@classes/errors/error';
import { CoreNetworkError } from '@classes/errors/network-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 { CoreFileUploader, CoreFileUploaderStoreFilesResult } from '@features/fileuploader/services/fileuploader';
import { CanLeave } from '@guards/can-leave'; import { CanLeave } from '@guards/can-leave';
import { CoreFileEntry } from '@services/file-helper'; import { CoreFileEntry } from '@services/file-helper';
@ -83,7 +82,7 @@ export class AddonModGlossaryEditPage implements OnInit, CanLeave {
protected isDestroyed = false; protected isDestroyed = false;
protected saved = false; protected saved = false;
constructor(protected route: ActivatedRoute, @Optional() protected splitView: CoreSplitViewComponent) {} constructor(protected route: ActivatedRoute) {}
/** /**
* @inheritdoc * @inheritdoc
@ -109,8 +108,7 @@ export class AddonModGlossaryEditPage implements OnInit, CanLeave {
} }
} catch (error) { } catch (error) {
CoreDomUtils.showErrorModal(error); CoreDomUtils.showErrorModal(error);
CoreNavigator.back();
this.goBack();
return; return;
} }
@ -144,8 +142,7 @@ export class AddonModGlossaryEditPage implements OnInit, CanLeave {
}); });
} catch (error) { } catch (error) {
CoreDomUtils.showErrorModalDefault(error, 'addon.mod_glossary.errorloadingglossary', true); CoreDomUtils.showErrorModalDefault(error, 'addon.mod_glossary.errorloadingglossary', true);
CoreNavigator.back();
this.goBack();
} }
} }
@ -223,7 +220,7 @@ export class AddonModGlossaryEditPage implements OnInit, CanLeave {
CoreForms.triggerFormSubmittedEvent(this.formElement, savedOnline, CoreSites.getCurrentSiteId()); CoreForms.triggerFormSubmittedEvent(this.formElement, savedOnline, CoreSites.getCurrentSiteId());
this.goBack(); CoreNavigator.back();
} catch (error) { } catch (error) {
CoreDomUtils.showErrorModalDefault(error, 'addon.mod_glossary.cannoteditentry', true); CoreDomUtils.showErrorModalDefault(error, 'addon.mod_glossary.cannoteditentry', true);
} finally { } finally {
@ -249,17 +246,6 @@ export class AddonModGlossaryEditPage implements OnInit, CanLeave {
return CoreFileUploader.areFileListDifferent(this.data.attachments, this.originalData.attachments); 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'; } from '../../services/glossary';
import { CoreTime } from '@singletons/time'; import { CoreTime } from '@singletons/time';
import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics'; 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. * Page that displays a glossary entry.
@ -70,9 +71,14 @@ export class AddonModGlossaryEntryPage implements OnInit, OnDestroy {
courseId!: number; courseId!: number;
cmId!: number; cmId!: number;
protected entrySlug!: string;
protected logView: () => void; 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 () => { this.logView = CoreTime.once(async () => {
if (!this.onlineEntry || !this.glossary || !this.componentId) { if (!this.onlineEntry || !this.glossary || !this.componentId) {
return; return;
@ -100,8 +106,8 @@ export class AddonModGlossaryEntryPage implements OnInit, OnDestroy {
this.tagsEnabled = CoreTag.areTagsAvailableInSite(); this.tagsEnabled = CoreTag.areTagsAvailableInSite();
this.commentsEnabled = CoreComments.areCommentsEnabledInSite(); this.commentsEnabled = CoreComments.areCommentsEnabledInSite();
this.cmId = CoreNavigator.getRequiredRouteNumberParam('cmId'); this.cmId = CoreNavigator.getRequiredRouteNumberParam('cmId');
this.entrySlug = CoreNavigator.getRequiredRouteParam<string>('entrySlug');
const entrySlug = CoreNavigator.getRequiredRouteParam<string>('entrySlug');
const routeData = CoreNavigator.getRouteData(this.route); const routeData = CoreNavigator.getRouteData(this.route);
const source = CoreRoutedItemsManagerSourcesTracker.getOrCreateSource( const source = CoreRoutedItemsManagerSourcesTracker.getOrCreateSource(
AddonModGlossaryEntriesSource, AddonModGlossaryEntriesSource,
@ -112,14 +118,14 @@ export class AddonModGlossaryEntryPage implements OnInit, OnDestroy {
await this.entries.start(); await this.entries.start();
if (entrySlug.startsWith('new-')) { if (this.entrySlug.startsWith('new-')) {
offlineEntryTimeCreated = Number(entrySlug.slice(4)); offlineEntryTimeCreated = Number(this.entrySlug.slice(4));
} else { } else {
onlineEntryId = Number(entrySlug); onlineEntryId = Number(this.entrySlug);
} }
} catch (error) { } catch (error) {
CoreDomUtils.showErrorModal(error); CoreDomUtils.showErrorModal(error);
CoreNavigator.back(); this.goBack();
return; return;
} }
@ -160,7 +166,9 @@ export class AddonModGlossaryEntryPage implements OnInit, OnDestroy {
* Edit entry. * Edit entry.
*/ */
async editEntry(): Promise<void> { 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); CoreDomUtils.showToast('addon.mod_glossary.entrydeleted', true, ToastDuration.LONG);
if (this.splitView?.outletActivated) { await this.goBack();
await CoreNavigator.navigate('../../');
} else {
await CoreNavigator.back();
}
} catch (error) { } catch (error) {
CoreDomUtils.showErrorModalDefault(error, 'addon.mod_glossary.errordeleting', true); CoreDomUtils.showErrorModalDefault(error, 'addon.mod_glossary.errordeleting', true);
} finally { } finally {
@ -237,8 +241,7 @@ export class AddonModGlossaryEntryPage implements OnInit, OnDestroy {
await CoreUtils.ignoreErrors(AddonModGlossary.invalidateEntry(this.onlineEntry.id)); await CoreUtils.ignoreErrors(AddonModGlossary.invalidateEntry(this.onlineEntry.id));
await this.loadOnlineEntry(this.onlineEntry.id); await this.loadOnlineEntry(this.onlineEntry.id);
} else if (this.offlineEntry) { } else if (this.offlineEntry) {
const entrySlug = CoreNavigator.getRequiredRouteParam<string>('entrySlug'); const timecreated = Number(this.entrySlug.slice(4));
const timecreated = Number(entrySlug.slice(4));
await this.loadOfflineEntry(timecreated); 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 { CoreNavigator } from '@services/navigator';
import { AddonModImscp, AddonModImscpTocItem } from '../../services/imscp'; import { AddonModImscp, AddonModImscpTocItem } from '../../services/imscp';
import { CoreUtils } from '@services/utils/utils'; 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. * 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. * @param href Item href to open, undefined for last item seen.
*/ */
openImscp(href?: string): void { async openImscp(href?: string): Promise<void> {
CoreNavigator.navigate('view', { await CoreNavigator.navigateToSitePath(
`${ADDON_MOD_IMSCP_PAGE_NAME}/${this.courseId}/${this.module.id}/view`,
{
params: { params: {
cmId: this.module.id, cmId: this.module.id,
courseId: this.courseId, courseId: this.courseId,
initialHref: href, initialHref: href,
}, },
}); },
);
this.hasStarted = true; this.hasStarted = true;
} }