Skip to content

Commit d1d8182

Browse files
cede-odooprbo-odoo
authored andcommitted
[ADD] website airproof: add solution for website theme tutorial
closes odoo#764 Signed-off-by: Antoine Vandevenne (anv) <[email protected]>
1 parent 4c650f3 commit d1d8182

File tree

125 files changed

+4690
-27
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+4690
-27
lines changed

awesome_dashboard/__manifest__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@
2424
'assets': {
2525
'web.assets_backend': [
2626
'awesome_dashboard/static/src/**/*',
27+
('remove', 'awesome_dashboard/static/src/dashboard/**/*'),
2728
],
29+
'awesome_dashboard.dashboard': [
30+
'awesome_dashboard/static/src/dashboard/**/*'
31+
]
2832
},
2933
'license': 'AGPL-3'
3034
}

awesome_dashboard/static/src/dashboard.js

Lines changed: 0 additions & 10 deletions
This file was deleted.

awesome_dashboard/static/src/dashboard.xml

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/** @odoo-module **/
2+
import { Component , useState } from "@odoo/owl";
3+
import { registry } from "@web/core/registry";
4+
import { Layout } from "@web/search/layout";
5+
import { useService } from "@web/core/utils/hooks";
6+
import { DashboardItem } from "./dashboard_item/dashboard_item";
7+
import { Dialog } from "@web/core/dialog/dialog";
8+
import { CheckBox } from "@web/core/checkbox/checkbox";
9+
import { browser } from "@web/core/browser/browser";
10+
11+
class AwesomeDashboard extends Component {
12+
static template = "awesome_dashboard.AwesomeDashboard";
13+
static components = { Layout , DashboardItem };
14+
setup() {
15+
this.action = useService("action");
16+
this.statisticsService = useState(useService("awesome_dashboard.statistics"));
17+
this.dialog = useService("dialog");
18+
this.display = {
19+
controlPanel: {},
20+
};
21+
this.items = registry.category("awesome_dashboard").getAll();
22+
this.state = useState({
23+
disabledItems: browser.localStorage.getItem("disabledDashboardItems")?.split(",") || []
24+
});
25+
}
26+
openConfiguration() {
27+
this.dialog.add(ConfigurationDialog, {
28+
items: this.items,
29+
disabledItems: this.state.disabledItems,
30+
onUpdateConfiguration: this.updateConfiguration.bind(this),
31+
})
32+
}
33+
updateConfiguration(newDisabledItems) {
34+
this.state.disabledItems = newDisabledItems;
35+
}
36+
37+
openCustomerView() {
38+
this.action.doAction("base.action_partner_form");
39+
}
40+
41+
openLeads() {
42+
this.action.doAction({
43+
type: "ir.actions.act_window",
44+
name: "All leads",
45+
res_model: "crm.lead",
46+
views: [
47+
[false, "list"],
48+
[false, "form"],
49+
],
50+
target:"current"
51+
});
52+
}
53+
}
54+
55+
class ConfigurationDialog extends Component {
56+
static template = "awesome_dashboard.ConfigurationDialog";
57+
static components = { Dialog, CheckBox };
58+
static props = ["close", "items", "disabledItems", "onUpdateConfiguration"];
59+
60+
setup() {
61+
this.items = useState(this.props.items.map((item) => {
62+
return {
63+
...item,
64+
enabled: !this.props.disabledItems.includes(item.id),
65+
}
66+
}));
67+
}
68+
69+
done() {
70+
this.props.close();
71+
}
72+
73+
onChange(checked, changedItem) {
74+
changedItem.enabled = checked;
75+
const newDisabledItems = Object.values(this.items).filter(
76+
(item) => !item.enabled
77+
).map((item) => item.id)
78+
79+
browser.localStorage.setItem(
80+
"disabledDashboardItems",
81+
newDisabledItems,
82+
);
83+
84+
this.props.onUpdateConfiguration(newDisabledItems);
85+
}
86+
87+
}
88+
89+
registry.category("lazy_components").add("AwesomeDashboard", AwesomeDashboard);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.o_dashboard {
2+
background-color: var(--gray);
3+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<templates xml:space="preserve">
3+
4+
<t t-name="awesome_dashboard.AwesomeDashboard">
5+
<div class="awesome-dashboard-wrapper">
6+
<Layout display="display" className="'o_dashboard h-100'">
7+
<t t-set-slot="layout-buttons">
8+
<button class="btn btn-primary" t-on-click="openCustomerView">Customers</button>
9+
<button class="btn btn-primary" t-on-click="openLeads">Leads</button>
10+
</t>
11+
<t t-set-slot="control-panel-additional-actions">
12+
<button t-on-click="openConfiguration" class="btn p-0 ms-1 border-0">
13+
<i class="fa fa-cog"/>
14+
</button>
15+
</t>
16+
<div class="d-flex flex-wrap" t-if="statisticsService.isReady">
17+
<t t-foreach="items" t-as="item" t-key="item.id">
18+
<DashboardItem t-if="!state.disabledItems.includes(item.id)" size="item.size || 1">
19+
<t t-set="itemProp" t-value="item.props ? item.props(statisticsService) : {'data': statisticsService}"/>
20+
<t t-component="item.Component" t-props="itemProp" />
21+
</DashboardItem>
22+
</t>
23+
</div>
24+
</Layout>
25+
</div>
26+
</t>
27+
<t t-name="awesome_dashboard.ConfigurationDialog">
28+
<div class="configuration-dialog-wrapper">
29+
<Dialog title="'Dashboard items configuration'">
30+
Which cards do you whish to see ?
31+
<t t-foreach="items" t-as="item" t-key="item.id">
32+
<CheckBox value="item.enabled" onChange="(ev) => this.onChange(ev, item)">
33+
<t t-esc="item.description"/>
34+
</CheckBox>
35+
</t>
36+
<t t-set-slot="footer">
37+
<button class="btn btn-primary" t-on-click="done">
38+
Done
39+
</button>
40+
</t>
41+
</Dialog>
42+
</div>
43+
</t>
44+
</templates>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Component } from "@odoo/owl";
2+
3+
export class DashboardItem extends Component {
4+
static template = "awesome_dashboard.DashboardItem";
5+
static props = {
6+
slots: {
7+
type: Object,
8+
shape: {
9+
default: Object,
10+
},
11+
},
12+
size: {
13+
type: Number,
14+
default: 1,
15+
optional: true,
16+
},
17+
};
18+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<templates xml:space="preserve">
3+
<t t-name="awesome_dashboard.DashboardItem">
4+
<div class="card m-2 border-dark" t-attf-style="width: {{18*props.size}}rem;">
5+
<div class="card-body">
6+
<t t-slot="default"/>
7+
</div>
8+
</div>
9+
</t>
10+
</templates>
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/** @odoo-module */
2+
3+
import { NumberCard } from "@awesome_dashboard/dashboard/number_card/number_card";
4+
import { PieChartCard } from "@awesome_dashboard/dashboard/pie_chart_card/pie_chart_card";
5+
import { registry } from "@web/core/registry";
6+
import { _t } from "@web/core/l10n/translation";
7+
8+
const items = [
9+
{
10+
id: "average_quantity",
11+
description: _t("Average amount of t-shirt"),
12+
Component: NumberCard,
13+
props: (data) => ({
14+
title: _t("Average amount of t-shirt by order this month"),
15+
value: data.average_quantity,
16+
})
17+
},
18+
{
19+
id: "average_time",
20+
description: _t("Average time for an order"),
21+
Component: NumberCard,
22+
props: (data) => ({
23+
title: _t("Average time for an order to go from 'new' to 'sent' or 'cancelled'"),
24+
value: data.average_time,
25+
})
26+
},
27+
{
28+
id: "number_new_orders",
29+
description: _t("New orders this month"),
30+
Component: NumberCard,
31+
props: (data) => ({
32+
title: _t("Number of new orders this month"),
33+
value: data.nb_new_orders,
34+
})
35+
},
36+
{
37+
id: "cancelled_orders",
38+
description: _t("Cancelled orders this month"),
39+
Component: NumberCard,
40+
props: (data) => ({
41+
title: _t("Number of cancelled orders this month"),
42+
value: data.nb_cancelled_orders,
43+
})
44+
},
45+
{
46+
id: "amount_new_orders",
47+
description: _t("amount orders this month"),
48+
Component: NumberCard,
49+
props: (data) => ({
50+
title: _t("Total amount of new orders this month"),
51+
value: data.total_amount,
52+
})
53+
},
54+
{
55+
id: "pie_chart",
56+
description: _t("Shirt orders by size"),
57+
Component: PieChartCard,
58+
size: 2,
59+
props: (data) => ({
60+
title: _t("Shirt orders by size"),
61+
values: data.orders_by_size,
62+
})
63+
}
64+
]
65+
items.forEach(item => {
66+
registry.category("awesome_dashboard").add(item.id, item);
67+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/** @odoo-module */
2+
3+
import { Component } from "@odoo/owl";
4+
5+
export class NumberCard extends Component {
6+
static template = "awesome_dashboard.NumberCard";
7+
static props = {
8+
title: {
9+
type: String,
10+
},
11+
value: {
12+
type: Number,
13+
}
14+
}
15+
}

0 commit comments

Comments
 (0)