MOBILE-3833 sitehome: Fix site home link handler
parent
da11a08c07
commit
5ee3dc13e2
|
@ -306,13 +306,7 @@ export class CoreTabsBaseComponent<T extends CoreTabBase> implements OnInit, Aft
|
|||
this.calculateSlides();
|
||||
});
|
||||
|
||||
let selectedTab: T | undefined = this.tabs[this.selectedIndex || 0] || undefined;
|
||||
|
||||
if (!selectedTab || !selectedTab.enabled) {
|
||||
// The tab is not enabled or not shown. Get the first tab that is enabled.
|
||||
selectedTab = this.tabs.find((tab) => tab.enabled) || undefined;
|
||||
}
|
||||
|
||||
const selectedTab = this.calculateInitialTab();
|
||||
if (!selectedTab) {
|
||||
return;
|
||||
}
|
||||
|
@ -329,6 +323,22 @@ export class CoreTabsBaseComponent<T extends CoreTabBase> implements OnInit, Aft
|
|||
this.calculateSlides();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the initial tab to load.
|
||||
*
|
||||
* @return Initial tab, undefined if no valid tab found.
|
||||
*/
|
||||
protected calculateInitialTab(): T | undefined {
|
||||
const selectedTab: T | undefined = this.tabs[this.selectedIndex || 0] || undefined;
|
||||
|
||||
if (selectedTab && selectedTab.enabled) {
|
||||
return selectedTab;
|
||||
}
|
||||
|
||||
// The tab is not enabled or not shown. Get the first tab that is enabled.
|
||||
return this.tabs.find((tab) => tab.enabled) || undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method executed when the slides are changed.
|
||||
*/
|
||||
|
@ -564,8 +574,8 @@ export class CoreTabsBaseComponent<T extends CoreTabBase> implements OnInit, Aft
|
|||
}
|
||||
|
||||
const tabToSelect = this.tabs[index];
|
||||
if (!tabToSelect || !tabToSelect.enabled || tabToSelect.id == this.selected) {
|
||||
// Already selected or not enabled.
|
||||
if (!tabToSelect || !tabToSelect.enabled) {
|
||||
// Not enabled.
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -578,17 +588,32 @@ export class CoreTabsBaseComponent<T extends CoreTabBase> implements OnInit, Aft
|
|||
}
|
||||
}
|
||||
|
||||
if (tabToSelect.id === this.selected) {
|
||||
// Already selected.
|
||||
return;
|
||||
}
|
||||
|
||||
const ok = await this.loadTab(tabToSelect);
|
||||
|
||||
if (ok !== false) {
|
||||
this.selectHistory.push(tabToSelect.id!);
|
||||
this.selected = tabToSelect.id;
|
||||
this.selectedIndex = index;
|
||||
|
||||
this.ionChange.emit(tabToSelect);
|
||||
this.tabSelected(tabToSelect, index);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update selected tab.
|
||||
*
|
||||
* @param tab Tab.
|
||||
* @param tabIndex Tab index.
|
||||
*/
|
||||
protected tabSelected(tab: T, tabIndex: number): void {
|
||||
this.selectHistory.push(tab.id ?? '');
|
||||
this.selected = tab.id;
|
||||
this.selectedIndex = tabIndex;
|
||||
|
||||
this.ionChange.emit(tab);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the tab.
|
||||
*
|
||||
|
|
|
@ -88,7 +88,7 @@ export class CoreTabsOutletComponent extends CoreTabsBaseComponent<CoreTabsOutle
|
|||
}
|
||||
|
||||
/**
|
||||
* View has been initialized.
|
||||
* @inheritdoc
|
||||
*/
|
||||
async ngAfterViewInit(): Promise<void> {
|
||||
super.ngAfterViewInit();
|
||||
|
@ -103,12 +103,20 @@ export class CoreTabsOutletComponent extends CoreTabsBaseComponent<CoreTabsOutle
|
|||
return;
|
||||
}
|
||||
|
||||
// Search the tab loaded.
|
||||
const tabIndex = this.tabs.findIndex((tab) => tab.page == stackEvent.enteringView.url);
|
||||
const tab = tabIndex >= 0 ? this.tabs[tabIndex] : undefined;
|
||||
|
||||
// Add tabid to the tab content element.
|
||||
if (stackEvent.enteringView.element.id == '') {
|
||||
const tab = this.tabs.find((tab) => tab.page == stackEvent.enteringView.url);
|
||||
stackEvent.enteringView.element.id = tab?.id || '';
|
||||
}
|
||||
|
||||
if (tab && this.selected !== tab.id) {
|
||||
// Tab loaded using a navigation, update the selected tab.
|
||||
this.tabSelected(tab, tabIndex);
|
||||
}
|
||||
|
||||
this.showHideNavBarButtons(stackEvent.enteringView.element.tagName);
|
||||
|
||||
await this.listenContentScroll(stackEvent.enteringView.element, stackEvent.enteringView.id);
|
||||
|
@ -125,7 +133,7 @@ export class CoreTabsOutletComponent extends CoreTabsBaseComponent<CoreTabsOutle
|
|||
}
|
||||
|
||||
/**
|
||||
* Detect changes on input properties.
|
||||
* @inheritdoc
|
||||
*/
|
||||
ngOnChanges(changes: Record<string, SimpleChange>): void {
|
||||
if (changes.tabs) {
|
||||
|
@ -168,6 +176,21 @@ export class CoreTabsOutletComponent extends CoreTabsBaseComponent<CoreTabsOutle
|
|||
this.lastActiveComponent?.ionViewDidLeave?.();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected calculateInitialTab(): CoreTabsOutletTab | undefined {
|
||||
// Check if a tab should be selected because it was loaded by path.
|
||||
const currentPath = CoreNavigator.getCurrentPath();
|
||||
const currentPathTab = this.tabs.find(tab => tab.page === currentPath);
|
||||
|
||||
if (currentPathTab && currentPathTab.enabled) {
|
||||
return currentPathTab;
|
||||
}
|
||||
|
||||
return super.calculateInitialTab();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get router outlet.
|
||||
*
|
||||
|
|
|
@ -32,32 +32,21 @@ export class CoreSiteHomeIndexLinkHandlerService extends CoreContentLinksHandler
|
|||
pattern = /\/course\/view\.php.*([?&]id=\d+)/;
|
||||
|
||||
/**
|
||||
* Get the list of actions for a link (url).
|
||||
*
|
||||
* @param siteIds List of sites the URL belongs to.
|
||||
* @param url The URL to treat.
|
||||
* @param params The params of the URL. E.g. 'mysite.com?id=1' -> {id: 1}
|
||||
* @param courseId Course ID related to the URL. Optional but recommended.
|
||||
* @return List of (or promise resolved with list of) actions.
|
||||
* @inheritdoc
|
||||
*/
|
||||
getActions(): CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> {
|
||||
return [{
|
||||
action: (siteId: string): void => {
|
||||
// @todo This should open the 'sitehome' setting as well.
|
||||
CoreNavigator.navigateToSiteHome({ siteId });
|
||||
CoreNavigator.navigateToSitePath('/home/site', {
|
||||
preferCurrentTab: false,
|
||||
siteId,
|
||||
});
|
||||
},
|
||||
}];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the handler is enabled for a certain site (site + user) and a URL.
|
||||
* If not defined, defaults to true.
|
||||
*
|
||||
* @param siteId The site ID.
|
||||
* @param url The URL to treat.
|
||||
* @param params The params of the URL. E.g. 'mysite.com?id=1' -> {id: 1}
|
||||
* @param courseId Course ID related to the URL. Optional but recommended.
|
||||
* @return Whether the handler is enabled for the URL and site.
|
||||
* @inheritdoc
|
||||
*/
|
||||
async isEnabled(siteId: string, url: string, params: Record<string, string>, courseId?: number): Promise<boolean> {
|
||||
courseId = parseInt(params.id, 10);
|
||||
|
|
Loading…
Reference in New Issue