Skip to content

Commit

Permalink
Add MVC for enbdowed funds management report and higher rubocop thres…
Browse files Browse the repository at this point in the history
…holds
  • Loading branch information
jgreben committed Sep 16, 2016
1 parent 76e0944 commit 84bbc1a
Show file tree
Hide file tree
Showing 28 changed files with 1,476 additions and 62 deletions.
9 changes: 9 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ Metrics/LineLength:
Metrics/ClassLength:
Max: 120

Metrics/MethodLength:
Max: 15

Metrics/AbcSize:
Max: 22

Style/StringLiterals:
Enabled: true
EnforcedStyle: single_quotes

Style/FrozenStringLiteralComment:
Enabled: false
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ GEM
sshkit (>= 1.6.1, != 1.7.0)
arel (6.0.3)
ast (2.3.0)
autoprefixer-rails (6.4.0.2)
autoprefixer-rails (6.4.0.3)
execjs
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
Expand Down Expand Up @@ -78,7 +78,7 @@ GEM
capistrano-bundler (~> 1.1)
capistrano-releaseboard (0.0.1)
faraday
capybara (2.7.1)
capybara (2.8.0)
addressable
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
Expand Down Expand Up @@ -115,7 +115,7 @@ GEM
jbuilder (2.6.0)
activesupport (>= 3.0.0, < 5.1)
multi_json (~> 1.2)
jquery-rails (4.1.1)
jquery-rails (4.2.1)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/change_current_locations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ def new
@change_current_location = ChangeCurrentLocation.new
end

# rubocop:disable Metrics/MethodLength,Metrics/AbcSize
def create
@change_current_location = ChangeCurrentLocation.new(params[:change_current_location])
if @change_current_location.valid?
Expand All @@ -22,5 +21,4 @@ def create
render action: 'new'
end
end
# rubocop:enable Metrics/MethodLength,Metrics/AbcSize
end
2 changes: 0 additions & 2 deletions app/controllers/change_home_locations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ def new
@change_home_location = ChangeHomeLocation.new
end

# rubocop:disable Metrics/MethodLength,Metrics/AbcSize
def create
@change_home_location = ChangeHomeLocation.new(params[:change_home_location])
if @change_home_location.valid?
Expand All @@ -22,5 +21,4 @@ def create
render action: 'new'
end
end
# rubocop:enable Metrics/MethodLength,Metrics/AbcSize
end
2 changes: 0 additions & 2 deletions app/controllers/change_item_types_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ def new
@change_item_type = ChangeItemType.new
end

# rubocop:disable Metrics/MethodLength,Metrics/AbcSize
def create
@change_item_type = ChangeItemType.new(params[:change_item_type])
if @change_item_type.valid?
Expand All @@ -22,5 +21,4 @@ def create
render action: 'new'
end
end
# rubocop:enable Metrics/MethodLength,Metrics/AbcSize
end
32 changes: 32 additions & 0 deletions app/controllers/endowed_funds_reports_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
###
# Controller to handle the Encumberances Report
###
class EndowedFundsReportsController < ApplicationController
def new
@endowed_funds_report = EndowedFundsReport.new
end

def create
@endowed_funds_report = EndowedFundsReport.new(batch_params)
if @endowed_funds_report.valid?
if @endowed_funds_report.fund
catalog_keys = EndowedFundsReport.ol_cat_key(@endowed_funds_report.fund)
elsif @endowed_funds_report.fund_begin
catalog_keys = EndowedFundsReport.ol_cat_key(@endowed_funds_report.fund_begin)
end
# write keys to file to Symphony mount [/symphony] on libsys-webforms-dev
@endowed_funds_report.write_keys(catalog_keys)
# TODO: kick off perl script to run pl/sql report

flash[:success] = 'Report requested!'
redirect_to root_path
else
flash[:warning] = 'Check that all form fields are entered!'
render action: 'new'
end
end

def batch_params
params.require(:endowed_funds_report).permit!
end
end
7 changes: 0 additions & 7 deletions app/controllers/transfer_items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ def new
@transfer_item = TransferItem.new
end

# rubocop:disable Metrics/MethodLength,Metrics/AbcSize
def create
@transfer_item = TransferItem.new(params[:transfer_item])
if @transfer_item.valid?
Expand All @@ -23,10 +22,4 @@ def create
flash[:error] = 'Check that all fields are entered correctly'
end
end
# rubocop:enable Metrics/MethodLength,Metrics/AbcSize

