More resource tweaks

This commit is contained in:
Will Bradley 2014-02-09 04:32:45 -07:00
parent 23dcb0715c
commit a2cbcac798
9 changed files with 119 additions and 57 deletions

View File

@ -2,6 +2,10 @@ class ResourcesController < ApplicationController
load_and_authorize_resource load_and_authorize_resource
before_filter :authenticate_user!, :load_users before_filter :authenticate_user!, :load_users
def index
@featured_resource = @resources.where("picture_file_name IS NOT NULL").sample
end
def create def create
authorize! :create, @resource authorize! :create, @resource

View File

@ -1,5 +1,5 @@
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 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, :disposed_at
belongs_to :owner, :class_name => "ToolshareUser" #TODO: remove owner belongs_to :owner, :class_name => "ToolshareUser" #TODO: remove owner
belongs_to :user belongs_to :user

View File

@ -17,6 +17,11 @@
float: left; float: left;
margin-top: 5px; margin-top: 5px;
} }
@media (max-width: 768px) {
#logo {
margin-left: 15px;
}
}
#content { #content {
margin: 1em; margin: 1em;
} }
@ -25,54 +30,66 @@
<body> <body>
<nav class="navbar navbar-default" role="navigation"> <nav class="navbar navbar-default" role="navigation">
<div class="container-fluid"> <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> <div class="navbar-header">
<li> <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#mainmenu-collapse">
<%= link_to 'People', users_path if can? :read, User %> <span class="sr-only">Toggle navigation</span>
</li> <span class="icon-bar"></span>
<li class="active"> <span class="icon-bar"></span>
<%= link_to 'Tools', resources_path if can? :read, Resource %> <span class="icon-bar"></span>
</li> </button>
<li> <a id="home_nav_link" href="/" title="Home"><img src="/assets/logo.png" id="logo" /></a>
<%= link_to 'Access Cards', cards_path if can? :manage, Card %> </div>
</li>
<li class="dropdown"> <div class="collapse navbar-collapse" id="mainmenu-collapse">
<% if can? :create, UserCertification %> <ul class="nav navbar-nav">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Certifications <b class="caret"></b></a> <li>
<ul class="dropdown-menu"> <%= link_to 'People', users_path if can? :read, User %>
<li> </li>
<%= link_to 'Classes', certifications_path if can? :read, Certification %> <li class="active">
</li> <%= link_to 'Tools', resources_path if can? :read, Resource %>
<li> </li>
<%= link_to 'User Certs', user_certifications_path if can? :create, UserCertification %> <li>
</li> <%= link_to 'Access Cards', cards_path if can? :manage, Card %>
</ul> </li>
<% else %> <li class="dropdown">
<%= link_to 'Certifications', certifications_path if can? :read, Certification %> <% if can? :create, UserCertification %>
<% end %> <a href="#" class="dropdown-toggle" data-toggle="dropdown">Certifications <b class="caret"></b></a>
</li> <ul class="dropdown-menu">
<li> <li>
<%= link_to 'Payments', payments_path if can? :create, Payment %> <%= link_to 'Classes', certifications_path if can? :read, Certification %>
</li> </li>
<li> <li>
<%= link_to 'Computers', macs_path if user_signed_in? || (can? :read, Mac) %> <%= link_to 'User Certs', user_certifications_path if can? :create, UserCertification %>
</li> </li>
<li> </ul>
<%= link_to 'Settings', settings_path if can? :read, Setting %> <% else %>
</li> <%= link_to 'Certifications', certifications_path if can? :read, Certification %>
<li> <% end %>
<% if user_signed_in? then %><%= link_to 'Profile', edit_user_registration_path %><% end %> </li>
</li> <li>
<li> <%= link_to 'Payments', payments_path if can? :create, Payment %>
<%= link_to 'Logout', destroy_user_session_path, :method => :delete if user_signed_in? %> </li>
</li> <li>
<li> <%= link_to 'Computers', macs_path if user_signed_in? || (can? :read, Mac) %>
<%= link_to 'Login', new_user_session_path unless user_signed_in? %> </li>
</li> <li>
<li> <%= link_to 'Settings', settings_path if can? :read, Setting %>
<%= link_to 'Membership Application', new_user_registration_path unless user_signed_in? %> </li>
</li> <li>
</ul> <% 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>
</div> </div>
</nav> </nav>
<div class="container-fluid" id="content"> <div class="container-fluid" id="content">

View File

