MOBILE-2735 ux: Make all link handlers open a new page

main
Dani Palou 2019-06-18 09:50:14 +02:00
parent 04ebb8e50c
commit 08322a299d
30 changed files with 219 additions and 73 deletions

View File

@ -15,7 +15,7 @@
import { Injectable } from '@angular/core';
import { CoreContentLinksHandlerBase } from '@core/contentlinks/classes/base-handler';
import { CoreContentLinksAction } from '@core/contentlinks/providers/delegate';
import { CoreLoginHelperProvider } from '@core/login/providers/helper';
import { CoreContentLinksHelperProvider } from '@core/contentlinks/providers/helper';
import { AddonBadgesProvider } from './badges';
/**
@ -26,7 +26,7 @@ export class AddonBadgesBadgeLinkHandler extends CoreContentLinksHandlerBase {
name = 'AddonBadgesBadgeLinkHandler';
pattern = /\/badges\/badge\.php.*([\?\&]hash=)/;
constructor(private badgesProvider: AddonBadgesProvider, private loginHelper: CoreLoginHelperProvider) {
constructor(private badgesProvider: AddonBadgesProvider, private linkHelper: CoreContentLinksHelperProvider) {
super();
}
@ -44,8 +44,7 @@ export class AddonBadgesBadgeLinkHandler extends CoreContentLinksHandlerBase {
return [{
action: (siteId, navCtrl?): void => {
// Always use redirect to make it the new history root (to avoid "loops" in history).
this.loginHelper.redirect('AddonBadgesIssuedBadgePage', {courseId: 0, badgeHash: params.hash}, siteId);
this.linkHelper.goInSite(navCtrl, 'AddonBadgesIssuedBadgePage', {courseId: 0, badgeHash: params.hash}, siteId);
}
}];
}

View File

@ -15,7 +15,7 @@
import { Injectable } from '@angular/core';
import { CoreContentLinksHandlerBase } from '@core/contentlinks/classes/base-handler';
import { CoreContentLinksAction } from '@core/contentlinks/providers/delegate';
import { CoreLoginHelperProvider } from '@core/login/providers/helper';
import { CoreContentLinksHelperProvider } from '@core/contentlinks/providers/helper';
import { AddonBadgesProvider } from './badges';
/**
@ -27,7 +27,7 @@ export class AddonBadgesMyBadgesLinkHandler extends CoreContentLinksHandlerBase
featureName = 'CoreUserDelegate_AddonBadges';
pattern = /\/badges\/mybadges\.php/;
constructor(private badgesProvider: AddonBadgesProvider, private loginHelper: CoreLoginHelperProvider) {
constructor(private badgesProvider: AddonBadgesProvider, private linkHelper: CoreContentLinksHelperProvider) {
super();
}
@ -45,8 +45,7 @@ export class AddonBadgesMyBadgesLinkHandler extends CoreContentLinksHandlerBase
return [{
action: (siteId, navCtrl?): void => {
// Always use redirect to make it the new history root (to avoid "loops" in history).
this.loginHelper.redirect('AddonBadgesUserBadgesPage', {}, siteId);
this.linkHelper.goInSite(navCtrl, 'AddonBadgesUserBadgesPage', {}, siteId);
}
}];
}

View File

@ -15,7 +15,7 @@
import { Injectable } from '@angular/core';
import { CoreContentLinksHandlerBase } from '@core/contentlinks/classes/base-handler';
import { CoreContentLinksAction } from '@core/contentlinks/providers/delegate';
import { CoreLoginHelperProvider } from '@core/login/providers/helper';
import { CoreContentLinksHelperProvider } from '@core/contentlinks/providers/helper';
import { AddonBlogProvider } from './blog';
/**
@ -27,7 +27,7 @@ export class AddonBlogIndexLinkHandler extends CoreContentLinksHandlerBase {
featureName = 'CoreUserDelegate_AddonBlog:blogs';
pattern = /\/blog\/index\.php/;
constructor(private blogProvider: AddonBlogProvider, private loginHelper: CoreLoginHelperProvider) {
constructor(private blogProvider: AddonBlogProvider, private linkHelper: CoreContentLinksHelperProvider) {
super();
}
@ -53,8 +53,7 @@ export class AddonBlogIndexLinkHandler extends CoreContentLinksHandlerBase {
return [{
action: (siteId, navCtrl?): void => {
// Always use redirect to make it the new history root (to avoid "loops" in history).
this.loginHelper.redirect('AddonBlogEntriesPage', pageParams, siteId);
this.linkHelper.goInSite(navCtrl, 'AddonBlogEntriesPage', pageParams, siteId, !Object.keys(pageParams).length);
}
}];
}

View File

@ -63,7 +63,7 @@ export class AddonBlogUserHandler implements CoreUserProfileHandler {
action: (event, navCtrl, user, courseId): void => {
event.preventDefault();
event.stopPropagation();
// Always use redirect to make it the new history root (to avoid "loops" in history).
this.linkHelper.goInSite(navCtrl, 'AddonBlogEntriesPage', { userId: user.id, courseId: courseId });
}
};

View File

@ -15,7 +15,7 @@
import { Injectable } from '@angular/core';
import { CoreContentLinksHandlerBase } from '@core/contentlinks/classes/base-handler';
import { CoreContentLinksAction } from '@core/contentlinks/providers/delegate';
import { CoreLoginHelperProvider } from '@core/login/providers/helper';
import { CoreContentLinksHelperProvider } from '@core/contentlinks/providers/helper';
import { AddonCompetencyProvider } from './competency';
/**
@ -26,7 +26,7 @@ export class AddonCompetencyPlansLinkHandler extends CoreContentLinksHandlerBase
name = 'AddonCompetencyPlansLinkHandler';
pattern = /\/admin\/tool\/lp\/plans\.php/;
constructor(private loginHelper: CoreLoginHelperProvider, private competencyProvider: AddonCompetencyProvider) {
constructor(private linkHelper: CoreContentLinksHelperProvider, private competencyProvider: AddonCompetencyProvider) {
super();
}
@ -44,8 +44,8 @@ export class AddonCompetencyPlansLinkHandler extends CoreContentLinksHandlerBase
return [{
action: (siteId, navCtrl?): void => {
// Always use redirect to make it the new history root (to avoid "loops" in history).
this.loginHelper.redirect('AddonCompetencyPlanListPage', { userId: params.userid }, siteId);
this.linkHelper.goInSite(navCtrl, 'AddonCompetencyPlanListPage', { userId: params.userid }, siteId,
typeof params.userid == 'undefined');
}
}];
}

View File

@ -111,7 +111,7 @@ export class AddonCompetencyUserHandler implements CoreUserProfileHandler {
action: (event, navCtrl, user, courseId): void => {
event.preventDefault();
event.stopPropagation();
// Always use redirect to make it the new history root (to avoid "loops" in history).
this.linkHelper.goInSite(navCtrl, 'AddonCompetencyCourseCompetenciesPage', {courseId, userId: user.id});
}
};
@ -123,7 +123,7 @@ export class AddonCompetencyUserHandler implements CoreUserProfileHandler {
action: (event, navCtrl, user, courseId): void => {
event.preventDefault();
event.stopPropagation();
// Always use redirect to make it the new history root (to avoid "loops" in history).
this.linkHelper.goInSite(navCtrl, 'AddonCompetencyPlanListPage', {userId: user.id});
}
};

View File

@ -43,7 +43,6 @@ export class AddonMessagesContactRequestLinkHandler extends CoreContentLinksHand
CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> {
return [{
action: (siteId, navCtrl?): void => {
// Always use redirect to make it the new history root (to avoid "loops" in history).
this.linkHelper.goInSite(navCtrl, 'AddonMessagesContactsPage', {}, siteId);
}
}];

View File

@ -49,7 +49,6 @@ export class AddonMessagesDiscussionLinkHandler extends CoreContentLinksHandlerB
const stateParams = {
userId: parseInt(params.id || params.user2, 10)
};
// Always use redirect to make it the new history root (to avoid "loops" in history).
this.linkHelper.goInSite(navCtrl, 'AddonMessagesDiscussionPage', stateParams, siteId);
}
}];

View File

@ -49,7 +49,6 @@ export class AddonMessagesIndexLinkHandler extends CoreContentLinksHandlerBase {
pageName = 'AddonMessagesGroupConversationsPage';
}
// Always use redirect to make it the new history root (to avoid "loops" in history).
this.linkHelper.goInSite(navCtrl, pageName, undefined, siteId);
}
}];

View File

@ -76,7 +76,6 @@ export class AddonMessagesSendMessageUserHandler implements CoreUserProfileHandl
showKeyboard: true,
userId: user.id
};
// Always use redirect to make it the new history root (to avoid "loops" in history).
this.linkHelper.goInSite(navCtrl, 'AddonMessagesDiscussionPage', pageParams);
}
};

View File

@ -99,7 +99,7 @@ export class AddonNotesUserHandler implements CoreUserProfileHandler {
action: (event, navCtrl, user, courseId): void => {
event.preventDefault();
event.stopPropagation();
// Always use redirect to make it the new history root (to avoid "loops" in history).
this.linkHelper.goInSite(navCtrl, 'AddonNotesListPage', { userId: user.id, courseId: courseId });
}
};

View File

@ -63,7 +63,6 @@ export class CoreContentLinksModuleListHandler extends CoreContentLinksHandlerBa
title: this.title || this.translate.instant('addon.mod_' + this.modName + '.modulenameplural')
};
// Always use redirect to make it the new history root (to avoid "loops" in history).
this.linkHelper.goInSite(navCtrl, 'CoreCourseListModTypePage', stateParams, siteId);
}
}];

View File

@ -30,6 +30,7 @@ import { CoreConstants } from '@core/constants';
import { CoreConfigConstants } from '../../../configconstants';
import { CoreSitePluginsProvider } from '@core/siteplugins/providers/siteplugins';
import { CoreSite } from '@classes/site';
import { CoreMainMenuProvider } from '@core/mainmenu/providers/mainmenu';
/**
* Service that provides some features regarding content links.
@ -42,7 +43,8 @@ export class CoreContentLinksHelperProvider {
private contentLinksDelegate: CoreContentLinksDelegate, private appProvider: CoreAppProvider,
private domUtils: CoreDomUtilsProvider, private urlUtils: CoreUrlUtilsProvider, private translate: TranslateService,
private initDelegate: CoreInitDelegate, eventsProvider: CoreEventsProvider, private textUtils: CoreTextUtilsProvider,
private sitePluginsProvider: CoreSitePluginsProvider, private zone: NgZone, private utils: CoreUtilsProvider) {
private sitePluginsProvider: CoreSitePluginsProvider, private zone: NgZone, private utils: CoreUtilsProvider,
private mainMenuProvider: CoreMainMenuProvider) {
this.logger = logger.getInstance('CoreContentLinksHelperProvider');
}
@ -103,9 +105,10 @@ export class CoreContentLinksHelperProvider {
* @param {string} pageName Name of the page to go.
* @param {any} [pageParams] Params to send to the page.
* @param {string} [siteId] Site ID. If not defined, current site.
* @param {boolean} [checkMenu] If true, check if the root page of a main menu tab. Only the page name will be checked.
* @return {Promise<any>} Promise resolved when done.
*/
goInSite(navCtrl: NavController, pageName: string, pageParams: any, siteId?: string): Promise<any> {
goInSite(navCtrl: NavController, pageName: string, pageParams: any, siteId?: string, checkMenu?: boolean): Promise<any> {
siteId = siteId || this.sitesProvider.getCurrentSiteId();
const deferred = this.utils.promiseDefer();
@ -113,7 +116,23 @@ export class CoreContentLinksHelperProvider {
// Execute the code in the Angular zone, so change detection doesn't stop working.
this.zone.run(() => {
if (navCtrl && siteId == this.sitesProvider.getCurrentSiteId()) {
navCtrl.push(pageName, pageParams).then(deferred.resolve, deferred.reject);
if (checkMenu) {
// Check if the page is in the main menu.
this.mainMenuProvider.isCurrentMainMenuHandler(pageName, pageParams).catch(() => {
return false; // Shouldn't happen.
}).then((isInMenu) => {
if (isInMenu) {
// Just select the tab.
this.loginHelper.loadPageInMainMenu(pageName, pageParams);
deferred.resolve();
} else {
navCtrl.push(pageName, pageParams).then(deferred.resolve, deferred.reject);
}
});
} else {
navCtrl.push(pageName, pageParams).then(deferred.resolve, deferred.reject);
}
} else {
this.loginHelper.redirect(pageName, pageParams, siteId).then(deferred.resolve, deferred.reject);
}

View File

@ -245,7 +245,6 @@ export class CoreCourseModuleMainResourceComponent implements OnInit, OnDestroy,
* @param {any} event Event.
*/
gotoBlog(event: any): void {
// Always use redirect to make it the new history root (to avoid "loops" in history).
this.linkHelper.goInSite(this.navCtrl, 'AddonBlogEntriesPage', { cmId: this.module.id });
}

View File

@ -76,6 +76,7 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy {
loaded: boolean;
protected sectionStatusObserver;
protected selectTabObserver;
protected lastCourseFormat: string;
constructor(private cfDelegate: CoreCourseFormatDelegate, translate: TranslateService, private injector: Injector,
@ -124,6 +125,28 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy {
});
}
}, this.sitesProvider.getCurrentSiteId());
// Listen for select course tab events to select the right section if needed.
this.selectTabObserver = eventsProvider.on(CoreEventsProvider.SELECT_COURSE_TAB, (data) => {
if (!data.name) {
let section;
if (typeof data.sectionId != 'undefined' && data.sectionId != null && this.sections) {
section = this.sections.find((section) => {
return section.id == data.sectionId;
});
} else if (typeof data.sectionNumber != 'undefined' && data.sectionNumber != null && this.sections) {
section = this.sections.find((section) => {
return section.section == data.sectionNumber;
});
}
if (section) {
this.sectionChanged(section);
}
}
});
}
/**
@ -437,9 +460,8 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy {
* Component destroyed.
*/
ngOnDestroy(): void {
if (this.sectionStatusObserver) {
this.sectionStatusObserver.off();
}
this.sectionStatusObserver && this.sectionStatusObserver.off();
this.selectTabObserver && this.selectTabObserver.off();
}
/**

View File

@ -67,6 +67,7 @@ export class CoreCourseSectionPage implements OnDestroy {
protected modParams: any;
protected completionObserver;
protected courseStatusObserver;
protected selectTabObserver;
protected syncObserver;
protected firstTabName: string;
protected isDestroyed = false;
@ -120,6 +121,26 @@ export class CoreCourseSectionPage implements OnDestroy {
}
}, sitesProvider.getCurrentSiteId());
}
this.selectTabObserver = eventsProvider.on(CoreEventsProvider.SELECT_COURSE_TAB, (data) => {
if (!data.name) {
// If needed, set sectionId and sectionNumber. They'll only be used if the content tabs hasn't been loaded yet.
this.sectionId = data.sectionId || this.sectionId;
this.sectionNumber = data.sectionNumber || this.sectionNumber;
// Select course contents.
this.tabsComponent && this.tabsComponent.selectTab(0);
} else if (this.courseHandlers) {
const index = this.courseHandlers.findIndex((handler) => {
return handler.name == data.name;
});
if (index >= 0) {
this.tabsComponent && this.tabsComponent.selectTab(index + 1);
}
}
});
}
/**
@ -483,9 +504,8 @@ export class CoreCourseSectionPage implements OnDestroy {
*/
ngOnDestroy(): void {
this.isDestroyed = true;
if (this.completionObserver) {
this.completionObserver.off();
}
this.completionObserver && this.completionObserver.off();
this.selectTabObserver && this.selectTabObserver.off();
}
/**

View File

@ -164,6 +164,23 @@ export class CoreCourseProvider {
});
}
/**
* Check if the current view in a NavController is a certain course initial page.
*
* @param {NavController} navCtrl NavController.
* @param {number} courseId Course ID.
* @return {boolean} Whether the current view is a certain course.
*/
currentViewIsCourse(navCtrl: NavController, courseId: number): boolean {
if (navCtrl) {
const view = navCtrl.getActive();
return view && view.id == 'CoreCourseSectionPage' && view.data && view.data.course && view.data.course.id == courseId;
}
return false;
}
/**
* Get completion status of all the activities in a course for a certain user.
*
@ -973,6 +990,19 @@ export class CoreCourseProvider {
});
}
/**
* Select a certain tab in the course. Please use currentViewIsCourse() first to verify user is viewing the course.
*
* @param {string} [name] Name of the tab. If not provided, course contents.
* @param {any} [params] Other params.
*/
selectCourseTab(name?: string, params?: any): void {
params = params || {};
params.name = name || '';
this.eventsProvider.trigger(CoreEventsProvider.SELECT_COURSE_TAB, params);
}
/**
* Change the course status, setting it to the previous status.
*

View File

@ -119,15 +119,16 @@ export class CoreCourseHelperProvider {
protected logger;
constructor(private courseProvider: CoreCourseProvider, private domUtils: CoreDomUtilsProvider,
private moduleDelegate: CoreCourseModuleDelegate, private prefetchDelegate: CoreCourseModulePrefetchDelegate,
private filepoolProvider: CoreFilepoolProvider, private sitesProvider: CoreSitesProvider,
private textUtils: CoreTextUtilsProvider, private timeUtils: CoreTimeUtilsProvider,
private utils: CoreUtilsProvider, private translate: TranslateService, private loginHelper: CoreLoginHelperProvider,
private courseOptionsDelegate: CoreCourseOptionsDelegate, private siteHomeProvider: CoreSiteHomeProvider,
private eventsProvider: CoreEventsProvider, private fileHelper: CoreFileHelperProvider,
private appProvider: CoreAppProvider, private fileProvider: CoreFileProvider, private injector: Injector,
private coursesProvider: CoreCoursesProvider, private courseOffline: CoreCourseOfflineProvider,
private loggerProvider: CoreLoggerProvider) {
private moduleDelegate: CoreCourseModuleDelegate, private prefetchDelegate: CoreCourseModulePrefetchDelegate,
private filepoolProvider: CoreFilepoolProvider, private sitesProvider: CoreSitesProvider,
private textUtils: CoreTextUtilsProvider, private timeUtils: CoreTimeUtilsProvider,
private utils: CoreUtilsProvider, private translate: TranslateService, private loginHelper: CoreLoginHelperProvider,
private courseOptionsDelegate: CoreCourseOptionsDelegate, private siteHomeProvider: CoreSiteHomeProvider,
private eventsProvider: CoreEventsProvider, private fileHelper: CoreFileHelperProvider,
private appProvider: CoreAppProvider, private fileProvider: CoreFileProvider, private injector: Injector,
private coursesProvider: CoreCoursesProvider, private courseOffline: CoreCourseOfflineProvider,
loggerProvider: CoreLoggerProvider) {
this.logger = loggerProvider.getInstance('CoreCourseHelperProvider');
}
@ -1170,7 +1171,7 @@ export class CoreCourseHelperProvider {
// Otherwise, we will redirect below.
modal.dismiss();
return module.handlerData.action(event, navCtrl, module, courseId);
return module.handlerData.action(new Event('click'), navCtrl, module, courseId);
}
this.logger.warn('navCtrl was not passed to navigateToModule by the link handler for ' + module.modname);

View File

@ -40,8 +40,9 @@ export class CoreCoursesCourseLinkHandler extends CoreContentLinksHandlerBase {
private domUtils: CoreDomUtilsProvider,
private translate: TranslateService, private courseProvider: CoreCourseProvider,
private textUtils: CoreTextUtilsProvider, private courseHelper: CoreCourseHelperProvider,
private loggerProvider: CoreLoggerProvider) {
loggerProvider: CoreLoggerProvider) {
super();
this.logger = loggerProvider.getInstance('CoreCoursesCourseLinkHandler');
}
@ -80,9 +81,17 @@ export class CoreCoursesCourseLinkHandler extends CoreContentLinksHandlerBase {
action: (siteId, navCtrl?): void => {
siteId = siteId || this.sitesProvider.getCurrentSiteId();
if (siteId == this.sitesProvider.getCurrentSiteId()) {
this.actionEnrol(courseId, url, pageParams, navCtrl).catch(() => {
// Ignore errors.
});
// Check if we already are in the course index page.
if (this.courseProvider.currentViewIsCourse(navCtrl, courseId)) {
// Current view is this course, just select the contents tab.
this.courseProvider.selectCourseTab('', pageParams);
return;
} else {
this.actionEnrol(courseId, url, pageParams, navCtrl).catch(() => {
// Ignore errors.
});
}
} else {
// Don't pass the navCtrl to make the course the new history root (to avoid "loops" in history).
this.courseHelper.getAndOpenCourse(undefined, courseId, pageParams, siteId);

View File

@ -15,7 +15,7 @@
import { Injectable } from '@angular/core';
import { CoreContentLinksHandlerBase } from '@core/contentlinks/classes/base-handler';
import { CoreContentLinksAction } from '@core/contentlinks/providers/delegate';
import { CoreLoginHelperProvider } from '@core/login/providers/helper';
import { CoreContentLinksHelperProvider } from '@core/contentlinks/providers/helper';
import { CoreCoursesProvider } from './courses';
/**
@ -27,7 +27,7 @@ export class CoreCoursesIndexLinkHandler extends CoreContentLinksHandlerBase {
featureName = 'CoreMainMenuDelegate_CoreCourses';
pattern = /\/course\/?(index\.php.*)?$/;
constructor(private coursesProvider: CoreCoursesProvider, private loginHelper: CoreLoginHelperProvider) {
constructor(private coursesProvider: CoreCoursesProvider, private linkHelper: CoreContentLinksHelperProvider) {
super();
}
@ -56,8 +56,7 @@ export class CoreCoursesIndexLinkHandler extends CoreContentLinksHandlerBase {
}
}
// Always use redirect to make it the new history root (to avoid "loops" in history).
this.loginHelper.redirect(page, pageParams, siteId);
this.linkHelper.goInSite(navCtrl, page, pageParams, siteId);
}
}];
}

View File

@ -43,7 +43,7 @@ export class CoreCoursesDashboardLinkHandler extends CoreContentLinksHandlerBase
CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> {
return [{
action: (siteId, navCtrl?): void => {
// Always use redirect to make it the new history root (to avoid "loops" in history).
// Use redirect to select the tab.
this.loginHelper.redirect('CoreCoursesDashboardPage', undefined, siteId);
}
}];

View File

@ -24,7 +24,6 @@ import { CoreUrlUtilsProvider } from '@providers/utils/url';
import { CoreUtilsProvider } from '@providers/utils/utils';
import { CoreDomUtilsProvider } from '@providers/utils/dom';
import { CoreContentLinksHelperProvider } from '@core/contentlinks/providers/helper';
import { CoreLoginHelperProvider } from '@core/login/providers/helper';
import { CoreCourseHelperProvider } from '@core/course/providers/helper';
/**
@ -38,8 +37,7 @@ export class CoreGradesHelperProvider {
private gradesProvider: CoreGradesProvider, private sitesProvider: CoreSitesProvider,
private textUtils: CoreTextUtilsProvider, private courseProvider: CoreCourseProvider,
private domUtils: CoreDomUtilsProvider, private urlUtils: CoreUrlUtilsProvider, private utils: CoreUtilsProvider,
private linkHelper: CoreContentLinksHelperProvider, private loginHelper: CoreLoginHelperProvider,
private courseHelper: CoreCourseHelperProvider) {
private linkHelper: CoreContentLinksHelperProvider, private courseHelper: CoreCourseHelperProvider) {
this.logger = logger.getInstance('CoreGradesHelperProvider');
}
@ -457,14 +455,22 @@ export class CoreGradesHelperProvider {
});
}
// View own grades. Open the course with the grades tab selected.
// View own grades. Check if we already are in the course index page.
if (this.courseProvider.currentViewIsCourse(navCtrl, courseId)) {
// Current view is this course, just select the grades tab.
this.courseProvider.selectCourseTab('CoreGrades');
return;
}
// Open the course with the grades tab selected.
return this.courseHelper.getCourse(courseId, siteId).then((result) => {
const pageParams: any = {
course: result.course,
selectedTab: 'CoreGrades'
};
return this.loginHelper.redirect('CoreCourseSectionPage', pageParams, siteId).catch(() => {
return this.linkHelper.goInSite(navCtrl, 'CoreCourseSectionPage', pageParams, siteId).catch(() => {
// Ignore errors.
});
});

View File

@ -43,7 +43,6 @@ export class CoreGradesOverviewLinkHandler extends CoreContentLinksHandlerBase {
CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> {
return [{
action: (siteId, navCtrl?): void => {
// Always use redirect to make it the new history root (to avoid "loops" in history).
this.linkHelper.goInSite(navCtrl, 'CoreGradesCoursesPage', undefined, siteId);
}
}];

View File

@ -112,7 +112,6 @@ export class CoreGradesUserHandler implements CoreUserProfileHandler {
courseId: courseId,
userId: user.id
};
// Always use redirect to make it the new history root (to avoid "loops" in history).
this.linkHelper.goInSite(navCtrl, 'CoreGradesCoursePage', pageParams);
}
};

View File

@ -629,7 +629,7 @@ export class CoreLoginHelperProvider {
* @param {string} page Name of the page to load.
* @param {any} params Params to pass to the page.
*/
protected loadPageInMainMenu(page: string, params: any): void {
loadPageInMainMenu(page: string, params: any): void {
if (!this.appProvider.isMainMenuOpen()) {
// Main menu not open. Store the page to be loaded later.
this.pageToLoad = {

View File

@ -16,7 +16,9 @@ import { Injectable } from '@angular/core';
import { NavController } from 'ionic-angular';
import { CoreLangProvider } from '@providers/lang';
import { CoreSitesProvider } from '@providers/sites';
import { CoreUtilsProvider } from '@providers/utils/utils';
import { CoreConfigConstants } from '../../../configconstants';
import { CoreMainMenuDelegate, CoreMainMenuHandlerToDisplay } from './delegate';
/**
* Custom main menu item.
@ -56,10 +58,34 @@ export class CoreMainMenuProvider {
static ITEM_MIN_WIDTH = 72; // Min with of every item, based on 5 items on a 360 pixel wide screen.
protected tablet = false;
constructor(private langProvider: CoreLangProvider, private sitesProvider: CoreSitesProvider) {
constructor(private langProvider: CoreLangProvider, private sitesProvider: CoreSitesProvider,
protected menuDelegate: CoreMainMenuDelegate, protected utils: CoreUtilsProvider) {
this.tablet = window && window.innerWidth && window.innerWidth >= 576 && window.innerHeight >= 576;
}
/**
* Get the current main menu handlers.
*
* @return {Promise<CoreMainMenuHandlerToDisplay[]>} Promise resolved with the current main menu handlers.
*/
getCurrentMainMenuHandlers(): Promise<CoreMainMenuHandlerToDisplay[]> {
const deferred = this.utils.promiseDefer();
const subscription = this.menuDelegate.getHandlers().subscribe((handlers) => {
subscription && subscription.unsubscribe();
// Remove the handlers that should only appear in the More menu.
handlers = handlers.filter((handler) => {
return !handler.onlyInMore;
});
// Return main handlers.
deferred.resolve(handlers.slice(0, this.getNumItems()));
});
return deferred.promise;
}
/**
* Get a list of custom menu items for a certain site.
*
@ -211,6 +237,23 @@ export class CoreMainMenuProvider {
return tablet ? 'side' : 'bottom';
}
/**
* Check if a certain page is the root of a main menu handler currently displayed.
*
* @param {string} page Name of the page.
* @param {string} [pageParams] Page params.
* @return {Promise<boolean>} Promise resolved with boolean: whether it's the root of a main menu handler.
*/
isCurrentMainMenuHandler(pageName: string, pageParams?: any): Promise<boolean> {
return this.getCurrentMainMenuHandlers().then((handlers) => {
const handler = handlers.find((handler, i) => {
return handler.page == pageName;
});
return !!handler;
});
}
/**
* Check if responsive main menu items is disabled in the current site.
*

View File

@ -16,7 +16,7 @@ import { Injectable } from '@angular/core';
import { CoreSitesProvider } from '@providers/sites';
import { CoreContentLinksHandlerBase } from '@core/contentlinks/classes/base-handler';
import { CoreContentLinksAction } from '@core/contentlinks/providers/delegate';
import { CoreLoginHelperProvider } from '@core/login/providers/helper';
import { CoreContentLinksHelperProvider } from '@core/contentlinks/providers/helper';
import { CoreSiteHomeProvider } from './sitehome';
/**
@ -29,7 +29,7 @@ export class CoreSiteHomeIndexLinkHandler extends CoreContentLinksHandlerBase {
pattern = /\/course\/view\.php.*([\?\&]id=\d+)/;
constructor(private sitesProvider: CoreSitesProvider, private siteHomeProvider: CoreSiteHomeProvider,
private loginHelper: CoreLoginHelperProvider) {
private linkHelper: CoreContentLinksHelperProvider) {
super();
}
@ -46,8 +46,7 @@ export class CoreSiteHomeIndexLinkHandler extends CoreContentLinksHandlerBase {
CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> {
return [{
action: (siteId, navCtrl?): void => {
// Always use redirect to make it the new history root (to avoid "loops" in history).
this.loginHelper.redirect('CoreSiteHomeIndexPage', undefined, siteId);
this.linkHelper.goInSite(navCtrl, 'CoreSiteHomeIndexPage', undefined, siteId);
}
}];
}

View File

@ -16,7 +16,7 @@ import { Injectable } from '@angular/core';
import { CoreDomUtilsProvider } from '@providers/utils/dom';
import { CoreContentLinksHandlerBase } from '@core/contentlinks/classes/base-handler';
import { CoreContentLinksAction } from '@core/contentlinks/providers/delegate';
import { CoreLoginHelperProvider } from '@core/login/providers/helper';
import { CoreCourseProvider } from '@core/course/providers/course';
import { CoreCourseHelperProvider } from '@core/course/providers/helper';
import { CoreContentLinksHelperProvider } from '@core/contentlinks/providers/helper';
import { CoreUserProvider } from './user';
@ -30,9 +30,9 @@ export class CoreUserParticipantsLinkHandler extends CoreContentLinksHandlerBase
featureName = 'CoreCourseOptionsDelegate_CoreUserParticipants';
pattern = /\/user\/index\.php/;
constructor(private userProvider: CoreUserProvider, private loginHelper: CoreLoginHelperProvider,
constructor(private userProvider: CoreUserProvider,
private courseHelper: CoreCourseHelperProvider, private domUtils: CoreDomUtilsProvider,
private linkHelper: CoreContentLinksHelperProvider) {
private linkHelper: CoreContentLinksHelperProvider, private courseProvider: CoreCourseProvider) {
super();
}
@ -51,6 +51,14 @@ export class CoreUserParticipantsLinkHandler extends CoreContentLinksHandlerBase
return [{
action: (siteId, navCtrl?): void => {
// Check if we already are in the course index page.
if (this.courseProvider.currentViewIsCourse(navCtrl, courseId)) {
// Current view is this course, just select the participants tab.
this.courseProvider.selectCourseTab('CoreUserParticipants');
return;
}
const modal = this.domUtils.showModalLoading();
this.courseHelper.getCourse(courseId, siteId).then((result) => {
@ -59,8 +67,9 @@ export class CoreUserParticipantsLinkHandler extends CoreContentLinksHandlerBase
selectedTab: 'CoreUserParticipants'
};
// Always use redirect to make it the new history root (to avoid "loops" in history).
return this.loginHelper.redirect('CoreCourseSectionPage', params, siteId);
return this.linkHelper.goInSite(navCtrl, 'CoreCourseSectionPage', params, siteId).catch(() => {
// Ignore errors.
});
}).catch(() => {
// Cannot get course for some reason, just open the participants page.
return this.linkHelper.goInSite(navCtrl, 'CoreUserParticipantsPage', {courseId: courseId}, siteId);

View File

@ -47,7 +47,6 @@ export class CoreUserProfileLinkHandler extends CoreContentLinksHandlerBase {
courseId: params.course,
userId: parseInt(params.id, 10)
};
// Always use redirect to make it the new history root (to avoid "loops" in history).
this.linkHelper.goInSite(navCtrl, 'CoreUserProfilePage', pageParams, siteId);
}
}];

View File

@ -60,6 +60,7 @@ export class CoreEventsProvider {
static LOAD_PAGE_MAIN_MENU = 'load_page_main_menu';
static SEND_ON_ENTER_CHANGED = 'send_on_enter_changed';
static MAIN_MENU_OPEN = 'main_menu_open';
static SELECT_COURSE_TAB = 'select_course_tab';
protected logger;
protected observables: { [s: string]: Subject<any> } = {};