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;
|
||||
}
|
||||
}
|
||||
|
||||
/* Discuss */
|
||||
.o_discuss {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ interface Subscription {
|
||||
/**
|
||||
* Simple event bus: it can emit events, and add/remove listeners.
|
||||
*/
|
||||
export class Bus {
|
||||
export class EventBus {
|
||||
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 { Env } from "../env";
|
||||
import { Router, Query } from "./router";
|
||||
import { Discuss } from "../widgets/discuss";
|
||||
import { CRM } from "../widgets/crm";
|
||||
import { Discuss } from "../widgets/discuss";
|
||||
import { Query, Router } from "./router";
|
||||
|
||||
interface Type<T> extends Function {
|
||||
new (...args: any[]): T;
|
||||
@@ -32,7 +32,7 @@ const actions: any[] = [
|
||||
{ id: 2, title: "CRM", Widget: CRM }
|
||||
];
|
||||
|
||||
export class ActionManager extends Bus {
|
||||
export class ActionManager extends EventBus {
|
||||
router: Router;
|
||||
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 };
|
||||
|
||||
@@ -6,7 +6,7 @@ function clearSlashes(s: string): string {
|
||||
return s.replace(/\/$/, "").replace(/^\//, "");
|
||||
}
|
||||
|
||||
export class Router extends Bus {
|
||||
export class Router extends EventBus {
|
||||
currentQuery: Query;
|
||||
|
||||
constructor() {
|
||||
|
||||
@@ -6,7 +6,7 @@ const template = `
|
||||
<span class="title">Odoo</span>
|
||||
<ul>
|
||||
<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"/>
|
||||
</a>
|
||||
</li>
|
||||
@@ -22,9 +22,4 @@ export class Navbar extends Widget<Env> {
|
||||
const action_id = String(menu.actionID);
|
||||
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 { Navbar } from "./navbar";
|
||||
import { ActionWidget } from "../services/action_manager";
|
||||
// import { Action } from "../services/actions";
|
||||
import { Env } from "../env";
|
||||
|
||||
const template = `
|
||||
@@ -35,25 +34,4 @@ export class RootWidget extends Widget<Env> {
|
||||
}
|
||||
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", () => {
|
||||
test("can subscribe and be notified", () => {
|
||||
const bus = new Bus();
|
||||
const bus = new EventBus();
|
||||
let notified = false;
|
||||
bus.on("event", {}, () => (notified = true));
|
||||
expect(notified).toBe(false);
|
||||
@@ -12,7 +12,7 @@ describe("event bus behaviour", () => {
|
||||
|
||||
test("callbacks are called with proper 'this'", () => {
|
||||
expect.assertions(1);
|
||||
const bus = new Bus();
|
||||
const bus = new EventBus();
|
||||
const owner = {};
|
||||
bus.on("event", owner, function(this: any) {
|
||||
expect(this).toBe(owner);
|
||||
@@ -21,7 +21,7 @@ describe("event bus behaviour", () => {
|
||||
});
|
||||
|
||||
test("can unsubscribe", () => {
|
||||
const bus = new Bus();
|
||||
const bus = new EventBus();
|
||||
let notified = false;
|
||||
let owner = {};
|
||||
bus.on("event", owner, () => (notified = true));
|
||||
@@ -32,7 +32,7 @@ describe("event bus behaviour", () => {
|
||||
|
||||
test("arguments are properly propagated", () => {
|
||||
expect.assertions(1);
|
||||
const bus = new Bus();
|
||||
const bus = new EventBus();
|
||||
bus.on("event", {}, (arg: any) => expect(arg).toBe("hello world"));
|
||||
bus.trigger("event", "hello world");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user