Skip to content

Commit 1aae9fc

Browse files
committed
[IMP] awesome_owl, awesome_dashboard: Web Framework Done
1 parent cbcef67 commit 1aae9fc

31 files changed

+575
-23
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,7 @@ dmypy.json
129129
.pyre/
130130

131131
estate/.idea/
132+
.idea
133+
package.json
134+
package-lock.json
135+
node_modules

awesome_dashboard/__manifest__.py

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

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: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { Component, useState } from "@odoo/owl";
2+
import { Dialog } from "@web/core/dialog/dialog";
3+
import { CheckBox } from "@web/core/checkbox/checkbox";
4+
import { browser } from "@web/core/browser/browser";
5+
6+
export class ConfigurationDialog extends Component {
7+
static template = "awesome_dashboard.ConfigurationDialog";
8+
static components = { Dialog, CheckBox };
9+
static props = ["close", "items", "disabledItems", "onUpdateConfiguration"];
10+
11+
setup() {
12+
this.items = useState(this.props.items.map((item) => {
13+
return {
14+
...item,
15+
enabled: !this.props.disabledItems.includes(item.id),
16+
}
17+
}));
18+
}
19+
20+
done() {
21+
this.props.close();
22+
}
23+
24+
onChange(checked, changedItem) {
25+
changedItem.enabled = checked;
26+
const newDisabledItems = Object.values(this.items).filter(
27+
(item) => !item.enabled
28+
).map((item) => item.id)
29+
30+
browser.localStorage.setItem(
31+
"disabledDashboardItems",
32+
newDisabledItems,
33+
);
34+
35+
this.props.onUpdateConfiguration(newDisabledItems);
36+
}
37+
38+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<t t-name="awesome_dashboard.ConfigurationDialog">
2+
<Dialog title="'Dashboard items configuration'">
3+
Which cards do you wish to see ?
4+
<t t-foreach="items" t-as="item" t-key="item.id">
5+
<CheckBox value="item.enabled" onChange="(ev) => this.onChange(ev, item)">
6+
<t t-esc="item.description"/>
7+
</CheckBox>
8+
</t>
9+
<t t-set-slot="footer">
10+
<button class="btn btn-primary" t-on-click="done">
11+
Done
12+
</button>
13+
</t>
14+
</Dialog>
15+
</t>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/** @odoo-module **/
2+
3+
import { Component, useState } from "@odoo/owl";
4+
import { registry } from "@web/core/registry";
5+
import { Layout } from "@web/search/layout";
6+
import { useService } from "@web/core/utils/hooks";
7+
import { DashboardItem } from "./dashboard_item/dashboard_item";
8+
import { browser } from "@web/core/browser/browser";
9+
import { ConfigurationDialog } from "./configuration_dialog";
10+
11+
class AwesomeDashboard extends Component {
12+
static template = "awesome_dashboard.AwesomeDashboard";
13+
static components = { Layout, DashboardItem };
14+
15+
setup() {
16+
this.dialog = useService("dialog");
17+
this.action = useService("action");
18+
this.display = {
19+
controlPanel: {},
20+
};
21+
this.statistics = useState(useService("awesome_dashboard.statistics"));
22+
this.items = registry.category("awesome_dashboard").getAll();
23+
this.state = useState({
24+
disabledItems: browser.localStorage.getItem("disabledDashboardItems")?.split(",") || []
25+
});
26+
}
27+
28+
openConfiguration() {
29+
this.dialog.add(ConfigurationDialog, {
30+
items: this.items,
31+
disabledItems: this.state.disabledItems,
32+
onUpdateConfiguration: this.updateConfiguration.bind(this),
33+
})
34+
}
35+
36+
updateConfiguration(newDisabledItems) {
37+
this.state.disabledItems = newDisabledItems;
38+
}
39+
40+
openCustomerView() {
41+
this.action.doAction("base.action_partner_form");
42+
}
43+
44+
openLeads() {
45+
this.action.doAction({
46+
type: "ir.actions.act_window",
47+
name: "All leads",
48+
res_model: "crm.lead",
49+
views: [
50+
[false, "list"],
51+
[false, "form"],
52+
],
53+
});
54+
}
55+
}
56+
57+
registry.category("lazy_components").add("AwesomeDashboard", AwesomeDashboard);
58+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.o_dashboard {
2+
background-color: gray;
3+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<templates xml:space="preserve">
3+
4+
<t t-name="awesome_dashboard.AwesomeDashboard">
5+
<Layout display="display" className="'o_dashboard h-100'">
6+
<t t-set-slot="layout-buttons">
7+
<button class="btn btn-primary" t-on-click="openCustomerView">Customers</button>
8+
<button class="btn btn-primary" t-on-click="openLeads">Leads</button>
9+
</t>
10+
<t t-set-slot="control-panel-additional-actions">
11+
<button t-on-click="openConfiguration" class="btn p-0 ms-1 border-0">
12+
<i class="fa fa-cog"></i>
13+
</button>
14+
</t>
15+
<div class="d-flex flex-wrap" t-if="statistics.isReady">
16+
<t t-foreach="items" t-as="item" t-key="item.id">
17+
<DashboardItem t-if="!state.disabledItems.includes(item.id)" size="item.size || 1">
18+
<t t-set="itemProp" t-value="item.props ? item.props(statistics) : {'data': statistics}"/>
19+
<t t-component="item.Component" t-props="itemProp" />
20+
</DashboardItem>
21+
</t>
22+
</div>
23+
</Layout>
24+
</t>
25+
</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+
}

0 commit comments

Comments
 (0)