-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Technical onboarding - Discover the web framework - FLMAL #965
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
fmalfroid
wants to merge
28
commits into
odoo:18.0
Choose a base branch
from
odoo-dev:18.0-web-framework-tutorial-flmal
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 22 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
e99d693
[IMP] awesome_owl: Technical onboarding, chapter 1, step 1 to 5
fmalfroid a5aa410
[IMP] awesome_owl: Discover the web framework step 6: The sum of two …
fmalfroid cdc5670
[IMP] awesome_owl: Discover the web framework step 7: A todo list
fmalfroid 045c2fd
[IMP] awesome_owl: Discover the web framework step 8: Use dynamic att…
fmalfroid 103de17
[IMP] awesome_owl: Discover the web framework step 9: Adding a todo
fmalfroid 9b751cc
[IMP] awesome_owl: Discover the web framework step 10: Focusing the i…
fmalfroid a1b31a0
[IMP] awesome_owl: Discover the web framework step 11: Toggling todos
fmalfroid 295aaf0
[IMP] awesome_owl: Discover the web framework step 12: Deleting todos
fmalfroid 6866ff9
[IMP] awesome_owl: Discover teh web framework step 13: Generic Card w…
fmalfroid 1bf3b4a
[IMP] awesome_owl: Discover the web framework Chapter 1: Owl components
fmalfroid d8c3e56
[IMP] awesome_dashboard: Discover the web framework, Chapter 2, Step …
fmalfroid 0cc3c1d
[IMP] awesome_dashboard: Discover the web framework, Chapter 2, step …
fmalfroid 17662bf
[IMP] awesome_dashboard: Discover the web framework, Chapter 2, Step …
fmalfroid d2432e2
[IMP] awesome_dashboard: Discover the web framework, Chapter 2, Step …
fmalfroid fb73735
[IMP] awesome_dashboard: Discover the web framework, Chapter 2, Step …
fmalfroid 15347e5
[IMP] awesome_dashboard: Discover the web framework, Chapter 2, Step …
fmalfroid cd512a5
[IMP] awesome_dashboard: Discover the web framework, Chapter 2, Step …
fmalfroid 096972b
[IMP] awesome_dashboard: Discover the web framework, Chapter 2, Step …
fmalfroid 46a5eca
[IMP] awesome_dashboard: Discover the web framework, Chapter 2, step …
fmalfroid 15df7b2
[IMP] awesome_dashboard: Discover the web framework, Chapter 2, step …
fmalfroid 58fffbe
[IMP] awesome_dashboard: Discover the web framework, Chapter 2, Step …
fmalfroid 346aea5
[IMP] awesome_dashboard: Discover the web framework, Chapter 2, Step …
fmalfroid a3d43b7
[IMP] awesome_dashboard: Discover the web framework, Chapter 2, list …
fmalfroid 7cb706e
[IMP] awesome_owl: modifications based on review comments
fmalfroid bea33c7
[IMP] awesome_owl: changed useAutoFocus to use onMounted instead of u…
fmalfroid 8344dc3
[IMP] awesome_dashboard: Cards are 100% of the width on mobile
fmalfroid d1d1bac
[IMP] awesome_dashboard: scrollable dashboard
fmalfroid 6ad8344
[IMP] awesome_clicker: Built a clicker game for Matser the web framew…
fmalfroid 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,56 @@ | ||
| /** @odoo-module **/ | ||
|
|
||
| import { _t } from "@web/core/l10n/translation"; | ||
| import { Component, useState } from "@odoo/owl"; | ||
| import { registry } from "@web/core/registry"; | ||
| import { useService } from "@web/core/utils/hooks"; | ||
| import { Layout } from "@web/search/layout"; | ||
| import { DashboardItem } from "./dashboard_item/dashboard_item"; | ||
| import { PieChart } from "./dashboard_pie_chart/dashboard_pie_chart"; | ||
| import { DashboardConfig } from "./dashboard_config/dashboard_config"; | ||
|
|
||
| class AwesomeDashboard extends Component { | ||
| static template = "awesome_dashboard.AwesomeDashboard"; | ||
| static components = { Layout, DashboardItem, PieChart }; | ||
| static props = ['*']; | ||
|
|
||
| setup() { | ||
| this.action = useService("action"); | ||
| this.title = _t("Awesome Dashboard"); | ||
| this.statistics = useState(useService("awesome_dashboard.statistics")); | ||
| this.items = registry.category("awesome_dashboard.items").getAll(); | ||
| this.dialog = useService("dialog"); | ||
| this.state = useState({ | ||
| disabledItems: localStorage.getItem("disabledItems") ? localStorage.getItem("disabledItems").split(",") : [] | ||
| }); | ||
| } | ||
|
|
||
| openCustomers = () => { | ||
| this.action.doAction("base.action_partner_form"); | ||
| } | ||
|
|
||
| openLeads = () => { | ||
| this.action.doAction({ | ||
| type: 'ir.actions.act_window', | ||
| name: 'Leads', | ||
| res_model: 'crm.lead', | ||
| views: [[false, 'list'], [false, 'form']], | ||
| target: 'current', | ||
| }) | ||
| } | ||
|
|
||
| openDashboardConfig = () => { | ||
| this.dialog.add(DashboardConfig, { | ||
| items: this.items, | ||
| applyFunction: this.onApplyConfiguration.bind(this), | ||
| disabledItems: this.state.disabledItems | ||
| }); | ||
| } | ||
|
|
||
| onApplyConfiguration = (ids) => { | ||
| this.state.disabledItems = ids; | ||
| localStorage.setItem("disabledItems", ids); | ||
| } | ||
| } | ||
|
|
||
| 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,3 @@ | ||
| .o_dashboard { | ||
| background-color: gray; | ||
| } |
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,26 @@ | ||
| <?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="layout-buttons"> | ||
| <button class="btn btn-primary" t-on-click="() => openCustomers()">Customers</button> | ||
| <button class="btn btn-primary" t-on-click="() => openLeads()">Leads</button> | ||
| </t> | ||
| <t t-set-slot="control-panel-additional-actions"> | ||
| <i class="fa fa-cog align-self-center cursor-pointer" t-on-click="() => openDashboardConfig()"/> | ||
| </t> | ||
| <t t-set-slot="default"> | ||
| <div class="d-flex flex-wrap"> | ||
| <t t-foreach="items" t-as="item" t-key="item.id"> | ||
| <DashboardItem size="item.size || 1" t-if="!state.disabledItems.includes(item.id)"> | ||
| <t t-set="itemProp" t-value="item.props ? item.props(statistics) : {'data': statistics}"/> | ||
| <t t-component="item.Component" t-props="itemProp" /> | ||
| </DashboardItem> | ||
| </t> | ||
| </div> | ||
| </t> | ||
| </Layout> | ||
| </t> | ||
|
|
||
| </templates> |
33 changes: 33 additions & 0 deletions
33
awesome_dashboard/static/src/dashboard/dashboard_config/dashboard_config.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,33 @@ | ||
| import { Component } from "@odoo/owl"; | ||
| import { Dialog } from "@web/core/dialog/dialog"; | ||
|
|
||
| export class DashboardConfig extends Component { | ||
| static template = "awesome_dashboard.DashboardConfig"; | ||
| static components = { Dialog }; | ||
| static props = { | ||
| items: Object, | ||
| applyFunction: Function, | ||
| disabledItems: Array, | ||
| close: Function | ||
| } | ||
|
|
||
| setup() { | ||
| this.disabledItems = this.props.disabledItems.slice(); | ||
|
|
||
| this.onChange = (ev, item_id) => { | ||
| if (ev.target.checked) { | ||
| const index = this.disabledItems.indexOf(item_id); | ||
| if (index >= 0) { | ||
| this.disabledItems.splice(index, 1); | ||
| } | ||
| } else { | ||
| this.disabledItems.push(item_id); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| onApply() { | ||
| this.props.applyFunction(this.disabledItems); | ||
| this.props.close(); | ||
| } | ||
| } |
21 changes: 21 additions & 0 deletions
21
awesome_dashboard/static/src/dashboard/dashboard_config/dashboard_config.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,21 @@ | ||
| <?xml version="1.0" encoding="UTF-8" ?> | ||
| <templates xml:space="preserve"> | ||
|
|
||
| <t t-name="awesome_dashboard.DashboardConfig"> | ||
| <Dialog size="'md'" title.translate="Dashboard items configuration" modalRef="modalRef"> | ||
| <div> | ||
| <p>Which cards do you wish to see ?</p> | ||
| <t t-foreach="props.items" t-as="item" t-key="item.id"> | ||
| <div class="form-check"> | ||
| <input type="checkbox" class="form-check-input" t-att-id="item.id" t-att-checked="!props.disabledItems.includes(item.id)" t-on-change="(ev) => {this.onChange(ev, item.id)}"/> | ||
| <t t-esc="item.description"/> | ||
| </div> | ||
| </t> | ||
| </div> | ||
| <t t-set-slot="footer"> | ||
| <button class="btn btn-primary" t-on-click="onApply">Apply</button> | ||
| </t> | ||
| </Dialog> | ||
| </t> | ||
|
|
||
| </templates> |
9 changes: 9 additions & 0 deletions
9
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,9 @@ | ||
| import { Component } from "@odoo/owl"; | ||
|
|
||
| export class DashboardItem extends Component { | ||
| static template = "awesome_dashboard.DashboardItem"; | ||
| static props = { | ||
| size: {type: Number, optional: true}, | ||
| slots: {type: Object, optional: true} | ||
| } | ||
| } |
10 changes: 10 additions & 0 deletions
10
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,10 @@ | ||
| <?xml version="1.0" encoding="UTF-8" ?> | ||
| <templates xml:space="preserve"> | ||
|
|
||
| <t t-name="awesome_dashboard.DashboardItem"> | ||
| <div class="card m-2 d-inline-block" t-att-style="'width: ' + (18 * (props.size || 1)) + 'rem;'"> | ||
fmalfroid marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <t t-slot="default"/> | ||
| </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 { _t } from "@web/core/l10n/translation"; | ||
| import { registry } from "@web/core/registry"; | ||
| import { NumberCard } from "./number_card/number_card"; | ||
| import { PieChartCard } from "./pie_chart_card/pie_chart_card"; | ||
|
|
||
| const items = [ | ||
| { | ||
| id: "average_quantity", | ||
| description: _t("Average amount of t-shirt"), | ||
| Component: NumberCard, | ||
| props: (data) => ({ | ||
| title: _t("Average amount of t-shirt by order this month"), | ||
| value: data.average_quantity, | ||
| }) | ||
| }, | ||
| { | ||
| id: "average_time", | ||
| description: _t("Average time for an order"), | ||
| Component: NumberCard, | ||
| props: (data) => ({ | ||
| title: _t("Average time for an order to go from 'new' to 'sent' or 'cancelled'"), | ||
| value: data.average_time, | ||
| }) | ||
| }, | ||
| { | ||
| id: "number_new_orders", | ||
| description: _t("New orders this month"), | ||
| Component: NumberCard, | ||
| props: (data) => ({ | ||
| title: _t("Number of new orders this month"), | ||
| value: data.nb_new_orders, | ||
| }) | ||
| }, | ||
| { | ||
| id: "cancelled_orders", | ||
| description: _t("Cancelled orders this month"), | ||
| Component: NumberCard, | ||
| props: (data) => ({ | ||
| title: _t("Number of cancelled orders this month"), | ||
| value: data.nb_cancelled_orders, | ||
| }) | ||
| }, | ||
| { | ||
| id: "amount_new_orders", | ||
| description: _t("Amount orders this month"), | ||
| Component: NumberCard, | ||
| props: (data) => ({ | ||
| title: _t("Total amount of new orders this month"), | ||
| value: data.total_amount, | ||
| }) | ||
| }, | ||
| { | ||
| id: "pie_chart", | ||
| description: _t("Shirt orders by size"), | ||
| Component: PieChartCard, | ||
| size: 2, | ||
| props: (data) => ({ | ||
| title: _t("Shirt orders by size"), | ||
| value: data.orders_by_size, | ||
| }) | ||
| } | ||
| ] | ||
|
|
||
| items.forEach(item => { | ||
| registry.category("awesome_dashboard.items").add(item.id, item); | ||
| }); |
46 changes: 46 additions & 0 deletions
46
awesome_dashboard/static/src/dashboard/dashboard_pie_chart/dashboard_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,46 @@ | ||
| import { Component, onWillStart, useEffect, onWillUnmount, useRef } from "@odoo/owl"; | ||
| import { loadJS } from "@web/core/assets"; | ||
|
|
||
| export class PieChart extends Component { | ||
| static template = "awesome_dashboard.PieChart"; | ||
| static props = { | ||
| data: Object, | ||
| }; | ||
|
|
||
| setup() { | ||
| this.canvasRef = useRef('canvas'); | ||
| onWillStart(() => loadJS("/web/static/lib/Chart/Chart.js")); | ||
| useEffect(() => this.renderChart()); | ||
| onWillUnmount(() => { | ||
| if (this.chart) { | ||
| this.chart.destroy(); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Creates and binds the chart on `canvasRef`. | ||
| */ | ||
| renderChart() { | ||
| if (this.chart) { | ||
| this.chart.destroy(); | ||
| } | ||
| const ctx = this.canvasRef.el.getContext('2d'); | ||
| this.chart = new Chart(ctx, this.getChartConfig()); | ||
| } | ||
|
|
||
| /** | ||
| * @returns {object} Chart config for the current data | ||
| */ | ||
| getChartConfig() { | ||
| return { | ||
| type: 'pie', | ||
| data: { | ||
| labels: Object.keys(this.props.data), | ||
| datasets: [{ | ||
| data: Object.values(this.props.data) | ||
| }] | ||
| } | ||
| }; | ||
| } | ||
| } |
8 changes: 8 additions & 0 deletions
8
awesome_dashboard/static/src/dashboard/dashboard_pie_chart/dashboard_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,8 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <odoo> | ||
| <t t-name="awesome_dashboard.PieChart"> | ||
| <div class="o_pie_chart"> | ||
| <canvas t-ref="canvas"/> | ||
| </div> | ||
| </t> | ||
| </odoo> |
20 changes: 20 additions & 0 deletions
20
awesome_dashboard/static/src/dashboard/dashboard_statistics/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,20 @@ | ||
| import { reactive } from "@odoo/owl"; | ||
| import { registry } from "@web/core/registry"; | ||
| import { rpc } from "@web/core/network/rpc"; | ||
|
|
||
| const dashboardStatisticsService = { | ||
| start(env) { | ||
| const statistics = reactive({}); | ||
|
|
||
| async function loadData() { | ||
| Object.assign(statistics, await rpc("/awesome_dashboard/statistics")); | ||
| } | ||
|
|
||
| setInterval(loadData, 10 * 60 * 1000); | ||
| loadData(); | ||
|
|
||
| return statistics | ||
| }, | ||
| }; | ||
|
|
||
| registry.category("services").add("awesome_dashboard.statistics", dashboardStatisticsService); |
9 changes: 9 additions & 0 deletions
9
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,9 @@ | ||
| import { Component } from "@odoo/owl"; | ||
|
|
||
| export class NumberCard extends Component { | ||
| static template = "awesome_dashboard.NumberCard"; | ||
| static props = { | ||
| title: String, | ||
| value: Number | ||
| } | ||
| } |
13 changes: 13 additions & 0 deletions
13
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,13 @@ | ||
| <?xml version="1.0" encoding="UTF-8" ?> | ||
| <templates xml:space="preserve"> | ||
|
|
||
| <t t-name="awesome_dashboard.NumberCard"> | ||
| <div class="card-header"> | ||
| <h6 t-esc="props.title"></h6> | ||
| </div> | ||
| <div class="card-body d-flex align-items-center justify-content-center"> | ||
| <h1 class="text-success" t-esc="props.value || 0"></h1> | ||
fmalfroid marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </div> | ||
| </t> | ||
|
|
||
| </templates> | ||
11 changes: 11 additions & 0 deletions
11
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,11 @@ | ||
| import { Component } from "@odoo/owl"; | ||
| import { PieChart } from "../dashboard_pie_chart/dashboard_pie_chart"; | ||
|
|
||
| export class PieChartCard extends Component { | ||
| static template = "awesome_dashboard.PieChartCard"; | ||
| static components = { PieChart }; | ||
| static props = { | ||
| title: String, | ||
| value: Object | ||
| }; | ||
| } |
13 changes: 13 additions & 0 deletions
13
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,13 @@ | ||
| <?xml version="1.0" encoding="UTF-8" ?> | ||
| <templates xml:space="preserve"> | ||
|
|
||
| <t t-name="awesome_dashboard.PieChartCard"> | ||
| <div class="card-header"> | ||
| <h6 t-esc="props.title"></h6> | ||
| </div> | ||
| <div class="card-body d-flex align-items-center justify-content-center"> | ||
| <PieChart data="props.value || {}"/> | ||
fmalfroid marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </div> | ||
| </t> | ||
|
|
||
| </templates> | ||
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.