MOBILE-3320 mainmenu: Fix confirm tab root displayed when it shouldn't
parent
aaa300266b
commit
3e98be5a02
|
@ -32,10 +32,16 @@ function buildRoutes(injector: Injector): Routes {
|
|||
return [
|
||||
{
|
||||
path: 'index',
|
||||
data: {
|
||||
isMainMenuRoot: true,
|
||||
},
|
||||
loadChildren: () => import('@/addons/calendar/pages/index/index.module').then(m => m.AddonCalendarIndexPageModule),
|
||||
},
|
||||
{
|
||||
path: 'list',
|
||||
data: {
|
||||
isMainMenuRoot: true,
|
||||
},
|
||||
loadChildren: () => import('@/addons/calendar/pages/list/list.module').then(m => m.AddonCalendarListPageModule),
|
||||
},
|
||||
{
|
||||
|
|
|
@ -26,6 +26,9 @@ import { AddonMessagesDiscussions35Page } from './discussions.page';
|
|||
const mobileRoutes: Routes = [
|
||||
{
|
||||
path: '',
|
||||
data: {
|
||||
isMainMenuRoot: true,
|
||||
},
|
||||
component: AddonMessagesDiscussions35Page,
|
||||
},
|
||||
AddonMessagesDiscussionRoute,
|
||||
|
@ -34,6 +37,9 @@ const mobileRoutes: Routes = [
|
|||
const tabletRoutes: Routes = [
|
||||
{
|
||||
path: '',
|
||||
data: {
|
||||
isMainMenuRoot: true,
|
||||
},
|
||||
component: AddonMessagesDiscussions35Page,
|
||||
children: [
|
||||
AddonMessagesDiscussionRoute,
|
||||
|
|
|
@ -25,6 +25,9 @@ import { AddonMessagesGroupConversationsPage } from './group-conversations.page'
|
|||
const mobileRoutes: Routes = [
|
||||
{
|
||||
path: '',
|
||||
data: {
|
||||
isMainMenuRoot: true,
|
||||
},
|
||||
component: AddonMessagesGroupConversationsPage,
|
||||
},
|
||||
AddonMessagesDiscussionRoute,
|
||||
|
@ -33,6 +36,9 @@ const mobileRoutes: Routes = [
|
|||
const tabletRoutes: Routes = [
|
||||
{
|
||||
path: '',
|
||||
data: {
|
||||
isMainMenuRoot: true,
|
||||
},
|
||||
component: AddonMessagesGroupConversationsPage,
|
||||
children: [
|
||||
AddonMessagesDiscussionRoute,
|
||||
|
|
|
@ -21,6 +21,9 @@ function buildRoutes(injector: Injector): Routes {
|
|||
return [
|
||||
{
|
||||
path: 'list',
|
||||
data: {
|
||||
isMainMenuRoot: true,
|
||||
},
|
||||
loadChildren: () => import('./pages/list/list.module').then(m => m.AddonNotificationsListPageModule),
|
||||
},
|
||||
...buildTabMainRoutes(injector, {
|
||||
|
|
|
@ -19,12 +19,19 @@ import { buildTabMainRoutes } from '@features/mainmenu/mainmenu-tab-routing.modu
|
|||
|
||||
function buildRoutes(injector: Injector): Routes {
|
||||
return [
|
||||
{
|
||||
path: 'root',
|
||||
data: {
|
||||
isMainMenuRoot: true,
|
||||
},
|
||||
loadChildren: () => import('./pages/index/index.module').then(m => m.AddonPrivateFilesIndexPageModule),
|
||||
},
|
||||
{
|
||||
path: ':hash',
|
||||
loadChildren: () => import('./pages/index/index.module').then(m => m.AddonPrivateFilesIndexPageModule),
|
||||
},
|
||||
...buildTabMainRoutes(injector, {
|
||||
redirectTo: 'root', // Fake "hash".
|
||||
redirectTo: 'root',
|
||||
pathMatch: 'full',
|
||||
}),
|
||||
];
|
||||
|
|
|
@ -48,7 +48,6 @@ export class AddonPrivateFilesMainMenuHandlerService implements CoreMainMenuHand
|
|||
icon: 'fas-folder',
|
||||
title: 'addon.privatefiles.files',
|
||||
page: AddonPrivateFilesMainMenuHandlerService.PAGE_NAME,
|
||||
subPage: 'root',
|
||||
class: 'addon-privatefiles-handler',
|
||||
};
|
||||
}
|
||||
|
|
|
@ -28,6 +28,9 @@ function buildRoutes(injector: Injector): Routes {
|
|||
return [
|
||||
...buildTabMainRoutes(injector, {
|
||||
path: '',
|
||||
data: {
|
||||
isMainMenuRoot: true,
|
||||
},
|
||||
component: CoreMainMenuHomePage,
|
||||
children: routes.children,
|
||||
}),
|
||||
|
|
|
@ -13,13 +13,12 @@
|
|||
// limitations under the License.
|
||||
|
||||
import { Component, OnInit, OnDestroy, ViewChild, ChangeDetectorRef } from '@angular/core';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { IonTabs } from '@ionic/angular';
|
||||
import { BackButtonEvent } from '@ionic/core';
|
||||
import { Subscription } from 'rxjs';
|
||||
|
||||
import { CoreApp } from '@services/app';
|
||||
import { CoreTextUtils } from '@services/utils/text';
|
||||
import { CoreEvents, CoreEventObserver } from '@singletons/events';
|
||||
import { CoreMainMenu, CoreMainMenuProvider } from '../../services/mainmenu';
|
||||
import { CoreMainMenuDelegate, CoreMainMenuHandlerToDisplay } from '../../services/mainmenu-delegate';
|
||||
|
@ -27,6 +26,7 @@ import { CoreDomUtils } from '@services/utils/dom';
|
|||
import { Translate } from '@singletons';
|
||||
import { CoreUtils } from '@services/utils/utils';
|
||||
import { CoreAriaRoleTab, CoreAriaRoleTabFindable } from '@classes/aria-role-tab';
|
||||
import { CoreNavigator } from '@services/navigator';
|
||||
|
||||
/**
|
||||
* Page that displays the main menu of the app.
|
||||
|
@ -61,7 +61,6 @@ export class CoreMainMenuPage implements OnInit, OnDestroy {
|
|||
constructor(
|
||||
protected route: ActivatedRoute,
|
||||
protected changeDetector: ChangeDetectorRef,
|
||||
protected router: Router,
|
||||
) {
|
||||
this.resizeFunction = this.initHandlers.bind(this);
|
||||
this.backButtonFunction = this.backButtonClicked.bind(this);
|
||||
|
@ -172,29 +171,26 @@ export class CoreMainMenuPage implements OnInit, OnDestroy {
|
|||
return;
|
||||
}
|
||||
|
||||
const trimmedUrl = CoreTextUtils.trimCharacter(this.router.url, '/');
|
||||
|
||||
// Current tab was clicked. Check if user is already at root level.
|
||||
if (trimmedUrl == CoreTextUtils.trimCharacter(page, '/')) {
|
||||
// Already at root level, nothing to do.
|
||||
return;
|
||||
}
|
||||
|
||||
// Ask the user if he wants to go back to the root page of the tab.
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
e.stopImmediatePropagation();
|
||||
|
||||
// Current tab was clicked. Check if user is already at root level.
|
||||
const mainMenuRootRoute = CoreNavigator.getCurrentRoute({ routeData: { isMainMenuRoot: true } });
|
||||
if (mainMenuRootRoute) {
|
||||
return; // Already at root level, nothing to do.
|
||||
}
|
||||
|
||||
// Current route doesn't define isMainMenuRoot. Check if the current path is the tab one.
|
||||
const currentPath = CoreNavigator.getCurrentPath();
|
||||
if (currentPath == `/main/${page}`) {
|
||||
return; // Already at root level, nothing to do.
|
||||
}
|
||||
|
||||
// Ask the user if he wants to go back to the root page of the tab.
|
||||
try {
|
||||
const tab = this.tabs.find((tab) => tab.page == page);
|
||||
|
||||
// Use tab's subPage to check if user is already at root level.
|
||||
if (tab?.subPage && trimmedUrl ==
|
||||
CoreTextUtils.trimCharacter(CoreTextUtils.concatenatePaths(tab.page, tab.subPage), '/')) {
|
||||
// Already at root level, nothing to do.
|
||||
return;
|
||||
}
|
||||
|
||||
if (tab?.title) {
|
||||
await CoreDomUtils.showConfirm(Translate.instant('core.confirmgotabroot', {
|
||||
name: Translate.instant(tab.title),
|
||||
|
|
|
@ -136,7 +136,6 @@ export class CoreMainMenuMorePage implements OnInit, OnDestroy {
|
|||
* Open a handler.
|
||||
*
|
||||
* @param handler Handler to open.
|
||||
* @todo: use subPage?
|
||||
*/
|
||||
openHandler(handler: CoreMainMenuHandlerData): void {
|
||||
const params = handler.pageParams;
|
||||
|
|
|
@ -42,7 +42,6 @@ export class CoreMainMenuHomeHandlerService implements CoreMainMenuHandler {
|
|||
icon: 'fas-tachometer-alt',
|
||||
title: 'core.mainmenu.home',
|
||||
page: CoreMainMenuHomeHandlerService.PAGE_NAME,
|
||||
// @todo: subPage? The page can change due to core-tabs.
|
||||
class: 'core-home-handler',
|
||||
};
|
||||
}
|
||||
|
|
|
@ -33,13 +33,6 @@ export interface CoreMainMenuHandlerData {
|
|||
*/
|
||||
page: string;
|
||||
|
||||
/**
|
||||
* Sub page loaded when the handler page is loaded.
|
||||
* If your module performs a redirect when it's opened you need to specify the sub page in here.
|
||||
* E.g. if page is 'foo' but it redirects to 'foo/bar' when opened, this value must be 'bar'.
|
||||
*/
|
||||
subPage?: string;
|
||||
|
||||
/**
|
||||
* Title to display for the handler.
|
||||
*/
|
||||
|
|
|
@ -31,6 +31,9 @@ function buildRoutes(injector: Injector): Routes {
|
|||
},
|
||||
{
|
||||
path: 'search',
|
||||
data: {
|
||||
isMainMenuRoot: true,
|
||||
},
|
||||
loadChildren: () => import('@features/tag//pages/search/search.page.module').then(m => m.CoreTagSearchPageModule),
|
||||
},
|
||||
CoreTagIndexAreaRoute,
|
||||
|
|
|
@ -519,6 +519,31 @@ export class CoreNavigatorService {
|
|||
return path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the full path of a certain route, including parent routes paths.
|
||||
*
|
||||
* @param route Route.
|
||||
* @return Path.
|
||||
*/
|
||||
getRouteFullPath(route: ActivatedRoute | null): string {
|
||||
if (!route) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const parentPath = this.getRouteFullPath(route.parent);
|
||||
const routePath = route.snapshot.url.join('/');
|
||||
|
||||
if (!parentPath && !routePath) {
|
||||
return '';
|
||||
} else if (parentPath && !routePath) {
|
||||
return parentPath;
|
||||
} else if (!parentPath && routePath) {
|
||||
return '/' + routePath;
|
||||
} else {
|
||||
return parentPath + '/' + routePath;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export const CoreNavigator = makeSingleton(CoreNavigatorService);
|
||||
|
|
Loading…
Reference in New Issue