atrium 0.0.1.alpha

Sign up to get free protection for your applications and to get access to all the features.
Files changed (212) hide show
  1. data/.gitignore +13 -0
  2. data/.gitmodules +3 -0
  3. data/.rvmrc +32 -0
  4. data/GETTING_STARTED.textile +109 -0
  5. data/Gemfile +4 -0
  6. data/Gemfile.lock +320 -0
  7. data/Guardfile +10 -0
  8. data/README.mkd +56 -0
  9. data/Rakefile +6 -0
  10. data/app/assets/images/atrium/ajax-loader.gif +0 -0
  11. data/app/assets/images/atrium/lightbox-ico-loading.gif +0 -0
  12. data/app/assets/images/atrium/logo.png +0 -0
  13. data/app/assets/javascripts/atrium/atrium.js +281 -0
  14. data/app/assets/javascripts/chosen.jquery.js +899 -0
  15. data/app/assets/javascripts/ckeditor.warning.js +65 -0
  16. data/app/assets/javascripts/ckeditor/config.js.coffee +6 -0
  17. data/app/assets/javascripts/ckeditor/jquery.generateId.js +13 -0
  18. data/app/assets/javascripts/ckeditor/jquery.jeditable.ckeditor.js +59 -0
  19. data/app/assets/javascripts/ckeditor/plugins/linkItem/application_link.png +0 -0
  20. data/app/assets/javascripts/ckeditor/plugins/linkItem/dialogs/linkItem.js +1470 -0
  21. data/app/assets/javascripts/ckeditor/plugins/linkItem/plugin.js +16 -0
  22. data/app/assets/javascripts/ckeditor/plugins/linkItem/ui_toolbar_pencil.png +0 -0
  23. data/app/assets/javascripts/jquery.colorbox.js +864 -0
  24. data/app/assets/javascripts/jquery.jeditable.js +543 -0
  25. data/app/assets/stylesheets/atrium/atrium.css +216 -0
  26. data/app/assets/stylesheets/atrium/chosen-sprite.png +0 -0
  27. data/app/assets/stylesheets/atrium/chosen.css +367 -0
  28. data/app/assets/stylesheets/colorbox.css +42 -0
  29. data/app/assets/stylesheets/controls.png +0 -0
  30. data/app/assets/stylesheets/loading.gif +0 -0
  31. data/app/controllers/atrium/base_controller.rb +25 -0
  32. data/app/controllers/atrium/collection_exhibit_order_controller.rb +21 -0
  33. data/app/controllers/atrium/collections_controller.rb +165 -0
  34. data/app/controllers/atrium/customization_controller.rb +41 -0
  35. data/app/controllers/atrium/descriptions_controller.rb +177 -0
  36. data/app/controllers/atrium/exhibit_facet_order_controller.rb +19 -0
  37. data/app/controllers/atrium/exhibits_controller.rb +108 -0
  38. data/app/controllers/atrium/showcases_controller.rb +193 -0
  39. data/app/helpers/atrium/base_helper.rb +6 -0
  40. data/app/models/ability.rb +14 -0
  41. data/app/models/atrium/browse_level.rb +41 -0
  42. data/app/models/atrium/collection.rb +121 -0
  43. data/app/models/atrium/description.rb +128 -0
  44. data/app/models/atrium/essay.rb +21 -0
  45. data/app/models/atrium/exhibit.rb +58 -0
  46. data/app/models/atrium/search/facet.rb +29 -0
  47. data/app/models/atrium/search/facet_selection.rb +17 -0
  48. data/app/models/atrium/showcase.rb +173 -0
  49. data/app/models/atrium/showcase/facet_selection.rb +21 -0
  50. data/app/models/atrium/showcase/item.rb +19 -0
  51. data/app/models/role_mapper.rb +23 -0
  52. data/app/views/_user_util_links.html.erb +25 -0
  53. data/app/views/atrium/collections/_bookmark_control.html.erb +25 -0
  54. data/app/views/atrium/collections/_browse_index.html.erb +20 -0
  55. data/app/views/atrium/collections/_collection_items_index.html.erb +10 -0
  56. data/app/views/atrium/collections/_document.html.erb +24 -0
  57. data/app/views/atrium/collections/_document_list.html.erb +6 -0
  58. data/app/views/atrium/collections/_edit_navigation.html.erb +20 -0
  59. data/app/views/atrium/collections/_folder_control.html.erb +12 -0
  60. data/app/views/atrium/collections/_form.html.erb +93 -0
  61. data/app/views/atrium/collections/_listing.html.erb +18 -0
  62. data/app/views/atrium/collections/_navigation.html.erb +45 -0
  63. data/app/views/atrium/collections/_results_pagination.html.erb +9 -0
  64. data/app/views/atrium/collections/_sort_and_per_page.html.erb +23 -0
  65. data/app/views/atrium/collections/edit.html.erb +5 -0
  66. data/app/views/atrium/collections/new.html.erb +6 -0
  67. data/app/views/atrium/collections/show.html.erb +22 -0
  68. data/app/views/atrium/descriptions/_form.html.erb +64 -0
  69. data/app/views/atrium/descriptions/edit.html.erb +4 -0
  70. data/app/views/atrium/descriptions/index.html.erb +4 -0
  71. data/app/views/atrium/descriptions/new.html.erb +2 -0
  72. data/app/views/atrium/descriptions/show.html.erb +20 -0
  73. data/app/views/atrium/exhibits/_bookmark_control.html.erb +25 -0
  74. data/app/views/atrium/exhibits/_folder_control.html.erb +12 -0
  75. data/app/views/atrium/exhibits/_form.html.erb +108 -0
  76. data/app/views/atrium/exhibits/edit.html.erb +9 -0
  77. data/app/views/atrium/exhibits/new.html.erb +6 -0
  78. data/app/views/atrium/exhibits/show.html.erb +26 -0
  79. data/app/views/atrium/showcases/_showcase_navigation.html.erb +23 -0
  80. data/app/views/atrium/showcases/show.html.erb +1 -0
  81. data/app/views/catalog/_collection_home_text.html.erb +6 -0
  82. data/app/views/catalog/_constraints.html.erb +9 -0
  83. data/app/views/catalog/_default_collection_text.html.erb +18 -0
  84. data/app/views/catalog/_default_home_text.html.erb +6 -0
  85. data/app/views/catalog/_home_text.html.erb +6 -0
  86. data/app/views/catalog/_index_partials/_description.html.erb +8 -0
  87. data/app/views/catalog/_search_form.html.erb +66 -0
  88. data/app/views/catalog/_show_partials/_description.html.erb +15 -0
  89. data/app/views/catalog/browse_show.html.erb +18 -0
  90. data/app/views/catalog/index.html.erb +35 -0
  91. data/app/views/catalog/list_description.html.erb +24 -0
  92. data/app/views/catalog/list_item.html.erb +3 -0
  93. data/app/views/layouts/atrium.html.erb +86 -0
  94. data/app/views/layouts/atrium_themes/default.html.erb +4 -0
  95. data/app/views/layouts/item_listing.html.erb +36 -0
  96. data/app/views/listing/_document.html.erb +27 -0
  97. data/app/views/listing/_document_list.html.erb +3 -0
  98. data/app/views/listing/_item_search.html.erb +27 -0
  99. data/app/views/shared/_banner.html.erb +5 -0
  100. data/app/views/shared/_collection_complete_list.html.erb +33 -0
  101. data/app/views/shared/_collection_search_form.html.erb +12 -0
  102. data/app/views/shared/_collection_title_header.html.erb +3 -0
  103. data/app/views/shared/_featured_sources.html.erb +20 -0
  104. data/app/views/shared/_list_descriptions.html.erb +38 -0
  105. data/app/views/shared/_navigation_browse_levels.html.erb +34 -0
  106. data/app/views/shared/_showcase_configure_menu.html.erb +22 -0
  107. data/app/views/shared/_top_navigation.html.erb +9 -0
  108. data/atrium.gemspec +76 -0
  109. data/config/routes.rb +12 -0
  110. data/init.rb +3 -0
  111. data/lib/application_controller.rb +24 -0
  112. data/lib/atrium.rb +42 -0
  113. data/lib/atrium/application_helper.rb +24 -0
  114. data/lib/atrium/atrium_helper_behavior.rb +162 -0
  115. data/lib/atrium/catalog.rb +203 -0
  116. data/lib/atrium/collections_helper.rb +139 -0
  117. data/lib/atrium/controller.rb +10 -0
  118. data/lib/atrium/descriptions_helper.rb +23 -0
  119. data/lib/atrium/engine.rb +12 -0
  120. data/lib/atrium/layout_helper.rb +13 -0
  121. data/lib/atrium/routes.rb +99 -0
  122. data/lib/atrium/solr_helper.rb +440 -0
  123. data/lib/atrium/version.rb +3 -0
  124. data/lib/generators/atrium/assets_generator.rb +44 -0
  125. data/lib/generators/atrium/atrium_generator.rb +149 -0
  126. data/lib/generators/atrium/cucumber_support_generator.rb +29 -0
  127. data/lib/generators/atrium/templates/config/role_map_cucumber.yml +2 -0
  128. data/lib/generators/atrium/templates/config/role_map_development.yml +2 -0
  129. data/lib/generators/atrium/templates/config/role_map_production.yml +2 -0
  130. data/lib/generators/atrium/templates/config/role_map_test.yml +2 -0
  131. data/lib/generators/atrium/templates/config/solr.yml +10 -0
  132. data/lib/generators/atrium/templates/db/seeds.rb +87 -0
  133. data/lib/generators/atrium/templates/migrations/create_atrium_browse_levels.rb +18 -0
  134. data/lib/generators/atrium/templates/migrations/create_atrium_collections.rb +20 -0
  135. data/lib/generators/atrium/templates/migrations/create_atrium_descriptions.rb +16 -0
  136. data/lib/generators/atrium/templates/migrations/create_atrium_essays.rb +15 -0
  137. data/lib/generators/atrium/templates/migrations/create_atrium_exhibits.rb +16 -0
  138. data/lib/generators/atrium/templates/migrations/create_atrium_search_facets.rb +14 -0
  139. data/lib/generators/atrium/templates/migrations/create_atrium_showcase_facet_selections.rb +15 -0
  140. data/lib/generators/atrium/templates/migrations/create_atrium_showcase_items.rb +17 -0
  141. data/lib/generators/atrium/templates/migrations/create_atrium_showcases.rb +16 -0
  142. data/lib/generators/atrium/templates/themes/example.html.erb +21 -0
  143. data/lib/railties/all_tests.rake +23 -0
  144. data/lib/railties/atrium_cucumber.rake +121 -0
  145. data/lib/railties/index.rake +37 -0
  146. data/tasks/atrium.rake +268 -0
  147. data/tasks/atrium_rspec.rake +91 -0
  148. data/test_support/etc/Gemfile +33 -0
  149. data/test_support/etc/bundle_config +3 -0
  150. data/test_support/etc/rvmrc +32 -0
  151. data/test_support/features/atrium_collections.feature +162 -0
  152. data/test_support/features/atrium_exhibits.feature +164 -0
  153. data/test_support/features/step_definitions/atrium_collection_steps.rb +102 -0
  154. data/test_support/features/step_definitions/atrium_exhibit_steps.rb +53 -0
  155. data/test_support/features/step_definitions/bookmarks_steps.rb +6 -0
  156. data/test_support/features/step_definitions/error_steps.rb +5 -0
  157. data/test_support/features/step_definitions/folder_steps.rb +27 -0
  158. data/test_support/features/step_definitions/general_steps.rb +50 -0
  159. data/test_support/features/step_definitions/record_view_steps.rb +12 -0
  160. data/test_support/features/step_definitions/saved_searches_steps.rb +22 -0
  161. data/test_support/features/step_definitions/search_facets_steps.rb +29 -0
  162. data/test_support/features/step_definitions/search_history_steps.rb +9 -0
  163. data/test_support/features/step_definitions/search_result_steps.rb +114 -0
  164. data/test_support/features/step_definitions/search_steps.rb +103 -0
  165. data/test_support/features/step_definitions/user_steps.rb +5 -0
  166. data/test_support/features/step_definitions/web_steps.rb +213 -0
  167. data/test_support/features/support/env.rb +67 -0
  168. data/test_support/features/support/paths.rb +76 -0
  169. data/test_support/features/support/selectors.rb +40 -0
  170. data/test_support/fixtures/atrium_exhibits.yml +3 -0
  171. data/test_support/spec/controllers/atrium/base_controller_spec.rb +13 -0
  172. data/test_support/spec/controllers/atrium/collection_exhibit_order_controller_spec.rb +29 -0
  173. data/test_support/spec/controllers/atrium/collections_controller_spec.rb +185 -0
  174. data/test_support/spec/controllers/atrium/customization_controller_spec.rb +38 -0
  175. data/test_support/spec/controllers/atrium/descriptions_controller_spec.rb +150 -0
  176. data/test_support/spec/controllers/atrium/exhibit_facet_order_controller_spec.rb +36 -0
  177. data/test_support/spec/controllers/atrium/exhibits_controller_spec.rb +192 -0
  178. data/test_support/spec/controllers/atrium/showcases_controller_spec.rb +185 -0
  179. data/test_support/spec/helpers/atrium_collections_helper_spec.rb +147 -0
  180. data/test_support/spec/helpers/atrium_description_helper_spec.rb +47 -0
  181. data/test_support/spec/helpers/atrium_solr_helper_spec.rb +512 -0
  182. data/test_support/spec/models/atrium/browse_level_spec.rb +31 -0
  183. data/test_support/spec/models/atrium/collection_spec.rb +30 -0
  184. data/test_support/spec/models/atrium/description_spec.rb +67 -0
  185. data/test_support/spec/models/atrium/essay_spec.rb +12 -0
  186. data/test_support/spec/models/atrium/exhibit_spec.rb +76 -0
  187. data/test_support/spec/models/atrium/search/facet_selection_spec.rb +24 -0
  188. data/test_support/spec/models/atrium/search/facet_spec.rb +11 -0
  189. data/test_support/spec/models/atrium/search_facet_spec.rb +54 -0
  190. data/test_support/spec/models/atrium/showcase/facet_selection_spec.rb +15 -0
  191. data/test_support/spec/models/atrium/showcase/item_spec.rb +12 -0
  192. data/test_support/spec/models/atrium/showcase_facet_selection_spec.rb +65 -0
  193. data/test_support/spec/models/atrium/showcase_spec.rb +134 -0
  194. data/test_support/spec/rcov.opts +3 -0
  195. data/test_support/spec/routing/atrium/collections_routing_spec.rb +33 -0
  196. data/test_support/spec/spec.opts +4 -0
  197. data/test_support/spec/spec_helper.rb +47 -0
  198. data/test_support/spec/support/be_accessible_matcher.rb +8 -0
  199. data/test_support/spec/support/be_routed_mixin.rb +7 -0
  200. data/test_support/tmp/step_definitions/catalog_index_steps.rb +14 -0
  201. data/test_support/tmp/step_definitions/edit_document_steps.rb +67 -0
  202. data/test_support/tmp/step_definitions/hydra_metadata_steps.rb +3 -0
  203. data/test_support/tmp/step_definitions/hydra_steps.rb +8 -0
  204. data/test_support/tmp/step_definitions/search_steps.rb +86 -0
  205. data/test_support/tmp/step_definitions/searching_steps.rb +22 -0
  206. data/test_support/tmp/step_definitions/select_steps.rb +8 -0
  207. data/test_support/tmp/step_definitions/show_document_steps.rb +73 -0
  208. data/test_support/tmp/step_definitions/user_steps.rb +15 -0
  209. data/test_support/tmp/step_definitions/web_steps.rb +273 -0
  210. data/test_support/tmp/support/env.rb +54 -0
  211. data/test_support/tmp/support/paths.rb +57 -0
  212. metadata +1047 -0
