Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,10 @@ dmypy.json

# Pyre type checker
.pyre/

.eslintignore
.eslintrc.json
jsconfig.json
package.json
package-lock.json
node_modules
3 changes: 3 additions & 0 deletions awesome_dashboard/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
'web.assets_backend': [
'awesome_dashboard/static/src/**/*',
],
'awesome_dashboard.dashboard': [
'awesome_dashboard/static/src/dashboard/**/*',
],
},
'license': 'AGPL-3'
}
Binary file added awesome_dashboard/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 0 additions & 8 deletions awesome_dashboard/static/src/dashboard.js

This file was deleted.

8 changes: 0 additions & 8 deletions awesome_dashboard/static/src/dashboard.xml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Component } from "@odoo/owl";

export class DashboardItem extends Component {
static template = "awesome_dashboard.DashboardItem";
static props = {
title: {
type: String,
optional: true
},
slots: {
type: Object,
shape: {
default: Object,
},
},
size: {
type: Number,
optional: true,
},
};
}
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.DashboardItem">
<div class="card m-2" t-attf-style="width: {{ 18 * props.size || 18 }}rem;">
<div class="card-body">
<t t-slot="default"/>
</div>
</div>
</t>
</templates>
12 changes: 12 additions & 0 deletions awesome_dashboard/static/src/dashboard/NumberCard/number_card.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Component } from "@odoo/owl";

export class NumberCard extends Component {
static template = "awesome_dashboard.NumberCard";
static props = {
title: {
type: String,
optional: true
},
value: Number,
};
}
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.NumberCard">
<h5 class="mb-0" t-esc="props.title"/>
<p class='fs-1 fw-bold text-success mb-0' t-esc="props.value"/>
</t>
</templates>
68 changes: 68 additions & 0 deletions awesome_dashboard/static/src/dashboard/PieChart/pie_chart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { Component, onWillStart, onPatched, useRef, onMounted } from "@odoo/owl";
import { loadJS } from "@web/core/assets";

export class PieChart extends Component {
static template = "awesome_dashboard.PieChart";
static props = {
items: {
type: Object,
optional: true,
default: () => ({}),
},
}

setup() {
this.chartRef = useRef("pie-canvas");
this.myPieChart = null;
onWillStart(async () => {
await loadJS("/web/static/lib/Chart/Chart.js");
});
onMounted(() => {
this.renderChart()
});
onPatched(() => {
this.renderChart()
});
}

renderChart() {
if (!this.chartRef.el) {
return;
}
if (this.myPieChart) {
this.myPieChart.destroy();
}
this.pieChartData = {
labels: ['M', 'S', 'XL'],
datasets: [{
label: 'Sales Count',
data: [this.props.items.m, this.props.items.s, this.props.items.xl],
backgroundColor: [
'rgba(255, 99, 132, 0.6)',
'rgba(54, 162, 235, 0.6)',
'rgba(255, 206, 86, 0.6)'
],
borderColor: [
'rgba(255, 99, 132, 1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)'
],
borderWidth: 1
}]
};
this.pieChartOptions = {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: {
position: 'top',
}
}
};
this.myPieChart = new Chart(this.chartRef.el, {
type: 'pie',
data: this.pieChartData,
options: this.pieChartOptions
});
}
}
8 changes: 8 additions & 0 deletions awesome_dashboard/static/src/dashboard/PieChart/pie_chart.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">
<t t-name="awesome_dashboard.PieChart">
<div class="card-body">
<canvas t-ref="pie-canvas" class="o_pie_chart_canvas"/>
</div>
</t>
</templates>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Component } from "@odoo/owl";
import { PieChart } from "../PieChart/pie_chart";

