blacklight-spotlight 0.25.0 → 0.26.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d68cf5423c8ab3b9eaefd0b0cbdccafaf2eaf8d4
4
- data.tar.gz: 5c81452e6aec254a83c977e1905edadc22142df6
3
+ metadata.gz: 7796437b15cb33ea287b007cfdc234f32dbf4ebb
4
+ data.tar.gz: 14073a32190fea37021fa92b517d12511f22c02b
5
5
  SHA512:
6
- metadata.gz: d0b21a7dd31dc34df83e91db7f2861d0c15260675348e98376b5cba29a67e441aba2319e72857ad51537068cbd0d5b67c1594c1b560a3bc6b143840f48d0530f
7
- data.tar.gz: 2a86b06e1ee71519050007e5e3b5cbd20f5d5ed3ab34b32acde37785486a56d6661e25bbafc915d775668d743a1a7da10ce2b48562acb9b0ace96d9447837e58
6
+ metadata.gz: 5e44725a667615c9270a471493e28d1e79c20d52b5606d66e57faf62a2ef276941f7afc86df470a0f946c816d5cecbcfb71c4619f15d7db1764023765da238e3
7
+ data.tar.gz: c0b91e1e8d835c5e96c444eab21c1d56be0e3755cb382d81683564d15214010f8ddc1452163dc6f1dfc7e560390de5d8ac868bad9adaf034633ebd180fad5de9
@@ -5,9 +5,9 @@ module Spotlight
5
5
  before_action :authenticate_user!, except: [:show]
6
6
 
7
7
  load_and_authorize_resource :exhibit, class: Spotlight::Exhibit
8
- before_action :build_resource, only: [:create]
9
8
 
10
- load_and_authorize_resource through: :exhibit
9
+ # explicit options support better subclassing
10
+ load_and_authorize_resource through: :exhibit, instance_name: :resource, through_association: :resources
11
11
 
12
12
  def new
13
13
  add_breadcrumb t(:'spotlight.exhibits.breadcrumb', title: @exhibit.title), exhibit_root_path(@exhibit)
@@ -20,11 +20,12 @@ module Spotlight
20
20
 
21
21
  def create
22
22
  if @resource.save_and_index
23
- redirect_to admin_exhibit_catalog_path(@resource.exhibit, sort: :timestamp)
23
+ redirect_to spotlight.admin_exhibit_catalog_path(@resource.exhibit, sort: :timestamp)
24
24
  else
25
25
  render action: 'new'
26
26
  end
27
27
  end
28
+ alias update create
28
29
 
29
30
  def monitor
30
31
  render json: current_exhibit.reindex_progress
@@ -38,12 +39,13 @@ module Spotlight
38
39
 
39
40
  protected
40
41
 
41
- def resource_params
42
- params.require(:resource).permit(:url, data: params[:resource][:data].try(:keys))
42
+ def resource_class
43
+ Spotlight::Resource
43
44
  end
44
45
 
45
- def build_resource
46
- @resource ||= @exhibit.resources.build(resource_params)
46
+ def resource_params
47
+ params.require(:resource).tap { |x| x['type'] ||= resource_class.name }
48
+ .permit(:url, :type, *resource_class.stored_attributes[:data], data: params[:resource][:data].try(:keys))
47
49
  end
48
50
  end
49
51
  end
@@ -3,6 +3,8 @@ module SirTrevorRails
3
3
  ##
4
4
  # Multi-up browse block
5
5
  class BrowseBlock < SirTrevorRails::Block
6
+ include Displayable
7
+
6
8
  attr_reader :solr_helper
7
9
 
8
10
  def with_solr_helper(solr_helper)
@@ -15,7 +17,7 @@ module SirTrevorRails
15
17
 
16
18
  def searches
17
19
  @searches ||= parent.exhibit.searches.published.where(slug: item_ids).sort do |a, b|
18
- order.index(a.slug) <=> order.index(b.slug)
20
+ ordered_items.index(a.slug) <=> ordered_items.index(b.slug)
19
21
  end
