diff --git a/web/static/src/scss/app.scss b/web/static/src/scss/app.scss index d170be59..7ba28c59 100644 --- a/web/static/src/scss/app.scss +++ b/web/static/src/scss/app.scss @@ -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; diff --git a/web/static/src/ts/init.ts b/web/static/src/ts/init.ts index e829f12d..cba3d05d 100644 --- a/web/static/src/ts/init.ts +++ b/web/static/src/ts/init.ts @@ -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 = { 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 }; } diff --git a/web/static/src/ts/widgets/Navbar.ts b/web/static/src/ts/widgets/Navbar.ts index 9b34fabf..b3bedc88 100644 --- a/web/static/src/ts/widgets/Navbar.ts +++ b/web/static/src/ts/widgets/Navbar.ts @@ -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 { 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 }); } diff --git a/web/static/src/ts/widgets/home_menu.ts b/web/static/src/ts/widgets/home_menu.ts index ead08e81..c63bfbd0 100644 --- a/web/static/src/ts/widgets/home_menu.ts +++ b/web/static/src/ts/widgets/home_menu.ts @@ -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 { 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) { diff --git a/web/static/src/ts/widgets/root.ts b/web/static/src/ts/widgets/root.ts index d29e1bdb..3306a574 100644 --- a/web/static/src/ts/widgets/root.ts +++ b/web/static/src/ts/widgets/root.ts @@ -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 { 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 { } 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 { 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; } diff --git a/web/static/src/xml/templates.xml b/web/static/src/xml/templates.xml index 409b9242..86d895d4 100644 --- a/web/static/src/xml/templates.xml +++ b/web/static/src/xml/templates.xml @@ -55,7 +55,7 @@