Big chunk of work
This commit is contained in:
parent
701a55ce29
commit
e4bd7d3ced
@ -113,12 +113,14 @@ class RouteSearch extends Component {
|
|||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
|
const hours = now.getHours();
|
||||||
this.state = {
|
this.state = {
|
||||||
fromStation: "",
|
fromStation: "",
|
||||||
toStation: "",
|
toStation: "",
|
||||||
depart: 'now',
|
depart: 'now',
|
||||||
min: now.getMinutes(),
|
min: now.getMinutes(),
|
||||||
hour: now.getHours(),
|
hour: hours === 0 ? 12 : hours % 12,
|
||||||
|
isPM: hours >= 12
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,7 +136,11 @@ class RouteSearch extends Component {
|
|||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
api.action("bartinfo", "json", {
|
api.action("bartinfo", "json", {
|
||||||
from: this.state.fromStation,
|
from: this.state.fromStation,
|
||||||
to: this.state.toStation});
|
to: this.state.toStation,
|
||||||
|
min: this.state.min,
|
||||||
|
hour: this.state.hour,
|
||||||
|
isPM: this.state.isPM,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
changeStation(evt) {
|
changeStation(evt) {
|
||||||
@ -155,10 +161,12 @@ class RouteSearch extends Component {
|
|||||||
setDepartAt(evt) {
|
setDepartAt(evt) {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
|
const hours = now.getHours();
|
||||||
this.setState({
|
this.setState({
|
||||||
depart: "givenTime",
|
depart: "givenTime",
|
||||||
hour: now.getHours(),
|
|
||||||
min: now.getMinutes(),
|
min: now.getMinutes(),
|
||||||
|
hour: hours === 0 ? 12 : hours % 12,
|
||||||
|
isPM: hours >= 12
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -182,13 +190,30 @@ class RouteSearch extends Component {
|
|||||||
<div></div>
|
<div></div>
|
||||||
<div>
|
<div>
|
||||||
</div>
|
</div>
|
||||||
<select name="hour" value={this.state.hour} onChange={(evt) => this.setState({hour: evt.target.value}) } disabled={departNow}>
|
<select
|
||||||
{ _.map(_.range(0, 24), (hour) => { return <option key={`h-${hour}`} value={hour}>{hour}</option>;}) }
|
name="hour"
|
||||||
|
value={this.state.hour}
|
||||||
|
onChange={(evt) => this.setState({hour: evt.target.value}) } disabled={departNow}
|
||||||
|
>
|
||||||
|
{ _.map(_.range(1, 13), (hour) => { return <option key={`h-${hour}`} value={hour}>{hour}</option>;}) }
|
||||||
</select>
|
</select>
|
||||||
<span>:</span>
|
<span>:</span>
|
||||||
<select name="min" value={this.state.min} onChange={(evt) => this.setState({min: evt.target.value}) } disabled={departNow}>
|
<select
|
||||||
|
name="min"
|
||||||
|
value={this.state.min}
|
||||||
|
onChange={(evt) => this.setState({min: evt.target.value}) } disabled={departNow}
|
||||||
|
>
|
||||||
{ _.map(_.range(0, 60), (min) => { return <option key={`m-${min}`} value={min}>{min}</option>;}) }
|
{ _.map(_.range(0, 60), (min) => { return <option key={`m-${min}`} value={min}>{min}</option>;}) }
|
||||||
</select>
|
</select>
|
||||||
|
<select
|
||||||
|
name="isPM"
|
||||||
|
value={this.state.isPM ? "PM" : "AM"}
|
||||||
|
disabled={departNow}
|
||||||
|
onChange={(evt) => this.setState({isPM: evt.target.value === "PM"})}
|
||||||
|
>
|
||||||
|
<option value="AM">AM</option>
|
||||||
|
<option value="PM">PM</option>
|
||||||
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>);
|
</div>);
|
||||||
}
|
}
|
||||||
|
@ -105,12 +105,19 @@
|
|||||||
?> ?=(%o -.value)
|
?> ?=(%o -.value)
|
||||||
=/ update=json (pairs:enjs:format [update+o+p.value ~])
|
=/ update=json (pairs:enjs:format [update+o+p.value ~])
|
||||||
[%give %fact ~[/bartstations] %json !>(update)]~
|
[%give %fact ~[/bartstations] %json !>(update)]~
|
||||||
::
|
::
|
||||||
[%elevators *]
|
[%elevators *]
|
||||||
=/ value=json (parse-elevator-status-response:cc client-response.sign-arvo)
|
=/ value=json (parse-elevator-status-response:cc client-response.sign-arvo)
|
||||||
?> ?=(%o -.value)
|
?> ?=(%o -.value)
|
||||||
=/ update=json (pairs:enjs:format [update+o+p.value ~])
|
=/ update=json (pairs:enjs:format [update+o+p.value ~])
|
||||||
[%give %fact ~[/elevators] %json !>(update)]~
|
[%give %fact ~[/elevators] %json !>(update)]~
|
||||||
|
::
|
||||||
|
[%routeplan *]
|
||||||
|
~& client-response.sign-arvo
|
||||||
|
=/ value=json (parse-routeplan-response:cc client-response.sign-arvo)
|
||||||
|
?> ?=(%o -.value)
|
||||||
|
=/ update=json (pairs:enjs:format [update+o+p.value ~])
|
||||||
|
[%give %fact ~[/routes] %json !>(update)]~
|
||||||
==
|
==
|
||||||
[http-moves this]
|
[http-moves this]
|
||||||
?. ?=(%bound +<.sign-arvo)
|
?. ?=(%bound +<.sign-arvo)
|
||||||
@ -194,14 +201,20 @@
|
|||||||
(with-json-handler response handler)
|
(with-json-handler response handler)
|
||||||
::
|
::
|
||||||
++ bart-api-routeplan
|
++ bart-api-routeplan
|
||||||
|= [from=tape to=tape]
|
|= [from=tape to=tape hour=@ min=@ ispm=?]
|
||||||
^- request:http
|
^- request:http
|
||||||
:: http://api.bart.gov/api/sched.aspx?cmd=depart&orig=ASHB&dest=CIVC&date=now
|
:: http://api.bart.gov/api/sched.aspx?cmd=depart&orig=ASHB&dest=CIVC&date=now
|
||||||
:: TODO cmd can be 'depart' or 'arrive', also 'fare'
|
:: TODO cmd can be 'depart' or 'arrive', also 'fare'
|
||||||
=/ url (crip "{bart-api-url-base}/sched.aspx?cmd=depart&orig={from}&dest={to}&key={bart-api-key}&json=y")
|
=/ meridian ?:(ispm "pm" "am")
|
||||||
|
=/ time "{<hour>}:{<min>}{meridian}"
|
||||||
|
=/ url (crip "{bart-api-url-base}/sched.aspx?cmd=depart&orig={from}&dest={to}&time={time}&key={bart-api-key}&json=y")
|
||||||
~& url
|
~& url
|
||||||
=/ headers [['Accept' 'application/json']]~
|
=/ headers [['Accept' 'application/json']]~
|
||||||
[%'GET' url headers *(unit octs)]
|
[%'GET' url headers *(unit octs)]
|
||||||
|
++ parse-routeplan-response
|
||||||
|
|= response=client-response:iris
|
||||||
|
^- json
|
||||||
|
(with-json-handler response |=(x=json x))
|
||||||
++ poke-handle-json
|
++ poke-handle-json
|
||||||
|= jon=json
|
|= jon=json
|
||||||
^- (list card)
|
^- (list card)
|
||||||
@ -209,15 +222,20 @@
|
|||||||
=, format
|
=, format
|
||||||
?. ?=(%o -.jon)
|
?. ?=(%o -.jon)
|
||||||
[~]
|
[~]
|
||||||
=/ omso ((om:dejs so:dejs) jon)
|
=/ [hour=@ min=@ ispm=? from-station=tape to-station=tape]
|
||||||
=/ from-station=tape (trip (~(gut by omso) 'from' ''))
|
%.
|
||||||
=/ to-station=tape (trip (~(gut by omso) 'to' ''))
|
jon
|
||||||
=/ req (bart-api-routeplan from-station to-station)
|
%: ot:dejs
|
||||||
|
['hour' ni:dejs]
|
||||||
|
['min' ni:dejs]
|
||||||
|
['isPM' bo:dejs]
|
||||||
|
['from' sa:dejs]
|
||||||
|
['to' sa:dejs]
|
||||||
|
~
|
||||||
|
==
|
||||||
|
=/ req (bart-api-routeplan from-station to-station hour min ispm)
|
||||||
=/ out *outbound-config:iris
|
=/ out *outbound-config:iris
|
||||||
=/ output [%pass /routeplan %arvo %i %request req out]
|
[[%pass /routeplan %arvo %i %request req out] ~]
|
||||||
::
|
|
||||||
=/ update=json *json
|
|
||||||
[%give %fact ~[/routes] %json !>(update)]~
|
|
||||||
::
|
::
|
||||||
++ poke-handle-http-request
|
++ poke-handle-http-request
|
||||||
|= =inbound-request:eyre
|
|= =inbound-request:eyre
|
||||||
|
Loading…
Reference in New Issue
Block a user