Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion awesome_owl/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# -*- coding: utf-8 -*-

from . import controllers
from . import controllers
2 changes: 1 addition & 1 deletion awesome_owl/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# -*- coding: utf-8 -*-

from . import controllers
from . import controllers
25 changes: 25 additions & 0 deletions awesome_owl/static/src/card/card.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {Component, useState} from "@odoo/owl"


export class Card extends Component {
static template = "awesome_owl.card";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
static template = "awesome_owl.card";
static template = "awesome_owl.Card";


static props = {
title: String,
slots: {type: Object, optional: true},
};

setup() {
const {title} = this.props;
this.title = title;
this.state = useState({isOpened: true})
}

get isOpened() {
return this.state.isOpened;
}

toggle() {
this.state.isOpened = !this.isOpened;
}
}
14 changes: 14 additions & 0 deletions awesome_owl/static/src/card/card.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?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 p-2" style="width: 18rem;">
<div class="d-inline-block">
<h3 class="card-title"><t t-esc="title"/></h3>
<button class="btn btn-primary" t-on-click="toggle">Toggle</button>
</div>
<div t-if="isOpened" class="card-body">
<t t-slot="default"/>
</div>
</div>
</t>
</templates>
18 changes: 18 additions & 0 deletions awesome_owl/static/src/counter/counter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Component, useState } from "@odoo/owl";

export class Counter extends Component {
static template = "awesome_owl.counter";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. You should use PascalCase for the name after the dot.


static props = {
onChange: { type: Function, optional: true }
};

setup() {
this.state = useState({ value: 0 });
}

increment() {
this.state.value++;
this.props.onChange();
}
}
10 changes: 10 additions & 0 deletions awesome_owl/static/src/counter/counter.xml
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-block p-3">
Counter: <t t-esc="this.state.value"/>
<button class="btn btn-primary" t-on-click="increment">Increment</button>
</div>
</t>
</templates>
1 change: 1 addition & 0 deletions awesome_owl/static/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { whenReady } from "@odoo/owl";
import { mountComponent } from "@web/env";
import { Playground } from "./playground";


Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That diff is not necessary 😃. We try to do as little change as possible as It can generate a big PR and it can make it complicate to read and understand.

const config = {
dev: true,
name: "Owl Tutorial",
Expand Down
17 changes: 15 additions & 2 deletions awesome_owl/static/src/playground.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
/** @odoo-module **/
import { Card } from "./card/card"
import { Component, useState } from "@odoo/owl";
import { Counter } from "./counter/counter";
import { TodoList } from "./todo_list/todo_list";

import { Component } from "@odoo/owl";

export class Playground extends Component {
static template = "awesome_owl.playground";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They should have used PascalCase 😢. No need to change that.


static components = { Counter, Card, TodoList };

setup() {
this.state = useState({ sum: 0 });
this.incrementSum = this.incrementSum.bind(this);
}

incrementSum() {
this.state.sum++;
}
}
15 changes: 11 additions & 4 deletions awesome_owl/static/src/playground.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
<?xml version="1.0" encoding="UTF-8" ?>
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">

<t t-name="awesome_owl.playground">
<div class="p-3">
hello world
<Card title="'card1'">
<Counter onChange="incrementSum"/>
</Card>
<Card title="'card2'">
<Counter onChange="incrementSum"/>
</Card>
<p>The sum is: <t t-esc="this.state.sum"/></p>
<br/>
<br/>
<TodoList/>
</div>
</t>

</templates>
26 changes: 26 additions & 0 deletions awesome_owl/static/src/todo_list/todo_item.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Component } from "@odoo/owl"


export class TodoItem extends Component {
static template = "awesome_owl.todo.item";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
static template = "awesome_owl.todo.item";
static template = "awesome_owl.TodoItem";


static props = {
id: Number,
description: String,
isCompleted: Boolean,
toggleState: Function,
deleteTodo: Function,
}

get id() {
return this.props.id;
}

get description() {
return this.props.description;
}

get isCompleted() {
return this.props.isCompleted;
}
}
11 changes: 11 additions & 0 deletions awesome_owl/static/src/todo_list/todo_item.xml
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.todo.item">
<p t-att-class="{'text-muted': isCompleted, 'text-decoration-line-through': isCompleted}">
<input type="checkbox" t-att-checked="isCompleted" t-on-change="() => props.toggleState(id)"/>
<t t-esc="id"/>.
<t t-esc="description"/>
<span class="fa fa-remove" t-on-click="() => props.deleteTodo(id)"/>
</p>
</t>
</templates>
50 changes: 50 additions & 0 deletions awesome_owl/static/src/todo_list/todo_list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { Component, useState } from "@odoo/owl"
import { TodoItem } from "./todo_item";
import { useAutofocus } from "../utils";


export class TodoList extends Component {
static template = "awesome_owl.todo.list";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
static template = "awesome_owl.todo.list";
static template = "awesome_owl.TodoList";


static components = { TodoItem };

static idGen = 0;

static get id() {
return this.idGen++;
}

setup() {
this.todos = useState([]);
useAutofocus('todo_input');
this.toggleTodo = this.toggleTodo.bind(this);
this.deleteTodo = this.deleteTodo.bind(this);
}

addTodo(event) {
if (event.keyCode === 13 && event.target.value) {
this.todos.push(
{
id: this.constructor.id,
description: event.target.value,
isCompleted: false
}
);
event.target.value = '';
}
}

toggleTodo(id) {
const idx = this.todos.findIndex((elem) => elem.id === id);
if (idx !== -1) {
this.todos[idx].isCompleted = !this.todos[idx].isCompleted;
}
}

deleteTodo(id) {
const idx = this.todos.findIndex((elem) => elem.id === id);
if (idx !== -1) {
this.todos.splice(idx, 1);
}
}
}
14 changes: 14 additions & 0 deletions awesome_owl/static/src/todo_list/todo_list.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-name="awesome_owl.todo.list">

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

<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_index">
<TodoItem id="todo.id" description="todo.description" isCompleted="todo.isCompleted"
toggleState="toggleTodo" deleteTodo="deleteTodo"/>
</t>
</div>
</t>
</templates>
9 changes: 9 additions & 0 deletions awesome_owl/static/src/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { onMounted, useRef } from "@odoo/owl";


export function useAutofocus(name) {
const ref = useRef(name);
onMounted(() => {
ref.el.focus();
});
}