From 0782ee02b6ea3d2ef526520e2fcf1e13aaab8ab2 Mon Sep 17 00:00:00 2001 From: Wajih-Wanis Date: Tue, 28 Oct 2025 15:51:56 +0100 Subject: [PATCH 1/3] [IMP] awesome_owl: mid chapter 1 debugging --- awesome_owl/static/src/card/card.js | 9 +++++++ awesome_owl/static/src/card/card.xml | 13 +++++++++ awesome_owl/static/src/counter/counter.js | 20 ++++++++++++++ awesome_owl/static/src/counter/counter.xml | 9 +++++++ awesome_owl/static/src/playground.js | 19 +++++++++++-- awesome_owl/static/src/playground.xml | 9 +++---- awesome_owl/static/src/to_do/to_do_item.js | 22 +++++++++++++++ awesome_owl/static/src/to_do/to_do_item.xml | 14 ++++++++++ awesome_owl/static/src/to_do/to_do_list.js | 30 +++++++++++++++++++++ awesome_owl/static/src/to_do/to_do_list.xml | 14 ++++++++++ awesome_owl/static/src/utils.js | 10 +++++++ 11 files changed, 162 insertions(+), 7 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 create mode 100644 awesome_owl/static/src/to_do/to_do_item.js create mode 100644 awesome_owl/static/src/to_do/to_do_item.xml create mode 100644 awesome_owl/static/src/to_do/to_do_list.js create mode 100644 awesome_owl/static/src/to_do/to_do_list.xml create mode 100644 awesome_owl/static/src/utils.js diff --git a/awesome_owl/static/src/card/card.js b/awesome_owl/static/src/card/card.js new file mode 100644 index 00000000000..1ef5c1d1373 --- /dev/null +++ b/awesome_owl/static/src/card/card.js @@ -0,0 +1,9 @@ +/** @odoo-module **/ + +import { Component } from '@odoo/owl' + + +export class Card extends Component{ + static template = "awesome_owl.card" + static props = ['title', 'content'] +} diff --git a/awesome_owl/static/src/card/card.xml b/awesome_owl/static/src/card/card.xml new file mode 100644 index 00000000000..aaf3580b86f --- /dev/null +++ b/awesome_owl/static/src/card/card.xml @@ -0,0 +1,13 @@ + + + +
+
+
+

+ +

+
+
+
+
\ No newline at end of file diff --git a/awesome_owl/static/src/counter/counter.js b/awesome_owl/static/src/counter/counter.js new file mode 100644 index 00000000000..fa3f7c400b1 --- /dev/null +++ b/awesome_owl/static/src/counter/counter.js @@ -0,0 +1,20 @@ +/** @odoo-module **/ + +import { Component, useState } from "@odoo/owl" + + +export class Counter extends Component{ + static template = "awesome_owl.counter"; + static props = { + onChange: { type: Function, optional: true} + } + + setup() { + this.state = useState({ value: 0}); + } + + increment() { + this.state.value++; + this.props.onChange(); + } +} diff --git a/awesome_owl/static/src/counter/counter.xml b/awesome_owl/static/src/counter/counter.xml new file mode 100644 index 00000000000..5a685ed4d5d --- /dev/null +++ b/awesome_owl/static/src/counter/counter.xml @@ -0,0 +1,9 @@ + + + +
+

Counter:

