2019-02-19 09:33:09 +01:00
|
|
|
import { WEnv } from "./core/component";
|
2019-02-18 15:34:23 +01:00
|
|
|
import { QWeb } from "./core/qweb_vdom";
|
2019-02-19 20:47:21 +01:00
|
|
|
import { idGenerator } from "./core/utils";
|
2019-02-27 13:48:36 +01:00
|
|
|
import { INotification, RPC, Services, Store } from "./store/store";
|
2019-02-18 15:34:23 +01:00
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
// Types
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
2019-02-19 09:33:09 +01:00
|
|
|
export interface Env extends WEnv {
|
2019-02-19 20:47:21 +01:00
|
|
|
services: Services;
|
2019-02-19 09:33:09 +01:00
|
|
|
|
2019-02-20 14:55:49 +01:00
|
|
|
// commands
|
|
|
|
|
activateMenuItem(menuId: number): void;
|
2019-02-20 09:46:22 +01:00
|
|
|
addNotification(notif: Partial<INotification>): number;
|
2019-02-20 14:55:49 +01:00
|
|
|
closeNotification(id: number): void;
|
|
|
|
|
toggleHomeMenu(): void;
|
|
|
|
|
|
|
|
|
|
// helpers
|
2019-02-19 20:47:21 +01:00
|
|
|
rpc: RPC;
|
2019-02-19 09:33:09 +01:00
|
|
|
|
|
|
|
|
// configuration
|
|
|
|
|
debug: boolean;
|
|
|
|
|
isMobile: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-18 15:34:23 +01:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
// Environment
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
2019-02-19 20:47:21 +01:00
|
|
|
export function makeEnv(store: Store, templates: string): Env {
|
2019-02-18 15:34:23 +01:00
|
|
|
const qweb = new QWeb();
|
|
|
|
|
qweb.addTemplate("default", "<div/>");
|
|
|
|
|
qweb.loadTemplates(templates);
|
|
|
|
|
|
|
|
|
|
const env: Env = {
|
|
|
|
|
qweb,
|
|
|
|
|
getID: idGenerator(),
|
2019-02-20 14:55:49 +01:00
|
|
|
|
2019-02-19 20:47:21 +01:00
|
|
|
services: store.services,
|
2019-02-20 14:55:49 +01:00
|
|
|
|
|
|
|
|
activateMenuItem: store.activateMenuItem.bind(store),
|
2019-02-20 09:46:22 +01:00
|
|
|
addNotification: store.addNotification.bind(store),
|
|
|
|
|
closeNotification: store.closeNotification.bind(store),
|
2019-02-20 14:55:49 +01:00
|
|
|
toggleHomeMenu: store.toggleHomeMenu.bind(store),
|
|
|
|
|
|
2019-02-19 20:47:21 +01:00
|
|
|
rpc: store.rpc.bind(store),
|
2019-02-20 14:55:49 +01:00
|
|
|
|
2019-02-18 15:34:23 +01:00
|
|
|
debug: false,
|
|
|
|
|
isMobile: window.innerWidth <= 768
|
|
|
|
|
};
|
|
|
|
|
return env;
|
|
|
|
|
}
|