add tabular /collections
authorTom Clegg <tom@clinicalfuture.com>
Fri, 1 Feb 2013 06:52:20 +0000 (22:52 -0800)
committerTom Clegg <tom@clinicalfuture.com>
Fri, 1 Feb 2013 06:52:20 +0000 (22:52 -0800)
app/controllers/collections_controller.rb
app/views/collections/index.html.erb

index f14b82fe9d99ffb29f00ac2f1c1e0126d7acd972..09d4fe5c884ef5bb3c1796dce8fadcb342a3e088 100644 (file)
@@ -6,7 +6,32 @@ class CollectionsController < ApplicationController
   end
 
   def index
-    @links = Link.where(head_kind: 'orvos#collection') |
-      Link.where(tail_kind: 'orvos#collection')
+    @links = Link.eager.where(head_kind: 'orvos#collection') |
+      Link.eager.where(tail_kind: 'orvos#collection')
+    @collections = {}
+    @links.each do |l|
+      if l.head_kind == 'orvos#collection'
+        c = (@collections[l.head_uuid] ||= {uuid: l.head_uuid})
+        if l.link_class == 'resources' and l.name == 'wants'
+          if l.head.respond_to? :created_at
+            c[:created_at] = l.head.created_at
+          end
+          c[:wanted] = true
+          if l.owner == current_user.uuid
+            c[:wanted_by_me] = true
+          end
+        end
+      end
+      if l.tail_kind == 'orvos#collection'
+        c = (@collections[l.tail_uuid] ||= {uuid: l.tail_uuid})
+        if l.link_class == 'group' and l.name == 'member_of'
+          c[:projects] ||= {}
+          c[:projects][l.tail_uuid] = true
+        end
+        if l.link_class == 'data_origin'
+          c[:origin] = l
+        end
+      end
+    end
   end
 end
index fe4360756f4a90f5c34753dd79c0f0fd1c8e6ee2..13a0eb1a3ba869b5be3df612f294d498c53a6315 100644 (file)
@@ -1,5 +1,56 @@
-    <h1>Bootstrap starter template</h1>
-    <p>Use this document as a way to quick start any new project.<br> All you get is this message and a barebones HTML document.</p>
+<% content_for :head do %>
+<style>
+  table.topalign>tbody>tr>td {
+  vertical-align: top;
+  }
+  table.topalign>thead>tr>td {
+  vertical-align: bottom;
+  }
+  .deemphasize {
+  font-size: .8em;
+  color: #888;
+  }
+</style>
+<% end %>
 
-<p>foo
-</p>
+<table class="topalign">
+  <thead>
+    <tr class="contain-align-left">
+      <th>
+       uuid
+      </th><th>
+       created
+      </th><th>
+       protected
+      </th><th>
+       projects
+      </th><th>
+       origin
+      </th>
+    </tr>
+  </thead>
+  <tbody>
+
+    <% @collections.values.sort_by { |c| c[:created_at] }.reverse.each do |c| %>
+
+    <tr class="collection">
+      <td>
+       <%= c[:uuid] %>
+      </td><td>
+       <%= distance_of_time_in_words(c[:created_at], Time.now).sub('about ','~').sub(' ','&nbsp;') if c[:created_at] %>
+      </td><td>
+       <%= ('Y' if c[:wanted_by_me]) or ('y' if c[:wanted]) %>
+      </td><td>
+       <%= c[:projects].size if c[:projects] %>
+      </td><td>
+       <% if c[:origin] %>
+       <span class="deemphasize"><%= c[:origin].name %></span>
+       <%= c[:origin].head_uuid %>
+       <% end %>
+      </td>
+    </tr>
+
+    <% end %>
+
+  </tbody>
+</table>