Skip to content
This repository has been archived by the owner on Jul 24, 2020. It is now read-only.

[v3.4] 494 import equipment #897

Merged
merged 34 commits into from
Aug 4, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
a5feecc
created import_equipment_models controller and started putting it tog…
orenyk Mar 25, 2014
437f43d
Revert "created import_equipment_models controller and started puttin…
orenyk Mar 27, 2014
d50375e
Created import_equipment_controller, set up routes, minor tweaks
orenyk Mar 27, 2014
14acc3c
started filling in controller, put together import view
orenyk Mar 27, 2014
ac03cf7
added strategy comments to controller
orenyk Mar 27, 2014
cb15839
fleshed out import structure, on to actual code :-)
orenyk Apr 3, 2014
1f3c69a
fixed confusion about csv_import and filepath
orenyk Apr 3, 2014
1ea47b9
fixed example data and import page (downcase and underscore)
orenyk Apr 3, 2014
0c34c8f
added general and specific validation methods
orenyk Apr 3, 2014
eb153cf
added csv_import field to tables in database
orenyk Apr 3, 2014
e7ac28d
started working on import code, comments for next time
orenyk Apr 3, 2014
48399d8
moved equipment import validators to lib file
orenyk Apr 7, 2014
dadb602
started category import function
orenyk Apr 7, 2014
321b10d
added include call to lib file in controller
orenyk Apr 7, 2014
478c9eb
category import working, not sure about validators
orenyk Apr 8, 2014
00ffa97
fixed validators
orenyk Apr 8, 2014
69d9072
created model and object import methods, everything seems to work
orenyk Apr 8, 2014
6487896
added rake task to undo example import
orenyk Apr 10, 2014
6283012
updated test data
orenyk Apr 10, 2014
dc44653
fixed space issue in import view
orenyk Apr 10, 2014
ddb50a7
added import status view and associated partials
orenyk Apr 10, 2014
143f6f8
added link to import page on equipment index views
orenyk Apr 10, 2014
e3e5b8f
added 'sort_order' as parameter for categories
orenyk Apr 14, 2014
15be8dc
created framework for library testing (I think)
orenyk Apr 14, 2014
c84e76d
getting tests to work
orenyk Apr 18, 2014
e4deaa3
finally got working tests for methods, added file for CsvImport
orenyk Apr 20, 2014
0dacf68
started category testing code... having issues
orenyk Apr 24, 2014
4ec20f8
Merge branch 'release-v3.4' into 494_import_equipment
orenyk Aug 4, 2014
22ccd37
update controller to use CanCan
orenyk Aug 4, 2014
1feac10
more CanCan modifications
orenyk Aug 4, 2014
89a308f
more CanCan fixes in the view tables
orenyk Aug 4, 2014
25f7d94
add link back to import page
orenyk Aug 4, 2014
d9e8058
omg more CanCan fixes
orenyk Aug 4, 2014
3138f9f
remove dev and spec files, clean up comments
orenyk Aug 4, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions app/controllers/import_equipment_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
class ImportEquipmentController < ApplicationController
include CsvImport
include EquipmentImport

authorize_resource :class => false

# modeled after the ImportUsersController
def import
# initialize, we take up to three CSV files, now we have to check each
cat_file = params[:cat_upload]
model_file = params[:model_upload]
object_file = params[:object_upload]

# if the user uploaded a category CSV file
if cat_file
# store the overwrite parameter and filepath
cat_overwrite = params[:cat_overwrite]
cat_filepath = cat_file.tempfile.path

# process the category CSV file
processed_cats = csv_import(cat_filepath)

# validate processed categories
if valid_cat_import?(processed_cats, cat_file)
# create categories
@cat_statuses = import_cats(processed_cats, cat_overwrite)
else
redirect_to :back and return
end
end

# next, import the EquipmentModels
if model_file
# store the overwrite parameter and filepath
model_overwrite = params[:model_overwrite]
model_filepath = model_file.tempfile.path

# process the equipment model CSV file
processed_models = csv_import(model_filepath)

# validate the processed equipment models
if valid_model_import?(processed_models, model_file)
# create EquipmentModels
@model_statuses = import_models(processed_models, model_overwrite)
else
redirect_to :back and return
end
end

# finally, import EquipmentObjects
if object_file
# no overwrite paramter since there is no index for EquipmentObjects
# store the filepath
object_filepath = object_file.tempfile.path
processed_objects = csv_import(object_filepath)

if valid_object_import?(processed_objects, object_file)
@object_statuses = import_objects(processed_objects)
else
redirect_to :back and return
end
end

# render the import status page
render 'imported'
end

def import_page
render 'import'
end

