Permalink
Browse files

Add view for individual resources.

  • Loading branch information...
1 parent 86d833a commit b58d5632dd4d9e1694b76a250595d3a08794cb53 Mike Simpson committed Aug 5, 2012
@@ -117,3 +117,13 @@
(defn find-user [username]
(let [conn (d/connect (uri datomic-config))]
(first (first (q `[:find ?c :where [?c user/username ~username]] (db conn))))))
+
+(defn find-resource [id]
+(let [conn (d/connect (uri datomic-config))
+ entity (datomic.api/entity (db conn) id)]
+ {
+ :name (:resource/name entity)
+ :description (:resource/description entity)
+ }
+ )
+)
@@ -13,4 +13,8 @@
(defn get-all []
- (map (partial zipmap '(:id :name :description)) (db/get-all-resources)))
+ (map (partial zipmap '(:id :name :description)) (db/get-all-resources)))
+
+(defn get-by-id [id]
+ (db/find-resource (read-string id))
+ )
@@ -3,37 +3,56 @@
hiccup.core
hiccup.page
hiccup.element)
- (:require [shared-resource.models.resource :as resource]
+ (:require [shared-resource.models.resource :as r]
[shared-resource.views.common :as common]
[noir.response :as resp]))
;; Partials
(defpartial resource-list [
{:keys [
- perma-link
+ id
name
description
- start-time
- end-time
]
:as resource-item}
]
(when resource-item
[:li.resource-item
- [:h2 name]
+ [:h2 (link-to (str "resources/" id) name)]
[:div.content description]
;;(when (user/admin?)
- ;[:li (link-to (resource/edit-url post) "edit")])
]))
+
+(defpartial show-resource [
+ {:keys [
+ name
+ description
+ ]
+ :as resource-item}
+ ]
+ [:h2 name]
+ [:div.content description]
+ ;;(when (user/admin?)
+ )
+
(defpartial resources-page [resources]
(common/layout
[:ul.resources
(map resource-list resources)]
))
+
+(defpartial resource-page [resource]
+ (common/layout
+ (show-resource resource)))
+
;; Page structure
-(defpage "/" []
- (resources-page (resource/get-all)))
+ (defpage "/resources" []
+ (resources-page (r/get-all)))
+
+(defpage "/resources/:id" {:keys [id]}
+ (resource-page (r/get-by-id id)))
+

0 comments on commit b58d563

Please sign in to comment.