@ -34,7 +34,13 @@
<br/> <br/>
<%= f.text_field :status %> <%= f.text_field :status %>
</p> </p>
<% if can? :assign_user, @resource %>
<p>
<%= f.label :disposed_at, "Disposed?" %><br />
<%= f.date_select :disposed_at, include_blank: true %>
</p>
<% if can? :assign_user, @resource %>
<p> <p>
<%= f.label :user_id, "Owner" %> <%= f.label :user_id, "Owner" %>
<br /> <br />

View File

@ -3,6 +3,9 @@
<% if resource.user %> <% if resource.user %>
<span class="ownership">Owned by:<br/><%= resource.user.name %></span> <span class="ownership">Owned by:<br/><%= resource.user.name %></span>
<% end %> <% end %>
<% if resource.disposed_at %>
<span class="disposed">Disposed:<br/><%= resource.disposed_at.to_date %></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? %>
<h4><%=h resource.name %></h4> <h4><%=h resource.name %></h4>

View File

@ -1,6 +1,3 @@
<h1>Lab Resources
<%= link_to 'Add Resource', new_resource_path, :class => "btn btn-success" if can? :create, Resource %>
</h1>
<link href="/bootstrap/css/bootstrap-theme.min.css" type="text/css" /> <link href="/bootstrap/css/bootstrap-theme.min.css" type="text/css" />
@ -9,10 +6,28 @@
<style> <style>
#accordion .thumbnail { height: 150px; position: relative; } #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 .ownership,
#accordion .thumbnail .disposed
{ position: absolute; top: 1px;
text-shadow:
-1px -1px 0 #fff,
1px -1px 0 #fff,
-1px 1px 0 #fff,
1px 1px 0 #fff;
font-weight: bold; left: 10px; }
#accordion .thumbnail .disposed { color: red; }
#accordion .thumbnail h4 { position: absolute; bottom: 1px; margin-bottom: 1px; } #accordion .thumbnail h4 { position: absolute; bottom: 1px; margin-bottom: 1px; }
</style> </style>
<h1 class="col-sm-4">Lab Resources
<%= link_to 'Add Resource', new_resource_path, :class => "btn btn-success" if can? :create, Resource %>
</h1>
<h3 class="col-sm-2">Featured item:</h3>
<%= render @featured_resource %>
<div class="row">
<% unless @resources.blank? %> <% unless @resources.blank? %>
<div class="panel-group col-sm-8" 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| %>
@ -31,6 +46,7 @@
<% end %> <% end %>
</div> </div>
<% end %> <% end %>
</div>
<br /> <br />

View File

@ -3,9 +3,13 @@
<h2><%=h @resource.name %> <h2><%=h @resource.name %>
<%= link_to 'Back', resources_path, class: "btn btn-default" %> <%= link_to 'Back', resources_path, class: "btn btn-default" %>
<%= link_to 'Edit', edit_resource_path(@resource), class: "btn btn-primary" %> <%= 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> </h2>
<% if @resource.user || @resource.owner %>
<p>
<b>Owner:</b>
<%=h (@resource.user || @resource.owner).name %>
</p>
<% end %>
<p> <p>
<b>Category:</b> <b>Category:</b>
<%=h @resource.category.name if !@resource.category.blank? %> <%=h @resource.category.name if !@resource.category.blank? %>
@ -24,6 +28,11 @@
<p> <p>
<b>Status/Location:</b> <b>Status/Location:</b>
<%=h @resource.status %> <%=h @resource.status %>
<% if @resource.disposed_at %>
<b>Disposed:</b>
<%=h @resource.disposed_at.to_date %>
<% end %>
</p> </p>
<p> <p>
@ -43,3 +52,4 @@
<%= 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 %>

View File

@ -0,0 +1,5 @@
class AddDisposedAtToResource < ActiveRecord::Migration
def change
add_column :resources, :disposed_at, :datetime
end
end

View File

@ -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 => 20140209080523) do ActiveRecord::Schema.define(:version => 20140209104356) do
create_table "cards", :force => true do |t| create_table "cards", :force => true do |t|
t.string "card_number" t.string "card_number"
@ -141,6 +141,7 @@ ActiveRecord::Schema.define(:version => 20140209080523) do
t.datetime "updated_at" t.datetime "updated_at"
t.string "estimated_value" t.string "estimated_value"
t.integer "user_id" t.integer "user_id"
t.datetime "disposed_at"
end end
create_table "settings", :force => true do |t| create_table "settings", :force => true do |t|