Merge pull request #4170 from dpalou/MOBILE-4641
MOBILE-4641 core: Support custom default home pagesmain
commit
5fe7a7beb1
|
@ -445,6 +445,7 @@ export type CoreSiteInfoResponse = {
|
|||
userquota?: number; // User quota (bytes). 0 means user can ignore the quota.
|
||||
usermaxuploadfilesize?: number; // User max upload file size (bytes). -1 means the user can ignore the upload file size.
|
||||
userhomepage?: CoreSiteInfoUserHomepage; // The default home page for the user.
|
||||
userhomepageurl?: string; // @since 4.5. The URL of the custom user home page when using HOMEPAGE_URL.
|
||||
userprivateaccesskey?: string; // Private user access key for fetching files.
|
||||
siteid?: number; // Site course ID.
|
||||
sitecalendartype?: string; // Calendar type set in the site.
|
||||
|
@ -475,6 +476,7 @@ export enum CoreSiteInfoUserHomepage {
|
|||
HOMEPAGE_SITE = 0, // Site home.
|
||||
HOMEPAGE_MY = 1, // Dashboard.
|
||||
HOMEPAGE_MYCOURSES = 3, // My courses.
|
||||
HOMEPAGE_URL = 4, // A custom URL.
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -136,7 +136,7 @@ export class CoreContentLinksHelperProvider {
|
|||
|
||||
if (data.site) {
|
||||
// URL is the root of the site.
|
||||
this.handleRootURL(data.site, openBrowserRoot);
|
||||
await this.handleRootURL(data.site, openBrowserRoot);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -150,19 +150,19 @@ export class CoreContentLinksHelperProvider {
|
|||
if (!CoreSites.isLoggedIn()) {
|
||||
// No current site. Perform the action if only 1 site found, choose the site otherwise.
|
||||
if (action.sites?.length == 1) {
|
||||
action.action(action.sites[0]);
|
||||
await action.action(action.sites[0]);
|
||||
} else {
|
||||
this.goToChooseSite(url);
|
||||
}
|
||||
} else if (action.sites?.length == 1 && action.sites[0] == CoreSites.getCurrentSiteId()) {
|
||||
// Current site.
|
||||
action.action(action.sites[0]);
|
||||
await action.action(action.sites[0]);
|
||||
} else {
|
||||
try {
|
||||
// Not current site or more than one site. Ask for confirmation.
|
||||
await CoreDomUtils.showConfirm(Translate.instant('core.contentlinks.confirmurlothersite'));
|
||||
if (action.sites?.length == 1) {
|
||||
action.action(action.sites[0]);
|
||||
await action.action(action.sites[0]);
|
||||
} else {
|
||||
this.goToChooseSite(url);
|
||||
}
|
||||
|
|
|
@ -60,9 +60,10 @@ export class CoreCoursesMyCoursesMainMenuHandlerService implements CoreMainMenuH
|
|||
* @inheritdoc
|
||||
*/
|
||||
getDisplayData(): CoreMainMenuHandlerData {
|
||||
const site = CoreSites.getCurrentSite();
|
||||
const userHomePage = CoreSites.getCurrentSite()?.getInfo()?.userhomepage;
|
||||
|
||||
const displayMyCourses = site?.getInfo() && site?.getInfo()?.userhomepage === CoreSiteInfoUserHomepage.HOMEPAGE_MYCOURSES;
|
||||
const displayMyCourses = userHomePage === CoreSiteInfoUserHomepage.HOMEPAGE_MYCOURSES ||
|
||||
userHomePage === CoreSiteInfoUserHomepage.HOMEPAGE_URL;
|
||||
|
||||
return {
|
||||
title: 'core.courses.mycourses',
|
||||
|
|
|
@ -33,6 +33,8 @@ import { CoreLogger } from '@singletons/logger';
|
|||
import { CorePlatform } from '@services/platform';
|
||||
import { CoreWait } from '@singletons/wait';
|
||||
import { CoreMainMenuDeepLinkManager } from '@features/mainmenu/classes/deep-link-manager';
|
||||
import { CoreSiteInfoUserHomepage } from '@classes/sites/unauthenticated-site';
|
||||
import { CoreContentLinksHelper } from '@features/contentlinks/services/contentlinks-helper';
|
||||
|
||||
const ANIMATION_DURATION = 500;
|
||||
|
||||
|
@ -110,15 +112,7 @@ export class CoreMainMenuPage implements OnInit, OnDestroy {
|
|||
async ngOnInit(): Promise<void> {
|
||||
this.showTabs = true;
|
||||
|
||||
const deepLinkManager = new CoreMainMenuDeepLinkManager();
|
||||
|
||||
// Treat the deep link (if any) when the login navigation finishes.
|
||||
CoreSites.runAfterLoginNavigation({
|
||||
priority: 800,
|
||||
callback: async () => {
|
||||
await deepLinkManager.treatLink();
|
||||
},
|
||||
});
|
||||
this.initAfterLoginNavigations();
|
||||
|
||||
this.isMainScreen = !this.mainTabs?.outlet.canGoBack();
|
||||
this.updateVisibility();
|
||||
|
@ -223,6 +217,38 @@ export class CoreMainMenuPage implements OnInit, OnDestroy {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up the code to run after the login navigation finishes.
|
||||
*/
|
||||
protected initAfterLoginNavigations(): void {
|
||||
// Treat custom home page and deep link (if any) when the login navigation finishes.
|
||||
const deepLinkManager = new CoreMainMenuDeepLinkManager();
|
||||
|
||||
CoreSites.runAfterLoginNavigation({
|
||||
priority: 800,
|
||||
callback: async () => {
|
||||
await deepLinkManager.treatLink();
|
||||
},
|
||||
});
|
||||
|
||||
CoreSites.runAfterLoginNavigation({
|
||||
priority: 1000,
|
||||
callback: async () => {
|
||||
const userHomePage = CoreSites.getCurrentSite()?.getInfo()?.userhomepage;
|
||||
if (userHomePage !== CoreSiteInfoUserHomepage.HOMEPAGE_URL) {
|
||||
return;
|
||||
}
|
||||
|
||||
const url = CoreSites.getCurrentSite()?.getInfo()?.userhomepageurl;
|
||||
if (!url) {
|
||||
return;
|
||||
}
|
||||
|
||||
await CoreContentLinksHelper.handleLink(url);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Check all non visible tab handlers for any badge text or number.
|
||||
*/
|
||||
|
|
|
@ -38,6 +38,34 @@ Feature: Main Menu opens the right page
|
|||
And I should find "Course 1" in the app
|
||||
And "My courses" "text" should appear before "Home" "text" in the ".mainmenu-tabs" "css_element"
|
||||
|
||||
@lms_from4.5
|
||||
Scenario: Opens right main menu tab when defaulthomepage is set to a custom URL that belongs to a tab
|
||||
Given the following config values are set as admin:
|
||||
| defaulthomepage | #wwwroot#/message/index.php |
|
||||
And I entered the app as "student"
|
||||
Then "Messages" "ion-tab-button" should be selected in the app
|
||||
And I should find "Contacts" in the app
|
||||
|
||||
@lms_from4.5
|
||||
Scenario: Opens new page when defaulthomepage is set to a custom URL
|
||||
Given the following config values are set as admin:
|
||||
| defaulthomepage | #wwwroot#/badges/mybadges.php |
|
||||
And I entered the app as "student"
|
||||
Then I should find "Badges" in the app
|
||||
And I should find "There are currently no badges" in the app
|
||||
|
||||
When I press the back button in the app
|
||||
Then "My courses" "ion-tab-button" should be selected in the app
|
||||
And I should find "Course 1" in the app
|
||||
|
||||
@lms_from4.5
|
||||
Scenario: defaulthomepage ignored if it's set to a custom URL not supported by the app
|
||||
Given the following config values are set as admin:
|
||||
| defaulthomepage | #wwwroot#/foo/bar.php |
|
||||
And I entered the app as "student"
|
||||
Then "My courses" "ion-tab-button" should be selected in the app
|
||||
And I should find "Course 1" in the app
|
||||
|
||||
# @todo MOBILE-4119: This test is too flaky to run in CI until the race condition is fixed.
|
||||
# Scenario: Opens first tab after Site Home, Dashboard, and My Courses are disabled
|
||||
# Given I entered the app as "student"
|
||||
|
|
Loading…
Reference in New Issue