Extracted Duration from sprinklers
This commit is contained in:
parent
8ea82950fa
commit
3ce9bb4116
@ -1,7 +1,7 @@
|
|||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { Input, InputProps } from "semantic-ui-react";
|
import { Input, InputProps } from "semantic-ui-react";
|
||||||
|
|
||||||
import { Duration } from "@common/sprinklers";
|
import { Duration } from "@common/Duration";
|
||||||
|
|
||||||
export default class DurationInput extends React.Component<{
|
export default class DurationInput extends React.Component<{
|
||||||
duration: Duration,
|
duration: Duration,
|
||||||
|
@ -2,6 +2,7 @@ import { observer } from "mobx-react";
|
|||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { Table } from "semantic-ui-react";
|
import { Table } from "semantic-ui-react";
|
||||||
|
|
||||||
|
import { Duration } from "@common/Duration";
|
||||||
import { Program, Schedule } from "@common/sprinklers";
|
import { Program, Schedule } from "@common/sprinklers";
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
@ -20,10 +21,12 @@ export default class ProgramTable extends React.Component<{ programs: Program[]
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const { name, running, enabled, schedule, sequence } = program;
|
const { name, running, enabled, schedule, sequence } = program;
|
||||||
const sequenceItems = sequence.map((item, index) => (
|
const sequenceItems = sequence.map((item, index) => {
|
||||||
<li key={index}>Section {item.section + 1 + ""} for
|
const duration = Duration.fromSeconds(item.duration);
|
||||||
{item.duration.minutes}M {item.duration.seconds}S</li>
|
return (
|
||||||
));
|
<li key={index}>Section {item.section + 1 + ""} for {duration.toString()}</li>
|
||||||
|
);
|
||||||
|
});
|
||||||
return [(
|
return [(
|
||||||
<Table.Row key={i}>
|
<Table.Row key={i}>
|
||||||
<Table.Cell className="program--number">{"" + (i + 1)}</Table.Cell>
|
<Table.Cell className="program--number">{"" + (i + 1)}</Table.Cell>
|
||||||
|
@ -3,8 +3,9 @@ import { observer } from "mobx-react";
|
|||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { DropdownItemProps, DropdownProps, Form, Header, Segment } from "semantic-ui-react";
|
import { DropdownItemProps, DropdownProps, Form, Header, Segment } from "semantic-ui-react";
|
||||||
|
|
||||||
|
import { Duration } from "@common/Duration";
|
||||||
import log from "@common/logger";
|
import log from "@common/logger";
|
||||||
import { Duration, Section } from "@common/sprinklers";
|
import { Section } from "@common/sprinklers";
|
||||||
import DurationInput from "./DurationInput";
|
import DurationInput from "./DurationInput";
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
@ -17,7 +18,7 @@ export default class RunSectionForm extends React.Component<{
|
|||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.state = {
|
this.state = {
|
||||||
duration: new Duration(1, 1),
|
duration: new Duration(0, 0),
|
||||||
section: "",
|
section: "",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -67,7 +68,7 @@ export default class RunSectionForm extends React.Component<{
|
|||||||
}
|
}
|
||||||
const section: Section = this.props.sections[this.state.section];
|
const section: Section = this.props.sections[this.state.section];
|
||||||
const { duration } = this.state;
|
const { duration } = this.state;
|
||||||
section.run(duration)
|
section.run(duration.toSeconds())
|
||||||
.then((result) => log.debug({ result }, "requested section run"))
|
.then((result) => log.debug({ result }, "requested section run"))
|
||||||
.catch((err) => log.error(err, "error running section"));
|
.catch((err) => log.error(err, "error running section"));
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,14 @@
|
|||||||
import { observable } from "mobx";
|
import { observable } from "mobx";
|
||||||
import { Duration } from "./Duration";
|
|
||||||
import { Schedule } from "./schedule";
|
import { Schedule } from "./schedule";
|
||||||
import { SprinklersDevice } from "./SprinklersDevice";
|
import { SprinklersDevice } from "./SprinklersDevice";
|
||||||
|
|
||||||
export class ProgramItem {
|
export class ProgramItem {
|
||||||
// the section number
|
// the section number
|
||||||
readonly section: number;
|
readonly section: number;
|
||||||
// duration of the run
|
// duration of the run, in seconds
|
||||||
readonly duration: Duration;
|
readonly duration: number;
|
||||||
|
|
||||||
constructor(section: number = 0, duration: Duration = new Duration()) {
|
constructor(section: number = 0, duration: number = 0) {
|
||||||
this.section = section;
|
this.section = section;
|
||||||
this.duration = duration;
|
this.duration = duration;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import { observable } from "mobx";
|
import { observable } from "mobx";
|
||||||
import { Duration } from "./Duration";
|
|
||||||
import { SprinklersDevice } from "./SprinklersDevice";
|
import { SprinklersDevice } from "./SprinklersDevice";
|
||||||
|
|
||||||
export class Section {
|
export class Section {
|
||||||
@ -14,7 +13,8 @@ export class Section {
|
|||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
run(duration: Duration) {
|
/** duration is in seconds */
|
||||||
|
run(duration: number) {
|
||||||
return this.device.runSection({ sectionId: this.id, duration });
|
return this.device.runSection({ sectionId: this.id, duration });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
import { observable } from "mobx";
|
import { observable } from "mobx";
|
||||||
import { Duration } from "./Duration";
|
|
||||||
import { SprinklersDevice } from "./SprinklersDevice";
|
import { SprinklersDevice } from "./SprinklersDevice";
|
||||||
|
|
||||||
export class SectionRun {
|
export class SectionRun {
|
||||||
readonly sectionRunner: SectionRunner;
|
readonly sectionRunner: SectionRunner;
|
||||||
readonly id: number;
|
readonly id: number;
|
||||||
section: number;
|
section: number;
|
||||||
duration: Duration = new Duration();
|
duration: number = 0;
|
||||||
startTime: Date | null = null;
|
startTime: Date | null = null;
|
||||||
pauseTime: Date | null = null;
|
pauseTime: Date | null = null;
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
export * from "./Duration";
|
// export * from "./Duration";
|
||||||
export * from "./ISprinklersApi";
|
export * from "./ISprinklersApi";
|
||||||
export * from "./Program";
|
export * from "./Program";
|
||||||
export * from "./schedule";
|
export * from "./schedule";
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
import { Duration } from "./Duration";
|
|
||||||
|
|
||||||
export interface WithType<Type extends string = string> {
|
export interface WithType<Type extends string = string> {
|
||||||
type: Type;
|
type: Type;
|
||||||
}
|
}
|
||||||
@ -15,7 +13,7 @@ export type UpdateProgramResponse = Response<"updateProgram", { data: any }>;
|
|||||||
|
|
||||||
export interface WithSection { sectionId: number; }
|
export interface WithSection { sectionId: number; }
|
||||||
|
|
||||||
export type RunSectionData = WithSection & { duration: Duration };
|
export type RunSectionData = WithSection & { duration: number };
|
||||||
export type RunSectionReqeust = RunSectionData & WithType<"runSection">;
|
export type RunSectionReqeust = RunSectionData & WithType<"runSection">;
|
||||||
export type RunSectionResponse = Response<"runSection", { runId: number }>;
|
export type RunSectionResponse = Response<"runSection", { runId: number }>;
|
||||||
|
|
||||||
|
@ -3,17 +3,7 @@ import {
|
|||||||
} from "serializr";
|
} from "serializr";
|
||||||
import * as s from "..";
|
import * as s from "..";
|
||||||
|
|
||||||
export const duration: PropSchema = {
|
export const duration: PropSchema = primitive();
|
||||||
serializer: (d: s.Duration | null) =>
|
|
||||||
d != null ? d.toSeconds() : null,
|
|
||||||
deserializer: (json: any, done) => {
|
|
||||||
if (typeof json === "number") {
|
|
||||||
done(null, s.Duration.fromSeconds(json));
|
|
||||||
} else {
|
|
||||||
done(new Error(`Duration expects a number, not ${json}`), undefined);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
export const date: PropSchema = {
|
export const date: PropSchema = {
|
||||||
serializer: (jsDate: Date | null) => jsDate != null ?
|
serializer: (jsDate: Date | null) => jsDate != null ?
|
||||||
|
Loading…
x
Reference in New Issue
Block a user