MOBILE-3320 calendar: Fix calendar list page navigation
parent
a57297b09a
commit
5a528381b2
|
@ -18,7 +18,7 @@ import { Route, RouterModule, ROUTES, Routes } from '@angular/router';
|
||||||
import { buildTabMainRoutes } from '@features/mainmenu/mainmenu-tab-routing.module';
|
import { buildTabMainRoutes } from '@features/mainmenu/mainmenu-tab-routing.module';
|
||||||
|
|
||||||
export const AddonCalendarEditRoute: Route = {
|
export const AddonCalendarEditRoute: Route = {
|
||||||
path: 'edit',
|
path: 'edit/:eventId',
|
||||||
loadChildren: () =>
|
loadChildren: () =>
|
||||||
import('@/addons/calendar/pages/edit-event/edit-event.module').then(m => m.AddonCalendarEditEventPageModule),
|
import('@/addons/calendar/pages/edit-event/edit-event.module').then(m => m.AddonCalendarEditEventPageModule),
|
||||||
};
|
};
|
||||||
|
|
|
@ -553,10 +553,9 @@ export class AddonCalendarDayPage implements OnInit, OnDestroy {
|
||||||
openEdit(eventId?: number): void {
|
openEdit(eventId?: number): void {
|
||||||
const params: Params = {};
|
const params: Params = {};
|
||||||
|
|
||||||
if (eventId) {
|
if (!eventId) {
|
||||||
params.eventId = eventId;
|
|
||||||
} else {
|
|
||||||
// It's a new event, set the time.
|
// It's a new event, set the time.
|
||||||
|
eventId = 0;
|
||||||
params.timestamp = moment().year(this.year).month(this.month - 1).date(this.day).unix() * 1000;
|
params.timestamp = moment().year(this.year).month(this.month - 1).date(this.day).unix() * 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -564,7 +563,7 @@ export class AddonCalendarDayPage implements OnInit, OnDestroy {
|
||||||
params.courseId = this.filter.courseId;
|
params.courseId = this.filter.courseId;
|
||||||
}
|
}
|
||||||
|
|
||||||
CoreNavigator.navigateToSitePath('/calendar/edit', { params });
|
CoreNavigator.navigateToSitePath(`/calendar/edit/${eventId}`, { params });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -132,7 +132,7 @@ export class AddonCalendarEditEventPage implements OnInit, OnDestroy, CanLeave {
|
||||||
* Component being initialized.
|
* Component being initialized.
|
||||||
*/
|
*/
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.eventId = CoreNavigator.getRouteNumberParam('eventId');
|
this.eventId = CoreNavigator.getRouteNumberParam('eventId') || undefined;
|
||||||
this.courseId = CoreNavigator.getRouteNumberParam('courseId') || 0;
|
this.courseId = CoreNavigator.getRouteNumberParam('courseId') || 0;
|
||||||
this.title = this.eventId ? 'addon.calendar.editevent' : 'addon.calendar.newevent';
|
this.title = this.eventId ? 'addon.calendar.editevent' : 'addon.calendar.newevent';
|
||||||
|
|
||||||
|
|
|
@ -424,7 +424,7 @@ export class AddonCalendarEventPage implements OnInit, OnDestroy {
|
||||||
* Open the page to edit the event.
|
* Open the page to edit the event.
|
||||||
*/
|
*/
|
||||||
openEdit(): void {
|
openEdit(): void {
|
||||||
CoreNavigator.navigateToSitePath('/calendar/edit', { params: { eventId: this.eventId } });
|
CoreNavigator.navigateToSitePath(`/calendar/edit/${this.eventId}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -351,15 +351,13 @@ export class AddonCalendarIndexPage implements OnInit, OnDestroy {
|
||||||
*/
|
*/
|
||||||
openEdit(eventId?: number): void {
|
openEdit(eventId?: number): void {
|
||||||
const params: Params = {};
|
const params: Params = {};
|
||||||
|
eventId = eventId || 0;
|
||||||
|
|
||||||
if (eventId) {
|
|
||||||
params.eventId = eventId;
|
|
||||||
}
|
|
||||||
if (this.filter.courseId) {
|
if (this.filter.courseId) {
|
||||||
params.courseId = this.filter.courseId;
|
params.courseId = this.filter.courseId;
|
||||||
}
|
}
|
||||||
|
|
||||||
CoreNavigator.navigateToSitePath('/calendar/edit', { params });
|
CoreNavigator.navigateToSitePath(`/calendar/edit/${eventId}`, { params });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
</ion-toolbar>
|
</ion-toolbar>
|
||||||
</ion-header>
|
</ion-header>
|
||||||
<ion-content>
|
<ion-content>
|
||||||
<core-split-view>
|
|
||||||
<ion-refresher slot="fixed" [disabled]="!eventsLoaded" (ionRefresh)="doRefresh($event.target)">
|
<ion-refresher slot="fixed" [disabled]="!eventsLoaded" (ionRefresh)="doRefresh($event.target)">
|
||||||
<ion-refresher-content pullingText="{{ 'core.pulltorefresh' | translate }}"></ion-refresher-content>
|
<ion-refresher-content pullingText="{{ 'core.pulltorefresh' | translate }}"></ion-refresher-content>
|
||||||
</ion-refresher>
|
</ion-refresher>
|
||||||
|
@ -93,5 +92,4 @@
|
||||||
<ion-icon name="fas-plus" aria-hidden="true"></ion-icon>
|
<ion-icon name="fas-plus" aria-hidden="true"></ion-icon>
|
||||||
</ion-fab-button>
|
</ion-fab-button>
|
||||||
</ion-fab>
|
</ion-fab>
|
||||||
</core-split-view>
|
|
||||||
</ion-content>
|
</ion-content>
|
||||||
|
|
|
@ -29,7 +29,6 @@ import { CoreSites } from '@services/sites';
|
||||||
import { CoreLocalNotifications } from '@services/local-notifications';
|
import { CoreLocalNotifications } from '@services/local-notifications';
|
||||||
import { CoreEventObserver, CoreEvents } from '@singletons/events';
|
import { CoreEventObserver, CoreEvents } from '@singletons/events';
|
||||||
import { CoreApp } from '@services/app';
|
import { CoreApp } from '@services/app';
|
||||||
import { CoreSplitViewComponent } from '@components/split-view/split-view';
|
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import { CoreConstants } from '@/core/constants';
|
import { CoreConstants } from '@/core/constants';
|
||||||
import { AddonCalendarFilterPopoverComponent } from '../../components/filter/filter';
|
import { AddonCalendarFilterPopoverComponent } from '../../components/filter/filter';
|
||||||
|
@ -51,7 +50,6 @@ import { CoreNavigator } from '@services/navigator';
|
||||||
export class AddonCalendarListPage implements OnInit, OnDestroy {
|
export class AddonCalendarListPage implements OnInit, OnDestroy {
|
||||||
|
|
||||||
@ViewChild(IonContent) content?: IonContent;
|
@ViewChild(IonContent) content?: IonContent;
|
||||||
@ViewChild(CoreSplitViewComponent) splitviewCtrl?: CoreSplitViewComponent;
|
|
||||||
|
|
||||||
protected initialTime = 0;
|
protected initialTime = 0;
|
||||||
protected daysLoaded = 0;
|
protected daysLoaded = 0;
|
||||||
|
@ -117,26 +115,12 @@ export class AddonCalendarListPage implements OnInit, OnDestroy {
|
||||||
this.newEventObserver = CoreEvents.on(AddonCalendarProvider.NEW_EVENT_EVENT, (data) => {
|
this.newEventObserver = CoreEvents.on(AddonCalendarProvider.NEW_EVENT_EVENT, (data) => {
|
||||||
if (data && data.eventId) {
|
if (data && data.eventId) {
|
||||||
this.eventsLoaded = false;
|
this.eventsLoaded = false;
|
||||||
this.refreshEvents(true, false).finally(() => {
|
this.refreshEvents(true, false);
|
||||||
|
|
||||||
// In tablet mode try to open the event (only if it's an online event).
|
|
||||||
if (this.splitviewCtrl?.outletActivated && data.eventId > 0) {
|
|
||||||
this.gotoEvent(data.eventId);
|
|
||||||
} else if (this.splitviewCtrl?.outletActivated) {
|
|
||||||
// Discussion added, clear details page.
|
|
||||||
this.emptySplitView();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}, this.currentSiteId);
|
}, this.currentSiteId);
|
||||||
|
|
||||||
// Listen for new event discarded event. When it does, reload the data.
|
// Listen for new event discarded event. When it does, reload the data.
|
||||||
this.discardedObserver = CoreEvents.on(AddonCalendarProvider.NEW_EVENT_DISCARDED_EVENT, () => {
|
this.discardedObserver = CoreEvents.on(AddonCalendarProvider.NEW_EVENT_DISCARDED_EVENT, () => {
|
||||||
if (this.splitviewCtrl?.outletActivated) {
|
|
||||||
// Discussion added, clear details page.
|
|
||||||
this.emptySplitView();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.eventsLoaded = false;
|
this.eventsLoaded = false;
|
||||||
this.refreshEvents(true, false);
|
this.refreshEvents(true, false);
|
||||||
}, this.currentSiteId);
|
}, this.currentSiteId);
|
||||||
|
@ -150,15 +134,9 @@ export class AddonCalendarListPage implements OnInit, OnDestroy {
|
||||||
}, this.currentSiteId);
|
}, this.currentSiteId);
|
||||||
|
|
||||||
// Refresh data if calendar events are synchronized automatically.
|
// Refresh data if calendar events are synchronized automatically.
|
||||||
this.syncObserver = CoreEvents.on(AddonCalendarSyncProvider.AUTO_SYNCED, (data) => {
|
this.syncObserver = CoreEvents.on(AddonCalendarSyncProvider.AUTO_SYNCED, () => {
|
||||||
this.eventsLoaded = false;
|
this.eventsLoaded = false;
|
||||||
this.refreshEvents();
|
this.refreshEvents();
|
||||||
|
|
||||||
if (this.splitviewCtrl?.outletActivated &&
|
|
||||||
this.eventId && data && data.deleted && data.deleted.indexOf(this.eventId) != -1) {
|
|
||||||
// Current selected event was deleted. Clear details.
|
|
||||||
this.emptySplitView();
|
|
||||||
}
|
|
||||||
}, this.currentSiteId);
|
}, this.currentSiteId);
|
||||||
|
|
||||||
// Refresh data if calendar events are synchronized manually but not by this page.
|
// Refresh data if calendar events are synchronized manually but not by this page.
|
||||||
|
@ -167,12 +145,6 @@ export class AddonCalendarListPage implements OnInit, OnDestroy {
|
||||||
this.eventsLoaded = false;
|
this.eventsLoaded = false;
|
||||||
this.refreshEvents();
|
this.refreshEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.splitviewCtrl?.outletActivated &&
|
|
||||||
this.eventId && data && data.deleted && data.deleted.indexOf(this.eventId) != -1) {
|
|
||||||
// Current selected event was deleted. Clear details.
|
|
||||||
this.emptySplitView();
|
|
||||||
}
|
|
||||||
}, this.currentSiteId);
|
}, this.currentSiteId);
|
||||||
|
|
||||||
// Update the list when an event is deleted.
|
// Update the list when an event is deleted.
|
||||||
|
@ -185,11 +157,7 @@ export class AddonCalendarListPage implements OnInit, OnDestroy {
|
||||||
this.deletedEvents.push(data.eventId);
|
this.deletedEvents.push(data.eventId);
|
||||||
this.hasOffline = true;
|
this.hasOffline = true;
|
||||||
} else {
|
} else {
|
||||||
// Event deleted, clear the details if needed and refresh the view.
|
// Event deleted, refresh the view.
|
||||||
if (this.splitviewCtrl?.outletActivated) {
|
|
||||||
this.emptySplitView();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.eventsLoaded = false;
|
this.eventsLoaded = false;
|
||||||
this.refreshEvents();
|
this.refreshEvents();
|
||||||
}
|
}
|
||||||
|
@ -248,27 +216,6 @@ export class AddonCalendarListPage implements OnInit, OnDestroy {
|
||||||
this.syncIcon = CoreConstants.ICON_LOADING;
|
this.syncIcon = CoreConstants.ICON_LOADING;
|
||||||
|
|
||||||
await this.fetchData(false, true, false);
|
await this.fetchData(false, true, false);
|
||||||
|
|
||||||
if (!this.eventId && this.splitviewCtrl?.outletActivated && this.events.length > 0) {
|
|
||||||
// Take first online event and load it. If no online event, load the first offline.
|
|
||||||
if (this.onlineEvents[0]) {
|
|
||||||
this.gotoEvent(this.onlineEvents[0].id);
|
|
||||||
} else {
|
|
||||||
this.gotoEvent(this.offlineEvents[0].id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convenience function to clear detail view of the split view.
|
|
||||||
*/
|
|
||||||
protected emptySplitView(): void {
|
|
||||||
// Empty details.
|
|
||||||
const splitViewLoaded = CoreNavigator.isCurrentPathInTablet('**/calendar/list/event') ||
|
|
||||||
CoreNavigator.isCurrentPathInTablet('**/calendar/list/edit');
|
|
||||||
if (splitViewLoaded) {
|
|
||||||
CoreNavigator.navigate('../');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -633,20 +580,15 @@ export class AddonCalendarListPage implements OnInit, OnDestroy {
|
||||||
*/
|
*/
|
||||||
openEdit(eventId?: number): void {
|
openEdit(eventId?: number): void {
|
||||||
this.eventId = undefined;
|
this.eventId = undefined;
|
||||||
|
eventId = eventId || 0;
|
||||||
|
|
||||||
const params: Params = {};
|
const params: Params = {};
|
||||||
|
|
||||||
if (eventId) {
|
|
||||||
params.eventId = eventId;
|
|
||||||
}
|
|
||||||
if (this.filter.courseId) {
|
if (this.filter.courseId) {
|
||||||
params.courseId = this.filter.courseId;
|
params.courseId = this.filter.courseId;
|
||||||
}
|
}
|
||||||
|
|
||||||
const splitViewLoaded = CoreNavigator.isCurrentPathInTablet('**/calendar/list/event') ||
|
CoreNavigator.navigateToSitePath(`calendar/edit/${eventId}`, { params });
|
||||||
CoreNavigator.isCurrentPathInTablet('**/calendar/list/edit');
|
|
||||||
const path = (splitViewLoaded ? '../' : '') + 'edit';
|
|
||||||
CoreNavigator.navigate(path, { params });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -664,16 +606,11 @@ export class AddonCalendarListPage implements OnInit, OnDestroy {
|
||||||
gotoEvent(eventId: number): void {
|
gotoEvent(eventId: number): void {
|
||||||
this.eventId = eventId;
|
this.eventId = eventId;
|
||||||
|
|
||||||
if (eventId < 0) {
|
if (eventId <= 0) {
|
||||||
// It's an offline event, go to the edit page.
|
// It's an offline event, go to the edit page.
|
||||||
this.openEdit(eventId);
|
this.openEdit(eventId);
|
||||||
} else {
|
} else {
|
||||||
const splitViewLoaded = CoreNavigator.isCurrentPathInTablet('**/calendar/list/event') ||
|
CoreNavigator.navigateToSitePath(`/calendar/event/${eventId}`);
|
||||||
CoreNavigator.isCurrentPathInTablet('**/calendar/list/edit');
|
|
||||||
const path = (splitViewLoaded ? '../' : '') + 'event';
|
|
||||||
CoreNavigator.navigate(path, { params: {
|
|
||||||
id: eventId,
|
|
||||||
} });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -512,7 +512,7 @@ type NewEntryForm = { newEntry: true };
|
||||||
/**
|
/**
|
||||||
* Type of items that can be held by the entries manager.
|
* Type of items that can be held by the entries manager.
|
||||||
*/
|
*/
|
||||||
type EntryItem = AddonModGlossaryEntry | AddonModGlossaryOfflineEntry | NewEntryForm;
|
type EntryItem = AddonModGlossaryEntry | AddonModGlossaryOfflineEntry | NewEntryForm;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Entries manager.
|
* Entries manager.
|
||||||
|
|
Loading…
Reference in New Issue