More resource adding
This commit is contained in:
parent
74e60d4ec9
commit
23dcb0715c
|
@ -9,9 +9,11 @@ Copyright Will Bradley, 2012-2013
|
||||||
Distributed under a Creative Commons Attribution 3.0 license http://creativecommons.org/licenses/by/3.0/
|
Distributed under a Creative Commons Attribution 3.0 license http://creativecommons.org/licenses/by/3.0/
|
||||||
|
|
||||||
To use:
|
To use:
|
||||||
|
* Install Imagemagick (for Paperclip / image uploads)
|
||||||
* Load into a Rails 3 environment
|
* Load into a Rails 3 environment
|
||||||
* Copy config/config.yml.example to config/config.yml and edit appropriately
|
* Copy config/config.yml.example to config/config.yml and edit appropriately
|
||||||
* Copy config/database.yml.example to config/database.yml and edit appropriately
|
* Copy config/database.yml.example to config/database.yml and edit appropriately
|
||||||
|
* Copy config/s3.yml.example to config/s3.yml and edit appropriately OR adjust the resource.rb model settings to use different storage for picture attachments (via Paperclip)
|
||||||
* Copy config/initializers/secret_token.rb.example to config/config/initializers/secret_token.rb and edit appropriately
|
* Copy config/initializers/secret_token.rb.example to config/config/initializers/secret_token.rb and edit appropriately
|
||||||
* See/edit db/seeds.rb for the initial admin account info.
|
* See/edit db/seeds.rb for the initial admin account info.
|
||||||
* Run bundle install, rake db:migrate, rake db:seed, etc.
|
* Run bundle install, rake db:migrate, rake db:seed, etc.
|
||||||
|
|
|
@ -1,13 +1,50 @@
|
||||||
class ResourcesController < ApplicationController
|
class ResourcesController < ApplicationController
|
||||||
load_and_authorize_resource
|
load_and_authorize_resource
|
||||||
before_filter :authenticate_user!
|
before_filter :authenticate_user!, :load_users
|
||||||
|
|
||||||
|
def create
|
||||||
|
authorize! :create, @resource
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
if @resource.save
|
||||||
|
format.html { redirect_to resource_path(@resource), :notice => "Resource was successfully created." }
|
||||||
|
format.json { head :no_content }
|
||||||
|
else
|
||||||
|
format.html { render :action => "new" }
|
||||||
|
format.json { render :json => @resource.errors, :status => :unprocessable_entity }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
@resource.assign_attributes(params[:resource])
|
||||||
|
authorize! :update, @resource
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
if @resource.update_attributes(params[:resource])
|
||||||
|
format.html { redirect_to resource_path(@resource), :notice => "Resource was successfully updated." }
|
||||||
|
format.json { head :no_content }
|
||||||
|
else
|
||||||
|
format.html { render :action => "edit" }
|
||||||
|
format.json { render :json => @resource.errors, :status => :unprocessable_entity }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@resource.destroy
|
@resource.destroy
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { redirect_to(request.env["HTTP_REFERER"]) }
|
format.html { redirect_to resources_path, :notice => "Resource was deleted." }
|
||||||
format.json { head :ok }
|
format.json { head :ok }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def load_users
|
||||||
|
if can? :manage, Resource then
|
||||||
|
@users = User.accessible_by(current_ability).sort_by(&:name)
|
||||||
|
else
|
||||||
|
@users = [current_user]
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
class Resource < ActiveRecord::Base
|
class Resource < ActiveRecord::Base
|
||||||
|
attr_accessible :supercategory, :user_id, :category_id, :name, :serial, :specs, :status, :donatable, :picture, :picture_file_name, :picture_content_type, :picture_file_size, :picture_updated_at, :notes, :estimated_value
|
||||||
|
|
||||||
belongs_to :owner, :class_name => "ToolshareUser" #TODO: remove owner
|
belongs_to :owner, :class_name => "ToolshareUser" #TODO: remove owner
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
belongs_to :category, :class_name => "ResourceCategory"
|
belongs_to :category, :class_name => "ResourceCategory"
|
||||||
|
|
|
@ -2,7 +2,13 @@
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>hsl_members(<%= controller.controller_name %>.<%= controller.action_name %><%= "["+params[:id]+"]" unless params[:id].blank? %>)</title>
|
<title>hsl_members(<%= controller.controller_name %>.<%= controller.action_name %><%= "["+params[:id]+"]" unless params[:id].blank? %>)</title>
|
||||||
<%= stylesheet_link_tag "application", :media => "all" %>
|
<% if params[:controller] == "resources" %>
|
||||||
|
<link href="/bootstrap/css/bootstrap.min.css" type="text/css" rel="stylesheet" />
|
||||||
|
<link href="/bootstrap/css/bootstrap-theme.min.css" type="text/css" rel="stylesheet" />
|
||||||
|
<script src="/bootstrap/js/bootstrap.min.js" type="text/javascript" ></script>
|
||||||
|
<% else %>
|
||||||
|
<%= stylesheet_link_tag "application", :media => "all" %>
|
||||||
|
<% end %>
|
||||||
<%= javascript_include_tag "application" %>
|
<%= javascript_include_tag "application" %>
|
||||||
<%= csrf_meta_tags %>
|
<%= csrf_meta_tags %>
|
||||||
</head>
|
</head>
|
||||||
|
|
91
app/views/layouts/resources.html.erb
Executable file
91
app/views/layouts/resources.html.erb
Executable file
|
@ -0,0 +1,91 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>hsl_members(<%= controller.controller_name %>.<%= controller.action_name %><%= "["+params[:id]+"]" unless params[:id].blank? %>)</title>
|
||||||
|
|
||||||
|
<%= javascript_include_tag "application" %>
|
||||||
|
<%= csrf_meta_tags %>
|
||||||
|
|
||||||
|
<link href="/bootstrap/css/bootstrap.min.css" type="text/css" rel="stylesheet" />
|
||||||
|
<link href="/bootstrap/css/bootstrap-theme.min.css" type="text/css" rel="stylesheet" />
|
||||||
|
<script src="/bootstrap/js/bootstrap.min.js" type="text/javascript" ></script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
#logo {
|
||||||
|
height: 40px;
|
||||||
|
width: 40px;
|
||||||
|
float: left;
|
||||||
|
margin-top: 5px;
|
||||||
|
}
|
||||||
|
#content {
|
||||||
|
margin: 1em;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<nav class="navbar navbar-default" role="navigation">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<ul class="nav navbar-nav">
|
||||||
|
<a id="home_nav_link" href="/" title="Home"><img src="/assets/logo.png" id="logo" /></a>
|
||||||
|
<li>
|
||||||
|
<%= link_to 'People', users_path if can? :read, User %>
|
||||||
|
</li>
|
||||||
|
<li class="active">
|
||||||
|
<%= link_to 'Tools', resources_path if can? :read, Resource %>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<%= link_to 'Access Cards', cards_path if can? :manage, Card %>
|
||||||
|
</li>
|
||||||
|
<li class="dropdown">
|
||||||
|
<% if can? :create, UserCertification %>
|
||||||
|
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Certifications <b class="caret"></b></a>
|
||||||
|
<ul class="dropdown-menu">
|
||||||
|
<li>
|
||||||
|
<%= link_to 'Classes', certifications_path if can? :read, Certification %>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<%= link_to 'User Certs', user_certifications_path if can? :create, UserCertification %>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
<% else %>
|
||||||
|
<%= link_to 'Certifications', certifications_path if can? :read, Certification %>
|
||||||
|
<% end %>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<%= link_to 'Payments', payments_path if can? :create, Payment %>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<%= link_to 'Computers', macs_path if user_signed_in? || (can? :read, Mac) %>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<%= link_to 'Settings', settings_path if can? :read, Setting %>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<% if user_signed_in? then %><%= link_to 'Profile', edit_user_registration_path %><% end %>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<%= link_to 'Logout', destroy_user_session_path, :method => :delete if user_signed_in? %>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<%= link_to 'Login', new_user_session_path unless user_signed_in? %>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<%= link_to 'Membership Application', new_user_registration_path unless user_signed_in? %>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
<div class="container-fluid" id="content">
|
||||||
|
<div class="row">
|
||||||
|
<% if notice %>
|
||||||
|
<p class="alert alert-info"><%= raw(notice) %></p>
|
||||||
|
<% end %>
|
||||||
|
<% if alert %>
|
||||||
|
<p class="alert alert-danger"><%= raw(alert) %></p>
|
||||||
|
<% end %>
|
||||||
|
<%= yield %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<%= raw Setting.analytics_code if Setting.present? %>
|
||||||
|
</body>
|
||||||
|
</html>
|
69
app/views/resources/_form.html.erb
Normal file
69
app/views/resources/_form.html.erb
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
<%= form_for @resource, :html => { :multipart => true } do |f| %>
|
||||||
|
<% if @resource.errors.any? %>
|
||||||
|
<div id="error_explanation">
|
||||||
|
<h2><%= pluralize(@resource.errors.count, "error") %> prohibited this resource from being saved:</h2>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<% @resource.errors.full_messages.each do |msg| %>
|
||||||
|
<li><%= msg %></li>
|
||||||
|
<% end %>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<%= f.label :category_id %><br />
|
||||||
|
<%= select(:resource, :category_id, options_from_collection_for_select(ResourceCategory.all.sort_by(&:name), :id, :name, @resource.category_id ) ) %>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<%= f.label :name %><br />
|
||||||
|
<%= f.text_field :name %>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<%= f.label :serial, "Serial" %>
|
||||||
|
<br />
|
||||||
|
<%= f.text_field :serial %>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<%= f.label :specs, "Specs" %>
|
||||||
|
<br/>
|
||||||
|
<%= f.text_field :specs %>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<%= f.label :status, "Status/Location" %>
|
||||||
|
<br/>
|
||||||
|
<%= f.text_field :status %>
|
||||||
|
</p>
|
||||||
|
<% if can? :assign_user, @resource %>
|
||||||
|
<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) %>
|
||||||
|
</p>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<%= f.label :donatable %><br />
|
||||||
|
<%= f.check_box :donatable %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<%= f.label :estimated_value, "Estimated Value" %><br />
|
||||||
|
<%= f.text_field :estimated_value %>
|
||||||
|
</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>
|
||||||
|
<p>
|
||||||
|
<%= f.label :notes %><br />
|
||||||
|
<%= f.text_area :notes %>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<%= f.submit %>
|
||||||
|
</p>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<%= link_to 'Back', resources_path %>
|
|
@ -1,9 +1,11 @@
|
||||||
<div class="col-sm-2">
|
<div class="col-sm-2">
|
||||||
<div class="thumbnail">
|
<div class="thumbnail">
|
||||||
|
<% if resource.user %>
|
||||||
|
<span class="ownership">Owned by:<br/><%= resource.user.name %></span>
|
||||||
|
<% end %>
|
||||||
<%= link_to(resource) do %>
|
<%= link_to(resource) do %>
|
||||||
<%= image_tag(resource.picture.url(:thumb)) if resource.picture? %>
|
<%= image_tag(resource.picture.url(:thumb)) if resource.picture? %>
|
||||||
<strong><%=h resource.name %></strong>
|
<h4><%=h resource.name %></h4>
|
||||||
<% end %>
|
<% end %>
|
||||||
<%= "Owned by "+resource.user.name if resource.user %>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
2
app/views/resources/edit.html.erb
Normal file
2
app/views/resources/edit.html.erb
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
<h1>Edit Resource</h1>
|
||||||
|
<%= render 'form' %>
|
|
@ -1,23 +1,28 @@
|
||||||
<h1>Resources</h1>
|
<h1>Lab Resources
|
||||||
|
<%= link_to 'Add Resource', new_resource_path, :class => "btn btn-success" if can? :create, Resource %>
|
||||||
|
</h1>
|
||||||
|
|
||||||
<%= link_to 'Add Equipment', new_resource_path, :class => "btn" if can? :create, Resource %>
|
|
||||||
|
<link href="/bootstrap/css/bootstrap-theme.min.css" type="text/css" />
|
||||||
|
<link href="/bootstrap/css/bootstrap.min.css" type="text/css" />
|
||||||
|
<script src="/bootstrap/js/bootstrap.min.js" type="text/javascript" ></script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.collapsible .thumbnail { height: 150px; }
|
#accordion .thumbnail { height: 150px; position: relative; }
|
||||||
|
#accordion .thumbnail .ownership { position: absolute; top: 1px; text-shadow: 0.1em 0.1em 0.2em white; font-weight: bold; left: 10px; }
|
||||||
|
#accordion .thumbnail h4 { position: absolute; bottom: 1px; margin-bottom: 1px; }
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<% unless @resources.blank? %>
|
<% unless @resources.blank? %>
|
||||||
<div class="panel-group" id="accordion">
|
<div class="panel-group col-sm-8" id="accordion">
|
||||||
<% @resources.sort_by{|r| [r.category_name,r.name] }.group_by(&:category).each do |category,resources| %>
|
<% @resources.sort_by{|r| [r.category_name,r.name] }.group_by(&:category).each do |category,resources| %>
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
<div class="panel-heading">
|
<div class="panel-heading" data-toggle="collapse" data-parent="#accordion" href="#collapse_cat_<%= category.id %>">
|
||||||
<h4 class="panel-title">
|
<h4 class="panel-title">
|
||||||
<a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">
|
|
||||||
<%= category.name %>
|
<%= category.name %>
|
||||||
</a>
|
|
||||||
</h4>
|
</h4>
|
||||||
</div>
|
</div>
|
||||||
<div id="collapseOne" class="panel-collapse collapse in">
|
<div id="collapse_cat_<%= category.id %>" class="panel-collapse collapse">
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<%= render resources %>
|
<%= render resources %>
|
||||||
</div>
|
</div>
|
||||||
|
|
2
app/views/resources/new.html.erb
Normal file
2
app/views/resources/new.html.erb
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
<h1>New Resource</h1>
|
||||||
|
<%= render 'form' %>
|
45
app/views/resources/show.html.erb
Normal file
45
app/views/resources/show.html.erb
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
<%= link_to image_tag(@resource.picture.url(:medium)), @resource.picture.url, :popup => ['show_image_preview', 'height=300,width=400'] if @resource.picture? %>
|
||||||
|
|
||||||
|
<h2><%=h @resource.name %>
|
||||||
|
<%= link_to 'Back', resources_path, class: "btn btn-default" %>
|
||||||
|
<%= link_to 'Edit', edit_resource_path(@resource), class: "btn btn-primary" %>
|
||||||
|
<%= 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 %>
|
||||||
|
</h2>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<b>Category:</b>
|
||||||
|
<%=h @resource.category.name if !@resource.category.blank? %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<b>Serial:</b>
|
||||||
|
<%=h @resource.serial %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<b>Specs:</b>
|
||||||
|
<%=h @resource.specs %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<b>Status/Location:</b>
|
||||||
|
<%=h @resource.status %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<b>Donatable:</b>
|
||||||
|
<%=h @resource.donatable %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<b>Estimated Value:</b>
|
||||||
|
<%=h @resource.estimated_value %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<b>Notes:</b>
|
||||||
|
<%=h @resource.notes %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user