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
37 changes: 16 additions & 21 deletions awesome_dashboard/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,25 @@
# -*- coding: utf-8 -*-
{
'name': "Awesome Dashboard",

'summary': """
"name": "Awesome Dashboard",
"summary": """
Starting module for "Discover the JS framework, chapter 2: Build a dashboard"
""",

'description': """
"description": """
Starting module for "Discover the JS framework, chapter 2: Build a dashboard"
""",

'author': "Odoo",
'website': "https://www.odoo.com/",
'category': 'Tutorials',
'version': '0.1',
'application': True,
'installable': True,
'depends': ['base', 'web', 'mail', 'crm'],

'data': [
'views/views.xml',
"author": "Odoo",
"website": "https://www.odoo.com/",
"category": "Tutorials",
"version": "0.1",
"application": True,
"installable": True,
"depends": ["base", "web", "mail", "crm"],
"data": [
"views/views.xml",
],
'assets': {
'web.assets_backend': [
'awesome_dashboard/static/src/**/*',
"assets": {
"web.assets_backend": [
"awesome_dashboard/static/src/**/*",
],
},
'license': 'AGPL-3'
"license": "AGPL-3",
}
3 changes: 3 additions & 0 deletions awesome_dashboard/static/src/dashboard.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { Component } from "@odoo/owl";
import { Layout } from "@web/search/layout"
import { registry } from "@web/core/registry";

class AwesomeDashboard extends Component {
static template = "awesome_dashboard.AwesomeDashboard";

static components = { Layout }
}

registry.category("actions").add("awesome_dashboard.dashboard", AwesomeDashboard);
5 changes: 5 additions & 0 deletions awesome_dashboard/static/src/dashboard.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.o_dashboard {
background-color: #f0f2f5;
display: flex;
flex-direction: column;
}
4 changes: 3 additions & 1 deletion awesome_dashboard/static/src/dashboard.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
<templates xml:space="preserve">

<t t-name="awesome_dashboard.AwesomeDashboard">
hello dashboard
<Layout display="{controlPanel: {} }" className="'o_dashboard h-100'">
hello dashboard
</Layout>
</t>

</templates>
4 changes: 1 addition & 3 deletions awesome_owl/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
# -*- coding: utf-8 -*-

from . import controllers
from . import controllers
54 changes: 24 additions & 30 deletions awesome_owl/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,37 @@
# -*- coding: utf-8 -*-
{
'name': "Awesome Owl",

'summary': """
"name": "Awesome Owl",
"summary": """
Starting module for "Discover the JS framework, chapter 1: Owl components"
""",

'description': """
"description": """
Starting module for "Discover the JS framework, chapter 1: Owl components"
""",

'author': "Odoo",
'website': "https://www.odoo.com",

"author": "Odoo",
"website": "https://www.odoo.com",
# Categories can be used to filter modules in modules listing
# Check https://github.com/odoo/odoo/blob/15.0/odoo/addons/base/data/ir_module_category_data.xml
# for the full list
'category': 'Tutorials',
'version': '0.1',

"category": "Tutorials",
"version": "0.1",
# any module necessary for this one to work correctly
'depends': ['base', 'web'],
'application': True,
'installable': True,
'data': [
'views/templates.xml',
"depends": ["base", "web"],
"application": True,
"installable": True,
"data": [
"views/templates.xml",
],
'assets': {
'awesome_owl.assets_playground': [
('include', 'web._assets_helpers'),
('include', 'web._assets_backend_helpers'),
'web/static/src/scss/pre_variables.scss',
'web/static/lib/bootstrap/scss/_variables.scss',
'web/static/lib/bootstrap/scss/_maps.scss',
('include', 'web._assets_bootstrap'),
('include', 'web._assets_core'),
'web/static/src/libs/fontawesome/css/font-awesome.css',
'awesome_owl/static/src/**/*',
"assets": {
"awesome_owl.assets_playground": [
("include", "web._assets_helpers"),
("include", "web._assets_backend_helpers"),
"web/static/src/scss/pre_variables.scss",
"web/static/lib/bootstrap/scss/_variables.scss",
"web/static/lib/bootstrap/scss/_maps.scss",
("include", "web._assets_bootstrap"),
("include", "web._assets_core"),
"web/static/src/libs/fontawesome/css/font-awesome.css",
"awesome_owl/static/src/**/*",
],
},
'license': 'AGPL-3'
"license": "AGPL-3",
}
4 changes: 1 addition & 3 deletions awesome_owl/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
# -*- coding: utf-8 -*-

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

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

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

setup() {
this.state = useState({ isOpen: true })
}

toggleContent() {
this.state.isOpen = !this.state.isOpen
}
}
18 changes: 18 additions & 0 deletions awesome_owl/static/src/card/card.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?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-header d-flex align-items-center">
<h5 class="card-title m-0"><t t-esc="props.title"/></h5>
<button class="btn btn-sm btn-outline-secondary" t-on-click="toggleContent">
<i t-att-class="state.isOpen ? 'fa fa-chevron-up' : 'fa fa-chevron-down'"/>
</button>
</div>
<div class="card-body" t-if="state.isOpen">
<p class="card-text">
<t t-slot="default"/>
</p>
</div>
</div>
</t>
</templates>
20 changes: 20 additions & 0 deletions awesome_owl/static/src/counter/counter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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();
}
}
}
9 changes: 9 additions & 0 deletions awesome_owl/static/src/counter/counter.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">
<t t-name="awesome_owl.Counter">
<div class="border">
<p>Counter: <t t-esc="state.value"/></p>
<button class="btn btn-primary" t-on-click="increment">Increment</button>
</div>
</t>
</templates>
20 changes: 18 additions & 2 deletions awesome_owl/static/src/playground.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
import { Component } from "@odoo/owl";
import { markup, Component, useState } from "@odoo/owl"
import { Counter } from './counter/counter'
import { Card } from './card/card'
import { TodoList } from './todo/todolist'

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

static components = { Counter, Card , TodoList}

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

incrementSum() {
this.state.sum++
}

html_card_1 = "<u>Test Test Test Test Test Test Test Test Test</u>"
html_card_2 = markup("<u>Test Test Test Test Test Test Test Test Test</u>")
}
21 changes: 16 additions & 5 deletions awesome_owl/static/src/playground.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">

<t t-name="awesome_owl.playground">
<div class="p-3">
hello world
<t t-name="awesome_owl.Playground">
<div class="m-2 p-2 border">
<div class="d-flex gap-3 align-items-start justify-content-center">
<Card title="'Counter 1'">
<Counter onChange.bind="incrementSum"/>
</Card>
<Card title="'Counter 2'">
<Counter onChange.bind="incrementSum"/>
</Card>
</div>
<div class="h3 text-center">
Sum: <t t-esc="state.sum"/>
</div>
</div>
<div class="border m-2 p-2">
<TodoList/>
</div>
</t>

</templates>
14 changes: 14 additions & 0 deletions awesome_owl/static/src/todo/todoitem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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 }
},
toggleState: { type: Function, optional: true },
deleteTodo: { type: Function, optional: true }
}
}
12 changes: 12 additions & 0 deletions awesome_owl/static/src/todo/todoitem.xml
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.TodoItem">
<div class="list-group-item d-flex gap-3 align-items-center justify-content-between p-2" t-att-class="{'text-muted text-decoration-line-through': props.todo.isCompleted}">
<div class="d-flex align-items-center flex-grow-1 gap-3">
<input type="checkbox" t-att-checked="props.todo.isCompleted" t-on-change="() => props.toggleState(props.todo.id)"/>
<t t-esc="props.todo.id"/>. <t t-esc="props.todo.description"/>
</div>
<span class="fa fa-remove" t-on-click="() => props.deleteTodo(props.todo.id)"/>
</div>
</t>
</templates>
40 changes: 40 additions & 0 deletions awesome_owl/static/src/todo/todolist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Component, useState } from "@odoo/owl"
import { useAutoFocus } from "../utils"
import { TodoItem } from "./todoitem"

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

