Skip to content

Commit 8d4e436

Browse files
committed
MOBILE-4641 core: Support custom default home pages
1 parent 90a356f commit 8d4e436

File tree

5 files changed

+72
-15
lines changed

5 files changed

+72
-15
lines changed

src/core/classes/sites/unauthenticated-site.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@ export type CoreSiteInfoResponse = {
445445
userquota?: number; // User quota (bytes). 0 means user can ignore the quota.
446446
usermaxuploadfilesize?: number; // User max upload file size (bytes). -1 means the user can ignore the upload file size.
447447
userhomepage?: CoreSiteInfoUserHomepage; // The default home page for the user.
448+
userhomepageurl?: string; // @since 4.5. The URL of the custom user home page when using HOMEPAGE_URL.
448449
userprivateaccesskey?: string; // Private user access key for fetching files.
449450
siteid?: number; // Site course ID.
450451
sitecalendartype?: string; // Calendar type set in the site.
@@ -475,6 +476,7 @@ export enum CoreSiteInfoUserHomepage {
475476
HOMEPAGE_SITE = 0, // Site home.
476477
HOMEPAGE_MY = 1, // Dashboard.
477478
HOMEPAGE_MYCOURSES = 3, // My courses.
479+
HOMEPAGE_URL = 4, // A custom URL.
478480
}
479481

480482
/**

src/core/features/contentlinks/services/contentlinks-helper.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export class CoreContentLinksHelperProvider {
136136

137137
if (data.site) {
138138
// URL is the root of the site.
139-
this.handleRootURL(data.site, openBrowserRoot);
139+
await this.handleRootURL(data.site, openBrowserRoot);
140140

141141
return true;
142142
}
@@ -150,19 +150,19 @@ export class CoreContentLinksHelperProvider {
150150
if (!CoreSites.isLoggedIn()) {
151151
// No current site. Perform the action if only 1 site found, choose the site otherwise.
152152
if (action.sites?.length == 1) {
153-
action.action(action.sites[0]);
153+
await action.action(action.sites[0]);
154154
} else {
155155
this.goToChooseSite(url);
156156
}
157157
} else if (action.sites?.length == 1 && action.sites[0] == CoreSites.getCurrentSiteId()) {
158158
// Current site.
159-
action.action(action.sites[0]);
159+
await action.action(action.sites[0]);
160160
} else {
161161
try {
162162
// Not current site or more than one site. Ask for confirmation.
163163
await CoreDomUtils.showConfirm(Translate.instant('core.contentlinks.confirmurlothersite'));
164164
if (action.sites?.length == 1) {
165-
action.action(action.sites[0]);
165+
await action.action(action.sites[0]);
166166
} else {
167167
this.goToChooseSite(url);
168168
}

src/core/features/courses/services/handlers/my-courses-mainmenu.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,10 @@ export class CoreCoursesMyCoursesMainMenuHandlerService implements CoreMainMenuH
6060
* @inheritdoc
6161
*/
6262
getDisplayData(): CoreMainMenuHandlerData {
63-
const site = CoreSites.getCurrentSite();
63+
const userHomePage = CoreSites.getCurrentSite()?.getInfo()?.userhomepage;
6464

65-
const displayMyCourses = site?.getInfo() && site?.getInfo()?.userhomepage === CoreSiteInfoUserHomepage.HOMEPAGE_MYCOURSES;
65+
const displayMyCourses = userHomePage === CoreSiteInfoUserHomepage.HOMEPAGE_MYCOURSES ||
66+
userHomePage === CoreSiteInfoUserHomepage.HOMEPAGE_URL;
6667

6768
return {
6869
title: 'core.courses.mycourses',

src/core/features/mainmenu/pages/menu/menu.ts

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ import { CoreLogger } from '@singletons/logger';
3333
import { CorePlatform } from '@services/platform';
3434
import { CoreWait } from '@singletons/wait';
3535
import { CoreMainMenuDeepLinkManager } from '@features/mainmenu/classes/deep-link-manager';
36+
import { CoreSiteInfoUserHomepage } from '@classes/sites/unauthenticated-site';
37+
import { CoreContentLinksHelper } from '@features/contentlinks/services/contentlinks-helper';
3638

3739
const ANIMATION_DURATION = 500;
3840

@@ -110,15 +112,7 @@ export class CoreMainMenuPage implements OnInit, OnDestroy {
110112
async ngOnInit(): Promise<void> {
111113
this.showTabs = true;
112114

113-
const deepLinkManager = new CoreMainMenuDeepLinkManager();
114-
115-
// Treat the deep link (if any) when the login navigation finishes.
116-
CoreSites.runAfterLoginNavigation({
117-
priority: 800,
118-
callback: async () => {
119-
await deepLinkManager.treatLink();
120-
},
121-
});
115+
this.initAfterLoginNavigations();
122116

123117
this.isMainScreen = !this.mainTabs?.outlet.canGoBack();
124118
this.updateVisibility();
@@ -223,6 +217,38 @@ export class CoreMainMenuPage implements OnInit, OnDestroy {
223217
}
224218
}
225219

220+
/**
221+
* Set up the code to run after the login navigation finishes.
222+
*/
223+
protected initAfterLoginNavigations(): void {
224+
// Treat custom home page and deep link (if any) when the login navigation finishes.
225+
const deepLinkManager = new CoreMainMenuDeepLinkManager();
226+
227+
CoreSites.runAfterLoginNavigation({
228+
priority: 800,
229+
callback: async () => {
230+
await deepLinkManager.treatLink();
231+
},
232+
});
233+
234+
CoreSites.runAfterLoginNavigation({
235+
priority: 1000,
236+
callback: async () => {
237+
const userHomePage = CoreSites.getCurrentSite()?.getInfo()?.userhomepage;
238+
if (userHomePage !== CoreSiteInfoUserHomepage.HOMEPAGE_URL) {
239+
return;
240+
}
241+
242+
const url = CoreSites.getCurrentSite()?.getInfo()?.userhomepageurl;
243+
if (!url) {
244+
return;
245+
}
246+
247+
await CoreContentLinksHelper.handleLink(url);
248+
},
249+
});
250+
}
251+
226252
/**
227253
* Check all non visible tab handlers for any badge text or number.
228254
*/

src/core/features/mainmenu/tests/behat/mainmenu.feature

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,34 @@ Feature: Main Menu opens the right page
3838
And I should find "Course 1" in the app
3939
And "My courses" "text" should appear before "Home" "text" in the ".mainmenu-tabs" "css_element"
4040

41+
@lms_from4.5
42+
Scenario: Opens right main menu tab when defaulthomepage is set to a custom URL that belongs to a tab
43+
Given the following config values are set as admin:
44+
| defaulthomepage | #wwwroot#/message/index.php |
45+
And I entered the app as "student"
46+
Then "Messages" "ion-tab-button" should be selected in the app
47+
And I should find "Contacts" in the app
48+
49+
@lms_from4.5
50+
Scenario: Opens new page when defaulthomepage is set to a custom URL
51+
Given the following config values are set as admin:
52+
| defaulthomepage | #wwwroot#/badges/mybadges.php |
53+
And I entered the app as "student"
54+
Then I should find "Badges" in the app
55+
And I should find "There are currently no badges" in the app
56+
57+
When I press the back button in the app
58+
Then "My courses" "ion-tab-button" should be selected in the app
59+
And I should find "Course 1" in the app
60+
61+
@lms_from4.5
62+
Scenario: defaulthomepage ignored if it's set to a custom URL not supported by the app
63+
Given the following config values are set as admin:
64+
| defaulthomepage | #wwwroot#/foo/bar.php |
65+
And I entered the app as "student"
66+
Then "My courses" "ion-tab-button" should be selected in the app
67+
And I should find "Course 1" in the app
68+
4169
# @todo MOBILE-4119: This test is too flaky to run in CI until the race condition is fixed.
4270
# Scenario: Opens first tab after Site Home, Dashboard, and My Courses are disabled
4371
# Given I entered the app as "student"

0 commit comments

Comments
 (0)