Skip to content

Commit

Permalink
Merging in changes from master, adding back test_app - but just the t…
Browse files Browse the repository at this point in the history
…est files
  • Loading branch information
Dan Funk committed Mar 7, 2011
2 parents 4945cbb + 4c4bcf3 commit 755555a
Show file tree
Hide file tree
Showing 32 changed files with 459 additions and 313 deletions.
1 change: 0 additions & 1 deletion .gitignore
Expand Up @@ -8,7 +8,6 @@ jetty/logs/*.log
jetty/solr/data/*
log/*
webrat-*
public/
config/SolrMarc/*.log*
rerun.txt
solr_marc/solrmarc.log
Expand Down
21 changes: 12 additions & 9 deletions app/controllers/catalog_controller.rb
@@ -1,3 +1,5 @@


class CatalogController < BlacklightController

include Blacklight::SolrHelper
Expand All @@ -15,13 +17,13 @@ class CatalogController < BlacklightController
# When RSolr::RequestError is raised, the rsolr_request_error method is executed.
# The index action will more than likely throw this one.
# Example, when the standard query parser is used, and a user submits a "bad" query.
rescue_from RSolr::RequestError, :with => :rsolr_request_error
rescue_from RSolr::Error::Http, :with => :rsolr_request_error

# get search results from the solr index
def index

extra_head_content << '<link rel="alternate" type="application/rss+xml" title="RSS for results" href="'+ url_for(params.merge("format" => "rss")) + '">'
extra_head_content << '<link rel="alternate" type="application/atom+xml" title="Atom for results" href="'+ url_for(params.merge("format" => "atom")) + '">'
extra_head_content << view_context.auto_discovery_link_tag(:rss, url_for(params.merge(:format => 'rss')), :title => "RSS for results")
extra_head_content << view_context.auto_discovery_link_tag(:atom, url_for(params.merge(:format => 'atom')), :title => "Atom for results")

(@response, @document_list) = get_search_results
@filters = params[:f] || []
Expand Down Expand Up @@ -118,22 +120,23 @@ def send_email_record
@response, @documents = get_solr_response_for_field_values("id",params[:id])
if params[:to]
from = request.host # host w/o port for From address (from address cannot have port#)
host = request.host
host << ":#{request.port}" unless request.port.nil? # host w/ port for linking
url_gen_params = {:host => request.host_with_port, :protocol => request.protocol}

case params[:style]
when 'sms'
phone_num = params[:to].gsub(/[^\d]/, '')
if !params[:carrier].blank?
if params[:to].length != 10
if phone_num.length != 10
flash[:error] = "You must enter a valid 10 digit phone number"
else
email = RecordMailer.create_sms_record(@documents, {:to => params[:to], :carrier => params[:carrier]}, from, host)
email = RecordMailer.create_sms_record(@documents, {:to => phone_num, :carrier => params[:carrier]}, from, url_gen_params)
end
else
flash[:error] = "You must select a carrier"
end
when 'email'
if params[:to].match(/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/)
email = RecordMailer.create_email_record(@documents, {:to => params[:to], :message => params[:message]}, from, host)
email = RecordMailer.create_email_record(@documents, {:to => params[:to], :message => params[:message]}, from, url_gen_params)
else
flash[:error] = "You must enter a valid email address"
end
Expand Down
25 changes: 16 additions & 9 deletions app/controllers/folder_controller.rb
Expand Up @@ -6,9 +6,10 @@ class FolderController < BlacklightController
def index
@response, @documents = get_solr_response_for_field_values("id",session[:folder_document_ids] || [])
end


# add a document_id to the folder
def create
# add a document_id to the folder. :id of action is solr doc id
def update
session[:folder_document_ids] = session[:folder_document_ids] || []
session[:folder_document_ids] << params[:id]
# Rails 3 uses a one line notation for setting the flash notice.
Expand All @@ -19,19 +20,25 @@ def create
end
end

# remove a document_id from the folder
# remove a document_id from the folder. :id of action is solr_doc_id
def destroy
session[:folder_document_ids].delete(params[:id])
flash[:notice] = "#{params[:title] || "Item"} successfully removed from Folder"
respond_to do |format|
format.html { redirect_to :back }
format.js { render :json => session[:folder_document_ids] }
end

unless request.xhr?
respond_to do |format|
format.html do
flash[:notice] = "#{params[:title] || "Item"} successfully removed from selected items"
redirect_to :back
end
end
else
render :text => "OK"
end
end

# get rid of the items in the folder
def clear
flash[:notice] = "Cleared Folder"
flash[:notice] = "Cleared Selected Items"
session[:folder_document_ids] = []
respond_to do |format|
format.html { redirect_to :back }
Expand Down
30 changes: 15 additions & 15 deletions app/helpers/blacklight_helper.rb
Expand Up @@ -130,7 +130,7 @@ def render_link_rel_alternates(document=@document, options = {})
seen.add(spec[:content_type]) if options[:unique]
end
end
return html
return html.html_safe
end

def render_opensearch_response_metadata
Expand Down Expand Up @@ -175,21 +175,23 @@ def render_facet_limit(solr_field)
def render_document_list_partial options={}
render :partial=>'catalog/document_list'
end


# Save function area for search results 'index' view, normally
# renders next to title. Includes just 'Folder' by default.
def render_index_doc_actions(document, options={})
content_tag("div", :class=>"documentFunctions") do
"#{render(:partial => 'folder_control', :locals => {:document=> document}.merge(options))}
#{render(:partial => 'bookmark_control', :locals => {:document=> document}.merge(options))}".html_safe
raw("#{render(:partial => 'bookmark_control', :locals => {:document=> document}.merge(options))}
#{render(:partial => 'folder_control', :locals => {:document=> document}.merge(options))}")
end
end

# Save function area for item detail 'show' view, normally
# renders next to title. By default includes 'Folder' and 'Bookmarks'
def render_show_doc_actions(document=@document, options={})
render_index_doc_actions(document, options)
content_tag("div", :class=>"documentFunctions") do
raw("#{render(:partial => 'bookmark_control', :locals => {:document=> document}.merge(options))}
#{render(:partial => 'folder_control', :locals => {:document=> document}.merge(options))}")
end
end

# used in the catalog/_index_partials/_default view
Expand Down Expand Up @@ -222,7 +224,7 @@ def document_heading
@document[Blacklight.config[:show][:heading]] || @document.id
end
def render_document_heading
'<h1>' + document_heading + '</h1>'
content_tag(:h1, document_heading)
end

# Used in the show view for setting the main html document title
Expand All @@ -233,7 +235,7 @@ def document_show_html_title
# Used in citation view for displaying the title
def citation_title(document)
document[Blacklight.config[:show][:html_title]]
end
I end

# Used in the document_list partial (search view) for building a select element
def sort_fields
Expand Down Expand Up @@ -273,7 +275,7 @@ def render_document_show_field_value args

def render_field_value value=nil
value = [value] unless value.is_a? Array
return value.map { |v| v.html_safe }.join field_value_separator
return value.map { |v| html_escape v }.join(field_value_separator).html_safe
end

def field_value_separator
Expand Down Expand Up @@ -315,16 +317,14 @@ def link_to_previous_search(params)
# options consist of:
# :suppress_link => true # do not make it a link, used for an already selected value for instance
def render_facet_value(facet_solr_field, item, options ={})
link_to_unless(options[:suppress_link], item.value, add_facet_params_and_redirect(facet_solr_field, item.value), :class=>"facet_select label") + " " + render_facet_count(item.hits)
(link_to_unless(options[:suppress_link], item.value, add_facet_params_and_redirect(facet_solr_field, item.value), :class=>"facet_select label") + " " + render_facet_count(item.hits)).html_safe
end

# Standard display of a SELECTED facet value, no link, special span
# with class, and 'remove' button.
def render_selected_facet_value(facet_solr_field, item)
'<span class="selected label">' +
render_facet_value(facet_solr_field, item, :suppress_link => true) +
'</span>' +
link_to("[remove]", remove_facet_params(facet_solr_field, item.value, params), :class=>"remove")
content_tag(:span, render_facet_value(facet_solr_field, item, :suppress_link => true), :class => "selected label") +
link_to("[remove]", remove_facet_params(facet_solr_field, item.value, params), :class=>"remove")
end

# Renders a count value for facet limits. Can be over-ridden locally
Expand Down Expand Up @@ -418,8 +418,8 @@ def link_to_query(query)
def render_document_index_label doc, opts
label = nil
label ||= doc.get(opts[:label]) if opts[:label].instance_of? Symbol
label ||= opts[:label] if opts[:label].instance_of? String
label ||= opts[:label].call(doc, opts) if opts[:label].instance_of? Proc
label ||= opts[:label] if opts[:label].is_a? String
label ||= doc.id
end

Expand Down Expand Up @@ -511,7 +511,7 @@ def link_to_with_data(*args, &block)
end

href_attr = "href=\"#{url}\"" unless href
"<a #{href_attr}#{tag_options}>#{h(name) || h(url)}</a>"
"<a #{href_attr}#{tag_options}>#{h(name) || h(url)}</a>".html_safe
end
end

Expand Down
15 changes: 8 additions & 7 deletions app/helpers/catalog_helper.rb
Expand Up @@ -11,23 +11,24 @@ def format_num(num); number_with_delimiter(num) end
# an RSolr::Ext::Response works. Perhaps it duck-types to something
# from will_paginate?
def page_entries_info(collection, options = {})
start = collection.next_page == 2 ? 1 : collection.previous_page * collection.per_page + 1
start = (collection.current_page - 1) * collection.per_page + 1
total_hits = @response.total
start_num = format_num(start)
end_num = format_num(start + collection.per_page - 1)
end_num = format_num(start + collection.size - 1)
total_num = format_num(total_hits)
# end_num = total_num if total_hits < (start + collection.per_page - 1)

entry_name = options[:entry_name] ||
(collection.empty?? 'entry' : collection.first.class.name.underscore.sub('_', ' '))

if collection.total_pages < 2
case collection.size
when 0; "No #{entry_name.pluralize} found"
when 1; "Displaying <b>1</b> #{entry_name}"
else; "Displaying <b>all #{total_num}</b> #{entry_name.pluralize}"
when 0; "No #{h(entry_name.pluralize)} found".html_safe
when 1; "Displaying <b>1</b> #{h(entry_name)}".html_safe
else; "Displaying <b>all #{total_num}</b> #{entry_name.pluralize}".html_safe
end
else
"Displaying #{entry_name.pluralize} <b>#{start_num} - #{end_num}</b> of <b>#{total_num}</b>"
"Displaying #{h(entry_name.pluralize)} <b>#{start_num} - #{end_num}</b> of <b>#{total_num}</b>".html_safe
end
end

Expand All @@ -36,7 +37,7 @@ def page_entries_info(collection, options = {})
# Code should call this method rather than interrogating session directly,
# because implementation of where this data is stored/retrieved may change.
def item_page_entry_info
"Showing item <b>#{session[:search][:counter].to_i} of #{format_num(session[:search][:total])}</b> from your search."
"Showing item <b>#{session[:search][:counter].to_i} of #{format_num(session[:search][:total])}</b> from your search.".html_safe
end

# Look up search field user-displayable label
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/hash_as_hidden_fields.rb
Expand Up @@ -23,7 +23,7 @@ def hash_as_hidden_fields(hash)
end
end

hidden_fields.join("\n")
hidden_fields.join("\n").html_safe
end

protected
Expand Down
26 changes: 13 additions & 13 deletions app/helpers/render_constraints_helper.rb
Expand Up @@ -95,26 +95,26 @@ def render_search_to_s_filters(params)
params[:f].collect do |facet_field, value_list|
render_search_to_s_element(Blacklight.config[:facet][:labels][facet_field],
value_list.collect do |value|
"<span class='filterValue'>#{h(value)}</span>"
end.join(" <span class='label'>and</span> "),
:escape_value => false
render_filter_value(value)
end.join(content_tag(:span, 'and', :class =>'label'))
)
end.join(" \n ")
end.join(" \n ").html_safe
end

# value can be Array, in which case elements are joined with
# 'and'. Pass in option :escape_value => false to pass in pre-rendered
# html for value. key with escape_key if needed.
def render_search_to_s_element(key, value, options = {})
options[:escape_value] = true unless options.has_key?(:escape_value)
options[:escape_key] = true unless options.has_key?(:escape_key)

key = h(key) if options[:escape_key]
value = h(value) if options[:escape_value]

"<span class='constraint'>" +
(key.blank? ? "" : "<span class='filterName'>#{key}:</span>") +
"<span class='filterValue'>#{value}</span></span>"
content_tag(:span, render_filter_name(key) + render_filter_value(value), :class => 'constraint')
end

def render_filter_name name
return "" if name.blank?
content_tag(:span, h(name) + ":", :class => 'filterName')
end

def render_filter_value value
content_tag(:span, h(value), :class => 'filterValue')
end

end
87 changes: 43 additions & 44 deletions app/models/record_mailer.rb
@@ -1,44 +1,43 @@
# Only works for documents with a #to_marc right now.
class RecordMailer < ActionMailer::Base


def email_record(documents, details, from_host, host)
#raise ArgumentError.new("RecordMailer#email_record only works with documents with a #to_marc") unless document.respond_to?(:to_marc)

recipients details[:to]
if documents.size == 1
subject = "Item Record: #{documents.first.to_marc['245']['a'] rescue 'N/A'}"
else
subject = "Item records"
end

@documents = documents
@message = details[:message]
@host = host

mail(:to => details[:to], :from => "no-reply@" << from_host, :subject => subject)

end

def sms_record(documents, details, from_host, host)
if sms_mapping[details[:carrier]]
to = "#{details[:to]}@#{sms_mapping[details[:carrier]]}"
end
@documents = documents
@host = host
mail(:to => to, :from => "no-reply@" << from_host, :subject => "")
end

protected

def sms_mapping
{'virgin' => 'vmobl.com',
'att' => 'txt.att.net',
'verizon' => 'vtext.com',
'nextel' => 'messaging.nextel.com',
'sprint' => 'messaging.sprintpcs.com',
'tmobile' => 'tmomail.net',
'alltel' => 'message.alltel.com',
'cricket' => 'mms.mycricket.com'}
end
end
# Only works for documents with a #to_marc right now.
class RecordMailer < ActionMailer::Base

def email_record(documents, details, from_host, url_gen_params)
#raise ArgumentError.new("RecordMailer#email_record only works with documents with a #to_marc") unless document.respond_to?(:to_marc)

recipients details[:to]
if documents.size == 1
subject = "Item Record: #{documents.first.to_marc['245']['a'] rescue 'N/A'}"
else
subject = "Item records"
end

@documents = documents
@message = details[:message]
@url_gen_params = url_gen_params

mail(:to => details[:to], :from => "no-reply@" << from_host, :subject => subject)
end

def sms_record(documents, details, from_host, url_gen_params)
if sms_mapping[details[:carrier]]
to = "#{details[:to]}@#{sms_mapping[details[:carrier]]}"
end
@documents = documents
@host = host
@url_gen_params = url_gen_params
mail(:to => to, :from => "no-reply@" << from_host, :subject => "")
end

protected

def sms_mapping
{'virgin' => 'vmobl.com',
'att' => 'txt.att.net',
'verizon' => 'vtext.com',
'nextel' => 'messaging.nextel.com',
'sprint' => 'messaging.sprintpcs.com',
'tmobile' => 'tmomail.net',
'alltel' => 'message.alltel.com',
'cricket' => 'mms.mycricket.com'}
end
end

0 comments on commit 755555a

Please sign in to comment.