export class PieChartCard extends Component {
static template = "awesome_dashboard.PieChartCard";
static components = { PieChart };
static props = {
title: {
type: String,
optional: true
},
value: 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">
<h5 class="mb-0" t-esc="props.title"/>
<PieChart items="props.value"/>
</t>
</templates>
75 changes: 75 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { Component, useState } from "@odoo/owl";
import { registry } from "@web/core/registry";
import { Layout } from "@web/search/layout";
import { useService } from "@web/core/utils/hooks";
import { DashboardItem } from "./DashboardItem/dashboard_item";
import { PieChart } from "./PieChart/pie_chart";

class AwesomeDashboard extends Component {
static template = "awesome_dashboard.AwesomeDashboard";
static components = { Layout, DashboardItem, PieChart };

setup() {
this.action = useService("action");
const statisticsService = useService("awesome_dashboard.statistics");
this.statistics = useState(statisticsService.state);
this.modalState = useState({ isOpen: false });
this.hiddenItems = useState({ ids: JSON.parse(localStorage.getItem("hidden_dashboard_items") || "[]"), });
this.items = useState(registry.category("awesome_dashboard").getAll().filter((item) => !this.hiddenItems.ids.includes(item.id)));
this.allItems = useState(registry.category("awesome_dashboard").getAll());
}

openCustomers() {
this.action.doAction({
type: "ir.actions.act_window",
name: "Customers",
res_model: "res.partner",
views: [
[false, "kanban"],
[false, "form"],
[false, "list"],
],
});
}

openLeads() {
this.action.doAction({
type: "ir.actions.act_window",
name: "Leads",
res_model: "crm.lead",
views: [
[false, "list"],
[false, "form"],
],
});
}

toggleModal() {
this.modalState.isOpen = !this.modalState.isOpen
}

toggleItem(event) {
const itemId = event.target.value;
if (event.target.checked) {
this.hiddenItems.ids = this.hiddenItems.ids.filter(
(id) => id !== itemId
);
} else {
this.hiddenItems.ids.push(itemId);
}
}

applySettings() {
localStorage.setItem(
"hidden_dashboard_items",
JSON.stringify(this.hiddenItems.ids)
);
this.items = registry
.category("awesome_dashboard")
.getAll()
.filter((item) => !this.hiddenItems.ids.includes(item.id));
this.toggleModal();
}
}

registry.category("lazy_components").add("awesome_dashboard.AwesomeDashboard", AwesomeDashboard);
3 changes: 3 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.o_dashboard {
background-color: gray;
}
60 changes: 60 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">

<t t-name="awesome_dashboard.AwesomeDashboard">
<Layout className="'o_dashboard h-100'" display="{ controlPanel: {} }">
<t t-set-slot="control-panel-always-buttons">
<button class="btn btn-primary me-2" t-on-click="openCustomers">
Customers
</button>
<button class="btn btn-primary me-2" t-on-click="openLeads">
Leads
</button>
</t>

<t t-set-slot="control-panel-additional-actions">
<button type="button" class="btn btn-light p-1" t-on-click="toggleModal">
<i class="fa fa-fw fa-cog fs-5 text-muted"></i>
</button>
</t>

<div class="d-flex flex-wrap mt-1 text-center">
<t t-foreach="items" t-as="item" t-key="item.id">
<DashboardItem title="item.props.title" size="item.size">
<t t-set="itemProp" t-value="item.props ? item.props(this.statistics.data) : {'data': this.statistics.data}"/>
<t t-component="item.Component" t-props="itemProp" />
</DashboardItem>
</t>
</div>

<div class="modal fade d-block" t-att-class="(this.modalState.isOpen ? 'show': 'd-none')" tabindex="-1" role="dialog">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header d-flex justify-content-between">
<h5 class="modal-title">Dashboard items configuration</h5>
</div>
<div class="modal-body">
<label>Which card do you whish to see?</label>
<div class="m-2">
<t t-foreach="this.allItems" t-as="item" t-key="item.id">
<div>
<input type="checkbox" class='me-2'
t-att-value="item.id"
t-att-checked="!hiddenItems.ids.includes(item.id)"
t-on-change="toggleItem"/>
<t t-esc="item.description"/>
</div>
</t>
</div>
</div>
<div class="modal-footer">
<button class="btn btn-primary me-2" t-on-click="applySettings">Apply</button>
<button class="btn btn-secondary" t-on-click="toggleModal">Cancel</button>
</div>
</div>
</div>
</div>
</Layout>
</t>

</templates>
Loading