~pepe/neil

b71ff4834a638cd3394f2187bf5be10dca8c3be7 — Josef Pospíšil 2 months ago ab6fc14
Start with routes refactoring
M neil/sock/acts.janet => neil/sock/acts.janet +1 -1
@@ 2,7 2,7 @@
(use trolley trevor chidi/response jff/scorer)
(use shawn/act shawn/acts shawn/cocoon)

(use /neil/watch/utils /neil/sock)
(use /neil/watch/utils /neil/sock /neil/watch/routes)
(import /neil/acts/shared :as s)

(defn to-one [s p a]

M neil/watch/auth.janet => neil/watch/auth.janet +1 -1
@@ 3,7 3,7 @@
(use chidi/middleware chidi/response)
(import shawn/cocoon)

(use /neil/watch/utils)
(use /neil/watch/utils /neil/watch/routes)
(import /neil/acts/shared)

(def- see-auth (see-other "/auth"))

M neil/watch/init.janet => neil/watch/init.janet +1 -22
@@ 2,13 2,6 @@

(use /neil/watch/utils /neil/watch/middleware)

(import /neil/watch/clients)
(import /neil/watch/projects)
(import /neil/watch/tasks)
(import /neil/watch/work-intervals)
(import /neil/watch/stats)
(import /neil/watch/auth) # must be here, cause middleware uses it

(defn dashboard [brush trevor]
  (fn [_]
    (def r (running-task brush))


@@ 42,21 35,7 @@

(defn open [chidi trevor key brush]
  (drive
    {"/auth" @{"" (dispatch
                    @{"GET" (-> auth/form html-success)
                      "POST" (-> (auth/set chidi (:soak brush :password) key)
                                 urlencoded)})
               "/change" (-> brush (auth/change key) dry (urlenc-post brush))
               "/expire" (-> brush auth/expire dry (urlenc-post brush))}
     "/" (-> brush (dashboard trevor) (html-get brush))
     "/admin" (-> admin (set-admin brush trevor) (html-get brush))
     "/admin/:tab" (-> admin (set-admin brush trevor) (html-get brush))
     "/stats" (stats/routes brush trevor)
     "/tasks" (tasks/routes brush trevor)
     "/clients" (clients/routes brush trevor)
     "/projects" (projects/routes brush trevor)
     "/work-intervals" (work-intervals/routes brush)
     :not-found (stoic "public")}
    routes
    act-journal))

(defn supervisor

M neil/watch/middleware.janet => neil/watch/middleware.janet +1 -1
@@ 1,5 1,5 @@
(use shawn/cocoon shawn/acts)
(use /neil/watch/utils /neil/acts/shared /neil/sock/acts)
(use /neil/watch/utils /neil/acts/shared)
(import /neil/watch/auth)

(defn act-journal

A neil/watch/routes.janet => neil/watch/routes.janet +77 -0
@@ 0,0 1,77 @@
(use trolley)
(import chidi/middleware :prefix "")

(import /neil/watch/clients)
(import /neil/watch/projects)
(import /neil/watch/tasks)
(import /neil/watch/work-intervals)
(import /neil/watch/stats)
(import /neil/watch/auth)

(def routes
  {"/auth" @{"" (dispatch
                  @{"GET" (-> auth/form html-success)
                    "POST" (-> (auth/set chidi (:soak brush :password) key)
                               urlencoded)})
             "/change" (-> brush (auth/change key) dry (urlenc-post brush))
             "/expire" (-> brush auth/expire dry (urlenc-post brush))}
   "/" (-> brush (dashboard trevor) (html-get brush))
   "/admin" (-> admin (set-admin brush trevor) (html-get brush))
   "/admin/:tab" (-> admin (set-admin brush trevor) (html-get brush))
   "/stats" (stats/routes brush trevor)
   "/tasks" (tasks/routes brush trevor)
   "/clients" (clients/routes brush trevor)
   "/projects" (projects/routes brush trevor)
   "/work-intervals" (work-intervals/routes brush)
   :not-found (stoic "public")})

(defn resolve [action & params]
  (def ps (table ;params))
  ((resolver @{"/" :dashboard
               "/auth" :auth
               "/auth/change" :auth/change
               "/auth/expire" :auth/expire
               "/admin" :admin
               "/admin/:tab" :admin/tab
               "/stats" :stats
               "/stats/dowload.csv" :stats/dowload
               "/stats/:interval" :stats/interval
               "/stats/:interval/:project" :stats/interval/project
               "/clients/:id/detail" :clients/detail
               "/clients/:id/edit" :clients/edit
               "/clients/:id/save" :clients/save
               "/clients/create" :clients/create
               "/clients/new" :clients/new
               "/projects/:id/detail" :projects/detail
               "/projects/:id/edit" :projects/edit
               "/projects/:id/head" :projects/head
               "/projects/:id/save" :projects/save
               "/projects/:id/tasks/:state" :projects/tasks
               "/projects/create" :projects/create
               "/projects/:project-id/stats" :projects/stats
               "/projects/:id/pin/:time" :projects/pin
               "/projects/:id/unpin" :projects/unpin
               "/tasks/stop" :tasks/stop
               "/tasks/done" :/tasks/done
               "/tasks/add" :tasks/add
               "/tasks/add-start" :/tasks/add-start
               "/tasks/:id/start" :tasks/:id/start
               "/tasks/:id/complete" :tasks/complete
               "/tasks/:id/cancel" :tasks/cancel
               "/tasks/:id/resurrect" :tasks/resurect
               "/tasks/:id/work-intervals" :tasks/work-intervals
               "/tasks/:id/touch" :tasks/touch
               "/tasks/:id/edit" :tasks/edit
               "/tasks/save" :tasks/save
               "/tasks/:id/detail" :tasks/detail
               "/tasks/all/:state" :tasks/all
               "/tasks/:task-id/work-intervals/:work-interval-id/edit" :tasks/work-interval/edit
               "/tasks/:task-id/work-intervals/:work-interval-id/remove" :tasks/work-interval/remove
               "/tasks/:task-id/work-intervals/:work-interval-id" :tasks/work-interval
               "/tasks/:id/pin/:time" :tasks/pin
               "/tasks/:id/unpin" :tasks/unpin
               "/work-intervals/:task/new" :work-intervals/new
               "/work-intervals/:task/add" :work-intervals/dd
               "/work-intervals/cancel" :work-intervals/cancel
               "/work-intervals/save-note" :work-intervals/save-note})
    action ps))

M neil/watch/utils.janet => neil/watch/utils.janet +1 -52
@@ 1,4 1,4 @@
(use shawn/cocoon trolley)
(use shawn/cocoon)
(import chidi/response :prefix "" :export true)
(import chidi/middleware :prefix "" :export true)



@@ 106,54 106,3 @@
                               " " (get ,body (. ,period "-time"))))))

(defn sp->nbsp [label] (string/replace-all " " " " label))

(defn resolve [action & params]
  (def ps (table ;params))
  ((resolver @{"/" :dashboard
               "/auth" :auth
               "/auth/change" :auth/change
               "/auth/expire" :auth/expire
               "/admin" :admin
               "/admin/:tab" :admin/tab
               "/stats" :stats
               "/stats/dowload.csv" :stats/dowload
               "/stats/:interval" :stats/interval
               "/stats/:interval/:project" :stats/interval/project
               "/clients/:id/detail" :clients/detail
               "/clients/:id/edit" :clients/edit
               "/clients/:id/save" :clients/save
               "/clients/create" :clients/create
               "/clients/new" :clients/new
               "/projects/:id/detail" :projects/detail
               "/projects/:id/edit" :projects/edit
               "/projects/:id/head" :projects/head
               "/projects/:id/save" :projects/save
               "/projects/:id/tasks/:state" :projects/tasks
               "/projects/create" :projects/create
               "/projects/:project-id/stats" :projects/stats
               "/projects/:id/pin/:time" :projects/pin
               "/projects/:id/unpin" :projects/unpin
               "/tasks/stop" :tasks/stop
               "/tasks/done" :/tasks/done
               "/tasks/add" :tasks/add
               "/tasks/add-start" :/tasks/add-start
               "/tasks/:id/start" :tasks/:id/start
               "/tasks/:id/complete" :tasks/complete
               "/tasks/:id/cancel" :tasks/cancel
               "/tasks/:id/resurrect" :tasks/resurect
               "/tasks/:id/work-intervals" :tasks/work-intervals
               "/tasks/:id/touch" :tasks/touch
               "/tasks/:id/edit" :tasks/edit
               "/tasks/save" :tasks/save
               "/tasks/:id/detail" :tasks/detail
               "/tasks/all/:state" :tasks/all
               "/tasks/:task-id/work-intervals/:work-interval-id/edit" :tasks/work-interval/edit
               "/tasks/:task-id/work-intervals/:work-interval-id/remove" :tasks/work-interval/remove
               "/tasks/:task-id/work-intervals/:work-interval-id" :tasks/work-interval
               "/tasks/:id/pin/:time" :tasks/pin
               "/tasks/:id/unpin" :tasks/unpin
               "/work-intervals/:task/new" :work-intervals/new
               "/work-intervals/:task/add" :work-intervals/dd
               "/work-intervals/cancel" :work-intervals/cancel
               "/work-intervals/save-note" :work-intervals/save-note})
    action ps))