Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

List view with (partial) links.

  • Loading branch information...
commit 4740cba86e094fd8ffe78287c72f5b60cad1e098 1 parent e29df38
Sean Corfield authored
15 src/example/controllers/user.clj
@@ -14,6 +14,9 @@
14 14 (def ^:private users (atom initial-user-data))
15 15
16 16 ;; data access methods - would be in a service
  17 +(defn- get-department-by-id [id]
  18 + (first (filter #(== id (:id %)) departments)))
  19 +
17 20 (defn- get-user-by-id [id]
18 21 (first (filter #(== id (:id %)) @users)))
19 22
@@ -59,5 +62,13 @@
59 62 identity)
60 63 (content (:name dept)))))))
61 64
62   -(defn form-list [rc nodes]
63   - nodes)
  65 +(defn list-view [rc nodes]
  66 + (at nodes
  67 + [:tr.zero] (if (empty? @users) identity (substitute ""))
  68 + [:tr.user]
  69 + (clone-for [user @users]
  70 + [:td.id :a] (content (str (:id user)))
  71 + [:td.name :a] (content (str (:first-name user) " " (:last-name user)))
  72 + [:td.email] (content (:email user))
  73 + [:td.department] (content (:name (get-department-by-id (:department-id user))))
  74 + )))
23 src/example/views/user/list.html
... ... @@ -0,0 +1,23 @@
  1 +<table border="0" cellspacing="0">
  2 + <col width="40" />
  3 + <thead>
  4 + <tr>
  5 + <th>Id</th>
  6 + <th>Name</th>
  7 + <th>Email</th>
  8 + <th>Department</th>
  9 + <th>Delete</th>
  10 + </tr>
  11 + </thead>
  12 + <tbody>
  13 + <!-- need to make this conditional -->
  14 + <tr class="zero"><td colspan="5">No users exist but <a href="/user/form">new ones can be added</a>.</td></tr>
  15 + <tr class="user">
  16 + <td class="id"><a href="/user/form/id/">#local.id#</a></td>
  17 + <td class="name"><a href="/user/form/id/">#local.user.getFirstName()# #local.user.getLastName()#</a></td>
  18 + <td class="email">#local.user.getEmail()#</td>
  19 + <td class="department">#local.user.getDepartment().getName()#</td>
  20 + <td class="delete"><a href="/user/delete/id/">DELETE</a></td>
  21 + </tr>
  22 + </tbody>
  23 +</table>

0 comments on commit 4740cba

Please sign in to comment.
Something went wrong with that request. Please try again.