mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
change menuinfo data structure
This commit is contained in:
@@ -109,7 +109,7 @@ body {
|
||||
.o_app {
|
||||
width: 16.6666667%;
|
||||
max-height: 110px;
|
||||
padding: 10px 0;
|
||||
padding: 20px 0;
|
||||
text-decoration: none;
|
||||
text-align: center;
|
||||
color: white;
|
||||
|
||||
+14
-14
@@ -90,34 +90,34 @@ interface BaseMenuItem {
|
||||
* is supposed to be called once at startup.
|
||||
*/
|
||||
export function getMenuInfo(items: BaseMenuItem[]): MenuInfo {
|
||||
const menuMap: { [key: number]: MenuItem | undefined } = {};
|
||||
const actionMap: { [id: number]: number | undefined } = {};
|
||||
const menus: { [key: number]: MenuItem | undefined } = {};
|
||||
const actionMap: { [id: number]: MenuItem | undefined } = {};
|
||||
const roots: number[] = [];
|
||||
|
||||
// build MenuItems
|
||||
for (let root of items) {
|
||||
roots.push(root.id);
|
||||
addToMap(root, root.id);
|
||||
addToMap(root);
|
||||
}
|
||||
|
||||
function addToMap(m: BaseMenuItem, appId: number): MenuItem {
|
||||
const item: MenuItem = {
|
||||
function addToMap(m: BaseMenuItem, app?: MenuItem): MenuItem {
|
||||
const item: Partial<MenuItem> = {
|
||||
id: m.id,
|
||||
name: m.name,
|
||||
parentId: m.parent_id,
|
||||
action: m.action,
|
||||
icon: m.icon,
|
||||
appId: appId,
|
||||
actionId: -1, // will be filled later on with correct id
|
||||
children: m.children.map(c => addToMap(c, appId))
|
||||
actionId: -1 // will be filled later on with correct id
|
||||
};
|
||||
menuMap[item.id] = item;
|
||||
return item;
|
||||
item.app = app || (item as MenuItem);
|
||||
item.children = m.children.map(c => addToMap(c, item.app as MenuItem));
|
||||
menus[item.id!] = item as MenuItem;
|
||||
return item as MenuItem;
|
||||
}
|
||||
|
||||
// add proper actionId to every menuitems
|
||||
for (let menuId in menuMap) {
|
||||
const menu = menuMap[menuId]!;
|
||||
for (let menuId in menus) {
|
||||
const menu = menus[menuId]!;
|
||||
let menuWithAction = menu && findInTree(menu, m => Boolean(m.action));
|
||||
if (menuWithAction) {
|
||||
menu.actionId = parseInt(
|
||||
@@ -125,10 +125,10 @@ export function getMenuInfo(items: BaseMenuItem[]): MenuInfo {
|
||||
10
|
||||
);
|
||||
if (menuWithAction === menu) {
|
||||
actionMap[menu.actionId] = menu.id;
|
||||
actionMap[menu.actionId] = menu;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return { menuMap, roots, actionMap };
|
||||
return { menus, roots, actionMap };
|
||||
}
|
||||
|
||||
@@ -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 });
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@
|
||||
|
||||
<div t-name="web.home_menu" class="o_home_menu">
|
||||
<div class="o_apps">
|
||||
<a t-foreach="apps" t-as="app" t-att-href="'#menu_id=' + app.menuId + '&action_id=' + app.actionId" class="o_app" t-on-click="openMenu(app)">
|
||||
<a t-foreach="apps" t-as="app" t-att-href="'#menu_id=' + app.id + '&action_id=' + app.actionId" class="o_app" t-on-click="openMenu(app)">
|
||||
<i t-att-class="app.icon + ' o_app_icon fa-3x fa-fw'"/>
|
||||
<div class="o_caption">
|
||||
<t t-esc="app.name"/>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { HomeMenu, Props } from "../../src/ts/widgets/home_menu";
|
||||
import { makeTestEnv, makeTestFixture, loadTemplates } from "../helpers";
|
||||
import { MenuItem } from "../../src/ts/widgets/root";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Setup and helpers
|
||||
@@ -18,20 +19,22 @@ beforeEach(() => {
|
||||
fixture = makeTestFixture();
|
||||
env = makeTestEnv();
|
||||
env.qweb.loadTemplates(templates);
|
||||
const demoItem: MenuItem = <any>{
|
||||
id: 14,
|
||||
name: "Demo",
|
||||
parentId: false,
|
||||
action: false,
|
||||
icon: "fa fa-test",
|
||||
children: [],
|
||||
actionId: 43
|
||||
};
|
||||
demoItem.app = demoItem;
|
||||
props = {
|
||||
menuInfo: {
|
||||
menuMap: {
|
||||
14: {
|
||||
id: 14,
|
||||
name: "Demo",
|
||||
parent_id: false,
|
||||
action: false,
|
||||
icon: "fa fa-test",
|
||||
children: [],
|
||||
menuId: 14,
|
||||
actionId: 43
|
||||
}
|
||||
menus: {
|
||||
14: demoItem
|
||||
},
|
||||
actionMap: { 43: demoItem },
|
||||
roots: [14]
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user