20
22
  end
21
23
 
@@ -23,27 +25,9 @@ module SirTrevorRails
23
25
  !searches.empty?
24
26
  end
25
27
 
26
- def item_ids
27
- items.map { |v| v[:id] }
28
- end
29
-
30
- def items
31
- item_values.select { |x| x[:display] == 'true' }
32
- end
33
-
34
- def order
35
- items.sort_by { |x| x[:weight] }.map { |x| x[:id] }
36
- end
37
-
38
28
  def display_item_counts?
39
29
  send(:'display-item-counts') == 'true'
40
30
  end
41
-
42
- private
43
-
44
- def item_values
45
- item.try(:values) || []
46
- end
47
31
  end
48
32
  end
49
33
  end
@@ -0,0 +1,25 @@
1
+ module SirTrevorRails
2
+ module Blocks
3
+ ##
4
+ # Mixin for blocks that display text
5
+ module Displayable
6
+ def items
7
+ item_values.select { |x| x[:display] == 'true' }
8
+ end
9
+
10
+ def item_ids
11
+ items.map { |v| v[:id] }
12
+ end
13
+
14
+ def ordered_items
15
+ items.sort_by { |x| x[:weight] }.map { |x| x[:id] }
16
+ end
17
+
18
+ private
19
+
20
+ def item_values
21
+ Array((item.values if item.present?))
22
+ end
23
+ end
24
+ end
25
+ end
@@ -3,31 +3,21 @@ module SirTrevorRails
3
3
  ##
4
4
  # Multi-up featured page block
5
5
  class FeaturedPagesBlock < SirTrevorRails::Block
6
+ include Displayable
7
+
6
8
  def page_options(id)
7
9
  (items.detect { |x| x[:id] == id }) || {}
8
10
  end
9
11
 
10
12
  def pages
11
13
  @pages ||= parent.exhibit.pages.published.where(slug: item_ids).sort do |a, b|
12
- order.index(a.slug) <=> order.index(b.slug)
14
+ ordered_items.index(a.slug) <=> ordered_items.index(b.slug)
13
15
  end
14
16
  end
15
17
 
16
18
  def pages?
17
19
  !pages.empty?
18
20
  end
19
-
20
- def item_ids
21
- items.map { |v| v[:id] }
22
- end
23
-
24
- def items
25
- item.values.select { |x| x[:display] == 'true' }
26
- end
27
-
28
- def order
29
- items.sort_by { |x| x[:weight] }.map { |x| x[:id] }
30
- end
31
21
  end
32
22
  end
33
23
  end
@@ -3,6 +3,8 @@ module SirTrevorRails
3
3
  ##
4
4
  # Embed search results (from a browse category) into the page
5
5
  class SearchResultsBlock < SirTrevorRails::Block
6
+ include Displayable
7
+
6
8
  def query_params
7
9
  if search
8
10
  search.query_params
@@ -16,20 +18,12 @@ module SirTrevorRails
16
18
  end
17
19
 
18
20
  def searches
19
- @searches ||= parent.exhibit.searches.published.where(slug: item_ids).sort { |a, b| order.index(a.id) <=> order.index(b.id) }
20
- end
21
-
22
- def item_ids
23
- items.map { |v| v[:id] }
21
+ @searches ||= parent.exhibit.searches.published.where(slug: item_ids).sort { |a, b| ordered_items.index(a.id) <=> ordered_items.index(b.id) }
24
22
  end
25
23
 
26
24
  def searches?
27
25
  !searches.empty?
28
26
  end
29
-
30
- def items
31
- item.values.select { |x| x[:display] == 'true' }
32
- end
33
27
  end
34
28
  end
35
29
  end
@@ -4,6 +4,7 @@ module SirTrevorRails
4
4
  # Multi-up document viewer with text block
5
5
  class SolrDocumentsBlock < SirTrevorRails::Block
6
6
  include Textable
7
+ include Displayable
7
8
  attr_reader :solr_helper
8
9
 
