-
Notifications
You must be signed in to change notification settings - Fork 2.6k
[ADD] todo: add new todo, card and counter components #972
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
Draft
macocianradu
wants to merge
21
commits into
odoo:18.0
Choose a base branch
from
odoo-dev:18.0-tutorial-admac-js
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.
Draft
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
8242913
[ADD] todo: add new todo, card and counter components
macocianradu b57ecf4
[IMP] todo: Focusing the input
macocianradu 2d3beff
[IMP] todo: deleting todos
macocianradu 0c74508
[IMP] awesome_owl: generic card with slots
macocianradu 9cc166e
[IMP] awesome_owl: minimizing card content
macocianradu 8ae5640
[IMP] awesome_dashboard: add some buttons for quick navigation
macocianradu 3c99f45
[IMP] awesome_dashboard: add a dashboard item
macocianradu 2726b2e
[IMP] awesome_dashboard: call the server, add some statistics
macocianradu 0134803
[IMP] awesome_dashboard: cache network calls, create a service
macocianradu 4346a21
[IMP] awesome_dashboard: display a pie chart
macocianradu a5fa22a
[IMP] awesome_dashboard: real life update
macocianradu abddaa5
[IMP] awesome_dashboard: lazy loading the dashboard
macocianradu 3416192
[IMP] awesome_dashboard: making the dashboard extensible
macocianradu 6e53f4b
[IMP] awesome_dashboard: make the dashboard extensible
macocianradu 0df9683
[IMP] awesome_dashboard: add and remove dashboard items
macocianradu 9842f55
[IMP] awesome_dashboard: add translations to text
macocianradu bce86ab
[FIX] awesome_dashboard: run prettier
macocianradu 9a06420
[IMP] awesome_dashboard: opening orders on chart click
macocianradu abe7d49
[IMP] awesome_dashboard: make cards reactive on mobile
macocianradu df6646a
[IMP] awesome_dashboard: saving dashboard in config_properties
macocianradu f81a9cd
[IMP] awesome_dashboard: adding a controller action for user settings
macocianradu 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
Some comments aren't visible on the classic Files Changed page.
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.
41 changes: 41 additions & 0 deletions
41
awesome_dashboard/static/src/dashboard/configuration_dialog.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 @@ | ||
import { useService } from "@web/core/utils/hooks"; | ||
import { Component } from "@odoo/owl"; | ||
import { Dialog } from "@web/core/dialog/dialog"; | ||
import { CheckBox } from "@web/core/checkbox/checkbox"; | ||
import { session } from "@web/session"; | ||
import { rpc } from "@web/core/network/rpc"; | ||
|
||
export class ConfigurationDialog extends Component { | ||
static template = "awesome_dashboard.ConfigurationDialog"; | ||
static components = { Dialog, CheckBox }; | ||
static props = { | ||
items: Array, | ||
close: {}, | ||
onApply: Function, | ||
}; | ||
|
||
setup() { | ||
this.orm = useService("orm"); | ||
this.userId = session.storeData['res.partner'][1].userId; | ||
this.disabledElements = this.props.items | ||
.filter((item) => !item.enabled) | ||
.map((item) => item.element.id); | ||
} | ||
|
||
onChange(id) { | ||
let index = this.disabledElements.indexOf(id); | ||
if (index === -1) { | ||
this.disabledElements.push(id); | ||
return; | ||
} | ||
this.disabledElements.splice(index, 1); | ||
} | ||
|
||
async apply() { | ||
await rpc("/awesome_dashboard/set_config/" + this.userId, { | ||
config: JSON.stringify(this.disabledElements) | ||
}) | ||
this.props.onApply(); | ||
this.props.close(); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
awesome_dashboard/static/src/dashboard/configuration_dialog.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,22 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<templates xml:space="perserve"> | ||
<t t-name="awesome_dashboard.ConfigurationDialog"> | ||
<Dialog title="'Dashboard configuration dialog'"> | ||
<div class="d-flex flex-column"> | ||
<t t-foreach="props.items" t-as="item" t-key="item.element.id"> | ||
<div class="d-inline-flex gap-2"> | ||
<p><t t-esc="item.element.description" /></p> | ||
<CheckBox | ||
value="item.enabled" | ||
t-on-change="(_) => this.onChange(item.element.id)" /> | ||
</div> | ||
</t> | ||
</div> | ||
<t t-set-slot="footer"> | ||
<button class="btn btn-primary" t-on-click="apply" > | ||
Apply | ||
</button> | ||
</t> | ||
</Dialog> | ||
</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,71 @@ | ||
/** @odoo-module **/ | ||
|
||
import { _t } from "@web/core/l10n/translation"; | ||
import { Component, useState, onWillStart } 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"; | ||
import { PieChart } from "./pie_chart/pie_chart"; | ||
import { ConfigurationDialog } from "./configuration_dialog"; | ||
import { rpc } from "@web/core/network/rpc"; | ||
import { session } from "@web/session"; | ||
|
||
class AwesomeDashboard extends Component { | ||
static template = "awesome_dashboard.AwesomeDashboard"; | ||
static components = { Layout, DashboardItem, PieChart }; | ||
|
||
setup() { | ||
this.action = useService("action"); | ||
this.orm = useService("orm"); | ||
this.userId = session.storeData['res.partner'][1].userId; | ||
this.statistics = useService("awesome_dashboard.statistics"); | ||
this.state = useState({ items: [], stats: this.statistics }); | ||
this.dialog = useService("dialog"); | ||
|
||
onWillStart(async () => { | ||
await this.updateDashboard() | ||
}) | ||
} | ||
|
||
async updateDashboard() { | ||
const config = JSON.parse( | ||
await rpc("/awesome_dashboard/get_config/" + this.userId)) | ||
const disabledElements = config || [] | ||
this.state.items = registry | ||
.category("awesome_dashboard") | ||
.getAll() | ||
.filter((el) => !disabledElements.some((e) => e == el.id)); | ||
} | ||
|
||
openCustomers() { | ||
this.action.doAction("base.action_partner_form"); | ||
} | ||
|
||
openLeads() { | ||
this.action.doAction({ | ||
type: "ir.actions.act_window", | ||
name: _t("Leads"), | ||
res_model: "crm.lead", | ||
views: [ | ||
[false, "list"], | ||
[false, "form"], | ||
], | ||
}); | ||
} | ||
|
||
customizeDashboard() { | ||
const all_dashboard_items = registry.category("awesome_dashboard").getAll(); | ||
|
||
this.dialog.add(ConfigurationDialog, { | ||
items: all_dashboard_items.map(item => ({ | ||
element: item, | ||
enabled: this.state.items.some((element) => item.id == element.id) | ||
})) | ||
, | ||
onApply: this.updateDashboard.bind(this), | ||
}); | ||
} | ||
} | ||
|
||
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,27 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<templates xml:space="preserve"> | ||
|
||
<t t-name="awesome_dashboard.AwesomeDashboard"> | ||
<Layout display="{ controlPanel: {} }" className="'o_dashboard h-100 overflow-scroll'"> | ||
<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> | ||
<button class="btn" t-on-click="customizeDashboard"> | ||
<span class="fa fa-gear" /> | ||
</button> | ||
</t> | ||
<div class="d-flex p-0 p-md-4 flex-wrap "> | ||
<t t-foreach="state.items" t-as="item" t-key="item.id"> | ||
<DashboardItem size="item.size || 1"> | ||
<t t-set="itemProp" t-value="item.props | ||
? item.props(state.stats) | ||
: {'data': state.stats}" | ||
/> | ||
<t t-component="item.Component" t-props="itemProp" /> | ||
</DashboardItem> | ||
</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,14 @@ | ||
import { Component } from "@odoo/owl"; | ||
|
||
export class DashboardItem extends Component { | ||
static template = "awesome_dashboard.DashboardItem"; | ||
|
||
static props = { | ||
size: { type: Number, optional: true }, | ||
slots: {}, | ||
}; | ||
|
||
static defaultProps = { | ||
size: 1 | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
awesome_dashboard/static/src/dashboard/dashboard_item.scss
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 @@ | ||
h1 { | ||
color: green; | ||
} | ||
|
||
.card { | ||
width: 100%; | ||
|
||
@media (min-width: 758px) { | ||
width: var(--desktop-card-width); | ||
} | ||
} |
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.DashboardItem"> | ||
<div | ||
class="card m-0 m-md-2" | ||
t-attf-style="--desktop-card-width:{{18 * props.size}}rem;"> | ||
<div class="card-body"> | ||
<t t-slot="default"> | ||
</t> | ||
</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,73 @@ | ||
import { NumberCard } from "./number_card"; | ||
import { registry } from "@web/core/registry"; | ||
import { PieChartCard } from "./pie_chart_card"; | ||
import { _t } from "@web/core/l10n/translation"; | ||
|
||
const items = [ | ||
{ | ||
id: "average_quantity", | ||
description: _t("Average amount of t-shirt"), | ||
Component: NumberCard, | ||
size: 1, | ||
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 orders"), | ||
Component: NumberCard, | ||
size: 1, | ||
props: (data) => ({ | ||
title: _t( | ||
"Average time for an order to go from 'new' to 'sent' or 'cancelled'", | ||
), | ||
value: data.average_time, | ||
}), | ||
}, | ||
{ | ||
id: "nb_new_orders", | ||
description: _t("Number of new orders"), | ||
Component: NumberCard, | ||
size: 1, | ||
props: (data) => ({ | ||
title: _t("Number of new orders this month"), | ||
value: data.nb_new_orders, | ||
}), | ||
}, | ||
{ | ||
id: "nb_cancelled_orders", | ||
description: _t("Number of cancelled orders"), | ||
Component: NumberCard, | ||
size: 1, | ||
props: (data) => ({ | ||
title: _t("Number of cancelled orders this month"), | ||
value: data.nb_cancelled_orders, | ||
}), | ||
}, | ||
{ | ||
id: "total_amount", | ||
description: _t("Total amount of new orders"), | ||
Component: NumberCard, | ||
size: 1, | ||
props: (data) => ({ | ||
title: _t("Total amount of new orders this month"), | ||
value: data.total_amount, | ||
}), | ||
}, | ||
{ | ||
id: "orders_by_size", | ||
description: _t("Shirt orders by size"), | ||
Component: PieChartCard, | ||
size: 2, | ||
props: (data) => ({ | ||
title: _t("Shirt orders by size"), | ||
value: data.orders_by_size, | ||
}), | ||
}, | ||
]; | ||
|
||
for (let item of items) { | ||
registry.category("awesome_dashboard").add(item.id, item); | ||
} |
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"; | ||
|
||
export class NumberCard extends Component { | ||
static template = xml` | ||
<p><t t-esc="props.title" /></p> | ||
<h1><b><t t-esc="props.value" /></b></h1> | ||
`; | ||
static props = { | ||
title: String, | ||
value: [String, Number], | ||
}; | ||
} |
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.
What your function does is:
Thus, this if condition is actually half of your functionality. But when you return inside the block it looks like it's a corner case and for most records what will execute is
this.disabledElements.splice(index, 1);
which is not true.In this case I would prefer to have
so what your method does is clearer.
This is of course up for debate. What do you think?
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.
I guess it's a matter of preference.
I usually prefer to do early returns instead of else statements, so that if the function gets more complicated, I don't need to nest so much.
In this case it's probably the same.