MOBILE-3922 core: Display tab to select in first position
parent
ee8c9de101
commit
2dea93a60f
|
@ -118,14 +118,14 @@ export class CoreSortedDelegate<
|
|||
const handler = this.enabledHandlers[name];
|
||||
const data = <DisplayType> handler.getDisplayData();
|
||||
|
||||
data.priority = handler.priority || 0;
|
||||
data.priority = data.priority ?? handler.priority ?? 0;
|
||||
data.name = handler.name;
|
||||
|
||||
displayData.push(data);
|
||||
}
|
||||
|
||||
// Sort them by priority.
|
||||
displayData.sort((a, b) => b.priority! - a.priority!);
|
||||
displayData.sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
|
||||
|
||||
this.loaded = true;
|
||||
this.sortedHandlersRxJs.next(displayData);
|
||||
|
|
|
@ -27,7 +27,7 @@ export class CoreDashboardHomeHandlerService implements CoreMainMenuHomeHandler
|
|||
static readonly PAGE_NAME = 'dashboard';
|
||||
|
||||
name = 'CoreCoursesDashboard';
|
||||
priority = 1100;
|
||||
priority = 1200;
|
||||
|
||||
/**
|
||||
* Check if the handler is enabled on a site level.
|
||||
|
@ -92,7 +92,6 @@ export class CoreDashboardHomeHandlerService implements CoreMainMenuHomeHandler
|
|||
page: CoreDashboardHomeHandlerService.PAGE_NAME,
|
||||
class: 'core-courses-dashboard-handler',
|
||||
icon: 'fas-tachometer-alt',
|
||||
selectPriority: 1000,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
// limitations under the License.
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { CoreSiteInfoUserHomepage } from '@classes/site';
|
||||
import { CoreMainMenuHandler, CoreMainMenuHandlerData } from '@features/mainmenu/services/mainmenu-delegate';
|
||||
import { CoreSiteHomeHomeHandler } from '@features/sitehome/services/handlers/sitehome-home';
|
||||
import { CoreSites } from '@services/sites';
|
||||
|
@ -59,11 +60,16 @@ export class CoreCoursesMyCoursesMainMenuHandlerService implements CoreMainMenuH
|
|||
* @inheritdoc
|
||||
*/
|
||||
getDisplayData(): CoreMainMenuHandlerData {
|
||||
const site = CoreSites.getCurrentSite();
|
||||
|
||||
const displayMyCourses = site?.getInfo() && site?.getInfo()?.userhomepage === CoreSiteInfoUserHomepage.HOMEPAGE_MYCOURSES;
|
||||
|
||||
return {
|
||||
title: 'core.courses.mycourses',
|
||||
page: CoreCoursesMyCoursesMainMenuHandlerService.PAGE_NAME,
|
||||
class: 'core-courses-my-courses-handler',
|
||||
icon: 'fas-graduation-cap',
|
||||
priority: displayMyCourses ? this.priority + 200 : this.priority,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -17,5 +17,5 @@
|
|||
<core-loading [hideUntil]="loaded">
|
||||
<core-empty-box *ngIf="tabs.length == 0" icon="fas-home" [message]="'core.courses.nocourses' | translate"></core-empty-box>
|
||||
</core-loading>
|
||||
<core-tabs-outlet *ngIf="tabs.length > 0" [selectedIndex]="selectedTab" [hideUntil]="loaded" [tabs]="tabs" (ionChange)="tabSelected()">
|
||||
<core-tabs-outlet *ngIf="tabs.length > 0" [hideUntil]="loaded" [tabs]="tabs" (ionChange)="tabSelected()">
|
||||
</core-tabs-outlet>
|
||||
|
|
|
@ -39,10 +39,9 @@ export class CoreMainMenuHomePage implements OnInit {
|
|||
|
||||
@ViewChild(CoreTabsOutletComponent) tabsComponent?: CoreTabsOutletComponent;
|
||||
|
||||
siteName!: string;
|
||||
siteName = '';
|
||||
tabs: CoreTabsOutletTab[] = [];
|
||||
loaded = false;
|
||||
selectedTab?: number;
|
||||
|
||||
protected subscription?: Subscription;
|
||||
protected updateSiteObserver?: CoreEventObserver;
|
||||
|
@ -109,21 +108,6 @@ export class CoreMainMenuHomePage implements OnInit {
|
|||
// Sort them by priority so new handlers are in the right position.
|
||||
newTabs.sort((a, b) => (handlersMap[b.title].priority || 0) - (handlersMap[a.title].priority || 0));
|
||||
|
||||
if (this.selectedTab === undefined && newTabs.length > 0) {
|
||||
let maxPriority = 0;
|
||||
|
||||
this.selectedTab = Object.entries(newTabs).reduce((maxIndex, [index, tab]) => {
|
||||
const selectPriority = handlersMap[tab.title].selectPriority ?? 0;
|
||||
|
||||
if (selectPriority > maxPriority) {
|
||||
maxPriority = selectPriority;
|
||||
maxIndex = Number(index);
|
||||
}
|
||||
|
||||
return maxIndex;
|
||||
}, 0);
|
||||
}
|
||||
|
||||
this.tabs = newTabs;
|
||||
|
||||
// Try to prevent empty box displayed for an instant when it shouldn't.
|
||||
|
@ -136,7 +120,7 @@ export class CoreMainMenuHomePage implements OnInit {
|
|||
* Load the site name.
|
||||
*/
|
||||
protected loadSiteName(): void {
|
||||
this.siteName = CoreSites.getCurrentSite()!.getSiteName();
|
||||
this.siteName = CoreSites.getCurrentSite()?.getSiteName() || '';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -171,8 +155,8 @@ export class CoreMainMenuHomePage implements OnInit {
|
|||
const actions = await CoreContentLinksDelegate.getActionsFor(url, undefined);
|
||||
|
||||
const action = CoreContentLinksHelper.getFirstValidAction(actions);
|
||||
if (action) {
|
||||
action.action(action.sites![0]);
|
||||
if (action?.sites?.[0]) {
|
||||
action.action(action.sites[0]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -72,12 +72,7 @@ export interface CoreMainMenuHomeHandlerData {
|
|||
/**
|
||||
* Data returned by the delegate for each handler.
|
||||
*/
|
||||
export interface CoreMainMenuHomeHandlerToDisplay extends CoreDelegateToDisplay, CoreMainMenuHomeHandlerData {
|
||||
/**
|
||||
* Priority to select handler.
|
||||
*/
|
||||
selectPriority?: number;
|
||||
}
|
||||
export interface CoreMainMenuHomeHandlerToDisplay extends CoreDelegateToDisplay, CoreMainMenuHomeHandlerData {}
|
||||
|
||||
/**
|
||||
* Service to interact with plugins to be shown in the main menu. Provides functions to register a plugin
|
||||
|
|
|
@ -77,6 +77,11 @@ export interface CoreMainMenuHandlerData {
|
|||
* Whether the handler should only appear in More menu.
|
||||
*/
|
||||
onlyInMore?: boolean;
|
||||
|
||||
/**
|
||||
* Priority of the handler. If set, overrides the priority defined in CoreMainMenuHandler.
|
||||
*/
|
||||
priority?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -28,7 +28,7 @@ export class CoreSiteHomeHomeHandlerService implements CoreMainMenuHomeHandler {
|
|||
static readonly PAGE_NAME = 'site';
|
||||
|
||||
name = 'CoreSiteHomeDashboard';
|
||||
priority = 1200;
|
||||
priority = 1100;
|
||||
|
||||
/**
|
||||
* Check if the handler is enabled on a site level.
|
||||
|
@ -64,7 +64,7 @@ export class CoreSiteHomeHomeHandlerService implements CoreMainMenuHomeHandler {
|
|||
page: CoreSiteHomeHomeHandlerService.PAGE_NAME,
|
||||
class: 'core-sitehome-dashboard-handler',
|
||||
icon: 'fas-home',
|
||||
selectPriority: displaySiteHome ? 1100 : 900,
|
||||
priority: displaySiteHome ? this.priority + 200 : this.priority,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue