change menuinfo data structure

This commit is contained in:
Géry Debongnie
2019-02-05 21:08:06 +01:00
parent 5f49f82a04
commit 0eb68b7f77
7 changed files with 44 additions and 43 deletions
+2 -2
View File
@@ -1,4 +1,4 @@
import { MenuItem } from "../misc/menu_helpers";
import { MenuItem } from "./root";
import { PureWidget } from "./widget";
//------------------------------------------------------------------------------
@@ -19,7 +19,7 @@ export class Navbar extends PureWidget<Props, {}> {
getUrl(menu: MenuItem) {
const action_id = String(menu.actionId);
const menu_id = String(menu.menuId);
const menu_id = String(menu.app.id);
return this.env.router.formatURL("", { action_id, menu_id });
}
+2 -2
View File
@@ -1,4 +1,4 @@
import { MenuInfo, MenuItem } from "../misc/menu_helpers";
import { MenuInfo, MenuItem } from "../widgets/root";
import { Widget } from "./widget";
//------------------------------------------------------------------------------
@@ -18,7 +18,7 @@ export class HomeMenu extends Widget<Props, {}> {
get apps(): MenuItem[] {
const info = this.props.menuInfo;
return info.roots.map(root => info.menuMap[root]!);
return info.roots.map(root => info.menus[root]!);
}
openMenu(app: MenuItem, event: MouseEvent) {
+10 -12
View File
@@ -20,16 +20,15 @@ export interface MenuItem {
icon: string | false;
// root menu id
appId: number;
app: MenuItem;
actionId: number;
children: MenuItem[];
}
export interface MenuInfo {
menuMap: { [key: number]: MenuItem | undefined };
menus: { [key: number]: MenuItem | undefined };
// mapping from action id to menu id
actionMap: { [id: number]: number | undefined };
actionMap: { [id: number]: MenuItem | undefined };
roots: number[];
}
@@ -100,13 +99,14 @@ export class Root extends Widget<Props, State> {
const newApp = app || this.state.currentApp;
if (actionId) {
const query: Query = { action_id: String(actionId) };
const menuId = newApp ? newApp.appId : false;
const menuId = newApp ? newApp.app.id : false;
if (menuId) {
query.menu_id = String(menuId);
}
if (app) {
this.updateState({ currentApp: app });
}
debugger;
this.env.router.navigate(query);
this.env.actionManager.doAction(actionId);
} else {
@@ -119,8 +119,7 @@ export class Root extends Widget<Props, State> {
}
openMenu(menu: MenuItem) {
const app = this.props.menuInfo.menuMap[menu.appId]!;
this.updateAppState(app, menu.actionId);
this.updateAppState(menu.app, menu.actionId);
}
private getAppAndAction(
@@ -132,16 +131,15 @@ export class Root extends Widget<Props, State> {
if ("action_id" in query) {
actionId = parseInt(query.action_id, 10);
if (menuInfo.actionMap[actionId]) {
const menuId = menuInfo.actionMap[actionId]!;
const appId = menuInfo.menuMap[menuId]!.appId;
app = menuInfo.menuMap[appId]!;
const menu = menuInfo.actionMap[actionId]!;
app = menu.app;
}
}
if ("menu_id" in query) {
const menuId = parseInt(query.menu_id, 10);
const menu = menuInfo.menuMap[menuId];
const menu = menuInfo.menus[menuId];
if (menu) {
app = menuInfo.menuMap[menu.appId] || null;
app = menu.app;
if (!actionId) {
actionId = menu.actionId;
}