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
18 changes: 18 additions & 0 deletions awesome_clicker/static/src/click_value/click_value.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Component } from "@odoo/owl";
import { useClicker } from "../clicker_hook";
import { humanNumber } from "@web/core/utils/numbers"

export class ClickValue extends Component {
static template = "awesome_clicker.ClickValue";
static props = {};

setup() {
this.clicker = useClicker()
}

get humanVal() {
return humanNumber(this.clicker.count.clicks, {
decimals: 1,
});
}
}
6 changes: 6 additions & 0 deletions awesome_clicker/static/src/click_value/click_value.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">
<t t-name="awesome_clicker.ClickValue">
<t t-esc="humanVal"/>
</t>
</templates>
6 changes: 6 additions & 0 deletions awesome_clicker/static/src/clicker_hook.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { useService } from "@web/core/utils/hooks";
import { useState } from "@odoo/owl";

export function useClicker() {
return useState(useService("awesome_clicker.clicker"));
}
22 changes: 22 additions & 0 deletions awesome_clicker/static/src/clicker_service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { registry } from "@web/core/registry";
import { reactive } from "@odoo/owl";

export const clickerService = {
start() {

const count = reactive({ clicks: 0 });

function increment(c) {
count.clicks+= c;
}

document.addEventListener("click", () => increment(1), true);

return {
count,
increment,
};
},
};

registry.category("services").add("awesome_clicker.clicker", clickerService);
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { registry } from "@web/core/registry";
import { Component } from "@odoo/owl";
import { useService } from "@web/core/utils/hooks";
import { useClicker } from "../clicker_hook";
import { ClickValue } from "../click_value/click_value";

export class ClickerSystray extends Component {

static template = "awesome_clicker.ClickerSystray";
static props = {};
static components = {
ClickValue,
}

setup() {
this.action = useService("action");
this.clicker = useClicker()
}

openClientAction() {
this.action.doAction({
type: "ir.actions.client",
tag: "awesome_clicker.client_action",
target: "new",
name: "Clicker Game"
});
}

}

export const systrayItem = {
Component: ClickerSystray,
};

registry.category("systray").add("awesome_clicker.ClickerSystray", systrayItem, { sequence: 1000 });
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_clicker.ClickerSystray">
<div class="o_nav_entry">
Clicks: <ClickValue />
<button class="btn btn-secondary" t-on-click="() => this.clicker.increment(500)">
<i class="fa fa-lg fa-plus"></i>
</button>
<button class="btn btn-secondary" t-on-click="openClientAction">
Open
</button>
</div>
</t>
</templates>
19 changes: 19 additions & 0 deletions awesome_clicker/static/src/clicker_systray_item/client_action.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { registry } from "@web/core/registry";
import { Component } from "@odoo/owl";
import { useClicker } from "../clicker_hook";
import { ClickValue } from "../click_value/click_value";

export class ClientAction extends Component {
static template = "awesome_clicker.ClientAction";
static props = {};
static components = {
ClickValue,
}

setup() {
this.clicker = useClicker()
}

}

registry.category("actions").add("awesome_clicker.client_action", ClientAction);
11 changes: 11 additions & 0 deletions awesome_clicker/static/src/clicker_systray_item/client_action.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_clicker.ClientAction">
<div class="ms-1 mt-1">
<span>Clicks: <ClickValue /></span>
<button class="btn btn-primary ms-1" t-on-click="() => this.clicker.increment(9)">
Increment
</button>
</div>
</t>
</templates>
4 changes: 4 additions & 0 deletions awesome_dashboard/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
'assets': {
'web.assets_backend': [
'awesome_dashboard/static/src/**/*',
('remove', 'awesome_dashboard/static/src/dashboard**/*'),
],
'awesome_dashboard.dashboard': [
'awesome_dashboard/static/src/dashboard/**/*'
],
},
'license': 'AGPL-3'
Expand Down
10 changes: 0 additions & 10 deletions awesome_dashboard/static/src/dashboard.js

This file was deleted.

8 changes: 0 additions & 8 deletions awesome_dashboard/static/src/dashboard.xml

This file was deleted.

96 changes: 96 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/** @odoo-module **/