9
10
  def with_solr_helper(solr_helper)
@@ -31,10 +32,6 @@ module SirTrevorRails
31
32
  each_document.any?
32
33
  end
33
34
 
34
- def items
35
- (item || {}).values.select { |x| x[:display] == 'true' }
36
- end
37
-
38
35
  def primary_caption?
39
36
  primary_caption_field.present? && send(:'show-primary-caption')
40
37
  end
@@ -18,7 +18,7 @@ module Spotlight
18
18
  end
19
19
 
20
20
  def default_url
21
- ActionController::Base.helpers.asset_path('fallback/' + [version_name, 'default.png'].compact.join('_'))
21
+ ActionController::Base.helpers.image_path('spotlight/fallback/' + [version_name, 'default.png'].compact.join('_'))
22
22
  end
23
23
  end
24
24
  end
@@ -23,7 +23,7 @@ module Spotlight
23
23
  end
24
24
 
25
25
  def default_url
26
- ActionController::Base.helpers.asset_path('fallback/' + [version_name, 'default.png'].compact.join('_'))
26
+ ActionController::Base.helpers.image_path('spotlight/fallback/' + [version_name, 'default.png'].compact.join('_'))
27
27
  end
28
28
  end
29
29
  end
@@ -19,7 +19,7 @@ module Spotlight
19
19
  end
20
20
 
21
21
  def default_url
22
- ActionController::Base.helpers.asset_path('fallback/' + [version_name, 'default.png'].compact.join('_'))
22
+ ActionController::Base.helpers.image_path('spotlight/fallback/' + [version_name, 'default.png'].compact.join('_'))
23
23
  end
24
24
  end
25
25
  end
@@ -16,7 +16,7 @@ module Spotlight
16
16
  end
17
17
 
18
18
  def default_url
19
- ActionController::Base.helpers.asset_path('fallback/' + [version_name, 'default.png'].compact.join('_'))
19
+ ActionController::Base.helpers.image_path('spotlight/fallback/' + [version_name, 'default.png'].compact.join('_'))
20
20
  end
21
21
  end
22
22
  end
@@ -0,0 +1,9 @@
1
+ <%= bootstrap_form_for([current_exhibit, @resource]) do |f| %>
2
+ <%= f.text_field :url %>
3
+ <div class="form-actions">
4
+ <div class="primary-actions">
5
+ <%= cancel_link @resource, :back, class: 'btn btn-default' %>
6
+ <%= f.submit t('.add_item'), class: 'btn btn-primary' %>
7
+ </div>
8
+ </div>
9
+ <% end if can? :manage, @resource %>
@@ -506,6 +506,7 @@ en:
506
506
  form:
507
507
  needs_provider: "Could not find an appropriate importer"
508
508
  has_provider: "Ready to import"
509
+ add_item: "Add item"
509
510
  upload:
510
511
  csv:
511
512
  success: "'%{file_name}' has been uploaded. An email will be sent to you once indexing is complete."
