Skip to content

18.0 training mdoy #817

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

Draft
wants to merge 4 commits into
base: 18.0
Choose a base branch
from
Draft
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,6 @@ dmypy.json

# Pyre type checker
.pyre/

# Ruff configuration
ruff.toml
15 changes: 15 additions & 0 deletions awesome_clicker/static/src/clicker_action/clicker_client_action.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Component, useState } from "@odoo/owl";
import { registry } from "@web/core/registry";
import { useClicker } from "../clicker_hook";
import { ClickerValue } from "../clicker_value/clicker_value";

class ClickerClientAction extends Component {
static template = "awesome_clicker.ClickerClientAction";
static components = { ClickerValue };

setup() {
this.clickerService = useClicker();
}
}

registry.category("actions").add("awesome_clicker.clicker_client_action", ClickerClientAction);
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-name="awesome_clicker.ClickerClientAction">
<span class="me-2">
Clicks: <ClickerValue />
</span>
<button class="btn btn-primary" t-on-click="() => clickerService.increment(500)">Increment</button>
<h3>Bots</h3>
<div class="d-flex flex-row">
<div class="card">
<div t-if="clickerService.bots.clickBot.purchased">
<div class="card-header">
<t t-esc="clickerService.bots.clickBot.purchased" />x ClickBots (10 clicks/10 seconds)
<i class="fa fa-android"></i>
</div>
</div>
<div class="card-body">
<button class="btn btn-primary" t-on-click="() => clickerService.buyBot('clickBot')" t-att-disabled="clickerService.clicks lt 1000">Buy ClickBot (1000 clicks)</button>
</div>
</div>

<div class="card" t-if="clickerService.level gte 2">
<div t-if="clickerService.bots.bigBot.purchased">
<div class="card-header">
<t t-esc="clickerService.bots.bigBot.purchased" />x bigBots (100 clicks/10 seconds)
<i class="fa fa-android"></i>
</div>
</div>
<div class="card-body">
<button class="btn btn-primary" t-on-click="() => clickerService.buyBot('bigBot')" t-att-disabled="clickerService.clicks lt 5000">Buy BigBot (5000 clicks)</button>
</div>
</div>
</div>
</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 { useState } from "@odoo/owl";
import { useService } from "@web/core/utils/hooks";

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

export const getCount = {
dependencies: ["effect"],
start(env, services) {
const clicker = new ClickerModel();

setInterval(() => {
clicker.tick();
}, 10000)

const bus = clicker.bus
bus.addEventListener("MILESTONE", (ev) => {
services.effect.add({
message: `Milestone reached! You can now buy ${ev.detail}!`,
type: "rainbow_man",
})
})

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

return clicker;
}
}

registry.category("services").add("awesome_clicker.count", getCount);
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { registry } from "@web/core/registry";
import { Component } from "@odoo/owl";
import { useService } from "@web/core/utils/hooks";
import { useClicker } from "../clicker_hook";
import { ClickerValue } from "../clicker_value/clicker_value";

export class ClickerSystray extends Component {
static template = "awesome_clicker.ClickerSystray";
static components = { ClickerValue };

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

openClientAction() {
this.action.doAction({
type: "ir.actions.client",
tag: "awesome_clicker.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,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-name="awesome_clicker.ClickerSystray">
<div class="o_nav_entry">
<div class="me-2">
Clicks: <ClickerValue />
</div>
<button class="btn btn-secondary me-2" t-on-click="() => this.counterService.increment(9)">
<i class="fa fa-lg fa-plus"></i>
</button>
<button class="btn btn-secondary" t-on-click="openClientAction">
Open
</button>
</div>
</t>
</templates>
17 changes: 17 additions & 0 deletions awesome_clicker/static/src/clicker_value/clicker_value.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Component } from "@odoo/owl";
import { useClicker } from "../clicker_hook";
import { humanNumber } from "@web/core/utils/numbers";

export class ClickerValue extends Component {
static template = "awesome_clicker.ClickerValue";

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

get getClicks() {
return humanNumber(this.clicker.clicks, {
decimals: 1,
});
}
}
6 changes: 6 additions & 0 deletions awesome_clicker/static/src/clicker_value/clicker_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.ClickerValue">
<span t-esc="getClicks" t-att-data-tooltip="clicker.clicks" />
</t>
</templates>
61 changes: 61 additions & 0 deletions awesome_clicker/static/src/model/clicker_model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { Reactive } from "@web/core/utils/reactive";
import { EventBus } from "@odoo/owl";

export class ClickerModel extends Reactive {

constructor() {
super();
this.clicks = 0;
this.level = 0;
this.bus = new EventBus();
this.bots = {
clickBot: {
price: 1000,
level: 1,
increment: 10,
purchased: 0,
},
bigBot: {
price: 5000,
level: 2,
increment: 100,
purchased: 0,
},
}
}

increment(value) {
this.clicks += value;

if (this.milestones[this.level] && this.clicks >= this.milestones[this.level].clicks) {
this.bus.trigger("MILESTONE", this.milestones[this.level].unlock);
this.level++;
}
}

buyBot(name) {
if (!Object.keys(this.bots).includes(name)) {
throw new Error(`Invalid bot name ${name}`)
}

if (this.clicks < this.bots[name].price) {
return false;
}

this.clicks -= this.bots[name].price;
this.bots[name].purchased += 1;
}

tick() {
for (const bot in this.bots) {
this.increment(this.bots[bot].purchased * this.bots[bot].increment);
}
}

get milestones() {
return [
{ clicks: 1000, unlock: "clickbots" },
{ clicks: 5000, unlock: "bigbots" },
];
}
}
8 changes: 6 additions & 2 deletions awesome_dashboard/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@
'version': '0.1',
'application': True,
'installable': True,
'depends': ['base', 'web', 'mail', 'crm'],
'depends': ['base', 'web', 'mail', 'crm', 'sale'],

'data': [
'views/views.xml',
],
'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'
'license': 'AGPL-3',
}
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.

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

import { _t } from "@web/core/l10n/translation";
import { Component, useState } from "@odoo/owl";
import { registry } from "@web/core/registry";
import { Layout } from "@web/search/layout";
import { PieChart } from "./pie_chart/pie_chart";
import { DashboardItem } from "./dashboard_item";
import { useService } from "@web/core/utils/hooks";
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 = { DashboardItem, Layout, PieChart };

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

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

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

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

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

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);
3 changes: 3 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.o_dashboard {
background-color: gray;
}
Loading