From 3147aa932ce0751059427fd15dc9fb7ed7a8986b Mon Sep 17 00:00:00 2001 From: yagho-odoo Date: Mon, 27 Oct 2025 17:43:41 +0100 Subject: [PATCH 01/13] [ADD] awesome_owl: added 2 components for the owl tutorial --- awesome_owl/static/src/card/card.js | 10 ++++++++++ awesome_owl/static/src/card/card.xml | 17 +++++++++++++++++ awesome_owl/static/src/counter/counter.js | 13 +++++++++++++ awesome_owl/static/src/counter/counter.xml | 13 +++++++++++++ awesome_owl/static/src/playground.js | 11 ++++++++++- awesome_owl/static/src/playground.xml | 9 +++++---- 6 files changed, 68 insertions(+), 5 deletions(-) create mode 100644 awesome_owl/static/src/card/card.js create mode 100644 awesome_owl/static/src/card/card.xml create mode 100644 awesome_owl/static/src/counter/counter.js create mode 100644 awesome_owl/static/src/counter/counter.xml diff --git a/awesome_owl/static/src/card/card.js b/awesome_owl/static/src/card/card.js new file mode 100644 index 00000000000..77123e15ac7 --- /dev/null +++ b/awesome_owl/static/src/card/card.js @@ -0,0 +1,10 @@ +import { Component } from "@odoo/owl"; + +export class Card extends Component { + static template = "awesome_owl.card"; + + static props = { + title: String, + content: String, + } +} diff --git a/awesome_owl/static/src/card/card.xml b/awesome_owl/static/src/card/card.xml new file mode 100644 index 00000000000..5dcc0f6eef6 --- /dev/null +++ b/awesome_owl/static/src/card/card.xml @@ -0,0 +1,17 @@ + + + + +
+
+
+ +
+

+ +

