Skip to content

leol - Technical Training #724

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
wants to merge 17 commits into
base: 18.0
Choose a base branch
from
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
21 changes: 21 additions & 0 deletions awesome_owl/static/src/card/card.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/** @odoo-module **/

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

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

static props = {
title: { type: String },
slots: { type: Object },
// content: { type: String }, removed following 13. Generic Card with slots
}

setup() {
this.opened = useState({ value: true });
}

toggleOpened() {
this.opened.value = !this.opened.value;
}
}
19 changes: 19 additions & 0 deletions awesome_owl/static/src/card/card.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?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">
<p><t t-esc="props.title" /></p>
<button t-on-click="toggleOpened">Toggle</button>
</h5>
<p class="card-text" t-if="opened.value">
<!-- <t t-out="props.content" removed following 13. Generic Card with slots/> -->
<t t-slot="default" />
</p>
</div>
</div>
</t>

</templates>
23 changes: 23 additions & 0 deletions awesome_owl/static/src/counter/counter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/** @odoo-module **/

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();
}
}
}
13 changes: 13 additions & 0 deletions awesome_owl/static/src/counter/counter.xml
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.counter">
<div class="card d-inline-block m-2" style="width: 18rem;">
<div class="card-body">
<p>Counter: <t t-esc="state.value" /></p>
<button class="btn btn-primary" t-on-click="increment">Increment</button>
</div>
</div>
</t>

</templates>
20 changes: 19 additions & 1 deletion awesome_owl/static/src/playground.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
/** @odoo-module **/

import { Component } from "@odoo/owl";
import { Component, markup, useState } from "@odoo/owl";
import { Card } from "./card/card";
import { Counter } from "./counter/counter";
import { TodoList } from "./todolist/todolist";

export class Playground extends Component {
static components = { Counter, Card, TodoList };

static template = "awesome_owl.playground";

static props = {};

html1 = "<div style=\"background-color: red\">some content</div>";
html2 = markup("<div style=\"background-color: red\">some content</div>");

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

incrementSum() {
this.sum.value++;
}
}
18 changes: 16 additions & 2 deletions awesome_owl/static/src/playground.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
<?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
hello world, The sum is <t t-esc="sum.value" />
</div>
<div>
<Counter onChange.bind="incrementSum" />
<Counter onChange.bind="incrementSum" />
</div>
<div>
<Card title="'my title'">some content</Card>
<Card title="'my title'"><t t-out="this.html1" /></Card>
<Card title="'my title'"><t t-out="this.html2" /></Card>
<!-- <Card title="'my title'" content="0" /> Invalid props for component 'Card': 'content' is not a string -->
<Card title="'my title'"><Counter /></Card>
</div>
<div>
<TodoList />
</div>
</t>

Expand Down
25 changes: 25 additions & 0 deletions awesome_owl/static/src/todolist/todoitem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/** @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,
},
},
removeTodo: { type: Function },
}

toggleState(ev) {
if (!ev.target) return;

this.props.todo.isCompleted = ev.target.checked;
}
}
24 changes: 24 additions & 0 deletions awesome_owl/static/src/todolist/todoitem.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">

<t t-name="awesome_owl.todoitem">
<input
type="checkbox"
t-att-checked="props.todo.isCompleted"
t-on-change="toggleState"
style="display: inline-block; margin-right: 5px;" />
<div
t-att-class="{
'text-decoration-line-through' : props.todo.isCompleted,
'text-muted': props.todo.isCompleted,
}"
style="display: inline-block;" >
<t t-esc="props.todo.id" />. <t t-esc="props.todo.description" />
</div>
<span
class="fa fa-remove"
t-on-click="this.props.removeTodo"
style="display: inline-block; margin-left: 5px; color: red;" />
</t>

</templates>
56 changes: 56 additions & 0 deletions awesome_owl/static/src/todolist/todolist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/** @odoo-module **/

import { Component, useRef, useState } from "@odoo/owl";
import { useAutofocus } from "../utils";
import { TodoItem } from "./todoitem";

export class TodoList extends Component {
static components = { TodoItem };

static template = "awesome_owl.todolist";

static props = {};

setup() {
this.id = 1; // could be calculated every iteration but would get very slow with a lot of todos
this.todos = useState([
// removed following 9. Adding a todo
// { id: 2, description: "write tutorial", isCompleted: true },
// { id: 3, description: "buy milk", isCompleted: false },
]);
this.inputRef = useRef("add_task");
useAutofocus("add_task");
}

addTodo(ev) {
if (ev.keyCode != 13) return;

if (!this.inputRef.el) return;

const desc = this.inputRef.el.value;

if (desc === "") return;

this.todos.push({
id: this.id,
description: desc,
isCompleted: false,
});

this.inputRef.el.value = "";
this.id++;
}

removeTodo(ev) {
// is there not a better way ??? this doesn't feel good
const elemId = parseInt(ev.target.parentNode.childNodes[1].childNodes[0].textContent);

if (elemId < 0 || elemId >= this.id) return;

const index = this.todos.findIndex((elem) => elem.id === elemId);
if (index >= 0) {
// remove the element at index from list
this.todos.splice(index, 1);
}
}
}
15 changes: 15 additions & 0 deletions awesome_owl/static/src/todolist/todolist.xml
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.todolist">
<div class="card d-inline-block m-2" style="width: 18rem;">
<div class="card-body">
<input type="text" class="" placeholder="Enter a new task" t-on-keyup="addTodo" t-ref="add_task"/>
<div t-foreach="todos" t-as="todo" t-key="todo_index" style="margin: 2px;">
<TodoItem todo="todo" removeTodo.bind="removeTodo" />
</div>
</div>
</div>
</t>

</templates>
11 changes: 11 additions & 0 deletions awesome_owl/static/src/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/** @odoo-module **/

import { useEffect, useRef } from "@odoo/owl";

export function useAutofocus(name) {
let ref = useRef(name);
useEffect(
(el) => el && el.focus(),
() => [ref.el]
);
}
1 change: 1 addition & 0 deletions estate/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
26 changes: 26 additions & 0 deletions estate/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
'name': 'Real Estate',
'summary': """
Starting module for "Server framework 101"
""",
'description': """
Starting module for "Server framework 101"
""",
'author': 'Odoo',
'website': 'https://www.odoo.com',
'license': 'LGPL-3',
'category': 'Tutorials/Real Estate',
'version': '0.1',
'application': True,
'installable': True,
'data': [
'security/ir.model.access.csv',
'views/estate_property_views.xml',
'views/estate_property_tag_views.xml',
'views/estate_property_offer_views.xml',
'views/estate_property_type_views.xml',
'views/estate_menus.xml',
'views/res_users_views.xml',
],
'depends': ['base'],
}
5 changes: 5 additions & 0 deletions estate/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from . import estate_property
from . import estate_property_offer
from . import estate_property_tag
from . import estate_property_type
from . import res_users
Loading