From 337f2ea891ea92605a781f65f78d266c518d5e13 Mon Sep 17 00:00:00 2001 From: nape-odoo Date: Sun, 24 Nov 2024 16:43:02 +0100 Subject: [PATCH] [IMP] awesome_owl: Tutorial chapter 1 --- awesome_owl/static/src/misc/card.js | 18 ++++++++++ awesome_owl/static/src/misc/card.xml | 23 +++++++++++++ awesome_owl/static/src/misc/counter.js | 20 +++++++++++ awesome_owl/static/src/misc/counter.xml | 10 ++++++ awesome_owl/static/src/playground.js | 15 ++++++++- awesome_owl/static/src/playground.xml | 15 ++++++++- awesome_owl/static/src/todo/todo_item.js | 18 ++++++++++ awesome_owl/static/src/todo/todo_item.xml | 15 +++++++++ awesome_owl/static/src/todo/todo_list.js | 41 +++++++++++++++++++++++ awesome_owl/static/src/todo/todo_list.xml | 12 +++++++ 10 files changed, 185 insertions(+), 2 deletions(-) create mode 100644 awesome_owl/static/src/misc/card.js create mode 100644 awesome_owl/static/src/misc/card.xml create mode 100644 awesome_owl/static/src/misc/counter.js create mode 100644 awesome_owl/static/src/misc/counter.xml create mode 100644 awesome_owl/static/src/todo/todo_item.js create mode 100644 awesome_owl/static/src/todo/todo_item.xml create mode 100644 awesome_owl/static/src/todo/todo_list.js create mode 100644 awesome_owl/static/src/todo/todo_list.xml diff --git a/awesome_owl/static/src/misc/card.js b/awesome_owl/static/src/misc/card.js new file mode 100644 index 0000000000..68a946ce53 --- /dev/null +++ b/awesome_owl/static/src/misc/card.js @@ -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; + } +} diff --git a/awesome_owl/static/src/misc/card.xml b/awesome_owl/static/src/misc/card.xml new file mode 100644 index 0000000000..75ab7b33cc --- /dev/null +++ b/awesome_owl/static/src/misc/card.xml @@ -0,0 +1,23 @@ + + + + +
+
+
+ + +
+
+

+ +
    + +
+
+
+
+
+ +
+ diff --git a/awesome_owl/static/src/misc/counter.js b/awesome_owl/static/src/misc/counter.js new file mode 100644 index 0000000000..9cfcb73fbb --- /dev/null +++ b/awesome_owl/static/src/misc/counter.js @@ -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(); + } + } +} diff --git a/awesome_owl/static/src/misc/counter.xml b/awesome_owl/static/src/misc/counter.xml new file mode 100644 index 0000000000..16a9d052e9 --- /dev/null +++ b/awesome_owl/static/src/misc/counter.xml @@ -0,0 +1,10 @@ + + + + +

Counter:

+ +
+ +
+ diff --git a/awesome_owl/static/src/playground.js b/awesome_owl/static/src/playground.js index 657fb8b07b..16c8b374fb 100644 --- a/awesome_owl/static/src/playground.js +++ b/awesome_owl/static/src/playground.js @@ -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 = "
Content 1
" + this.message_2 = markup("
Content 2
") + this.counter_sum = useState({ value: 0 }) + } + onCounterIncrement(){ + this.counter_sum.value++; + } } diff --git a/awesome_owl/static/src/playground.xml b/awesome_owl/static/src/playground.xml index 4fb905d59f..95ddfa45e6 100644 --- a/awesome_owl/static/src/playground.xml +++ b/awesome_owl/static/src/playground.xml @@ -3,8 +3,21 @@
- hello world +

Playground

+

Sum of counters:

+
+
+ + + + + + +
+
+
+ diff --git a/awesome_owl/static/src/todo/todo_item.js b/awesome_owl/static/src/todo/todo_item.js new file mode 100644 index 0000000000..820a6df8dc --- /dev/null +++ b/awesome_owl/static/src/todo/todo_item.js @@ -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); + } +} diff --git a/awesome_owl/static/src/todo/todo_item.xml b/awesome_owl/static/src/todo/todo_item.xml new file mode 100644 index 0000000000..0cad212416 --- /dev/null +++ b/awesome_owl/static/src/todo/todo_item.xml @@ -0,0 +1,15 @@ + + + + +
+

+ + ID: + Description: + +

+
+
+ +
diff --git a/awesome_owl/static/src/todo/todo_list.js b/awesome_owl/static/src/todo/todo_list.js new file mode 100644 index 0000000000..e8479f9a4c --- /dev/null +++ b/awesome_owl/static/src/todo/todo_list.js @@ -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 + } + } + }) + } +} diff --git a/awesome_owl/static/src/todo/todo_list.xml b/awesome_owl/static/src/todo/todo_list.xml new file mode 100644 index 0000000000..670d26c10d --- /dev/null +++ b/awesome_owl/static/src/todo/todo_list.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + +