make widget generic on State

This commit is contained in:
Géry Debongnie
2019-02-04 21:09:17 +01:00
parent 70b25fc7b8
commit 05e9797f7a
16 changed files with 161 additions and 107 deletions
+2 -3
View File
@@ -1,6 +1,5 @@
import { Widget } from "../core/widget";
import { Env } from "../env";
import { Widget } from "./widget";
export class CRM extends Widget<Env, {}> {
export class CRM extends Widget<{}, {}> {
template = "web.crm";
}
+16 -4
View File
@@ -1,22 +1,34 @@
import { Widget } from "../core/widget";
import { Env } from "../env";
import { Widget } from "./widget";
//------------------------------------------------------------------------------
// Types
//------------------------------------------------------------------------------
interface Props {
initialState?: number;
}
export class Counter extends Widget<Env, Props> {
interface State {
counter: number;
}
//------------------------------------------------------------------------------
// Counter
//------------------------------------------------------------------------------
export class Counter extends Widget<Props, State> {
inlineTemplate = `
<div t-name="counter">
<button t-on-click="increment(-1)">-</button>
<span style="font-weight:bold">Value: <t t-esc="state.counter"/></span>
<button t-on-click="increment(1)">+</button>
</div>`;
state = {
counter: 0
};
constructor(parent: Widget<Env, {}>, props: Props) {
constructor(parent: Widget<any, any>, props: Props) {
super(parent, props);
this.state.counter = props.initialState || 0;
}
+16 -4
View File
@@ -1,9 +1,21 @@
import { Widget } from "../core/widget";
import { Env } from "../env";
import { Clock } from "./clock";
import { Counter } from "./counter";
import { Widget } from "./widget";
export class Discuss extends Widget<Env, {}> {
//------------------------------------------------------------------------------
// Types
//------------------------------------------------------------------------------
interface State {
validcounter: boolean;
color: "red" | "blue";
}
//------------------------------------------------------------------------------
// Discuss
//------------------------------------------------------------------------------
export class Discuss extends Widget<{}, State> {
template = "web.discuss";
widgets = { Clock, Counter, ColorWidget };
state = { validcounter: true, color: "red" };
@@ -38,7 +50,7 @@ export class Discuss extends Widget<Env, {}> {
}
}
class ColorWidget extends Widget<Env, { color: "red" | "blue" }> {
class ColorWidget extends Widget<{ color: "red" | "blue" }, {}> {
inlineTemplate = `
<div t-name="colorwidget">
<span>Current Color: </span>
+11 -3
View File
@@ -1,13 +1,21 @@
import { Widget } from "../core/widget";
import { Env, Menu } from "../env";
import { Menu } from "../env";
import { MenuItem } from "../misc/menu_helpers";
import { Widget } from "./widget";
//------------------------------------------------------------------------------
// Types
//------------------------------------------------------------------------------
export interface Props {
inHome: boolean;
app: MenuItem | null;
}
export class Navbar extends Widget<Env, Props> {
//------------------------------------------------------------------------------
// Navbar
//------------------------------------------------------------------------------
export class Navbar extends Widget<Props, {}> {
template = "web.navbar";
getUrl(menu: Menu) {
+10 -3
View File
@@ -1,12 +1,19 @@
import { Widget } from "../core/widget";
import { Env } from "../env";
import { ActionStack } from "../services/action_manager";
import { Widget } from "./widget";
//------------------------------------------------------------------------------
// Types
//------------------------------------------------------------------------------
export interface Props {
stack: ActionStack;
}
export class ActionContainer extends Widget<Env, Props> {
//------------------------------------------------------------------------------
// Action Container
//------------------------------------------------------------------------------
export class ActionContainer extends Widget<Props, {}> {
template = "web.action_container";
currentWidget: any;
+14 -3
View File
@@ -1,7 +1,18 @@
import { Widget } from "../core/widget";
import { Env } from "../env";
import { Widget } from "./widget";
export class Clock extends Widget<Env, {}> {
//------------------------------------------------------------------------------
// Types
//------------------------------------------------------------------------------
interface State {
currentTime: string;
}
//------------------------------------------------------------------------------
// Clock
//------------------------------------------------------------------------------
export class Clock extends Widget<{}, State> {
inlineTemplate = `<div class="o_clock"><t t-esc="state.currentTime"/></div>`;
timeout: any | undefined;
+2 -3
View File
@@ -1,6 +1,5 @@
import { Widget } from "../core/widget";
import { Env } from "../env";
import { MenuInfo, MenuItem } from "../misc/menu_helpers";
import { Widget } from "./widget";
//------------------------------------------------------------------------------
// Types
@@ -14,7 +13,7 @@ export interface Props {
// Home Menu
//------------------------------------------------------------------------------
export class HomeMenu extends Widget<Env, Props> {
export class HomeMenu extends Widget<Props, {}> {
template = "web.home_menu";
get apps(): MenuItem[] {
+2 -3
View File
@@ -1,8 +1,7 @@
import { Widget } from "../core/widget";
import { Env } from "../env";
import { INotification } from "../core/notifications";
import { Widget } from "./widget";
export class Notification extends Widget<Env, INotification> {
export class Notification extends Widget<INotification, {}> {
template = "web.notification";
close() {
+2 -2
View File
@@ -1,5 +1,5 @@
import { INotification } from "../core/notifications";
import { Widget } from "../core/widget";
import { Widget } from "./widget";
import { Env } from "../env";
import { MenuInfo, MenuItem, getAppAndAction } from "../misc/menu_helpers";
import { ActionStack } from "../services/action_manager";
@@ -28,7 +28,7 @@ interface Props {
// Root Widget
//------------------------------------------------------------------------------
export class Root extends Widget<Env, Props> {
export class Root extends Widget<Props, State> {
template = "web.web_client";
widgets = { Navbar, Notification, HomeMenu, ActionContainer };
+4
View File
@@ -0,0 +1,4 @@
import { BaseWidget } from "../core/base_widget";
import { Env } from "../env";
export class Widget<Props, State> extends BaseWidget<Env, Props, State> {}