mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
work on action manager
This commit is contained in:
@@ -1,8 +1,7 @@
|
|||||||
import { Registry } from "./core/registry";
|
import { Registry } from "./core/registry";
|
||||||
import { ActionWidget } from "./store/store";
|
import { ActionWidget } from "./store/store";
|
||||||
import { CRM } from "./widgets/crm";
|
|
||||||
import { Discuss } from "./widgets/discuss";
|
import { Discuss } from "./widgets/discuss";
|
||||||
|
|
||||||
export const actionRegistry: Registry<ActionWidget> = new Registry();
|
export const actionRegistry: Registry<ActionWidget> = new Registry();
|
||||||
|
|
||||||
actionRegistry.add("discuss", Discuss).add("crm", CRM);
|
actionRegistry.add("mail.discuss", Discuss);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { Type } from "../core/component";
|
import { Type } from "../core/component";
|
||||||
import { rpcMixin } from "./rpc_mixin";
|
import { rpcMixin } from "./rpc_mixin";
|
||||||
import { Widget } from "../widgets/widget";
|
import { Widget } from "../widgets/widget";
|
||||||
|
import { View } from "../widgets/view";
|
||||||
|
|
||||||
export type Context = { [key: string]: any };
|
export type Context = { [key: string]: any };
|
||||||
|
|
||||||
@@ -9,21 +10,19 @@ export interface CommonActionInfo {
|
|||||||
context: Context;
|
context: Context;
|
||||||
title: string;
|
title: string;
|
||||||
target: "current" | "new";
|
target: "current" | "new";
|
||||||
|
Widget: ActionWidget;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ActionRequest = string | number;
|
export type ActionRequest = number;
|
||||||
|
|
||||||
export type ActionWidget = Type<Widget<{}, {}>>;
|
export type ActionWidget = Type<Widget<{}, {}>>;
|
||||||
|
|
||||||
export interface ClientActionInfo extends CommonActionInfo {
|
export interface ClientActionInfo extends CommonActionInfo {
|
||||||
type: "client";
|
type: "client";
|
||||||
name: string;
|
|
||||||
Widget: ActionWidget;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ActWindowInfo extends CommonActionInfo {
|
export interface ActWindowInfo extends CommonActionInfo {
|
||||||
type: "act_window";
|
type: "act_window";
|
||||||
view: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface BaseActionDescription {
|
interface BaseActionDescription {
|
||||||
@@ -63,31 +62,55 @@ export function actionManagerMixin<T extends ReturnType<typeof rpcMixin>>(
|
|||||||
actionCache: { [key: number]: Promise<ActionDescription> } = {};
|
actionCache: { [key: number]: Promise<ActionDescription> } = {};
|
||||||
|
|
||||||
async doAction(request: ActionRequest) {
|
async doAction(request: ActionRequest) {
|
||||||
if (typeof request === "number") {
|
const descr = await this.loadAction(request);
|
||||||
const descr = await this.loadAction(request);
|
switch (descr.type) {
|
||||||
// this is an action ID
|
case "ir.actions.client":
|
||||||
let name = request === 131 ? "discuss" : "crm";
|
return this.doClientAction(descr);
|
||||||
let title =
|
case "ir.actions.act_window":
|
||||||
request === 131 ? "Discuss" : request === 250 ? "Notes" : "CRM";
|
return this.doActWindowAction(descr);
|
||||||
let Widget = this.actionRegistry.get(name);
|
default:
|
||||||
this.update({
|
throw new Error("unhandled action");
|
||||||
inHome: false,
|
|
||||||
stack: [
|
|
||||||
{
|
|
||||||
id: 1,
|
|
||||||
context: {},
|
|
||||||
target: "current",
|
|
||||||
type: "client",
|
|
||||||
name,
|
|
||||||
title,
|
|
||||||
Widget: Widget
|
|
||||||
}
|
|
||||||
]
|
|
||||||
});
|
|
||||||
document.title = descr.name + " - Odoo";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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> {
|
loadAction(id: number): Promise<ActionDescription> {
|
||||||
if (id in this.actionCache) {
|
if (id in this.actionCache) {
|
||||||
return this.actionCache[id];
|
return this.actionCache[id];
|
||||||
|
|||||||
@@ -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() {
|
async setContentWidget() {
|
||||||
const info = this.props.stack[this.props.stack.length - 1];
|
const info = this.props.stack[this.props.stack.length - 1];
|
||||||
if (info && info.type === "client") {
|
if (info) {
|
||||||
const Widget = info.Widget;
|
const Widget = info.Widget;
|
||||||
let widget = new Widget(this, {});
|
let widget = new Widget(this, {});
|
||||||
await widget.mount(this.el || document.createElement("div"));
|
await widget.mount(this.el || document.createElement("div"));
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import { Widget } from "./widget";
|
||||||
|
|
||||||
|
export class View extends Widget<{}, {}> {
|
||||||
|
inlineTemplate = "<div>some view</div>";
|
||||||
|
}
|
||||||
@@ -73,10 +73,6 @@
|
|||||||
|
|
||||||
<div t-name="web.action_container" class="o_content"/>
|
<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">
|
<div t-name="web.discuss" class="o_discuss">
|
||||||
<span>DISCUSS!!</span>
|
<span>DISCUSS!!</span>
|
||||||
<button t-on-click="resetCounter">Reset first counter</button>
|
<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 aria-label=\\"Applications\\" class=\\"o_title fa fa-th\\" href=\\"#\\" title=\\"Applications\\" accesskey=\\"h\\"></a>
|
||||||
|
|
||||||
<a class=\\"o_menu_brand\\" href=\\"\\" role=\\"button\\">
|
<a class=\\"o_menu_brand\\" href=\\"\\" role=\\"button\\">
|
||||||
CRM
|
Discuss
|
||||||
</a>
|
</a>
|
||||||
<ul class=\\"o_menu_sections\\">
|
<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>
|
</ul>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class=\\"o_content\\"><div class=\\"o_crm\\">
|
<div class=\\"o_content\\"><div class=\\"o_discuss\\">
|
||||||
<span>CRM!!!!</span>
|
<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></div>
|
||||||
|
|
||||||
<div class=\\"o_notification_container\\"></div>
|
<div class=\\"o_notification_container\\"></div>
|
||||||
|
|||||||
@@ -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 () => {
|
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 });
|
store = helpers.makeTestStore({ router });
|
||||||
env = makeEnv(store, templates);
|
env = makeEnv(store, templates);
|
||||||
await helpers.nextTick();
|
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);
|
const root = new Root(env, store);
|
||||||
await root.mount(fixture);
|
await root.mount(fixture);
|
||||||
expect(env.services.router.getQuery()).toEqual({
|
expect(env.services.router.getQuery()).toEqual({
|
||||||
action_id: "595",
|
action_id: "131",
|
||||||
menu_id: "409"
|
menu_id: "96"
|
||||||
});
|
});
|
||||||
expect(fixture.innerHTML).toMatchSnapshot();
|
expect(fixture.innerHTML).toMatchSnapshot();
|
||||||
// we check here that the url was changed to set app id as menu_id
|
// we check here that the url was changed to set app id as menu_id
|
||||||
|
|||||||
Reference in New Issue
Block a user