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 [
|
return [
|
||||||
{
|
{
|
||||||
path: 'index',
|
path: 'index',
|
||||||
|
data: {
|
||||||
|
isMainMenuRoot: true,
|
||||||
|
},
|
||||||
loadChildren: () => import('@/addons/calendar/pages/index/index.module').then(m => m.AddonCalendarIndexPageModule),
|
loadChildren: () => import('@/addons/calendar/pages/index/index.module').then(m => m.AddonCalendarIndexPageModule),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'list',
|
path: 'list',
|
||||||
|
data: {
|
||||||
|
isMainMenuRoot: true,
|
||||||
|
},
|
||||||
loadChildren: () => import('@/addons/calendar/pages/list/list.module').then(m => m.AddonCalendarListPageModule),
|
loadChildren: () => import('@/addons/calendar/pages/list/list.module').then(m => m.AddonCalendarListPageModule),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -26,6 +26,9 @@ import { AddonMessagesDiscussions35Page } from './discussions.page';
|
||||||
const mobileRoutes: Routes = [
|
const mobileRoutes: Routes = [
|
||||||
{
|
{
|
||||||
path: '',
|
path: '',
|
||||||
|
data: {
|
||||||
|
isMainMenuRoot: true,
|
||||||
|
},
|
||||||
component: AddonMessagesDiscussions35Page,
|
component: AddonMessagesDiscussions35Page,
|
||||||
},
|
},
|
||||||
AddonMessagesDiscussionRoute,
|
AddonMessagesDiscussionRoute,
|
||||||
|
@ -34,6 +37,9 @@ const mobileRoutes: Routes = [
|
||||||
const tabletRoutes: Routes = [
|
const tabletRoutes: Routes = [
|
||||||
{
|
{
|
||||||
path: '',
|
path: '',
|
||||||
|
data: {
|
||||||
|
isMainMenuRoot: true,
|
||||||
|
},
|
||||||
component: AddonMessagesDiscussions35Page,
|
component: AddonMessagesDiscussions35Page,
|
||||||
children: [
|
children: [
|
||||||
AddonMessagesDiscussionRoute,
|
AddonMessagesDiscussionRoute,
|
||||||
|
|
|
@ -25,6 +25,9 @@ import { AddonMessagesGroupConversationsPage } from './group-conversations.page'
|
||||||
const mobileRoutes: Routes = [
|
const mobileRoutes: Routes = [
|
||||||
{
|
{
|
||||||
path: '',
|
path: '',
|
||||||
|
data: {
|
||||||
|
isMainMenuRoot: true,
|
||||||
|
},
|
||||||
component: AddonMessagesGroupConversationsPage,
|
component: AddonMessagesGroupConversationsPage,
|
||||||
},
|
},
|
||||||
AddonMessagesDiscussionRoute,
|
AddonMessagesDiscussionRoute,
|
||||||
|
@ -33,6 +36,9 @@ const mobileRoutes: Routes = [
|
||||||
const tabletRoutes: Routes = [
|
const tabletRoutes: Routes = [
|
||||||
{
|
{
|
||||||
path: '',
|
path: '',
|
||||||
|
data: {
|
||||||
|
isMainMenuRoot: true,
|
||||||
|
},
|
||||||
component: AddonMessagesGroupConversationsPage,
|
component: AddonMessagesGroupConversationsPage,
|
||||||
children: [
|
children: [
|
||||||
AddonMessagesDiscussionRoute,
|
AddonMessagesDiscussionRoute,
|
||||||
|
|
|
@ -21,6 +21,9 @@ function buildRoutes(injector: Injector): Routes {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
path: 'list',
|
path: 'list',
|
||||||
|
data: {
|
||||||
|
isMainMenuRoot: true,
|
||||||
|
},
|
||||||
loadChildren: () => import('./pages/list/list.module').then(m => m.AddonNotificationsListPageModule),
|
loadChildren: () => import('./pages/list/list.module').then(m => m.AddonNotificationsListPageModule),
|
||||||
},
|
},
|
||||||
...buildTabMainRoutes(injector, {
|
...buildTabMainRoutes(injector, {
|
||||||
|
|
|
@ -19,12 +19,19 @@ import { buildTabMainRoutes } from '@features/mainmenu/mainmenu-tab-routing.modu
|
||||||
|
|
||||||
function buildRoutes(injector: Injector): Routes {
|
function buildRoutes(injector: Injector): Routes {
|
||||||
return [
|
return [
|
||||||
|
{
|
||||||
|
path: 'root',
|
||||||
|
data: {
|
||||||
|
isMainMenuRoot: true,
|
||||||
|
},
|
||||||
|
loadChildren: () => import('./pages/index/index.module').then(m => m.AddonPrivateFilesIndexPageModule),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: ':hash',
|
path: ':hash',
|
||||||
loadChildren: () => import('./pages/index/index.module').then(m => m.AddonPrivateFilesIndexPageModule),
|
loadChildren: () => import('./pages/index/index.module').then(m => m.AddonPrivateFilesIndexPageModule),
|
||||||
},
|
},
|
||||||
...buildTabMainRoutes(injector, {
|
...buildTabMainRoutes(injector, {
|
||||||
redirectTo: 'root', // Fake "hash".
|
redirectTo: 'root',
|
||||||
pathMatch: 'full',
|
pathMatch: 'full',
|
||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
|
|
|
@ -48,7 +48,6 @@ export class AddonPrivateFilesMainMenuHandlerService implements CoreMainMenuHand
|
||||||
icon: 'fas-folder',
|
icon: 'fas-folder',
|
||||||
title: 'addon.privatefiles.files',
|
title: 'addon.privatefiles.files',
|
||||||
page: AddonPrivateFilesMainMenuHandlerService.PAGE_NAME,
|
page: AddonPrivateFilesMainMenuHandlerService.PAGE_NAME,
|
||||||
subPage: 'root',
|
|
||||||
class: 'addon-privatefiles-handler',
|
class: 'addon-privatefiles-handler',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,9 @@ function buildRoutes(injector: Injector): Routes {
|
||||||
return [
|
return [
|
||||||
...buildTabMainRoutes(injector, {
|
...buildTabMainRoutes(injector, {
|
||||||
path: '',
|
path: '',
|
||||||
|
data: {
|
||||||
|
isMainMenuRoot: true,
|
||||||
|
},
|
||||||
component: CoreMainMenuHomePage,
|
component: CoreMainMenuHomePage,
|
||||||
children: routes.children,
|
children: routes.children,
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -13,13 +13,12 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
import { Component, OnInit, OnDestroy, ViewChild, ChangeDetectorRef } from '@angular/core';
|
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 { IonTabs } from '@ionic/angular';
|
||||||
import { BackButtonEvent } from '@ionic/core';
|
import { BackButtonEvent } from '@ionic/core';
|
||||||
import { Subscription } from 'rxjs';
|
import { Subscription } from 'rxjs';
|
||||||
|
|
||||||
import { CoreApp } from '@services/app';
|
import { CoreApp } from '@services/app';
|
||||||
import { CoreTextUtils } from '@services/utils/text';
|
|
||||||
import { CoreEvents, CoreEventObserver } from '@singletons/events';
|
import { CoreEvents, CoreEventObserver } from '@singletons/events';
|
||||||
import { CoreMainMenu, CoreMainMenuProvider } from '../../services/mainmenu';
|
import { CoreMainMenu, CoreMainMenuProvider } from '../../services/mainmenu';
|
||||||
import { CoreMainMenuDelegate, CoreMainMenuHandlerToDisplay } from '../../services/mainmenu-delegate';
|
import { CoreMainMenuDelegate, CoreMainMenuHandlerToDisplay } from '../../services/mainmenu-delegate';
|
||||||
|
@ -27,6 +26,7 @@ import { CoreDomUtils } from '@services/utils/dom';
|
||||||
import { Translate } from '@singletons';
|
import { Translate } from '@singletons';
|
||||||
import { CoreUtils } from '@services/utils/utils';
|
import { CoreUtils } from '@services/utils/utils';
|
||||||
import { CoreAriaRoleTab, CoreAriaRoleTabFindable } from '@classes/aria-role-tab';
|
import { CoreAriaRoleTab, CoreAriaRoleTabFindable } from '@classes/aria-role-tab';
|
||||||
|
import { CoreNavigator } from '@services/navigator';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Page that displays the main menu of the app.
|
* Page that displays the main menu of the app.
|
||||||
|
@ -61,7 +61,6 @@ export class CoreMainMenuPage implements OnInit, OnDestroy {
|
||||||
constructor(
|
constructor(
|
||||||
protected route: ActivatedRoute,
|
protected route: ActivatedRoute,
|
||||||
protected changeDetector: ChangeDetectorRef,
|
protected changeDetector: ChangeDetectorRef,
|
||||||
protected router: Router,
|
|
||||||
) {
|
) {
|
||||||
this.resizeFunction = this.initHandlers.bind(this);
|
this.resizeFunction = this.initHandlers.bind(this);
|
||||||
this.backButtonFunction = this.backButtonClicked.bind(this);
|
this.backButtonFunction = this.backButtonClicked.bind(this);
|
||||||
|
@ -172,29 +171,26 @@ export class CoreMainMenuPage implements OnInit, OnDestroy {
|
||||||
return;
|
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.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
e.stopImmediatePropagation();
|
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 {
|
try {
|
||||||
const tab = this.tabs.find((tab) => tab.page == page);
|
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) {
|
if (tab?.title) {
|
||||||
await CoreDomUtils.showConfirm(Translate.instant('core.confirmgotabroot', {
|
await CoreDomUtils.showConfirm(Translate.instant('core.confirmgotabroot', {
|
||||||
name: Translate.instant(tab.title),
|
name: Translate.instant(tab.title),
|
||||||
|
|
|
@ -136,7 +136,6 @@ export class CoreMainMenuMorePage implements OnInit, OnDestroy {
|
||||||
* Open a handler.
|
* Open a handler.
|
||||||
*
|
*
|
||||||
* @param handler Handler to open.
|
* @param handler Handler to open.
|
||||||
* @todo: use subPage?
|
|
||||||
*/
|
*/
|
||||||
openHandler(handler: CoreMainMenuHandlerData): void {
|
openHandler(handler: CoreMainMenuHandlerData): void {
|
||||||
const params = handler.pageParams;
|
const params = handler.pageParams;
|
||||||
|
|
|
@ -42,7 +42,6 @@ export class CoreMainMenuHomeHandlerService implements CoreMainMenuHandler {
|
||||||
icon: 'fas-tachometer-alt',
|
icon: 'fas-tachometer-alt',
|
||||||
title: 'core.mainmenu.home',
|
title: 'core.mainmenu.home',
|
||||||
page: CoreMainMenuHomeHandlerService.PAGE_NAME,
|
page: CoreMainMenuHomeHandlerService.PAGE_NAME,
|
||||||
// @todo: subPage? The page can change due to core-tabs.
|
|
||||||
class: 'core-home-handler',
|
class: 'core-home-handler',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,13 +33,6 @@ export interface CoreMainMenuHandlerData {
|
||||||
*/
|
*/
|
||||||
page: string;
|
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.
|
* Title to display for the handler.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -31,6 +31,9 @@ function buildRoutes(injector: Injector): Routes {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'search',
|
path: 'search',
|
||||||
|
data: {
|
||||||
|
isMainMenuRoot: true,
|
||||||
|
},
|
||||||
loadChildren: () => import('@features/tag//pages/search/search.page.module').then(m => m.CoreTagSearchPageModule),
|
loadChildren: () => import('@features/tag//pages/search/search.page.module').then(m => m.CoreTagSearchPageModule),
|
||||||
},
|
},
|
||||||
CoreTagIndexAreaRoute,
|
CoreTagIndexAreaRoute,
|
||||||
|
|
|
@ -519,6 +519,31 @@ export class CoreNavigatorService {
|
||||||
return path;
|
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);
|
export const CoreNavigator = makeSingleton(CoreNavigatorService);
|
||||||
|
|
Loading…
Reference in New Issue