@@ -0,0 +1,70 @@
1
+ require 'rails/generators'
2
+
3
+ # :nodoc:
4
+ module Spotlight
5
+ # spotlight:scaffold_resource generator
6
+ class ScaffoldResource < Rails::Generators::NamedBase
7
+ source_root File.expand_path('../templates', __FILE__)
8
+ def create_document_builder
9
+ create_file "app/services/#{file_name}_builder.rb", <<-FILE.strip_heredoc
10
+ class #{class_name}Builder < Spotlight::SolrDocumentBuilder
11
+ def to_solr
12
+ return to_enum(:to_solr) unless block_given?
13
+
14
+ # TODO: your implementation here
15
+ # yield { id: resource.id }
16
+ end
17
+ end
18
+ FILE
19
+ end
20
+
21
+ def create_model
22
+ create_file "app/models/#{file_name}_resource.rb", <<-FILE.strip_heredoc
23
+ class #{class_name}Resource < Spotlight::Resource
24
+ self.document_builder_class = #{class_name}Builder
25
+ end
26
+ FILE
27
+ end
28
+
29
+ def create_controller
30
+ create_file "app/controllers/#{file_name}_resources_controller.rb", <<-FILE.strip_heredoc
31
+ class #{class_name}ResourcesController < Spotlight::ResourcesController
32
+ private
33
+
34
+ def resource_class
35
+ #{class_name}Resource
36
+ end
37
+ end
38
+ FILE
39
+ end
40
+
41
+ def create_form
42
+ create_file "app/views/#{file_name}_resources/_form.html.erb", <<-FILE.strip_heredoc
43
+ <%= bootstrap_form_for([current_exhibit, @resource.becomes(#{class_name}Resource)], as: :resource) do |f| %>
44
+ <%= f.text_field :url %>
45
+ <div class="form-actions">
46
+ <div class="primary-actions">
47
+ <%= cancel_link @resource, :back, class: 'btn btn-default' %>
48
+ <%= f.submit t('.add_item'), class: 'btn btn-primary' %>
49
+ </div>
50
+ </div>
51
+ <% end if can? :manage, @resource %>
52
+ FILE
53
+ end
54
+ end
55
+
56
+ def inject_configuration
57
+ inject_into_file 'config/initializers/spotlight_initializer.rb' do
58
+ "\n Spotlight::Engine.config.external_resources_partials += ['#{file_name}_resources/form']\n"
59
+ end
60
+ end
61
+
62
+ def create_routes
63
+ route <<-FILE.strip_heredoc
64
+ resources :exhibits, only: [] do
65
+ resources :#{file_name}_resources, only: [:create, :update] do
66
+ end
67
+ end
68
+ FILE
69
+ end
70
+ end
@@ -34,6 +34,8 @@ module Spotlight
34
34
  require 'sir_trevor_rails'
35
35
  require 'openseadragon'
36
36
 
37
+ config.assets.precompile += %w(spotlight/fallback/*.png)
38
+
37
39
  config.autoload_paths += %W(
38
40
  #{config.root}/app/builders
39
41
  #{config.root}/app/controllers/concerns
@@ -1,3 +1,3 @@
1
1
  module Spotlight
2
- VERSION = '0.25.0'.freeze
2
+ VERSION = '0.26.0'.freeze
3
3
  end
@@ -0,0 +1,20 @@
1
+ describe SirTrevorRails::Blocks::FeaturedPagesBlock do
2
+ let(:page) { FactoryGirl.create(:feature_page) }
3
+ let(:block_data) { {} }
4
+ subject { described_class.new({ type: '', data: block_data }, page) }
5
+
6
+ describe '#items' do
7
+ it 'is the array of items with display set to true' do
8
+ block_data[:item] = {
9
+ '0': { id: 'abc123', display: 'true' },
10
+ '1': { id: 'xyz321', display: 'false' }
11
+ }
12
+ expect(subject.items.length).to eq 1
13
+ expect(subject.items).to eq([{ id: 'abc123', display: 'true' }])
14
+ end
15
+
16
+ it 'is an empty array when there is no browse category' do
17
+ expect(subject.items).to eq([])
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ describe SirTrevorRails::Blocks::SearchResultsBlock do
2
+ let(:page) { FactoryGirl.create(:feature_page) }
3
+ let(:block_data) { {} }
4
+ subject { described_class.new({ type: '', data: block_data }, page) }
5
+
6
+ describe '#items' do
7
+ it 'is the array of items with display set to true' do
8
+ block_data[:item] = {
9
+ '0': { id: 'abc123', display: 'true' },
10
+ '1': { id: 'xyz321', display: 'false' }
11
+ }
12
+ expect(subject.items.length).to eq 1
13
+ expect(subject.items).to eq([{ id: 'abc123', display: 'true' }])
14
+ end
15
+
16
+ it 'is an empty array when there is no browse category' do
17
+ expect(subject.items).to eq([])
18
+ end
19
+ end
20
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blacklight-spotlight
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.25.0
4
+ version: 0.26.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Beer
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2016-08-09 00:00:00.000000000 Z
14
+ date: 2016-08-12 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails
@@ -701,6 +701,7 @@ files:
701
701
  - Rakefile
702
702
  - app/assets/images/spotlight/blocks/sir-trevor-icons.svg
703
703
  - app/assets/images/spotlight/default_thumbnail.jpg
704
+ - app/assets/images/spotlight/fallback/default.png
704
705
  - app/assets/javascripts/spotlight/add_new_page_button.js
705
706
  - app/assets/javascripts/spotlight/appearance.js
706
707
  - app/assets/javascripts/spotlight/application.js
@@ -858,6 +859,7 @@ files:
858
859
  - app/models/concerns/spotlight/solr_document/uploaded_resource.rb
859
860
  - app/models/concerns/spotlight/user.rb
860
861
  - app/models/sir_trevor_rails/blocks/browse_block.rb
862
+ - app/models/sir_trevor_rails/blocks/displayable.rb
861
863
  - app/models/sir_trevor_rails/blocks/featured_pages_block.rb
862
864
  - app/models/sir_trevor_rails/blocks/oembed_block.rb
863
865
  - app/models/sir_trevor_rails/blocks/search_results_block.rb
@@ -1024,6 +1026,7 @@ files:
1024
1026
  - app/views/spotlight/pages/preview.html.erb
1025
1027
  - app/views/spotlight/pages/show.html.erb
1026
1028
  - app/views/spotlight/resources/_external_resources_form.html.erb
1029
+ - app/views/spotlight/resources/_form.html.erb
1027
1030
  - app/views/spotlight/resources/_missing_external_resources_partials.html.erb
1028
1031
  - app/views/spotlight/resources/csv_upload/_form.html.erb
1029
1032
  - app/views/spotlight/resources/json_upload/_form.html.erb
@@ -1120,6 +1123,7 @@ files:
1120
1123
  - db/migrate/20160711121314_add_default_view_to_spotlight_searches.rb
1121
1124
  - lib/blacklight/spotlight.rb
1122
1125
  - lib/generators/spotlight/install_generator.rb
1126
+ - lib/generators/spotlight/scaffold_resource_generator.rb
1123
1127
  - lib/generators/spotlight/templates/catalog_controller.rb
1124
1128
  - lib/generators/spotlight/templates/config/initializers/riiif.rb
1125
1129
  - lib/generators/spotlight/templates/config/initializers/spotlight_initializer.rb
@@ -1244,6 +1248,8 @@ files:
1244
1248
  - spec/lib/spotlight/controller_spec.rb
1245
1249
  - spec/mailers/spotlight/indexing_complete_mailer_spec.rb
1246
1250
  - spec/models/sir_trevor_rails/blocks/browse_block_spec.rb
1251
+ - spec/models/sir_trevor_rails/blocks/featured_pages_block_spec.rb
1252
+ - spec/models/sir_trevor_rails/blocks/search_results_block_spec.rb
1247
1253
  - spec/models/sir_trevor_rails/blocks/solr_documents_block_spec.rb
1248
1254
  - spec/models/sir_trevor_rails/blocks/textable_spec.rb
1249
1255
  - spec/models/solr_document_spec.rb
@@ -1512,6 +1518,8 @@ test_files:
1512
1518
  - spec/lib/spotlight/controller_spec.rb
1513
1519
  - spec/mailers/spotlight/indexing_complete_mailer_spec.rb
1514
1520
  - spec/models/sir_trevor_rails/blocks/browse_block_spec.rb
1521
+ - spec/models/sir_trevor_rails/blocks/featured_pages_block_spec.rb
1522
+ - spec/models/sir_trevor_rails/blocks/search_results_block_spec.rb
1515
1523
  - spec/models/sir_trevor_rails/blocks/solr_documents_block_spec.rb
1516
1524
  - spec/models/sir_trevor_rails/blocks/textable_spec.rb
1517
1525
  - spec/models/solr_document_spec.rb