Adding resources (imported from old toolshare)
This commit is contained in:
4
app/controllers/resources_controller.rb
Normal file
4
app/controllers/resources_controller.rb
Normal file
@@ -0,0 +1,4 @@
|
||||
class ResourcesController < ApplicationController
|
||||
load_and_authorize_resource
|
||||
before_filter :authenticate_user!
|
||||
end
|
||||
@@ -1,4 +1,10 @@
|
||||
module ApplicationHelper
|
||||
@payment_methods = [[nil],["PayPal"],["Dwolla"],["Bill Pay"],["Check"],["Cash"],["Other"]]
|
||||
@payment_instructions = {nil => nil, :paypal => "Set up a monthly recurring payment to hslfinances@gmail.com", :dwolla => "Set up a monthly recurring payment to hslfinances@gmail.com", :billpay => "Have your bank send a monthly check to HeatSync Labs Treasurer, 140 W Main St, Mesa AZ 85201", :check => "Mail to HeatSync Labs Treasurer, 140 W Main St, Mesa AZ 85201 OR put in the drop safe at the Lab with a deposit slip firmly attached each month.", :cash => "Put in the drop safe at the Lab with a deposit slip firmly attached each month.", :other => "Hmm... talk to a Treasurer!"}
|
||||
|
||||
def sort_link(title, column, options = {})
|
||||
condition = options[:unless] if options.has_key?(:unless)
|
||||
sort_dir = params[:dir] == 'up' ? 'down' : 'up'
|
||||
link_to_unless condition, title, request.parameters.merge( {:sort => column, :dir => sort_dir} )
|
||||
end
|
||||
end
|
||||
|
||||
@@ -14,6 +14,7 @@ class Ability
|
||||
can [:update], Mac, :user_id => nil
|
||||
can [:create,:update], Mac, :user_id => user.id
|
||||
can :read, Payment, :user_id => user.id
|
||||
can :read, Resource
|
||||
can :read, UserCertification, :user_id => user.id
|
||||
can :read, User, :id => user.id #TODO: why can users update themselves? Maybe because Devise doesn't check users/edit?
|
||||
can :compose_email, User
|
||||
|
||||
12
app/models/resource.rb
Normal file
12
app/models/resource.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
class Resource < ActiveRecord::Base
|
||||
belongs_to :owner, :class_name => "ToolshareUser"
|
||||
belongs_to :category, :class_name => "ResourceCategory"
|
||||
has_attached_file :picture,
|
||||
:styles => { :medium => "300x300>",
|
||||
:thumb => "100x100>",
|
||||
:tiny => "50x50>"},
|
||||
:storage => :s3,
|
||||
:s3_credentials => Rails.root.join('config', 's3.yml'),
|
||||
:path => ":attachment/:id/:style.:extension",
|
||||
:bucket => 'Toolshare'
|
||||
end
|
||||
3
app/models/resource_category.rb
Normal file
3
app/models/resource_category.rb
Normal file
@@ -0,0 +1,3 @@
|
||||
class ResourceCategory < ActiveRecord::Base
|
||||
has_many :resources
|
||||
end
|
||||
4
app/models/toolshare_user.rb
Normal file
4
app/models/toolshare_user.rb
Normal file
@@ -0,0 +1,4 @@
|
||||
class ToolshareUser < ActiveRecord::Base
|
||||
has_many :resources, :foreign_key => "owner_id"
|
||||
attr_accessible :name, :email
|
||||
end
|
||||
38
app/views/resources/index.html.erb
Normal file
38
app/views/resources/index.html.erb
Normal file
@@ -0,0 +1,38 @@
|
||||
<h1>Resources</h1>
|
||||
|
||||
<%= link_to 'New Resource', 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>
|
||||
|
||||
<% 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>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</table>
|
||||
|
||||
<br />
|
||||
|
||||
Reference in New Issue
Block a user