Module: Atrium::CollectionsHelper
- Included in:
- BaseController
- Defined in:
- lib/atrium/collections_helper.rb
Instance Method Summary collapse
- #add_browse_facet_params(field, value, p = HashWithIndifferentAccess.new) ⇒ Object
-
#browse_collection_link ⇒ String
Return the link to browse an collection.
- #can_add_view_exhibit? ⇒ Boolean
-
#edit_collection_link(css_class = nil) ⇒ String
Return the link to edit an collection.
- #exhibit_scoped_to_items?(exhibit_id) ⇒ Boolean
-
#get_browse_facet_path(facet_solr_field, value, browse_facets, exhibit_number, exhibit_id, opts = {}) ⇒ Object
Standard display of a facet value in a list.
-
#get_collection_id ⇒ String
Returns the current collection id in the parameters.
- #get_collections_list ⇒ Object
- #get_customize_page_path ⇒ Object
- #get_exhibit_set_number(exhibit_id) ⇒ Object
-
#get_selected_browse_facet_path(facet_solr_field, value, browse_facets, exhibit_number, exhibit_id, opts = {}) ⇒ Object
Standard display of a SELECTED facet value, no link, special span with class, and ‘remove’ button.
- #get_selected_browse_facets(browse_facets) ⇒ Object
- #get_solr_documents_from_asset(asset) ⇒ Object
- #grouped_result_count(response, facet_name = nil, facet_value = nil) ⇒ Object
-
#remove_related_facet_params(solr_facet_field, p, browse_facets, exhibit_number) ⇒ Object
Remove current selected facet plus any child facets selected.
Instance Method Details
#add_browse_facet_params(field, value, p = HashWithIndifferentAccess.new) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/atrium/collections_helper.rb', line 31 def add_browse_facet_params(field, value, p=HashWithIndifferentAccess.new) p[:f]||={} p[:f][field] ||= [] p[:f][field].push(value) p end |
#browse_collection_link ⇒ String
Return the link to browse an collection
108 109 110 |
# File 'lib/atrium/collections_helper.rb', line 108 def browse_collection_link atrium_collection_path(get_collection_id) end |
#can_add_view_exhibit? ⇒ Boolean
138 139 140 141 |
# File 'lib/atrium/collections_helper.rb', line 138 def can_add_view_exhibit? collection= @atrium_collection? @atrium_collection : Atrium::Collection.find(params[:id]) return !(collection && collection.filter_query_params && collection.filter_query_params[:solr_doc_ids]) end |
#edit_collection_link(css_class = nil) ⇒ String
Return the link to edit an collection
123 124 125 |
# File 'lib/atrium/collections_helper.rb', line 123 def edit_collection_link(css_class=nil) edit_atrium_collection_path(get_collection_id, :class => css_class, :render_search=>"false") end |
#exhibit_scoped_to_items?(exhibit_id) ⇒ Boolean
143 144 145 146 |
# File 'lib/atrium/collections_helper.rb', line 143 def exhibit_scoped_to_items?(exhibit_id) exhibit=Atrium::Exhibit.find(exhibit_id) return exhibit && exhibit.filter_query_params && exhibit.filter_query_params[:solr_doc_ids] end |
#get_browse_facet_path(facet_solr_field, value, browse_facets, exhibit_number, exhibit_id, opts = {}) ⇒ Object
Standard display of a facet value in a list. Used in both _facets sidebar partial and catalog/facet expanded list. Will output facet value name as a link to add that to your restrictions, with count in parens. first arg item is a facet value item from rsolr-ext. options consist of: :suppress_link => true # do not make it a link, used for an already selected value for instance
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/atrium/collections_helper.rb', line 9 def get_browse_facet_path(facet_solr_field, value, browse_facets, exhibit_number, exhibit_id, opts={}) p = HashWithIndifferentAccess.new p.merge!(:f=>params[:f].dup) if params[:f] if params[:collection_id] #p.merge!(:id=>params[:collection_id]) p.merge!(:collection_id=>params[:collection_id]) elsif params[:id] && params[:controller] == "atrium_collections" #p.merge!(:id=>params[:id]) p.merge!(:collection_id=>params[:id]) #p.merge!(:controller=>params[:controller]) end #if params[:edit_showcase] # p.merge!(:edit_showcase=>true) #end p.merge!(:id=>exhibit_id) p = (facet_solr_field, p, browse_facets, exhibit_number) p = add_browse_facet_params(facet_solr_field,value,p) #it should only return a path for current facet selection plus parent selected values so if generating for multiple levels, than need to ignore some potentially #params[:action] == "edit" ? edit_atrium_collection_path(p.merge!({:class=>"browse_facet_select"})) : atrium_collection_path(p.merge!({:class=>"browse_facet_select"})) atrium_exhibit_path(p.merge!({:class=>"browse_facet_select"})) end |
#get_collection_id ⇒ String
116 117 118 |
# File 'lib/atrium/collections_helper.rb', line 116 def get_collection_id params[:controller] == "atrium_collections" ? params[:id] : params[:collection_id] end |
#get_collections_list ⇒ Object
102 103 104 |
# File 'lib/atrium/collections_helper.rb', line 102 def get_collections_list Atrium::Collection.find(:all) end |
#get_customize_page_path ⇒ Object
127 128 129 130 131 132 133 134 135 136 |
# File 'lib/atrium/collections_helper.rb', line 127 def get_customize_page_path if params[:controller] == "atrium/exhibits" exhibit=Atrium::Exhibit.find(params[:id]) path = new_atrium_exhibit_showcases_path(exhibit, :facet_selection => params[:f]) elsif params[:controller] == "atrium/collections" collection=Atrium::Collection.find(params[:id]) path= new_atrium_collection_showcases_path(collection) end return path end |
#get_exhibit_set_number(exhibit_id) ⇒ Object
38 39 40 |
# File 'lib/atrium/collections_helper.rb', line 38 def get_exhibit_set_number(exhibit_id) Atrium::Exhibit.find(exhibit_id).set_number end |
#get_selected_browse_facet_path(facet_solr_field, value, browse_facets, exhibit_number, exhibit_id, opts = {}) ⇒ Object
Standard display of a SELECTED facet value, no link, special span with class, and ‘remove’ button.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/atrium/collections_helper.rb', line 44 def get_selected_browse_facet_path(facet_solr_field, value, browse_facets, exhibit_number, exhibit_id, opts={}) value = [value] unless value.is_a? Array p = HashWithIndifferentAccess.new p.merge!(:f=>params[:f].dup) if params[:f] p = (facet_solr_field, p, browse_facets, exhibit_number) if params[:collection_id] p.merge!(:id=>params[:collection_id]) p.merge!(:collection_id=>params[:collection_id]) elsif params[:id] && params[:controller] == "atrium_collections" p.merge!(:id=>params[:id]) p.merge!(:collection_id=>params[:id]) p.merge!(:controller=>params[:controller]) end #if params[:edit_showcase] # p.merge!(:edit_showcase=>true) #end p.merge!(:id=>exhibit_id) # params[:action] == "edit" ? edit_atrium_collection_path(p) : atrium_collection_path(p) atrium_exhibit_path(p) end |
#get_selected_browse_facets(browse_facets) ⇒ Object
81 82 83 84 85 86 87 88 89 |
# File 'lib/atrium/collections_helper.rb', line 81 def get_selected_browse_facets(browse_facets) selected = {} if params[:f] browse_facets.each do |facet| selected.merge!({facet.to_sym=>params[:f][facet].first}) if params[:f][facet] end end selected end |
#get_solr_documents_from_asset(asset) ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/atrium/collections_helper.rb', line 148 def get_solr_documents_from_asset(asset) p = params.dup params.delete :f params.delete :q params.delete :page logger.debug("Asset is: #{asset.class}") if asset.is_a?(Atrium::Showcase) if asset && !asset.showcase_items[:solr_doc_ids].nil? selected_document_ids = @atrium_showcase.showcase_items[:solr_doc_ids].split(',') response, documents = get_solr_response_for_field_values("id",selected_document_ids || []) end else if asset && asset.filter_query_params && asset.filter_query_params[:solr_doc_ids] document_ids = asset.filter_query_params[:solr_doc_ids].split(',') response, documents = get_solr_response_for_field_values("id",document_ids || []) end end params.merge!(:f=>p[:f]) params.merge!(:q=>p[:q]) params.merge!(:page=>p[:page]) return [response, documents] end |
#grouped_result_count(response, facet_name = nil, facet_value = nil) ⇒ Object
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/atrium/collections_helper.rb', line 91 def grouped_result_count(response, facet_name=nil, facet_value=nil) if facet_name && facet_value facet = response.facets.detect {|f| f.name == facet_name} facet_item = facet.items.detect {|i| i.value == facet_value} if facet count = facet_item ? facet_item.hits : 0 else count = response.docs.total end pluralize(count, 'document') end |
#remove_related_facet_params(solr_facet_field, p, browse_facets, exhibit_number) ⇒ Object
Remove current selected facet plus any child facets selected
66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/atrium/collections_helper.rb', line 66 def (solr_facet_field, p, browse_facets, exhibit_number) if params[:exhibit_number] && params[:exhibit_number].to_i != exhibit_number.to_i p.delete(:f) if p[:f] elsif browse_facets.include?(solr_facet_field) #iterate through browseable facets from current on down index = browse_facets.index(solr_facet_field) if p[:f] browse_facets.slice(index, browse_facets.length - index).each do |f| p[:f].delete(f) end end end p end |