Skip to content

Commit 451e46d

Browse files
committed
[ADD] awesome_dashboard: add a dashboard.
Using this dashboard a user can view information about their orders in real time (updated data). The dashboard is customizable too, a user can decide which cards to see.
1 parent 8787087 commit 451e46d

22 files changed

+354
-18
lines changed

awesome_dashboard/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# -*- coding: utf-8 -*-
22

33
from . import controllers
4+
from . import models

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'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import res_users_settings
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from odoo import fields, models
2+
3+
4+
class ResUsersSettings(models.Model):
5+
_inherit = "res.users.settings"
6+
7+
awesome_dashboard_preferences = fields.Text()

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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { Component, useState } from "@odoo/owl";
2+
import { Dialog } from "@web/core/dialog/dialog";
3+
import { CheckBox } from "@web/core/checkbox/checkbox";
4+
5+
export class ConfigurationDialog extends Component {
6+
static template = "awesome_dashboard.ConfigurationDialog";
7+
static components = { Dialog, CheckBox };
8+
static props = ["close", "items", "disabledItems", "onUpdateConfiguration"];
9+
10+
setup() {
11+
this.disabledItems = useState(this.props.disabledItems);
12+
}
13+
14+
done() {
15+
this.props.close();
16+
}
17+
18+
onChange(isChecked, changedItemId) {
19+
this.disabledItems = isChecked
20+
? this.disabledItems.filter(i => i !== changedItemId)
21+
: [...this.disabledItems, changedItemId];
22+
this.props.onUpdateConfiguration(this.disabledItems);
23+
}
24+
25+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<templates xml:space="preserve">
3+
<t t-name="awesome_dashboard.ConfigurationDialog">
4+
<Dialog>
5+
<t t-foreach="props.items" t-as="item" t-key="item.id">
6+
<CheckBox value="!this.disabledItems.includes(item.id)" onChange="(isChecked) => this.onChange(isChecked, item.id)">
7+
<t t-esc="item.description"/>
8+
</CheckBox>
9+
</t>
10+
<t t-set-slot="footer">
11+
<button class="btn btn-primary" t-on-click="done">Apply</button>
12+
</t>
13+
</Dialog>
14+
</t>
15+
</templates>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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 "./dashboarditem/dashboarditem";
8+
import { ConfigurationDialog } from "./configurationdialog/configurationdialog";
9+
import { _t } from "@web/core/l10n/translation";
10+
import { user } from "@web/core/user";
11+
12+
class AwesomeDashboard extends Component {
13+
static template = "awesome_dashboard.AwesomeDashboard";
14+
static styles = ["awesome_dashboard/static/src/dashboard.scss"];
15+
static components = { Layout, DashboardItem };
16+
17+
setup() {
18+
this.action = useService("action");
19+
this.stats = useState(useService("awesome_dashboard.statistics"));
20+
this.items = registry.category("awesome_dashboard").getAll();
21+
this.dialog = useService("dialog");
22+
23+
const user_settings = user.settings['awesome_dashboard_preferences']
24+
this.state = useState({ disabledItems: user_settings ? user_settings.split(",") : [] });
25+
}
26+
27+
openCustomerView() {
28+
this.action.doAction("base.action_partner_form");
29+
}
30+
31+
openLeadsView() {
32+
this.action.doAction({
33+
type: "ir.actions.act_window",
34+
name: _t("Leads"),
35+
res_model: "crm.lead",
36+
views: [
37+
[false, "list"],
38+
[false, "form"],
39+
],
40+
});
41+
}
42+
43+
openConfiguration() {
44+
this.dialog.add(ConfigurationDialog, {
45+
items: this.items,
46+
disabledItems: this.state.disabledItems,
47+
onUpdateConfiguration: this.updateConfiguration.bind(this),
48+
})
49+
}
50+
51+
updateConfiguration(newDisabledItems) {
52+
this.state.disabledItems = newDisabledItems;
53+
user.setUserSettings('awesome_dashboard_preferences', newDisabledItems.join(","));
54+
}
55+
}
56+
57+
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: gray;
3+
}

0 commit comments

Comments
 (0)