-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] awesome_owl: Tutorial chapter 1
- Loading branch information
Showing
10 changed files
with
185 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 @@ | ||
/** @odoo-module **/ | ||
|
||
import { Component, useState } from "@odoo/owl"; | ||
|
||
export class Card extends Component { | ||
static template = "awesome_owl.card"; | ||
static props = { | ||
title : String, | ||
message : String, | ||
slots : {type: Object, optional: true} | ||
} | ||
setup() { | ||
this.isMinimized = useState({ value: false }); | ||
} | ||
cardMinMaximize() { | ||
this.isMinimized.value = !this.isMinimized.value; | ||
} | ||
} |
This file contains 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,23 @@ | ||
<?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-esc="props.title"/> | ||
<span t-att-class="{'fa fa-plus' : isMinimized.value, 'fa fa-minus' : !isMinimized.value}" role="button" t-on-click="cardMinMaximize"/> | ||
</h5> | ||
<div t-if="!isMinimized.value"> | ||
<p class="card-text"><t t-out="props.message"/></p> | ||
<t t-slot="default"/> | ||
<ul> | ||
<!-- default slot content --> | ||
</ul> | ||
</div> | ||
</div> | ||
</div> | ||
</t> | ||
|
||
</templates> | ||
|
This file contains 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 @@ | ||
/** @odoo-module **/ | ||
|
||
import { Component, useState } from "@odoo/owl"; | ||
|
||
export class Counter extends Component { | ||
static template = "awesome_owl.counter"; | ||
static props = { | ||
onIncrement : { type : Function, optional : true } | ||
} | ||
setup() { | ||
this.state = useState({ value: 0 }); | ||
} | ||
|
||
increment() { | ||
this.state.value++; | ||
if (this.props.onIncrement) { | ||
this.props.onIncrement(); | ||
} | ||
} | ||
} |
This file contains 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"> | ||
<p>Counter: <t t-esc="state.value"/></p> | ||
<button class="btn btn-primary" t-on-click="increment">Increment</button> | ||
</t> | ||
|
||
</templates> | ||
|
This file contains 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,20 @@ | ||
/** @odoo-module **/ | ||
|
||
import { Component } from "@odoo/owl"; | ||
import { Component, markup, useState } from "@odoo/owl"; | ||
import { Counter } from "./misc/counter"; | ||
import { Card } from "./misc/card"; | ||
import { TodoList } from "./todo/todo_list" | ||
|
||
export class Playground extends Component { | ||
static template = "awesome_owl.playground"; | ||
static components = { Counter, Card, TodoList } | ||
static props = {} | ||
setup(){ | ||
this.message_1 = "<div class='text-primary'>Content 1</div>" | ||
this.message_2 = markup("<div class='text-primary'>Content 2</div>") | ||
this.counter_sum = useState({ value: 0 }) | ||
} | ||
onCounterIncrement(){ | ||
this.counter_sum.value++; | ||
} | ||
} |
This file contains 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 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 @@ | ||
/** @odoo-module **/ | ||
|
||
import { Component } from "@odoo/owl"; | ||
|
||
export class TodoItem extends Component { | ||
static template = "awesome_owl.todoitem"; | ||
static props = { | ||
todo : {type: Object, shape: {id : Number, description: String, isCompleted: Boolean }}, | ||
todoListToggleItem : { type : Function, optional : false }, | ||
todoListRemoveItem : { type : Function, optional : false } | ||
} | ||
todoItemToggleItem() { | ||
this.props.todoListToggleItem(this.props.todo.id); | ||
} | ||
todoItemRemoveItem() { | ||
this.props.todoListRemoveItem(this.props.todo.id); | ||
} | ||
} |
This file contains 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.todoitem"> | ||
<div t-att-class="{'text-decoration-line-through text-secondary': props.todo.isCompleted}"> | ||
<p> | ||
<input type="checkbox" t-on-change="todoItemToggleItem" t-att-checked="props.todo.isCompleted"/> | ||
ID: <t t-esc="props.todo.id"/> | ||
Description: <t t-esc="props.todo.description"/> | ||
<span class="fa fa-remove" role="button" t-on-click="todoItemRemoveItem"/> | ||
</p> | ||
</div> | ||
</t> | ||
|
||
</templates> |
This file contains 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 @@ | ||
/** @odoo-module **/ | ||
|
||
import { Component, useState } from "@odoo/owl"; | ||
import { TodoItem } from "./todo_item" | ||
|
||
export class TodoList extends Component { | ||
static template = "awesome_owl.todolist"; | ||
static components = { TodoItem } | ||
static props = {} | ||
setup(){ | ||
this.todos = useState([ | ||
{ id: 0, description: "Do something", isCompleted: true }, | ||
{ id: 1, description: "Do something else", isCompleted: false }, | ||
{ id: 2, description: "Do stuff", isCompleted: false }, | ||
{ id: 3, description: "Do more stuff", isCompleted: false } | ||
]); | ||
} | ||
todoListAddItem(input_value) { | ||
if (input_value.keyCode === 13 && input_value.target.value){ | ||
this.todos.push({id: (this.todos.length) ? this.todos.at(-1).id + 1 : 0, description: input_value.target.value, isCompleted: false}); | ||
input_value.target.value = ""; | ||
} | ||
} | ||
todoListToggleItem(todoId) { | ||
this.todos.forEach((todo) => { | ||
if (todo.id === todoId) { | ||
todo.isCompleted = !todo.isCompleted; | ||
} | ||
}) | ||
} | ||
todoListRemoveItem(todoId) { | ||
this.todos.forEach((todo) => { | ||
if (todo.id === todoId) { | ||
this.todos.splice(todoId, 1); | ||
for (let i = 0; i < this.todos.length; i++) { | ||
this.todos.at(i).id = i | ||
} | ||
} | ||
}) | ||
} | ||
} |
This file contains 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.todolist"> | ||
<input type="text" placeholder="Add a todo" t-on-keyup="todoListAddItem" t-ref="input"/> | ||
<t t-foreach="todos" t-as="todo" t-key="todo.id"> | ||
<TodoItem todo="todo" todoListToggleItem.bind="todoListToggleItem" todoListRemoveItem.bind="todoListRemoveItem"/> | ||
</t> | ||
</t> | ||
|
||
</templates> | ||
|