-
Notifications
You must be signed in to change notification settings - Fork 2.7k
18.0 owl components mohmo #969
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
Mohamed-Dallash
wants to merge
20
commits into
odoo:18.0
Choose a base branch
from
odoo-dev:18.0-owl-components-mohmo
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 17 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
3d26fef
[ADD] counter: create counter component
Mohamed-Dallash 1efd503
[IMP] playground: add two counters to the playground
Mohamed-Dallash bc8df7e
[IMP] counter: update styling of counter component
Mohamed-Dallash 38f3bfb
[ADD] card: create card component
Mohamed-Dallash c032556
[IMP] card: update card component to use t-out
Mohamed-Dallash 3ef6e22
[IMP] playground: update data displayed on cards and try markup
Mohamed-Dallash af70968
[IMP] card: add props validation to card component
Mohamed-Dallash 9657d39
[IMP] counter: add onChange callback to counters
Mohamed-Dallash 6da5f5f
[IMP] playground: add a sum and increment it using the counters
Mohamed-Dallash 8161e3f
[ADD] todo_list: add todo item and todo list components
Mohamed-Dallash bc5e35d
[IMP] todo_list: add styling to completed todo items
Mohamed-Dallash ea02bb0
[IMP] todo_list: remove hard coded list and allow user to add todo items
Mohamed-Dallash fd87e8c
[IMP] todo_list: automatically focus on the todo list input when load…
Mohamed-Dallash 205a7b4
[IMP] todo_list: allow toggling of todos
Mohamed-Dallash 99d8ecf
[IMP] todo_list: low deletion of todo list items
Mohamed-Dallash 3c2782a
[IMP] card: allow generic data inside cards using slots
Mohamed-Dallash 3af4e61
[IMP] card: allow toggling of cards' content
Mohamed-Dallash 423ede6
[IMP] playground: add newlines to files that didn't have them at the…
Mohamed-Dallash 6131331
[IMP] todo_list: fix a potential bug with toggling and deleting todos
Mohamed-Dallash 8f6e5ed
[IMP] todo_list: add models for todo and use them instead of hard cod…
Mohamed-Dallash 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 |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import { Component, useState } from "@odoo/owl" | ||
|
|
||
| export class Card extends Component { | ||
| static template = "awesome_owl.card" | ||
| static props = { | ||
| title: String, | ||
| slots: Object, | ||
| } | ||
|
|
||
| setup() { | ||
| this.isOpened = useState({ value: true }); | ||
| } | ||
|
|
||
| toggle() { | ||
| this.isOpened.value = !this.isOpened.value; | ||
| } | ||
| } | ||
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 @@ | ||
| <?xml version="1.0" encoding="UTF-8" ?> | ||
| <templates xml:space="preserve"> | ||
|
|
||
| <t t-name="awesome_owl.card"> | ||
| <div class="card d-inline-block m-2" style="width: 18rem;"> | ||
| <div class="card-body"> | ||
| <h5 class="card-title"> | ||
| <t t-out="props.title"/> | ||
| <button class="btn btn-primary" t-on-click="toggle">toggle</button> | ||
| </h5> | ||
| <p class="card-text" t-if="isOpened.value"> | ||
| <t t-slot="default"/> | ||
| </p> | ||
| </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,19 @@ | ||
| import { Component, useState } from "@odoo/owl"; | ||
|
|
||
| export class Counter extends Component { | ||
| static template = "awesome_owl.counter" | ||
| static props = { | ||
| onChange: { type: Function, optional: true } | ||
| } | ||
|
|
||
| setup() { | ||
| this.state = useState({ value: 0 }); | ||
| } | ||
|
|
||
| increment() { | ||
| this.state.value++; | ||
| if (this.props.onChange) { | ||
| this.props.onChange(); | ||
| } | ||
Mohamed-Dallash marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
Mohamed-Dallash 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,11 @@ | ||
| <?xml version="1.0" encoding="UTF-8" ?> | ||
| <templates xml:space="preserve"> | ||
|
|
||
| <t t-name="awesome_owl.counter"> | ||
| <div class="m-2 p-2 border d-inline-block"> | ||
| <span class="me-2">Counter: <t t-esc="state.value"/></span> | ||
| <button class="btn btn-primary" t-on-click="increment">Increment</button> | ||
| </div> | ||
| </t> | ||
|
|
||
| </templates> | ||
Mohamed-Dallash 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 |
|---|---|---|
| @@ -1,7 +1,21 @@ | ||
| /** @odoo-module **/ | ||
|
|
||
| import { Component } from "@odoo/owl"; | ||
| import { Component, useState, markup } from "@odoo/owl"; | ||
| import { Counter } from "./counter/counter"; | ||
| import { Card } from "./card/card"; | ||
| import { TodoList } from "./todo_list/todo_list"; | ||
|
|
||
| export class Playground extends Component { | ||
| static template = "awesome_owl.playground"; | ||
| static components = { Counter, Card, TodoList }; | ||
|
|
||
| setup() { | ||
| this.normal_string = "<div class='text-primary'>some content</div>"; | ||
| this.markup_string = markup("<div class='text-primary'>some content</div>"); | ||
| this.sum = useState({ value: 2 }); | ||
| } | ||
|
|
||
| incrementSum() { | ||
| this.sum.value++; | ||
| } | ||
| } |
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,25 @@ | ||
| import { Component } from "@odoo/owl" | ||
|
|
||
| export class TodoItem extends Component { | ||
| static template = "awesome_owl.todo_item"; | ||
| static props = { | ||
| todo: { | ||
| type: Object, | ||
| shape: { | ||
Mohamed-Dallash marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| id: Number, | ||
| description: String, | ||
| isCompleted: Boolean, | ||
| }, | ||
| }, | ||
| toggleState: Function, | ||
| removeTodo: Function | ||
| } | ||
|
|
||
| toggleCheckbox() { | ||
| this.props.toggleState(this.props.todo.id); | ||
| } | ||
|
|
||
| delete() { | ||
| this.props.removeTodo(this.props.todo.id); | ||
| } | ||
| } | ||
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_owl.todo_item"> | ||
| <div t-att-class="{'text-muted text-decoration-line-through':props.todo.isCompleted}"> | ||
| <input type="checkbox" t-att-checked="props.todo.isCompleted" t-on-change="toggleCheckbox"/> | ||
| <t t-esc="props.todo.id"/>. | ||
| <t t-esc="props.todo.description"/> | ||
| <span class="fa fa-remove" t-on-click="delete"/> | ||
| </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,32 @@ | ||
| import { Component, useRef, useState, onMounted } from "@odoo/owl"; | ||
| import { TodoItem } from "./todo_item"; | ||
| import { useAutofocus } from "../utils"; | ||
|
|
||
| export class TodoList extends Component { | ||
| static template = "awesome_owl.todo_list"; | ||
| static components = { TodoItem }; | ||
|
|
||
| setup() { | ||
| this.todos = useState([]); | ||
| this.todo_idx = useState({ value: 1 }); | ||
Mohamed-Dallash marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| useAutofocus("todo_input"); | ||
| } | ||
|
|
||
| addTodo(ev) { | ||
| if (ev.keyCode !== 13 || ev.target.value == "") { | ||
| return; | ||
| } | ||
| this.todos.push({ "id": this.todo_idx.value++, "description": ev.target.value, "isCompleted": false }); | ||
Mohamed-Dallash marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ev.target.value = ""; | ||
| } | ||
|
|
||
| toggleTodo(id) { | ||
| const todo = this.todos.find((todo) => todo.id === id); | ||
| todo.isCompleted = !todo.isCompleted; | ||
| } | ||
|
|
||
| deleteTodo(id) { | ||
| const index = this.todos.findIndex((todo) => todo.id === id); | ||
| this.todos.splice(index, 1); | ||
Mohamed-Dallash 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,15 @@ | ||
| <?xml version="1.0" encoding="UTF-8" ?> | ||
| <templates xml:space="preserve"> | ||
|
|
||
| <t t-name="awesome_owl.todo_list"> | ||
| <div> | ||
| <input placeholder="Enter a new task" t-on-keyup="addTodo" t-ref="todo_input"/> | ||
| </div> | ||
| <div> | ||
| <t t-foreach="todos" t-as="todo" t-key="todo.id"> | ||
| <TodoItem todo="todo" toggleState.bind="toggleTodo" removeTodo.bind="deleteTodo"/> | ||
| </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(refName) { | ||
| const ref = useRef(refName); | ||
| onMounted(() => { | ||
| ref.el.focus(); | ||
| }) | ||
| } | ||
Mohamed-Dallash marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
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.