Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MOBILE-4641 core: Support custom default home pages #4170

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/core/classes/sites/unauthenticated-site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
44 changes: 35 additions & 9 deletions src/core/features/mainmenu/pages/menu/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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.
*/
Expand Down
28 changes: 28 additions & 0 deletions src/core/features/mainmenu/tests/behat/mainmenu.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down