Skip to content

Commit

Permalink
[WIP] save shelf selection searches to db
Browse files Browse the repository at this point in the history
  • Loading branch information
tallenaz committed Sep 14, 2016
1 parent fcf3e3e commit 8278e64
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/controllers/shelf_selection_reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ def new
def create
@shelf_selection_report = ShelfSelectionReport.new(params[:shelf_selection_report])
if @shelf_selection_report.valid?
flash[:notice] = 'Shelf Selection Report params submitted!'
flash[:notice] = 'Shelf Selection Report request submitted!'
# kick off background script
# save to shelf_sel_search
# if v_subj_name is not null and p_save_opt = 'save'
# hand the right params to ShelfSelSearch creation
ShelfSelSearch.save_search(@shelf_selection_report) if @shelf_selection_report.save_search?
redirect_to root_url
else
render action: 'new'
Expand Down
28 changes: 28 additions & 0 deletions app/models/shelf_sel_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,34 @@
class ShelfSelSearch < ActiveRecord::Base
self.table_name = 'shelf_sel_searches'

# rubocop:disable Metrics/MethodLength,Metrics/AbcSize
def self.save_search(shelf_sel_rpt)
params = { 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] }
ShelfSelSearch.create(params)
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
8 changes: 8 additions & 0 deletions app/models/shelf_selection_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ def self.generic_options
[["Doesn't matter", 0], ['INCLUDE only', 1], ['EXCLUDE', 2]]
end

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

def search_params
{ user_name: email }
end

private

def lc_range_type?
Expand Down
7 changes: 7 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,12 @@
expect(shelf_sel_search.call_hi).to eq('F')
end
end

describe '#save_search' do
xit 'saves a shelf selection search to the db' do
shelf_sel_search = FactoryGirl.create(:shelf_sel_search)
expect(shelf_sel_search.save_search?).to eq('true')
end
end
end
end

0 comments on commit 8278e64

Please sign in to comment.