worthwhile 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 51148dfa82366649166775f5fa61af807bddc4e6
4
- data.tar.gz: 9719ed8f1dfe0a007814ae0fafbd799dc95fda61
3
+ metadata.gz: 2f92a3d35183f9fecc6d40669f3947b604746570
4
+ data.tar.gz: 9f11fc3e4e3df7ccdea248f3bd77393590a9487b
5
5
  SHA512:
6
- metadata.gz: a60c1ae8730ea3828fd0ca18acb9076e9fd128e9e6c10d426c02f1c778d3d36e0b238c17242356a99c0f60dc1aa9235aac967b6cd3ddbd24e1d3a76ec6bbecc2
7
- data.tar.gz: 4f7cdd14bac47eeb3716473fd6ecccafa8d03962ba4f1643b41d7d24684a066817348b62c361a50fd73e3a07f22f19ead5f5d6965834d7d45cb8b00c365dd16e
6
+ metadata.gz: 553879425a72f231b43b5ffe8410fba8d65d2b11dee4a576f42ffc9bebe8693249d097eec384fe4d65d8c0b2c6537645ec89c2afdd5fb7882caa46f7105f3875
7
+ data.tar.gz: 33cb788b8e54d4c743588047bc9ceeab335d16c2a88d2f9c74320f0bc5303591ee5a457b203f4f3191c0be8f21fc89ce3b700d649950960396d3a54ae1df9b56
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -26,7 +26,7 @@ module Worthwhile::GenericWorkRdfProperties
26
26
  index.as :stored_searchable, :facetable
27
27
  end
28
28
  property :created, predicate: RDF::DC.created
29
-
29
+
30
30
  property :date, predicate: RDF::DC.date do |index|
31
31
  index.type :date
32
32
  index.as :stored_sortable
@@ -7,27 +7,4 @@ module Curate::CollectionsHelper
7
7
  }
8
8
  end
9
9
 
10
- def available_collections(item = nil)
11
- if item.present?
12
- collection_options.reject {|n| n == item}
13
- else
14
- collection_options
15
- end
16
- end
17
-
18
- private
19
-
20
- def collection_options
21
- @collection_options ||= current_users_collections
22
- end
23
-
24
- # Defaults to returning a list of all collections.
25
- # If you have implement User.collections, the results of that will be used.
26
- def current_users_collections
27
- if current_user.respond_to?(:collections)
28
- current_user.collections.to_a
29
- else
30
- Collection.all
31
- end
32
- end
33
10
  end
@@ -27,4 +27,37 @@ module Worthwhile::CollectionsHelper
27
27
  content_tag :span, '', class: "glyphicon glyphicon-#{type}"
28
28
  end
29
29
 
30
+ def collection_options_for_select(exclude_item = nil)
31
+ options_for_select(available_collections(exclude_item))
32
+ end
33
+
34
+ private
35
+ # return a list of collections for the current user with the exception of the passed in collection
36
+ def available_collections(exclude_item)
37
+ if exclude_item
38
+ collection_options.reject {|n| n.last == exclude_item.id}
39
+ else
40
+ collection_options
41
+ end
42
+ end
43
+
44
+
45
+ def collection_options
46
+ @collection_options ||= current_users_collections
47
+ end
48
+
49
+ # Defaults to returning a list of all collections.
50
+ # If you have implement User.collections, the results of that will be used.
51
+ def current_users_collections
52
+ if current_user.respond_to?(:collections)
53
+ current_user.collections.map { |c| [c.title.join(', '), c.id] }
54
+ else
55
+ query = ActiveFedora::SolrService.construct_query_for_rel(has_model: Collection.to_class_uri)
56
+ ActiveFedora::SolrService.query(query, fl: 'desc_metadata__title_tesim id',
57
+ rows: 1000).map do |r|
58
+ [r['desc_metadata__title_tesim'].join(', '), r['id']]
59
+ end.sort { |a, b| a.first <=> b.first }
60
+ end
61
+ end
62
+
30
63
  end
