Skip to content

Commit

Permalink
Fixed conflicts from rebase with master
Browse files Browse the repository at this point in the history
  • Loading branch information
jgreben committed Sep 15, 2016
2 parents ff0be5a + cf6954e commit 434ed2d
Show file tree
Hide file tree
Showing 12 changed files with 147 additions and 22 deletions.
9 changes: 2 additions & 7 deletions app/assets/javascripts/shelf_selection_reports.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,15 @@ $(document).ready(function() {
})
}
})
$('#shelf_selection_report_fmt_array option').remove();
$('#shelf_selection_report_fmt_array').append($(html_opts).find('fmts option'));
$.each($(html_opts).find('fmtsstring').text().split(','), function(i,e){
$("#shelf_selection_report_fmt_array option[value='" + e + "']").prop('selected', true);
});
$('#shelf_selection_report_itype_array option').remove();
$('#shelf_selection_report_itype_array').append($(html_opts).find('itypes option'));
$.each($(html_opts).find('itypesstring').text().split(','), function(i,e){
$("#shelf_selection_report_itype_array option[value='" + e + "']").prop('selected', true);
});
$('#shelf_selection_report_icat1_array option').remove();
$('#shelf_selection_report_itcat1_array').append($(html_opts).find('icats option'));
$('#shelf_selection_report_icat1_array option[value="ALL"]').prop('selected', false);
$.each($(html_opts).find('icat1sstring').text().split(','), function(i,e){
$("#shelf_selection_report_itcat1_array option[value='" + e + "']").prop('selected', true);
$("#shelf_selection_report_icat1_array option[value='" + e + "']").prop('selected', true);
});
$('#shelf_selection_report_lang').val($(html_opts).find('lang').text());
$('#shelf_selection_report_min_yr').val($(html_opts).find('minyr').text());
Expand Down
9 changes: 7 additions & 2 deletions app/controllers/shelf_selection_reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ def new

def create
@shelf_selection_report = ShelfSelectionReport.new(params[:shelf_selection_report])
flash[:notice] = 'Shelf Selection Report params submitted!'
redirect_to root_url
if @shelf_selection_report.valid?
flash[:notice] = 'Shelf Selection Report request submitted!'
ShelfSelSearch.save_search(@shelf_selection_report) if @shelf_selection_report.save_search?
redirect_to root_url
else
render action: 'new'
end
end

def home_locations
Expand Down
11 changes: 7 additions & 4 deletions app/models/circulation_statistics_report_log.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ def self.save_stats(circ_stats)
if circ_stats.barcodes
FileUtils.chmod 0o664, circ_stats.barcodes.tempfile.path
symphony_location = '/symphony/Dataload/Uploads/CircStats/'
FileUtils.mv circ_stats.barcodes.tempfile.path, "#{symphony_location}#{circ_stats.barcodes.original_filename}"
user = circ_stats.email.split('@')[0]
file_path = "#{symphony_location}#{user}_#{circ_stats.barcodes.original_filename}"
FileUtils.mv circ_stats.barcodes.tempfile.path, file_path
end
CirculationStatisticsReportLog.create(complete_params)
end
Expand All @@ -31,11 +33,12 @@ def self.process_range_type_params(circ_stats)
case circ_stats.range_type
when 'barcodes'
range_type_params['call_range'] = "Any call (Selection is barcode list #{circ_stats.barcodes.original_filename})"
range_type_params['input_path'] = "/symphony/Dataload/Uploads/CircStats/#{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['libs_locs'] = 'Any lib-loc'
when 'lc'
if circ_stats.call_lo.include?('#')
range_type_params['call_range'] = "#{circ_stats.call_lo}0-9999"
range_type_params['call_range'] = "#{circ_stats.call_lo[0]}0-9999"
elsif circ_stats.call_hi.blank?
range_type_params['call_range'] = circ_stats.call_lo
else
Expand All @@ -53,7 +56,7 @@ def self.process_range_type_params(circ_stats)
range_type_params['call_range'] = if circ_stats.call_hi.blank?
'NOT LC/DEWEY'
else
"NOT LC/DEWEY:#{circ_stats.call_hi}"
"NOT LC/DEWEY: #{circ_stats.call_hi}"
end
range_type_params['libs_locs'] = circ_stats.lib_loc_array
end
Expand Down
32 changes: 32 additions & 0 deletions app/models/shelf_sel_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,38 @@
class ShelfSelSearch < ActiveRecord::Base
self.table_name = 'shelf_sel_searches'

def self.save_search(shelf_sel_rpt)
params = build_search_params(shelf_sel_rpt)
ShelfSelSearch.create(params)
end

