-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Functional Training - Estate module #1180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 19.0
Are you sure you want to change the base?
Changes from all commits
6d4aa81
45e8921
6604169
8f1cf2e
c2b6c09
e4e3622
cf1a949
56e6200
9571313
e2709b4
2a97f38
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| 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"; | ||
| import { registry } from "@web/core/registry"; | ||
| import { useService } from "@web/core/utils/hooks"; | ||
| import { Layout } from "@web/search/layout"; | ||
| import { DashboardItem } from "./dashboard_item/dashboard_item"; | ||
|
|
||
| class AwesomeDashboard extends Component { | ||
| static template = "awesome_dashboard.AwesomeDashboard"; | ||
| static components = { Layout, DashboardItem }; | ||
|
|
||
| setup() { | ||
| this.action = useService("action"); | ||
| this.statistics = useState(useService("awesome_dashboard.statistics")); | ||
| this.items = registry.category("awesome_dashboard").getAll(); | ||
| this.display = { | ||
| controlPanel: {}, | ||
| }; | ||
| 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: "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; | ||
| } | ||
| } | ||
|
|
||
| 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) => ( | ||
| { ...item, enabled: !this.props.disabledItems.includes(item.id) } | ||
| ))); | ||
| } | ||
|
|
||
| toggleCheckbox(checked, toggledItem) { | ||
| toggledItem.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); | ||
| } | ||
|
|
||
| done() { | ||
| this.props.close(); | ||
| } | ||
| } | ||
|
|
||
| registry.category("lazy_components").add("AwesomeDashboard", AwesomeDashboard); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| .o_dashboard { | ||
| background-color: gray; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| <?xml version="1.0" encoding="UTF-8" ?> | ||
| <templates xml:space="preserve"> | ||
|
|
||
| <t t-name="awesome_dashboard.AwesomeDashboard"> | ||
| <Layout display="display" className="'o_dashboard h-100'"> | ||
| <t t-set-slot="layout-buttons"> | ||
| <button class="btn btn-primary" t-on-click="openCustomers">Customers</button> | ||
| <button class="btn btn-primary" t-on-click="openLeads">Leads</button> | ||
| </t> | ||
| <t t-set-slot="control-panel-additional-actions"> | ||
| <button t-on-click="openConfiguration" class="btn p-0 ms-1"> | ||
| <i class="fa fa-cog"/> | ||
| </button> | ||
| </t> | ||
| <div class="d-flex flex-wrap"> | ||
| <t t-foreach="items" t-as="item" t-key="item.id"> | ||
| <DashboardItem size="item.size || 1" t-if="!state.disabledItems.includes(item.id)"> | ||
| <t t-set="itemProp" t-value="item.props ? item.props(statistics) : {'data': statistics}"/> | ||
| <t t-component="item.Component" t-props="itemProp" /> | ||
| </DashboardItem> | ||
| </t> | ||
| </div> | ||
| </Layout> | ||
| </t> | ||
|
|
||
| <t t-name="awesome_dashboard.ConfigurationDialog"> | ||
| <Dialog title="'Dashboard items configuration'"> | ||
| Which cards do you whish to see ? | ||
| <t t-foreach="items" t-as="item" t-key="item.id"> | ||
| <CheckBox value="item.enabled" onChange="(ev) => this.toggleCheckbox(ev, item)"> | ||
| <t t-esc="item.description"/> | ||
| </CheckBox> | ||
| </t> | ||
| <t t-set-slot="footer"> | ||
| <button class="btn btn-primary" t-on-click="done"> | ||
| Apply | ||
| </button> | ||
| </t> | ||
| </Dialog> | ||
| </t> | ||
|
|
||
| </templates> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| 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, | ||
| optional: true, | ||
| default: 1, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line does not set a default value for the |
||
| }, | ||
| }; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| <?xml version="1.0" encoding="UTF-8" ?> | ||
| <templates xml:space="preserve"> | ||
|
|
||
| <t t-name="awesome_dashboard.DashboardItem"> | ||
| <div class="card m-2 border-dark" t-attf-style="width: {{18*props.size}}rem;"> | ||
| <div class="card-body"> | ||
| <t t-slot="default"/> | ||
| </div> | ||
| </div> | ||
| </t> | ||
|
|
||
| </templates> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import { registry } from "@web/core/registry"; | ||
| import { NumberCard } from "./number_card/number_card"; | ||
| import { PieChartCard } from "./pie_chart_card/pie_chart_card"; | ||
|
|
||
| const items = [ | ||
| { | ||
| id: "nb_new_orders", | ||
| description: "Number of new orders this month", | ||
| Component: NumberCard, | ||
| size: 1, | ||
| props: (data) => ({ | ||
| title: "Number of new orders this month", | ||
| value: data.nb_new_orders | ||
| }) | ||
| }, | ||
| { | ||
| id: "total_amount", | ||
| description: "Total amount of new orders this month", | ||
| Component: NumberCard, | ||
| size: 2, | ||
| props: (data) => ({ | ||
| title: "Total amount of new orders this month", | ||
| value: data.total_amount | ||
| }) | ||
| }, | ||
| { | ||
| id: "nb_cancelled_orders", | ||
| description: "Number of cancelled orders this month", | ||
| Component: NumberCard, | ||
| props: (data) => ({ | ||
| title: "Number of cancelled orders this month", | ||
| value: data.nb_cancelled_orders | ||
| }) | ||
| }, | ||
| { | ||
| 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 to go from 'new' to 'sent' or 'cancelled'", | ||
| Component: NumberCard, | ||
| props: (data) => ({ | ||
| title: "Average time for an order to go from 'new' to 'sent' or 'cancelled'", | ||
| value: data.average_time | ||
| }) | ||
| }, | ||
| { | ||
| id: "orders_by_size", | ||
| description: "Shirt orders by size", | ||
| Component: PieChartCard, | ||
| size: 2, | ||
| props: (data) => ({ | ||
| title: "Shirt orders by size", | ||
| data: data.orders_by_size | ||
| }) | ||
| }, | ||
| ]; | ||
|
|
||
| items.forEach(item => { | ||
| registry.category("awesome_dashboard").add(item.id, item); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import { Component } from "@odoo/owl"; | ||
|
|
||
| export class NumberCard extends Component { | ||
| static template = "awesome_dashboard.NumberCard"; | ||
| static props = { | ||
| title: String, | ||
| value: Number, | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| <?xml version="1.0" encoding="UTF-8" ?> | ||
| <templates xml:space="preserve"> | ||
| <t t-name="awesome_dashboard.NumberCard"> | ||
| <t t-esc="props.title"/> | ||
| <div class="fs-1 fw-bold text-success text-center"> | ||
| <t t-esc="props.value"/> | ||
| </div> | ||
| </t> | ||
| </templates> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| 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 = { | ||
| data: Object, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like the chart is not updated when the statistic service updates the values. |
||
| }; | ||
|
|
||
| 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: [ | ||
| { | ||
| data: data, | ||
| backgroundColor: color, | ||
| }, | ||
| ], | ||
| }, | ||
| }); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| <?xml version="1.0" encoding="UTF-8" ?> | ||
| <templates xml:space="preserve"> | ||
| <t t-name="awesome_dashboard.PieChart"> | ||
| <div t-att-class="'h-100 ' + props.class" t-ref="root"> | ||
| <div class="h-100 position-relative" t-ref="container"> | ||
| <canvas t-ref="canvas" /> | ||
| </div> | ||
| </div> | ||
| </t> | ||
| </templates> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| 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: String, | ||
| data: Object, | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| <?xml version="1.0" encoding="UTF-8" ?> | ||
| <templates xml:space="preserve"> | ||
| <t t-name="awesome_dashboard.PieChartCard"> | ||
| <t t-esc="props.title"/> | ||
| <PieChart data="props.data"/> | ||
| </t> | ||
| </templates> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import { reactive } from "@odoo/owl"; | ||
| import { rpc } from "@web/core/network/rpc"; | ||
| import { registry } from "@web/core/registry"; | ||
|
|
||
| const statisticsService = { | ||
|
|
||
| start() { | ||
| const statistics = reactive({ isReady: false }); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like the |
||
|
|
||
| async function loadData() { | ||
| const data = await rpc("/awesome_dashboard/statistics"); | ||
| Object.assign(statistics, data, { isReady: true }); | ||
| } | ||
|
|
||
| setInterval(loadData, 1000*60*10); | ||
| loadData(); | ||
|
|
||
| return statistics; | ||
| }, | ||
| } | ||
|
|
||
| registry.category("services").add("awesome_dashboard.statistics", statisticsService); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { Component, xml } from "@odoo/owl"; | ||
| import { LazyComponent } from "@web/core/assets"; | ||
| import { registry } from "@web/core/registry"; | ||
|
|
||
| export class AwesomeDashboardLoader extends Component { | ||
| static components = { LazyComponent }; | ||
| static template = xml` | ||
| <LazyComponent bundle="'awesome_dashboard.dashboard'" Component="'AwesomeDashboard'" /> | ||
| `; | ||
| } | ||
|
|
||
| registry.category("actions").add("awesome_dashboard.dashboard", AwesomeDashboardLoader); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A small detail: we usually reserve
evname for variables that contain events. Here it just contains the new value