Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

List view with (partial) links.

  • Loading branch information...
commit 4740cba86e094fd8ffe78287c72f5b60cad1e098 1 parent e29df38
Sean Corfield authored
Showing with 36 additions and 2 deletions.
  1. +13 −2 src/example/controllers/user.clj
  2. +23 −0 src/example/views/user/list.html
15 src/example/controllers/user.clj
View
@@ -14,6 +14,9 @@
(def ^:private users (atom initial-user-data))
;; data access methods - would be in a service
+(defn- get-department-by-id [id]
+ (first (filter #(== id (:id %)) departments)))
+
(defn- get-user-by-id [id]
(first (filter #(== id (:id %)) @users)))
@@ -59,5 +62,13 @@
identity)
(content (:name dept)))))))
-(defn form-list [rc nodes]
- nodes)
+(defn list-view [rc nodes]
+ (at nodes
+ [:tr.zero] (if (empty? @users) identity (substitute ""))
+ [:tr.user]
+ (clone-for [user @users]
+ [:td.id :a] (content (str (:id user)))
+ [:td.name :a] (content (str (:first-name user) " " (:last-name user)))
+ [:td.email] (content (:email user))
+ [:td.department] (content (:name (get-department-by-id (:department-id user))))
+ )))
23 src/example/views/user/list.html
View
@@ -0,0 +1,23 @@
+<table border="0" cellspacing="0">
+ <col width="40" />
+ <thead>
+ <tr>
+ <th>Id</th>
+ <th>Name</th>
+ <th>Email</th>
+ <th>Department</th>
+ <th>Delete</th>
+ </tr>
+ </thead>
+ <tbody>
+ <!-- need to make this conditional -->
+ <tr class="zero"><td colspan="5">No users exist but <a href="/user/form">new ones can be added</a>.</td></tr>
+ <tr class="user">
+ <td class="id"><a href="/user/form/id/">#local.id#</a></td>
+ <td class="name"><a href="/user/form/id/">#local.user.getFirstName()# #local.user.getLastName()#</a></td>
+ <td class="email">#local.user.getEmail()#</td>
+ <td class="department">#local.user.getDepartment().getName()#</td>
+ <td class="delete"><a href="/user/delete/id/">DELETE</a></td>
+ </tr>
+ </tbody>
+</table>
Please sign in to comment.
Something went wrong with that request. Please try again.