Adding resources (imported from old toolshare)

This commit is contained in:
2014-02-09 00:54:03 -07:00
parent 56450cf319
commit 1d0e8721e1
17 changed files with 212 additions and 2 deletions

View File

@@ -0,0 +1,4 @@
class ResourcesController < ApplicationController
load_and_authorize_resource
before_filter :authenticate_user!
end

View File

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

View File

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

View File

@@ -0,0 +1,3 @@
class ResourceCategory < ActiveRecord::Base
has_many :resources
end

View File

@@ -0,0 +1,4 @@
class ToolshareUser < ActiveRecord::Base
has_many :resources, :foreign_key => "owner_id"
attr_accessible :name, :email
end

View 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 />