MOBILE-3659 core: Always use CoreNavigator to get params

main
Dani Palou 2021-01-25 14:31:11 +01:00
parent afa94e3354
commit 3daf03dbf4
28 changed files with 150 additions and 207 deletions

View File

@ -20,8 +20,8 @@ import { CoreSites } from '@services/sites';
import { CoreUser, CoreUserProfile } from '@features/user/services/user';
import { AddonBadges, AddonBadgesUserBadge } from '../../services/badges';
import { CoreUtils } from '@services/utils/utils';
import { ActivatedRoute } from '@angular/router';
import { CoreCourses, CoreEnrolledCourseData } from '@features/courses/services/courses';
import { CoreNavigator } from '@services/navigator';
/**
* Page that displays the list of calendar events.
@ -42,18 +42,13 @@ export class AddonBadgesIssuedBadgePage implements OnInit {
badgeLoaded = false;
currentTime = 0;
constructor(
protected route: ActivatedRoute,
) { }
/**
* View loaded.
*/
ngOnInit(): void {
this.courseId = parseInt(this.route.snapshot.queryParams['courseId'], 10) || this.courseId; // Use 0 for site badges.
this.userId = this.route.snapshot.queryParams['userId'] ||
CoreSites.instance.getCurrentSite()?.getUserId();
this.badgeHash = this.route.snapshot.queryParams['badgeHash'];
this.courseId = CoreNavigator.instance.getRouteNumberParam('courseId') || this.courseId; // Use 0 for site badges.
this.userId = CoreNavigator.instance.getRouteNumberParam('userId') || CoreSites.instance.getCurrentSite()!.getUserId();
this.badgeHash = CoreNavigator.instance.getRouteParam('badgeHash') || '';
this.fetchIssuedBadge().finally(() => {
this.badgeLoaded = true;

View File

@ -20,7 +20,6 @@ import { CoreDomUtils } from '@services/utils/dom';
import { CoreSites } from '@services/sites';
import { CoreUtils } from '@services/utils/utils';
import { CoreNavigator } from '@services/navigator';
import { ActivatedRoute } from '@angular/router';
// @todo import { CoreSplitViewComponent } from '@components/split-view/split-view';
/**
@ -42,18 +41,13 @@ export class AddonBadgesUserBadgesPage implements OnInit {
currentTime = 0;
badgeHash!: string;
constructor(
protected route: ActivatedRoute,
) { }
/**
* View loaded.
*/
ngOnInit(): void {
this.courseId = parseInt(this.route.snapshot.queryParams['courseId'], 10) || this.courseId; // Use 0 for site badges.
this.userId = this.route.snapshot.queryParams['userId'] ||
CoreSites.instance.getCurrentSite()?.getUserId();
this.courseId = CoreNavigator.instance.getRouteNumberParam('courseId') || this.courseId; // Use 0 for site badges.
this.userId = CoreNavigator.instance.getRouteNumberParam('userId') || CoreSites.instance.getCurrentSite()!.getUserId();
this.fetchBadges().finally(() => {
// @todo splitview

View File

@ -37,7 +37,7 @@ import { AddonCalendarFilterPopoverComponent } from '../../components/filter/fil
import moment from 'moment';
import { Network, NgZone } from '@singletons';
import { CoreNavigator } from '@services/navigator';
import { ActivatedRoute, Params } from '@angular/router';
import { Params } from '@angular/router';
import { Subscription } from 'rxjs';
import { CoreUtils } from '@services/utils/utils';
@ -101,7 +101,6 @@ export class AddonCalendarDayPage implements OnInit, OnDestroy {
};
constructor(
protected route: ActivatedRoute,
private popoverCtrl: PopoverController,
) {
this.currentSiteId = CoreSites.instance.getCurrentSiteId();
@ -235,19 +234,18 @@ export class AddonCalendarDayPage implements OnInit, OnDestroy {
CoreUtils.instance.enumKeys(AddonCalendarEventType).forEach((name) => {
const value = AddonCalendarEventType[name];
const filter = this.route.snapshot.queryParams[name];
this.filter[name] = typeof filter == 'undefined' ? true : filter;
this.filter[name] = CoreNavigator.instance.getRouteBooleanParam(name) ?? true;
types.push(value);
});
this.filter.courseId = parseInt(this.route.snapshot.queryParams['courseId'], 10) || -1;
this.filter.categoryId = parseInt(this.route.snapshot.queryParams['categoryId'], 10) || undefined;
this.filter.courseId = CoreNavigator.instance.getRouteNumberParam('courseId') || -1;
this.filter.categoryId = CoreNavigator.instance.getRouteNumberParam('categoryId');
this.filter.filtered = typeof this.filter.courseId != 'undefined' || types.some((name) => !this.filter[name]);
const now = new Date();
this.year = this.route.snapshot.queryParams['year'] || now.getFullYear();
this.month = this.route.snapshot.queryParams['month'] || (now.getMonth() + 1);
this.day = this.route.snapshot.queryParams['day'] || now.getDate();
this.year = CoreNavigator.instance.getRouteNumberParam('year') || now.getFullYear();
this.month = CoreNavigator.instance.getRouteNumberParam('month') || (now.getMonth() + 1);
this.day = CoreNavigator.instance.getRouteNumberParam('day') || now.getDate();
this.calculateCurrentMoment();
this.calculateIsCurrentDay();

View File

@ -40,7 +40,6 @@ import { AddonCalendarSync, AddonCalendarSyncProvider } from '../../services/cal
import { CoreSite } from '@classes/site';
import { Translate } from '@singletons';
import { CoreFilterHelper } from '@features/filter/services/filter-helper';
import { ActivatedRoute } from '@angular/router';
import { AddonCalendarOfflineEventDBRecord } from '../../services/database/calendar-offline';
import { CoreError } from '@classes/errors/error';
import { CoreNavigator } from '@services/navigator';
@ -91,7 +90,6 @@ export class AddonCalendarEditEventPage implements OnInit, OnDestroy {
protected gotEventData = false;
constructor(
protected route: ActivatedRoute,
protected fb: FormBuilder,
) {
@ -128,11 +126,11 @@ export class AddonCalendarEditEventPage implements OnInit, OnDestroy {
* Component being initialized.
*/
ngOnInit(): void {
this.eventId = this.route.snapshot.queryParams['eventId'];
this.courseId = parseInt(this.route.snapshot.queryParams['courseId'], 10) || 0;
this.eventId = CoreNavigator.instance.getRouteNumberParam('eventId');
this.courseId = CoreNavigator.instance.getRouteNumberParam('courseId') || 0;
this.title = this.eventId ? 'addon.calendar.editevent' : 'addon.calendar.newevent';
const timestamp = parseInt(this.route.snapshot.queryParams['timestamp'], 10);
const timestamp = CoreNavigator.instance.getRouteNumberParam('timestamp');
const currentDate = CoreTimeUtils.instance.toDatetimeFormat(timestamp);
this.form.addControl('timestart', this.fb.control(currentDate, Validators.required));
this.form.addControl('timedurationuntil', this.fb.control(currentDate));

View File

@ -43,7 +43,6 @@ import { Subscription } from 'rxjs';
import { CoreNavigator } from '@services/navigator';
import { CoreUtils } from '@services/utils/utils';
import { AddonCalendarReminderDBRecord } from '../../services/database/calendar';
import { ActivatedRoute } from '@angular/router';
/**
* Page that displays a single calendar event.
@ -86,11 +85,7 @@ export class AddonCalendarEventPage implements OnInit, OnDestroy {
syncIcon = 'spinner'; // Sync icon.
isSplitViewOn = false;
constructor(
protected route: ActivatedRoute,
// @Optional() private svComponent: CoreSplitViewComponent,
) {
constructor() {
this.notificationsEnabled = CoreLocalNotifications.instance.isAvailable();
this.siteHomeId = CoreSites.instance.getCurrentSiteHomeId();
this.currentSiteId = CoreSites.instance.getCurrentSiteId();
@ -150,8 +145,15 @@ export class AddonCalendarEventPage implements OnInit, OnDestroy {
* View loaded.
*/
ngOnInit(): void {
this.eventId = this.route.snapshot.queryParams['id'];
const eventId = CoreNavigator.instance.getRouteNumberParam('id');
if (!eventId) {
CoreDomUtils.instance.showErrorModal('Event ID not supplied.');
CoreNavigator.instance.back();
return;
}
this.eventId = eventId;
this.syncIcon = 'spinner';
this.fetchEvent();

View File

@ -168,12 +168,12 @@ export class AddonCalendarIndexPage implements OnInit, OnDestroy {
ngOnInit(): void {
this.notificationsEnabled = CoreLocalNotifications.instance.isAvailable();
this.route.queryParams.subscribe(params => {
this.eventId = parseInt(params['eventId'], 10) || undefined;
this.filter.courseId = parseInt(params['courseId'], 10) || -1;
this.year = parseInt(params['year'], 10) || undefined;
this.month = parseInt(params['month'], 10) || undefined;
this.loadUpcoming = !!params['upcoming'];
this.route.queryParams.subscribe(() => {
this.eventId = CoreNavigator.instance.getRouteNumberParam('eventId');
this.filter.courseId = CoreNavigator.instance.getRouteNumberParam('courseId') || -1;
this.year = CoreNavigator.instance.getRouteNumberParam('year');
this.month = CoreNavigator.instance.getRouteNumberParam('month');
this.loadUpcoming = !!CoreNavigator.instance.getRouteBooleanParam('upcoming');
this.showCalendar = !this.loadUpcoming;
this.filter.filtered = this.filter.courseId > 0;

View File

@ -34,7 +34,7 @@ import { CoreApp } from '@services/app';
import moment from 'moment';
import { CoreConstants } from '@/core/constants';
import { AddonCalendarFilterPopoverComponent } from '../../components/filter/filter';
import { ActivatedRoute, Params } from '@angular/router';
import { Params } from '@angular/router';
import { Subscription } from 'rxjs';
import { Network, NgZone } from '@singletons';
import { CoreCoursesHelper } from '@features/courses/services/courses-helper';
@ -102,7 +102,6 @@ export class AddonCalendarListPage implements OnInit, OnDestroy {
};
constructor(
protected route: ActivatedRoute,
private popoverCtrl: PopoverController,
) {
@ -248,8 +247,8 @@ export class AddonCalendarListPage implements OnInit, OnDestroy {
* View loaded.
*/
async ngOnInit(): Promise<void> {
this.eventId = this.route.snapshot.queryParams['eventId'] || undefined;
this.filter.courseId = this.route.snapshot.queryParams['courseId'];
this.eventId = CoreNavigator.instance.getRouteNumberParam('eventId');
this.filter.courseId = CoreNavigator.instance.getRouteNumberParam('courseId') || -1;
if (this.eventId) {
// There is an event to load, open the event in a new state.

View File

@ -13,7 +13,6 @@
// limitations under the License.
import { Component, OnDestroy, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { IonRefresher } from '@ionic/angular';
import { Md5 } from 'ts-md5/dist/md5';
@ -59,9 +58,7 @@ export class AddonPrivateFilesIndexPage implements OnInit, OnDestroy {
protected updateSiteObserver: CoreEventObserver;
constructor(
protected route: ActivatedRoute,
) {
constructor() {
// Update visibility if current site info is updated.
this.updateSiteObserver = CoreEvents.on(CoreEvents.SITE_UPDATED, () => {
this.setVisibility();
@ -72,17 +69,18 @@ export class AddonPrivateFilesIndexPage implements OnInit, OnDestroy {
* Component being initialized.
*/
ngOnInit(): void {
this.root = this.route.snapshot.queryParams['root'];
this.root = CoreNavigator.instance.getRouteParam('root');
const contextId = CoreNavigator.instance.getRouteNumberParam('contextid');
if (this.route.snapshot.queryParams['contextid']) {
if (contextId) {
// Loading a certain folder.
this.path = {
contextid: this.route.snapshot.queryParams['contextid'],
component: this.route.snapshot.queryParams['component'],
filearea: this.route.snapshot.queryParams['filearea'],
itemid: this.route.snapshot.queryParams['itemid'],
filepath: this.route.snapshot.queryParams['filepath'],
filename: this.route.snapshot.queryParams['filename'],
contextid: contextId,
component: CoreNavigator.instance.getRouteParam<string>('component')!,
filearea: CoreNavigator.instance.getRouteParam<string>('filearea')!,
itemid: CoreNavigator.instance.getRouteNumberParam('itemid')!,
filepath: CoreNavigator.instance.getRouteParam<string>('filepath')!,
filename: CoreNavigator.instance.getRouteParam<string>('filename')!,
};
}

View File

@ -13,7 +13,6 @@
// limitations under the License.
import { Component, Input, OnInit, OnChanges, OnDestroy, SimpleChange } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { CoreApp } from '@services/app';
import { CoreSites } from '@services/sites';
@ -52,9 +51,7 @@ export class CoreUserAvatarComponent implements OnInit, OnChanges, OnDestroy {
protected currentUserId: number;
protected pictureObserver: CoreEventObserver;
constructor(
protected route: ActivatedRoute,
) {
constructor() {
this.currentUserId = CoreSites.instance.getCurrentSiteUserId();
this.pictureObserver = CoreEvents.on<CoreUserProfilePictureUpdatedData>(

View File

@ -13,7 +13,6 @@
// limitations under the License.
import { Directive, Input, OnInit, ElementRef } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { CoreNavigator } from '@services/navigator';
import { CoreObject } from '@singletons/object';
@ -33,7 +32,6 @@ export class CoreUserLinkDirective implements OnInit {
constructor(
element: ElementRef,
protected route: ActivatedRoute,
) {
this.element = element.nativeElement;
}

View File

@ -18,7 +18,6 @@ import { CoreDomUtils } from '@services/utils/dom';
import { Translate } from '@singletons';
import { CoreContentLinksAction } from '../../services/contentlinks-delegate';
import { CoreContentLinksHelper } from '../../services/contentlinks-helper';
import { ActivatedRoute } from '@angular/router';
import { CoreError } from '@classes/errors/error';
import { CoreNavigator } from '@services/navigator';
@ -33,26 +32,22 @@ import { CoreNavigator } from '@services/navigator';
})
export class CoreContentLinksChooseSitePage implements OnInit {
url: string;
url!: string;
sites: CoreSiteBasicInfo[] = [];
loaded = false;
protected action?: CoreContentLinksAction;
protected isRootURL = false;
constructor(
route: ActivatedRoute,
) {
this.url = route.snapshot.queryParamMap.get('url')!;
}
/**
* Component being initialized.
*/
async ngOnInit(): Promise<void> {
if (!this.url) {
const url = CoreNavigator.instance.getRouteParam<string>('url');
if (!url) {
return this.leaveView();
}
this.url = url;
let siteIds: string[] | undefined = [];
try {

View File

@ -19,7 +19,7 @@ import { CoreDomUtils } from '@services/utils/dom';
import { CoreUtils } from '@services/utils/utils';
import { CoreCategoryData, CoreCourses, CoreCourseSearchedData } from '../../services/courses';
import { Translate } from '@singletons';
import { ActivatedRoute } from '@angular/router';
import { CoreNavigator } from '@services/navigator';
/**
* Page that displays a list of categories and the courses in the current category if any.
@ -38,9 +38,7 @@ export class CoreCoursesCategoriesPage implements OnInit {
protected categoryId = 0;
constructor(
protected route: ActivatedRoute,
) {
constructor() {
this.title = Translate.instance.instant('core.courses.categories');
}
@ -48,7 +46,7 @@ export class CoreCoursesCategoriesPage implements OnInit {
* View loaded.
*/
ngOnInit(): void {
this.categoryId = parseInt(this.route.snapshot.params['id'], 0) || 0;
this.categoryId = CoreNavigator.instance.getRouteNumberParam('id') || 0;
this.fetchCategories().finally(() => {
this.categoriesLoaded = true;

View File

@ -13,7 +13,6 @@
// limitations under the License.
import { Component, OnInit, OnDestroy, ViewChild, ElementRef } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { CoreApp } from '@services/app';
@ -61,7 +60,6 @@ export class CoreLoginCredentialsPage implements OnInit, OnDestroy {
constructor(
protected fb: FormBuilder,
protected route: ActivatedRoute,
) {
const canScanQR = CoreUtils.instance.canScanQR();
@ -80,17 +78,23 @@ export class CoreLoginCredentialsPage implements OnInit, OnDestroy {
* Initialize the component.
*/
ngOnInit(): void {
this.route.queryParams.subscribe(params => {
this.siteUrl = params['siteUrl'];
this.siteName = params['siteName'] || undefined;
this.logoUrl = !CoreConstants.CONFIG.forceLoginLogo && params['logoUrl'] || undefined;
this.siteConfig = params['siteConfig'];
this.urlToOpen = params['urlToOpen'];
const siteUrl = CoreNavigator.instance.getRouteParam<string>('siteUrl');
if (!siteUrl) {
CoreDomUtils.instance.showErrorModal('Site URL not supplied.');
CoreNavigator.instance.back();
this.credForm = this.fb.group({
username: [params['username'] || '', Validators.required],
password: ['', Validators.required],
});
return;
}
this.siteUrl = siteUrl;
this.siteName = CoreNavigator.instance.getRouteParam('siteName');
this.logoUrl = !CoreConstants.CONFIG.forceLoginLogo && CoreNavigator.instance.getRouteParam('logoUrl') || undefined;
this.siteConfig = CoreNavigator.instance.getRouteParam('siteConfig');
this.urlToOpen = CoreNavigator.instance.getRouteParam('urlToOpen');
this.credForm = this.fb.group({
username: [CoreNavigator.instance.getRouteParam<string>('username') || '', Validators.required],
password: ['', Validators.required],
});
this.treatSiteConfig();

View File

@ -14,7 +14,6 @@
import { Component, ViewChild, ElementRef, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators, FormControl } from '@angular/forms';
import { ActivatedRoute } from '@angular/router';
import { IonContent, IonRefresher } from '@ionic/angular';
import { CoreSites } from '@services/sites';
@ -82,7 +81,6 @@ export class CoreLoginEmailSignupPage implements OnInit {
constructor(
protected fb: FormBuilder,
protected route: ActivatedRoute,
) {
// Create the ageVerificationForm.
this.ageVerificationForm = this.fb.group({
@ -115,7 +113,15 @@ export class CoreLoginEmailSignupPage implements OnInit {
* Component initialized.
*/
ngOnInit(): void {
this.siteUrl = this.route.snapshot.queryParams['siteUrl'];
const siteUrl = CoreNavigator.instance.getRouteParam<string>('siteUrl');
if (!siteUrl) {
CoreDomUtils.instance.showErrorModal('Site URL not supplied.');
CoreNavigator.instance.back();
return;
}
this.siteUrl = siteUrl;
// Fetch the data.
this.fetchData().finally(() => {

View File

@ -13,7 +13,6 @@
// limitations under the License.
import { Component, ViewChild, ElementRef, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { CoreDomUtils } from '@services/utils/dom';
@ -39,7 +38,6 @@ export class CoreLoginForgottenPasswordPage implements OnInit {
constructor(
protected formBuilder: FormBuilder,
protected route: ActivatedRoute,
) {
}
@ -47,13 +45,19 @@ export class CoreLoginForgottenPasswordPage implements OnInit {
* Initialize the component.
*/
ngOnInit(): void {
const params = this.route.snapshot.queryParams;
const siteUrl = CoreNavigator.instance.getRouteParam<string>('siteUrl');
if (!siteUrl) {
CoreDomUtils.instance.showErrorModal('Site URL not supplied.');
CoreNavigator.instance.back();
this.siteUrl = params['siteUrl'];
return;
}
this.siteUrl = siteUrl;
this.autoFocus = Platform.instance.is('tablet');
this.myForm = this.formBuilder.group({
field: ['username', Validators.required],
value: [params['username'] || '', Validators.required],
value: [CoreNavigator.instance.getRouteParam<string>('username') || '', Validators.required],
});
}

View File

@ -13,7 +13,7 @@
// limitations under the License.
import { Component, OnInit, OnDestroy, ViewChild, ElementRef } from '@angular/core';
import { ActivatedRoute, Params } from '@angular/router';
import { Params } from '@angular/router';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { CoreApp } from '@services/app';
@ -60,7 +60,6 @@ export class CoreLoginReconnectPage implements OnInit, OnDestroy {
constructor(
protected fb: FormBuilder,
protected route: ActivatedRoute,
) {
const currentSite = CoreSites.instance.getCurrentSite();
@ -75,11 +74,14 @@ export class CoreLoginReconnectPage implements OnInit, OnDestroy {
* Initialize the component.
*/
async ngOnInit(): Promise<void> {
const params = this.route.snapshot.queryParams;
const siteId = CoreNavigator.instance.getRouteParam<string>('siteId');
if (!siteId) {
return this.cancel();
}
this.siteId = params['siteId'];
this.page = params['pageName'];
this.pageParams = params['pageParams'];
this.siteUrl = siteId;
this.page = CoreNavigator.instance.getRouteParam('pageName');
this.pageParams = CoreNavigator.instance.getRouteParam('pageParams');
try {
const site = await CoreSites.instance.getSite(this.siteId);

View File

@ -13,7 +13,6 @@
// limitations under the License.
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { CoreSites } from '@services/sites';
import { CoreDomUtils } from '@services/utils/dom';
@ -38,18 +37,12 @@ export class CoreLoginSitePolicyPage implements OnInit {
protected siteId?: string;
protected currentSite?: CoreSite;
constructor(
protected route: ActivatedRoute,
) {
}
/**
* Component initialized.
*/
ngOnInit(): void {
const params = this.route.snapshot.queryParams;
this.siteId = params['siteId'];
this.siteId = CoreNavigator.instance.getRouteParam('siteId');
this.currentSite = CoreSites.instance.getCurrentSite();
if (!this.currentSite) {

View File

@ -13,7 +13,6 @@
// limitations under the License.
import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { FormBuilder, FormGroup, ValidatorFn, AbstractControl, ValidationErrors } from '@angular/forms';
import { CoreApp } from '@services/app';
@ -59,7 +58,6 @@ export class CoreLoginSitePage implements OnInit {
siteFinderSettings: SiteFinderSettings;
constructor(
protected route: ActivatedRoute,
protected formBuilder: FormBuilder,
) {
@ -115,9 +113,7 @@ export class CoreLoginSitePage implements OnInit {
* Initialize the component.
*/
ngOnInit(): void {
this.route.queryParams.subscribe(params => {
this.showKeyboard = !!params['showKeyboard'];
});
this.showKeyboard = !!CoreNavigator.instance.getRouteBooleanParam('showKeyboard');
}
/**

View File

@ -13,7 +13,6 @@
// limitations under the License.
import { Component } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { CoreConstants } from '@/core/constants';
import { CoreSites } from '@services/sites';
@ -32,9 +31,7 @@ export class CoreSettingsAboutPage {
versionName: string;
privacyPolicy: string;
constructor(
protected route: ActivatedRoute,
) {
constructor() {
const currentSite = CoreSites.instance.getCurrentSite();
this.appName = CoreConstants.CONFIG.appname;

View File

@ -13,7 +13,7 @@
// limitations under the License.
import { Component, OnDestroy, OnInit } from '@angular/core';
import { ActivatedRoute, Params, Router } from '@angular/router';
import { Params } from '@angular/router';
import { IonRefresher } from '@ionic/angular';
import { CoreSettingsDelegate, CoreSettingsHandlerData } from '../../services/settings-delegate';
@ -57,16 +57,11 @@ export class CoreSitePreferencesPage implements OnInit, OnDestroy {
protected sitesObserver: CoreEventObserver;
protected isDestroyed = false;
constructor(
protected route: ActivatedRoute,
protected router: Router, // Will be removed when splitview is implemented
) {
constructor() {
this.isIOS = CoreApp.instance.isIOS();
this.siteId = CoreSites.instance.getCurrentSiteId();
this.selectedPage = route.snapshot.paramMap.get('page') || undefined;
this.sitesObserver = CoreEvents.on(CoreEvents.SITE_UPDATED, (data: CoreEventSiteUpdatedData) => {
if (data.siteId == this.siteId) {
this.refreshData();
@ -78,6 +73,8 @@ export class CoreSitePreferencesPage implements OnInit, OnDestroy {
* View loaded.
*/
ngOnInit(): void {
// @todo this.selectedPage = route.snapshot.paramMap.get('page') || undefined;
this.fetchData().finally(() => {
this.loaded = true;

View File

@ -13,8 +13,8 @@
// limitations under the License.
import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { IonRefresher } from '@ionic/angular';
import { Params } from '@angular/router';
import { CoreSite, CoreSiteConfig } from '@classes/site';
import { CoreCourse, CoreCourseModuleBasicInfo, CoreCourseWSSection } from '@features/course/services/course';
@ -23,7 +23,7 @@ import { CoreSites } from '@services/sites';
import { CoreSiteHome } from '@features/sitehome/services/sitehome';
import { CoreCourses, CoreCoursesProvider } from '@features//courses/services/courses';
import { CoreEventObserver, CoreEvents } from '@singletons/events';
import { CoreCourseHelper } from '@features/course/services/course-helper';
import { CoreCourseHelper, CoreCourseModule } from '@features/course/services/course-helper';
import { CoreBlockCourseBlocksComponent } from '@features/block/components/course-blocks/course-blocks';
import { CoreCourseModuleDelegate, CoreCourseModuleHandlerData } from '@features/course/services/module-delegate';
import { CoreCourseModulePrefetchDelegate } from '@features/course/services/module-prefetch-delegate';
@ -58,16 +58,10 @@ export class CoreSiteHomeIndexPage implements OnInit, OnDestroy {
protected updateSiteObserver?: CoreEventObserver;
constructor(
protected route: ActivatedRoute,
) {}
/**
* Page being initialized.
*/
ngOnInit(): void {
const navParams = this.route.snapshot.queryParams;
this.searchEnabled = !CoreCourses.instance.isSearchCoursesDisabledInSite();
this.downloadCourseEnabled = !CoreCourses.instance.isDownloadCourseDisabledInSite();
this.downloadCoursesEnabled = !CoreCourses.instance.isDownloadCoursesDisabledInSite();
@ -84,9 +78,9 @@ export class CoreSiteHomeIndexPage implements OnInit, OnDestroy {
this.currentSite = CoreSites.instance.getCurrentSite()!;
this.siteHomeId = CoreSites.instance.getCurrentSiteHomeId();
const module = navParams['module'];
const module = CoreNavigator.instance.getRouteParam<CoreCourseModule>('module');
if (module) {
const modParams = navParams['modParams'];
const modParams = CoreNavigator.instance.getRouteParam<Params>('modParams');
CoreCourseHelper.instance.openModule(module, this.siteHomeId, undefined, modParams);
}

View File

@ -16,10 +16,9 @@ import { Component, OnInit, Type } from '@angular/core';
import { IonInfiniteScroll, IonRefresher } from '@ionic/angular';
import { CoreDomUtils } from '@services/utils/dom';
import { CoreTag } from '@features/tag/services/tag';
import { ActivatedRoute } from '@angular/router';
import { CoreTagAreaDelegate } from '../../services/tag-area-delegate';
import { Translate } from '@singletons';
import { CoreUtils } from '@services/utils/utils';
import { CoreNavigator } from '@services/navigator';
/**
* Page that displays the tag index area.
@ -50,32 +49,25 @@ export class CoreTagIndexAreaPage implements OnInit {
areaComponent?: Type<unknown>;
loadMoreError = false;
constructor(
protected route: ActivatedRoute,
) { }
/**
* View loaded.
*/
async ngOnInit(): Promise<void> {
this.tagId = CoreNavigator.instance.getRouteNumberParam('tagId') || this.tagId;
this.tagName = CoreNavigator.instance.getRouteParam('tagName') || this.tagName;
this.collectionId = CoreNavigator.instance.getRouteNumberParam('collectionId') || this.collectionId;
this.areaId = CoreNavigator.instance.getRouteNumberParam('areaId') || this.areaId;
this.fromContextId = CoreNavigator.instance.getRouteNumberParam('fromContextId') || this.fromContextId;
this.contextId = CoreNavigator.instance.getRouteNumberParam('contextId') || this.contextId;
this.recursive = CoreNavigator.instance.getRouteBooleanParam('recursive') ?? true;
const navParams = this.route.snapshot.queryParams;
this.tagId = navParams['tagId'] ? parseInt(navParams['tagId'], 10) : this.tagId;
this.tagName = navParams['tagName'] || this.tagName;
this.collectionId = navParams['collectionId'] ? parseInt(navParams['collectionId'], 10) : this.collectionId;
this.areaId = navParams['areaId'] ? parseInt(navParams['areaId']!, 10) : this.areaId;
this.fromContextId = parseInt(navParams['fromContextId'], 10) || this.fromContextId;
this.contextId = navParams['contextId'] ? parseInt(navParams['contextId'], 10) : this.contextId;
this.recursive = typeof navParams['recursive'] == 'undefined'? true : navParams['recursive'];
this.areaNameKey = navParams['areaNameKey'];
this.areaNameKey = CoreNavigator.instance.getRouteParam('areaNameKey') || '';
// Pass the the following parameters to avoid fetching the first page.
this.componentName = navParams['componentName'];
this.itemType = navParams['itemType'];
this.items = []; // @todo navParams['items'] || [];
this.nextPage = typeof navParams['nextPage'] != 'undefined' ? parseInt(navParams['nextPage'], 10) : 0;
this.canLoadMore = CoreUtils.instance.isTrueOrOne(navParams['canLoadMore']);
this.componentName = CoreNavigator.instance.getRouteParam('componentName');
this.itemType = CoreNavigator.instance.getRouteParam('itemType');
this.items = CoreNavigator.instance.getRouteParam<unknown[]>('items') || [];
this.nextPage = CoreNavigator.instance.getRouteNumberParam('nextPage') || 0;
this.canLoadMore = CoreNavigator.instance.getRouteBooleanParam('canLoadMore') || false;
try {
if (!this.componentName || !this.itemType || !this.items.length || this.nextPage == 0) {

View File

@ -18,7 +18,6 @@ import { CoreDomUtils } from '@services/utils/dom';
// import { CoreSplitViewComponent } from '@components/split-view/split-view';
import { CoreTag } from '@features/tag/services/tag';
import { CoreTagAreaDelegate } from '@features/tag/services/tag-area-delegate';
import { ActivatedRoute, Router } from '@angular/router';
import { CoreNavigator } from '@services/navigator';
/**
@ -45,24 +44,17 @@ export class CoreTagIndexPage implements OnInit {
areas: (CoreTagAreaDisplay | null)[] = [];
constructor(
protected route: ActivatedRoute,
protected router: Router,
) { }
/**
* View loaded.
*/
async ngOnInit(): Promise<void> {
const navParams = this.route.snapshot.queryParams;
this.tagId = navParams['tagId'] ? parseInt(navParams['tagId'], 10) : this.tagId;
this.tagName = navParams['tagName'] || this.tagName;
this.collectionId = navParams['collectionId'] ? parseInt(navParams['collectionId'], 10) : this.collectionId;
this.areaId = navParams['areaId'] ? parseInt(navParams['areaId']!, 10) : this.areaId;
this.fromContextId = parseInt(navParams['fromContextId'], 10) || this.fromContextId;
this.contextId = navParams['contextId'] ? parseInt(navParams['contextId'], 10) : this.contextId;
this.recursive = typeof navParams['recursive'] == 'undefined'? true : navParams['recursive'];
this.tagId = CoreNavigator.instance.getRouteNumberParam('tagId') || this.tagId;
this.tagName = CoreNavigator.instance.getRouteParam('tagName') || this.tagName;
this.collectionId = CoreNavigator.instance.getRouteNumberParam('collectionId') || this.collectionId;
this.areaId = CoreNavigator.instance.getRouteNumberParam('areaId') || this.areaId;
this.fromContextId = CoreNavigator.instance.getRouteNumberParam('fromContextId') || this.fromContextId;
this.contextId = CoreNavigator.instance.getRouteNumberParam('contextId') || this.contextId;
this.recursive = CoreNavigator.instance.getRouteBooleanParam('recursive') ?? true;
try {
await this.fetchData();

View File

@ -14,7 +14,6 @@
import { Component, OnInit } from '@angular/core';
import { IonRefresher } from '@ionic/angular';
import { ActivatedRoute } from '@angular/router';
import { CoreApp } from '@services/app';
import { CoreDomUtils } from '@services/utils/dom';
@ -23,6 +22,7 @@ import { CoreTextUtils } from '@services/utils/text';
import { CoreTagCloud, CoreTagCollection, CoreTagCloudTag, CoreTag } from '@features/tag/services/tag';
import { Translate } from '@singletons';
import { CoreContentLinksHelper } from '@features/contentlinks/services/contentlinks-helper';
import { CoreNavigator } from '@services/navigator';
/**
* Page that displays most used tags and allows searching.
@ -41,20 +41,12 @@ export class CoreTagSearchPage implements OnInit {
loaded = false;
searching = false;
constructor(
protected route: ActivatedRoute,
) {
}
/**
* View loaded.
*/
ngOnInit(): void {
// @todo: Check params work.
this.collectionId = this.route.snapshot.queryParamMap.has('collectionId') ?
parseInt(this.route.snapshot.queryParamMap.get('collectionId')!, 10) : 0;
this.query = this.route.snapshot.queryParamMap.get('query') || '';
this.collectionId = CoreNavigator.instance.getRouteNumberParam('collectionId') || 0;
this.query = CoreNavigator.instance.getRouteParam('query') || '';
this.fetchData().finally(() => {
this.loaded = true;

View File

@ -13,7 +13,6 @@
// limitations under the License.
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { SafeUrl } from '@angular/platform-browser';
import { IonRefresher } from '@ionic/angular';
@ -24,6 +23,7 @@ import { CoreUtils } from '@services/utils/utils';
import { CoreEvents } from '@singletons/events';
import { CoreUser, CoreUserProfile, CoreUserProfileRefreshedData, CoreUserProvider } from '@features/user/services/user';
import { CoreUserHelper } from '@features/user/services/user-helper';
import { CoreNavigator } from '@services/navigator';
/**
* Page that displays info about a user.
@ -46,9 +46,7 @@ export class CoreUserAboutPage implements OnInit {
formattedAddress?: string;
encodedAddress?: SafeUrl;
constructor(
protected route: ActivatedRoute,
) {
constructor() {
this.siteId = CoreSites.instance.getCurrentSiteId();
}
@ -58,8 +56,8 @@ export class CoreUserAboutPage implements OnInit {
* @return Promise resolved when done.
*/
async ngOnInit(): Promise<void> {
this.userId = parseInt(this.route.snapshot.queryParams['userId'], 10) || 0;
this.courseId = parseInt(this.route.snapshot.queryParams['courseId'], 10) || 0;
this.userId = CoreNavigator.instance.getRouteNumberParam('userId') || 0;
this.courseId = CoreNavigator.instance.getRouteNumberParam('courseId') || 0;
this.fetchUser().finally(() => {
this.userLoaded = true;

View File

@ -13,7 +13,6 @@
// limitations under the License.
import { Component, OnDestroy, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { IonRefresher } from '@ionic/angular';
import { Subscription } from 'rxjs';
@ -44,7 +43,7 @@ import { CoreNavigator } from '@services/navigator';
})
export class CoreUserProfilePage implements OnInit, OnDestroy {
protected courseId!: number;
protected courseId?: number;
protected userId!: number;
protected site?: CoreSite;
protected obsProfileRefreshed: CoreEventObserver;
@ -62,10 +61,7 @@ export class CoreUserProfilePage implements OnInit, OnDestroy {
newPageHandlers: CoreUserProfileHandlerData[] = [];
communicationHandlers: CoreUserProfileHandlerData[] = [];
constructor(
protected route: ActivatedRoute,
) {
constructor() {
this.obsProfileRefreshed = CoreEvents.on<CoreUserProfileRefreshedData>(CoreUserProvider.PROFILE_REFRESHED, (data) => {
if (!this.user || !data.user) {
return;
@ -81,12 +77,20 @@ export class CoreUserProfilePage implements OnInit, OnDestroy {
*/
async ngOnInit(): Promise<void> {
this.site = CoreSites.instance.getCurrentSite();
this.userId = parseInt(this.route.snapshot.queryParams['userId'], 10);
this.courseId = parseInt(this.route.snapshot.queryParams['courseId'], 10);
this.courseId = CoreNavigator.instance.getRouteNumberParam('courseId');
const userId = CoreNavigator.instance.getRouteNumberParam('userId');
if (!this.site) {
return;
}
if (userId === undefined) {
CoreDomUtils.instance.showErrorModal('User ID not supplied');
CoreNavigator.instance.back();
return;
}
this.userId = userId;
// Allow to change the profile image only in the app profile page.
this.canChangeProfilePicture =

View File

@ -51,7 +51,7 @@ export interface CoreUserProfileHandler extends CoreDelegateHandler {
*/
isEnabledForUser(
user: CoreUserProfile,
courseId: number,
courseId?: number,
navOptions?: CoreCourseUserAdminOrNavOptionIndexed,
admOptions?: CoreCourseUserAdminOrNavOptionIndexed,
): Promise<boolean>;
@ -63,7 +63,7 @@ export interface CoreUserProfileHandler extends CoreDelegateHandler {
* @param courseId Course ID where to show.
* @return Data to be shown.
*/
getDisplayData(user: CoreUserProfile, courseId: number): CoreUserProfileHandlerData;
getDisplayData(user: CoreUserProfile, courseId?: number): CoreUserProfileHandlerData;
}
/**
@ -218,7 +218,7 @@ export class CoreUserDelegateService extends CoreDelegate<CoreUserProfileHandler
* @param courseId The course ID.
* @return Resolved with the handlers.
*/
getProfileHandlersFor(user: CoreUserProfile, courseId: number): Subject<CoreUserProfileHandlerToDisplay[]> {
getProfileHandlersFor(user: CoreUserProfile, courseId?: number): Subject<CoreUserProfileHandlerToDisplay[]> {
// Initialize the user handlers if it isn't initialized already.
if (!this.userHandlers[user.id]) {
this.userHandlers[user.id] = {
@ -240,7 +240,7 @@ export class CoreUserDelegateService extends CoreDelegate<CoreUserProfileHandler
* @param courseId The course ID.
* @return Promise resolved when done.
*/
protected async calculateUserHandlers(user: CoreUserProfile, courseId: number): Promise<void> {
protected async calculateUserHandlers(user: CoreUserProfile, courseId?: number): Promise<void> {
// @todo: Get Course admin/nav options.
let navOptions;
let admOptions;

View File

@ -812,7 +812,7 @@ export class CoreUser extends makeSingleton(CoreUserProvider) {}
* Data passed to PROFILE_REFRESHED event.
*/
export type CoreUserProfileRefreshedData = {
courseId: number; // Course the user profile belongs to.
courseId?: number; // Course the user profile belongs to.
userId: number; // User ID.
user?: CoreUserProfile; // User affected.
};