Adding pictures to resources

This commit is contained in:
Will Bradley 2014-02-14 01:09:16 -07:00
parent 8a31655fd3
commit 8425aaecd2
10 changed files with 115 additions and 41 deletions

View File

@ -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

View File

@ -12,9 +12,9 @@
<style>
.thumbnail { height: 150px; position: relative; }
.thumbnail .ownership,
.thumbnail .disposed
.resource .thumbnail { height: 150px; position: relative; }
.resource .thumbnail .ownership,
.resource .thumbnail .disposed
{ position: absolute; top: 1px;
text-shadow:
-1px -1px 0 #fff,
@ -22,8 +22,8 @@
-1px 1px 0 #fff,
1px 1px 0 #fff;
font-weight: bold; left: 10px; }
.thumbnail .disposed { color: red; }
.thumbnail h4 { position: absolute; bottom: 1px; margin-bottom: 1px; }
.resource .thumbnail .disposed { color: red; }
.resource .thumbnail h4 { position: absolute; bottom: 1px; margin-bottom: 1px; }
</style>

View File

@ -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? %>
<div id="error_explanation">
<h2><%= pluralize(@resource.errors.count, "error") %> prohibited this resource from being saved:</h2>
@ -13,26 +13,26 @@
<p>
<%= f.label :resource_category_id, "Category" %><br />
<%= 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"} ) %>
</p>
<p>
<%= f.label :name %><br />
<%= f.text_field :name %>
<%= f.text_field :name, class: "form-control" %>
</p>
<p>
<%= f.label :serial, "Serial" %>
<br />
<%= f.text_field :serial %>
<%= f.text_field :serial, class: "form-control" %>
</p>
<p>
<%= f.label :specs, "Specs" %>
<br/>
<%= f.text_field :specs %>
<%= f.text_field :specs, class: "form-control" %>
</p>
<p>
<%= f.label :status, "Status/Location" %>
<br/>
<%= f.text_field :status %>
<%= f.text_field :status, class: "form-control" %>
</p>
<p>
@ -43,7 +43,7 @@
<p>
<%= f.label :user_id, "Owner" %>
<br />
<%= 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"}) %>
</p>
<p>
@ -53,21 +53,27 @@
<p>
<%= f.label :estimated_value, "Estimated Value" %><br />
<%= f.text_field :estimated_value %>
<%= f.text_field :estimated_value, class: "form-control" %>
</p>
<p>
<%= f.label :picture %><br />
<%= 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? %>
</p>
<% [:picture, :picture2, :picture3, :picture4].each do |p| %>
<p class="row">
<span class="col-sm-3">
<%= f.label p %><br />
<%= f.file_field p %>
</span>
<span class="col-sm-2">
<%= link_to image_tag(@resource.send(p).url(:tiny)), @resource.send(p).url unless @resource.send(p).blank? %>
</span>
</p>
<% end %>
<p>
<%= f.label :notes %><br />
<%= f.text_area :notes %>
<%= f.text_area :notes, class: "form-control" %>
</p>
<p>
<%= f.submit %>
<%= f.submit nil, class: "btn btn-primary" %>
</p>
<% end %>
<%= link_to 'Back', resources_path %>

View File

@ -1,4 +1,4 @@
<div class="col-sm-2">
<div class="resource">
<div class="thumbnail">
<%= link_to(resource) do %>
<% if resource.user %>

View File

@ -1,2 +1,4 @@
<h1>Edit Resource</h1>
<h1>Edit Resource
<%= link_to 'Back', resources_path, class: "btn btn-default" %>
</h1>
<%= render 'form' %>

View File

@ -1,10 +1,13 @@
<h1 class="col-sm-4">Lab Resources
<h1 class="col-sm-6">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 %>
<a class="btn btn-default" onclick="$('#accordion .collapse').collapse('toggle')" />Expand/Collapse All</a>
</h1>
<h3 class="col-sm-2">Featured item:</h3>
<span class="col-sm-2">
<h3>Featured item:</h3>
<%= render @featured_resource %>
</span>
<div class="row">
<% unless @resources.blank? %>
@ -18,7 +21,11 @@
</div>
<div id="collapse_cat_<%= resource_category.id %>" class="panel-collapse collapse">
<div class="panel-body">
<%= render resources %>
<% resources.each do |resource| %>
<div class="col-sm-2">
<%= render resource %>
</div>
<% end %>
</div>
</div>
</div>

View File

@ -1,2 +1,4 @@
<h1>New Resource</h1>
<h1>New Resource
<%= link_to 'Back', resources_path, class: "btn btn-default" %>
</h1>
<%= render 'form' %>

View File

@ -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? %>
<div class="row">
<div class="thumbnail" style="width: 300px">
<div class="row">
<div class="col-xs-12">
<%= link_to image_tag(@resource.picture.url(:medium), height: 300, width: 300), @resource.picture.url if @resource.picture? %>
</div>
</div>
<div class="row">
<% [:picture2, :picture3, :picture4].each do |p| %>
<% unless @resource.send(p).blank? %>
<div class="col-xs-4">
<%= link_to image_tag(@resource.send(p).url(:thumb)), @resource.send(p).url %>
</div>
<% end %>
<% end %>
</div>
</div>
</div>
<h2><%=h @resource.name %>
<%= link_to 'Back', resources_path, class: "btn btn-default" %>
@ -47,9 +64,11 @@
<p>
<b>Notes:</b>
<%=h @resource.notes %>
<div class="row">
<div class="col-sm-6">
<%= simple_format @resource.notes %>
</div>
</div>
</p>
<%= 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 %>

View File

@ -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

View File

@ -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|