# rubocop:disable Metrics/MethodLength,Metrics/AbcSize
def self.build_search_params(shelf_sel_rpt)
{ user_name: shelf_sel_rpt.email.split('@')[0],
search_name: shelf_sel_rpt.subj_name,
call_range: "#{shelf_sel_rpt.call_alpha}#{shelf_sel_rpt.call_lo}-#{shelf_sel_rpt.call_hi}",
lib: shelf_sel_rpt.lib,
locs: shelf_sel_rpt.loc_array.join(',')[1..-1],
fmts: shelf_sel_rpt.fmt_array.join(',')[1..-1],
itypes: shelf_sel_rpt.itype_array.join(',')[1..-1],
min_yr: shelf_sel_rpt.min_yr,
max_yr: shelf_sel_rpt.max_yr,
min_circ: shelf_sel_rpt.min_circ,
max_circ: shelf_sel_rpt.max_circ,
na_i_e_shadow: shelf_sel_rpt.shadowed.to_i,
na_i_e_url: shelf_sel_rpt.url.to_i,
na_i_e_dups: shelf_sel_rpt.has_dups.to_i,
na_i_e_boundw: shelf_sel_rpt.no_boundw.to_i,
na_i_e_cloc_diff: shelf_sel_rpt.cloc_diff.to_i,
na_i_e_digisent: shelf_sel_rpt.digisent.to_i,
na_i_e_mhlds: shelf_sel_rpt.mhlds.to_i,
na_i_e_multvol: shelf_sel_rpt.multvol.to_i,
na_i_e_multcop: shelf_sel_rpt.multcop.to_i,
lang: shelf_sel_rpt.lang,
icat1s: shelf_sel_rpt.icat1_array.join(',')[1..-1] }
end
# rubocop:enable Metrics/MethodLength,Metrics/AbcSize

def self.saved_cursors(sunet_id)
own_saved_cursor(sunet_id) + others_saved_cursor(sunet_id)
end
Expand Down
36 changes: 36 additions & 0 deletions app/models/shelf_selection_report.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,50 @@
# app/model/shelf_selection_report.rb
class ShelfSelectionReport
include ActiveModel::Model
extend ActiveModel::Callbacks
include ActiveModel::Validations
include ActiveModel::Validations::Callbacks
attr_accessor :email, :lib, :loc_array, :cloc_diff, :fmt_array,
:itype_array, :icat1_array, :lang, :min_yr, :max_yr,
:min_circ, :max_circ, :shadowed, :digisent, :url,
:mhlds, :has_dups, :multvol, :multcop, :no_boundw,
:range_type, :call_alpha, :subj_name,
:save_opt, :search_name, :call_lo, :call_hi
validates :email, :loc_array, presence: true
validates :loc_array, length: { minimum: 2, message: "can't be empty" }
validates :call_lo, presence: true, if: :lc_range_type?
validates :fmt_array, :itype_array, length: { minimum: 2, message: "can't be empty" }, if: :lc_range_type?
validate :classic_call_lo_and_hi, if: :classic_range_type?
validates :itype_array, length: { minimum: 2, message: "can't be empty" }, if: :classic_range_type?
validates :fmt_array, length: { minimum: 2, message: "can't be empty" }, if: :other_range_type?
validates :fmt_array, length: { minimum: 2, message: "can't be empty" }, if: :other_range_type?

def self.generic_options
[["Doesn't matter", 0], ['INCLUDE only', 1], ['EXCLUDE', 2]]
end

def save_search?
subj_name.present? && save_opt == 'save'
end

private

def lc_range_type?
range_type == 'lc'
end

def classic_range_type?
range_type == 'classic'
end

def other_range_type?
range_type == 'other'
end