end
34 changes: 34 additions & 0 deletions app/views/categories/_table.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<table id="table_categories" class="datatable-wide table table-striped table-bordered">
<thead>
<tr>
<th>Name</th>
<th>Max Per User</th>
<th>Max Checkout Length (days)</th>
<th>Sort Order</th>
<% if can? :manage, Category %>
<th class="no_sort"> </th>
<th class="no_sort"> </th>
<% end %>
</tr>
</thead>
<tbody>
<% for category in categories %>
<tr>
<td><%= link_to category.name, category %></td>
<td><%= category.maximum_per_user %></td>
<td><%= category.maximum_checkout_length %></td>
<td><%= category.sort_order %></td>
<% if can? :manage, Category %>
<td><%= link_to "Edit", edit_category_path(category), :class => "btn" %></td>
<td>
<% if category.deleted_at %>
<%= make_activate_btn(:categories,category) %>
<% else %>
<%= make_deactivate_btn(:categories,category) %>
<% end %>
</td>
<% end %>
</tr>
<% end %>
</tbody>
</table>
1 change: 1 addition & 0 deletions app/views/categories/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<div class="form-actions">
<% if can? :manage, Category %>
<%= link_to "New Category", new_category_path, :class => "btn btn-primary" %>
<%= link_to "Import Categories", equip_import_page_path, :class => "btn" %>
<% end %>
<% if params[:show_deleted] %>
<%= link_to "Hide Old Categories from List", categories_path, :class => "btn" %>
Expand Down
31 changes: 31 additions & 0 deletions app/views/equipment_models/_table.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<table id="table_equipment_models" class="datatable-wide table table-striped table-bordered">
<thead>
<tr>
<th>Name</th>
<%= "<th>Type</th>".html_safe unless @category %>
<%# these blank TH's necessary for the sort function %>
<% if can? :manage, EquipmentModel %>
<th class="no_sort"> </th>
<th class="no_sort"> </th>
<% end %>
</tr>
</thead>
<tbody>
<% for equipment_model in equipment_models %>
<tr>
<td><%= link_to equipment_model.name, equipment_model %></td>
<%= ("<td>" + (link_to equipment_model.category.name.singularize, equipment_model.category) + "</td>").html_safe unless @category %>
<% if can? :manage, EquipmentModel %>
<td><%= link_to "Edit", edit_equipment_model_path(equipment_model), :class => "btn" %></td>
<td>
<% if equipment_model.deleted_at %>
<%= make_activate_btn(:equipment_models,equipment_model) %>
<% else %>
<%= make_deactivate_btn(:equipment_models,equipment_model) %>
<% end %>
</td>
<% end %>
</tr>
<% end %>
</tbody>
</table>
1 change: 1 addition & 0 deletions app/views/equipment_models/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<%= link_to "View All Equipment Models", equipment_models_path, :class => 'btn' %>
<% else %>
<%= link_to "New Equipment Model", new_equipment_model_path, :class => "btn btn-primary" %>
<%= link_to "Import Equipment Models", equip_import_page_path, :class => "btn" %>
<% end %>
<% if params[:show_deleted] %>
<% if (@category.nil?) %>
Expand Down
42 changes: 42 additions & 0 deletions app/views/equipment_objects/_table.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<table id="table_equipment_objects" class="datatable-wide table table-striped table-bordered">
<thead>
<tr>
<th>Equipment Model</th>
<th>Item Name</th>
<th>Serial (optional)</th>
<th>Status</th>
<%# these blank TH's necessary for the sort function %>
<% if can? :manage, EquipmentObject %>
<th class="no_sort"> </th>
<th class="no_sort"> </th>
<% end %>
</tr>
</thead>
<tbody>
<% for equipment_object in equipment_objects %>
<tr>
<td><%= link_to equipment_object.equipment_model.name, equipment_object.equipment_model %></td>
<% if can? :manage, EquipmentObject %>
<td><%= link_to equipment_object.name, equipment_object %></td>
<% else %>
<td> <%=equipment_object.name%> </td>
<% end %>
<td><%= equipment_object.serial %></td>

<% current_res = equipment_object.current_reservation %>
<td><%= link_to_if current_res, equipment_object.status, current_res %></td>

<% if can? :manage, EquipmentObject %>
<td><%= link_to "Edit", edit_equipment_object_path(equipment_object), :class => "btn" %></td>
<td>
<% if equipment_object.deleted_at %>
<%= make_activate_btn(:equipment_objects,equipment_object) %>
<% else %>
<%= make_deactivate_btn(:equipment_objects,equipment_object) %>
<% end %>
</td>
<% end %>
</tr>
<% end %>
</tbody>
</table>
1 change: 1 addition & 0 deletions app/views/equipment_objects/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<%= link_to "View All Equipment Items", equipment_objects_path %>
<% else %>
<%= link_to "New Equipment Item", new_equipment_object_path, :class => "btn btn-primary" %>
<%= link_to "Import Equipment Item", equip_import_page_path, :class => "btn" %>
<% end %>

