Updating resources

This commit is contained in:
Will Bradley 2014-02-09 02:08:08 -07:00
parent e16e35e098
commit 58926cf3ab
7 changed files with 55 additions and 33 deletions

View File

@ -1,4 +1,13 @@
class ResourcesController < ApplicationController
load_and_authorize_resource
before_filter :authenticate_user!
def destroy
@resource.destroy
respond_to do |format|
format.html { redirect_to(request.env["HTTP_REFERER"]) }
format.json { head :ok }
end
end
end

View File

@ -1,7 +1,8 @@
class Resource < ActiveRecord::Base
belongs_to :owner, :class_name => "ToolshareUser"
belongs_to :owner, :class_name => "ToolshareUser" #TODO: remove owner
belongs_to :user
belongs_to :category, :class_name => "ResourceCategory"
has_attached_file :picture,
has_attached_file :picture, #TODO: move to local storage
:styles => { :medium => "300x300>",
:thumb => "100x100>",
:tiny => "50x50>"},
@ -9,4 +10,8 @@ class Resource < ActiveRecord::Base
:s3_credentials => Rails.root.join('config', 's3.yml'),
:path => ":attachment/:id/:style.:extension",
:bucket => 'Toolshare'
def category_name
self.category.name if self.category
end
end

View File

@ -4,7 +4,7 @@
<div class="payment_links <%= "payment-highlighted" if params[:flash] == "welcome_msg" %>">
<%= render '/statistics/index' %>
<%= render '/statistics/index' unless params[:flash] == "welcome_msg" %>
<% if can? :read, resource.payments.first then %>
<h3>Recorded Payments:</h3>
<ul>

View File

@ -0,0 +1,9 @@
<div class="col-sm-2">
<div class="thumbnail">
<%= link_to(resource) do %>
<%= image_tag(resource.picture.url(:thumb)) if resource.picture? %>
<strong><%=h resource.name %></strong>
<% end %>
<%= "Owned by "+resource.user.name if resource.user %>
</div>
</div>

View File

@ -1,38 +1,31 @@
<h1>Resources</h1>
<%= link_to 'New Resource', new_resource_path, :class => "btn" if can? :create, Resource %>
<%= link_to 'Add Equipment', new_resource_path, :class => "btn" if can? :create, Resource %>
<table class="lined-table">
<tr>
<th></th>
<th> <%= sort_link 'Owner', :owner_id %></th>
<th> <%= sort_link 'Category', :category_id %></th>
<th> <%= sort_link 'Name', :name %></th>
<th> <%= sort_link 'Serial', :serial %></th>
<th> <%= sort_link 'Status/Location', :status %></th>
</tr>
<style>
.collapsible .thumbnail { height: 150px; }
</style>
<% unless @resources.blank? %>
<% @resources.group_by(&:supercategory).each do |supercategory,resources| %>
<tr><th><%= supercategory %></th></tr>
<% resources.each do |resource| %>
<tr>
<td>
<%= link_to image_tag(resource.picture.url(:tiny)), resource.picture.url, :popup => ['index_image_preview', 'height=300,width=400'] if resource.picture? %>
</td>
<td>
<%=h resource.owner.name if resource.owner %>
<td><%=h resource.category.name unless resource.category.nil? %></td>
<td><%=h resource.name %></td>
<td><%=h resource.serial %></td>
<td><%=h resource.status %></td>
<td><%= link_to 'Edit', edit_resource_path(resource) if can? :update, resource %></td>
<td><%= link_to 'Destroy', resource, :confirm => 'Are you sure you want to delete this?', :method => :delete if can? :destroy, resource %></td>
</tr>
<div class="panel-group" id="accordion">
<% @resources.sort_by{|r| [r.category_name,r.name] }.group_by(&:category).each do |category,resources| %>
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">
<%= category.name %>
</a>
</h4>
</div>
<div id="collapseOne" class="panel-collapse collapse in">
<div class="panel-body">
<%= render resources %>
</div>
</div>
</div>
<% end %>
</div>
<% end %>
<% end %>
</table>
<br />

View File

@ -0,0 +1,5 @@
class AddUserIdToResource < ActiveRecord::Migration
def change
add_column :resources, :user_id, :integer
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 => 20140209072532) do
ActiveRecord::Schema.define(:version => 20140209080523) do
create_table "cards", :force => true do |t|
t.string "card_number"
@ -140,6 +140,7 @@ ActiveRecord::Schema.define(:version => 20140209072532) do
t.datetime "created_at"
t.datetime "updated_at"
t.string "estimated_value"
t.integer "user_id"
end
create_table "settings", :force => true do |t|