Skip to content

Commit

Permalink
load selection criteria for shelf selection
Browse files Browse the repository at this point in the history
  • Loading branch information
tallenaz committed Jul 12, 2016
1 parent 3b11b0e commit 0e535ba
Show file tree
Hide file tree
Showing 20 changed files with 223 additions and 71 deletions.
2 changes: 0 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ gem 'bootstrap_form'
gem 'sass-rails', '~> 5.0'
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Use cancan for authorization
gem 'cancan'
# Use ActiveModel has_secure_password
Expand Down
7 changes: 3 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,6 @@ GEM
thread_safe (0.3.5)
tilt (2.0.5)
tins (1.6.0)
turbolinks (5.0.0)
turbolinks-source (~> 5)
turbolinks-source (5.0.0)
tzinfo (1.2.2)
thread_safe (~> 0.1)
unicode-display_width (1.1.0)
Expand Down Expand Up @@ -282,5 +279,7 @@ DEPENDENCIES
sqlite3
sul_styles
therubyracer
turbolinks
web-console (~> 2.0)

BUNDLED WITH
1.11.2
1 change: 0 additions & 1 deletion app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
//
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require bootstrap
//= require forms
//= require_tree .
74 changes: 64 additions & 10 deletions app/assets/javascripts/shelf_selection_reports.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,71 @@
$(document).on('change', '#shelf_selection_report_lib', function() {
$("#shelf_selection_report_loc_array option").remove();
lib = $('#shelf_selection_report_lib').find(':selected').text();
$.ajax({
url: '/shelf_selection_reports/home_locations',
cache: false,
data: { lib: lib },
success: function(html){
$('#shelf_selection_report_loc_array').append(html);
}
$(document).on('ready page:load', function() {
$('#shelf_selection_report_lib').change(function() {
$("#shelf_selection_report_loc_array option").remove();
lib = $('#shelf_selection_report_lib').find(':selected').text();
$.ajax({
url: '/shelf_selection_reports/home_locations',
cache: false,
data: { lib: lib },
success: function(html){
$('#shelf_selection_report_loc_array').append(html);
}
})
})
$('input[type="radio"]').click(function (){
$('#lc-show-hide').css('display', ($(this).val() == 'lc') ? 'block' : 'none');
$('#classic-show-hide').css('display', ($(this).val() == 'classic') ? 'block' : 'none');
$('#other-show-hide').css('display', ($(this).val() == 'other') ? 'block' : 'none');
})
$('#shelf_selection_report_search_name').change(function(){
search_name = $('#shelf_selection_report_search_name').find(':selected').text();
$.ajax({
url: '/shelf_selection_reports/load_saved_options',
cache: false,
data: { search_name: search_name },
success: function(html_opts) {
$('#shelf_selection_report_lib').val($(html_opts).find('lib').text());
$("#shelf_selection_report_loc_array option").remove();
$.ajax({
url: '/shelf_selection_reports/home_locations',
cache: false,
data: { lib: $(html_opts).find('lib').text() },
success: function(html){
$('#shelf_selection_report_loc_array').append(html);
$('#shelf_selection_report_loc_array').val($(html_opts).find('locs').text());
}
})
$('#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'));
$.each($(html_opts).find('icat1sstring').text().split(','), function(i,e){
$("#shelf_selection_report_itcat1_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());
$('#shelf_selection_report_max_yr').val($(html_opts).find('maxyr').text());
$('#shelf_selection_report_min_circ').val($(html_opts).find('mincirc').text());
$('#shelf_selection_report_max_circ').val($(html_opts).find('maxcirc').text());
$('#shelf_selection_report_shadowed').val($(html_opts).find('shadowed').text());
$('#shelf_selection_report_digisent').val($(html_opts).find('digisent').text());
$('#shelf_selection_report_url').val($(html_opts).find('url').text());
$('#shelf_selection_report_mhlds').val($(html_opts).find('mhlds').text());
$('#shelf_selection_report_has_dups').val($(html_opts).find('hasdups').text());
$('#shelf_selection_report_multvol').val($(html_opts).find('multvol').text());
$('#shelf_selection_report_multcop').val($(html_opts).find('multcop').text());
$('#noboundw').val($(html_opts).find('noboundw').text());
$('#shelf_selection_report_lc_call_lo').val($(html_opts).find('calllo').text());
$('#shelf_selection_report_lc_call_hi').val($(html_opts).find('callhi').text());
$('#shelf_selection_report_subj_name').val($(html_opts).find('subjname').text());
}
})
})
});
19 changes: 10 additions & 9 deletions app/controllers/shelf_selection_reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@ def new
@shelf_selection_report = ShelfSelectionReport.new
end

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

def home_locations
@home_locations = UniLibsLocs.home_locations_from(params[:lib])
render layout: false
end

def load_saved_options
@shelf_sel_search = ShelfSelSearch.from_search_name(params[:search_name])
render layout: false
end
end
2 changes: 1 addition & 1 deletion app/models/circulation_statistics_report_format.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ class CirculationStatisticsReportFormat < ActiveRecord::Base
self.table_name = 'circ_stats_rpt_fmts'

def self.formats
select(:format).distinct.order(:format).pluck(:format)
(select(:format).distinct.order(:format).pluck(:format) + ['ALL']).sort
end
end
2 changes: 1 addition & 1 deletion app/models/shelf_sel_item_cat1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ class ShelfSelItemCat1 < ActiveRecord::Base
self.table_name = 'shelf_sel_item_cat1s'

def self.item_category1s
select(:item_category1).distinct.order(:item_category1).pluck(:item_category1)
(select(:item_category1).distinct.order(:item_category1).pluck(:item_category1) + ['ALL']).sort
end
end
24 changes: 22 additions & 2 deletions app/models/shelf_sel_search.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,32 @@
# app/model/shelf_sel_search.rb
class ShelfSelSearch < ActiveRecord::Base
self.table_name = 'shelf_sel_searches'
# TODO: make saved_cursors return more than just my own

def self.saved_cursors(sunet_id)
own_saved_cursor(sunet_id)
own_saved_cursor(sunet_id) + others_saved_cursor(sunet_id)
end

def self.own_saved_cursor(sunet_id)
where(user_name: sunet_id).order(:search_name).pluck(:search_name, :user_name).map { |a| a.join(', ') }
end

def self.others_saved_cursor(sunet_id)
where.not(user_name: sunet_id).order(:search_name).pluck(:search_name, :user_name).map { |a| a.join(', ') }
end

def self.from_search_name(search_name)
# example search_name param: 'Green Stacks A-Z, azanella'
search_name_array = search_name.split(',').map(&:strip)
search_name = search_name_array[0]
user_name = search_name_array[1]
find_by(search_name: search_name, user_name: user_name)
end

def call_lo
call_range.split('-')[0]
end

def call_hi
call_range.split('-')[1]
end
end
2 changes: 1 addition & 1 deletion app/models/shelf_selection_item_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ class ShelfSelectionItemType < ActiveRecord::Base
self.table_name = 'shelf_sel_item_types'

def self.item_types
select(:item_type).distinct.order(:item_type).pluck(:item_type)
(select(:item_type).distinct.order(:item_type).pluck(:item_type) + ['ALL']).sort
end
end
2 changes: 1 addition & 1 deletion app/models/shelf_selection_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class ShelfSelectionReport
:mhlds, :has_dups, :multvol, :multcop, :no_boundw,
:range_type, :lc_call_lo, :lc_call_hi, :classic_call_lo,
:classic_call_hi, :other_call_hi, :call_alpha, :subj_name,
:save_opt
:save_opt, :search_name

def self.generic_options
[["Doesn't matter", 0], ['INCLUDE only', 1], ['EXCLUDE', 2]]
Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/_uni_libs_locs.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class='form-group row pad'>
<%= f.label :lib, 'Select Library:', class: 'col-sm-5 form-control-label' %>
<div class='col-sm-10'>
<%= f.select :lib, UniLibsLocs.libraries, { include_blank: true }, { class: 'form-control' } %>
<%= f.select :lib, UniLibsLocs.libraries, { include_blank: true, selected: 'GREEN' }, { class: 'form-control' } %>
</div>
</div>
2 changes: 1 addition & 1 deletion app/views/shelf_selection_reports/home_locations.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<% @home_locations.each do |home_location| %>
<option><%= home_location %></option>
<option value='<%= home_location %>'><%= home_location %></option>
<% end %>
43 changes: 43 additions & 0 deletions app/views/shelf_selection_reports/load_saved_options.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<search>
<username><%= @shelf_sel_search.user_name %></username>
<searchname><%= @shelf_sel_search.search_name %></searchname>
<callrange><%= @shelf_sel_search.call_range %></callrange>
<lib><%= @shelf_sel_search.lib %></lib>
<locs><%= @shelf_sel_search.locs %></locs>
<fmtsstring><%= @shelf_sel_search.fmts %></fmtsstring>
<fmts>
<% @shelf_sel_search.fmts.split(',').each do |fmt| %>
<option value='<%= fmt %>'><%= fmt %></option>
<% end %>
</fmts>
<itypesstring><%= @shelf_sel_search.itypes %></itypesstring>
<itypes>
<% @shelf_sel_search.itypes.split(',').each do |itype| %>
<option value='<%= itype %>'><%= itype %></option>
<% end %>
</itypes>
<% unless @shelf_sel_search.blank? %>
<itcat1sstring><%= @shelf_sel_search.icat1s %></icat1sstring>
<icat1s>
<% @shelf_sel_search.icat1s.split(',').each do |icat1| %>
<option value='<%= icat1 %>'><%= icat1 %></option>
<% end %>
</icat1s>
<% end %>
<lang><%= @shelf_sel_search.lang %></lang>
<minyr><%= @shelf_sel_search.min_yr %></minyr>
<maxyr><%= @shelf_sel_search.max_yr %></maxyr>
<mincirc><%= @shelf_sel_search.min_circ %></mincirc>
<maxcirc><%= @shelf_sel_search.max_circ %></maxcirc>
<shadowed><%= @shelf_sel_search.na_i_e_shadow %></shadowed>
<digisent><%= @shelf_sel_search.na_i_e_digisent %></digisent>
<url><%= @shelf_sel_search.na_i_e_url %></url>
<mhlds><%= @shelf_sel_search.na_i_e_mhlds %></mhlds>
<hasdups><%= @shelf_sel_search.na_i_e_dups %></hasdups>
<multvol><%= @shelf_sel_search.na_i_e_multvol %></multvol>
<multcop><%= @shelf_sel_search.na_i_e_multcop %></multcop>
<noboundw><%= @shelf_sel_search.na_i_e_boundw %></noboundw>
<calllo><%= @shelf_sel_search.call_lo %></calllo>
<callhi><%= @shelf_sel_search.call_hi %></callhi>
<subjname><%= @shelf_sel_search.search_name %></subjname>
</search>
58 changes: 30 additions & 28 deletions app/views/shelf_selection_reports/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,33 +1,36 @@
<h2>Shelf Selection Report Request</h2>
<%= form_for @shelf_selection_report, class: 'form-group' do |f| %>
<% if @shelf_selection_report.errors.any? %>
<div id="error_explanation">
<ul>
<% @shelf_selection_report.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<% if @shelf_selection_report.errors.any? %>
<div id="error_explanation">
<ul>
<% @shelf_selection_report.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class='panel panel-default col-sm-10'>
<div class='panel-body'>
<p>Optionally intialize the fields on this page with previously saved selection criteria.</p>
<%= f.select :search_name, ShelfSelSearch.saved_cursors(current_user.user_id), { prompt: '[Reload with no saved criteria]' }, class: 'form-control' %>
</div>
</div>
<div>
<%= render 'shared/enter_email', f: f %>
<%= render 'shared/uni_libs_locs', f: f %>

<div class='form-group row'>
<%= f.label :loc_array, 'Select Home Location(s) from the list below after selecting library above:', class: 'col-sm-10 form-control-label' %>
<div class='col-sm-10'>
<%= f.select :loc_array, [], { prompt: 'Please choose from above' }, { multiple: true, class: 'form-control' } %>
<%= f.select :loc_array, UniLibsLocs.home_locations_from('GREEN'), {}, { multiple: true, class: 'form-control' } %>
</div>
</div>
<div class='form-group row'>
<%= f.label :cloc_diff, 'Exclude items with Current Location different from Home Location', class: 'col-sm-10 form-control-label' do %>
<%= f.check_box :cloc_diff %>
Exclude items with Current Location different from Home Location
<%= f.check_box :cloc_diff %>
Exclude items with Current Location different from Home Location
<% end %>
</div>

<%= render 'shared/circulation_statistics_report_formats', f: f %>

<div class='form-group row'>
<%= f.label :itype_array, 'Select the item types to include:', class: 'col-sm-10 form-control-label' %>
<div class='col-sm-10'>
Expand Down Expand Up @@ -118,23 +121,23 @@
</div>
<div class='form-group row'>
<%= f.label :no_boundw, 'Exclude Bound-With Child items', class: 'col-sm-10 form-control-label' do %>
<%= f.check_box :no_boundw %>
Exclude Bound-With Child items
<%= f.check_box :no_boundw, id: 'noboundw', checked: 'checked' %>
Exclude Bound-With Child items
<% end %>
</div>
<div class='form-group row'><strong>Type of Call Number selection to use in the report:</strong> <em>(See bottom of page for examples of call number options)</em></div>
<div class='form-group row'>
<%= f.label :range_type, 'LC Letters Range: All LC call numbers beginning with specified letter(s) or range of letters', class:'col-sm-10 form-control-label' do %>
<%= f.radio_button :range_type, 'lc', checked: 'checked' %>
LC Letters Range: All LC call numbers beginning with specified letter(s) or range of letters
<%= f.radio_button :range_type, 'lc', checked: 'checked' %>
LC Letters Range: All LC call numbers beginning with specified letter(s) or range of letters
<% end %>
<%= f.label :range_type, 'Classic Selection: LC numerical range all beginning with same letter(s), or any range of Dewey numbers', class:'col-sm-10 form-control-label' do %>
<%= f.radio_button :range_type, 'classic' %>
Classic Selection: LC numerical range all beginning with same letter(s), or any range of Dewey numbers
<%= f.radio_button :range_type, 'classic' %>
Classic Selection: LC numerical range all beginning with same letter(s), or any range of Dewey numbers
<% end %>
<%= f.label :range_type, 'Other call numbers: All that are neither LC nor Dewey, optionally filtered by start of call number', class:'col-sm-10 form-control-label' do %>
<%= f.radio_button :range_type, 'other' %>
Other call numbers: All that are neither LC nor Dewey, optionally filtered by start of call number
<%= f.radio_button :range_type, 'other' %>
Other call numbers: All that are neither LC nor Dewey, optionally filtered by start of call number
<% end %>
</div>
<!-- bunch of javascript to show some fields depending on the range_type -->
Expand Down Expand Up @@ -194,12 +197,12 @@
</div>
<div class='form-group row'>
<%= f.label :save_opt, 'Use as email subject and name of saved criteria.', class:'col-sm-5 form-control-label' do %>
<%= f.radio_button :save_opt, 'save' %>
Use as email subject and name of saved criteria.
<%= f.radio_button :save_opt, 'save', checked: true %>
Use as email subject and name of saved criteria.
<% end %>
<%= f.label :save_opt, "Use as email subject only, don't save.", class:'form-control-label' do %>
<%= f.radio_button :save_opt, 'nosave' %>
Use as email subject only, don't save.
<%= f.radio_button :save_opt, 'nosave' %>
Use as email subject only, don't save.
<% end %>
</div>
<div><%= f.submit 'Submit', class: 'btn' %></div>
Expand All @@ -208,5 +211,4 @@
<div class="btn-group pad">
<%= main_menu_button %>
</div>

<%= render 'shared/call_number_range_examples' %>
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
resources :expenditures_with_circ_stats_reports, only: [:new, :create]

get 'shelf_selection_reports/home_locations' => 'shelf_selection_reports#home_locations', as: :home_locations_for_library
get 'shelf_selection_reports/load_saved_options' => 'shelf_selection_reports#load_saved_options', as: :load_saved_options

get 'batch_record_updates/errors_for_batch' => 'batch_record_updates#errors_for_batch'
get 'batch_record_updates/errors_for_batch/:batch_number' => 'batch_record_updates#errors_for_batch'
Expand Down

0 comments on commit 0e535ba

Please sign in to comment.