mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
small cleanup
This commit is contained in:
@@ -52,3 +52,8 @@ body {
|
|||||||
padding: 0 5px;
|
padding: 0 5px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Discuss */
|
||||||
|
.o_discuss {
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ interface Subscription {
|
|||||||
/**
|
/**
|
||||||
* Simple event bus: it can emit events, and add/remove listeners.
|
* Simple event bus: it can emit events, and add/remove listeners.
|
||||||
*/
|
*/
|
||||||
export class Bus {
|
export class EventBus {
|
||||||
private subscriptions: { [eventType: string]: Subscription[] } = {};
|
private subscriptions: { [eventType: string]: Subscription[] } = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
import { Bus } from "../core/bus";
|
import { EventBus } from "../core/event_bus";
|
||||||
import { Widget } from "../core/widget";
|
import { Widget } from "../core/widget";
|
||||||
import { Env } from "../env";
|
import { Env } from "../env";
|
||||||
import { Router, Query } from "./router";
|
|
||||||
import { Discuss } from "../widgets/discuss";
|
|
||||||
import { CRM } from "../widgets/crm";
|
import { CRM } from "../widgets/crm";
|
||||||
|
import { Discuss } from "../widgets/discuss";
|
||||||
|
import { Query, Router } from "./router";
|
||||||
|
|
||||||
interface Type<T> extends Function {
|
interface Type<T> extends Function {
|
||||||
new (...args: any[]): T;
|
new (...args: any[]): T;
|
||||||
@@ -32,7 +32,7 @@ const actions: any[] = [
|
|||||||
{ id: 2, title: "CRM", Widget: CRM }
|
{ id: 2, title: "CRM", Widget: CRM }
|
||||||
];
|
];
|
||||||
|
|
||||||
export class ActionManager extends Bus {
|
export class ActionManager extends EventBus {
|
||||||
router: Router;
|
router: Router;
|
||||||
currentAction: ActionWidget | null = null;
|
currentAction: ActionWidget | null = null;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Bus } from "../core/bus";
|
import { EventBus } from "../core/event_bus";
|
||||||
|
|
||||||
export type Query = { [key: string]: string };
|
export type Query = { [key: string]: string };
|
||||||
|
|
||||||
@@ -6,7 +6,7 @@ function clearSlashes(s: string): string {
|
|||||||
return s.replace(/\/$/, "").replace(/^\//, "");
|
return s.replace(/\/$/, "").replace(/^\//, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Router extends Bus {
|
export class Router extends EventBus {
|
||||||
currentQuery: Query;
|
currentQuery: Query;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ const template = `
|
|||||||
<span class="title">Odoo</span>
|
<span class="title">Odoo</span>
|
||||||
<ul>
|
<ul>
|
||||||
<li t-foreach="env.menus" t-as="menu">
|
<li t-foreach="env.menus" t-as="menu">
|
||||||
<a t-on-click="activateMenu(menu)" t-att-href="getUrl(menu)">
|
<a t-att-href="getUrl(menu)">
|
||||||
<t t-esc="menu.title"/>
|
<t t-esc="menu.title"/>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
@@ -22,9 +22,4 @@ export class Navbar extends Widget<Env> {
|
|||||||
const action_id = String(menu.actionID);
|
const action_id = String(menu.actionID);
|
||||||
return this.env.router.formatURL("", { action_id });
|
return this.env.router.formatURL("", { action_id });
|
||||||
}
|
}
|
||||||
|
|
||||||
activateMenu(menu: Menu, event: MouseEvent) {
|
|
||||||
event.preventDefault();
|
|
||||||
this.env.actionManager.doAction(menu.actionID);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { Widget } from "../core/widget";
|
import { Widget } from "../core/widget";
|
||||||
import { Navbar } from "./navbar";
|
import { Navbar } from "./navbar";
|
||||||
import { ActionWidget } from "../services/action_manager";
|
import { ActionWidget } from "../services/action_manager";
|
||||||
// import { Action } from "../services/actions";
|
|
||||||
import { Env } from "../env";
|
import { Env } from "../env";
|
||||||
|
|
||||||
const template = `
|
const template = `
|
||||||
@@ -35,25 +34,4 @@ export class RootWidget extends Widget<Env> {
|
|||||||
}
|
}
|
||||||
this.content = newWidget;
|
this.content = newWidget;
|
||||||
}
|
}
|
||||||
|
|
||||||
// onUrlChange() {
|
|
||||||
// this.setMainWidget();
|
|
||||||
// // notice that this can only be safely done because the root widget is
|
|
||||||
// // mounted now.
|
|
||||||
// this.render();
|
|
||||||
// }
|
|
||||||
|
|
||||||
// getAction(): Action {
|
|
||||||
// const routeInfo = this.env.router.getRoute();
|
|
||||||
// const actionID = parseInt(routeInfo.query.action_id);
|
|
||||||
// let actions: Action[] = this.env.actions;
|
|
||||||
// let action = actions.find(a => a.id === actionID);
|
|
||||||
// if (!action) {
|
|
||||||
// action = actions.find(a => a.default === true);
|
|
||||||
// if (!action) {
|
|
||||||
// throw new Error("No valid action!");
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return action;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { Bus } from "../src/ts/core/bus";
|
import { EventBus } from "../src/ts/core/event_bus";
|
||||||
|
|
||||||
describe("event bus behaviour", () => {
|
describe("event bus behaviour", () => {
|
||||||
test("can subscribe and be notified", () => {
|
test("can subscribe and be notified", () => {
|
||||||
const bus = new Bus();
|
const bus = new EventBus();
|
||||||
let notified = false;
|
let notified = false;
|
||||||
bus.on("event", {}, () => (notified = true));
|
bus.on("event", {}, () => (notified = true));
|
||||||
expect(notified).toBe(false);
|
expect(notified).toBe(false);
|
||||||
@@ -12,7 +12,7 @@ describe("event bus behaviour", () => {
|
|||||||
|
|
||||||
test("callbacks are called with proper 'this'", () => {
|
test("callbacks are called with proper 'this'", () => {
|
||||||
expect.assertions(1);
|
expect.assertions(1);
|
||||||
const bus = new Bus();
|
const bus = new EventBus();
|
||||||
const owner = {};
|
const owner = {};
|
||||||
bus.on("event", owner, function(this: any) {
|
bus.on("event", owner, function(this: any) {
|
||||||
expect(this).toBe(owner);
|
expect(this).toBe(owner);
|
||||||
@@ -21,7 +21,7 @@ describe("event bus behaviour", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("can unsubscribe", () => {
|
test("can unsubscribe", () => {
|
||||||
const bus = new Bus();
|
const bus = new EventBus();
|
||||||
let notified = false;
|
let notified = false;
|
||||||
let owner = {};
|
let owner = {};
|
||||||
bus.on("event", owner, () => (notified = true));
|
bus.on("event", owner, () => (notified = true));
|
||||||
@@ -32,7 +32,7 @@ describe("event bus behaviour", () => {
|
|||||||
|
|
||||||
test("arguments are properly propagated", () => {
|
test("arguments are properly propagated", () => {
|
||||||
expect.assertions(1);
|
expect.assertions(1);
|
||||||
const bus = new Bus();
|
const bus = new EventBus();
|
||||||
bus.on("event", {}, (arg: any) => expect(arg).toBe("hello world"));
|
bus.on("event", {}, (arg: any) => expect(arg).toBe("hello world"));
|
||||||
bus.trigger("event", "hello world");
|
bus.trigger("event", "hello world");
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user