refactoring: api usage eliminated from views
This commit is contained in:
@@ -64,14 +64,15 @@
|
|||||||
(return-content-type "text/plain; charset=utf-8" md-text)))
|
(return-content-type "text/plain; charset=utf-8" md-text)))
|
||||||
|
|
||||||
(GET "/:year/:month/:day/:title/stats" [year month day title]
|
(GET "/:year/:month/:day/:title/stats" [year month day title]
|
||||||
(let [note-id (api/build-key year month day title)
|
(let [note-id (api/build-key year month day title)]
|
||||||
resp {:statistics (storage/get-note-statistics note-id)
|
(statistics-page (api/derive-title (storage/get-note note-id))
|
||||||
:note (storage/get-note note-id)
|
(storage/get-note-statistics note-id))))
|
||||||
:noteID note-id}]
|
|
||||||
(statistics-page resp)))
|
|
||||||
|
|
||||||
(GET "/:year/:month/:day/:title/edit" [year month day title]
|
(GET "/:year/:month/:day/:title/edit" [year month day title]
|
||||||
(note-update-page year month day title))
|
(let [note-id (api/build-key year month day title)]
|
||||||
|
(note-update-page
|
||||||
|
note-id
|
||||||
|
(:note (api/get-note {:noteID note-id})))))
|
||||||
|
|
||||||
(GET "/new" [] (new-note-page
|
(GET "/new" [] (new-note-page
|
||||||
(str
|
(str
|
||||||
@@ -89,7 +90,8 @@
|
|||||||
(swap! C cache/hit short-url)
|
(swap! C cache/hit short-url)
|
||||||
(storage/increment-note-view note-id))
|
(storage/increment-note-view note-id))
|
||||||
(swap! C cache/miss short-url
|
(swap! C cache/miss short-url
|
||||||
(note-page note-id short-url)))
|
(note-page (api/get-note {:noteID note-id})
|
||||||
|
(api/url short-url))))
|
||||||
(cache/lookup @C short-url))))
|
(cache/lookup @C short-url))))
|
||||||
|
|
||||||
(GET "/:short-url" [short-url]
|
(GET "/:short-url" [short-url]
|
||||||
|
|||||||
+21
-29
@@ -7,8 +7,6 @@
|
|||||||
[hiccup.element]
|
[hiccup.element]
|
||||||
[hiccup.util :only [escape-html]]
|
[hiccup.util :only [escape-html]]
|
||||||
[hiccup.page :only [include-js html5]])
|
[hiccup.page :only [include-js html5]])
|
||||||
(:require
|
|
||||||
[notehub.api :as api])
|
|
||||||
(:import (org.pegdown PegDownProcessor Extensions)))
|
(:import (org.pegdown PegDownProcessor Extensions)))
|
||||||
|
|
||||||
(def get-message (get-map "messages"))
|
(def get-message (get-map "messages"))
|
||||||
@@ -52,7 +50,6 @@
|
|||||||
[:div.central-element.helvetica {:style "margin-bottom: 3em"}
|
[:div.central-element.helvetica {:style "margin-bottom: 3em"}
|
||||||
(form-to {:autocomplete :off} [:post form-url]
|
(form-to {:autocomplete :off} [:post form-url]
|
||||||
(hidden-field :action command)
|
(hidden-field :action command)
|
||||||
(hidden-field :version api/version)
|
|
||||||
(hidden-field :password)
|
(hidden-field :password)
|
||||||
fields
|
fields
|
||||||
(text-area {:class :max-width} :note content)
|
(text-area {:class :max-width} :note content)
|
||||||
@@ -76,12 +73,11 @@
|
|||||||
[:div#footer (md-to-html (get-message :footer))]))
|
[:div#footer (md-to-html (get-message :footer))]))
|
||||||
|
|
||||||
|
|
||||||
(defn statistics-page [resp]
|
(defn statistics-page [note-title stats]
|
||||||
(let [stats (:statistics resp)
|
(let [page-title (get-message :statistics)]
|
||||||
title (get-message :statistics)]
|
(layout :no-js page-title
|
||||||
(layout :no-js title
|
[:h2.central-element note-title]
|
||||||
[:h2.central-element (api/derive-title (:note resp))]
|
[:h3.central-element.helvetica page-title]
|
||||||
[:h3.central-element.helvetica title]
|
|
||||||
[:table#stats.helvetica.central-element
|
[:table#stats.helvetica.central-element
|
||||||
(map
|
(map
|
||||||
#(when-let [v (% stats)]
|
#(when-let [v (% stats)]
|
||||||
@@ -91,11 +87,12 @@
|
|||||||
(str (java.util.Date. (Long/parseLong v))) v)]])
|
(str (java.util.Date. (Long/parseLong v))) v)]])
|
||||||
[:published :edited :publisher :views])])))
|
[:published :edited :publisher :views])])))
|
||||||
|
|
||||||
(defn note-update-page [year month day title]
|
(defn note-update-page [note-id note]
|
||||||
(let [note-id (api/build-key year month day title)]
|
(input-form "/update-note"
|
||||||
(input-form "/update-note" :update
|
:update
|
||||||
(html (hidden-field :noteID note-id))
|
(html (hidden-field :noteID note-id))
|
||||||
(:note (api/get-note {:noteID note-id})) :enter-passwd)))
|
note
|
||||||
|
:enter-passwd))
|
||||||
|
|
||||||
(defn new-note-page [session]
|
(defn new-note-page [session]
|
||||||
(input-form "/post-note" :publish
|
(input-form "/post-note" :publish
|
||||||
@@ -103,18 +100,13 @@
|
|||||||
(hidden-field {:id :signature} :signature))
|
(hidden-field {:id :signature} :signature))
|
||||||
(get-message :loading) :set-passwd))
|
(get-message :loading) :set-passwd))
|
||||||
|
|
||||||
(defn note-page [note-id short-url]
|
(defn note-page [note short-url]
|
||||||
(let [note (api/get-note {:noteID note-id})
|
(layout :no-js (:title note)
|
||||||
sanitized-note (sanitize (:note note))]
|
[:article.bottom-space (md-to-html (sanitize (:note note)))]
|
||||||
(layout :no-js (:title note)
|
(let [urls {:short-url short-url
|
||||||
[:article.bottom-space (md-to-html sanitized-note)]
|
:notehub "/"}
|
||||||
(let [urls {:short-url (api/url short-url)
|
links (map #(link-to
|
||||||
:notehub "/"}
|
(urls % (str (:longURL note) "/" (name %)))
|
||||||
links (map #(link-to
|
(get-message %))
|
||||||
(if (urls %)
|
[:notehub :stats :edit :export :short-url])]
|
||||||
(urls %)
|
[:div#footer (interpose [:span.middot "·"] links)])))
|
||||||
(str (:longURL note) "/" (name %)))
|
|
||||||
(get-message %))
|
|
||||||
[:notehub :stats :edit :export :short-url])
|
|
||||||
links (interpose [:span.middot "·"] links)]
|
|
||||||
[:div#footer links]))))
|
|
||||||
|
|||||||
Reference in New Issue
Block a user