@@ -8,14 +8,8 @@
8
8
 
9
9
  <div class="form-group collection_id">
10
10
  <div class="controls">
11
- <% options = "" %>
12
- <% collections = available_collections(collectible) %>
13
- <% if collections.any? -%>
14
- <% options << '<optgroup label="Your Collections">'.html_safe %>
15
- <% options << options_from_collection_for_select(collections, "pid", "title") %>
16
- <% options << '</optgroup>'.html_safe %>
17
- <% end %>
18
- <%= select_tag :id, options, prompt: 'Make a Selection', class: 'form-control', :'aria-labelledby' => select_label_id %>
11
+ <%= select_tag :id, collection_options_for_select(collectible), prompt: 'Make a Selection',
12
+ class: 'form-control', :'aria-labelledby' => select_label_id %>
19
13
  </div>
20
14
  </div>
21
15
 
@@ -1,3 +1,3 @@
1
1
  module Worthwhile
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -16,4 +16,18 @@ describe Worthwhile::CollectionsHelper do
16
16
  batch_document_ids: [ '456' ])
17
17
  end
18
18
  end
19
+
20
+ describe "#collection_options_for_select" do
21
+ before do
22
+ allow(helper).to receive(:current_user).and_return(User.new)
23
+ end
24
+ let!(:collection1) { Collection.create!(pid: 'test:123', title: 'One') }
25
+ let!(:collection2) { Collection.create!(pid: 'test:456', title: 'Two') }
26
+ let!(:collection3) { Collection.create!(pid: 'test:789', title: 'Thre') }
27
+ subject { helper.collection_options_for_select(collection2) }
28
+
29
+ it "should exclude the passed in collection" do
30
+ expect(subject).to eq "<option value=\"#{collection1.id}\">#{collection1.title}</option>\n<option value=\"#{collection3.id}\">#{collection3.title}</option>"
31
+ end
32
+ end
19
33
  end
@@ -12,7 +12,7 @@ module Worthwhile
12
12
  include Sufia::GenericFile::Metadata
13
13
  include Sufia::GenericFile::Versions
14
14
  include Sufia::Permissions::Readable
15
- include CurationConcern::VersionedContent
15
+ include ::CurationConcern::VersionedContent
16
16
 
17
17
  included do
18
18
  belongs_to :batch, property: :is_part_of, class_name: 'ActiveFedora::Base'
@@ -27,8 +27,10 @@ module Worthwhile
27
27
  # @example
28
28
  # link_to '...', SolrDocument(:id => 'bXXXXXX5').new => <a href="/dams_object/bXXXXXX5">...</a>
29
29
  def to_model
30
- m = ActiveFedora::Base.load_instance_from_solr(id, self)
31
- m.class == ActiveFedora::Base ? self : m
30
+ @model ||= begin
31
+ m = ActiveFedora::Base.load_instance_from_solr(id, self)
32
+ m.class == ActiveFedora::Base ? self : m
33
+ end
32
34
  end
33
35
 
34
36
  def collection?
@@ -48,7 +50,7 @@ module Worthwhile
48
50
  Array(self[Solrizer.solr_name('human_readable_type', :stored_searchable)]).first
49
51
  end
50
52
 
51
- def representative
53
+ def representative
52
54
  Array(self[Solrizer.solr_name('representative', :stored_searchable)]).first
53
55
  end
54
56
 
@@ -1,5 +1,5 @@
1
1
  module Worthwhile
2
2
  module Models
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: worthwhile
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Coyne
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-09 00:00:00.000000000 Z
11
+ date: 2014-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hydra-head
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - '='
74
74
  - !ruby/object:Gem::Version
75
- version: 0.1.1
75
+ version: 0.1.2
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - '='
81
81
  - !ruby/object:Gem::Version
82
- version: 0.1.1
82
+ version: 0.1.2
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: sufia-models
85
85
  requirement: !ruby/object:Gem::Requirement