From 8425aaecd28a8f659002200e67dcc9dafc5e8846 Mon Sep 17 00:00:00 2001 From: Will Bradley Date: Fri, 14 Feb 2014 01:09:16 -0700 Subject: [PATCH] Adding pictures to resources --- app/models/resource.rb | 28 +++++++++----- app/views/layouts/resources.html.erb | 10 ++--- app/views/resources/_form.html.erb | 38 +++++++++++-------- app/views/resources/_resource.html.erb | 2 +- app/views/resources/edit.html.erb | 4 +- app/views/resources/index.html.erb | 13 +++++-- app/views/resources/new.html.erb | 4 +- app/views/resources/show.html.erb | 27 +++++++++++-- ...14070420_add_more_pictures_to_resources.rb | 16 ++++++++ db/schema.rb | 14 ++++++- 10 files changed, 115 insertions(+), 41 deletions(-) create mode 100644 db/migrate/20140214070420_add_more_pictures_to_resources.rb diff --git a/app/models/resource.rb b/app/models/resource.rb index d829a25..43448e1 100755 --- a/app/models/resource.rb +++ b/app/models/resource.rb @@ -1,17 +1,27 @@ class Resource < ActiveRecord::Base - attr_accessible :supercategory, :user_id, :resource_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, :modified_by + attr_accessible :supercategory, :user_id, :resource_category_id, :name, :serial, :specs, :status, :donatable, +:picture, :picture_file_name, :picture_content_type, :picture_file_size, :picture_updated_at, +:picture2, :picture2_file_name, :picture2_content_type, :picture2_file_size, :picture2_updated_at, +:picture3, :picture3_file_name, :picture3_content_type, :picture3_file_size, :picture3_updated_at, +:picture4, :picture4_file_name, :picture4_content_type, :picture4_file_size, :picture4_updated_at, + :notes, :estimated_value, :disposed_at, :modified_by belongs_to :owner, :class_name => "ToolshareUser" #TODO: remove owner belongs_to :user belongs_to :resource_category - has_attached_file :picture, #TODO: move to local storage - :styles => { :medium => "300x300>", - :thumb => "100x100>", - :tiny => "50x50>"}, - :storage => :s3, - :s3_credentials => Rails.root.join('config', 's3.yml'), - :path => ":attachment/:id/:style.:extension", - :bucket => 'Toolshare' + + PICTURE_OPTIONS = { :styles => { :medium => "300x300>", + :thumb => "100x100>", + :tiny => "50x50>"}, + :storage => :s3, + :s3_credentials => Rails.root.join('config', 's3.yml'), + :path => ":attachment/:id/:style.:extension", + :bucket => 'Toolshare' } + + has_attached_file :picture, PICTURE_OPTIONS #TODO: move to local storage + has_attached_file :picture2, PICTURE_OPTIONS + has_attached_file :picture3, PICTURE_OPTIONS + has_attached_file :picture4, PICTURE_OPTIONS def resource_category_name resource_category.name if resource_category diff --git a/app/views/layouts/resources.html.erb b/app/views/layouts/resources.html.erb index 8e16134..525052e 100755 --- a/app/views/layouts/resources.html.erb +++ b/app/views/layouts/resources.html.erb @@ -12,9 +12,9 @@ diff --git a/app/views/resources/_form.html.erb b/app/views/resources/_form.html.erb index 21cf8fb..6c9c2de 100644 --- a/app/views/resources/_form.html.erb +++ b/app/views/resources/_form.html.erb @@ -1,4 +1,4 @@ -<%= form_for @resource, :html => { :multipart => true } do |f| %> +<%= form_for @resource, :html => { :multipart => true, class: "col-sm-6" } do |f| %> <% if @resource.errors.any? %>

<%= pluralize(@resource.errors.count, "error") %> prohibited this resource from being saved:

@@ -13,26 +13,26 @@

<%= f.label :resource_category_id, "Category" %>
- <%= select(:resource, :resource_category_id, options_from_collection_for_select(ResourceCategory.all.sort_by(&:name), :id, :name, @resource.resource_category_id ) ) %> + <%= select(:resource, :resource_category_id, options_from_collection_for_select(ResourceCategory.all.sort_by(&:name), :id, :name, @resource.resource_category_id ), {}, {class: "form-control"} ) %>

<%= f.label :name %>
- <%= f.text_field :name %> + <%= f.text_field :name, class: "form-control" %>

<%= f.label :serial, "Serial" %>
- <%= f.text_field :serial %> + <%= f.text_field :serial, class: "form-control" %>

<%= f.label :specs, "Specs" %>
- <%= f.text_field :specs %> + <%= f.text_field :specs, class: "form-control" %>

<%= f.label :status, "Status/Location" %>
- <%= f.text_field :status %> + <%= f.text_field :status, class: "form-control" %>

@@ -43,7 +43,7 @@

<%= f.label :user_id, "Owner" %>
- <%= select(:resource, :user_id, options_from_collection_for_select(@users, :id, :name, @resource.user_id), include_blank: true) %> + <%= select(:resource, :user_id, options_from_collection_for_select(@users, :id, :name, @resource.user_id), {include_blank: true}, {class: "form-control"}) %>

@@ -53,21 +53,27 @@

<%= f.label :estimated_value, "Estimated Value" %>
- <%= f.text_field :estimated_value %> + <%= f.text_field :estimated_value, class: "form-control" %>

-

- <%= f.label :picture %>
- <%= f.file_field :picture %> - <%= link_to image_tag(@resource.picture.url(:tiny)), @resource.picture.url, :popup => ['form_image_preview', 'height=300,width=400'] if @resource.picture? %> -

