|
|
@ -1,5 +1,5 @@ |
|
|
|
|
|
|
|
import { assign, merge } from "lodash"; |
|
|
|
import { observer } from "mobx-react"; |
|
|
|
import { observer } from "mobx-react"; |
|
|
|
import { createViewModel, IViewModel } from "mobx-utils"; |
|
|
|
|
|
|
|
import * as qs from "query-string"; |
|
|
|
import * as qs from "query-string"; |
|
|
|
import * as React from "react"; |
|
|
|
import * as React from "react"; |
|
|
|
import { RouteComponentProps } from "react-router"; |
|
|
|
import { RouteComponentProps } from "react-router"; |
|
|
@ -23,7 +23,7 @@ class ProgramPage extends React.Component<ProgramPageProps> { |
|
|
|
|
|
|
|
|
|
|
|
device!: SprinklersDevice; |
|
|
|
device!: SprinklersDevice; |
|
|
|
program!: Program; |
|
|
|
program!: Program; |
|
|
|
programView: Program & IViewModel<Program> | null = null; |
|
|
|
programView: Program | null = null; |
|
|
|
|
|
|
|
|
|
|
|
renderName(program: Program) { |
|
|
|
renderName(program: Program) { |
|
|
|
const { name } = program; |
|
|
|
const { name } = program; |
|
|
@ -111,11 +111,14 @@ class ProgramPage extends React.Component<ProgramPageProps> { |
|
|
|
} |
|
|
|
} |
|
|
|
if (this.isEditing) { |
|
|
|
if (this.isEditing) { |
|
|
|
if (this.programView == null && this.program) { |
|
|
|
if (this.programView == null && this.program) { |
|
|
|
this.programView = createViewModel(this.program); |
|
|
|
// this.programView = createViewModel(this.program);
|
|
|
|
|
|
|
|
// this.programView = observable(toJS(this.program));
|
|
|
|
|
|
|
|
this.programView = new Program(this.program.device, this.program.id); |
|
|
|
|
|
|
|
merge(this.programView, this.program); |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if (this.programView != null) { |
|
|
|
if (this.programView != null) { |
|
|
|
this.programView.reset(); |
|
|
|
// this.programView.reset();
|
|
|
|
this.programView = null; |
|
|
|
this.programView = null; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -170,7 +173,7 @@ class ProgramPage extends React.Component<ProgramPageProps> { |
|
|
|
if (!this.programView || !this.program) { |
|
|
|
if (!this.programView || !this.program) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
this.programView.submit(); |
|
|
|
assign(this.program, this.programView); |
|
|
|
this.program.update() |
|
|
|
this.program.update() |
|
|
|
.then((data) => { |
|
|
|
.then((data) => { |
|
|
|
log.info({ data }, "Program updated"); |
|
|
|
log.info({ data }, "Program updated"); |
|
|
@ -186,10 +189,7 @@ class ProgramPage extends React.Component<ProgramPageProps> { |
|
|
|
|
|
|
|
|
|
|
|
private close = () => { |
|
|
|
private close = () => { |
|
|
|
const { deviceId } = this.props.match.params; |
|
|
|
const { deviceId } = this.props.match.params; |
|
|
|
if (this.programView) { |
|
|
|
this.props.history.push({ pathname: rp.device(deviceId), search: "" }); |
|
|
|
this.programView.reset(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.props.history.push({ pathname: rp.device(deviceId) }); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private onNameChange = (e: any, p: InputOnChangeData) => { |
|
|
|
private onNameChange = (e: any, p: InputOnChangeData) => { |
|
|
|