+
+
+
+ +
diff --git a/awesome_owl/static/src/counter/counter.js b/awesome_owl/static/src/counter/counter.js new file mode 100644 index 00000000000..4eff2c220d1 --- /dev/null +++ b/awesome_owl/static/src/counter/counter.js @@ -0,0 +1,13 @@ +import { useState, Component } from "@odoo/owl"; + +export class Counter extends Component { + static template = "awesome_owl.counter"; + + setup() { + this.state = useState({ value: 0 }); + } + + increment() { + this.state.value++; + } +} diff --git a/awesome_owl/static/src/counter/counter.xml b/awesome_owl/static/src/counter/counter.xml new file mode 100644 index 00000000000..bacf49c6f3b --- /dev/null +++ b/awesome_owl/static/src/counter/counter.xml @@ -0,0 +1,13 @@ + + + + +
+ hello world : + + + +
+
+ +
diff --git a/awesome_owl/static/src/playground.js b/awesome_owl/static/src/playground.js index 657fb8b07bb..ff4914604ac 100644 --- a/awesome_owl/static/src/playground.js +++ b/awesome_owl/static/src/playground.js @@ -1,7 +1,16 @@ /** @odoo-module **/ -import { Component } from "@odoo/owl"; +import { Component, markup } from "@odoo/owl"; +import { Counter } from "./counter/counter" +import { Card } from "./card/card" export class Playground extends Component { static template = "awesome_owl.playground"; + static components = { + Counter, + Card, + } + + value1 = "
some content
"; + value2 = markup("
some content
"); } diff --git a/awesome_owl/static/src/playground.xml b/awesome_owl/static/src/playground.xml index 4fb905d59f9..a657eddb96c 100644 --- a/awesome_owl/static/src/playground.xml +++ b/awesome_owl/static/src/playground.xml @@ -2,9 +2,10 @@ -
- hello world -
+ + + +
- +
From 57527a7b884fac15f5403b01c53e404eec8dc81c Mon Sep 17 00:00:00 2001 From: yagho-odoo Date: Tue, 28 Oct 2025 13:51:30 +0100 Subject: [PATCH 02/13] [ADD] awesome_owl: added a sum for the counters and a todo list --- awesome_owl/static/src/counter/counter.js | 8 +++++--- awesome_owl/static/src/playground.js | 10 +++++++++- awesome_owl/static/src/playground.xml | 10 +++++++--- awesome_owl/static/src/todo_list/todo_item.js | 16 ++++++++++++++++ awesome_owl/static/src/todo_list/todo_item.xml | 13 +++++++++++++ awesome_owl/static/src/todo_list/todo_list.js | 15 +++++++++++++++ awesome_owl/static/src/todo_list/todo_list.xml | 12 ++++++++++++ 7 files changed, 77 insertions(+), 7 deletions(-) create mode 100644 awesome_owl/static/src/todo_list/todo_item.js create mode 100644 awesome_owl/static/src/todo_list/todo_item.xml create mode 100644 awesome_owl/static/src/todo_list/todo_list.js create mode 100644 awesome_owl/static/src/todo_list/todo_list.xml diff --git a/awesome_owl/static/src/counter/counter.js b/awesome_owl/static/src/counter/counter.js index 4eff2c220d1..f236f3f3131 100644 --- a/awesome_owl/static/src/counter/counter.js +++ b/awesome_owl/static/src/counter/counter.js @@ -2,12 +2,14 @@ import { useState, Component } from "@odoo/owl"; export class Counter extends Component { static template = "awesome_owl.counter"; - - setup() { - this.state = useState({ value: 0 }); + static props = { + incrementSum: {type: Function, optional: true}, } + state = useState({ value: 1 }); + increment() { this.state.value++; + this.props.incrementSum() } } diff --git a/awesome_owl/static/src/playground.js b/awesome_owl/static/src/playground.js index ff4914604ac..730020c448a 100644 --- a/awesome_owl/static/src/playground.js +++ b/awesome_owl/static/src/playground.js @@ -1,16 +1,24 @@ /** @odoo-module **/ -import { Component, markup } from "@odoo/owl"; +import { Component, markup, useState } from "@odoo/owl"; import { Counter } from "./counter/counter" import { Card } from "./card/card" +import { TodoList } from "./todo_list/todo_list"; export class Playground extends Component { static template = "awesome_owl.playground"; static components = { Counter, Card, + TodoList, } value1 = "
some content
"; value2 = markup("
some content
"); + + state = useState({ sum: 2 }); + + incrementSum() { + this.state.sum++; + } } diff --git a/awesome_owl/static/src/playground.xml b/awesome_owl/static/src/playground.xml index a657eddb96c..cba383ca44e 100644 --- a/awesome_owl/static/src/playground.xml +++ b/awesome_owl/static/src/playground.xml @@ -2,10 +2,14 @@ - - + + +
+ Total is : +
+
- +
diff --git a/awesome_owl/static/src/todo_list/todo_item.js b/awesome_owl/static/src/todo_list/todo_item.js new file mode 100644 index 00000000000..a0e74907a39 --- /dev/null +++ b/awesome_owl/static/src/todo_list/todo_item.js @@ -0,0 +1,16 @@ +import { Component } from "@odoo/owl"; + +export class TodoItem extends Component { + static template = "awesome_owl.TodoItem"; + + static props = { + item : { + type: Object, + shape: { + id: Number, + description: String, + isCompleted: Boolean, + } + } + } +} diff --git a/awesome_owl/static/src/todo_list/todo_item.xml b/awesome_owl/static/src/todo_list/todo_item.xml new file mode 100644 index 00000000000..5e901ca31b0 --- /dev/null +++ b/awesome_owl/static/src/todo_list/todo_item.xml @@ -0,0 +1,13 @@ + + + + + + . + + + + + + + diff --git a/awesome_owl/static/src/todo_list/todo_list.js b/awesome_owl/static/src/todo_list/todo_list.js new file mode 100644 index 00000000000..0120f43c954 --- /dev/null +++ b/awesome_owl/static/src/todo_list/todo_list.js @@ -0,0 +1,15 @@ +import { Component, useState } from "@odoo/owl"; +import { TodoItem } from "./todo_item"; + +export class TodoList extends Component { + static template = "awesome_owl.TodoList"; + static components = { + TodoItem, + } + + todos = [ + { id: 1, description: "buy sugar", isCompleted: false }, + { id: 2, description: "buy cereal", isCompleted: false }, + { id: 3, description: "buy milk", isCompleted: false } + ]; +} diff --git a/awesome_owl/static/src/todo_list/todo_list.xml b/awesome_owl/static/src/todo_list/todo_list.xml new file mode 100644 index 00000000000..b7d45d259ff --- /dev/null +++ b/awesome_owl/static/src/todo_list/todo_list.xml @@ -0,0 +1,12 @@ + + + + + +
+ +
+
+
+ +
From a9cef993261a111d6713da8f5e19441865380f85 Mon Sep 17 00:00:00 2001 From: yagho-odoo Date: Tue, 28 Oct 2025 14:57:26 +0100 Subject: [PATCH 03/13] [ADD] awesome_owl: added dynamic class attributes, the ability to add todos and focus on the input field --- .../static/src/todo_list/todo_item.xml | 14 +++++---- awesome_owl/static/src/todo_list/todo_list.js | 30 +++++++++++++++---- .../static/src/todo_list/todo_list.xml | 3 ++ 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/awesome_owl/static/src/todo_list/todo_item.xml b/awesome_owl/static/src/todo_list/todo_item.xml index 5e901ca31b0..9d14fa36ade 100644 --- a/awesome_owl/static/src/todo_list/todo_item.xml +++ b/awesome_owl/static/src/todo_list/todo_item.xml @@ -2,12 +2,14 @@ - - . - - - - +
+ + . + + + + +
diff --git a/awesome_owl/static/src/todo_list/todo_list.js b/awesome_owl/static/src/todo_list/todo_list.js index 0120f43c954..709550591fb 100644 --- a/awesome_owl/static/src/todo_list/todo_list.js +++ b/awesome_owl/static/src/todo_list/todo_list.js @@ -1,4 +1,4 @@ -import { Component, useState } from "@odoo/owl"; +import { Component, useState, useRef, onMounted } from "@odoo/owl"; import { TodoItem } from "./todo_item"; export class TodoList extends Component { @@ -7,9 +7,27 @@ export class TodoList extends Component { TodoItem, } - todos = [ - { id: 1, description: "buy sugar", isCompleted: false }, - { id: 2, description: "buy cereal", isCompleted: false }, - { id: 3, description: "buy milk", isCompleted: false } - ]; + todos = useState([]); + ids = 1 + + setup() { + this.myRef = useRef('myInput'); + onMounted(() => { + console.log(this.myRef.el); + this.myRef.el.focus() + }); + } + + addTodos(ev) { + if(ev.keyCode === 13) { + if(ev.target.value == "") return; + this.todos.push({ + id: this.ids, + description: ev.target.value, + isCompleted: false, + }) + this.ids++ + ev.target.value = "" + } + } } diff --git a/awesome_owl/static/src/todo_list/todo_list.xml b/awesome_owl/static/src/todo_list/todo_list.xml index b7d45d259ff..135e54c64c9 100644 --- a/awesome_owl/static/src/todo_list/todo_list.xml +++ b/awesome_owl/static/src/todo_list/todo_list.xml @@ -2,6 +2,9 @@ +
+ +
From 8a7f1e39fef60a8d753e424d8b90e5735239c51a Mon Sep 17 00:00:00 2001 From: yagho-odoo Date: Tue, 28 Oct 2025 16:40:25 +0100 Subject: [PATCH 04/13] [IMP] awesome_owl: toggling and deleting todos --- awesome_owl/static/src/todo_list/todo_item.js | 17 +++++++++++++++++ awesome_owl/static/src/todo_list/todo_item.xml | 4 +++- awesome_owl/static/src/todo_list/todo_list.js | 11 ++++++++++- awesome_owl/static/src/todo_list/todo_list.xml | 2 +- 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/awesome_owl/static/src/todo_list/todo_item.js b/awesome_owl/static/src/todo_list/todo_item.js index a0e74907a39..2a0184d8a9b 100644 --- a/awesome_owl/static/src/todo_list/todo_item.js +++ b/awesome_owl/static/src/todo_list/todo_item.js @@ -11,6 +11,23 @@ export class TodoItem extends Component { description: String, isCompleted: Boolean, } + }, + toggleState : { + type: Function, + optional: true, + }, + deleteTodo : { + type: Function, + optional: true, } } + + onChangeCheck (id){ + // this.props.toggleState(id) + this.props.item.isCompleted = !this.props.item.isCompleted + } + + onClickDelete (id){ + this.props.deleteTodo(id) + } } diff --git a/awesome_owl/static/src/todo_list/todo_item.xml b/awesome_owl/static/src/todo_list/todo_item.xml index 9d14fa36ade..5fe31891404 100644 --- a/awesome_owl/static/src/todo_list/todo_item.xml +++ b/awesome_owl/static/src/todo_list/todo_item.xml @@ -2,13 +2,15 @@ -
+
+ . +
diff --git a/awesome_owl/static/src/todo_list/todo_list.js b/awesome_owl/static/src/todo_list/todo_list.js index 709550591fb..389a334ef4b 100644 --- a/awesome_owl/static/src/todo_list/todo_list.js +++ b/awesome_owl/static/src/todo_list/todo_list.js @@ -13,7 +13,6 @@ export class TodoList extends Component { setup() { this.myRef = useRef('myInput'); onMounted(() => { - console.log(this.myRef.el); this.myRef.el.focus() }); } @@ -30,4 +29,14 @@ export class TodoList extends Component { ev.target.value = "" } } + + toggleState(id){ + let todo = this.todos.filter((todo) => todo.id == id) + todo[0].isCompleted = !todo[0].isCompleted + } + + deleteTodo(id){ + const index = this.todos.findIndex((elem) => elem.id === id); + if (index >= 0) this.todos.splice(index, 1); + } } diff --git a/awesome_owl/static/src/todo_list/todo_list.xml b/awesome_owl/static/src/todo_list/todo_list.xml index 135e54c64c9..7d587141503 100644 --- a/awesome_owl/static/src/todo_list/todo_list.xml +++ b/awesome_owl/static/src/todo_list/todo_list.xml @@ -7,7 +7,7 @@
- +
From 83628ac0f8bc564ff14cecdd94f31cd0a64b0ceb Mon Sep 17 00:00:00 2001 From: yagho-odoo Date: Tue, 28 Oct 2025 17:20:50 +0100 Subject: [PATCH 05/13] [IMP] awesome_owl: added slots to props and a card toggle button --- awesome_owl/static/src/card/card.js | 15 +++++++++++++-- awesome_owl/static/src/card/card.xml | 3 ++- awesome_owl/static/src/playground.xml | 4 ++-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/awesome_owl/static/src/card/card.js b/awesome_owl/static/src/card/card.js index 77123e15ac7..873cea2c369 100644 --- a/awesome_owl/static/src/card/card.js +++ b/awesome_owl/static/src/card/card.js @@ -1,10 +1,21 @@ -import { Component } from "@odoo/owl"; +import { Component, useState } from "@odoo/owl"; export class Card extends Component { static template = "awesome_owl.card"; static props = { title: String, - content: String, + slots: { + type: Object, + optional: true, + }, + isOpen: Boolean, + } + + state = useState({ isOpen: this.props.isOpen }); + + onToggleOpen(){ + this.state.isOpen = !this.state.isOpen + console.log(this.state.isOpen) } } diff --git a/awesome_owl/static/src/card/card.xml b/awesome_owl/static/src/card/card.xml index 5dcc0f6eef6..af30d0312e0 100644 --- a/awesome_owl/static/src/card/card.xml +++ b/awesome_owl/static/src/card/card.xml @@ -6,9 +6,10 @@
+ toggle

- +

diff --git a/awesome_owl/static/src/playground.xml b/awesome_owl/static/src/playground.xml index cba383ca44e..6fc309350a1 100644 --- a/awesome_owl/static/src/playground.xml +++ b/awesome_owl/static/src/playground.xml @@ -7,8 +7,8 @@
Total is :
- - + +
From 0aa3756bfef26bf80fb7dd89fa5dfeac0330cd39 Mon Sep 17 00:00:00 2001 From: yagho-odoo Date: Wed, 29 Oct 2025 11:01:40 +0100 Subject: [PATCH 06/13] [ADD] awesome_dashboard: added quick nav buttons and a dashboard item component --- awesome_dashboard/static/src/dashboard.js | 31 +++++++++++++++++++ awesome_dashboard/static/src/dashboard.scss | 7 +++++ awesome_dashboard/static/src/dashboard.xml | 10 +++++- .../src/dashboard_item/dashboard_item.js | 20 ++++++++++++ .../src/dashboard_item/dashboard_item.scss | 4 +++ .../src/dashboard_item/dashboard_item.xml | 10 ++++++ 6 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 awesome_dashboard/static/src/dashboard.scss create mode 100644 awesome_dashboard/static/src/dashboard_item/dashboard_item.js create mode 100644 awesome_dashboard/static/src/dashboard_item/dashboard_item.scss create mode 100644 awesome_dashboard/static/src/dashboard_item/dashboard_item.xml diff --git a/awesome_dashboard/static/src/dashboard.js b/awesome_dashboard/static/src/dashboard.js index 637fa4bb972..8e57f33fb1c 100644 --- a/awesome_dashboard/static/src/dashboard.js +++ b/awesome_dashboard/static/src/dashboard.js @@ -2,9 +2,40 @@ import { Component } from "@odoo/owl"; import { registry } from "@web/core/registry"; +import { Layout } from "@web/search/layout"; +import { useService } from "@web/core/utils/hooks"; +import { DashboardItem } from "./dashboard_item/dashboard_item"; class AwesomeDashboard extends Component { static template = "awesome_dashboard.AwesomeDashboard"; + static components = { + Layout, + DashboardItem + }; + + static props = { + display : { + controlPanel: {} + }, + } + + setup() { + this.action = useService("action"); + } + + openCustomerKanban() { + this.action.doAction("base.action_partner_form"); + } + + async openActivity() { + this.action.doAction({ + type: 'ir.actions.act_window', + name: 'Leads', + target: 'current', + res_model: 'crm.lead', + views: [[false, 'list'], [false, 'form']], + }); + } } registry.category("actions").add("awesome_dashboard.dashboard", AwesomeDashboard); diff --git a/awesome_dashboard/static/src/dashboard.scss b/awesome_dashboard/static/src/dashboard.scss new file mode 100644 index 00000000000..845518d2a75 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard.scss @@ -0,0 +1,7 @@ +.o_dashboard { + background-color: grey; +} + +.myBtnChange { + margin: 2rem; +} diff --git a/awesome_dashboard/static/src/dashboard.xml b/awesome_dashboard/static/src/dashboard.xml index 1a2ac9a2fed..6ee4cbc9e94 100644 --- a/awesome_dashboard/static/src/dashboard.xml +++ b/awesome_dashboard/static/src/dashboard.xml @@ -2,7 +2,15 @@ - hello dashboard +
+ + + + long content + very very very very long content + + +
diff --git a/awesome_dashboard/static/src/dashboard_item/dashboard_item.js b/awesome_dashboard/static/src/dashboard_item/dashboard_item.js new file mode 100644 index 00000000000..235cc6fe68d --- /dev/null +++ b/awesome_dashboard/static/src/dashboard_item/dashboard_item.js @@ -0,0 +1,20 @@ +import { Component } from "@odoo/owl"; + +export class DashboardItem extends Component { + static template = "awesome_dashboard.DashboardItem"; + + static props = { + size: { + type: Number, + optional: true, + }, + slots: { + type: Object, + optional: true, + }, + } + + static defaultProps = { + size: 1 + } +} diff --git a/awesome_dashboard/static/src/dashboard_item/dashboard_item.scss b/awesome_dashboard/static/src/dashboard_item/dashboard_item.scss new file mode 100644 index 00000000000..c32423615ef --- /dev/null +++ b/awesome_dashboard/static/src/dashboard_item/dashboard_item.scss @@ -0,0 +1,4 @@ +.box { + border: 3px; + background-color: white; +} diff --git a/awesome_dashboard/static/src/dashboard_item/dashboard_item.xml b/awesome_dashboard/static/src/dashboard_item/dashboard_item.xml new file mode 100644 index 00000000000..0a5573ba3eb --- /dev/null +++ b/awesome_dashboard/static/src/dashboard_item/dashboard_item.xml @@ -0,0 +1,10 @@ + + + + +
+ +
+
+ +
From 6056586c862a8ee1c7afb29e9c18000916a80019 Mon Sep 17 00:00:00 2001 From: yagho-odoo Date: Wed, 29 Oct 2025 14:47:08 +0100 Subject: [PATCH 07/13] [IMP] awesome_dashboard: added some statistics and caching --- awesome_dashboard/static/src/dashboard.js | 9 ++++-- awesome_dashboard/static/src/dashboard.xml | 29 +++++++++++++++++-- .../src/dashboard_item/dashboard_item.scss | 5 +++- .../src/dashboard_item/dashboard_item.xml | 4 +-- .../static/src/get_statistics.js | 13 +++++++++ 5 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 awesome_dashboard/static/src/get_statistics.js diff --git a/awesome_dashboard/static/src/dashboard.js b/awesome_dashboard/static/src/dashboard.js index 8e57f33fb1c..8e345c3e8ac 100644 --- a/awesome_dashboard/static/src/dashboard.js +++ b/awesome_dashboard/static/src/dashboard.js @@ -1,6 +1,6 @@ /** @odoo-module **/ -import { Component } from "@odoo/owl"; +import { Component, onWillStart } from "@odoo/owl"; import { registry } from "@web/core/registry"; import { Layout } from "@web/search/layout"; import { useService } from "@web/core/utils/hooks"; @@ -20,7 +20,12 @@ class AwesomeDashboard extends Component { } setup() { - this.action = useService("action"); + this.action = useService("action"); + const statsService = useService("awesome_dashboard.getStats"); + + onWillStart(async () => { + this.result = await statsService.loadStatistics(); + }); } openCustomerKanban() { diff --git a/awesome_dashboard/static/src/dashboard.xml b/awesome_dashboard/static/src/dashboard.xml index 6ee4cbc9e94..a379c2dc58e 100644 --- a/awesome_dashboard/static/src/dashboard.xml +++ b/awesome_dashboard/static/src/dashboard.xml @@ -6,8 +6,33 @@ - long content - very very very very long content +
+ Average quantity sold is : + + + + + Number of new orders this month : + + + + + Total amount of new orders this month : + + + + + Number of cancelled orders this month : + + + + + Average time for an order : + + + + +
diff --git a/awesome_dashboard/static/src/dashboard_item/dashboard_item.scss b/awesome_dashboard/static/src/dashboard_item/dashboard_item.scss index c32423615ef..e7e1b959618 100644 --- a/awesome_dashboard/static/src/dashboard_item/dashboard_item.scss +++ b/awesome_dashboard/static/src/dashboard_item/dashboard_item.scss @@ -1,4 +1,7 @@ .box { - border: 3px; + border: 30px black; + // border-color: black; + border-radius: 10px; background-color: white; + margin: 1rem; } diff --git a/awesome_dashboard/static/src/dashboard_item/dashboard_item.xml b/awesome_dashboard/static/src/dashboard_item/dashboard_item.xml index 0a5573ba3eb..21b0a5e45e7 100644 --- a/awesome_dashboard/static/src/dashboard_item/dashboard_item.xml +++ b/awesome_dashboard/static/src/dashboard_item/dashboard_item.xml @@ -2,9 +2,9 @@ -
+ -
+
diff --git a/awesome_dashboard/static/src/get_statistics.js b/awesome_dashboard/static/src/get_statistics.js new file mode 100644 index 00000000000..557768d4e96 --- /dev/null +++ b/awesome_dashboard/static/src/get_statistics.js @@ -0,0 +1,13 @@ +import { registry } from "@web/core/registry"; +import { rpc } from "@web/core/network/rpc"; +import { memoize } from "@web/core/utils/functions"; + +export const getStatistics = { + async start() { + return { + loadStatistics: memoize(() => rpc("/awesome_dashboard/statistics")), + }; + }, +}; + +registry.category("services").add("awesome_dashboard.getStats", getStatistics); From 33a674ec2be20a2d14e9272d72833487e8809d91 Mon Sep 17 00:00:00 2001 From: yagho-odoo Date: Thu, 30 Oct 2025 10:46:12 +0100 Subject: [PATCH 08/13] [IMP] awesome_dashboard: added a pie chart and refresh data every 30 seconds --- awesome_dashboard/static/src/dashboard.js | 12 ++-- awesome_dashboard/static/src/dashboard.xml | 72 +++++++++++++------ .../src/dashboard_item/dashboard_item.xml | 4 +- .../static/src/get_statistics.js | 16 +++-- .../static/src/pie_chart/pie_chart.js | 36 ++++++++++ .../static/src/pie_chart/pie_chart.xml | 12 ++++ 6 files changed, 118 insertions(+), 34 deletions(-) create mode 100644 awesome_dashboard/static/src/pie_chart/pie_chart.js create mode 100644 awesome_dashboard/static/src/pie_chart/pie_chart.xml diff --git a/awesome_dashboard/static/src/dashboard.js b/awesome_dashboard/static/src/dashboard.js index 8e345c3e8ac..6bfb358768b 100644 --- a/awesome_dashboard/static/src/dashboard.js +++ b/awesome_dashboard/static/src/dashboard.js @@ -1,16 +1,18 @@ /** @odoo-module **/ -import { Component, onWillStart } from "@odoo/owl"; +import { Component, useState } from "@odoo/owl"; import { registry } from "@web/core/registry"; import { Layout } from "@web/search/layout"; import { useService } from "@web/core/utils/hooks"; import { DashboardItem } from "./dashboard_item/dashboard_item"; +import { PieChart } from "./pie_chart/pie_chart"; class AwesomeDashboard extends Component { static template = "awesome_dashboard.AwesomeDashboard"; static components = { Layout, - DashboardItem + DashboardItem, + PieChart }; static props = { @@ -21,11 +23,7 @@ class AwesomeDashboard extends Component { setup() { this.action = useService("action"); - const statsService = useService("awesome_dashboard.getStats"); - - onWillStart(async () => { - this.result = await statsService.loadStatistics(); - }); + this.result = useState(useService("awesome_dashboard.getStats")); } openCustomerKanban() { diff --git a/awesome_dashboard/static/src/dashboard.xml b/awesome_dashboard/static/src/dashboard.xml index a379c2dc58e..6ebb2cf0da2 100644 --- a/awesome_dashboard/static/src/dashboard.xml +++ b/awesome_dashboard/static/src/dashboard.xml @@ -6,31 +6,61 @@ -
- Average quantity sold is : - - - +
+ +
+
+ Average quantity sold is : +
+
+ +
+
- Number of new orders this month : - - - + +
+
+ Number of new orders this month : +
+
+ +
+
- Total amount of new orders this month : - - - + +
+
+ Total amount of new orders this month : +
+
+ +
+
- Number of cancelled orders this month : - - - + +
+
+ Number of cancelled orders this month : +
+
+ +
+
- Average time for an order : - - - + +
+
+ Average time for an order : +
+
+ +
+
+
+ + + Shirt orders by size +
diff --git a/awesome_dashboard/static/src/dashboard_item/dashboard_item.xml b/awesome_dashboard/static/src/dashboard_item/dashboard_item.xml index 21b0a5e45e7..0a5573ba3eb 100644 --- a/awesome_dashboard/static/src/dashboard_item/dashboard_item.xml +++ b/awesome_dashboard/static/src/dashboard_item/dashboard_item.xml @@ -2,9 +2,9 @@ - +
- +
diff --git a/awesome_dashboard/static/src/get_statistics.js b/awesome_dashboard/static/src/get_statistics.js index 557768d4e96..238a1a58d3b 100644 --- a/awesome_dashboard/static/src/get_statistics.js +++ b/awesome_dashboard/static/src/get_statistics.js @@ -1,12 +1,20 @@ import { registry } from "@web/core/registry"; import { rpc } from "@web/core/network/rpc"; -import { memoize } from "@web/core/utils/functions"; +import { reactive } from "@odoo/owl"; export const getStatistics = { async start() { - return { - loadStatistics: memoize(() => rpc("/awesome_dashboard/statistics")), - }; + const statistics = reactive({ isReady: false }); + + async function loadData() { + const updates = await rpc("/awesome_dashboard/statistics"); + Object.assign(statistics, updates, { isReady: true }); + } + + setInterval(loadData, 30*1000); + loadData(); + + return statistics; }, }; diff --git a/awesome_dashboard/static/src/pie_chart/pie_chart.js b/awesome_dashboard/static/src/pie_chart/pie_chart.js new file mode 100644 index 00000000000..a273255e63d --- /dev/null +++ b/awesome_dashboard/static/src/pie_chart/pie_chart.js @@ -0,0 +1,36 @@ +import { Component, onWillStart, useRef, onMounted, useState } from "@odoo/owl"; +import { loadJS } from "@web/core/assets"; + +export class PieChart extends Component { + static template = "awesome_dashboard.PieChart"; + + static props = { + label: String, + data: Object, + }; + + setup() { + this.canvasRef = useRef("canvas"); + onWillStart(() => loadJS("/web/static/lib/Chart/Chart.js")); + onMounted(() => { + this.renderChart(); + }); + } + + renderChart() { + const labels = Object.keys(this.props.data); + const data = Object.values(this.props.data); + this.chart = new Chart(this.canvasRef.el, { + type: "pie", + data: { + labels: labels, + datasets: [ + { + label: this.props.label, + data: data, + }, + ], + }, + }); + } +} diff --git a/awesome_dashboard/static/src/pie_chart/pie_chart.xml b/awesome_dashboard/static/src/pie_chart/pie_chart.xml new file mode 100644 index 00000000000..99711839c96 --- /dev/null +++ b/awesome_dashboard/static/src/pie_chart/pie_chart.xml @@ -0,0 +1,12 @@ + + + + +
+
+ +
+
+
+ +
From fbb15af296f3d61e72af366c6cf4eb8b58f2094c Mon Sep 17 00:00:00 2001 From: yagho-odoo Date: Thu, 30 Oct 2025 15:59:39 +0100 Subject: [PATCH 09/13] [IMP] awesome_dashboard: changed project structure and made dashboard item more modular --- awesome_dashboard/__manifest__.py | 4 ++ awesome_dashboard/static/src/dashboard.xml | 71 ------------------- .../static/src/{ => dashboard}/dashboard.js | 6 +- .../static/src/{ => dashboard}/dashboard.scss | 0 .../static/src/dashboard/dashboard.xml | 22 ++++++ .../dashboard_item/dashboard_item.js | 0 .../dashboard_item/dashboard_item.scss | 0 .../dashboard_item/dashboard_item.xml | 0 .../static/src/dashboard/dashboard_items.js | 60 ++++++++++++++++ .../src/{ => dashboard}/get_statistics.js | 0 .../src/dashboard/number_card/number_card.js | 13 ++++ .../src/dashboard/number_card/number_card.xml | 9 +++ .../{ => dashboard}/pie_chart/pie_chart.js | 0 .../{ => dashboard}/pie_chart/pie_chart.xml | 0 .../pie_chart_card/pie_chart_card.js | 15 ++++ .../pie_chart_card/pie_chart_card.xml | 7 ++ .../static/src/dashboard_loader.js | 15 ++++ .../static/src/dashboard_loader.xml | 8 +++ 18 files changed, 156 insertions(+), 74 deletions(-) delete mode 100644 awesome_dashboard/static/src/dashboard.xml rename awesome_dashboard/static/src/{ => dashboard}/dashboard.js (87%) rename awesome_dashboard/static/src/{ => dashboard}/dashboard.scss (100%) create mode 100644 awesome_dashboard/static/src/dashboard/dashboard.xml rename awesome_dashboard/static/src/{ => dashboard}/dashboard_item/dashboard_item.js (100%) rename awesome_dashboard/static/src/{ => dashboard}/dashboard_item/dashboard_item.scss (100%) rename awesome_dashboard/static/src/{ => dashboard}/dashboard_item/dashboard_item.xml (100%) create mode 100644 awesome_dashboard/static/src/dashboard/dashboard_items.js rename awesome_dashboard/static/src/{ => dashboard}/get_statistics.js (100%) create mode 100644 awesome_dashboard/static/src/dashboard/number_card/number_card.js create mode 100644 awesome_dashboard/static/src/dashboard/number_card/number_card.xml rename awesome_dashboard/static/src/{ => dashboard}/pie_chart/pie_chart.js (100%) rename awesome_dashboard/static/src/{ => dashboard}/pie_chart/pie_chart.xml (100%) create mode 100644 awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_card.js create mode 100644 awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_card.xml create mode 100644 awesome_dashboard/static/src/dashboard_loader.js create mode 100644 awesome_dashboard/static/src/dashboard_loader.xml diff --git a/awesome_dashboard/__manifest__.py b/awesome_dashboard/__manifest__.py index 31406e8addb..e2363aef60b 100644 --- a/awesome_dashboard/__manifest__.py +++ b/awesome_dashboard/__manifest__.py @@ -24,6 +24,10 @@ 'assets': { 'web.assets_backend': [ 'awesome_dashboard/static/src/**/*', + ('remove', 'awesome_dashboard/static/src/dashboard**/*'), + ], + 'awesome_dashboard.dashboard': [ + 'awesome_dashboard/static/src/dashboard/**/*' ], }, 'license': 'AGPL-3' diff --git a/awesome_dashboard/static/src/dashboard.xml b/awesome_dashboard/static/src/dashboard.xml deleted file mode 100644 index 6ebb2cf0da2..00000000000 --- a/awesome_dashboard/static/src/dashboard.xml +++ /dev/null @@ -1,71 +0,0 @@ - - - - -
- - - -
- -
-
- Average quantity sold is : -
-
- -
-
-
- -
-
- Number of new orders this month : -
-
- -
-
-
- -
-
- Total amount of new orders this month : -
-
- -
-
-
- -
-
- Number of cancelled orders this month : -
-
- -
-
-
- -
-
- Average time for an order : -
-
- -
-
-
- - - Shirt orders by size - - -
-
- -
-
- -
diff --git a/awesome_dashboard/static/src/dashboard.js b/awesome_dashboard/static/src/dashboard/dashboard.js similarity index 87% rename from awesome_dashboard/static/src/dashboard.js rename to awesome_dashboard/static/src/dashboard/dashboard.js index 6bfb358768b..8c6046e7978 100644 --- a/awesome_dashboard/static/src/dashboard.js +++ b/awesome_dashboard/static/src/dashboard/dashboard.js @@ -5,14 +5,13 @@ import { registry } from "@web/core/registry"; import { Layout } from "@web/search/layout"; import { useService } from "@web/core/utils/hooks"; import { DashboardItem } from "./dashboard_item/dashboard_item"; -import { PieChart } from "./pie_chart/pie_chart"; +import { items } from "./dashboard_items"; class AwesomeDashboard extends Component { static template = "awesome_dashboard.AwesomeDashboard"; static components = { Layout, DashboardItem, - PieChart }; static props = { @@ -24,6 +23,7 @@ class AwesomeDashboard extends Component { setup() { this.action = useService("action"); this.result = useState(useService("awesome_dashboard.getStats")); + this.items = items } openCustomerKanban() { @@ -41,4 +41,4 @@ class AwesomeDashboard extends Component { } } -registry.category("actions").add("awesome_dashboard.dashboard", AwesomeDashboard); +registry.category("lazy_components").add("AwesomeDashboard", AwesomeDashboard); diff --git a/awesome_dashboard/static/src/dashboard.scss b/awesome_dashboard/static/src/dashboard/dashboard.scss similarity index 100% rename from awesome_dashboard/static/src/dashboard.scss rename to awesome_dashboard/static/src/dashboard/dashboard.scss diff --git a/awesome_dashboard/static/src/dashboard/dashboard.xml b/awesome_dashboard/static/src/dashboard/dashboard.xml new file mode 100644 index 00000000000..ab1fb6225b0 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard.xml @@ -0,0 +1,22 @@ + + + + +
+ + + +
+ + + + + + +
+
+ +
+
+ +
diff --git a/awesome_dashboard/static/src/dashboard_item/dashboard_item.js b/awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.js similarity index 100% rename from awesome_dashboard/static/src/dashboard_item/dashboard_item.js rename to awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.js diff --git a/awesome_dashboard/static/src/dashboard_item/dashboard_item.scss b/awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.scss similarity index 100% rename from awesome_dashboard/static/src/dashboard_item/dashboard_item.scss rename to awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.scss diff --git a/awesome_dashboard/static/src/dashboard_item/dashboard_item.xml b/awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.xml similarity index 100% rename from awesome_dashboard/static/src/dashboard_item/dashboard_item.xml rename to awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.xml diff --git a/awesome_dashboard/static/src/dashboard/dashboard_items.js b/awesome_dashboard/static/src/dashboard/dashboard_items.js new file mode 100644 index 00000000000..e8dfd94875d --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard_items.js @@ -0,0 +1,60 @@ +import { NumberCard } from "./number_card/number_card"; +import { PieChartCard } from "./pie_chart_card/pie_chart_card"; + +export const items = [ + { + id: "average_quantity", + description: "Average amount of t-shirt", + Component: NumberCard, + props: (data) => ({ + title: "Average amount of t-shirt by order this month", + value: data.average_quantity, + }) + }, + { + id: "average_time", + description: "Average time for an order", + Component: NumberCard, + props: (data) => ({ + title: "Average time for an order to go from 'new' to 'sent' or 'cancelled'", + value: data.average_time, + }) + }, + { + id: "number_new_orders", + description: "New orders this month", + Component: NumberCard, + props: (data) => ({ + title: "Number of new orders this month", + value: data.nb_new_orders, + }) + }, + { + id: "cancelled_orders", + description: "Cancelled orders this month", + Component: NumberCard, + props: (data) => ({ + title: "Number of cancelled orders this month", + value: data.nb_cancelled_orders, + }) + }, + { + id: "amount_new_orders", + description: "amount orders this month", + Component: NumberCard, + props: (data) => ({ + title: "Total amount of new orders this month", + value: data.total_amount, + }) + }, + { + id: "pie_chart", + description: "Shirt orders by size", + Component: PieChartCard, + size: 1, + props: (data) => ({ + title: "Shirt orders by size", + values: data.orders_by_size, + }) + } +] \ No newline at end of file diff --git a/awesome_dashboard/static/src/get_statistics.js b/awesome_dashboard/static/src/dashboard/get_statistics.js similarity index 100% rename from awesome_dashboard/static/src/get_statistics.js rename to awesome_dashboard/static/src/dashboard/get_statistics.js diff --git a/awesome_dashboard/static/src/dashboard/number_card/number_card.js b/awesome_dashboard/static/src/dashboard/number_card/number_card.js new file mode 100644 index 00000000000..d3bd9c0e4ef --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/number_card/number_card.js @@ -0,0 +1,13 @@ +import { Component } from "@odoo/owl"; + +export class NumberCard extends Component { + static template = "awesome_dashboard.NumberCard"; + static props = { + title: { + type: String, + }, + value: { + type: Number, + } + } +} \ No newline at end of file diff --git a/awesome_dashboard/static/src/dashboard/number_card/number_card.xml b/awesome_dashboard/static/src/dashboard/number_card/number_card.xml new file mode 100644 index 00000000000..73bc3cac926 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/number_card/number_card.xml @@ -0,0 +1,9 @@ + + + + +
+ +
+
+
\ No newline at end of file diff --git a/awesome_dashboard/static/src/pie_chart/pie_chart.js b/awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.js similarity index 100% rename from awesome_dashboard/static/src/pie_chart/pie_chart.js rename to awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.js diff --git a/awesome_dashboard/static/src/pie_chart/pie_chart.xml b/awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.xml similarity index 100% rename from awesome_dashboard/static/src/pie_chart/pie_chart.xml rename to awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.xml diff --git a/awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_card.js b/awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_card.js new file mode 100644 index 00000000000..04dc61aa73a --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_card.js @@ -0,0 +1,15 @@ +import { Component } from "@odoo/owl"; +import { PieChart } from "../pie_chart/pie_chart"; + +export class PieChartCard extends Component { + static template = "awesome_dashboard.PieChartCard"; + static components = { PieChart } + static props = { + title: { + type: String, + }, + values: { + type: Object, + }, + } +} \ No newline at end of file diff --git a/awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_card.xml b/awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_card.xml new file mode 100644 index 00000000000..b8c94bebb64 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_card.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/awesome_dashboard/static/src/dashboard_loader.js b/awesome_dashboard/static/src/dashboard_loader.js new file mode 100644 index 00000000000..861cf1900ea --- /dev/null +++ b/awesome_dashboard/static/src/dashboard_loader.js @@ -0,0 +1,15 @@ +import { registry } from "@web/core/registry"; +import { LazyComponent } from "@web/core/assets"; +import { Component, xml } from "@odoo/owl"; + +class AwesomeDashboardLoader extends Component { + + // static template = "awesome_dashboard.dashboardLoader"; + static template = xml` + ` + ; + static components = { LazyComponent }; + +} + +registry.category("actions").add("awesome_dashboard.dashboard", AwesomeDashboardLoader); diff --git a/awesome_dashboard/static/src/dashboard_loader.xml b/awesome_dashboard/static/src/dashboard_loader.xml new file mode 100644 index 00000000000..ce002eadb47 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard_loader.xml @@ -0,0 +1,8 @@ + + + + + + + + From c71277f1ac88e6a05b88197fd6727f811a14dafd Mon Sep 17 00:00:00 2001 From: yagho-odoo Date: Thu, 30 Oct 2025 17:11:37 +0100 Subject: [PATCH 10/13] [IMP] awesome_dashboard: added a cog to disbale cards --- .../static/src/dashboard/dashboard.js | 56 ++++++++++++++++++- .../static/src/dashboard/dashboard.xml | 25 ++++++++- .../static/src/dashboard/dashboard_items.js | 9 ++- 3 files changed, 83 insertions(+), 7 deletions(-) diff --git a/awesome_dashboard/static/src/dashboard/dashboard.js b/awesome_dashboard/static/src/dashboard/dashboard.js index 8c6046e7978..328c9db4d5b 100644 --- a/awesome_dashboard/static/src/dashboard/dashboard.js +++ b/awesome_dashboard/static/src/dashboard/dashboard.js @@ -5,7 +5,9 @@ import { registry } from "@web/core/registry"; import { Layout } from "@web/search/layout"; import { useService } from "@web/core/utils/hooks"; import { DashboardItem } from "./dashboard_item/dashboard_item"; -import { items } from "./dashboard_items"; +import { Dialog } from "@web/core/dialog/dialog"; +import { CheckBox } from "@web/core/checkbox/checkbox"; +import { browser } from "@web/core/browser/browser"; class AwesomeDashboard extends Component { static template = "awesome_dashboard.AwesomeDashboard"; @@ -23,7 +25,23 @@ class AwesomeDashboard extends Component { setup() { this.action = useService("action"); this.result = useState(useService("awesome_dashboard.getStats")); - this.items = items + this.dialog = useService("dialog"); + this.items = registry.category("awesome_dashboard").getAll(); + this.state = useState({ + disabledItems: browser.localStorage.getItem("disabledDashboardItems")?.split(",") || [] + }); + } + + openConfiguration() { + this.dialog.add(ConfigurationDialog, { + items: this.items, + disabledItems: this.state.disabledItems, + onUpdateConfiguration: this.updateConfiguration.bind(this), + }) + } + + updateConfiguration(newDisabledItems) { + this.state.disabledItems = newDisabledItems; } openCustomerKanban() { @@ -41,4 +59,38 @@ class AwesomeDashboard extends Component { } } +class ConfigurationDialog extends Component { + static template = "awesome_dashboard.ConfigurationDialog"; + static components = { Dialog, CheckBox }; + static props = ["close", "items", "disabledItems", "onUpdateConfiguration"]; + + setup() { + this.items = useState(this.props.items.map((item) => { + return { + ...item, + enabled: !this.props.disabledItems.includes(item.id), + } + })); + } + + done() { + this.props.close(); + } + + onChange(checked, changedItem) { + changedItem.enabled = checked; + const newDisabledItems = Object.values(this.items).filter( + (item) => !item.enabled + ).map((item) => item.id) + + browser.localStorage.setItem( + "disabledDashboardItems", + newDisabledItems, + ); + + this.props.onUpdateConfiguration(newDisabledItems); + } + +} + registry.category("lazy_components").add("AwesomeDashboard", AwesomeDashboard); diff --git a/awesome_dashboard/static/src/dashboard/dashboard.xml b/awesome_dashboard/static/src/dashboard/dashboard.xml index ab1fb6225b0..a158437e6d1 100644 --- a/awesome_dashboard/static/src/dashboard/dashboard.xml +++ b/awesome_dashboard/static/src/dashboard/dashboard.xml @@ -1,14 +1,19 @@ - + + + +
- + @@ -18,5 +23,19 @@
- + + + Which cards do you whish to see ? + + + + + + + + + + diff --git a/awesome_dashboard/static/src/dashboard/dashboard_items.js b/awesome_dashboard/static/src/dashboard/dashboard_items.js index e8dfd94875d..4532ee3a413 100644 --- a/awesome_dashboard/static/src/dashboard/dashboard_items.js +++ b/awesome_dashboard/static/src/dashboard/dashboard_items.js @@ -1,7 +1,8 @@ import { NumberCard } from "./number_card/number_card"; import { PieChartCard } from "./pie_chart_card/pie_chart_card"; +import { registry } from "@web/core/registry" -export const items = [ +const items = [ { id: "average_quantity", description: "Average amount of t-shirt", @@ -57,4 +58,8 @@ export const items = [ values: data.orders_by_size, }) } -] \ No newline at end of file +] + +items.forEach(item => { + registry.category("awesome_dashboard").add(item.id, item); +}); From 9fc2ddbeb8045392f8ce60b4356429777991ba0a Mon Sep 17 00:00:00 2001 From: yagho-odoo Date: Fri, 31 Oct 2025 09:56:24 +0100 Subject: [PATCH 11/13] [ADD] awesome_clicker: added the module to systray and body clicking increments counter --- .../clicker_systray_item.js | 27 +++++++++++++++++++ .../clicker_systray_item.xml | 11 ++++++++ 2 files changed, 38 insertions(+) create mode 100644 awesome_clicker/static/src/clicker_systray_item/clicker_systray_item.js create mode 100644 awesome_clicker/static/src/clicker_systray_item/clicker_systray_item.xml diff --git a/awesome_clicker/static/src/clicker_systray_item/clicker_systray_item.js b/awesome_clicker/static/src/clicker_systray_item/clicker_systray_item.js new file mode 100644 index 00000000000..fd45390ba35 --- /dev/null +++ b/awesome_clicker/static/src/clicker_systray_item/clicker_systray_item.js @@ -0,0 +1,27 @@ +import { registry } from "@web/core/registry"; +import { Component, useState, useExternalListener } from "@odoo/owl"; + +export class ClickerSystray extends Component { + static template = "awesome_clicker.ClickerSystray"; + static props = {}; + + setup() { + this.state = useState({ counter: 0 }); + useExternalListener(window, "click", this.incrementBody, { capture: true }); + } + + increment() { + this.state.counter+=9; + } + + incrementBody() { + this.state.counter++; + } + +} + +export const systrayItem = { + Component: ClickerSystray, +}; + +registry.category("systray").add("awesome_clicker.ClickerSystray", systrayItem, { sequence: 1000 }); \ No newline at end of file diff --git a/awesome_clicker/static/src/clicker_systray_item/clicker_systray_item.xml b/awesome_clicker/static/src/clicker_systray_item/clicker_systray_item.xml new file mode 100644 index 00000000000..cb3a383a5d8 --- /dev/null +++ b/awesome_clicker/static/src/clicker_systray_item/clicker_systray_item.xml @@ -0,0 +1,11 @@ + + + +
+ Clicks: + +
+
+
\ No newline at end of file From 949b26da3360d0e8dd872eeb14fcb7e9883d5dd6 Mon Sep 17 00:00:00 2001 From: yagho-odoo Date: Fri, 31 Oct 2025 10:42:29 +0100 Subject: [PATCH 12/13] [IMP] awesome_clicker: added a client action menu and moved the counter state to a service --- .../clicker_systray_item/clicker_service.js | 22 +++++++++++++++++++ .../clicker_systray_item.js | 20 +++++++++-------- .../clicker_systray_item.xml | 7 ++++-- .../src/clicker_systray_item/client_action.js | 15 +++++++++++++ .../clicker_systray_item/client_action.xml | 11 ++++++++++ 5 files changed, 64 insertions(+), 11 deletions(-) create mode 100644 awesome_clicker/static/src/clicker_systray_item/clicker_service.js create mode 100644 awesome_clicker/static/src/clicker_systray_item/client_action.js create mode 100644 awesome_clicker/static/src/clicker_systray_item/client_action.xml diff --git a/awesome_clicker/static/src/clicker_systray_item/clicker_service.js b/awesome_clicker/static/src/clicker_systray_item/clicker_service.js new file mode 100644 index 00000000000..aee2d803c42 --- /dev/null +++ b/awesome_clicker/static/src/clicker_systray_item/clicker_service.js @@ -0,0 +1,22 @@ +import { registry } from "@web/core/registry"; +import { reactive } from "@odoo/owl"; + +export const clickerService = { + start() { + + const count = reactive({ clicks: 0 }); + + function increment(c) { + count.clicks+= c; + } + + document.addEventListener("click", () => increment(1), true); + + return { + count, + increment, + }; + }, +}; + +registry.category("services").add("awesome_clicker.clicker", clickerService); diff --git a/awesome_clicker/static/src/clicker_systray_item/clicker_systray_item.js b/awesome_clicker/static/src/clicker_systray_item/clicker_systray_item.js index fd45390ba35..ea3a6383c30 100644 --- a/awesome_clicker/static/src/clicker_systray_item/clicker_systray_item.js +++ b/awesome_clicker/static/src/clicker_systray_item/clicker_systray_item.js @@ -1,21 +1,23 @@ import { registry } from "@web/core/registry"; -import { Component, useState, useExternalListener } from "@odoo/owl"; +import { Component, useState } from "@odoo/owl"; +import { useService } from "@web/core/utils/hooks"; export class ClickerSystray extends Component { static template = "awesome_clicker.ClickerSystray"; static props = {}; setup() { - this.state = useState({ counter: 0 }); - useExternalListener(window, "click", this.incrementBody, { capture: true }); + this.action = useService("action"); + this.clickService = useState(useService("awesome_clicker.clicker")) } - increment() { - this.state.counter+=9; - } - - incrementBody() { - this.state.counter++; + openClientAction() { + this.action.doAction({ + type: "ir.actions.client", + tag: "awesome_clicker.client_action", + target: "new", + name: "Clicker Game" + }); } } diff --git a/awesome_clicker/static/src/clicker_systray_item/clicker_systray_item.xml b/awesome_clicker/static/src/clicker_systray_item/clicker_systray_item.xml index cb3a383a5d8..7ae61548b80 100644 --- a/awesome_clicker/static/src/clicker_systray_item/clicker_systray_item.xml +++ b/awesome_clicker/static/src/clicker_systray_item/clicker_systray_item.xml @@ -2,10 +2,13 @@
- Clicks: - +
\ No newline at end of file diff --git a/awesome_clicker/static/src/clicker_systray_item/client_action.js b/awesome_clicker/static/src/clicker_systray_item/client_action.js new file mode 100644 index 00000000000..76eea79cced --- /dev/null +++ b/awesome_clicker/static/src/clicker_systray_item/client_action.js @@ -0,0 +1,15 @@ +import { registry } from "@web/core/registry"; +import { Component, useState } from "@odoo/owl"; +import { useService } from "@web/core/utils/hooks"; + +export class ClientAction extends Component { + static template = "awesome_clicker.ClientAction"; + static props = {}; + + setup() { + this.clickService = useState(useService("awesome_clicker.clicker")) + } + +} + +registry.category("actions").add("awesome_clicker.client_action", ClientAction); \ No newline at end of file diff --git a/awesome_clicker/static/src/clicker_systray_item/client_action.xml b/awesome_clicker/static/src/clicker_systray_item/client_action.xml new file mode 100644 index 00000000000..81778047bfc --- /dev/null +++ b/awesome_clicker/static/src/clicker_systray_item/client_action.xml @@ -0,0 +1,11 @@ + + + +
+ Clicks: + +
+
+
\ No newline at end of file From da11c4c938bc5e78ea0d9c9ec330fa29abdde290 Mon Sep 17 00:00:00 2001 From: yagho-odoo Date: Fri, 31 Oct 2025 11:46:17 +0100 Subject: [PATCH 13/13] [IMP] awesome_clicker: created a custom hook for the clicks and the number representation uses humanValue fn --- .../static/src/click_value/click_value.js | 18 ++++++++++++++++++ .../static/src/click_value/click_value.xml | 6 ++++++ awesome_clicker/static/src/clicker_hook.js | 6 ++++++ .../clicker_service.js | 0 .../clicker_systray_item.js | 10 ++++++++-- .../clicker_systray_item.xml | 4 ++-- .../src/clicker_systray_item/client_action.js | 10 +++++++--- .../src/clicker_systray_item/client_action.xml | 4 ++-- 8 files changed, 49 insertions(+), 9 deletions(-) create mode 100644 awesome_clicker/static/src/click_value/click_value.js create mode 100644 awesome_clicker/static/src/click_value/click_value.xml create mode 100644 awesome_clicker/static/src/clicker_hook.js rename awesome_clicker/static/src/{clicker_systray_item => }/clicker_service.js (100%) diff --git a/awesome_clicker/static/src/click_value/click_value.js b/awesome_clicker/static/src/click_value/click_value.js new file mode 100644 index 00000000000..ecfa780a6e0 --- /dev/null +++ b/awesome_clicker/static/src/click_value/click_value.js @@ -0,0 +1,18 @@ +import { Component } from "@odoo/owl"; +import { useClicker } from "../clicker_hook"; +import { humanNumber } from "@web/core/utils/numbers" + +export class ClickValue extends Component { + static template = "awesome_clicker.ClickValue"; + static props = {}; + + setup() { + this.clicker = useClicker() + } + + get humanVal() { + return humanNumber(this.clicker.count.clicks, { + decimals: 1, + }); + } +} diff --git a/awesome_clicker/static/src/click_value/click_value.xml b/awesome_clicker/static/src/click_value/click_value.xml new file mode 100644 index 00000000000..8a1f150a072 --- /dev/null +++ b/awesome_clicker/static/src/click_value/click_value.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/awesome_clicker/static/src/clicker_hook.js b/awesome_clicker/static/src/clicker_hook.js new file mode 100644 index 00000000000..4fdaeb40980 --- /dev/null +++ b/awesome_clicker/static/src/clicker_hook.js @@ -0,0 +1,6 @@ +import { useService } from "@web/core/utils/hooks"; +import { useState } from "@odoo/owl"; + +export function useClicker() { + return useState(useService("awesome_clicker.clicker")); +} \ No newline at end of file diff --git a/awesome_clicker/static/src/clicker_systray_item/clicker_service.js b/awesome_clicker/static/src/clicker_service.js similarity index 100% rename from awesome_clicker/static/src/clicker_systray_item/clicker_service.js rename to awesome_clicker/static/src/clicker_service.js diff --git a/awesome_clicker/static/src/clicker_systray_item/clicker_systray_item.js b/awesome_clicker/static/src/clicker_systray_item/clicker_systray_item.js index ea3a6383c30..bbcf9b8d2b5 100644 --- a/awesome_clicker/static/src/clicker_systray_item/clicker_systray_item.js +++ b/awesome_clicker/static/src/clicker_systray_item/clicker_systray_item.js @@ -1,14 +1,20 @@ import { registry } from "@web/core/registry"; -import { Component, useState } from "@odoo/owl"; +import { Component } from "@odoo/owl"; import { useService } from "@web/core/utils/hooks"; +import { useClicker } from "../clicker_hook"; +import { ClickValue } from "../click_value/click_value"; export class ClickerSystray extends Component { + static template = "awesome_clicker.ClickerSystray"; static props = {}; + static components = { + ClickValue, + } setup() { this.action = useService("action"); - this.clickService = useState(useService("awesome_clicker.clicker")) + this.clicker = useClicker() } openClientAction() { diff --git a/awesome_clicker/static/src/clicker_systray_item/clicker_systray_item.xml b/awesome_clicker/static/src/clicker_systray_item/clicker_systray_item.xml index 7ae61548b80..b1b4b6172bc 100644 --- a/awesome_clicker/static/src/clicker_systray_item/clicker_systray_item.xml +++ b/awesome_clicker/static/src/clicker_systray_item/clicker_systray_item.xml @@ -2,8 +2,8 @@
- Clicks: -