def redirect_valid
flash[:notice] = 'Batch uploaded!'
redirect_to @uni_updates_batch
end
end
2 changes: 0 additions & 2 deletions app/controllers/withdraw_items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ def new
@withdraw_item = WithdrawItem.new
end

# rubocop:disable Metrics/MethodLength,Metrics/AbcSize
def create
@withdraw_item = WithdrawItem.new(params[:withdraw_item])
if @withdraw_item.valid?
Expand All @@ -22,5 +21,4 @@ def create
render action: 'new'
end
end
# rubocop:enable Metrics/MethodLength,Metrics/AbcSize
end
8 changes: 4 additions & 4 deletions app/models/circulation_statistics_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def lc_call_lo
end
end

# rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
# rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
def lc_call_hi
if call_lo.length == 1
callnum_range = call_lo..'Z'
Expand All @@ -66,7 +66,7 @@ def lc_call_hi
errors.add(:base, 'Hi callnum range must be empty.') unless call_hi.blank?
end
end
# rubocop:enable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
# rubocop:enable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity

def classic_call_lo_and_hi
lo_integer = call_lo.to_i
Expand All @@ -75,7 +75,7 @@ def classic_call_lo_and_hi
errors.add(:base, message) unless call_lo =~ /^[0-9]+$/ && call_hi =~ /^[0-9]+$/ && lo_integer < hi_integer
end

# rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
# rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
def classic_call_alpha
message = 'Alpha callnum range must be empty or one to two letters.'
errors.add(:base, message) unless call_alpha.blank? || call_alpha =~ /^[A-Z]{1,2}$/
Expand All @@ -87,5 +87,5 @@ def classic_call_alpha
errors.add(:base, message) unless call_lo =~ /^[0-9]{1,4}$/ && call_hi =~ /^[0-9]{1,4}$/
end
end
# rubocop:enable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
# rubocop:enable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
end
11 changes: 3 additions & 8 deletions app/models/circulation_statistics_report_log.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
class CirculationStatisticsReportLog < ActiveRecord::Base
self.table_name = 'circ_stats_rpt_log'

# rubocop:disable Metrics/AbcSize
def self.save_stats(circ_stats)
complete_params = other_params(circ_stats).merge process_range_type_params(circ_stats)
complete_params.merge! CirculationStatisticsReportLog.build_output_type(circ_stats)
Expand All @@ -15,9 +14,7 @@ def self.save_stats(circ_stats)
end
CirculationStatisticsReportLog.create(complete_params)
end
# rubocop:enable Metrics/AbcSize

# rubocop:disable Metrics/AbcSize
def self.other_params(circ_stats)
{ email: circ_stats.email, selcall_src: circ_stats.source,
exclude_inactive: circ_stats.exclude_inactive,
Expand All @@ -29,16 +26,14 @@ def self.other_params(circ_stats)
blank_columns: String(circ_stats.blank_col_array).split(',').join(','),
status: 'SAVED' }
end
# rubocop:enable Metrics/AbcSize

# rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
# rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity,Metrics/MethodLength
def self.process_range_type_params(circ_stats)
range_type_params = {}
case circ_stats.range_type
when 'barcodes'
range_type_params['call_range'] = "Any call (Selection is barcode list #{circ_stats.barcodes.original_filename})"
file_name = "#{circ_stats.email.split('@')[0]}_#{circ_stats.barcodes.original_filename}"
range_type_params['input_path'] = "/s/SUL/Dataload/Uploads/CircStats/#{file_name}"
range_type_params['input_path'] = "/symphony/Dataload/Uploads/CircStats/#{circ_stats.barcodes.original_filename}"
range_type_params['libs_locs'] = 'Any lib-loc'
when 'lc'
if circ_stats.call_lo.include?('#')
Expand Down Expand Up @@ -66,7 +61,7 @@ def self.process_range_type_params(circ_stats)
end
range_type_params
end
# rubocop:enable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
# rubocop:enable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity,Metrics/MethodLength

def self.build_output_type(circ_stats)
if circ_stats.range_type == 'barcodes'
Expand Down
37 changes: 37 additions & 0 deletions app/models/endowed_funds_report.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
###
# Class to model EXPENDITURES oracle table
###
class EndowedFundsReport
include ActiveModel::Model
include ActiveModel::Validations

