-
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 6 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,31 @@ | ||
/** @odoo-module **/ | ||
|
||
import { _t } from "@web/core/l10n/translation"; | ||
import { Component } from "@odoo/owl"; | ||
import { registry } from "@web/core/registry"; | ||
import { Layout } from "@web/search/layout"; | ||
import { useService } from "@web/core/utils/hooks"; | ||
|
||
class AwesomeDashboard extends Component { | ||
static template = "awesome_dashboard.AwesomeDashboard"; | ||
static components = { Layout }; | ||
|
||
setup() { | ||
this.action = useService("action"); | ||
} | ||
|
||
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']] | ||
}) | ||
} | ||
} | ||
|
||
registry.category("actions").add("awesome_dashboard.dashboard", 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
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,15 @@ | ||
import { Component, useState } from "@odoo/owl"; | ||
|
||
export class Card extends Component { | ||
static template = "awesome_owl.card"; | ||
|
||
static props = ['title', 'slots'] | ||
|
||
setup() { | ||
this.state = useState({ hidden: false }) | ||
} | ||
|
||
hide() { | ||
this.state.hidden = !this.state.hidden | ||
} | ||
} |
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 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<templates xml:space="preserve"> | ||
|
||
<t t-name="awesome_owl.card"> | ||
<div class="card m-2"> | ||
<div class="card-body"> | ||
<h5 class="card-title d-inline-flex justify-content-between w-100"> | ||
<t t-esc="props.title"/> | ||
<span class="fa fa-remove" t-on-click="hide"/> | ||
</h5> | ||
<t t-slot="default" t-if="!this.state.hidden"> | ||
</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,21 @@ | ||
import { Component, useState } from "@odoo/owl"; | ||
|
||
export class Counter extends Component { | ||
static template = "awesome_owl.counter"; | ||
static props = { | ||
onChange: { | ||
type: Function, | ||
optional: true} | ||
macocianradu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
|
||
setup() { | ||
this.state = useState({ value: 1 }) | ||
} | ||
|
||
increment() { | ||
this.state.value++; | ||
if(this.props.onChange){ | ||
this.props.onChange(); | ||
} | ||
} | ||
} |
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_owl.counter"> | ||
<div class="d-inline-flex m-2 p-2 border border-2 border-dark"> | ||
<p>Counter: <t t-esc="state.value"/></p> | ||
<button class="btn btn-primary" t-on-click="increment">Increment</button> | ||
</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 |
---|---|---|
@@ -1,7 +1,27 @@ | ||
/** @odoo-module **/ | ||
|
||
import { Component } from "@odoo/owl"; | ||
import { Component, markup, useState } from "@odoo/owl"; | ||
import { Counter } from "./counter/counter"; | ||
import { Card } from "./card/card"; | ||
import { TodoList } from "./todo/todo_list"; | ||
|
||
export class Playground extends Component { | ||
static template = "awesome_owl.playground"; | ||
static components = { TodoList, Counter, Card } | ||
|
||
setup() { | ||
this.state = useState({sum: 2}) | ||
} | ||
|
||
incrementSum() { | ||
console.log('call') | ||
macocianradu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
this.state.sum++ | ||
} | ||
|
||
card_body = markup(` | ||
<span class="text-secondary"> | ||
content of card <b>2</b> | ||
</span> | ||
`); | ||
} | ||
|
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
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. Nice 🥇 |
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 @@ | ||
export class Todo { | ||
id | ||
description | ||
isCompleted | ||
constructor(id, description, isCompleted) { | ||
this.id = id | ||
this.description = description; | ||
this.isCompleted = isCompleted; | ||
} | ||
} |
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,18 @@ | ||
import { Component } from "@odoo/owl"; | ||
import { Todo } from "./todo"; | ||
import { Card } from "../card/card"; | ||
|
||
export class TodoItem extends Component { | ||
static template = "awesome_owl.todo_item"; | ||
static components = { Card }; | ||
|
||
static props = { todo: { type: Todo }, onRemove: { type: Function } } | ||
macocianradu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
toggle() { | ||
this.props.todo.isCompleted = !this.props.todo.isCompleted; | ||
} | ||
|
||
remove() { | ||
this.props.onRemove(this.props.todo.id) | ||
macocianradu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
} |
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 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<templates xml:space="preserve"> | ||
|
||
<t t-name="awesome_owl.todo_item"> | ||
<div class="d-inline-flex" t-on-click="toggle"> | ||
<p | ||
class="me-4" | ||
t-esc="this.props.todo.description" | ||
t-att-class="{'text-muted text-decoration-line-through': this.props.todo.isCompleted}" /> | ||
<t t-if="this.props.todo.isCompleted" class="mx-2"> | ||
✅ | ||
</t> | ||
<t t-if="!this.props.todo.isCompleted" class="mx-2"> | ||
🔄 | ||
</t> | ||
<span class="fa fa-remove mx-4" t-on-click="remove"/> | ||
</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,31 @@ | ||
import { Component, useState } from "@odoo/owl"; | ||
import { TodoItem } from "./todo_item"; | ||
import { Todo } from "./todo"; | ||
import { Card } from "../card/card"; | ||
import { useAutofocus } from "../utils"; | ||
|
||
export class TodoList extends Component { | ||
static template = "awesome_owl.todo_list"; | ||
static components = { Card, TodoItem }; | ||
|
||
ids = 0 | ||
macocianradu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
setup() { | ||
this.state = useState({ todos: [], input: '' }) | ||
macocianradu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
useAutofocus('todo_input') | ||
} | ||
|
||
keyup(event) { | ||
if (event.keyCode === 13) { | ||
this.state.todos.push(new Todo(this.ids++, event.srcElement.value, false)) | ||
macocianradu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
remove(id) { | ||
const index = this.state.todos.findIndex((elem) => elem.id === id) | ||
if (index >= 0) { | ||
this.state.todos.splice(index, 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,12 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<templates xml:space="preserve"> | ||
<t t-name="awesome_owl.todo_list"> | ||
<div class="d-flex flex-column card p-2 w-25"> | ||
<h5> Todos </h5> | ||
<input type="text" t-on-keyup="keyup" t-ref="todo_input" /> | ||
<t t-foreach="this.state.todos" t-as="todo" t-key="todo.id"> | ||
<TodoItem todo="todo" onRemove.bind="remove" /> | ||
</t> | ||
</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,8 @@ | ||
import { useRef, onMounted } from "@odoo/owl" | ||
|
||
export function useAutofocus(name) { | ||
let ref = useRef(name) | ||
onMounted(() => { | ||
ref.el.focus() | ||
}) | ||
} |
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.