add /collections html view, dry up CollectionsController
authorTom Clegg <tom@clinicalfuture.com>
Tue, 15 Jan 2013 20:15:55 +0000 (12:15 -0800)
committerTom Clegg <tom@clinicalfuture.com>
Tue, 15 Jan 2013 20:15:55 +0000 (12:15 -0800)
app/controllers/collections_controller.rb [new file with mode: 0644]
app/controllers/orvos/v1/collections_controller.rb
app/models/collection.rb
app/views/collections/index.html.erb [new file with mode: 0644]

diff --git a/app/controllers/collections_controller.rb b/app/controllers/collections_controller.rb
new file mode 100644 (file)
index 0000000..1714f68
--- /dev/null
@@ -0,0 +1,5 @@
+class CollectionsController < ApplicationController
+  def index
+    @objects = model_class.order("created_at desc")
+  end
+end
index ccdf3843032c10a14da3d8ae30f3453956fb3e24..33a59a06ca0c962b7bd4f8603cde8330cb801d5f 100644 (file)
@@ -1,94 +1,2 @@
 class Orvos::V1::CollectionsController < ApplicationController
-  # GET /collections
-  # GET /collections.json
-  def index
-    @collections = Collection.all
-
-    @collectionlist = {
-      :kind  => "orvos#collectionList",
-      :etag => "",
-      :self_link => "",
-      :next_page_token => "",
-      :next_link => "",
-      :items => @collections.map { |collection| collection }
-    }
-    respond_to do |format|
-      format.json { render json: @collectionlist }
-    end
-  end
-
-  # GET /collections/1
-  # GET /collections/1.json
-  def show
-    @collection = Collection.find(params[:id])
-
-    respond_to do |format|
-      format.html # show.html.erb
-      format.json { render json: @collection }
-    end
-  end
-
-  # GET /collections/new
-  # GET /collections/new.json
-  def new
-    @collection = Collection.new
-
-    respond_to do |format|
-      format.html # new.html.erb
-      format.json { render json: @collection }
-    end
-  end
-
-  # GET /collections/1/edit
-  def edit
-    @collection = Collection.find(params[:id])
-  end
-
-  # POST /collections
-  # POST /collections.json
-  def create
-    if params[:collection].class == String
-      @collection = Collection.new(JSON.parse(params[:collection]))
-    else
-      @collection = Collection.new(params[:collection])
-    end
-
-    respond_to do |format|
-      if @collection.save
-        format.html { redirect_to @collection, notice: 'Collection was successfully created.' }
-        format.json { render json: @collection, status: :created, location: @collection }
-      else
-        format.html { render action: "new" }
-        format.json { render json: @collection.errors, status: :unprocessable_entity }
-      end
-    end
-  end
-
-  # PUT /collections/1
-  # PUT /collections/1.json
-  def update
-    @collection = Collection.find(params[:id])
-
-    respond_to do |format|
-      if @collection.update_attributes(params[:collection])
-        format.html { redirect_to @collection, notice: 'Collection was successfully updated.' }
-        format.json { head :ok }
-      else
-        format.html { render action: "edit" }
-        format.json { render json: @collection.errors, status: :unprocessable_entity }
-      end
-    end
-  end
-
-  # DELETE /collections/1
-  # DELETE /collections/1.json
-  def destroy
-    @collection = Collection.find(params[:id])
-    @collection.destroy
-
-    respond_to do |format|
-      format.html { redirect_to collections_url }
-      format.json { head :ok }
-    end
-  end
 end
index ccb2ccb8f03404082be4e59d3b15df70116f230f..6cbe330f3a80ed8de84eecac8bd2bb69abf05973 100644 (file)
@@ -12,4 +12,20 @@ class Collection < ActiveRecord::Base
     t.add :redundancy_confirmed_at
     t.add :redundancy_confirmed_as
   end
+
+  def redundancy_status
+    if redundancy_confirmed_as.nil?
+      'unconfirmed'
+    elsif redundancy_confirmed_as < redundancy
+      'degraded'
+    else
+      if redundancy_confirmed_at.nil?
+        'unconfirmed'
+      elsif Time.now - redundancy_confirmed_at < 7.days
+        'OK'
+      else
+        'stale'
+      end
+    end
+  end
 end
diff --git a/app/views/collections/index.html.erb b/app/views/collections/index.html.erb
new file mode 100644 (file)
index 0000000..a73c74b
--- /dev/null
@@ -0,0 +1,47 @@
+<table style="width:100%">
+  <tr class="contain-align-left">
+    <th>
+      redundancy
+    </th><th>
+      uuid
+    </th><th>
+      name
+    </th><th>
+      locator
+    </th><th>
+      last updated
+    </th>
+  </tr>
+
+  <% @objects.each do |o| %>
+
+  <tr class="collection-redundancy-status collection-redundancy-status-<%= o.redundancy_status %>" data-showhide-selector="tr#extra-info-<%= o.uuid %>" style="cursor:pointer">
+    <td>
+      <%= o.redundancy_status %> (<%= o.redundancy %>)
+    </td><td>
+      <%= o.uuid %>
+    </td><td>
+      <%= o.name %>
+    </td><td>
+      <%= o.locator %>
+    </td><td>
+      <%= distance_of_time_in_words(o.updated_at, Time.now, true) + ' ago' if o.updated_at %>
+    </td>
+  </tr>
+
+  <% if  %>
+  <tr id="extra-info-<%= o.uuid %>" data-showhide-default>
+    <td colspan="5">
+      <table>
+       <tr>
+         <td>
+           (file list not available)
+         </td>
+       </tr>
+      </table>
+    </td>
+  </tr>
+
+  <% end %>
+  <% end %>
+</table>