Formatted everything and fixed lint issues
This commit is contained in:
parent
79a9cb4cd0
commit
5e491bbd33
@ -1,14 +1,14 @@
|
|||||||
import * as React from "react";
|
import "app/style/app.css";
|
||||||
import DevTools from "mobx-react-devtools";
|
import "font-awesome/css/font-awesome.css";
|
||||||
import {observer} from "mobx-react";
|
import {observer} from "mobx-react";
|
||||||
import {SprinklersDevice} from "../sprinklers";
|
import DevTools from "mobx-react-devtools";
|
||||||
import {Item} from "semantic-ui-react";
|
import * as React from "react";
|
||||||
import {UiStore} from "../ui";
|
|
||||||
import {MessagesView, DeviceView} from ".";
|
|
||||||
|
|
||||||
import "semantic-ui-css/semantic.css";
|
import "semantic-ui-css/semantic.css";
|
||||||
import "font-awesome/css/font-awesome.css";
|
import {Item} from "semantic-ui-react";
|
||||||
import "app/style/app.css";
|
import {DeviceView, MessagesView} from ".";
|
||||||
|
import {SprinklersDevice} from "../sprinklers";
|
||||||
|
import {UiStore} from "../ui";
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
export default class App extends React.PureComponent<{ device: SprinklersDevice, uiStore: UiStore }, any> {
|
export default class App extends React.PureComponent<{ device: SprinklersDevice, uiStore: UiStore }, any> {
|
||||||
@ -16,7 +16,7 @@ export default class App extends React.PureComponent<{ device: SprinklersDevice,
|
|||||||
return <Item.Group divided>
|
return <Item.Group divided>
|
||||||
<MessagesView uiStore={this.props.uiStore}/>
|
<MessagesView uiStore={this.props.uiStore}/>
|
||||||
<DeviceView device={this.props.device}/>
|
<DeviceView device={this.props.device}/>
|
||||||
<DevTools />
|
<DevTools/>
|
||||||
</Item.Group>;
|
</Item.Group>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import * as React from "react";
|
|
||||||
import {observer} from "mobx-react";
|
|
||||||
import {Item, Header} from "semantic-ui-react";
|
|
||||||
import FontAwesome = require("react-fontawesome");
|
|
||||||
import * as classNames from "classnames";
|
import * as classNames from "classnames";
|
||||||
|
import {observer} from "mobx-react";
|
||||||
|
import * as React from "react";
|
||||||
|
import {Header, Item} from "semantic-ui-react";
|
||||||
|
import {ProgramTable, RunSectionForm, SectionTable} from ".";
|
||||||
|
|
||||||
import {SprinklersDevice} from "../sprinklers";
|
import {SprinklersDevice} from "../sprinklers";
|
||||||
import {SectionTable, RunSectionForm, ProgramTable} from ".";
|
import FontAwesome = require("react-fontawesome");
|
||||||
|
|
||||||
const ConnectionState = ({connected}: { connected: boolean }) =>
|
const ConnectionState = ({connected}: { connected: boolean }) =>
|
||||||
<span className={classNames({
|
<span className={classNames({
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import {Duration} from "../sprinklers";
|
|
||||||
import {Input} from "semantic-ui-react";
|
import {Input} from "semantic-ui-react";
|
||||||
|
import {Duration} from "../sprinklers";
|
||||||
|
|
||||||
export default class DurationInput extends React.Component<{
|
export default class DurationInput extends React.Component<{
|
||||||
duration: Duration,
|
duration: Duration,
|
||||||
|
@ -1,27 +1,27 @@
|
|||||||
import * as React from "react";
|
|
||||||
import { CSSTransitionGroup } from "react-transition-group";
|
|
||||||
import {observer} from "mobx-react";
|
import {observer} from "mobx-react";
|
||||||
import {UiStore, Message as UiMessage} from "../ui";
|
import * as React from "react";
|
||||||
|
import {CSSTransitionGroup} from "react-transition-group";
|
||||||
import {Message} from "semantic-ui-react";
|
import {Message} from "semantic-ui-react";
|
||||||
|
import {Message as UiMessage, UiStore} from "../ui";
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
export default class MessagesView extends React.PureComponent<{ uiStore: UiStore }, {}> {
|
export default class MessagesView extends React.PureComponent<{ uiStore: UiStore }, {}> {
|
||||||
render() {
|
render() {
|
||||||
return <div className="messages">
|
return <div className="messages">
|
||||||
<CSSTransitionGroup transitionName="message" transitionAppear={true} transitionAppearTimeout={500}
|
<CSSTransitionGroup transitionName="message" transitionAppear={true} transitionAppearTimeout={500}
|
||||||
transitionEnterTimeout={500} transitionLeaveTimeout={500}>
|
transitionEnterTimeout={500} transitionLeaveTimeout={500}>
|
||||||
{this.props.uiStore.messages.map(this.renderMessage)}
|
{this.props.uiStore.messages.map(this.renderMessage)}
|
||||||
</CSSTransitionGroup>
|
</CSSTransitionGroup>
|
||||||
</div>;
|
</div>;
|
||||||
}
|
}
|
||||||
|
|
||||||
private renderMessage = (message: UiMessage, index: number) => {
|
private renderMessage = (message: UiMessage, index: number) => {
|
||||||
const { header, content, type } = message;
|
const {header, content, type} = message;
|
||||||
return <Message key={message.id} className="message"
|
return <Message key={message.id} className="message"
|
||||||
header={header} content={content}
|
header={header} content={content}
|
||||||
success={type === UiMessage.Type.Success}
|
success={type === UiMessage.Type.Success}
|
||||||
info={type === UiMessage.Type.Info} warning={type === UiMessage.Type.Warning}
|
info={type === UiMessage.Type.Info} warning={type === UiMessage.Type.Warning}
|
||||||
error={type === UiMessage.Type.Error} onDismiss={() => this.dismiss(index)} />;
|
error={type === UiMessage.Type.Error} onDismiss={() => this.dismiss(index)}/>;
|
||||||
}
|
}
|
||||||
|
|
||||||
private dismiss(index: number) {
|
private dismiss(index: number) {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import * as React from "react";
|
|
||||||
import {observer} from "mobx-react";
|
import {observer} from "mobx-react";
|
||||||
import {Program, Schedule} from "../sprinklers";
|
import * as React from "react";
|
||||||
import {Table} from "semantic-ui-react";
|
import {Table} from "semantic-ui-react";
|
||||||
|
import {Program, Schedule} from "../sprinklers";
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
export class ScheduleView extends React.PureComponent<{ schedule: Schedule }, {}> {
|
export class ScheduleView extends React.PureComponent<{ schedule: Schedule }, {}> {
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import * as React from "react";
|
|
||||||
import {SyntheticEvent} from "react";
|
|
||||||
import {computed} from "mobx";
|
import {computed} from "mobx";
|
||||||
import {observer} from "mobx-react";
|
import {observer} from "mobx-react";
|
||||||
import {Duration, Section} from "../sprinklers";
|
import * as React from "react";
|
||||||
import {Segment, Header, Form, DropdownProps, DropdownItemProps} from "semantic-ui-react";
|
import {SyntheticEvent} from "react";
|
||||||
|
import {DropdownItemProps, DropdownProps, Form, Header, Segment} from "semantic-ui-react";
|
||||||
import {DurationInput} from ".";
|
import {DurationInput} from ".";
|
||||||
|
import {Duration, Section} from "../sprinklers";
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
export default class RunSectionForm extends React.Component<{
|
export default class RunSectionForm extends React.Component<{
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import * as React from "react";
|
|
||||||
import {observer} from "mobx-react";
|
|
||||||
import * as classNames from "classnames";
|
import * as classNames from "classnames";
|
||||||
|
import {observer} from "mobx-react";
|
||||||
|
import * as React from "react";
|
||||||
import {Table} from "semantic-ui-react";
|
import {Table} from "semantic-ui-react";
|
||||||
import FontAwesome = require("react-fontawesome");
|
|
||||||
|
|
||||||
import {Section} from "../sprinklers";
|
import {Section} from "../sprinklers";
|
||||||
|
import FontAwesome = require("react-fontawesome");
|
||||||
|
|
||||||
/* tslint:disable:object-literal-sort-keys */
|
/* tslint:disable:object-literal-sort-keys */
|
||||||
|
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import * as ReactDOM from "react-dom";
|
import * as ReactDOM from "react-dom";
|
||||||
import { AppContainer } from "react-hot-loader";
|
import {AppContainer} from "react-hot-loader";
|
||||||
|
|
||||||
import App from "./components/App";
|
import App from "./components/App";
|
||||||
import { MqttApiClient } from "./mqtt";
|
import {MqttApiClient} from "./mqtt";
|
||||||
import {Message, UiStore} from "./ui";
|
import {Message, UiStore} from "./ui";
|
||||||
|
|
||||||
const client = new MqttApiClient();
|
const client = new MqttApiClient();
|
||||||
@ -15,14 +15,14 @@ uiStore.addMessage(new Message("asdf", "boo!", Message.Type.Error));
|
|||||||
const rootElem = document.getElementById("app");
|
const rootElem = document.getElementById("app");
|
||||||
|
|
||||||
ReactDOM.render(<AppContainer>
|
ReactDOM.render(<AppContainer>
|
||||||
<App device={device} uiStore={uiStore} />
|
<App device={device} uiStore={uiStore}/>
|
||||||
</AppContainer>, rootElem);
|
</AppContainer>, rootElem);
|
||||||
|
|
||||||
if (module.hot) {
|
if (module.hot) {
|
||||||
module.hot.accept("./components/App", () => {
|
module.hot.accept("./components/App", () => {
|
||||||
const NextApp = require<any>("./components/App").default;
|
const NextApp = require<any>("./components/App").default;
|
||||||
ReactDOM.render(<AppContainer>
|
ReactDOM.render(<AppContainer>
|
||||||
<App device={device} uiStore={uiStore} />
|
<App device={device} uiStore={uiStore}/>
|
||||||
</AppContainer>, rootElem);
|
</AppContainer>, rootElem);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,21 +1,22 @@
|
|||||||
import "paho-mqtt";
|
|
||||||
import MQTT = Paho.MQTT;
|
|
||||||
|
|
||||||
import {EventEmitter} from "events";
|
import {EventEmitter} from "events";
|
||||||
|
import "paho-mqtt";
|
||||||
import {
|
import {
|
||||||
SprinklersDevice, ISprinklersApi, Section, Program, Schedule, ITimeOfDay, Duration, SectionRunner, ISectionRun,
|
Duration,
|
||||||
|
ISectionRun,
|
||||||
|
ISprinklersApi,
|
||||||
|
ITimeOfDay,
|
||||||
|
Program,
|
||||||
|
Schedule,
|
||||||
|
Section,
|
||||||
|
SectionRunner,
|
||||||
|
SprinklersDevice,
|
||||||
} from "./sprinklers";
|
} from "./sprinklers";
|
||||||
import {checkedIndexOf} from "./utils";
|
import {checkedIndexOf} from "./utils";
|
||||||
|
import MQTT = Paho.MQTT;
|
||||||
|
|
||||||
export class MqttApiClient extends EventEmitter implements ISprinklersApi {
|
export class MqttApiClient extends EventEmitter implements ISprinklersApi {
|
||||||
private static newClientId() {
|
|
||||||
return "sprinklers3-MqttApiClient-" + Math.round(Math.random() * 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
client: MQTT.Client;
|
client: MQTT.Client;
|
||||||
|
|
||||||
connected: boolean;
|
connected: boolean;
|
||||||
|
|
||||||
devices: { [prefix: string]: MqttSprinklersDevice } = {};
|
devices: { [prefix: string]: MqttSprinklersDevice } = {};
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
@ -26,6 +27,10 @@ export class MqttApiClient extends EventEmitter implements ISprinklersApi {
|
|||||||
// (this.client as any).trace = (m => console.log(m));
|
// (this.client as any).trace = (m => console.log(m));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static newClientId() {
|
||||||
|
return "sprinklers3-MqttApiClient-" + Math.round(Math.random() * 1000);
|
||||||
|
}
|
||||||
|
|
||||||
start() {
|
start() {
|
||||||
console.log("connecting to mqtt with client id %s", this.client.clientId);
|
console.log("connecting to mqtt with client id %s", this.client.clientId);
|
||||||
this.client.connect({
|
this.client.connect({
|
||||||
@ -106,6 +111,22 @@ class MqttSprinklersDevice extends SprinklersDevice {
|
|||||||
this.sectionRunner = new MqttSectionRunner(this);
|
this.sectionRunner = new MqttSectionRunner(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get id(): string {
|
||||||
|
return this.prefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
private get subscriptions() {
|
||||||
|
return [
|
||||||
|
`${this.prefix}/connected`,
|
||||||
|
`${this.prefix}/sections`,
|
||||||
|
`${this.prefix}/sections/+/#`,
|
||||||
|
`${this.prefix}/programs`,
|
||||||
|
`${this.prefix}/programs/+/#`,
|
||||||
|
`${this.prefix}/responses/+`,
|
||||||
|
`${this.prefix}/section_runner`,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
doSubscribe() {
|
doSubscribe() {
|
||||||
const c = this.apiClient.client;
|
const c = this.apiClient.client;
|
||||||
this.subscriptions
|
this.subscriptions
|
||||||
@ -184,10 +205,6 @@ class MqttSprinklersDevice extends SprinklersDevice {
|
|||||||
console.warn(`MqttSprinklersDevice recieved invalid topic: ${topic}`);
|
console.warn(`MqttSprinklersDevice recieved invalid topic: ${topic}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
get id(): string {
|
|
||||||
return this.prefix;
|
|
||||||
}
|
|
||||||
|
|
||||||
runSection(section: Section | number, duration: Duration) {
|
runSection(section: Section | number, duration: Duration) {
|
||||||
const sectionNum = checkedIndexOf(section, this.sections, "Section");
|
const sectionNum = checkedIndexOf(section, this.sections, "Section");
|
||||||
const payload: IRunSectionJSON = {
|
const payload: IRunSectionJSON = {
|
||||||
@ -202,7 +219,7 @@ class MqttSprinklersDevice extends SprinklersDevice {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cancelSectionRunById(id: number) {
|
cancelSectionRunById(id: number) {
|
||||||
return this.makeRequest(`section_runner/cancel_id`, { id });
|
return this.makeRequest(`section_runner/cancel_id`, {id});
|
||||||
}
|
}
|
||||||
|
|
||||||
//noinspection JSMethodCanBeStatic
|
//noinspection JSMethodCanBeStatic
|
||||||
@ -228,23 +245,12 @@ class MqttSprinklersDevice extends SprinklersDevice {
|
|||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private get subscriptions() {
|
|
||||||
return [
|
|
||||||
`${this.prefix}/connected`,
|
|
||||||
`${this.prefix}/sections`,
|
|
||||||
`${this.prefix}/sections/+/#`,
|
|
||||||
`${this.prefix}/programs`,
|
|
||||||
`${this.prefix}/programs/+/#`,
|
|
||||||
`${this.prefix}/responses/+`,
|
|
||||||
`${this.prefix}/section_runner`,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IResponseData {
|
interface IResponseData {
|
||||||
reqTopic: string;
|
reqTopic: string;
|
||||||
error?: string;
|
error?: string;
|
||||||
|
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { observable, IObservableArray } from "mobx";
|
import {IObservableArray, observable} from "mobx";
|
||||||
|
|
||||||
export abstract class Section {
|
export abstract class Section {
|
||||||
device: SprinklersDevice;
|
device: SprinklersDevice;
|
||||||
@ -41,10 +41,6 @@ export class Schedule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class Duration {
|
export class Duration {
|
||||||
static fromSeconds(seconds: number): Duration {
|
|
||||||
return new Duration(Math.floor(seconds / 60), seconds % 60);
|
|
||||||
}
|
|
||||||
|
|
||||||
minutes: number = 0;
|
minutes: number = 0;
|
||||||
seconds: number = 0;
|
seconds: number = 0;
|
||||||
|
|
||||||
@ -53,6 +49,10 @@ export class Duration {
|
|||||||
this.seconds = seconds;
|
this.seconds = seconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static fromSeconds(seconds: number): Duration {
|
||||||
|
return new Duration(Math.floor(seconds / 60), seconds % 60);
|
||||||
|
}
|
||||||
|
|
||||||
toSeconds(): number {
|
toSeconds(): number {
|
||||||
return this.minutes * 60 + this.seconds;
|
return this.minutes * 60 + this.seconds;
|
||||||
}
|
}
|
||||||
@ -162,17 +162,18 @@ export abstract class SprinklersDevice {
|
|||||||
@observable
|
@observable
|
||||||
sectionRunner: SectionRunner;
|
sectionRunner: SectionRunner;
|
||||||
|
|
||||||
|
abstract get id(): string;
|
||||||
|
|
||||||
abstract runSection(section: number | Section, duration: Duration): Promise<{}>;
|
abstract runSection(section: number | Section, duration: Duration): Promise<{}>;
|
||||||
|
|
||||||
abstract runProgram(program: number | Program): Promise<{}>;
|
abstract runProgram(program: number | Program): Promise<{}>;
|
||||||
|
|
||||||
abstract cancelSectionRunById(id: number): Promise<{}>;
|
abstract cancelSectionRunById(id: number): Promise<{}>;
|
||||||
|
|
||||||
abstract get id(): string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ISprinklersApi {
|
export interface ISprinklersApi {
|
||||||
start();
|
start();
|
||||||
|
|
||||||
getDevice(id: string): SprinklersDevice;
|
getDevice(id: string): SprinklersDevice;
|
||||||
|
|
||||||
removeDevice(id: string);
|
removeDevice(id: string);
|
||||||
|
19
tslint.json
19
tslint.json
@ -11,15 +11,22 @@
|
|||||||
"max-classes-per-file": [
|
"max-classes-per-file": [
|
||||||
false
|
false
|
||||||
],
|
],
|
||||||
"ordered-imports": false,
|
"ordered-imports": true,
|
||||||
"variable-name": [
|
"variable-name": [
|
||||||
"allow-leading-underscore"
|
"allow-leading-underscore"
|
||||||
],
|
],
|
||||||
"no-namespace": [
|
"no-namespace": false,
|
||||||
"allow-declarations"
|
|
||||||
],
|
|
||||||
"interface-name": false,
|
"interface-name": false,
|
||||||
"member-access": [ true, "no-public" ]
|
"member-access": [
|
||||||
|
true,
|
||||||
|
"no-public"
|
||||||
|
],
|
||||||
|
"member-ordering": [
|
||||||
|
true,
|
||||||
|
{
|
||||||
|
"order": "fields-first"
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"rulesDirectory": []
|
"rulesDirectory": []
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user