+ <% [:picture, :picture2, :picture3, :picture4].each do |p| %> +

+ + <%= f.label p %>
+ <%= f.file_field p %> +
+ + <%= link_to image_tag(@resource.send(p).url(:tiny)), @resource.send(p).url unless @resource.send(p).blank? %> + +

+ <% end %> +

<%= f.label :notes %>
- <%= f.text_area :notes %> + <%= f.text_area :notes, class: "form-control" %>

- <%= f.submit %> + <%= f.submit nil, class: "btn btn-primary" %>

<% end %> -<%= link_to 'Back', resources_path %> diff --git a/app/views/resources/_resource.html.erb b/app/views/resources/_resource.html.erb index 3b7cb97..56df6c3 100755 --- a/app/views/resources/_resource.html.erb +++ b/app/views/resources/_resource.html.erb @@ -1,4 +1,4 @@ -
+
<%= link_to(resource) do %> <% if resource.user %> diff --git a/app/views/resources/edit.html.erb b/app/views/resources/edit.html.erb index 324db8f..46288c6 100644 --- a/app/views/resources/edit.html.erb +++ b/app/views/resources/edit.html.erb @@ -1,2 +1,4 @@ -

Edit Resource

+

Edit Resource +<%= link_to 'Back', resources_path, class: "btn btn-default" %> +

<%= render 'form' %> diff --git a/app/views/resources/index.html.erb b/app/views/resources/index.html.erb index 02d4771..9740b29 100755 --- a/app/views/resources/index.html.erb +++ b/app/views/resources/index.html.erb @@ -1,10 +1,13 @@ -

Lab Resources +

Lab Resources <%= link_to 'Add Resource', new_resource_path, :class => "btn btn-success" if can? :create, Resource %> <%= link_to 'Categories', resource_categories_path, :class => "btn btn-primary" if can? :read, ResourceCategory %> + Expand/Collapse All

-

Featured item:

+ +

Featured item:

<%= render @featured_resource %> +
<% unless @resources.blank? %> @@ -18,7 +21,11 @@
- <%= render resources %> + <% resources.each do |resource| %> +
+ <%= render resource %> +
+ <% end %>
diff --git a/app/views/resources/new.html.erb b/app/views/resources/new.html.erb index 6a853e5..80bf4db 100644 --- a/app/views/resources/new.html.erb +++ b/app/views/resources/new.html.erb @@ -1,2 +1,4 @@ -

New Resource

+

New Resource +<%= link_to 'Back', resources_path, class: "btn btn-default" %> +

<%= render 'form' %> diff --git a/app/views/resources/show.html.erb b/app/views/resources/show.html.erb index fb2b9d8..e914e14 100644 --- a/app/views/resources/show.html.erb +++ b/app/views/resources/show.html.erb @@ -1,4 +1,21 @@ -<%= link_to image_tag(@resource.picture.url(:medium)), @resource.picture.url, :popup => ['show_image_preview', 'height=300,width=400'] if @resource.picture? %> +
+
+
+
+ <%= link_to image_tag(@resource.picture.url(:medium), height: 300, width: 300), @resource.picture.url if @resource.picture? %> +
+
+
+ <% [:picture2, :picture3, :picture4].each do |p| %> + <% unless @resource.send(p).blank? %> +
+ <%= link_to image_tag(@resource.send(p).url(:thumb)), @resource.send(p).url %> +
+ <% end %> + <% end %> +
+
+

<%=h @resource.name %> <%= link_to 'Back', resources_path, class: "btn btn-default" %> @@ -47,9 +64,11 @@

Notes: - <%=h @resource.notes %> +

+
+ <%= simple_format @resource.notes %> +
+

- - <%= 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/20140214070420_add_more_pictures_to_resources.rb b/db/migrate/20140214070420_add_more_pictures_to_resources.rb new file mode 100644 index 0000000..a357002 --- /dev/null +++ b/db/migrate/20140214070420_add_more_pictures_to_resources.rb @@ -0,0 +1,16 @@ +class AddMorePicturesToResources < ActiveRecord::Migration + def change + add_column :resources, :picture2_file_name, :string + add_column :resources, :picture2_content_type, :string + add_column :resources, :picture2_file_size, :integer + add_column :resources, :picture2_updated_at, :datetime + add_column :resources, :picture3_file_name, :string + add_column :resources, :picture3_content_type, :string + add_column :resources, :picture3_file_size, :integer + add_column :resources, :picture3_updated_at, :datetime + add_column :resources, :picture4_file_name, :string + add_column :resources, :picture4_content_type, :string + add_column :resources, :picture4_file_size, :integer + add_column :resources, :picture4_updated_at, :datetime + end +end diff --git a/db/schema.rb b/db/schema.rb index 2c8371b..002efd5 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 => 20140214055051) do +ActiveRecord::Schema.define(:version => 20140214070420) do create_table "cards", :force => true do |t| t.string "card_number" @@ -143,6 +143,18 @@ ActiveRecord::Schema.define(:version => 20140214055051) do t.integer "user_id" t.datetime "disposed_at" t.integer "modified_by" + t.string "picture2_file_name" + t.string "picture2_content_type" + t.integer "picture2_file_size" + t.datetime "picture2_updated_at" + t.string "picture3_file_name" + t.string "picture3_content_type" + t.integer "picture3_file_size" + t.datetime "picture3_updated_at" + t.string "picture4_file_name" + t.string "picture4_content_type" + t.integer "picture4_file_size" + t.datetime "picture4_updated_at" end create_table "settings", :force => true do |t|