small cleanup

This commit is contained in:
Géry Debongnie
2019-01-24 13:17:40 +01:00
parent c6b83b1aed
commit 3415d830c7
7 changed files with 18 additions and 40 deletions
+5
View File
@@ -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[] } = {};
/**
+4 -4
View File
@@ -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;
+2 -2
View File
@@ -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() {
+1 -6
View File
@@ -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);
}
}
-22
View File
@@ -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;
// }
}
+5 -5
View File
@@ -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");
});