From 0e9edd4d1746488ef9af41062aeb402b1d58f31d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Fri, 1 Mar 2019 12:58:26 +0100 Subject: [PATCH] update demo data for actions --- web/demo_data.js | 132 +++++++++++++++--- web/static/src/ts/services/ajax.ts | 4 +- .../src/ts/store/action_manager_mixin.ts | 21 ++- 3 files changed, 133 insertions(+), 24 deletions(-) diff --git a/web/demo_data.js b/web/demo_data.js index 383c09ca..b1a82180 100644 --- a/web/demo_data.js +++ b/web/demo_data.js @@ -8,25 +8,7 @@ parent_id: false, action: "ir.actions.client,131", icon: "fa fa-comment", - children: [ - { - id: 97, - name: "Integrations", - parent_id: 96, - action: false, - icon: false, - children: [ - { - id: 188, - name: "Github Repositories", - parent_id: 97, - action: "ir.actions.act_window,233", - icon: false, - children: [] - } - ] - } - ] + children: [] }, { id: 205, @@ -107,4 +89,116 @@ window.demoData = { menus: menus }; + + const actions = [ + { + id: 131, + type: "ir.actions.client", + target: "current", + name: "Discuss", + tag: "mail.discuss" + }, + { + id: 250, + type: "ir.actions.act_window", + name: "Notes", + target: "current", + domain: false, + context: "{}", + views: [[false, "kanban"], [false, "list"], [false, "form"]], + res_id: 0, + res_model: "note.note" + }, + { + id: 597, + type: "ir.actions.act_window", + name: "Pipeline", + target: "current", + domain: false, + context: { default_team_id: 1 }, + views: [[2103, "kanban"], [2106, "list"], [2105, "form"]], + res_id: 0, + res_model: "crm.lead" + }, + { + id: 1051, + type: "ir.actions.act_window", + name: "Quotations", + target: "current", + domain: false, + context: "{'search_default_my_quotation': 1}", + views: [ + [3387, "list"], + [3385, "kanban"], + [3389, "form"], + [3382, "calendar"], + [3384, "pivot"], + [3383, "graph"] + ], + res_id: 0, + res_model: "sale.order" + }, + { + id: 275, + type: "ir.actions.act_window", + name: "Team Pipelines", + target: "current", + context: "{}", + domain: "[('use_opportunities', '=', True)]", + views: [[false, "kanban"], [false, "form"]], + res_id: 0, + res_model: "crm.team" + }, + { + id: 595, + type: "ir.actions.act_window", + name: "Leads", + target: "current", + context: + "{ 'default_type':'lead', 'search_default_type': 'lead', 'search_default_to_process':1, }", + domain: "['|', ('type','=','lead'), ('type','=',False)]", + views: [ + [2098, "list"], + [2099, "kanban"], + [2100, "calendar"], + [2108, "pivot"], + [2107, "graph"], + [false, "form"] + ], + res_id: 0, + res_model: "crm.lead" + }, + { + id: 1083, + type: "ir.actions.act_window", + name: "Scores", + target: "current", + context: "{}", + domain: false, + views: [[false, "list"], [false, "kanban"], [false, "form"]], + res_id: 0, + res_model: "website.crm.score" + } + ]; + + window.demoData.mockAjax = async function(route, params) { + console.log("RPC", route, params); + + // wait some random delay + const delay = Math.random() * 1000; + await new Promise(resolve => setTimeout(resolve, delay)); + + // mock action + if (route === "web/action/load") { + const action = actions.find(a => a.id === params.action_id); + if (action) { + return action; + } else { + throw new Error("cannot find action"); + } + } + // unknown route + console.warn("Unknown route", route); + return true; + }; })(window); diff --git a/web/static/src/ts/services/ajax.ts b/web/static/src/ts/services/ajax.ts index eba8e968..f632d0c2 100644 --- a/web/static/src/ts/services/ajax.ts +++ b/web/static/src/ts/services/ajax.ts @@ -1,7 +1,5 @@ export type RPC = (route: string, params: any) => Promise; export const rpc: RPC = async function(route, params) { - console.log("RPC", route, params); - const delay = Math.random() * 1000; - return new Promise(resolve => setTimeout(resolve, delay)); + return (window).demoData.mockAjax(route, params); }; diff --git a/web/static/src/ts/store/action_manager_mixin.ts b/web/static/src/ts/store/action_manager_mixin.ts index 6ecdbdc3..08a62ad5 100644 --- a/web/static/src/ts/store/action_manager_mixin.ts +++ b/web/static/src/ts/store/action_manager_mixin.ts @@ -26,11 +26,28 @@ export interface ActWindowInfo extends CommonActionInfo { view: string; } -export interface ActionDescription { +interface BaseActionDescription { id: number; - type: "ir.actions.act_window" | "ir.actions.client"; target: "current"; + name: string; } +interface ClientActionDescription extends BaseActionDescription { + type: "ir.actions.client"; + tag: string; +} + +interface ActWindowActionDescription extends BaseActionDescription { + type: "ir.actions.act_window"; + views: [false | number, string][]; + domain: false | string; + res_id: number; + res_model: string; + context: Object | string; +} + +export type ActionDescription = + | ClientActionDescription + | ActWindowActionDescription; export type ActionInfo = ClientActionInfo | ActWindowInfo; export type ActionStack = ActionInfo[];