<% if params[:show_deleted] %>
Expand Down
22 changes: 22 additions & 0 deletions app/views/import_equipment/_import_cat_table.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<thead>
<tr>
<th>Name</th>
<th>Max Per User</th>
<th>Max Checkout Length</th>
<th>Sort Order</th>
<th>Reason</th>
</tr>
</thead>
<tbody>
<% cats.each do |cat_data| %>
<% cat = cat_data.first %>
<% message = cat_data.last %>
<tr>
<td><%= cat[:name] %></td>
<td><%= cat[:max_per_user] %></td>
<td><%= cat[:max_checkout_length] %></td>
<td><%= cat[:sort_order] %></td>
<td><%= message %></td>
</tr>
<% end %>
</tbody>
28 changes: 28 additions & 0 deletions app/views/import_equipment/_import_model_table.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<thead>
<tr>
<th>Category</th>
<th>Name</th>
<th>Description</th>
<th>Late Fee</th>
<th>Replacement Fee</th>
<th>Max/User</th>
<th>Renewal Length</th>
<th>Reason</th>
</tr>
</thead>
<tbody>
<% models.each do |model_data| %>
<% model = model_data.first %>
<% message = model_data.last %>
<tr>
<td><%= Category.find(model[:category]).name if model[:category] and Category.find(model[:category]) %></td>
<td><%= model[:name] %></td>
<td><%= model[:description] %></td>
<td><%= model[:late_fee] %></td>
<td><%= model[:replacement_fee] %></td>
<td><%= model[:max_per_user] %></td>
<td><%= model[:max_renewal_length] %></td>
<td><%= message %></td>
</tr>
<% end %>
</tbody>
20 changes: 20 additions & 0 deletions app/views/import_equipment/_import_object_table.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<thead>
<tr>
<th>object</th>
<th>Name</th>
<th>Serial #</th>
<th>Reason</th>
</tr>
</thead>
<tbody>
<% objects.each do |object_data| %>
<% object = object_data.first %>
<% message = object_data.last %>
<tr>
<td><%= EquipmentModel.find(object[:equipment_model]).name if object[:equipment_model] and EquipmentModel.find(object[:equipment_model]) %></td>
<td><%= object[:name] %></td>
<td><%= object[:serial] %></td>
<td><%= message %></td>
</tr>
<% end %>
</tbody>
60 changes: 60 additions & 0 deletions app/views/import_equipment/import.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<% title "Import Equipment" %>

<h2>CSV Import Format</h2>
<p>This form will allow you to import Equipment Categories, Equipment Models, and/or Equipment Items. You can upload a CSV file for any or all of them and they will be processed in the appropriate order. Each import type requires a different CSV format, illustrated below.</p>
<h3>Columns (must be in the first row of the CSV file)</h3>
<h5>Categories (Name is mandatory)</h5>
<%= markdown("
name, max_per_user, max_checkout_length, max_renewal_times, max_renewal_length, renewal_days_before_due, sort_order") %>
<h5>Equipment Models (Category, Name, Description, Late Fee, and Replacement Fee are mandatory)</h5>
<%= markdown("
category, name, description, late_fee, replacement_fee, max_per_user, max_renewal_length") %>
<h5>Equipment Items (Equipment Model and Name are mandatory)</h5>
<%= markdown("
equipment_model, name, serial") %>
<h3>Examples</h3>
<h5>Categories</h5>
<%= markdown("
name,max_per_user,max_checkout_length,max_renewal_times,max_renewal_length,renewal_days_before_due,sort_order
DSLRs,1,14,1,7,3,47
Tripods,,7,2,7,,
Power Cables,,,,,,99") %>
<h5>Equipment Models (ensure that the description contains no commas!)</h5>
<%= markdown("
category,name,description,late_fee,replacement_fee,max_per_user,max_renewal_length
DSLRs,Nikon D70,Nikon D70 body,25,500,1,7
Tripods,Amazon Basics 60-inch,Amazon Basics 60-inch tripod,10,25,,
Power Cables,Three-Pronged Extension Cord,Three-pronged extension cord,0,10,,") %>
<h5>Equipment Items (you can duplicate item names)</h5>
<%= markdown("
equipment_model,name,serial
Nikon D70,Nikon D70,253X52
Nikon D70,Nikon D70,243G53
Amazon Basics 60-inch,Amazon Basics 60-inch,") %>

<hr />

<%= form_tag equip_imported_path, :multipart => true do %>

<p>
<label>CSV file with Categories to import:</label>
<%= file_field_tag 'cat_upload' %>
</p>
<p>
<label>Update existing Categories' information?</label>
<%= check_box_tag 'cat_overwrite' %>
</p>
<p>
<label>CSV file with Equipment Models to import:</label>
<%= file_field_tag 'model_upload' %>
</p>
<p>
<label>Update existing Equipment Models' information?</label>
<%= check_box_tag 'model_overwrite' %>
</p>
<p>
<label>CSV file with Equipment Items to import:</label>
<%= file_field_tag 'object_upload' %>
</p>
<%= submit_tag 'Import Equipment!', :class => 'btn' %>
<% end %>
Loading