MainWidget.tsx
72 lines
| 2.3 KiB
| text/x-typescript
|
TypeScriptLexer
|
|
r107 | import { djbase, djclass } from "@implab/djx/declare"; | ||
| import { DjxWidgetBase } from "@implab/djx/tsx/DjxWidgetBase"; | ||||
|
|
r110 | import { bind, createElement, prop, watch, watchFor } from "@implab/djx/tsx"; | ||
| import MainModel from "../model/MainModel"; | ||||
| import { OrderUpdate, Observable } from "@implab/djx/observable"; | ||||
| import { Appointment } from "../model/Appointment"; | ||||
| import { LocalDate } from "@js-joda/core"; | ||||
|
|
r107 | import Button = require("dijit/form/Button"); | ||
|
|
r109 | |||
|
|
r107 | @djclass | ||
| export default class MainWidget extends djbase(DjxWidgetBase) { | ||||
|
|
r110 | appointments?: Observable<OrderUpdate<Appointment>>; | ||
| model: MainModel; | ||||
|
|
r107 | |||
|
|
r110 | dateTo?: LocalDate; | ||
|
|
r107 | |||
|
|
r110 | dateFrom?: LocalDate; | ||
|
|
r107 | |||
|
|
r110 | constructor(opts?: Partial<MainWidget> & ThisType<MainWidget>, srcNode?: string | Node) { | ||
| super(opts, srcNode); | ||||
|
|
r107 | |||
|
|
r110 | const model = this.model = new MainModel(); | ||
| this.own(model); | ||||
| model.subscribe({ next: x => this.set(x) }); | ||||
| } | ||||
|
|
r107 | |||
| render() { | ||||
| return <div className="tundra"> | ||||
|
|
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> | ||||
| )} | ||||
| <div> | ||||
| <Button onClick={this._onAddAppointmentClick}>Add new appointment</Button> | ||||
| </div> | ||||
|
|
r107 | </div>; | ||
| } | ||||
|
|
r110 | load() { | ||
| this.model.load(); | ||||
|
|
r107 | } | ||
|
|
r110 | private readonly _onAddMemberClick = (appointmentId: string) => { | ||
| this.model.addMember(appointmentId, { | ||||
| email: "some-mail", | ||||
| name: "Member Name", | ||||
| position: "Member position", | ||||
| role: "participant" | ||||
| }); | ||||
|
|
r109 | }; | ||
|
|
r107 | |||
|
|
r110 | private readonly _onAddAppointmentClick = () => { | ||
| this.model.addAppointment("Appointment", new Date, 30); | ||||
|
|
r109 | }; | ||
|
|
r107 | } | ||
