From: Tom Clegg Date: Tue, 15 Jan 2013 20:15:55 +0000 (-0800) Subject: add /collections html view, dry up CollectionsController X-Git-Tag: 1.1.0~3512 X-Git-Url: https://git.arvados.org/arvados.git/commitdiff_plain/8d26e6e46a5f2c15fa64b2cd4673bc5ee9ee100e add /collections html view, dry up CollectionsController --- diff --git a/app/controllers/collections_controller.rb b/app/controllers/collections_controller.rb new file mode 100644 index 0000000000..1714f68c99 --- /dev/null +++ b/app/controllers/collections_controller.rb @@ -0,0 +1,5 @@ +class CollectionsController < ApplicationController + def index + @objects = model_class.order("created_at desc") + end +end diff --git a/app/controllers/orvos/v1/collections_controller.rb b/app/controllers/orvos/v1/collections_controller.rb index ccdf384303..33a59a06ca 100644 --- a/app/controllers/orvos/v1/collections_controller.rb +++ b/app/controllers/orvos/v1/collections_controller.rb @@ -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 diff --git a/app/models/collection.rb b/app/models/collection.rb index ccb2ccb8f0..6cbe330f3a 100644 --- a/app/models/collection.rb +++ b/app/models/collection.rb @@ -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 index 0000000000..a73c74babe --- /dev/null +++ b/app/views/collections/index.html.erb @@ -0,0 +1,47 @@ + + + + + + <% @objects.each do |o| %> + + + + + + <% if %> + + + + + <% end %> + <% end %> +
+ redundancy + + uuid + + name + + locator + + last updated +
+ <%= o.redundancy_status %> (<%= o.redundancy %>) + + <%= o.uuid %> + + <%= o.name %> + + <%= o.locator %> + + <%= distance_of_time_in_words(o.updated_at, Time.now, true) + ' ago' if o.updated_at %> +
+ + + + +
+ (file list not available) +
+