Commits

Marco Yuen committed fd0bc03

Add a page that shows all stops.

Comments (0)

Files changed (3)

src/nextrain/controller.clj

 (ns nextrain.controller
-  (:use nextrain.pages
-        nextrain.snippets
-        nextrain.data.gtfs
-        nextrain.utils
-        hiccup.core
-        ring.util.json-response
-        [korma.core :only [select where join fields subselect order]]
-        [clojure.data.json :only [json-str]]
-        [clojure.pprint :only [pprint cl-format]])
-  (:import (java.util Calendar)
-           (java.text SimpleDateFormat)))
+(:use nextrain.pages
+      nextrain.snippets
+      nextrain.data.gtfs
+      nextrain.utils
+      hiccup.core
+      ring.util.json-response
+      [korma.core :only [select where join fields subselect order]]
+      [clojure.data.json :only [json-str]]
+      [clojure.pprint :only [pprint cl-format]])
+(:import (java.util Calendar)
+         (java.text SimpleDateFormat)))
 
 ; 30 minutes in millis
 (defonce time-offset (* 30 60 1000))
 (defonce calendar-date-format (SimpleDateFormat. "yyyyMMdd"))
 (defonce train-time-format    (SimpleDateFormat. "HH:mm:ss"))
+(defonce stops-cache (atom []))
 
 (defn nearest-stops [coord]
   (let [[[lat-min lon-min] [lat-max lon-max]] (bounding-box coord 1500)
       )
     ))
 
+(defn get-all-stops []
+  (if (empty? @stops-cache)
+    (reset! stops-cache (select stops (order :stop_name)))
+    @stops-cache))
 
 ;;;
 ;;; Handlers
 (defn stop [stop-id]
   (layout :body (stop-mobile-page (first (stop-info stop-id)))))
 
+(defn all-stops []
+  (layout :body (all-stops-mobile-page (get-all-stops))))
+
 (defn next-train-times [params]
   (println "next-train-times:" params)
   (let [times (next-train params)]

src/nextrain/core.clj

 (defroutes main-routes
   (GET "/" [] (index))
   (GET "/stop/:id" [id] (stop id))
+  (GET "/allstops" [] (all-stops))
   (POST "/findstops" {params :params} (find-stops params))
   (POST "/traintimes" {params :params} (next-train-times params))
   (GET "/ses" {params :params

src/nextrain/snippets.clj

 (ns nextrain.snippets
-  (:use hiccup.core))
+  (:use hiccup.core
+        [clojure.pprint :only [pprint]]))
 
 (defn mobile-page
   [& {:as params}]
 
 (defn index-mobile-page []
   (mobile-page :id "indexpage"
-               :header (html [:h1 "Nearest Stops"])
+               :header (html [:h1 "Nearest Stops"]
+                             [:a {:href "/allstops"} "Stops"])
                :content (html [:div#stops-list-template
                                 [:ul#stops-list {:data-role "listview"}]])))
 
                :header  (html [:h1 (:stop_name stop)])
                :content (html [:div#times-list-template
                                [:ul#times-list {:data-role "listview"}]])))
+
+(defn all-stops-mobile-page [stops]
+  (mobile-page :id "allstopspage"
+               :header (html [:h1 "Stops"])
+               :content (html [:div
+                               [:ul#all-stops-list {:data-role "listview"
+                                                    :data-filter "true"
+                                                    :data-filter-placeholder "Search Stop ..."}
+                                (for [stop stops]
+                                  [:li
+                                   [:a {:href (str "/stop/" (:stop_id stop))}
+                                    (:stop_name stop)]])]])))