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

Commit

Permalink
Merge pull request #1545 from YaleSTC/1499_clean_up_1337
Browse files Browse the repository at this point in the history
[1499] Clean up #1337
  • Loading branch information
orenyk committed May 3, 2016
2 parents 7fe77ff + 278cadb commit 9556f2f
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 30 deletions.
8 changes: 8 additions & 0 deletions app/controllers/categories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ def index
end

def show
respond_to do |format|
format.html
format.zip do
models = @category.equipment_models
items = EquipmentItem.where(equipment_model_id: models.all.map(&:id))
download_equipment_data(cats: [@category], models: models, items: items)
end
end
end

def new
Expand Down
6 changes: 6 additions & 0 deletions app/controllers/equipment_items_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# rubocop:disable Metrics/ClassLength
class EquipmentItemsController < ApplicationController
load_and_authorize_resource
decorates_assigned :equipment_item
Expand All @@ -7,6 +8,7 @@ class EquipmentItemsController < ApplicationController
before_action :set_equipment_model_if_possible, only: [:index, :new]

include ActivationHelper
include CsvExport
include Calendarable

# ---------- before filter methods ---------- #
Expand All @@ -29,6 +31,10 @@ def index
else
@equipment_items = EquipmentItem.send(method)
end
respond_to do |format|
format.html
format.zip { download_equipment_data }
end
end

def show
Expand Down
1 change: 1 addition & 0 deletions app/controllers/equipment_models_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class EquipmentModelsController < ApplicationController
before_action :set_category_if_possible, only: [:index, :new]

include ActivationHelper
include CsvExport
include Calendarable

# --------- before filter methods --------- #
Expand Down
12 changes: 6 additions & 6 deletions app/views/categories/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<td><%= intify category.max_checkout_length %></td>
<td><%= category.sort_order %></td>
<% if can? :manage, Category %>
<td><%= link_to "Edit", edit_category_path(category), :class => "btn btn-default" %></td>
<td><%= link_to "Edit", edit_category_path(category), class: "btn btn-default" %></td>
<td><%= category.decorate.make_deactivate_btn %></td>
<% end %>
</tr>
Expand All @@ -32,12 +32,12 @@
<hr />

<% 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 btn-default" %>
<%= link_to "Export Equipment Data", categories_path(format: 'zip'), :class => "btn btn-default" %>
<%= link_to "New Category", new_category_path, class: "btn btn-primary" %>
<%= link_to "Import Categories", equip_import_page_path, class: "btn btn-default" %>
<%= link_to "Export Equipment Data", categories_path(format: 'zip'), class: "btn btn-default" %>
<% end %>
<% if params[:show_deleted] %>
<%= link_to "Hide Old Categories from List", categories_path, :class => "btn btn-default" %>
<%= link_to "Hide Old Categories from List", categories_path, class: "btn btn-default" %>
<% else %>
<%= link_to "Show Old Categories in List", categories_path(:show_deleted => true), :class => "btn btn-default" %>
<%= link_to "Show Old Categories in List", categories_path(:show_deleted => true), class: "btn btn-default" %>
<% end %>
1 change: 1 addition & 0 deletions app/views/categories/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,6 @@
<%= link_to "#{@category.name} Reservations Calendar", calendar_category_path(@category), class: 'btn btn-default' %>
<%= link_to "Edit Category", edit_category_path(@category), class: 'btn btn-default' %>
<%= category.make_deactivate_btn %>
<%= link_to "Export Category Data", category_path(@category, format: 'zip'), class: 'btn btn-default' %>
<%= link_to "View All Categories", categories_path, class: 'btn btn-default' %>
<% end %>
4 changes: 2 additions & 2 deletions app/views/equipment_items/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</td>

