work on action manager

This commit is contained in:
Géry Debongnie
2019-03-02 08:34:29 +01:00
parent 1f0ae87262
commit fec7a9caec
8 changed files with 87 additions and 97 deletions
+1 -2
View File
@@ -1,8 +1,7 @@
import { Registry } from "./core/registry";
import { ActionWidget } from "./store/store";
import { CRM } from "./widgets/crm";
import { Discuss } from "./widgets/discuss";
export const actionRegistry: Registry<ActionWidget> = new Registry();
actionRegistry.add("discuss", Discuss).add("crm", CRM);
actionRegistry.add("mail.discuss", Discuss);
+49 -26
View File
@@ -1,6 +1,7 @@
import { Type } from "../core/component";
import { rpcMixin } from "./rpc_mixin";
import { Widget } from "../widgets/widget";
import { View } from "../widgets/view";
export type Context = { [key: string]: any };
@@ -9,21 +10,19 @@ export interface CommonActionInfo {
context: Context;
title: string;
target: "current" | "new";
Widget: ActionWidget;
}
export type ActionRequest = string | number;
export type ActionRequest = number;
export type ActionWidget = Type<Widget<{}, {}>>;
export interface ClientActionInfo extends CommonActionInfo {
type: "client";
name: string;
Widget: ActionWidget;
}
export interface ActWindowInfo extends CommonActionInfo {
type: "act_window";
view: string;
}
interface BaseActionDescription {
@@ -63,31 +62,55 @@ export function actionManagerMixin<T extends ReturnType<typeof rpcMixin>>(
actionCache: { [key: number]: Promise<ActionDescription> } = {};
async doAction(request: ActionRequest) {
if (typeof request === "number") {
const descr = await this.loadAction(request);
// this is an action ID
let name = request === 131 ? "discuss" : "crm";
let title =
request === 131 ? "Discuss" : request === 250 ? "Notes" : "CRM";
let Widget = this.actionRegistry.get(name);
this.update({
inHome: false,
stack: [
{
id: 1,
context: {},
target: "current",
type: "client",
name,
title,
Widget: Widget
}
]
});
document.title = descr.name + " - Odoo";
const descr = await this.loadAction(request);
switch (descr.type) {
case "ir.actions.client":
return this.doClientAction(descr);
case "ir.actions.act_window":
return this.doActWindowAction(descr);
default:
throw new Error("unhandled action");
}
}
doActWindowAction(descr: ActWindowActionDescription) {
let title = descr.name;
this.update({
inHome: false,
stack: [
{
id: 1,
context: {},
target: "current",
type: "act_window",
title,
Widget: View
}
]
});
document.title = descr.name + " - Odoo";
}
doClientAction(descr: ClientActionDescription) {
let key = descr.tag;
let title = descr.name;
let Widget = this.actionRegistry.get(key);
this.update({
inHome: false,
stack: [
{
id: 1,
context: {},
target: "current",
type: "client",
title,
Widget: Widget
}
]
});
document.title = descr.name + " - Odoo";
}
loadAction(id: number): Promise<ActionDescription> {
if (id in this.actionCache) {
return this.actionCache[id];
-5
View File
@@ -1,5 +0,0 @@
import { Widget } from "./widget";
export class CRM extends Widget<{}, {}> {
template = "web.crm";
}
@@ -38,7 +38,7 @@ export class ActionContainer extends Widget<Props, {}> {
async setContentWidget() {
const info = this.props.stack[this.props.stack.length - 1];
if (info && info.type === "client") {
if (info) {
const Widget = info.Widget;
let widget = new Widget(this, {});
await widget.mount(this.el || document.createElement("div"));
+5
View File
@@ -0,0 +1,5 @@
import { Widget } from "./widget";
export class View extends Widget<{}, {}> {
inlineTemplate = "<div>some view</div>";
}
-4
View File
@@ -73,10 +73,6 @@
<div t-name="web.action_container" class="o_content"/>
<div t-name="web.crm" class="o_crm">
<span>CRM!!!!</span>
</div>
<div t-name="web.discuss" class="o_discuss">
<span>DISCUSS!!</span>
<button t-on-click="resetCounter">Reset first counter</button>
@@ -39,69 +39,41 @@ exports[`if url has action_id, will render action and navigate to proper menu_id
<a aria-label=\\"Applications\\" class=\\"o_title fa fa-th\\" href=\\"#\\" title=\\"Applications\\" accesskey=\\"h\\"></a>
<a class=\\"o_menu_brand\\" href=\\"\\" role=\\"button\\">
CRM
Discuss
</a>
<ul class=\\"o_menu_sections\\">
<li>
<a href=\\"#\\" role=\\"button\\" class=\\"dropdown-toggle o-no-caret\\" data-toggle=\\"dropdown\\">
<span>
Sales
</span>
</a>
<div class=\\"dropdown-menu\\" role=\\"menu\\">
<a href=\\"\\" data-toggle=\\"collapse\\" data-target=\\"#someid\\" role=\\"menuitem\\" class=\\"dropdown-item\\">
<span>
My Pipeline
</span>
</a>
<a href=\\"\\" data-toggle=\\"collapse\\" data-target=\\"#someid\\" role=\\"menuitem\\" class=\\"dropdown-item\\">
<span>
My Quotations
</span>
</a>
<a href=\\"\\" data-toggle=\\"collapse\\" data-target=\\"#someid\\" role=\\"menuitem\\" class=\\"dropdown-item\\">
<span>
Team Pipelines
</span>
</a>
</div>
</li><li>
<a href=\\"#\\" role=\\"button\\" class=\\"dropdown-toggle o-no-caret\\" data-toggle=\\"dropdown\\">
<span>
Leads
</span>
</a>
<div class=\\"dropdown-menu\\" role=\\"menu\\">
<a href=\\"\\" data-toggle=\\"collapse\\" data-target=\\"#someid\\" role=\\"menuitem\\" class=\\"dropdown-item\\">
<span>
Leads
</span>
</a>
<a href=\\"\\" data-toggle=\\"collapse\\" data-target=\\"#someid\\" role=\\"menuitem\\" class=\\"dropdown-item\\">
<span>
Scoring Rules
</span>
</a>
</div>
</li>
</ul>
</div>
<div class=\\"o_content\\"><div class=\\"o_crm\\">
<span>CRM!!!!</span>
<div class=\\"o_content\\"><div class=\\"o_discuss\\">
<span>DISCUSS!!</span>
<button>Reset first counter</button>
<button>Reset counter 2 in 3s</button>
<button>Toggle Clock/counters</button>
<button>Toggle Color</button>
<button>Rerender this widget</button>
<input>
<div>
<button>-</button>
<span style=\\"font-weight:bold\\">Value: 4</span>
<button>+</button>
</div>
<div>
<button>-</button>
<span style=\\"font-weight:bold\\">Value: 400</span>
<button>+</button>
</div>
<div>
<span>Current Color: </span>
red
</div>
<button>Add notif</button>
<button>Add sticky notif</button>
</div></div>
<div class=\\"o_notification_container\\"></div>
+3 -3
View File
@@ -38,7 +38,7 @@ test("can be rendered (in home menu)", async () => {
});
test("if url has action_id, will render action and navigate to proper menu_id", async () => {
const router = new helpers.MockRouter({ action_id: "595" });
const router = new helpers.MockRouter({ action_id: "131" });
store = helpers.makeTestStore({ router });
env = makeEnv(store, templates);
await helpers.nextTick();
@@ -46,8 +46,8 @@ test("if url has action_id, will render action and navigate to proper menu_id",
const root = new Root(env, store);
await root.mount(fixture);
expect(env.services.router.getQuery()).toEqual({
action_id: "595",
menu_id: "409"
action_id: "131",
menu_id: "96"
});
expect(fixture.innerHTML).toMatchSnapshot();
// we check here that the url was changed to set app id as menu_id