-
Notifications
You must be signed in to change notification settings - Fork 2.6k
HKAFE - JS Tutorial #1008
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
HashemKhaled
wants to merge
24
commits into
odoo:18.0
Choose a base branch
from
odoo-dev:18.0-js-tutorial-hkafe
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
HKAFE - JS Tutorial #1008
Changes from 19 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
6f5a7eb
[IMP] awesome_owl: add Card and Counter components
HashemKhaled 5927c86
[IMP] awesome_owl: add card props validation
HashemKhaled 55f4028
[IMP] awesome_owl: display the sum of two counters
HashemKhaled 20d5c85
[IMP] awesome_owl: add a todo list
HashemKhaled a2c679a
[FIX] awesome_owl: use dynamic attributes
HashemKhaled dd51372
[IMP] awesome_owl: add a todo from the UI
HashemKhaled 0d14be0
[IMP] awesome_owl: implement useAutofocus hook
HashemKhaled b1e3577
[IMP] awesome_owl: implement toggle functionality for todo items
HashemKhaled 32e8847
[IMP] awesome_owl: delete todos
HashemKhaled 07ae391
[IMP] awesome_owl: refactor Card component to use slots
HashemKhaled 8ac0d11
[IMP] awesome_owl: toggle card content
HashemKhaled e286ff6
[IMP] awesome_dashboard: add layout with some buttons for quick navig…
HashemKhaled 94c0020
[IMP] awesome_dashboard: add a dashboard item
HashemKhaled 22dbdb4
[IMP] awesome_dashboard: call the server for adding some statistics
HashemKhaled 4282ec3
[IMP] awesome_dashboard: implement statistics service
HashemKhaled 2dfd044
[IMP] awesome_dashboard: display a pie chart
HashemKhaled 1a863c6
[IMP] awesome_dashboard: lazy loading the dashboard
HashemKhaled 639c920
[IMP] awesome_dashboard: make the dashboard generic
HashemKhaled 939fb62
[IMP] awesome_dashboard: make the dashboard extensible
HashemKhaled b299103
[IMP] awesome_dashboard: add settings dialog for managing dashboard i…
HashemKhaled d4fa2a0
[FIX] awesome_dashboard: add missing newline at end of XML files
HashemKhaled d1884f2
[FIX] awesome_dashboard: fix default size handling in DashboardItem c…
HashemKhaled 0f622fb
[FIX] awesome_owl: correct glob pattern for static assets inclusion
HashemKhaled 281a073
[FIX] awesome_dashboard: remove redundant chart destruction in PieCha…
HashemKhaled 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.
This file was deleted.
Oops, something went wrong.
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,38 @@ | ||
| /** @odoo-module **/ | ||
|
|
||
| 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 "./dashboard_item/dashboard_item"; | ||
| import { PieChart } from "./pie_chart/pie_chart"; | ||
|
|
||
| class AwesomeDashboard extends Component { | ||
| static components = { Layout, DashboardItem, PieChart }; | ||
| static template = "awesome_dashboard.AwesomeDashboard"; | ||
|
|
||
| setup() { | ||
| this.display = { controlPanel: {} }; | ||
| this.action = useService("action"); | ||
| this.stats = useState(useService("awesome_dashboard.statistics")); | ||
| this.items = registry.category("awesome_dashboard").getAll(); | ||
| } | ||
|
|
||
| openCustomers() { | ||
| this.action.doAction("base.action_partner_form"); | ||
| } | ||
|
|
||
| openLeads() { | ||
| this.action.doAction({ | ||
| type: "ir.actions.act_window", | ||
| res_model: "crm.lead", | ||
| name: "Leads", | ||
| views: [ | ||
| [false, "list"], | ||
| [false, "form"], | ||
| ], | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| registry.category("lazy_components").add("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,14 @@ | ||
| .o_dashboard { | ||
| background-color: gray; | ||
| } | ||
|
|
||
| .btn-primary { | ||
| background-color: purple; | ||
| border-color: purple; | ||
| } | ||
|
|
||
| .divider{ | ||
| width:5px; | ||
| height:auto; | ||
| display:inline-block; | ||
| } |
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,24 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <templates xml:space="preserve"> | ||
|
|
||
| <t t-name="awesome_dashboard.AwesomeDashboard"> | ||
| <Layout display="display" className="'o_dashboard h-100'"> | ||
| <button type="button" class="btn btn-primary" t-on-click="openCustomers"> | ||
| Customers | ||
| </button> | ||
| <div class="divider"/> | ||
| <button type="button" class="btn btn-primary" t-on-click="openLeads"> | ||
| Leads | ||
| </button> | ||
| <div class="d-flex flex-wrap" t-if="stats.isLoaded"> | ||
| <t t-foreach="items" t-as="item" t-key="item.id"> | ||
| <DashboardItem size="item.size || 1"> | ||
| <t t-set="itemProp" t-value="item.props ? item.props(stats) : {'data': stats}"/> | ||
| <t t-component="item.component" t-props="itemProp"/> | ||
| </DashboardItem> | ||
| </t> | ||
| </div> | ||
| </Layout> | ||
| </t> | ||
|
|
||
| </templates> | ||
HashemKhaled marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
16 changes: 16 additions & 0 deletions
16
awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.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,16 @@ | ||
| import { Component } from "@odoo/owl"; | ||
|
|
||
| export class DashboardItem extends Component { | ||
| static template = "awesome_dashboard.DashboardItem"; | ||
| static props = { | ||
| size: { | ||
| type: Number, | ||
| default: 1, | ||
HashemKhaled marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| optional: true, | ||
| }, | ||
| slots: { | ||
| type: Object, | ||
| optional: true, | ||
| }, | ||
| }; | ||
| } | ||
11 changes: 11 additions & 0 deletions
11
awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.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.DashboardItem"> | ||
| <div class="card d-inline-block m-2" t-attf-style="width: {{18 * this.props.size}}rem;"> | ||
| <div class="card-body"> | ||
| <t t-slot="default"/> | ||
| </div> | ||
| </div> | ||
| </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,66 @@ | ||
| import { NumberCard } from "./number_card/number_card"; | ||
| import { PieChartCard } from "./pie_chart_card/pie_chart_card"; | ||
| import { registry } from "@web/core/registry"; | ||
|
|
||
| const dashboardItems = [ | ||
| { | ||
| id: "average_quantity", | ||
| description: "Average amount of t-shirt by order this month", | ||
| component: NumberCard, | ||
| props: (data) => ({ | ||
| title: "Average amount of t-shirt by order this month", | ||
| value: data.average_quantity, | ||
| }), | ||
| }, | ||
| { | ||
| id: "average_time", | ||
| description: | ||
| "Average time for an order to go from 'new' to 'sent' or 'cancelled'", | ||
| component: NumberCard, | ||
| props: (data) => ({ | ||
| title: "Average time for an order to go from 'new' to 'sent' or 'cancelled'", | ||
| value: data.average_time, | ||
| }), | ||
| }, | ||
| { | ||
| id: "nb_new_orders", | ||
| description: "Number of new orders this month", | ||
| component: NumberCard, | ||
| props: (data) => ({ | ||
| title: "Number of new orders this month", | ||
| value: data.nb_new_orders, | ||
| }), | ||
| }, | ||
| { | ||
| id: "nb_cancelled_orders", | ||
| description: "Number of cancelled orders this month", | ||
| component: NumberCard, | ||
| props: (data) => ({ | ||
| title: "Number of cancelled orders this month", | ||
| value: data.nb_cancelled_orders, | ||
| }), | ||
| }, | ||
| { | ||
| id: "total_amount", | ||
| description: "Total amount of new orders this month", | ||
| component: NumberCard, | ||
| props: (data) => ({ | ||
| title: "Total amount of new orders this month", | ||
| value: data.total_amount, | ||
| }), | ||
| }, | ||
| { | ||
| id: "orders_by_size", | ||
| description: "Shirt orders by size", | ||
| component: PieChartCard, | ||
| size: 1.5, | ||
| props: (data) => ({ | ||
| title: "Shirt orders by size", | ||
| values: data.orders_by_size, | ||
| }), | ||
| }, | ||
| ]; | ||
|
|
||
| dashboardItems.forEach((item) => { | ||
| registry.category("awesome_dashboard").add(item.id, item); | ||
| }); |
10 changes: 10 additions & 0 deletions
10
awesome_dashboard/static/src/dashboard/number_card/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,10 @@ | ||
| import { Component } from "@odoo/owl"; | ||
|
|
||
| export class NumberCard extends Component { | ||
| static template = "awesome_dashboard.NumberCard"; | ||
|
|
||
| static props = { | ||
| title: String, | ||
| value: Number, | ||
| }; | ||
| } |
10 changes: 10 additions & 0 deletions
10
awesome_dashboard/static/src/dashboard/number_card/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,10 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <templates xml:space="preserve"> | ||
|
|
||
| <t t-name="awesome_dashboard.NumberCard"> | ||
| <t t-esc="props.title"/> | ||
| <div class="fs-1 fw-bold text-success text-center"> | ||
| <t t-esc="props.value"/> | ||
| </div> | ||
| </t> | ||
| </templates> |
52 changes: 52 additions & 0 deletions
52
awesome_dashboard/static/src/dashboard/pie_chart/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,52 @@ | ||
| import { | ||
| Component, | ||
| useEffect, | ||
| useRef, | ||
| onWillUnmount, | ||
| onWillStart, | ||
| } from "@odoo/owl"; | ||
| import { loadJS } from "@web/core/assets"; | ||
| import { getColor } from "@web/core/colors/colors"; | ||
|
|
||
| export class PieChart extends Component { | ||
| static template = "awesome_dashboard.PieChart"; | ||
| static props = { | ||
| label: { type: String, optional: true }, | ||
| data: { type: Object }, | ||
| }; | ||
|
|
||
| setup() { | ||
| this.canvasRef = useRef("canvas"); | ||
| this.chart = null; | ||
|
|
||
| onWillStart(() => loadJS(["/web/static/lib/Chart/Chart.js"])); | ||
| useEffect(() => this.renderChart()); | ||
| onWillUnmount(() => { | ||
| if (this.chart) { | ||
| this.chart.destroy(); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| renderChart() { | ||
| const labels = Object.keys(this.props.data); | ||
| const values = Object.values(this.props.data); | ||
| const color = labels.map((_, idx) => getColor(idx * 2)); | ||
| if (this.chart) { | ||
| this.chart.destroy(); | ||
HashemKhaled marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| this.chart = new Chart(this.canvasRef.el, { | ||
| type: "pie", | ||
| data: { | ||
| labels: labels, | ||
| datasets: [ | ||
| { | ||
| label: this.props.label || "", | ||
| data: values, | ||
| backgroundColor: color, | ||
| }, | ||
| ], | ||
| }, | ||
| }); | ||
| } | ||
| } | ||
6 changes: 6 additions & 0 deletions
6
awesome_dashboard/static/src/dashboard/pie_chart/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 |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <templates xml:space="preserve"> | ||
| <t t-name="awesome_dashboard.PieChart"> | ||
| <canvas t-ref="canvas" /> | ||
| </t> | ||
| </templates> |
12 changes: 12 additions & 0 deletions
12
awesome_dashboard/static/src/dashboard/pie_chart_card/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,12 @@ | ||
| import { Component } from "@odoo/owl"; | ||
| import { PieChart } from "../pie_chart/pie_chart"; | ||
|
|
||
| export class PieChartCard extends Component { | ||
| static template = "awesome_dashboard.PieChartCard"; | ||
| static components = { PieChart }; | ||
|
|
||
| static props = { | ||
| title: String, | ||
| values: Object, | ||
| }; | ||
| } |
8 changes: 8 additions & 0 deletions
8
awesome_dashboard/static/src/dashboard/pie_chart_card/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,8 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <templates xml:space="preserve"> | ||
|
|
||
| <t t-name="awesome_dashboard.PieChartCard"> | ||
| <t t-esc="props.title"/> | ||
| <PieChart data="props.values" label="''"/> | ||
| </t> | ||
| </templates> |
25 changes: 25 additions & 0 deletions
25
awesome_dashboard/static/src/dashboard/statistics_service.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,25 @@ | ||
| import { registry } from "@web/core/registry"; | ||
| import { rpc } from "@web/core/network/rpc"; | ||
| import { reactive } from "@odoo/owl"; | ||
|
|
||
| const statisticsService = { | ||
| async: ["loadStatistics"], | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this line necessary for the service ? |
||
| start() { | ||
| const statistics = reactive({ isLoaded: false }); | ||
|
|
||
| async function loadStatistics() { | ||
| const result = await rpc("/awesome_dashboard/statistics"); | ||
| statistics.isLoaded = true; | ||
| Object.assign(statistics, result); | ||
| } | ||
|
|
||
| setInterval(loadStatistics, 10 * 60 * 1000); | ||
| loadStatistics(); | ||
|
|
||
| return statistics; | ||
| }, | ||
| }; | ||
|
|
||
| registry | ||
| .category("services") | ||
| .add("awesome_dashboard.statistics", statisticsService); | ||
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 @@ | ||
| import { Component, xml } from "@odoo/owl"; | ||
| import { registry } from "@web/core/registry"; | ||
| import { LazyComponent } from "@web/core/assets"; | ||
|
|
||
| export class DashboardAction extends Component { | ||
| static components = { LazyComponent }; | ||
| static template = xml`<LazyComponent bundle="'awesome_dashboard.dashboard'" Component="'AwesomeDashboard'" props="props"/>`; | ||
| } | ||
|
|
||
| registry | ||
| .category("actions") | ||
| .add("awesome_dashboard.dashboard", DashboardAction); |
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 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,24 @@ | ||
| import { Component, useState } from "@odoo/owl"; | ||
|
|
||
| export class Card extends Component { | ||
| static template = "awesome_owl.card"; | ||
| static props = { | ||
| title: { type: String }, | ||
| slots: { | ||
| type: Object, | ||
| shape: { | ||
| default: true, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| setup() { | ||
| this.state = useState({ | ||
| isOpen: true, | ||
| }); | ||
| } | ||
|
|
||
| onToggle() { | ||
| this.state.isOpen = !this.state.isOpen; | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.