+ +
+
+
\ No newline at end of file diff --git a/awesome_owl/static/src/playground.js b/awesome_owl/static/src/playground.js index 657fb8b07bb..22e7b4a904f 100644 --- a/awesome_owl/static/src/playground.js +++ b/awesome_owl/static/src/playground.js @@ -1,7 +1,22 @@ /** @odoo-module **/ -import { Component } from "@odoo/owl"; +import { Component, useState, markup } from "@odoo/owl"; +import { Counter } from "./counter/counter"; +import { Card } from "./card/card"; +import { ToDoList } from "./to_do/to_do_list"; export class Playground extends Component { - static template = "awesome_owl.playground"; + static template = "awesome_owl.playground" + + setup(){ + this.state = useState({ sum: 0}) + this.incrementSum = this.incrementSum.bind(this); + } + + incrementSum(){ + this.state.sum++ + } + + static components = { Counter, Card, ToDoList }; + state = useState({title: "title from js", content: markup("
title from js
")}) } diff --git a/awesome_owl/static/src/playground.xml b/awesome_owl/static/src/playground.xml index 4fb905d59f9..b55b1bbcf6d 100644 --- a/awesome_owl/static/src/playground.xml +++ b/awesome_owl/static/src/playground.xml @@ -1,10 +1,9 @@ - -
- hello world -
+ + +

Sum:

+
-
diff --git a/awesome_owl/static/src/to_do/to_do_item.js b/awesome_owl/static/src/to_do/to_do_item.js new file mode 100644 index 00000000000..38da4beb571 --- /dev/null +++ b/awesome_owl/static/src/to_do/to_do_item.js @@ -0,0 +1,22 @@ +/** @odoo-module **/ + +import { Component } from "@odoo/owl" + +export class ToDoItem extends Component{ + static template = "awesome_owl.to_do_item" + static props = { + todo : { + type: Object, + shape : {id: Number, description: String, isComplete: Boolean} + }, + toggleState: { + type: Function, + optional: true + } + } + + setState(todo) { + this.props.toggleState(todo); + } + +} diff --git a/awesome_owl/static/src/to_do/to_do_item.xml b/awesome_owl/static/src/to_do/to_do_item.xml new file mode 100644 index 00000000000..ecbca7c3f9c --- /dev/null +++ b/awesome_owl/static/src/to_do/to_do_item.xml @@ -0,0 +1,14 @@ + + + +
+
+

+ + + +

+
+
+
+
\ No newline at end of file diff --git a/awesome_owl/static/src/to_do/to_do_list.js b/awesome_owl/static/src/to_do/to_do_list.js new file mode 100644 index 00000000000..40b6a59d3bc --- /dev/null +++ b/awesome_owl/static/src/to_do/to_do_list.js @@ -0,0 +1,30 @@ +/** @odoo-module **/ + +import { Component, useState, onMounted } from '@odoo/owl' +import { ToDoItem } from './to_do_item' +import { useAutoFocus } from '../utils' + +export class ToDoList extends Component { + static template = "awesome_owl.to_do_list" + static props = {} + setup(){ + this.state = useState({value: 1}); + this.todos = useState([]); + useAutoFocus('task'); + this.toggleState = this.toggleState.bind(this); + } + + addToDo(event) { + if(event.keyCode===13 && event.target.value){ + this.todos.push({id: this.state.value, description: event.target.value, isComplete: false}); + this.state.value++; + event.target.value = "" + } + } + + toggleState(todo) { + console.log("state toggled", todo.isComplete) + } + + static components = { ToDoItem }; +} diff --git a/awesome_owl/static/src/to_do/to_do_list.xml b/awesome_owl/static/src/to_do/to_do_list.xml new file mode 100644 index 00000000000..cf9e38898d0 --- /dev/null +++ b/awesome_owl/static/src/to_do/to_do_list.xml @@ -0,0 +1,14 @@ + + + +
+
+ +
+

To Do List

+ + + +
+
+
\ No newline at end of file diff --git a/awesome_owl/static/src/utils.js b/awesome_owl/static/src/utils.js new file mode 100644 index 00000000000..55ff0fa7ffa --- /dev/null +++ b/awesome_owl/static/src/utils.js @@ -0,0 +1,10 @@ +/** @odoo-module **/ + +import { useRef, onMounted } from '@odoo/owl' + +export function useAutoFocus(name) { + const inputRef = useRef(name); + onMounted(() => { + inputRef.el.focus(); + }) +} From 574b260cc95f7734f8bcc184cfbf8420b412aa8f Mon Sep 17 00:00:00 2001 From: Wajih-Wanis Date: Wed, 29 Oct 2025 11:33:41 +0100 Subject: [PATCH 2/3] [ADD] awesome_owl: end of chapter 1 --- awesome_owl/static/src/card/card.js | 13 +++++++++++-- awesome_owl/static/src/card/card.xml | 14 ++++++++------ awesome_owl/static/src/playground.js | 1 - awesome_owl/static/src/playground.xml | 4 +++- awesome_owl/static/src/to_do/to_do_item.js | 18 ++++++++++++++---- awesome_owl/static/src/to_do/to_do_item.xml | 1 + awesome_owl/static/src/to_do/to_do_list.js | 16 ++++++++++++---- awesome_owl/static/src/to_do/to_do_list.xml | 2 +- 8 files changed, 50 insertions(+), 19 deletions(-) diff --git a/awesome_owl/static/src/card/card.js b/awesome_owl/static/src/card/card.js index 1ef5c1d1373..42a40f2256b 100644 --- a/awesome_owl/static/src/card/card.js +++ b/awesome_owl/static/src/card/card.js @@ -1,9 +1,18 @@ /** @odoo-module **/ -import { Component } from '@odoo/owl' +import { Component, useState } from '@odoo/owl' export class Card extends Component{ static template = "awesome_owl.card" - static props = ['title', 'content'] + static props = ['slots'] + + setup(){ + this.state = useState({isToggled: true}); + } + + toggle() { + console.log(this.state.isToggled) + this.state.isToggled = !this.state.isToggled; + } } diff --git a/awesome_owl/static/src/card/card.xml b/awesome_owl/static/src/card/card.xml index aaf3580b86f..4bc3a2ccda7 100644 --- a/awesome_owl/static/src/card/card.xml +++ b/awesome_owl/static/src/card/card.xml @@ -2,12 +2,14 @@
-
-
-

- -

-
+
Card 1 + +
+ +
+ +
+
\ No newline at end of file diff --git a/awesome_owl/static/src/playground.js b/awesome_owl/static/src/playground.js index 22e7b4a904f..ab5b5ea3d8e 100644 --- a/awesome_owl/static/src/playground.js +++ b/awesome_owl/static/src/playground.js @@ -18,5 +18,4 @@ export class Playground extends Component { } static components = { Counter, Card, ToDoList }; - state = useState({title: "title from js", content: markup("
title from js
")}) } diff --git a/awesome_owl/static/src/playground.xml b/awesome_owl/static/src/playground.xml index b55b1bbcf6d..ed8ba6435af 100644 --- a/awesome_owl/static/src/playground.xml +++ b/awesome_owl/static/src/playground.xml @@ -2,7 +2,9 @@ - + + +

Sum:

diff --git a/awesome_owl/static/src/to_do/to_do_item.js b/awesome_owl/static/src/to_do/to_do_item.js index 38da4beb571..327aa4d7729 100644 --- a/awesome_owl/static/src/to_do/to_do_item.js +++ b/awesome_owl/static/src/to_do/to_do_item.js @@ -9,14 +9,24 @@ export class ToDoItem extends Component{ type: Object, shape : {id: Number, description: String, isComplete: Boolean} }, - toggleState: { + deleteToDo: { type: Function, - optional: true + optional: true, } } + + setup(){ + this.toggleState = this.toggleState.bind(this); + } - setState(todo) { - this.props.toggleState(todo); + toggleState() { + this.props.todo.isComplete = !this.props.todo.isComplete + } + + removeToDo() { + if(this.props.todo){ + this.props.deleteToDo(this.props.todo.id) + } } } diff --git a/awesome_owl/static/src/to_do/to_do_item.xml b/awesome_owl/static/src/to_do/to_do_item.xml index ecbca7c3f9c..5e49ffb6c35 100644 --- a/awesome_owl/static/src/to_do/to_do_item.xml +++ b/awesome_owl/static/src/to_do/to_do_item.xml @@ -7,6 +7,7 @@ +

diff --git a/awesome_owl/static/src/to_do/to_do_list.js b/awesome_owl/static/src/to_do/to_do_list.js index 40b6a59d3bc..b4639587e69 100644 --- a/awesome_owl/static/src/to_do/to_do_list.js +++ b/awesome_owl/static/src/to_do/to_do_list.js @@ -6,12 +6,17 @@ import { useAutoFocus } from '../utils' export class ToDoList extends Component { static template = "awesome_owl.to_do_list" - static props = {} + static props = { + removeTodo: { + type: Function, + optional: true + } + } setup(){ this.state = useState({value: 1}); this.todos = useState([]); useAutoFocus('task'); - this.toggleState = this.toggleState.bind(this); + this.deleteToDo = this.deleteToDo.bind(this); } addToDo(event) { @@ -22,8 +27,11 @@ export class ToDoList extends Component { } } - toggleState(todo) { - console.log("state toggled", todo.isComplete) + deleteToDo(id){ + const index = this.todos.findIndex((elem) => elem.id === id) + if(index >= 0){ + this.todos.splice(index,1) + } } static components = { ToDoItem }; diff --git a/awesome_owl/static/src/to_do/to_do_list.xml b/awesome_owl/static/src/to_do/to_do_list.xml index cf9e38898d0..87975315643 100644 --- a/awesome_owl/static/src/to_do/to_do_list.xml +++ b/awesome_owl/static/src/to_do/to_do_list.xml @@ -7,7 +7,7 @@

To Do List

- +
From 87fe2dc507cfbb6794ac893b698f700e04ae0001 Mon Sep 17 00:00:00 2001 From: Wajih-Wanis Date: Fri, 31 Oct 2025 14:39:36 +0100 Subject: [PATCH 3/3] [IMP] awesome_dashboard: done 1 to 11 --- awesome_dashboard/__manifest__.py | 7 +- awesome_dashboard/static/src/dashboard.js | 10 --- awesome_dashboard/static/src/dashboard.xml | 8 -- .../static/src/dashboard/dashboard.js | 71 +++++++++++++++++ .../static/src/dashboard/dashboard.xml | 24 ++++++ .../dashboard_item/dashboard_item.js | 21 +++++ .../dashboard_item/dashboard_item.xml | 10 +++ .../static/src/dashboard/dashboard_items.js | 76 +++++++++++++++++++ .../dashboard/dashboard_setting_dialog.xml | 24 ++++++ .../dashboard/dashboard_settings_dialog.js | 30 ++++++++ .../src/dashboard/number_card/number_card.js | 15 ++++ .../src/dashboard/number_card/number_card.xml | 9 +++ .../src/dashboard/pie_chart/pie_chart.js | 43 +++++++++++ .../src/dashboard/pie_chart/pie_chart.xml | 10 +++ .../pie_chart_card/pie_chart_card.js | 17 +++++ .../pie_chart_card/pie_chart_card.xml | 7 ++ .../src/dashboard/statistics_service.js | 23 ++++++ .../static/src/dashboard_loader.js | 15 ++++ 18 files changed, 401 insertions(+), 19 deletions(-) delete mode 100644 awesome_dashboard/static/src/dashboard.js delete mode 100644 awesome_dashboard/static/src/dashboard.xml create mode 100644 awesome_dashboard/static/src/dashboard/dashboard.js create mode 100644 awesome_dashboard/static/src/dashboard/dashboard.xml create mode 100644 awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.js create mode 100644 awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.xml create mode 100644 awesome_dashboard/static/src/dashboard/dashboard_items.js create mode 100644 awesome_dashboard/static/src/dashboard/dashboard_setting_dialog.xml create mode 100644 awesome_dashboard/static/src/dashboard/dashboard_settings_dialog.js 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 create mode 100644 awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.js create mode 100644 awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.xml 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/statistics_service.js create mode 100644 awesome_dashboard/static/src/dashboard_loader.js diff --git a/awesome_dashboard/__manifest__.py b/awesome_dashboard/__manifest__.py index 31406e8addb..e783edeacf1 100644 --- a/awesome_dashboard/__manifest__.py +++ b/awesome_dashboard/__manifest__.py @@ -24,7 +24,12 @@ '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' -} +} \ No newline at end of file diff --git a/awesome_dashboard/static/src/dashboard.js b/awesome_dashboard/static/src/dashboard.js deleted file mode 100644 index 637fa4bb972..00000000000 --- a/awesome_dashboard/static/src/dashboard.js +++ /dev/null @@ -1,10 +0,0 @@ -/** @odoo-module **/ - -import { Component } from "@odoo/owl"; -import { registry } from "@web/core/registry"; - -class AwesomeDashboard extends Component { - static template = "awesome_dashboard.AwesomeDashboard"; -} - -registry.category("actions").add("awesome_dashboard.dashboard", AwesomeDashboard); diff --git a/awesome_dashboard/static/src/dashboard.xml b/awesome_dashboard/static/src/dashboard.xml deleted file mode 100644 index 1a2ac9a2fed..00000000000 --- a/awesome_dashboard/static/src/dashboard.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - hello dashboard - - - diff --git a/awesome_dashboard/static/src/dashboard/dashboard.js b/awesome_dashboard/static/src/dashboard/dashboard.js new file mode 100644 index 00000000000..ff912400a7f --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard.js @@ -0,0 +1,71 @@ +/** @odoo-module **/ + +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 { DashboardSettingsDialog } from "./dashboard_settings_dialog"; + +class AwesomeDashboard extends Component { + static template = "awesome_dashboard.AwesomeDashboard"; + static components = { Layout, DashboardItem }; + + setup() { + this.action = useService("action"); + this.dialog = useService("dialog"); + this.statistics = useState(useService("awesome_dashboard.statistics")); + this.dashboardRegistry = registry.category("awesome_dashboard.items"); + this.display = { + controlPanel: {}, + }; + this.state = useState({ + items: this.getVisibleItems() + }); + } + + getVisibleItems() { + const allItems = this.dashboardRegistry.getAll(); + const hiddenItems = this.getHiddenItems(); + return allItems.filter(item => !hiddenItems.includes(item.id)) + } + + getHiddenItems() { + const stored = localStorage.getItem('dashboard_hidden_items'); + return stored ? JSON.parse(stored) : []; + } + + saveHiddenItems(hiddenItemIds){ + localStorage.setItem('dashboard_hidden_items', JSON.stringify(hiddenItemIds)); + this.state.items = this.getVisibleItems(); + } + + openSettings() { + const allItems = this.dashboardRegistry.getAll(); + this.dialog.add(DashboardSettingsDialog, { + items: allItems, + hiddenItems: this.getHiddenItems(), + onApply: (hiddenItemIds) => { + this.saveHiddenItems(hiddenItemIds); + } + }) + } + + openCustomerView() { + this.action.doAction("base.action_partner_form"); + } + + openLeads() { + this.action.doAction({ + type: "ir.actions.act_window", + name: "All leads", + res_model: "crm.lead", + views: [ + [false, "list"], + [false, "form"], + ], + }); + } +} + +registry.category("lazy_components").add("AwesomeDashboard", AwesomeDashboard); \ No newline at end of file diff --git a/awesome_dashboard/static/src/dashboard/dashboard.xml b/awesome_dashboard/static/src/dashboard/dashboard.xml new file mode 100644 index 00000000000..ee485dc552c --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard.xml @@ -0,0 +1,24 @@ + + + + + + + + + + +
+ + + + + + +
+
+
+ +
\ No newline at end of file diff --git a/awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.js b/awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.js new file mode 100644 index 00000000000..d4619303083 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.js @@ -0,0 +1,21 @@ +/** @odoo-module */ + +import { Component } from "@odoo/owl"; + + +export class DashboardItem extends Component { + static template = "awesome_dashboard.DashboardItem" + static props = { + slots: { + type: Object, + shape: { + default: Object + }, + }, + size: { + type: Number, + default: 1, + optional: true, + }, + }; +} \ No newline at end of file diff --git a/awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.xml b/awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.xml new file mode 100644 index 00000000000..d023340bb59 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.xml @@ -0,0 +1,10 @@ + + + +
+
+ +
+
+
+
\ No newline at end of file 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..a6c2cd553c0 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard_items.js @@ -0,0 +1,76 @@ +/** @odoo-module */ + +import { NumberCard } from "./number_card/number_card"; +import { PieChartCard } from "./pie_chart_card/pie_chart_card"; +import { registry } from "@web/core/registry"; + +const dashboardRegistry = registry.category("awesome_dashboard.items"); + + + +dashboardRegistry.add("average_quantity", + { + 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, + }) + }); + +dashboardRegistry.add("average_time", + { + 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, + }) + }); + +dashboardRegistry.add("number_new_orders", + { + 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, + }) + }); + +dashboardRegistry.add("cancelled_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, + }) + }); + +dashboardRegistry.add("amount_new_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, + }) + }); + +dashboardRegistry.add("pie_chart", + { + id: "pie_chart", + description: "Shirt orders by size", + Component: PieChartCard, + size: 2, + 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/dashboard/dashboard_setting_dialog.xml b/awesome_dashboard/static/src/dashboard/dashboard_setting_dialog.xml new file mode 100644 index 00000000000..bdcc981393a --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard_setting_dialog.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/awesome_dashboard/static/src/dashboard/dashboard_settings_dialog.js b/awesome_dashboard/static/src/dashboard/dashboard_settings_dialog.js new file mode 100644 index 00000000000..382a2254ebc --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard_settings_dialog.js @@ -0,0 +1,30 @@ +/** @odoo-module **/ + +import { Component } from "@odoo/owl"; +import { Dialog } from "@web/core/dialog/dialog"; + +export class DashboardSettingsDialog extends Component { + static template = "awesome_dashboard.DashboardSettingsDialog"; + static components = { Dialog }; + + static props = { + items: Array, + hiddenItems: Array, + onApply: Function, + close: Function, + }; + + onApply() { + const hiddenItemIds = []; + this.props.items.forEach(item => { + const checkbox = document.getElementById(item.id); + if (!checkbox.checked) { + hiddenItemIds.push(item.id); + } + }); + + this.props.onApply(hiddenItemIds); + + this.props.close(); + } +} 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..cc5e2d439d7 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/number_card/number_card.js @@ -0,0 +1,15 @@ +/** @odoo-module */ + +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/dashboard/pie_chart/pie_chart.js b/awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.js new file mode 100644 index 00000000000..29de2774d35 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.js @@ -0,0 +1,43 @@ +/** @odoo-module */ + +import { loadJS } from "@web/core/assets"; +import { getColor } from "@web/core/colors/colors"; +import { Component, onWillStart, useRef, onMounted, onWillUnmount } from "@odoo/owl"; + +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(); + }); + onWillUnmount(() => { + this.chart.destroy(); + }); + } + + renderChart() { + const labels = Object.keys(this.props.data); + const data = Object.values(this.props.data); + const color = labels.map((_, index) => getColor(index)); + this.chart = new Chart(this.canvasRef.el, { + type: "pie", + data: { + labels: labels, + datasets: [ + { + label: this.props.label, + data: data, + backgroundColor: color, + }, + ], + }, + }); + } +} \ No newline at end of file diff --git a/awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.xml b/awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.xml new file mode 100644 index 00000000000..18416e9a223 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.xml @@ -0,0 +1,10 @@ + + + +
+
+ +
+
+
+
\ No newline at end of file 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..6a962d2c99b --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_card.js @@ -0,0 +1,17 @@ +/** @odoo-module */ + +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/statistics_service.js b/awesome_dashboard/static/src/dashboard/statistics_service.js new file mode 100644 index 00000000000..e435d676105 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/statistics_service.js @@ -0,0 +1,23 @@ +/** @odoo-module */ + +import { registry } from "@web/core/registry"; +import { reactive } from "@odoo/owl"; +import { rpc } from "@web/core/network/rpc" + +const statisticsService = { + start(env) { + const statistics = reactive({ isReady: false }); + + async function loadData() { + const updates = await rpc("/awesome_dashboard/statistics"); + Object.assign(statistics, updates, { isReady: true }); + } + + setInterval(loadData, 10*60*1000); + loadData(); + + return statistics; + }, +}; + +registry.category("services").add("awesome_dashboard.statistics", statisticsService); \ 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..06ae51de339 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard_loader.js @@ -0,0 +1,15 @@ +/** @odoo-module */ + +import { registry } from "@web/core/registry"; +import { LazyComponent } from "@web/core/assets"; +import { Component, xml } from "@odoo/owl"; + +class AwesomeDashboardLoader extends Component { + static components = { LazyComponent }; + static template = xml` + + `; + +} + +registry.category("actions").add("awesome_dashboard.dashboard", AwesomeDashboardLoader); \ No newline at end of file