MainWidget.tsx
77 lines
| 2.5 KiB
| text/x-typescript
|
TypeScriptLexer
cin
|
r107 | import { djbase, djclass } from "@implab/djx/declare"; | ||
import { DjxWidgetBase } from "@implab/djx/tsx/DjxWidgetBase"; | ||||
cin
|
r134 | import { attach, bind, createElement, prop, watch, watchFor } from "@implab/djx/tsx"; | ||
cin
|
r110 | import MainModel from "../model/MainModel"; | ||
cin
|
r116 | import { Observable } from "@implab/djx/observable"; | ||
import { OrderedUpdate } from "@implab/djx/store"; | ||||
cin
|
r110 | import { Appointment } from "../model/Appointment"; | ||
import { LocalDate } from "@js-joda/core"; | ||||
cin
|
r107 | import Button = require("dijit/form/Button"); | ||
cin
|
r134 | import NewAppointment from "./NewAppointment"; | ||
cin
|
r109 | |||
cin
|
r107 | @djclass | ||
export default class MainWidget extends djbase(DjxWidgetBase) { | ||||
cin
|
r116 | appointments?: Observable<OrderedUpdate<Appointment>>; | ||
cin
|
r110 | |||
model: MainModel; | ||||
cin
|
r107 | |||
cin
|
r110 | dateTo?: LocalDate; | ||
cin
|
r107 | |||
cin
|
r110 | dateFrom?: LocalDate; | ||
cin
|
r107 | |||
cin
|
r134 | toolbarNode?: HTMLDivElement; | ||
cin
|
r110 | constructor(opts?: Partial<MainWidget> & ThisType<MainWidget>, srcNode?: string | Node) { | ||
super(opts, srcNode); | ||||
cin
|
r107 | |||
cin
|
r110 | const model = this.model = new MainModel(); | ||
this.own(model); | ||||
model.subscribe({ next: x => this.set(x) }); | ||||
} | ||||
cin
|
r107 | |||
render() { | ||||
return <div className="tundra"> | ||||
cin
|
r110 | <h2 ref={bind("innerHTML", prop(this, "title"))} /> | ||
{watch(prop(this, "appointments"), items => items && | ||||
<ul> | ||||
{watchFor(items, ({ id, title, getMembers }) => | ||||
<li>{title} | ||||
<ul> | ||||
{watchFor(getMembers(), ({ role, name, position }) => | ||||
<li className={role}>{name}({position})</li> | ||||
)} | ||||
</ul> | ||||
<div> | ||||
<Button onClick={() => this._onAddMemberClick(id)}>Add member</Button> | ||||
</div> | ||||
</li> | ||||
)} | ||||
</ul> | ||||
)} | ||||
cin
|
r134 | <NewAppointment/> | ||
<div ref={attach(this, "toolbarNode")}> | ||||
cin
|
r110 | <Button onClick={this._onAddAppointmentClick}>Add new appointment</Button> | ||
</div> | ||||
cin
|
r107 | </div>; | ||
} | ||||
cin
|
r110 | load() { | ||
this.model.load(); | ||||
cin
|
r107 | } | ||
cin
|
r110 | private readonly _onAddMemberClick = (appointmentId: string) => { | ||
this.model.addMember(appointmentId, { | ||||
email: "some-mail", | ||||
name: "Member Name", | ||||
position: "Member position", | ||||
role: "participant" | ||||
}); | ||||
cin
|
r109 | }; | ||
cin
|
r107 | |||
cin
|
r110 | private readonly _onAddAppointmentClick = () => { | ||
this.model.addAppointment("Appointment", new Date, 30); | ||||
cin
|
r109 | }; | ||
cin
|
r107 | } | ||