static components = { TodoItem }

setup() {
this.todos = useState([])
this.nextId = 1
this.inputRef = useAutoFocus('input')
}

addTodo(ev) {
if (ev.keyCode == 13) {
const content = ev.target.value.trim()
if (content !== "") {
this.todos.push({ id: this.nextId, description: content, isCompleted: false })
ev.target.value = ""
this.nextId++
}
}
}

toggleTodo(id) {
const todo = this.todos.find(t => t.id === id)
if (todo) {
todo.isCompleted = !todo.isCompleted
}
}

deleteTodo(id) {
const index = this.todos.findIndex((t) => t.id === id);
if (index >= 0) {
this.todos.splice(index, 1)
}
}
}
11 changes: 11 additions & 0 deletions awesome_owl/static/src/todo/todolist.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.TodoList">
<div class="p-2">
<input type="text" class="form-control mb-3" placeholder="Enter a new task" t-on-keyup="addTodo" t-ref="input"/>
<t t-foreach="todos" t-as="todo" t-key="todo.id">
<TodoItem todo="todo" toggleState.bind="toggleTodo" deleteTodo.bind="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 { useRef, onMounted } from "@odoo/owl"

export function useAutoFocus(refName) {
const ref = useRef(refName)
onMounted(() => {
ref.el.focus()
})
return ref
}