Skip to content

Commit b633817

Browse files
committed
[IMP] awesome_owl: add todo list
add todo list in awesome_owl
1 parent e06e590 commit b633817

File tree

9 files changed

+81
-10
lines changed

9 files changed

+81
-10
lines changed

awesome_owl/static/src/card/card.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Component } from "@odoo/owl";
22

3+
34
export class Card extends Component {
45
static template = "awesome_owl.Card";
56
static props = {

awesome_owl/static/src/counter/counter.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Component, useState } from "@odoo/owl";
22

3+
34
export class Counter extends Component {
45
static template = "awesome_owl.Counter";
56

@@ -16,7 +17,14 @@ export class Counter extends Component {
1617
increment() {
1718
this.state.value++;
1819
if (this.props.onChange) {
19-
this.props.onChange(this.state.value);
20+
this.props.onChange(this.state.value,true);
21+
}
22+
}
23+
24+
decrement() {
25+
this.state.value--;
26+
if (this.props.onChange) {
27+
this.props.onChange(this.state.value,false);
2028
}
2129
}
2230
}
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
22
<templates xml:space="preserve">
33
<t t-name="awesome_owl.Counter">
4-
<div style="border: 3px solid #ccc; display: inline-block; min-width: 300px; padding: 20px; margin: 20px">
4+
<div style="background-color: #FFFFE0; border: 3px solid #ccc; display: inline-block; min-width: 300px; padding: 20px; margin: 20px">
55
<p>Counter: <t t-esc="state.value"/></p>
66
<button style="background: purple; color: white; padding: 8px; border-radius: 5px; border: 0;" class="btn btn-primary" t-on-click="increment">
77
Increment
88
</button>
9+
<button style="background: purple; color: white; padding: 8px; border-radius: 5px; border: 0; margin:5px" class="btn btn-primary" t-on-click="decrement">
10+
Decrement
11+
</button>
912
</div>
1013
</t>
1114
</templates>
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
import { Component, useState } from "@odoo/owl";
22
import { Counter } from "./counter/counter";
33
import { Card } from "./card/card";
4+
import { TodoList } from "./todo/todo_list";
5+
46

57
export class Playground extends Component {
6-
static template = "awesome_owl.Playground";
7-
static components = { Counter, Card };
8+
static template = "awesome_owl.playground";
9+
static components = { Counter, Card, TodoList };
810

911
setup() {
1012
this.state = useState({
1113
sum: 0,
1214
});
1315
}
1416

15-
incrementSum(newValue) {
16-
this.state.sum++;
17+
incrementSum(newVal,Checker){
18+
if(Checker)
19+
this.state.sum++;
20+
else
21+
this.state.sum--;
1722
}
1823
}
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
22
<templates xml:space="preserve">
3-
<t t-name="awesome_owl.Playground">
3+
<t t-name="awesome_owl.playground">
44
<Counter onChange.bind="incrementSum"/>
55
<Counter onChange.bind="incrementSum"/>
66
<Counter onChange.bind="incrementSum"/>
7-
<h3 style="border: 3px solid #ccc; margin: 20px; padding: 20px">Sum of Counters: <t t-esc="state.sum"/></h3>
8-
<Card title="'This is title1'" content="'Hello from card1'"/>
9-
<Card title="'This is title2'" content="'Hello from card2'"/>
7+
<h3 style="background-color: #90EE90; border: 3px solid #ccc; margin: 20px; padding: 20px">Sum of Counters: <t t-esc="state.sum"/></h3>
8+
<TodoList/>
109
</t>
1110
</templates>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { Component } from "@odoo/owl";
2+
3+
4+
export class TodoItem extends Component {
5+
static template = "awesome_owl.TodoItem";
6+
7+
static props = {
8+
todo: Object,
9+
};
10+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<templates xml:space="preserve">
3+
<t t-name="awesome_owl.TodoItem">
4+
<div class="p-1" t-att-class="props.todo.isCompleted ? 'text-muted text-decoration-line-through' : ''">
5+
<span t-esc="props.todo.id"/> -
6+
<span t-esc="props.todo.description"/>
7+
</div>
8+
</t>
9+
</templates>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { Component, useState } from "@odoo/owl";
2+
import { TodoItem } from "./todo_item";
3+
4+
5+
export class TodoList extends Component {
6+
static template = "awesome_owl.TodoList";
7+
8+
static components = { TodoItem };
9+
10+
setup() {
11+
this.todos = useState([])
12+
}
13+
14+
addTodo(ev) {
15+
if(ev.keyCode == '13') {
16+
this.todos.push({
17+
id: this.todos.length + 1,
18+
description: ev.target.value,
19+
isCompleted: false
20+
})
21+
ev.target.value = ''
22+
}
23+
}
24+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<templates xml:space="preserve">
3+
<t t-name="awesome_owl.TodoList">
4+
<div style="background-color: #ADD8E6; border: 3px solid #ccc; display: inline-block; min-width: 300px; padding: 20px; margin: 20px">
5+
<h3>Todo List</h3>
6+
<input type="text" placeholder="Enter a new task" t-on-keyup="addTodo" class="form-control mb-2"/>
7+
<div t-foreach="todos" t-as="todo" t-key="todo.id">
8+
<TodoItem todo="todo"/>
9+
</div>
10+
</div>
11+
</t>
12+
</templates>

0 commit comments

Comments
 (0)