Anyone who can write an APL function should be able to host it on the web.™
Rendered webpage |
APL code |
Please select city and origin and destination
:class Tube_Planner : MiPageSample
⍝ Control:: _JS.Chosen
⍝ Description:: Tube/Metro/Subway planner for multiple cities
∇ Compose;ipcity;go;route;inputs
:Access public
:If 0=⎕NC'#.TUBE.cities'
'#.TUBE'⎕NS''
#.TUBE.⎕CY(1⊃⎕NPARTS(¯1↓#.Boot.AppRoot),_PageName),'../Data/tube'
cities←'^.' '_(.)'⎕R'\u&' ' \u1'⊢(#.TUBE.⎕NL ¯9)~⊂'notes'
:EndIf
Add _.style'.sel {width: 250px} #route {margin-top: 20px}'
'#title'Add _.h1'Tube/Metro/Subway Planner'
inputs←'#inputs'Add _.Form
ipcity←'#city' '.sel'inputs.Add _.Chosen cities ⍬ ⍬'select city' ⋄ inputs.Add': '
ipcity.On'change' 'UpdateCity'
IPFR←'#from' '.sel .fromto'inputs.Add _.Chosen ⍬ ⍬ ⍬'select origin' ⋄ inputs.Add' → '
IPTO←'#to' '.sel .fromto'inputs.Add _.Chosen ⍬ ⍬ ⍬'select destination' ⋄ inputs.Add' '
go←inputs.Add _.Button'Go!'
go.On'click' 'CalculateRoute'
route←'#route'Add _.pre'Please select city and origin and destination'
∇
∇ r←CalculateRoute;route;inputs;empty
:Access public
inputs←Get'city' 'from' 'to'
empty←0=≢¨inputs
:If ∨/empty
r←'#route'Replace'Please select ',⊃{⍺,' and ',⍵}/empty/'city' 'origin' 'destination'
:Else
SetCITYvars
route←CITYDATA #.TUBE.trip 1↓inputs
r←'#route'Replace route,⎕UCS 10
:EndIf
∇
∇ r←UpdateCity;ctl
:Access public
SetCITYvars
ctl←⎕NEW _.Select
r←'#from'ctl.ReplaceOptions STOPS
r,←'#to'ctl.ReplaceOptions STOPS
r,←Execute('$(".fromto").trigger("chosen:updated")')
∇
∇ SetCITYvars
:Access private
CITYDATA←#.TUBE⍎'_'@(=∘' ')#.Strings.lc Get'city'
#.TUBE.compile CITYDATA
STOPS←{(1=≡¨⍵)/⍵}CITYDATA.labels
∇
:endclass