Skip to content

Commit

Permalink
Merge ffc5946 into 995d89e
Browse files Browse the repository at this point in the history
  • Loading branch information
jgreben committed Mar 4, 2020
2 parents 995d89e + ffc5946 commit f872a3e
Show file tree
Hide file tree
Showing 11 changed files with 230 additions and 107 deletions.
2 changes: 1 addition & 1 deletion app/assets/javascripts/circulation_statistics_reports.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ $(document).ready(function(){
$('#' + value + 'select').append(html);
}
})
$('#' + value).show();
})
$('#' + selected_libs).show();
})
$('.btn').click(function(){
var col1 = $('#circulation_statistics_report_col_header1').val();
Expand Down
23 changes: 10 additions & 13 deletions app/models/circulation_statistics_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,31 @@ class CirculationStatisticsReport
attr_accessor :email, :lib_array, :source, :range_type, :call_lo, :call_hi,
:call_alpha, :barcodes, :format_array, :exclude_inactive, :min_yr,
:max_yr, :exclude_bad_yr, :include_inhouse, :no_qtrly, :ckey_url,
:tag_field, :tag_field2, :tags_url, :link_type, :col_header1,
:col_header2, :col_header3, :col_header4, :col_header5,
:blank_col_array, :lib_loc_array, :user_id
:tag_field, :tag_field2, :tag_field3, :tag_field4, :tags_url,
:link_type, :col_header1, :col_header2, :col_header3, :col_header4,
:col_header5, :blank_col_array, :lib_loc_array, :user_id

validates :email, :lib_array, presence: true
validates :barcodes, presence: true, if: :barcode_range_type?
validates :lib_array, length: { minimum: 2, message: "can't be empty" }, if: :not_barcode_range_type?
validates :min_yr, length: { is: 4 }, numericality: { only_integer: true }, allow_blank: true
validates :max_yr, length: { is: 4 }, numericality: { only_integer: true }, allow_blank: true
validates :tag_field, length: { is: 3 }, numericality: { only_integer: true },
exclusion: { in: %w[008] }, allow_blank: true
validates :tag_field2, length: { is: 3 }, numericality: { only_integer: true },
exclusion: { in: %w[008] }, allow_blank: true
validates :tag_field, :tag_field2, :tag_field3, :tag_field4, length: { is: 3 }, numericality: { only_integer: true },
exclusion: { in: %w[008] }, allow_blank: true
validate :lc_call_lo, if: :lc_range_type?
validate :lc_call_hi, if: :lc_range_type?
validate :classic_call_lo_and_hi, if: :classic_range_type?
validate :classic_call_alpha, if: :classic_range_type?
validates :email, format: { with: Rails.configuration.email_pattern }, allow_blank: true

before_validation :upcase_call_alpha
before_validation :upcase_call_numbers

private

def upcase_call_alpha
call_alpha&.upcase!
end

def upcase_call_lo
def upcase_call_numbers
call_lo&.upcase!
call_hi&.upcase!
call_alpha&.upcase!
end

def barcode_range_type?
Expand Down
178 changes: 103 additions & 75 deletions app/views/circulation_statistics_reports/new.html.erb

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions app/views/encumbrance_reports/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
<%= render 'shared/funds_selection', f: f %>

<div class='form-group row'>
<%= f.label :funding_paid, 'Show funds with payments:', class: 'col-sm-3 form-control-label' %>
<%= f.label :funding_paid, 'Show funds with payments:', class: 'col-sm-2 form-control-label' %>
<div class='col-sm-10'>
<%= f.radio_button :funding_paid, 'All records', checked: true %> All records<br />
<%= f.radio_button :funding_paid, '$0 paid' %> $0 paid<br />
<%= f.radio_button :funding_paid, 'More than $0 paid' %> More than $0 paid<br />
</div>
</div>
<div class='form-group row'>
<%= f.label :fundcyc_cycle, 'Fiscal Cycle:', class: 'col-sm-3 form-control-label' %>
<%= f.label :fundcyc_cycle, 'Fiscal Cycle:', class: 'col-sm-2 form-control-label' %>
<div class='col-sm-10'>
<%= f.select :fundcyc_cycle, options_for_select(fiscal_years.map{ |b| [ b ] }), {}, {class: 'form-control'} %>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class='form-group row'>
<%= f.label :format_array, 'Select the formats to include:', class: 'col-sm-10 form-control-label' %>
<div class='col-sm-10'>
<%= f.select :format_array, CirculationStatisticsReportFormat.formats, { selected: 'All Formats' }, { multiple: true, class: 'form-control' } %>
<%= f.label :format_array, 'Select the formats to include:', class: 'col-sm-4 form-control-label' %>
<div class='col-sm-8'>
<%= f.select :format_array, CirculationStatisticsReportFormat.formats, { selected: 'All Formats' }, { multiple: true, size: CirculationStatisticsReportFormat.formats.size/2, class: 'form-control' } %>
</div>
</div>
6 changes: 2 additions & 4 deletions app/views/shared/_enter_email.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<div class='form-group row'>
<div class='col-sm-10'>
<%= f.label :email, 'Email for notification when the report is ready:', class: 'form-control-label' %>
</div>
<div class='col-sm-10'>
<%= f.label :email, 'Email for notification when the report is ready:', class: 'col-sm-4 form-control-label' %>
<div class='col-sm-8'>
<%= f.text_field 'email', class: 'form-control' %>
</div>
</div>
9 changes: 5 additions & 4 deletions app/views/shared/_funds_selection.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<div class='form-group row'>
<div class='col-sm-10'>
<%= f.label :fund_select, 'Select funds for report by:', class: 'form-control-label'%>
</div>
<%= f.label :fund_select, 'Select funds for report by:', class: 'col-sm-2 form-control-label'%>
<div class='col-sm-10'>
<p><%= f.radio_button :fund_select, 'fund_name_id', {'class'=>'fund_selects', 'data-toggle' => 'collapse', 'data-target' => '.fund_name_id', onChange: '$(".collapse").removeClass("in");$(".all_sul").prop("checked", false);'} %> Fund ID/PTA or name</p>
<p><%= f.radio_button :fund_select, 'fund_begins_with', {'class'=>'fund_selects', 'data-toggle' => 'collapse', 'data-target' => '.fund_begins_with', onChange: '$(".collapse").removeClass("in");$(".all_sul").prop("checked", false);'} %> Fund ID/PTA begins with</p>
Expand Down Expand Up @@ -66,7 +64,10 @@
<% end %>
</div>
</div>
</div>
<div class='form-group row'>
<label class="col-sm-2 form-control-label" for="encumbrance_report_fund_begin"></label>
<div class='col-sm-10'>
<p> <%= f.radio_button :fund_begin, 'All SUL Funds', class: 'all_sul', onClick: "$('input:radio[class=fund_selects]').each(function () { $(this).prop('checked', false); });$('.collapse').removeClass('in')" %> Select all SUL funds </p>
<%= f.radio_button :fund_begin, 'All SUL Funds', class: 'all_sul', onClick: "$('input:radio[class=fund_selects]').each(function () { $(this).prop('checked', false); });$('.collapse').removeClass('in')" %> Select all SUL funds </p>
</div>
</div>
6 changes: 4 additions & 2 deletions spec/factories/circulation_statistics_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
email { 'test@test.com' }
lib_array { ['', 'ARS', 'ART', 'GREEN', 'SAL3'] }
source { 0 }
range_type { 'lc' }
range_type { '' }
call_alpha { '' }
barcodes { '' }
call_lo { 'K' }
call_lo { '' }
call_hi { '' }
format_array { ['', 'EQUIP', 'MANUSCRIPT'] }
exclude_inactive { 1 }
Expand All @@ -16,6 +16,8 @@
include_inhouse { 1 }
tag_field { '' }
tag_field2 { '' }
tag_field3 { '' }
tag_field4 { '' }
tags_url { 'Y' }
link_type { 'E' }
col_header1 { 'Selector Decision' }
Expand Down
15 changes: 15 additions & 0 deletions spec/features/circulation_statistics_report_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require 'rails_helper'

describe 'Circulation Statistics Report Page', type: :feature, js: true do
before do
FactoryBot.create(:uni_libs_locs)
stub_current_user(FactoryBot.create(:authorized_user))
visit new_circulation_statistics_report_path
select('SAL3', from: 'circulation_statistics_report_lib_array')
end

it 'shows the optional criteria when you click on the Proceed to next step button' do
find_link('Proceed to next step').click
expect(page).to have_css '#SAL3select option', count: 2
end
end
6 changes: 3 additions & 3 deletions spec/models/circulation_statistics_report_log_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@
end

it 'constructs lc range type params where call_hi is blank' do
report = FactoryBot.build(:circulation_statistics_report)
report = FactoryBot.build(:circulation_statistics_report, range_type: 'lc', call_lo: 'K')
log_params = described_class.process_range_type_params(report)
expect(log_params).to eq(params.merge!('call_range' => 'K'))
end

it 'constructs lc range type params where call_lo includes #' do
report = FactoryBot.build(:circulation_statistics_report, call_lo: 'L#')
report = FactoryBot.build(:circulation_statistics_report, range_type: 'lc', call_lo: 'L#')
log_params = described_class.process_range_type_params(report)
expect(log_params).to eq(params.merge!('call_range' => 'L0-9999'))
end

it 'constructs lc range type params where call_hi is not blank' do
report = FactoryBot.build(:circulation_statistics_report, call_hi: 'LZ')
report = FactoryBot.build(:circulation_statistics_report, range_type: 'lc', call_lo: 'K', call_hi: 'LZ')
log_params = described_class.process_range_type_params(report)
expect(log_params).to eq(params.merge!('call_range' => 'K-LZ'))
end
Expand Down
82 changes: 82 additions & 0 deletions spec/models/circulation_statistics_report_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
require 'rails_helper'

RSpec.describe CirculationStatisticsReport, type: :model do
describe 'LC callnum range' do
context 'when call_lo is one or two LC letters' do
let(:report) { FactoryBot.build(:circulation_statistics_report, range_type: 'lc', call_lo: 'n', call_hi: '') }

it 'call_hi can be blank' do
expect(report).to be_valid
end

it 'converts the call_lo to upper case' do
report.validate
expect(report.call_lo).to eq 'N'
end
end
end

context 'when call_lo is one or two LC letters' do
let(:report) { FactoryBot.build(:circulation_statistics_report, range_type: 'lc', call_lo: 'nd', call_hi: 'nz') }

it 'call_hi can be a latter letter' do
expect(report).to be_valid
end

it 'converts the call_lo to upper case' do
report.validate
expect(report.call_lo).to eq 'ND'
end

it 'converts the call_hi to upper case' do
report.validate
expect(report.call_hi).to eq 'NZ'
end
end

context 'when call lo is one or two letters with a wildcard' do
let(:report) { FactoryBot.build(:circulation_statistics_report, range_type: 'lc', call_lo: 'n#') }

it 'call_hi should be blank' do
expect(report).to be_valid
end

it 'converts the call_lo to upper case' do
report.validate
expect(report.call_lo).to eq 'N#'
end
end

describe 'classic call' do
context 'when classic call number alpha range' do
let(:report) { FactoryBot.build(:circulation_statistics_report, range_type: 'classic', call_alpha: 'nd') }

it 'converts the call_alpha to upper case before validations' do
report.validate
expect(report.call_alpha).to eq 'ND'
end
end

context 'when classic call number numeric range' do
let(:report) do
FactoryBot.build(:circulation_statistics_report, range_type: 'classic', call_lo: '100', call_hi: '230')
end

it 'is a valid report' do
report.validate
expect(report).to be_valid
end
end
end

describe 'tag fields' do
context 'when there is a 008 in one of the tag fields' do
let(:report) { FactoryBot.build(:circulation_statistics_report, tag_field4: '008') }

it 'is an invalis report' do
report.validate
expect(report).not_to be_valid
end
end
end
end

0 comments on commit f872a3e

Please sign in to comment.