@@ -0,0 +1,128 @@
1
+ require 'sanitize'
2
+ class Atrium::Description < ActiveRecord::Base
3
+ self.table_name = 'atrium_descriptions'
4
+
5
+ belongs_to(
6
+ :showcase,
7
+ :class_name => 'Atrium::Showcase',
8
+ :foreign_key => 'atrium_showcase_id'
9
+ )
10
+
11
+ has_one(
12
+ :summary,
13
+ :class_name => 'Atrium::Essay',
14
+ :conditions => "\"atrium_essays\".content_type = \"summary\"",
15
+ :foreign_key => 'atrium_description_id',
16
+ :dependent => :destroy
17
+ )
18
+ accepts_nested_attributes_for :summary, :allow_destroy => true
19
+ def get_summary
20
+ essay.blank? ? "" : summary.content
21
+ end
22
+
23
+ has_one(
24
+ :essay,
25
+ :class_name => 'Atrium::Essay',
26
+ :conditions => "\"atrium_essays\".content_type = \"essay\"",
27
+ :foreign_key => 'atrium_description_id',
28
+ :dependent => :destroy
29
+ )
30
+ accepts_nested_attributes_for :essay, :allow_destroy => true
31
+ def get_essay
32
+ essay.blank? ? "" : essay.content
33
+ end
34
+
35
+
36
+ validates_presence_of :atrium_showcase_id
37
+
38
+ attr_accessible(
39
+ :description_solr_id,
40
+ :page_display,
41
+ :title,
42
+ :atrium_showcase_id,
43
+ :essay_attributes,
44
+ :summary_attributes
45
+ )
46
+
47
+ def self.get_description_from_solr_id(solr_id)
48
+ atrium_description=Atrium::Description.find_by_description_solr_id(solr_id.to_s)
49
+
50
+ if atrium_description
51
+ atrium_showcase=Atrium::Showcase.find(atrium_description.atrium_showcase_id)
52
+ return atrium_description , atrium_showcase
53
+ else
54
+ return []
55
+ end
56
+ end
57
+
58
+ def generate_solr_id
59
+ "atrium_description_#{id}"
60
+ end
61
+
62
+ def as_solr
63
+ doc= {
64
+ :active_fedora_model_s => "Description",
65
+ :page_display_s => (page_display unless page_display.blank?),
66
+ :id => generate_solr_id,
67
+ :format => "Description",
68
+ :title_t => pretty_title,
69
+ :title_s => pretty_title,
70
+ :summary_t => (summary_text unless summary.blank?),
71
+ :summary_s => (summary_text unless summary.blank?),
72
+ :description_content_t => (essay.content unless essay.blank?),
73
+ :description_content_s => (essay.content unless essay.blank?),
74
+ :description_content_no_html_t => (essay_text unless essay.blank?),
75
+ :atrium_showcase_id_t => get_atrium_showcase_id,
76
+ :atrium_showcase_id_display => get_atrium_showcase_id
77
+ }.reject{|key, value| value.blank?}
78
+ return doc
79
+ end
80
+
81
+ def to_solr
82
+ Blacklight.solr.add as_solr
83
+ end
84
+
85
+ def update_solr
86
+ if (description_solr_id.blank?)
87
+ to_solr
88
+ Blacklight.solr.commit
89
+ end
90
+ end
91
+
92
+ def summary_text
93
+ ::Sanitize.clean(summary.content).squish unless summary.blank?
94
+ end
95
+ private :summary_text
96
+
97
+ def essay_text
98
+ ::Sanitize.clean(essay.content).squish unless essay.blank?
99
+ end
100
+ private :essay_text
101
+
102
+ def remove_from_solr
103
+ if(description_solr_id.blank?)
104
+ Blacklight.solr.delete_by_id solr_id
105
+ Blacklight.solr.commit
106
+ end
107
+ end
108
+ private :remove_from_solr
109
+
110
+ def get_atrium_showcase_id
111
+ "atrium_showcase_#{id}"
112
+ end
113
+ private :get_atrium_showcase_id
114
+
115
+
116
+ def pretty_title
117
+ title.blank? ? "Description #{id}" : title
118
+ end
119
+
120
+ def show_on_this_page?
121
+ page_display.nil? || page_display == "newpage"
122
+ end
123
+
124
+ def blank?
125
+ title.blank? && essay.blank?
126
+ end
127
+
128
+ end
@@ -0,0 +1,21 @@
1
+ class Atrium::Essay < ActiveRecord::Base
2
+ self.table_name = 'atrium_essays'
3
+
4
+ belongs_to(
5
+ :description,
6
+ :class_name => 'Atrium::Description',
7
+ :foreign_key => 'atrium_description_id'
8
+ )
9
+
10
+ validates_presence_of :atrium_description_id
11
+
12
+ attr_accessible(
13
+ :content_type,
14
+ :content ,
15
+ :atrium_description_id
16
+ )
17
+
18
+ def blank?
19
+ content.blank?
20
+ end
21
+ end
@@ -0,0 +1,58 @@
1
+ class Atrium::Exhibit < ActiveRecord::Base
2
+ self.table_name = 'atrium_exhibits'
3
+
4
+ attr_accessible(
5
+ :atrium_collection_id,
6
+ :filter_query_params,
7
+ :label,
8
+ :set_number,
9
+ :browse_levels_attributes,
10
+ :showcases_attributes
11
+ )
12
+
13
+ belongs_to(
14
+ :collection,
15
+ :class_name => 'Atrium::Collection',
16
+ :foreign_key => 'atrium_collection_id'
17
+ )
18
+
19
+ has_many(
20
+ :showcases,
21
+ :class_name => 'Atrium::Showcase',
22
+ :as => :showcases
23
+ )
24
+ accepts_nested_attributes_for :showcases
25
+
26
+
27
+ has_many(
28
+ :browse_levels,
29
+ :class_name => 'Atrium::BrowseLevel',
30
+ :foreign_key => 'atrium_exhibit_id',
31
+ :order => 'level_number ASC'
32
+ )
33
+
34
+ accepts_nested_attributes_for :browse_levels, :allow_destroy => true
35
+ def browse_facet_names
36
+ browse_levels.collect {|facet| facet.solr_facet_name} rescue []
37
+ end
38
+
39
+ def facet_order
40
+ facet_order = {}
41
+ browse_levels.map{|facet| facet_order[facet[:id]] = facet.level_number }
42
+ facet_order
43
+ end
44
+
45
+ def facet_order=(facet_order = {})
46
+ valid_ids = browse_levels.select(:id).map{|facet| facet[:id]}
47
+ facet_order.each_pair do |id, order|
48
+ Atrium::BrowseLevel.find(id).update_attributes!(:level_number => order) if valid_ids.include?(id.to_i)
49
+ end
50
+ end
51
+
52
+
53
+ serialize :filter_query_params
54
+
55
+ def pretty_title
56
+ label.blank? ? "Exhibit #{set_number}" : label
57
+ end
58
+ end
@@ -0,0 +1,29 @@
1
+ class Atrium::Search::Facet < ActiveRecord::Base
2
+ self.table_name = 'atrium_search_facets'
3
+
4
+ belongs_to(
5
+ :collection,
6
+ :class_name => 'Atrium::Collection',
7
+ :foreign_key => 'atrium_collection_id'
8
+ )
9
+
10
+ scope :find_by_name_and_collection_id, lambda {|name, collection_id|
11
+ where("#{self.quoted_table_name}.`name` = ? AND #{self.quoted_table_name}.`atrium_collection_id` = ?", name, collection_id)
12
+ }
13
+
14
+ def self.find_or_create_by_name_and_collection_id(name, collection_id)
15
+ find_by_name_and_collection_id(name, collection_id).first ||
16
+ self.create(:name => name, :atrium_collection_id => id)
17
+ end
18
+
19
+ validates_presence_of(
20
+ :atrium_collection_id,
21
+ :name
22
+ )
23
+
24
+ attr_accessible(
25
+ :atrium_collection_id,
26
+ :name
27
+ )
28
+
29
+ end
@@ -0,0 +1,17 @@
1
+ require 'morphine'
2
+ class Atrium::Search::FacetSelection
3
+ attr_reader :field_name
4
+
5
+ def initialize(field_name)
6
+ @field_name = field_name
7
+ end
8
+
9
+ def label
10
+ @label ||= facet_configuration[:label]
11
+ end
12
+
13
+ include Morphine
14
+ register :facet_configuration do
15
+ CatalogController.blacklight_config.facet_fields[field_name] || {}
16
+ end
17
+ end
@@ -0,0 +1,173 @@
1
+ class Atrium::Showcase < ActiveRecord::Base
2
+ self.table_name = 'atrium_showcases'
3
+
4
+ # TODO: remove the need to expose the showcase_id to the AtriumShowcasesController
5
+ attr_accessible(
6
+ :showcases_id,
7
+ :showcases_type,
8
+ :showcase_items,
9
+ :solr_facet_name,
10
+ :value,
11
+ :descriptions_attributes,
12
+ :facet_selections_attributes,
13
+ :featured_items_attributes,
14
+ :related_items_attributes
15
+ )
16
+
17
+ has_many(
18
+ :descriptions,
19
+ :class_name => 'Atrium::Description',
20
+ :foreign_key => 'atrium_showcase_id',
21
+ :dependent => :destroy
22
+ )
23
+ accepts_nested_attributes_for(
24
+ :descriptions,
25
+ :allow_destroy => true
26
+ )
27
+
28
+ has_many(
29
+ :facet_selections,
30
+ :class_name => 'Atrium::Showcase::FacetSelection',
31
+ :foreign_key => 'atrium_showcase_id',
32
+ :dependent => :destroy
33
+ )
34
+ accepts_nested_attributes_for :facet_selections
35
+
36
+ def get_parent_path
37
+ if for_exhibit?
38
+ facet={}
39
+ unless facet_selections.blank?
40
+ facet[facet_selections.first.solr_facet_name]=facet_selections.first.value
41
+ end
42
+ path= Rails.application.routes.url_helpers.atrium_exhibit_path(parent, :f=>facet)
43
+ return path
44
+ else
45
+ return parent
46
+ end
47
+ end
48
+
49
+ has_many(
50
+ :featured_items,
51
+ :class_name => 'Atrium::Showcase::Item::Featured',
52
+ :foreign_key => 'atrium_showcase_id',
53
+ :dependent => :destroy
54
+ )
55
+ accepts_nested_attributes_for(
56
+ :featured_items,
57
+ :allow_destroy => true
58
+ )
59
+
60
+ has_many(
61
+ :related_items,
62
+ :class_name => 'Atrium::Showcase::Item::Related',
63
+ :foreign_key => 'atrium_showcase_id',
64
+ :dependent => :destroy
65
+ )
66
+ accepts_nested_attributes_for(
67
+ :related_items,
68
+ :allow_destroy => true
69
+ )
70
+
71
+ belongs_to(
72
+ :showcases,
73
+ :polymorphic => true
74
+ )
75
+
76
+ serialize :showcase_items, Hash
77
+
78
+ def showcase_items
79
+ read_attribute(:showcase_items) || write_attribute(:showcase_items, {})
80
+ end
81
+
82
+ def solr_doc_ids
83
+ showcase_items[:solr_doc_ids] unless showcase_items.blank?
84
+ end
85
+
86
+ def type
87
+ showcase_items[:type] unless showcase_items.blank?
88
+ end
89
+
90
+ def parent
91
+ # debugger;true
92
+ if showcases_type && showcases_id
93
+ begin
94
+ showcases_type.constantize.find(showcases_id)
95
+ rescue
96
+ logger.error("Invalid showcase parent type set for showcase id: #{id}")
97
+ nil
98
+ end
99
+ end
100
+ end
101
+
102
+ def parent_title
103
+ parent.pretty_title
104
+ end
105
+
106
+ def for_exhibit?
107
+ showcases_type == "Atrium::Exhibit"
108
+ end
109
+
110
+ # This method will select showcase objects that have exactly the selected facets passed in (but no more or no less) and is tied to the given exhibit id
111
+ # It expects two parameters:
112
+ # @param[String] the exhibit id
113
+ # @param[Hash] hash of key value pairs of selected facets
114
+ # @return Array of showcase objects found
115
+ scope :with_selected_facets, lambda {|*args|
116
+ parent_id, parent_type, selected_facets = args.flatten(1)
117
+
118
+ selected_facets =
119
+ if parent_type.eql?("Atrium::Collection")
120
+ {}
121
+ else
122
+ selected_facets
123
+ end
124
+ facet_condition_values = []
125
+ facet_conditions =
126
+ if selected_facets
127
+ selected_facets.collect {|key,value|
128
+ facet_condition_values << key
129
+ facet_condition_values << (value.is_a?(String) ? value : value.flatten.compact.to_s)
130
+
131
+ %((
132
+ #{Atrium::Showcase::FacetSelection.quoted_table_name}.`solr_facet_name` = ?
133
+ AND #{Atrium::Showcase::FacetSelection.quoted_table_name}.`value` = ?
134
+ ))
135
+ }
136
+ else
137
+ []
138
+ end
139
+
140
+ if facet_conditions.empty?
141
+ joins(%(
142
+ LEFT OUTER JOIN #{Atrium::Showcase::FacetSelection.quoted_table_name}
143
+ ON #{quoted_table_name}.`id` = #{Atrium::Showcase::FacetSelection.quoted_table_name}.`atrium_showcase_id`)
144
+ ).
145
+ where(:showcases_id => parent_id,:showcases_type => parent_type).
146
+ where("#{Atrium::Showcase::FacetSelection.quoted_table_name}.`id` is NULL")
147
+ else
148
+ # unfortunately have to do subselect here to get this correct
149
+ conditions = [%(
150
+ #{Atrium::Showcase::FacetSelection.quoted_table_name}.`atrium_showcase_id`
151
+ IN (
152
+ SELECT #{Atrium::Showcase::FacetSelection.quoted_table_name}.`atrium_showcase_id`
153
+ FROM #{Atrium::Showcase::FacetSelection.quoted_table_name}
154
+ INNER JOIN #{quoted_table_name}
155
+ ON #{Atrium::Showcase::FacetSelection.quoted_table_name}.`atrium_showcase_id` = #{quoted_table_name}.`id`
156
+ WHERE #{quoted_table_name}.showcases_id = ?
157
+ AND #{quoted_table_name}.`showcases_type` = ?
158
+ AND (#{facet_conditions.join(" OR ")})
159
+ )
160
+ ), parent_id, parent_type] + facet_condition_values
161
+
162
+ having_str = %(
163
+ COUNT(#{Atrium::Showcase::FacetSelection.quoted_table_name}.`atrium_showcase_id`) = #{facet_conditions.size}
164
+ )
165
+
166
+ joins(:facet_selections).
167
+ where(conditions).
168
+ group("#{Atrium::Showcase::FacetSelection.quoted_table_name}.`atrium_showcase_id`").
169
+ having(having_str)
170
+ end
171
+ }
172
+
173
+ end
@@ -0,0 +1,21 @@
1
+ class Atrium::Showcase::FacetSelection < ActiveRecord::Base
2
+ self.table_name = 'atrium_showcase_facet_selections'
3
+
4
+ belongs_to(
5
+ :showcase,
6
+ :class_name => 'Atrium::Showcase',
7
+ :foreign_key => 'atrium_showcase_id'
8
+ )
9
+
10
+ validates_presence_of(
11
+ :atrium_showcase_id,
12
+ :value,
13
+ :solr_facet_name
14
+ )
15
+
16
+ attr_accessible(
17
+ :atrium_showcase_id,
18
+ :solr_facet_name,
19
+ :value
20
+ )
21
+ end