Files
owl/web/static/src/ts/env.ts
T

70 lines
1.9 KiB
TypeScript
Raw Normal View History

2019-01-24 10:33:11 +01:00
import { QWeb } from "./core/qweb_vdom";
import { idGenerator, memoize } from "./core/utils";
2019-01-23 14:28:41 +01:00
import { WEnv } from "./core/widget";
2019-01-27 09:41:56 +01:00
import { registry } from "./registry";
2019-01-26 20:22:32 +01:00
import { ActionManager, IActionManager } from "./services/action_manager";
import { Ajax, IAjax } from "./services/ajax";
2019-01-26 23:41:03 +01:00
import { IRouter, Router } from "./services/router";
//------------------------------------------------------------------------------
// Types
//------------------------------------------------------------------------------
export interface Menu {
title: string;
actionID: number;
}
2019-01-16 13:19:58 +01:00
2019-01-23 14:28:41 +01:00
export interface Env extends WEnv {
2019-01-26 23:41:03 +01:00
// services
2019-01-26 20:22:32 +01:00
actionManager: IActionManager;
ajax: IAjax;
2019-01-26 18:12:54 +01:00
router: IRouter;
menus: Menu[];
2019-01-26 23:41:03 +01:00
// helpers
2019-01-26 20:22:32 +01:00
rpc: IAjax["rpc"];
2019-01-26 23:41:03 +01:00
// configuration
debug: boolean;
2019-01-23 14:28:41 +01:00
}
2019-01-26 23:41:03 +01:00
//------------------------------------------------------------------------------
// Code
//------------------------------------------------------------------------------
/**
* makeEnvironment returns the main environment for the application.
*
* Note that it does not make much sense (except for tests) to have more than
* one environment. For example, with two environment, the router code in one
* environment will probably interfere with the code from the other environment.
*
* For this reason, the result of makeEnvironment is memoized: every call to
* this function will actually return the same environment.
*/
export const makeEnvironment = memoize(function(): Env {
2019-01-23 14:28:41 +01:00
const qweb = new QWeb();
const router = new Router();
const ajax = new Ajax();
2019-01-27 09:41:56 +01:00
const actionManager = new ActionManager(router, registry);
const menus = [
{ title: "Discuss", actionID: 1 },
{ title: "CRM", actionID: 2 }
];
2019-01-23 14:28:41 +01:00
return {
2019-01-26 20:22:32 +01:00
// Base widget requirements
2019-01-23 14:28:41 +01:00
qweb,
2019-01-26 20:22:32 +01:00
getID: idGenerator(),
2019-01-23 14:28:41 +01:00
ajax,
router,
actionManager,
menus,
2019-01-26 20:22:32 +01:00
2019-01-26 23:41:03 +01:00
rpc: ajax.rpc,
debug: false
2019-01-23 14:28:41 +01:00
};
});