def classic_call_lo_and_hi
lo_integer = call_lo.to_i
hi_integer = call_hi.to_i
message = 'Low and hi callnum range must be all digits, with lo lower than hi.'
errors.add(:base, message) unless call_lo =~ /^[0-9]+$/ && call_hi =~ /^[0-9]+$/ && lo_integer < hi_integer
end
end
4 changes: 2 additions & 2 deletions app/views/circulation_statistics_reports/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<div class='form-group row'>
<%= f.label :email, 'Email for notification when the report is ready:', class: 'col-sm-5 form-control-label' %>
<div class='col-sm-10'>
<%= f.text_field 'email', class: 'form-control' %>
<%= f.text_field 'email', class: 'form-control', value: "#{user_id}@stanford.edu" %>
</div>
</div>
<div class='form-group row'>
Expand Down Expand Up @@ -130,7 +130,7 @@
</div>
<div class='form-group row'>
<%= f.label :ckey_url, 'Show CKEY cells as links to Searchworks pages for those ckeys.', class: 'col-sm-10 form-control-label' do %>
<%= f.check_box :ckey_url, {}, 'Y', nil %>
<%= f.check_box :ckey_url, { checked: true }, 'Y', nil %>
Show CKEY cells as links to Searchworks pages for those ckeys.
<% end %>
</div>
Expand Down
7 changes: 4 additions & 3 deletions app/views/shelf_selection_reports/load_saved_options.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@
<option value='<%= itype %>'><%= itype %></option>
<% end %>
</itypes>
<% unless @shelf_sel_search.icat1s.blank? %>
<itcat1sstring><%= @shelf_sel_search.icat1s %></icat1sstring>
<% if @shelf_sel_search.icat1s == nil %>
<% else %>
<icat1sstring><%= @shelf_sel_search.icat1s %></icat1sstring>
<icat1s>
<% @shelf_sel_search.icat1s.split(',').each do |icat1| %>
<option value='<%= icat1 %>'><%= icat1 %></option>
<% end %>
<% end %>
</icat1s>
<% end %>
<lang><%= @shelf_sel_search.lang %></lang>
Expand Down
4 changes: 2 additions & 2 deletions app/views/shelf_selection_reports/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<div class='form-group row'>
<%= f.label :icat1_array, 'Select the item category1s to include:', class: 'col-sm-10 form-control-label' %>
<div class='col-sm-10'>
<%= f.select :icat1_array, ShelfSelItemCat1.item_category1s, {}, { multiple: true, class: 'form-control' } %>
<%= f.select :icat1_array, ShelfSelItemCat1.item_category1s, { selected: 'ALL' }, { multiple: true, class: 'form-control' } %>
</div>
</div>
<div class='form-group row'>Leave any text input fields below blank to not filter by those conditions</div>
Expand Down Expand Up @@ -155,7 +155,7 @@
or one letter followed by # symbol.', class: 'form-control-label' %>
</div>
<div id='classic-call-lo-label' style='display:none;'>
<%= f.label :call_lo, 'Enter the LC or Dewey call number range to select. 1 to 3 letters at start of LC call number Leave blank for Dewey. Letters only.', class: 'form-control-label' %>
<%= f.label :call_lo, 'Lowest number of call number range. Maximum 4 digits for LC, 3 digits for Dewey.', class: 'form-control-label' %>
</div>
<div id='lc-classic-call-lo-form-element'>
<%= f.text_field :call_lo, class: 'input-mini' %>
Expand Down
11 changes: 9 additions & 2 deletions spec/controllers/shelf_selection_reports_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,17 @@
end

describe 'post#create' do
it 'redirects to root_url' do
it 'redirects to root_url when params are valid' do
stub_current_user(FactoryGirl.create(:authorized_user))
post :create, shelf_selection_report: { email: '' }
post :create, shelf_selection_report: { email: 'testuser@test.org', range_type: 'lc',
loc_array: 'ALL', call_lo: 'A',
fmt_array: ['', 'EQUIP'], itype_array: ['', 'ATLAS'] }
expect(response).to redirect_to root_url
end
it 'renders the new action when params are invalid' do
stub_current_user(FactoryGirl.create(:authorized_user))
post :create, shelf_selection_report: { email: '' }
expect(response).to render_template('new')
end
end
end
32 changes: 32 additions & 0 deletions spec/factories/shelf_selection_report.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# frozen_string_literal: true
FactoryGirl.define do
factory :shelf_selection_report do
email 'test@test.org'
lib 'GREEN'
loc_array ['', 'BENDER']
cloc_diff '0'
fmt_array ['', 'MANUSCRIPT']
itype_array ['', 'ATLAS-EXP']
icat1_array ['', 'ALL']
lang ''
min_yr ''
max_yr ''
min_circ ''
max_circ ''
shadowed '2'
digisent '0'
url '0'
mhlds '0'
has_dups '0'
multvol '0'
multcop '0'
no_boundw '1'
range_type 'lc'
call_alpha ''
subj_name 'Green Bender A-B'
save_opt 'save'
search_name ''
call_lo 'A'
call_hi 'B'
end
end
8 changes: 8 additions & 0 deletions spec/models/shelf_sel_search_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,13 @@
expect(shelf_sel_search.call_hi).to eq('F')
end
end

describe 'save_search class method' do
it 'creates a ShelfSelSearch from ShelfSelRpt params' do
shelf_selection_report = FactoryGirl.build(:shelf_selection_report)
shelf_sel_search = ShelfSelSearch.save_search(shelf_selection_report)
expect(shelf_sel_search).to be_instance_of(ShelfSelSearch)
end
end
end
end
6 changes: 6 additions & 0 deletions spec/models/shelf_selection_report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,11 @@
it 'returns generic options for selects' do
expect(ShelfSelectionReport.generic_options).to eq([["Doesn't matter", 0], ['INCLUDE only', 1], ['EXCLUDE', 2]])
end

it 'validates lo and hi call numbers' do
shelf_selection_report = ShelfSelectionReport.new(email: 'test@test.org', range_type: 'classic')
message = ['Low and hi callnum range must be all digits, with lo lower than hi.']
expect(shelf_selection_report.send(:classic_call_lo_and_hi)).to eq(message)
end
end
end

0 comments on commit 434ed2d

Please sign in to comment.