|
|
@ -20,8 +20,9 @@ import { AppState, injectState } from "@client/state"; |
|
|
|
import { ISprinklersDevice } from "@common/httpApi"; |
|
|
|
import { ISprinklersDevice } from "@common/httpApi"; |
|
|
|
import log from "@common/logger"; |
|
|
|
import log from "@common/logger"; |
|
|
|
import { Program, SprinklersDevice } from "@common/sprinklersRpc"; |
|
|
|
import { Program, SprinklersDevice } from "@common/sprinklersRpc"; |
|
|
|
import { action } from "mobx"; |
|
|
|
|
|
|
|
import classNames = require("classnames"); |
|
|
|
import classNames = require("classnames"); |
|
|
|
|
|
|
|
import { action } from "mobx"; |
|
|
|
|
|
|
|
import * as moment from "moment"; |
|
|
|
|
|
|
|
|
|
|
|
interface ProgramPageProps |
|
|
|
interface ProgramPageProps |
|
|
|
extends RouteComponentProps<{ deviceId: string; programId: string }> { |
|
|
|
extends RouteComponentProps<{ deviceId: string; programId: string }> { |
|
|
@ -186,7 +187,6 @@ class ProgramPage extends React.Component<ProgramPageProps> { |
|
|
|
toggle |
|
|
|
toggle |
|
|
|
label="Enabled" |
|
|
|
label="Enabled" |
|
|
|
checked={enabled} |
|
|
|
checked={enabled} |
|
|
|
readOnly={!editing} |
|
|
|
|
|
|
|
onChange={this.onEnabledChange} |
|
|
|
onChange={this.onEnabledChange} |
|
|
|
/> |
|
|
|
/> |
|
|
|
<Form.Checkbox |
|
|
|
<Form.Checkbox |
|
|
@ -211,6 +211,16 @@ class ProgramPage extends React.Component<ProgramPageProps> { |
|
|
|
editing={editing} |
|
|
|
editing={editing} |
|
|
|
label={<h4>Schedule</h4>} |
|
|
|
label={<h4>Schedule</h4>} |
|
|
|
/> |
|
|
|
/> |
|
|
|
|
|
|
|
{ !editing && ( |
|
|
|
|
|
|
|
<h4 className="program--nextRun">Next run: </h4>) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
!editing && ( |
|
|
|
|
|
|
|
program.nextRun |
|
|
|
|
|
|
|
? <time title={moment(program.nextRun).toString()}>{moment(program.nextRun).fromNow()}</time> |
|
|
|
|
|
|
|
: <time title="never">never</time> |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
</Form> |
|
|
|
</Form> |
|
|
|
</Modal.Content> |
|
|
|
</Modal.Content> |
|
|
|
{this.renderActions(program)} |
|
|
|
{this.renderActions(program)} |
|
|
@ -243,6 +253,10 @@ class ProgramPage extends React.Component<ProgramPageProps> { |
|
|
|
}, |
|
|
|
}, |
|
|
|
err => { |
|
|
|
err => { |
|
|
|
log.error({ err }, "error updating Program"); |
|
|
|
log.error({ err }, "error updating Program"); |
|
|
|
|
|
|
|
this.props.appState.uiStore.addMessage({ |
|
|
|
|
|
|
|
error: true, |
|
|
|
|
|
|
|
content: `Error updating program: ${err}`, |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
); |
|
|
|
); |
|
|
|
this.stopEditing(); |
|
|
|
this.stopEditing(); |
|
|
@ -268,11 +282,28 @@ class ProgramPage extends React.Component<ProgramPageProps> { |
|
|
|
|
|
|
|
|
|
|
|
@action.bound |
|
|
|
@action.bound |
|
|
|
private onEnabledChange(e: any, p: CheckboxProps) { |
|
|
|
private onEnabledChange(e: any, p: CheckboxProps) { |
|
|
|
if (this.programView) { |
|
|
|
if (p.checked !== undefined && this.program) { |
|
|
|
this.programView.enabled = p.checked!; |
|
|
|
this.program.enabled = p.checked; |
|
|
|
|
|
|
|
this.program.update().then( |
|
|
|
|
|
|
|
data => { |
|
|
|
|
|
|
|
log.info({ data }, "Program updated"); |
|
|
|
|
|
|
|
this.props.appState.uiStore.addMessage({ |
|
|
|
|
|
|
|
success: true, |
|
|
|
|
|
|
|
content: `Program ${this.program!.name} ${this.program!.enabled ? "enabled" : "disabled"}`, |
|
|
|
|
|
|
|
timeout: 2000, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
err => { |
|
|
|
|
|
|
|
log.error({ err }, "error updating Program"); |
|
|
|
|
|
|
|
this.props.appState.uiStore.addMessage({ |
|
|
|
|
|
|
|
error: true, |
|
|
|
|
|
|
|
content: `Error updating program: ${err}`, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const DecoratedProgramPage = injectState(withRouter(observer(ProgramPage))); |
|
|
|
const DecoratedProgramPage = injectState(withRouter(ProgramPage)); |
|
|
|
export default DecoratedProgramPage; |
|
|
|
export default DecoratedProgramPage; |
|
|
|