<% if can? :manage, EquipmentItem %>
<td><%= link_to "Edit", edit_equipment_item_path(equipment_item), :class => "btn btn-default" %></td>
<td><%= link_to "Edit", edit_equipment_item_path(equipment_item), class: "btn btn-default" %></td>
<td><%= equipment_item.decorate.make_deactivate_btn %></td>
<% end %>
</tr>
Expand All @@ -48,7 +48,7 @@
<% else %>
<%= link_to "New Equipment Item", new_equipment_item_path, class: 'btn btn-primary' %>
<%= link_to "Import Equipment Item", equip_import_page_path, class: 'btn btn-default' %>
<%= link_to "Export Equipment Data", categories_path(format: 'zip'), :class => "btn btn-default" %>
<%= link_to "Export Equipment Data", equipment_items_path(format: 'zip'), class: "btn btn-default" %>
<% end %>
<% if params[:show_deleted] %>
Expand Down
22 changes: 12 additions & 10 deletions app/views/equipment_models/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,29 @@
<hr>
<% if can? :manage, EquipmentModel %>
<% if @category %>
<%= link_to "New #{@category.name.singularize}", new_category_equipment_model_path(@category), :class => 'btn btn-primary' %>
<%= link_to "New #{@category.name.singularize}", new_category_equipment_model_path(@category), class: 'btn btn-primary' %>
<%= link_to "#{@category.name} Reservations Calendar", calendar_category_path(@category), class: 'btn btn-default' %>
<%= link_to "View All Equipment Models", equipment_models_path, :class => 'btn btn-default' %>
<%= link_to "View All Equipment Models", equipment_models_path, class: 'btn btn-default' %>
<%= link_to "Import Equipment Models", equip_import_page_path, class: "btn btn-default" %>
<%= link_to "Export Equipment Data", category_path(@category, format: 'zip'), class: "btn btn-default" %>
<% 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 btn-default" %>
<%= link_to "Export Equipment Data", categories_path(format: 'zip'), :class => "btn btn-default" %>
<%= link_to "New Equipment Model", new_equipment_model_path, class: "btn btn-primary" %>
<%= link_to "Import Equipment Models", equip_import_page_path, class: "btn btn-default" %>
<%= link_to "Export Equipment Data", equipment_models_path(format: 'zip'), class: "btn btn-default" %>
<% end %>
<% if params[:show_deleted] %>
<% if (@category.nil?) %>
<%= link_to "Hide Deactivated Models", equipment_models_path, :class => "btn btn-default" %>
<%= link_to "Hide Deactivated Models", equipment_models_path, class: "btn btn-default" %>
<% else %>
<%= link_to "Hide Deactivated Models", category_equipment_models_path(@category), :class => "btn btn-default" %>
<%= link_to "Hide Deactivated Models", category_equipment_models_path(@category), class: "btn btn-default" %>
<% end %>
<% else %>
<% if (@category.nil?) %>
<%= link_to "Show Deactivated Models", equipment_models_path(show_deleted: true), :class => "btn btn-default" %>
<%= link_to "Show Deactivated Models", equipment_models_path(show_deleted: true), class: "btn btn-default" %>
<% else %>
<%= link_to "Show Deactivated Models", category_equipment_models_path(@category, show_deleted: true), :class => "btn btn-default" %>
<%= link_to "Show Deactivated Models", category_equipment_models_path(@category, show_deleted: true), class: "btn btn-default" %>
<% end %>
<% end %>
<% else %>
<%= link_to "Return to Catalog", catalog_path, :class => 'btn btn-default' %>
<%= link_to "Return to Catalog", catalog_path, class: 'btn btn-default' %>
<% end %>
3 changes: 1 addition & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
resources :documents,
:requirements

resources :equipment_items, except: [:index],
concerns: [:deactivatable, :calendarable]
resources :equipment_items, concerns: [:deactivatable, :calendarable]

resources :announcements, except: [:show]

Expand Down
18 changes: 8 additions & 10 deletions lib/csv_export.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,13 @@ def download_zip(tables, filename)
end

# NOTE: this method depends on ActionController
def download_equipment_data
categories = [Category.all, %w(name max_per_user max_checkout_length
max_renewal_times max_renewal_length
renewal_days_before_due sort_order)]
models = [EquipmentModel.all, %w(category name description late_fee
replacement_fee max_per_user
max_renewal_length)]
items = [EquipmentItem.all, %w(equipment_model name serial)]
download_zip([categories, models, items],
"EquipmentData_#{Time.zone.now.to_s(:number)}")
def download_equipment_data(cats: Category.all, models: EquipmentModel.all,
items: EquipmentItem.all)
c = [cats, %w(name max_per_user max_checkout_length max_renewal_times
max_renewal_length renewal_days_before_due sort_order)]
m = [models, %w(category name description late_fee replacement_fee
max_per_user max_renewal_length)]
i = [items, %w(equipment_model name serial)]
download_zip([c, m, i], "EquipmentData_#{Time.zone.now.to_s(:number)}")
end
end

0 comments on commit 9556f2f

Please sign in to comment.