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
34 changes: 33 additions & 1 deletion awesome_dashboard/static/src/dashboard.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,40 @@
import { Component } from "@odoo/owl";
import { Component, onWillStart } from "@odoo/owl";
import { _t } from "@web/core/l10n/translation";
import { rpc } from "@web/core/network/rpc"
import { registry } from "@web/core/registry";
import { useService } from "@web/core/utils/hooks";
import { Layout } from "@web/search/layout";


import { DashboardItem } from "./dashboardItem/dashboardItem";

class AwesomeDashboard extends Component {
static template = "awesome_dashboard.AwesomeDashboard";
static components = { Layout, DashboardItem };

setup() {
this.action = useService("action");

onWillStart(async () => {
this.statistics = await rpc("/awesome_dashboard/statistics");
})
}

openCustomers() {
this.action.doAction("base.action_partner_form");
}

openLeads() {
this.action.doAction({
type: 'ir.actions.act_window',
name: _t("CRM Leads"),
res_model: 'crm.lead',
views: [
[false, 'list'],
[false, 'form'],
],
})
}
}

registry.category("actions").add("awesome_dashboard.dashboard", AwesomeDashboard);
55 changes: 51 additions & 4 deletions awesome_dashboard/static/src/dashboard.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,55 @@
<?xml version="1.0" encoding="UTF-8" ?>
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">

<t t-name="awesome_dashboard.AwesomeDashboard">
hello dashboard
</t>
<Layout display="{ controlPanel: {} }" className="'o_dashboard h-100'">
<div class="d-flex flex-wrap gap-3 p-3">

<DashboardItem>
<div class="text-center p-2">
<div class="fs-2 fw-bold text-primary">
<t t-esc="statistics.nb_new_orders"/>
</div>
<div class="text-muted">Number of new orders this month</div>
</div>
</DashboardItem>

<DashboardItem>
<div class="text-center p-2">
<div class="fs-2 fw-bold text-success">
<t t-esc="statistics.total_amount"/>
</div>
<div class="text-muted">Total amount of new orders this month</div>
</div>
</DashboardItem>

<DashboardItem>
<div class="text-center p-2">
<div class="fs-2 fw-bold text-info">
<t t-esc="statistics.average_quantity"/>
</div>
<div class="text-muted">Average amount of t-shirt by order this month</div>
</div>
</DashboardItem>

<DashboardItem>
<div class="text-center p-2">
<div class="fs-2 fw-bold text-danger">
<t t-esc="statistics.nb_cancelled_orders"/>
</div>
<div class="text-muted">Number of cancelled orders this month</div>
</div>
</DashboardItem>

<DashboardItem>
<div class="text-center p-2">
<div class="fs-2 fw-bold text-warning">
<t t-esc="statistics.average_time"/>
</div>
<div class="text-muted">Average time from 'new' to 'sent' or 'cancelled'</div>
</div>
</DashboardItem>

</div>
</Layout>
</t>
</templates>
12 changes: 12 additions & 0 deletions awesome_dashboard/static/src/dashboardItem/dashboardItem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Component } from "@odoo/owl";

export class DashboardItem extends Component {
static template = 'awesome_dashboard.AwesomeDashboardItem';
static props = {
size: { type: Number, optional: true },
slots: { type: Object, optional: true },
};
static defaultProps = {
size: 1,
};
}
8 changes: 8 additions & 0 deletions awesome_dashboard/static/src/dashboardItem/dashboardItem.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-name='awesome_dashboard.AwesomeDashboardItem'>
<div class='card shadow-sm p-3' t-attf-style='width: {{ props.size * 18 }}rem;'>
<t t-slot="default"/>
</div>
</t>
</templates>
3 changes: 3 additions & 0 deletions awesome_dashboard/static/src/scss/dashboard.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.o_dashboard {
background-color: gray;
}
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: {type: String},
slots: {type: Object, optional: true},
};

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

toggleCard() {
this.state.isOpen = !this.state.isOpen;
}
}
22 changes: 22 additions & 0 deletions awesome_owl/static/src/card/card.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">

<t t-name="awesome_owl.card">
<div class="m-3 p-3 border rounded">
<div class="d-flex align-items-center gap-2">
<button class="btn btn-sm btn-light border-0 fs-6 p-0 px-1"
t-on-click="toggleCard">
<t t-esc="state.isOpen ? '▼' : '▶'"/>
</button>
<h5 class="m-0">
<t t-esc="props.title"/>
</h5>
</div>

<div t-if="state.isOpen" class="mt-3">
<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";

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

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

increment() {
this.state.value++;
this.props.onChange?.();
}
}
11 changes: 11 additions & 0 deletions awesome_owl/static/src/counter/counter.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.counter">
<div class="m-3 p-3 border rounded d-inline-flex align-items-center gap-3">
<span>Counter: <t t-esc="state.value"/></span>
<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 { Component, markup, 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 };
static props = {};

value1 = "<div>content 1</div>"
value2 = markup("<div>content 2</div>")

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

incrementSum() {
this.sum.value++;
}
}
16 changes: 13 additions & 3 deletions awesome_owl/static/src/playground.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
<?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-3 p-3 border rounded'>
<div class='d-flex gap-3 mb-3'>
<Counter onChange.bind='incrementSum'/>
<Counter onChange.bind='incrementSum'/>
</div>
<div>
<span>The sum is: <t t-esc="sum.value"/></span>
</div>
<TodoList/>
<Card title="'New Card'">
<Counter/>
</Card>
</div>
</t>

Expand Down
22 changes: 22 additions & 0 deletions awesome_owl/static/src/todo/todoItem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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: Function,
removeTodo: Function,
};

onChange() {
this.props.toggleState(this.props.todo.id);
}

onClick() {
this.props.removeTodo(this.props.todo.id);
}
}
19 changes: 19 additions & 0 deletions awesome_owl/static/src/todo/todoItem.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.todoItem'>
<div class="d-flex align-items-center gap-2"
t-att-class="{ 'text-muted text-decoration-line-through': props.todo.isCompleted }">
<input type="checkbox"
class="form-check-input mt-0"
t-att-checked="props.todo.isCompleted"
t-on-change="onChange"/>
<span>
<t t-esc='props.todo.id'/>. <t t-esc='props.todo.description'/>
</span>
<span class="fa fa-remove"
t-on-click="onClick"/>
</div>
</t>

</templates>
42 changes: 42 additions & 0 deletions awesome_owl/static/src/todo/todoList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Component, useState, useRef, onMounted } from "@odoo/owl"
import { TodoItem } from "./todoItem";
import { useAutofocus } from "../utils";

export class TodoList extends Component {
static template = 'awesome_owl.todoList';
static components = { TodoItem };
static props = {};

setup() {
this.todos = useState([]);
this.id = 1;

this.inputRef = useAutofocus('todo');
}

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

const value = ev.target.value.trim();

if (value.length === 0)
return;

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

ev.target.value = "";
}

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

removeTodo(id) {
const index = this.todos.findIndex((elem) => elem.id === id);
if (index >= 0)
this.todos.splice(index, 1);
}
}
18 changes: 18 additions & 0 deletions awesome_owl/static/src/todo/todoList.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.todoList'>
<div class='m-3 p-3 border rounded d-inline-block'>
<input type='text'
placeholder="Enter a new task"
t-ref='todo'
t-on-keyup='addTodo'/>
<t t-foreach='todos' t-as='todo' t-key='todo.id'>
<TodoItem todo='todo'
toggleState.bind='toggleTodo'
removeTodo.bind='removeTodo'/>
</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();
});
return ref;
}