mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
preliminary work for better menu support
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
import { debounce } from "./core/utils";
|
||||
import { makeEnvironment } from "./env";
|
||||
import { Root } from "./widgets/root";
|
||||
import { MenuItem, processMenuItems } from "./misc/menu_helpers";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Application bootstrapping
|
||||
@@ -10,9 +11,18 @@ import { Root } from "./widgets/root";
|
||||
|
||||
document.addEventListener("DOMContentLoaded", async function() {
|
||||
const env = await makeEnvironment();
|
||||
const rootWidget = new Root(env);
|
||||
await rootWidget.mount(document.body);
|
||||
|
||||
// menu processing
|
||||
const menuItems: MenuItem[] = (<any>window).odoo.menus;
|
||||
const menuInfo = processMenuItems(menuItems);
|
||||
delete (<any>window).odoo.menus; // overkill?
|
||||
|
||||
// creating root widget
|
||||
const rootWidget = new Root(env, { menuInfo });
|
||||
await rootWidget.mount(document.body);
|
||||
(<any>window).odoo.rootWidget = rootWidget;
|
||||
|
||||
// adding reactiveness to mobile/non mobile
|
||||
window.addEventListener("resize", <any>debounce(() => {
|
||||
const isMobile = window.innerWidth <= 768;
|
||||
if (isMobile !== env.isMobile) {
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Types
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
export interface BaseMenuItem {
|
||||
id: number;
|
||||
name: string;
|
||||
parent_id: number | false;
|
||||
action: string | false;
|
||||
icon: string | false;
|
||||
}
|
||||
|
||||
export interface MenuItem extends BaseMenuItem {
|
||||
children: MenuItem[];
|
||||
}
|
||||
|
||||
export interface ProcessedMenuItem extends BaseMenuItem {
|
||||
children: number[];
|
||||
}
|
||||
|
||||
export interface MenuInfo {
|
||||
menuMap: { [key: number]: ProcessedMenuItem | undefined };
|
||||
roots: number[];
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Helpers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
export function processMenuItems(items: MenuItem[]): MenuInfo {
|
||||
const menuMap: MenuInfo["menuMap"] = {};
|
||||
const roots: number[] = [];
|
||||
|
||||
for (let root of items) {
|
||||
roots.push(root.id);
|
||||
addToMap(root);
|
||||
}
|
||||
|
||||
function addToMap(m: MenuItem) {
|
||||
let processedItem: ProcessedMenuItem = Object.assign({}, m, {
|
||||
children: m.children.map(c => c.id)
|
||||
});
|
||||
menuMap[processedItem.id] = processedItem;
|
||||
m.children.forEach(addToMap);
|
||||
}
|
||||
|
||||
return { menuMap, roots };
|
||||
}
|
||||
|
||||
// todo
|
||||
|
||||
// menu -> formatURL(menuID, menus),
|
||||
// findApp(menuID, menus),
|
||||
// findMenu
|
||||
@@ -1,7 +1,8 @@
|
||||
import { INotification } from "../core/notifications";
|
||||
import { Widget } from "../core/widget";
|
||||
import { Env } from "../env";
|
||||
import { MenuInfo } from "../misc/menu_helpers";
|
||||
import { ActionStack } from "../services/action_manager";
|
||||
import { INotification } from "../core/notifications";
|
||||
import { ActionContainer } from "./action_container";
|
||||
import { HomeMenu } from "./home_menu";
|
||||
import { Navbar } from "./navbar";
|
||||
@@ -17,11 +18,15 @@ interface State {
|
||||
inHome: boolean;
|
||||
}
|
||||
|
||||
interface Props {
|
||||
menuInfo: MenuInfo;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Root Widget
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
export class Root extends Widget<Env, {}> {
|
||||
export class Root extends Widget<Env, Props> {
|
||||
template = "web.web_client";
|
||||
widgets = { Navbar, Notification, HomeMenu, ActionContainer };
|
||||
|
||||
@@ -31,11 +36,6 @@ export class Root extends Widget<Env, {}> {
|
||||
inHome: false
|
||||
};
|
||||
|
||||
constructor(env: Env) {
|
||||
super(env);
|
||||
this.toggleHome = this.toggleHome.bind(this);
|
||||
}
|
||||
|
||||
mounted() {
|
||||
this.env.notifications.on("notifications_updated", this, notifs =>
|
||||
this.updateState({ notifications: notifs })
|
||||
|
||||
Reference in New Issue
Block a user