diff --git a/app/controllers/resources_controller.rb b/app/controllers/resources_controller.rb index 1ccdec7..eebae3d 100755 --- a/app/controllers/resources_controller.rb +++ b/app/controllers/resources_controller.rb @@ -2,6 +2,10 @@ class ResourcesController < ApplicationController load_and_authorize_resource before_filter :authenticate_user!, :load_users + def index + @featured_resource = @resources.where("picture_file_name IS NOT NULL").sample + end + def create authorize! :create, @resource diff --git a/app/models/resource.rb b/app/models/resource.rb index b87f96e..8b40e86 100755 --- a/app/models/resource.rb +++ b/app/models/resource.rb @@ -1,5 +1,5 @@ class Resource < ActiveRecord::Base - attr_accessible :supercategory, :user_id, :category_id, :name, :serial, :specs, :status, :donatable, :picture, :picture_file_name, :picture_content_type, :picture_file_size, :picture_updated_at, :notes, :estimated_value + attr_accessible :supercategory, :user_id, :category_id, :name, :serial, :specs, :status, :donatable, :picture, :picture_file_name, :picture_content_type, :picture_file_size, :picture_updated_at, :notes, :estimated_value, :disposed_at belongs_to :owner, :class_name => "ToolshareUser" #TODO: remove owner belongs_to :user diff --git a/app/views/layouts/resources.html.erb b/app/views/layouts/resources.html.erb index 4b91797..7a35de0 100755 --- a/app/views/layouts/resources.html.erb +++ b/app/views/layouts/resources.html.erb @@ -17,6 +17,11 @@ float: left; margin-top: 5px; } + @media (max-width: 768px) { + #logo { + margin-left: 15px; + } + } #content { margin: 1em; } @@ -25,54 +30,66 @@
diff --git a/app/views/resources/_form.html.erb b/app/views/resources/_form.html.erb index 0242240..3af8080 100644 --- a/app/views/resources/_form.html.erb +++ b/app/views/resources/_form.html.erb @@ -34,7 +34,13 @@
<%= f.text_field :status %>

- <% if can? :assign_user, @resource %> + +

+ <%= f.label :disposed_at, "Disposed?" %>
+ <%= f.date_select :disposed_at, include_blank: true %> +

+ + <% if can? :assign_user, @resource %>

<%= f.label :user_id, "Owner" %>
diff --git a/app/views/resources/_resource.html.erb b/app/views/resources/_resource.html.erb index a7823e1..acb0c38 100755 --- a/app/views/resources/_resource.html.erb +++ b/app/views/resources/_resource.html.erb @@ -3,6 +3,9 @@ <% if resource.user %> Owned by:
<%= resource.user.name %>
<% end %> + <% if resource.disposed_at %> + Disposed:
<%= resource.disposed_at.to_date %>
+ <% end %> <%= link_to(resource) do %> <%= image_tag(resource.picture.url(:thumb)) if resource.picture? %>

<%=h resource.name %>

diff --git a/app/views/resources/index.html.erb b/app/views/resources/index.html.erb index d8e49f2..dbd0fb1 100755 --- a/app/views/resources/index.html.erb +++ b/app/views/resources/index.html.erb @@ -1,6 +1,3 @@ -

Lab Resources - <%= link_to 'Add Resource', new_resource_path, :class => "btn btn-success" if can? :create, Resource %> -

@@ -9,10 +6,28 @@ + +

Lab Resources + <%= link_to 'Add Resource', new_resource_path, :class => "btn btn-success" if can? :create, Resource %> +

+ +

Featured item:

+<%= render @featured_resource %> + +
<% unless @resources.blank? %>
<% @resources.sort_by{|r| [r.category_name,r.name] }.group_by(&:category).each do |category,resources| %> @@ -31,6 +46,7 @@ <% end %>
<% end %> +

diff --git a/app/views/resources/show.html.erb b/app/views/resources/show.html.erb index edd1ca0..01efe9b 100644 --- a/app/views/resources/show.html.erb +++ b/app/views/resources/show.html.erb @@ -3,9 +3,13 @@

<%=h @resource.name %> <%= link_to 'Back', resources_path, class: "btn btn-default" %> <%= link_to 'Edit', edit_resource_path(@resource), class: "btn btn-primary" %> -<%= link_to 'Delete', resource_path(@resource), {:confirm => 'Are you sure you want to delete this forever?', :method => :delete, :class => "btn btn-danger"} if can? :destroy, @resource %>

- +<% if @resource.user || @resource.owner %> +

+ Owner: + <%=h (@resource.user || @resource.owner).name %> +

+<% end %>

Category: <%=h @resource.category.name if !@resource.category.blank? %> @@ -24,6 +28,11 @@

Status/Location: <%=h @resource.status %> + + <% if @resource.disposed_at %> + Disposed: + <%=h @resource.disposed_at.to_date %> + <% end %>

@@ -43,3 +52,4 @@ +<%= link_to 'Delete', resource_path(@resource), {:confirm => 'Are you sure you want to delete this forever?', :method => :delete, :class => "btn btn-danger"} if can? :destroy, @resource %> diff --git a/db/migrate/20140209104356_add_disposed_at_to_resource.rb b/db/migrate/20140209104356_add_disposed_at_to_resource.rb new file mode 100644 index 0000000..4aae5c4 --- /dev/null +++ b/db/migrate/20140209104356_add_disposed_at_to_resource.rb @@ -0,0 +1,5 @@ +class AddDisposedAtToResource < ActiveRecord::Migration + def change + add_column :resources, :disposed_at, :datetime + end +end diff --git a/db/schema.rb b/db/schema.rb index de89034..52fde6c 100755 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20140209080523) do +ActiveRecord::Schema.define(:version => 20140209104356) do create_table "cards", :force => true do |t| t.string "card_number" @@ -141,6 +141,7 @@ ActiveRecord::Schema.define(:version => 20140209080523) do t.datetime "updated_at" t.string "estimated_value" t.integer "user_id" + t.datetime "disposed_at" end create_table "settings", :force => true do |t|