Updating resources
This commit is contained in:
parent
e16e35e098
commit
58926cf3ab
|
@ -1,4 +1,13 @@
|
||||||
class ResourcesController < ApplicationController
|
class ResourcesController < ApplicationController
|
||||||
load_and_authorize_resource
|
load_and_authorize_resource
|
||||||
before_filter :authenticate_user!
|
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
|
end
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
class Resource < ActiveRecord::Base
|
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"
|
belongs_to :category, :class_name => "ResourceCategory"
|
||||||
has_attached_file :picture,
|
has_attached_file :picture, #TODO: move to local storage
|
||||||
:styles => { :medium => "300x300>",
|
:styles => { :medium => "300x300>",
|
||||||
:thumb => "100x100>",
|
:thumb => "100x100>",
|
||||||
:tiny => "50x50>"},
|
:tiny => "50x50>"},
|
||||||
|
@ -9,4 +10,8 @@ class Resource < ActiveRecord::Base
|
||||||
:s3_credentials => Rails.root.join('config', 's3.yml'),
|
:s3_credentials => Rails.root.join('config', 's3.yml'),
|
||||||
:path => ":attachment/:id/:style.:extension",
|
:path => ":attachment/:id/:style.:extension",
|
||||||
:bucket => 'Toolshare'
|
:bucket => 'Toolshare'
|
||||||
|
|
||||||
|
def category_name
|
||||||
|
self.category.name if self.category
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
<div class="payment_links <%= "payment-highlighted" if params[:flash] == "welcome_msg" %>">
|
<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 %>
|
<% if can? :read, resource.payments.first then %>
|
||||||
<h3>Recorded Payments:</h3>
|
<h3>Recorded Payments:</h3>
|
||||||
<ul>
|
<ul>
|
||||||
|
|
9
app/views/resources/_resource.html.erb
Normal file
9
app/views/resources/_resource.html.erb
Normal 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>
|
|
@ -1,38 +1,31 @@
|
||||||
<h1>Resources</h1>
|
<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">
|
<style>
|
||||||
<tr>
|
.collapsible .thumbnail { height: 150px; }
|
||||||
<th></th>
|
</style>
|
||||||
<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>
|
|
||||||
|
|
||||||
<% unless @resources.blank? %>
|
<% unless @resources.blank? %>
|
||||||
<% @resources.group_by(&:supercategory).each do |supercategory,resources| %>
|
<div class="panel-group" id="accordion">
|
||||||
<tr><th><%= supercategory %></th></tr>
|
<% @resources.sort_by{|r| [r.category_name,r.name] }.group_by(&:category).each do |category,resources| %>
|
||||||
<% resources.each do |resource| %>
|
<div class="panel panel-default">
|
||||||
<tr>
|
<div class="panel-heading">
|
||||||
<td>
|
<h4 class="panel-title">
|
||||||
<%= link_to image_tag(resource.picture.url(:tiny)), resource.picture.url, :popup => ['index_image_preview', 'height=300,width=400'] if resource.picture? %>
|
<a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">
|
||||||
</td>
|
<%= category.name %>
|
||||||
<td>
|
</a>
|
||||||
<%=h resource.owner.name if resource.owner %>
|
</h4>
|
||||||
<td><%=h resource.category.name unless resource.category.nil? %></td>
|
</div>
|
||||||
<td><%=h resource.name %></td>
|
<div id="collapseOne" class="panel-collapse collapse in">
|
||||||
<td><%=h resource.serial %></td>
|
<div class="panel-body">
|
||||||
<td><%=h resource.status %></td>
|
<%= render resources %>
|
||||||
<td><%= link_to 'Edit', edit_resource_path(resource) if can? :update, resource %></td>
|
</div>
|
||||||
<td><%= link_to 'Destroy', resource, :confirm => 'Are you sure you want to delete this?', :method => :delete if can? :destroy, resource %></td>
|
</div>
|
||||||
</tr>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
</table>
|
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
|
|
||||||
|
|
5
db/migrate/20140209080523_add_user_id_to_resource.rb
Normal file
5
db/migrate/20140209080523_add_user_id_to_resource.rb
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
class AddUserIdToResource < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :resources, :user_id, :integer
|
||||||
|
end
|
||||||
|
end
|
|
@ -11,7 +11,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended to check this file into your version control system.
|
# 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|
|
create_table "cards", :force => true do |t|
|
||||||
t.string "card_number"
|
t.string "card_number"
|
||||||
|
@ -140,6 +140,7 @@ ActiveRecord::Schema.define(:version => 20140209072532) do
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
t.string "estimated_value"
|
t.string "estimated_value"
|
||||||
|
t.integer "user_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "settings", :force => true do |t|
|
create_table "settings", :force => true do |t|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user