-
Notifications
You must be signed in to change notification settings - Fork 2.2k
[ADD] awesome_owl, awesome_dashboard : Training OWL #793
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
Open
Lud0do1202
wants to merge
3
commits into
odoo:18.0
Choose a base branch
from
Lud0do1202:18.0-training_owl-ltra
base: 18.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
awesome_dashboard/static/src/dashboard/cards/number_card.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** @odoo-module **/ | ||
|
||
import { Component } from "@odoo/owl"; | ||
|
||
export class NumberCard extends Component { | ||
static template = "awesome_dashboard.NumberCard"; | ||
static props = { | ||
title: { type: String, optional: true }, | ||
value: { type: [String, Number] }, | ||
}; | ||
} |
11 changes: 11 additions & 0 deletions
11
awesome_dashboard/static/src/dashboard/cards/number_card.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<templates xml:space="preserve"> | ||
|
||
<t t-name="awesome_dashboard.NumberCard"> | ||
<div class="text-center"> | ||
<div class="fs-3" t-esc="props.title" /> | ||
<div class="text-success fs-1" t-esc="props.value" /> | ||
</div> | ||
</t> | ||
|
||
</templates> |
13 changes: 13 additions & 0 deletions
13
awesome_dashboard/static/src/dashboard/cards/pie_chart_card.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** @odoo-module **/ | ||
|
||
import { Component } from "@odoo/owl"; | ||
import { PieChart } from "@awesome_dashboard/dashboard/charts/pie_chart"; | ||
|
||
export class PieChartCard extends Component { | ||
static template = "awesome_dashboard.PieChartCard"; | ||
static components = { PieChart }; | ||
static props = { | ||
title: { type: String, optional: true }, | ||
chart: { type: Object, optional: true, shape: { ...PieChart.props } }, | ||
}; | ||
} |
11 changes: 11 additions & 0 deletions
11
awesome_dashboard/static/src/dashboard/cards/pie_chart_card.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<templates xml:space="preserve"> | ||
|
||
<t t-name="awesome_dashboard.PieChartCard"> | ||
<div class="text-center"> | ||
<div class="fs-3" t-esc="props.title" /> | ||
<PieChart t-props="props.chart" /> | ||
</div> | ||
</t> | ||
|
||
</templates> |
42 changes: 42 additions & 0 deletions
42
awesome_dashboard/static/src/dashboard/charts/pie_chart.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** @odoo-module **/ | ||
|
||
import { Component, onWillStart, onWillUnmount, useRef, useEffect } from "@odoo/owl"; | ||
import { loadJS } from "@web/core/assets"; | ||
|
||
export class PieChart extends Component { | ||
static template = "awesome_dashboard.PieChart"; | ||
static props = { | ||
data: { type: Object }, | ||
options: { type: Object, optional: true }, | ||
}; | ||
|
||
setup() { | ||
this.canvasRef = useRef("canvas"); | ||
this.chart = null; | ||
|
||
onWillStart(async () => { | ||
await loadJS("/web/static/lib/Chart/Chart.js"); | ||
}); | ||
useEffect(() => this.renderChart()); | ||
onWillUnmount(this.onWillUnmount); | ||
} | ||
|
||
onWillUnmount() { | ||
if (this.chart) { | ||
this.chart.destroy(); | ||
} | ||
} | ||
|
||
renderChart() { | ||
if (this.chart) { | ||
this.chart.destroy(); | ||
} | ||
if (this.canvasRef.el) { | ||
this.chart = new Chart(this.canvasRef.el, { | ||
type: "pie", | ||
data: this.props.data, | ||
options: this.props.options, | ||
}); | ||
} | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
awesome_dashboard/static/src/dashboard.xml → ...static/src/dashboard/charts/pie_chart.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<templates xml:space="preserve"> | ||
|
||
<t t-name="awesome_dashboard.AwesomeDashboard"> | ||
hello dashboard | ||
<t t-name="awesome_dashboard.PieChart"> | ||
<canvas t-ref="canvas" /> | ||
</t> | ||
|
||
</templates> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** @odoo-module **/ | ||
|
||
import { Component, useState, useEffect } from "@odoo/owl"; | ||
import { Layout } from "@web/search/layout"; | ||
import { useService } from "@web/core/utils/hooks"; | ||
import { AwesomeDashboardItem } from "@awesome_dashboard/dashboard/dashboard_item"; | ||
import { registry } from "@web/core/registry"; | ||
import { CogMenu } from "@web/search/cog_menu/cog_menu"; | ||
import { AwesomeDashboardConfigDialog } from "@awesome_dashboard/dashboard/dialogs/dashboard_config_dailog"; | ||
|
||
class AwesomeDashboard extends Component { | ||
static template = "awesome_dashboard.AwesomeDashboard"; | ||
static components = { Layout, AwesomeDashboardItem, CogMenu }; | ||
|
||
setup() { | ||
this.action = useService("action"); | ||
this.stats = useState(useService("awesome_dashboard_statistics")); | ||
const config = JSON.parse(localStorage.getItem("awesome_dashboard_config")); | ||
const data = registry.category("awesome_dashboard").get("data"); | ||
this.setActives(config, data); | ||
this.items = useState({ data }); | ||
this.dialog = useService("dialog"); | ||
} | ||
|
||
onClickCustomers() { | ||
this.action.doAction({ | ||
type: "ir.actions.act_window", | ||
name: "Customers", | ||
target: "current", | ||
res_model: "res.partner", | ||
views: [[false, "kanban"]], | ||
}); | ||
} | ||
|
||
onClickLeads() { | ||
this.action.doAction({ | ||
type: "ir.actions.act_window", | ||
name: "Leads", | ||
target: "current", | ||
res_model: "crm.lead", | ||
views: [[false, "list"]], | ||
}); | ||
} | ||
|
||
setActives(ref, toUpdate) { | ||
for (const key in ref) { | ||
const entry = ref[key]; | ||
const dataItem = toUpdate[key]; | ||
if (dataItem) { | ||
dataItem.active = entry.active; | ||
} | ||
} | ||
} | ||
|
||
openConfiguration() { | ||
this.dialog.add(AwesomeDashboardConfigDialog, { | ||
onConfirm: (configItems) => { | ||
this.setActives(configItems, this.items.data); | ||
}, | ||
}); | ||
} | ||
} | ||
|
||
registry.category("lazy_components").add("awesome_dashboard.AwesomeDashboard", AwesomeDashboard); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
.o_dashboard { | ||
background-color: #f0f0f0; | ||
padding: 20px; | ||
|
||
.o_dashboard_items { | ||
display: flex; | ||
flex-wrap: wrap; | ||
align-items: stretch; | ||
gap: 20px; | ||
|
||
.o_dashboard_item { | ||
background-color: #fff; | ||
border: 1px solid #ccc; | ||
border-radius: 5px; | ||
padding: 10px; | ||
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<templates xml:space="preserve"> | ||
|
||
<t t-name="awesome_dashboard.AwesomeDashboard"> | ||
<Layout display="{ controlPanel: {} }" className="'o_dashboard o_awesome_dashboard h-100'"> | ||
<t t-set-slot="layout-buttons"> | ||
<div class="o_list_buttons d-flex gap-1 d-empty-none align-items-baseline" role="toolbar" aria-label="Main actions"> | ||
<button type="button" class="btn btn-primary" t-on-click="onClickCustomers"> | ||
Customers | ||
</button> | ||
<button type="button" class="btn btn-primary" t-on-click="onClickLeads"> | ||
Leads | ||
</button> | ||
</div> | ||
</t> | ||
<t t-set-slot="control-panel-additional-actions"> | ||
<button t-on-click="openConfiguration" class="btn p-0 ms-1 border-0"> | ||
<i class="fa fa-cog"></i> | ||
</button> | ||
</t> | ||
<div class="o_dashboard_items"> | ||
<t t-foreach="Object.entries(items.data)" t-as="entry" t-key="entry[0]"> | ||
<t t-set="key" t-value="entry[0]"/> | ||
<t t-set="item" t-value="entry[1]"/> | ||
<AwesomeDashboardItem t-if="item.active" size="item.size"> | ||
<t t-component="item.Component" t-props="item.props(stats)" /> | ||
</AwesomeDashboardItem> | ||
</t> | ||
</div> | ||
</Layout> | ||
</t> | ||
|
||
</templates> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** @odoo-module **/ | ||
|
||
import { Component } from "@odoo/owl"; | ||
|
||
export class AwesomeDashboardItem extends Component { | ||
static template = "awesome_dashboard.AwesomeDashboardItem"; | ||
static props = { | ||
size: { type: Number, optional: true }, | ||
slots: { type: Object }, | ||
}; | ||
static defaultProps = { size: 1 }; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.AwesomeDashboardItem"> | ||
<div class="o_dashboard_item" t-attf-style="min-width: {{ props.size * 18}}rem;"> | ||
<t t-slot="default"/> | ||
</div> | ||
</t> | ||
|
||
</templates> |
72 changes: 72 additions & 0 deletions
72
awesome_dashboard/static/src/dashboard/data/dashboard_data.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/** @odoo-module **/ | ||
|
||
import { registry } from "@web/core/registry"; | ||
import { PieChartCard } from "@awesome_dashboard/dashboard/cards/pie_chart_card"; | ||
import { NumberCard } from "@awesome_dashboard/dashboard/cards/number_card"; | ||
|
||
registry.category("awesome_dashboard").add("data", { | ||
average_quantity: { | ||
Component: NumberCard, | ||
props: (stats) => ({ | ||
title: "Average amount of t-shirt by order this month", | ||
value: stats.data.average_quantity, | ||
}), | ||
active: true, | ||
}, | ||
average_time: { | ||
Component: NumberCard, | ||
props: (stats) => ({ | ||
title: "Average time to deliver an order this month", | ||
value: stats.data.average_time, | ||
}), | ||
active: true, | ||
}, | ||
nb_cancelled_orders: { | ||
Component: NumberCard, | ||
size: 2.5, | ||
props: (stats) => ({ | ||
title: "Number of cancelled orders this month", | ||
value: stats.data.nb_cancelled_orders, | ||
}), | ||
active: true, | ||
}, | ||
nb_new_orders: { | ||
Component: NumberCard, | ||
size: 2.5, | ||
props: (stats) => ({ | ||
title: "Number of new orders this month", | ||
value: stats.data.nb_new_orders, | ||
}), | ||
active: true, | ||
}, | ||
total_amount: { | ||
Component: NumberCard, | ||
size: 2.5, | ||
props: (stats) => ({ | ||
title: "Total amount of orders this month", | ||
value: stats.data.total_amount, | ||
}), | ||
active: true, | ||
}, | ||
orders_by_size: { | ||
Component: PieChartCard, | ||
props: (stats) => ({ | ||
title: "Orders by size", | ||
chart: { | ||
data: { | ||
datasets: [ | ||
{ | ||
data: [ | ||
stats.data.orders_by_size.m, | ||
stats.data.orders_by_size.s, | ||
stats.data.orders_by_size.xl, | ||
], | ||
}, | ||
], | ||
labels: ["M", "S", "XL"], | ||
}, | ||
}, | ||
}), | ||
active: true, | ||
}, | ||
}); |
41 changes: 41 additions & 0 deletions
41
awesome_dashboard/static/src/dashboard/dialogs/dashboard_config_dailog.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** @odoo-module **/ | ||
|
||
import { Component } from "@odoo/owl"; | ||
import { Dialog } from "@web/core/dialog/dialog"; | ||
|
||
export class AwesomeDashboardConfigDialog extends Component { | ||
static template = "awesome_dashboard.AwesomeDashboardConfigDialog"; | ||
static components = { Dialog }; | ||
static props = { close: { type: Function, optional: true }, onConfirm: { type: Function, optional: true } }; | ||
static defaultProps = { | ||
close: () => {}, | ||
onConfirm: () => {}, | ||
}; | ||
|
||
setup() { | ||
if (localStorage.getItem("awesome_dashboard_config") === null) { | ||
localStorage.setItem( | ||
"awesome_dashboard_config", | ||
JSON.stringify({ | ||
average_quantity: { title: "Average Quantity", active: true }, | ||
average_time: { title: "Average Time", active: true }, | ||
nb_cancelled_orders: { title: "Cancelled Orders", active: true }, | ||
nb_new_orders: { title: "New Orders", active: true }, | ||
total_amount: { title: "Total Amount", active: true }, | ||
orders_by_size: { title: "Orders by Size", active: true }, | ||
}) | ||
); | ||
} | ||
this.configItems = JSON.parse(localStorage.getItem("awesome_dashboard_config")); | ||
} | ||
|
||
onSave() { | ||
localStorage.setItem("awesome_dashboard_config", JSON.stringify(this.configItems)); | ||
this.props.onConfirm(this.configItems); | ||
this.props.close(); | ||
} | ||
|
||
discard() { | ||
this.props.close(); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Misspelling, happens 🤷
Don't forget to rename your file too