attr_accessor :fund, :fund_begin, :fund_select, :report_format, :date_request,
:date_ran, :date_type, :fy_start, :fy_end, :cal_start, :cal_end,
:pd_start, :pd_end, :email

validates :fund, presence: true, if: 'fund_begin.nil?'
validates :fund_begin, presence: true, if: 'fund.nil?'

# get cat keys
def self.ol_cat_key(fund)
if fund.is_a?(Array)
fund_codes = []
fund.each do |fc|
Expenditures.where('ta_fund_code = ?', fc).pluck(:ol_cat_key).each do |ckey|
fund_codes << ckey
end
end
fund_codes.uniq
elsif fund.is_a?(String)
Expenditures.where('ta_fund_code LIKE ?', "%#{fund}%").pluck(:ol_cat_key)
end
end

def write_keys(catalog_keys)
symphony_file = "endow#{Time.zone.now.strftime('%y%m%d%H%M%S%L%1N')}"
symphony_location = "/symphony/Dataload/EndowRpt/#{symphony_file}"
out_file = File.new(symphony_location, 'w')
out_file.puts(catalog_keys.join("\n"))
out_file.close
end
end
10 changes: 10 additions & 0 deletions app/models/expenditures.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
###
# Class to model EXPENDITURES_FUNDS oracle table
###
class Expenditures < ActiveRecord::Base
self.table_name = 'expenditures'

def self.ta_fund_code
order(ta_fund_code: :asc)
end
end
4 changes: 2 additions & 2 deletions app/models/uni_updates_batch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class UniUpdatesBatch < ActiveRecord::Base
self.primary_key = 'batch_id'
has_many :uni_updates, foreign_key: 'batch_id', class_name: UniUpdates, dependent: :destroy

# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
# rubocop:disable Metrics/AbcSize
def self.create_item_type_batch(params, total_bcs)
create(batch_date: params[:change_item_type][:batch_date],
user_name: params[:change_item_type][:user_name],
Expand Down Expand Up @@ -86,5 +86,5 @@ def self.create_home_location_batch(params, total_bcs)
pending: 'Y',
total_bcs: total_bcs)
end
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
# rubocop:enable Metrics/AbcSize
end
52 changes: 52 additions & 0 deletions app/views/endowed_funds_reports/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<h2>Endowed Funds Report Request</h2>
<%= form_for @endowed_funds_report, multipart: true, class: 'form-group' do |f| %>
<% if @endowed_funds_report.errors.any? %>
<div id='error_explanation'>
<ul>
<% @endowed_funds_report.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div>
<%= render 'shared/enter_email', f: f %>
<%= render 'shared/funds_selection', f: f %>
<%= render 'shared/date_range_selection', f: f %>

<div class='form-group row pad'>
<%= f.label :report_format, class: 'col-sm-10 form-control-label' %>
<div class='col-sm-10'>
<p>
<%= f.radio_button :report_format, 'n', checked: true %>
Text with no bibliographic field labels
</p>
<p>
<%= f.radio_button :report_format, 'i' %>
Text with MARC numeric tags
</p>
<p>
<%= f.radio_button :report_format, 'd' %>
Text with descriptive field labels
</p>
<p>
<%= f.radio_button :report_format, 'r' %>
RefWorks citations
</p>
<p>
<%= f.radio_button :report_format, 'm' %>
MARC (Can be imported to Zotero citations)
</p>
</div>
</div>

<%= f.hidden_field :date_request, value: Time.now %>
<%= f.hidden_field :date_ran, value: Time.now %>

<div class='pad'><%= f.submit 'Submit request', class: 'btn' %></div><br/>

<% end %>
<div class='btn-group'>
<%= main_menu_button %>
</div>
</div>
4 changes: 2 additions & 2 deletions app/views/management_reports/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
<li><%= link_to "Shelf Selection Report", new_shelf_selection_report_path %></li>
<li><%= link_to "Expenditures with Circ Stats Report", new_expenditures_with_circ_stats_report_path %></li>
<li><%= link_to "Encumbrances Report", new_encumbrance_report_path %></li>
<li><%= link_to "Endowed Funds Report", 'endowed_funds_report' %></li>
<li><%= link_to "Google Selection Report", 'google_selection_report' %> (coming soon)</li>
<li><%= link_to "Endowed Funds Report", new_endowed_funds_report_path %></li>
<!--<li><%= link_to "Google Selection Report", 'google_selection_report' %> (coming soon)</li>-->
</ul>

0 comments on commit 84bbc1a

Please sign in to comment.