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/configuration_dialogue/configuration_dialogue.js b/awesome_dashboard/static/src/dashboard/configuration_dialogue/configuration_dialogue.js new file mode 100644 index 00000000000..d4f288a9ff1 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/configuration_dialogue/configuration_dialogue.js @@ -0,0 +1,34 @@ +/** @odoo-module **/ + +import { Component, useState } from "@odoo/owl"; +import { browser } from "@web/core/browser/browser"; +import { CheckBox } from "@web/core/checkbox/checkbox"; +import { Dialog } from "@web/core/dialog/dialog"; + + +export 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); + } + +} diff --git a/awesome_dashboard/static/src/dashboard/configuration_dialogue/configuration_dialogue.xml b/awesome_dashboard/static/src/dashboard/configuration_dialogue/configuration_dialogue.xml new file mode 100644 index 00000000000..a7351dbe738 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/configuration_dialogue/configuration_dialogue.xml @@ -0,0 +1,20 @@ + + + + + + Which cards do you whish to see ? + + + + + + + + + + + + diff --git a/awesome_dashboard/static/src/dashboard/dashboard.js b/awesome_dashboard/static/src/dashboard/dashboard.js new file mode 100644 index 00000000000..4a42e7bf5a8 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard.js @@ -0,0 +1,57 @@ +/** @odoo-module **/ + +import { Component, useState } from "@odoo/owl"; +import { browser } from "@web/core/browser/browser"; +import { _t } from "@web/core/l10n/translation"; +import { registry } from "@web/core/registry"; +import { useService } from "@web/core/utils/hooks"; +import { Layout } from "@web/search/layout"; +import { ConfigurationDialog } from "./configuration_dialogue/configuration_dialogue"; +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, PieChart }; + + setup() { + this.action = useService("action"); + this.items = registry.category("awesome_dashboard").getAll(); + this.dashboardData = useState(useService("load_statistics")); + this.dialog = useService("dialog"); + this.state = useState({ + disabledItems: browser.localStorage.getItem("disabledDashboardItems")?.split(",") || [], + }); + } + + openCustomers() { + this.action.doAction("base.action_partner_form"); + } + + openLeads() { + this.action.doAction({ + type: "ir.actions.act_window", + name: _t("All leads"), + res_model: "crm.lead", + views: [ + [false, "list"], + [false, "form"], + ], + }); + } + + openConfiguration() { + this.dialog.add(ConfigurationDialog, { + items: this.items, + disabledItems: this.state.disabledItems, + onUpdateConfiguration: this.updateConfiguration.bind(this), + }) + } + + updateConfiguration(newDisabledItems) { + this.state.disabledItems = newDisabledItems; + } +} + +registry.category("lazy_components").add("AwesomeDashboard", AwesomeDashboard); diff --git a/awesome_dashboard/static/src/dashboard/dashboard.scss b/awesome_dashboard/static/src/dashboard/dashboard.scss new file mode 100644 index 00000000000..34b2d0a2fa2 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard.scss @@ -0,0 +1,3 @@ +.o_dashboard { + background-color: bisque; +} diff --git a/awesome_dashboard/static/src/dashboard/dashboard.xml b/awesome_dashboard/static/src/dashboard/dashboard.xml new file mode 100644 index 00000000000..341849c8ee5 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard.xml @@ -0,0 +1,26 @@ + + + + + +
+ + + + +
+ +
+ + + + + + +
+
+
+ +
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..8a8ddaf346b --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.js @@ -0,0 +1,22 @@ +/** @odoo-module **/ + +import { Component } from "@odoo/owl"; + + +export class DashboardItem extends Component { + static template = "awesome_dashboard.DashboardItem"; + + static props = { + size: { + type: Number, + optional: true, + default: 1 + }, + slots: { + type: Object, + shape: { + default: true + }, + }, + }; +} 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..3b8b037335d --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.xml @@ -0,0 +1,13 @@ + + + + +
+
+ +
+
+
+ +
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..6a81bca2f33 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard_items.js @@ -0,0 +1,66 @@ +import { NumberCard } from "./number_card/number_card"; +import { PieChartCard } from "./pie_chart_card/pie_chart_card"; +import { registry } from "@web/core/registry"; +import { _t } from "@web/core/l10n/translation"; + +const items = [ + { + id: "average_quantity", + description: "Average amount of t-shirt", + Component: NumberCard, + props: (data) => ({ + title: _t("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: _t("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: _t("Number of new orders this month"), + value: data.nb_new_orders, + }) + }, + { + id: "cancelled_orders", + description: "Cancelled orders this month", + Component: NumberCard, + props: (data) => ({ + title: _t("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: _t("Total amount of new orders this month"), + value: data.total_amount, + }) + }, + { + id: "pie_chart", + description: "Shirt orders by size", + Component: PieChartCard, + size: 2, + props: (data) => ({ + title: _t("Shirt orders by size"), + values: data.orders_by_size, + }) + } +] + +items.forEach(item => { + registry.category("awesome_dashboard").add(item.id, item); +}); 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..ca8b584a334 --- /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, + } + } +} 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..e0f723b3963 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/number_card/number_card.xml @@ -0,0 +1,11 @@ + + + + + +
+ +
+
+ +
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..f88194c8236 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.js @@ -0,0 +1,73 @@ +/** @odoo-module **/ + +import { Component, onWillStart, useEffect, useRef } from "@odoo/owl"; +import { loadJS } from "@web/core/assets"; +import { _t } from "@web/core/l10n/translation"; + + +export class PieChart extends Component { + static template = "awesome_dashboard.PieChart"; + + static props = { + data: { + type: Object, + optional: true, + default: null, + }, + } + + setup() { + this.chart = null; + + this.rootRef = useRef("root"); + this.canvasRef = useRef("canvas"); + this.containerRef = useRef("container"); + + onWillStart(() => loadJS(["/web/static/lib/Chart/Chart.js"])); + + useEffect(() => this.renderChart()); + } + + generateData() { + if (this.props.data === null || Object.keys(this.props.data).length === 0) + return {}; + + const labels = Object.keys(this.props.data); + const datasets = []; + + datasets.push({ + label: 'Shirt Sizes', + data: Object.values(this.props.data), + backgroundColor: [ + 'rgba(27, 192, 204, 0.2)', + 'rgba(207, 116, 30, 0.2)', + 'rgba(255, 206, 86, 0.2)', + ], + }); + + return { labels, datasets }; + } + + renderChart() { + if (this.chart) { + this.chart.destroy(); + } + const config = { + type: 'pie', + data: this.generateData(), + options: { + responsive: true, + plugins: { + legend: { + position: 'top', + }, + title: { + display: true, + text: _t('Shirt Order By Size') + } + } + }, + }; + this.chart = new Chart(this.canvasRef.el, config); + } +} 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..2b54cfab532 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.xml @@ -0,0 +1,12 @@ + + + + +
+
+ +
+
+
+ +
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..a28c2f48c6f --- /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, + }, + } +} 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..c6682bab5f8 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_card.xml @@ -0,0 +1,9 @@ + + + + + + + + + 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..27d1487c692 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/statistics_service.js @@ -0,0 +1,30 @@ +/** @odoo-module **/ + +import { reactive } from "@odoo/owl"; +import { rpc } from "@web/core/network/rpc"; +import { registry } from "@web/core/registry"; + +const statisticsService = { + start() { + const data = reactive({ + average_quantity: 0, + average_time: 0, + nb_cancelled_orders: 0, + nb_new_orders: 0, + orders_by_size: { m: 0, s: 0, xl: 0 }, + total_amount: 0, + }); + + async function loadData() { + const result = await rpc("/awesome_dashboard/statistics"); + Object.assign(data, result); + } + + setInterval(loadData, 10 * 60 * 1000); + loadData(); + + return data; + }, +}; + +registry.category("services").add("load_statistics", statisticsService); diff --git a/awesome_dashboard/static/src/dashboard_action.js b/awesome_dashboard/static/src/dashboard_action.js new file mode 100644 index 00000000000..91296268369 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard_action.js @@ -0,0 +1,16 @@ +/** @odoo-module */ + +import { Component, xml } from "@odoo/owl"; +import { LazyComponent } from "@web/core/assets"; +import { registry } from "@web/core/registry"; + +class AwesomeDashboardLoader extends Component { + static components = { LazyComponent }; + + static template = xml` + + `; + +} + +registry.category("actions").add("awesome_dashboard.dashboard", AwesomeDashboardLoader); diff --git a/awesome_owl/static/src/card/card.js b/awesome_owl/static/src/card/card.js new file mode 100644 index 00000000000..0fea67650a8 --- /dev/null +++ b/awesome_owl/static/src/card/card.js @@ -0,0 +1,30 @@ +/** @odoo-module **/ + +import { Component, useState } from "@odoo/owl"; + +export class Card extends Component { + static template = "awesome_owl.card"; + + setup() { + this.state = useState({ + show: false, + }); + } + + static props = { + title: { + type: String, + optional: true, + }, + slots: { + type: Object, + shape: { + default: true + }, + }, + }; + + toggleDisplay() { + this.state.show = !this.state.show; + } +} diff --git a/awesome_owl/static/src/card/card.xml b/awesome_owl/static/src/card/card.xml new file mode 100644 index 00000000000..fce6693447c --- /dev/null +++ b/awesome_owl/static/src/card/card.xml @@ -0,0 +1,20 @@ + + + + + +
+
+
+
+ +
+
+ +
+
+
+ +
+ +
diff --git a/awesome_owl/static/src/counter/counter.js b/awesome_owl/static/src/counter/counter.js new file mode 100644 index 00000000000..5c3baa58bec --- /dev/null +++ b/awesome_owl/static/src/counter/counter.js @@ -0,0 +1,23 @@ +/** @odoo-module **/ + +import { Component, useState } from "@odoo/owl"; + +export class Counter extends Component { + static template = "awesome_owl.counter"; + + static props = { + callback: { + type: Function, + optional: true, + } + } + + setup() { + this.count = useState({ value: 0 }); + } + + increment() { + this.count.value += 1; + this.props.callback?.(); + } +} diff --git a/awesome_owl/static/src/counter/counter.xml b/awesome_owl/static/src/counter/counter.xml new file mode 100644 index 00000000000..2bd0fedeb18 --- /dev/null +++ b/awesome_owl/static/src/counter/counter.xml @@ -0,0 +1,11 @@ + + + + +
+ + +
+
+ +
diff --git a/awesome_owl/static/src/playground.js b/awesome_owl/static/src/playground.js index 657fb8b07bb..680851bb6e7 100644 --- a/awesome_owl/static/src/playground.js +++ b/awesome_owl/static/src/playground.js @@ -1,7 +1,25 @@ /** @odoo-module **/ -import { Component } from "@odoo/owl"; +import { Component, useState } from "@odoo/owl"; +import { Card } from "./card/card"; +import { Counter } from "./counter/counter"; +import { TodoList } from "./todo_list/todo_list"; export class Playground extends Component { static template = "awesome_owl.playground"; + static components = { + Counter, Card, TodoList + }; + + setup() { + this.content1 = "Card Content 1"; + this.content2 = "Card Content 2"; + this.state = useState({ + sum: 0, + }); + } + + incrementSum() { + this.state.sum += 1; + } } diff --git a/awesome_owl/static/src/playground.xml b/awesome_owl/static/src/playground.xml index 4fb905d59f9..1c33b00c755 100644 --- a/awesome_owl/static/src/playground.xml +++ b/awesome_owl/static/src/playground.xml @@ -1,10 +1,41 @@ - +
- hello world +

◇─◇─ welcome to the Owl Playground! ─◇─◇

+

Here you can experiment with Owl components and see how they work.

+

Feel free to modify the code and see the changes in real-time.

+

Use the buttons below to interact with the components.

+

Have fun!

+

love u 🫶🏻💓

+
+
+ + +
+
+
+

The sum is

+
+ +
+

Todo List

+ +
+ +
+ +

Here is a simple card component.

+

You can put any content inside it.

+

Try adding more components inside this card!

+
+ + + +
+
diff --git a/awesome_owl/static/src/todo_list/todo_item/todo_item.js b/awesome_owl/static/src/todo_list/todo_item/todo_item.js new file mode 100644 index 00000000000..177423845c2 --- /dev/null +++ b/awesome_owl/static/src/todo_list/todo_item/todo_item.js @@ -0,0 +1,31 @@ +/** @odoo-module **/ + +import { Component } from "@odoo/owl"; + +export class TodoItem extends Component { + static template = "awesome_owl.todo_item"; + + static props = { + todo: { + type: Object, + optional: true, + }, + toggleCallback: { + type: Function, + optional: true, + }, + removeCallback: { + type: Function, + optional: true, + } + }; + + toggleChange() { + this.props.todo.isCompleted = !this.props.todo.isCompleted; + this.props.toggleCallback?.(); + } + + removeTodo() { + this.props.removeCallback?.(this.props.todo.id); + } +} diff --git a/awesome_owl/static/src/todo_list/todo_item/todo_item.xml b/awesome_owl/static/src/todo_list/todo_item/todo_item.xml new file mode 100644 index 00000000000..e5a9551ab30 --- /dev/null +++ b/awesome_owl/static/src/todo_list/todo_item/todo_item.xml @@ -0,0 +1,14 @@ + + + + +

+ + . + + +

+
+ +
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..137ff96454c --- /dev/null +++ b/awesome_owl/static/src/todo_list/todo_list.js @@ -0,0 +1,39 @@ +/** @odoo-module **/ + +import { Component, useState } from "@odoo/owl"; +import { useAutofocus } from "../utils"; +import { TodoItem } from "./todo_item/todo_item"; + + +export class TodoList extends Component { + static template = "awesome_owl.todo_list"; + + static components = { + TodoItem, + }; + + setup() { + this.todos = useState([]); + this.nextIndex = 0; + useAutofocus("input_ref"); + } + + addTodo(ev) { + let input_val = ev.target.value; + if (ev.keyCode === 13 && input_val != "") { + this.todos.push({ + id: this.nextIndex++, + description: input_val, + isCompleted: false, + }); + ev.target.value = ""; + } + } + + removeTodoFromList(todoId) { + let index = this.todos.findIndex(todo => todo.id === todoId); + if (index !== -1) { + 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 new file mode 100644 index 00000000000..7da893cc0c3 --- /dev/null +++ b/awesome_owl/static/src/todo_list/todo_list.xml @@ -0,0 +1,17 @@ + + + + +
+
+ +
+ + + +
+
+
+
+ +
diff --git a/awesome_owl/static/src/utils.js b/awesome_owl/static/src/utils.js new file mode 100644 index 00000000000..51993344014 --- /dev/null +++ b/awesome_owl/static/src/utils.js @@ -0,0 +1,9 @@ +import { onMounted, useRef } from "@odoo/owl"; + +export function useAutofocus(ref_name) { + const inputRef = useRef(ref_name); + + onMounted(() => { + inputRef.el.focus(); + }); +}