import { Component, useState } from "@odoo/owl";
import { registry } from "@web/core/registry";
import { Layout } from "@web/search/layout";
import { useService } from "@web/core/utils/hooks";
import { DashboardItem } from "./dashboard_item/dashboard_item";
import { Dialog } from "@web/core/dialog/dialog";
import { CheckBox } from "@web/core/checkbox/checkbox";
import { browser } from "@web/core/browser/browser";

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

static props = {
display : {
controlPanel: {}
},
}

setup() {
this.action = useService("action");
this.result = useState(useService("awesome_dashboard.getStats"));
this.dialog = useService("dialog");
this.items = registry.category("awesome_dashboard").getAll();
this.state = useState({
disabledItems: browser.localStorage.getItem("disabledDashboardItems")?.split(",") || []
});
}

openConfiguration() {
this.dialog.add(ConfigurationDialog, {
items: this.items,
disabledItems: this.state.disabledItems,
onUpdateConfiguration: this.updateConfiguration.bind(this),
})
}

updateConfiguration(newDisabledItems) {
this.state.disabledItems = newDisabledItems;
}

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

async openActivity() {
this.action.doAction({
type: 'ir.actions.act_window',
name: 'Leads',
target: 'current',
res_model: 'crm.lead',
views: [[false, 'list'], [false, 'form']],
});
}
}

class ConfigurationDialog extends Component {
static template = "awesome_dashboard.ConfigurationDialog";
static components = { Dialog, CheckBox };
static props = ["close", "items", "disabledItems", "onUpdateConfiguration"];

setup() {
this.items = useState(this.props.items.map((item) => {
return {
...item,
enabled: !this.props.disabledItems.includes(item.id),
}
}));
}

done() {
this.props.close();
}

onChange(checked, changedItem) {
changedItem.enabled = checked;
const newDisabledItems = Object.values(this.items).filter(
(item) => !item.enabled
).map((item) => item.id)

browser.localStorage.setItem(
"disabledDashboardItems",
newDisabledItems,
);

this.props.onUpdateConfiguration(newDisabledItems);
}

}

registry.category("lazy_components").add("AwesomeDashboard", AwesomeDashboard);
7 changes: 7 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.o_dashboard {
background-color: grey;
}

.myBtnChange {
margin: 2rem;
}
41 changes: 41 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">

<t t-name="awesome_dashboard.AwesomeDashboard">
<t t-set-slot="control-panel-additional-actions">
<button t-on-click="openConfiguration" class="btn p-0 ms-1 border-0">
<i class="fa fa-cog"></i>
</button>
</t>
<div t-ref="root" class="h-100 d-flex flex-column">
<Layout className="'o_dashboard h-100'" display="props.display">
<button class="btn btn-primary myBtnChange" t-on-click="openCustomerKanban"> Open customer kanban </button>
<button class="btn btn-primary myBtnChange" t-on-click="openActivity"> Leads </button>
<div style="margin-left: 1rem; display: flex;">
<t t-foreach="items" t-as="item" t-key="item.id">
<DashboardItem t-if="!state.disabledItems.includes(item.id)" size="item.size">
<t t-set="itemProp" t-value="item.props ? item.props(result) : {'data': result}"/>
<t t-component="item.Component" t-props="itemProp" />
</DashboardItem>
</t>
</div>
</Layout>

</div>
</t>
<t t-name="awesome_dashboard.ConfigurationDialog">
<Dialog title="'Dashboard items configuration'">
Which cards do you whish to see ?
<t t-foreach="items" t-as="item" t-key="item.id">
<CheckBox value="item.enabled" onChange="(ev) => this.onChange(ev, item)">
<t t-esc="item.description"/>
</CheckBox>
</t>
<t t-set-slot="footer">
<button class="btn btn-primary" t-on-click="done">
Done
</button>
</t>
</Dialog>
</t>
</templates>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Component } from "@odoo/owl";

export class DashboardItem extends Component {
static template = "awesome_dashboard.DashboardItem";

static props = {
size: {
type: Number,
optional: true,
},
slots: {
type: Object,
optional: true,
},
}

static defaultProps = {
size: 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.box {
border: 30px black;
// border-color: black;
border-radius: 10px;
background-color: white;
margin: 1rem;
}
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_dashboard.DashboardItem">
<div class="p-3 box" t-att-style="'width: ' + 18 * props.size + 'rem;'">
<t t-slot="default" />
</div>
</t>

</templates>
Loading