blacklight 5.3.0 → 5.4.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -1
- data/VERSION +1 -1
- data/app/assets/javascripts/blacklight/blacklight.js +1 -0
- data/app/assets/javascripts/blacklight/collapsable.js +9 -0
- data/app/controllers/bookmarks_controller.rb +72 -9
- data/app/helpers/blacklight/blacklight_helper_behavior.rb +15 -7
- data/app/helpers/blacklight/catalog_helper_behavior.rb +17 -9
- data/app/helpers/blacklight/configuration_helper_behavior.rb +59 -7
- data/app/helpers/blacklight/facets_helper_behavior.rb +1 -16
- data/app/helpers/blacklight/url_helper_behavior.rb +21 -2
- data/app/models/bookmark.rb +13 -4
- data/app/models/solr_document.rb +5 -0
- data/app/views/bookmarks/_tools.html.erb +10 -11
- data/app/views/catalog/_bookmark_control.html.erb +2 -2
- data/app/views/catalog/_refworks_form.html.erb +3 -2
- data/app/views/catalog/_sort_widget.html.erb +5 -5
- data/app/views/catalog/_view_type_group.html.erb +2 -2
- data/app/views/shared/_header_navbar.html.erb +1 -3
- data/config/locales/blacklight.pt-BR.yml +223 -0
- data/db/migrate/20140320000000_add_polymorphic_type_to_bookmarks.rb +8 -0
- data/gemfiles/rails4.1.gemfile +1 -1
- data/lib/blacklight.rb +5 -0
- data/lib/blacklight/catalog.rb +33 -5
- data/lib/blacklight/configuration.rb +12 -3
- data/lib/blacklight/configuration/facet_field.rb +1 -1
- data/lib/blacklight/configuration/search_field.rb +3 -2
- data/lib/blacklight/configuration/solr_field.rb +2 -1
- data/lib/blacklight/configuration/sort_field.rb +2 -1
- data/lib/blacklight/engine.rb +9 -1
- data/lib/blacklight/exceptions.rb +3 -0
- data/lib/blacklight/rails/routes.rb +12 -0
- data/lib/blacklight/request_builders.rb +19 -18
- data/lib/blacklight/search_fields.rb +0 -9
- data/lib/blacklight/solr/document.rb +15 -0
- data/lib/blacklight/solr/document/export.rb +4 -0
- data/lib/blacklight/solr_helper.rb +25 -28
- data/lib/blacklight/solr_response.rb +31 -29
- data/lib/blacklight/solr_response/response.rb +18 -0
- data/lib/blacklight/user.rb +17 -4
- data/lib/blacklight/utils.rb +30 -2
- data/lib/generators/blacklight/install_generator.rb +4 -0
- data/lib/generators/blacklight/templates/config/initializers/blacklight_initializer.rb +9 -0
- data/spec/controllers/application_controller_spec.rb +0 -1
- data/spec/controllers/bookmarks_controller_spec.rb +8 -4
- data/spec/controllers/catalog_controller_spec.rb +48 -55
- data/spec/controllers/saved_searches_controller_spec.rb +1 -4
- data/spec/controllers/search_history_controller_spec.rb +0 -1
- data/spec/features/bookmarks_spec.rb +14 -0
- data/spec/features/search_formats_spec.rb +45 -0
- data/spec/helpers/blacklight_helper_spec.rb +71 -30
- data/spec/helpers/configuration_helper_spec.rb +128 -4
- data/spec/helpers/facets_helper_spec.rb +1 -1
- data/spec/lib/blacklight/configuration_spec.rb +0 -5
- data/spec/lib/blacklight/search_fields_spec.rb +0 -22
- data/spec/lib/blacklight/solr/document_spec.rb +6 -0
- data/spec/lib/blacklight/solr_helper_spec.rb +31 -10
- data/spec/lib/blacklight/solr_response_spec.rb +8 -0
- data/spec/lib/blacklight/user_spec.rb +38 -4
- data/spec/models/bookmark_spec.rb +22 -17
- data/spec/spec_helper.rb +2 -0
- data/template.demo.rb +4 -9
- metadata +12 -6
- data/spec/data/sample_docs.yml +0 -655
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 540546b2abe3b14b82ac1bf0bc9c079db212a291
|
4
|
+
data.tar.gz: 7fa2ffa45e80e88b3d02a744124b94be1f7b64a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a06c30a6d5e7b2bb8686ed8f80a8bad01e237b9bf52d6af2fb63c546c15a631e4b8f77c033afffcd231499101d404369d8eda26c2ed58f18f02b8e490c4884d4
|
7
|
+
data.tar.gz: b47793969ac19bd39fc851cd1ade641be5b97c84ecc2bdbc34a0412ca628150833c2d50dda1f093ba4e8d331543c46fb5ca6e5b5d5978a38d79610177b5ce26a
|
data/Gemfile
CHANGED
@@ -4,7 +4,9 @@ source 'https://rubygems.org'
|
|
4
4
|
gemspec path: File.expand_path('..', __FILE__)
|
5
5
|
|
6
6
|
|
7
|
-
|
7
|
+
# Peg simplecov to < 0.8 until this is resolved:
|
8
|
+
# https://github.com/colszowka/simplecov/issues/281
|
9
|
+
gem 'simplecov', '~> 0.7.1', require: false
|
8
10
|
gem 'coveralls', require: false
|
9
11
|
|
10
12
|
gem 'engine_cart', '~> 0.3.0'
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
5.
|
1
|
+
5.4.0.rc1
|
@@ -9,6 +9,7 @@
|
|
9
9
|
//= require blacklight/bookmark_toggle
|
10
10
|
//= require blacklight/ajax_modal
|
11
11
|
//= require blacklight/search_context
|
12
|
+
//= require blacklight/collapsable
|
12
13
|
//
|
13
14
|
//Bootstrap JS for providing collapsable tablet/mobile menu/alert boxes
|
14
15
|
//= require bootstrap/transition
|
@@ -0,0 +1,9 @@
|
|
1
|
+
(function($) {
|
2
|
+
Blacklight.onLoad(function() {
|
3
|
+
// when clicking on a link that toggles the collapsing behavior, don't do anything
|
4
|
+
// with the hash or the page could jump around.
|
5
|
+
$(document).on("click", "a[data-toggle=collapse][href='#'], [data-toggle=collapse] a[href='#']", function(event) {
|
6
|
+
event.preventDefault();
|
7
|
+
});
|
8
|
+
});
|
9
|
+
})(jQuery);
|
@@ -9,6 +9,10 @@ class BookmarksController < CatalogController
|
|
9
9
|
include Blacklight::SolrHelper
|
10
10
|
|
11
11
|
copy_blacklight_config_from(CatalogController)
|
12
|
+
|
13
|
+
rescue_from Blacklight::Exceptions::ExpiredSessionToken do
|
14
|
+
head :unauthorized
|
15
|
+
end
|
12
16
|
|
13
17
|
# Blacklight uses #search_action_url to figure out the right URL for
|
14
18
|
# the global search box
|
@@ -19,12 +23,25 @@ class BookmarksController < CatalogController
|
|
19
23
|
before_filter :verify_user
|
20
24
|
|
21
25
|
def index
|
22
|
-
@bookmarks =
|
26
|
+
@bookmarks = token_or_current_or_guest_user.bookmarks
|
23
27
|
bookmark_ids = @bookmarks.collect { |b| b.document_id.to_s }
|
24
28
|
|
25
|
-
@response, @document_list =
|
29
|
+
@response, @document_list = get_solr_response_for_document_ids(bookmark_ids)
|
30
|
+
|
31
|
+
respond_to do |format|
|
32
|
+
format.html { }
|
33
|
+
format.rss { render :layout => false }
|
34
|
+
format.atom { render :layout => false }
|
35
|
+
format.json do
|
36
|
+
render json: render_search_results_as_json
|
37
|
+
end
|
38
|
+
|
39
|
+
additional_response_formats(format)
|
40
|
+
document_export_formats(format)
|
41
|
+
end
|
26
42
|
end
|
27
43
|
|
44
|
+
|
28
45
|
def update
|
29
46
|
create
|
30
47
|
end
|
@@ -41,13 +58,13 @@ class BookmarksController < CatalogController
|
|
41
58
|
if params[:bookmarks]
|
42
59
|
@bookmarks = params[:bookmarks]
|
43
60
|
else
|
44
|
-
@bookmarks = [{ :
|
61
|
+
@bookmarks = [{ document_id: params[:id], document_type: blacklight_config.solr_document_model.to_s }]
|
45
62
|
end
|
46
63
|
|
47
64
|
current_or_guest_user.save! unless current_or_guest_user.persisted?
|
48
65
|
|
49
66
|
success = @bookmarks.all? do |bookmark|
|
50
|
-
current_or_guest_user.bookmarks.create(bookmark) unless current_or_guest_user.
|
67
|
+
current_or_guest_user.bookmarks.create(bookmark) unless current_or_guest_user.bookmarks.where(bookmark).exists?
|
51
68
|
end
|
52
69
|
|
53
70
|
if request.xhr?
|
@@ -66,10 +83,10 @@ class BookmarksController < CatalogController
|
|
66
83
|
# Beware, :id is the Solr document_id, not the actual Bookmark id.
|
67
84
|
# idempotent, as DELETE is supposed to be.
|
68
85
|
def destroy
|
69
|
-
bookmark = current_or_guest_user.
|
70
|
-
|
71
|
-
success =
|
72
|
-
|
86
|
+
bookmark = current_or_guest_user.bookmarks.where(document_id: params[:id], document_type: blacklight_config.solr_document_model).first
|
87
|
+
|
88
|
+
success = bookmark && bookmark.delete && bookmark.destroyed?
|
89
|
+
|
73
90
|
unless request.xhr?
|
74
91
|
if success
|
75
92
|
flash[:notice] = I18n.t('blacklight.bookmarks.remove.success')
|
@@ -94,10 +111,56 @@ class BookmarksController < CatalogController
|
|
94
111
|
|
95
112
|
protected
|
96
113
|
def verify_user
|
97
|
-
|
114
|
+
unless current_or_guest_user or (action == "index" and token_or_current_or_guest_user)
|
115
|
+
flash[:notice] = I18n.t('blacklight.bookmarks.need_login') and raise Blacklight::Exceptions::AccessDenied
|
116
|
+
end
|
98
117
|
end
|
99
118
|
|
100
119
|
def start_new_search_session?
|
101
120
|
action_name == "index"
|
102
121
|
end
|
122
|
+
|
123
|
+
# Used for #export action, with encrypted user_id.
|
124
|
+
def decrypt_user_id(encrypted_user_id)
|
125
|
+
user_id, timestamp = message_encryptor.decrypt_and_verify(encrypted_user_id)
|
126
|
+
|
127
|
+
if timestamp < 1.hour.ago
|
128
|
+
raise Blacklight::Exceptions::ExpiredSessionToken.new
|
129
|
+
end
|
130
|
+
|
131
|
+
user_id
|
132
|
+
end
|
133
|
+
|
134
|
+
# Used for #export action with encrypted user_id, available
|
135
|
+
# as a helper method for views.
|
136
|
+
def encrypt_user_id(user_id)
|
137
|
+
message_encryptor.encrypt_and_sign([user_id, Time.now])
|
138
|
+
end
|
139
|
+
helper_method :encrypt_user_id
|
140
|
+
|
141
|
+
##
|
142
|
+
# This method provides Rails 3 compatibility to our message encryptor.
|
143
|
+
# When we drop support for Rails 3, we can just use the AS::KeyGenerator
|
144
|
+
# directly instead of this helper.
|
145
|
+
def bookmarks_export_secret_token salt
|
146
|
+
OpenSSL::PKCS5.pbkdf2_hmac_sha1(Blacklight.secret_key, salt, 1000, 64)
|
147
|
+
end
|
148
|
+
|
149
|
+
def message_encryptor
|
150
|
+
derived_secret = bookmarks_export_secret_token("bookmarks session key")
|
151
|
+
ActiveSupport::MessageEncryptor.new(derived_secret)
|
152
|
+
end
|
153
|
+
|
154
|
+
def token_or_current_or_guest_user
|
155
|
+
token_user || current_or_guest_user
|
156
|
+
end
|
157
|
+
|
158
|
+
def token_user
|
159
|
+
@token_user ||= if params[:encrypted_user_id]
|
160
|
+
user_id = decrypt_user_id params[:encrypted_user_id]
|
161
|
+
User.find(user_id)
|
162
|
+
else
|
163
|
+
nil
|
164
|
+
end
|
165
|
+
end
|
103
166
|
end
|
@@ -134,9 +134,7 @@ module Blacklight::BlacklightHelperBehavior
|
|
134
134
|
# @param [Blacklight::Solr::Configuration::SolrField] solr_field
|
135
135
|
# @return [Boolean]
|
136
136
|
def should_render_index_field? document, solr_field
|
137
|
-
document
|
138
|
-
(document.has_highlight_field? solr_field.field if solr_field.highlight) ||
|
139
|
-
solr_field.accessor
|
137
|
+
should_render_field?(solr_field, document) && document_has_value?(document, solr_field)
|
140
138
|
end
|
141
139
|
|
142
140
|
##
|
@@ -146,9 +144,19 @@ module Blacklight::BlacklightHelperBehavior
|
|
146
144
|
# @param [Blacklight::Solr::Configuration::SolrField] solr_field
|
147
145
|
# @return [Boolean]
|
148
146
|
def should_render_show_field? document, solr_field
|
149
|
-
document
|
150
|
-
|
151
|
-
|
147
|
+
should_render_field?(solr_field, document) && document_has_value?(document, solr_field)
|
148
|
+
end
|
149
|
+
|
150
|
+
##
|
151
|
+
# Check if a document has (or, might have, in the case of accessor methods) a value for
|
152
|
+
# the given solr field
|
153
|
+
# @param [SolrDocument] document
|
154
|
+
# @param [Blacklight::Solr::Configuration::SolrField] solr_field
|
155
|
+
# @return [Boolean]
|
156
|
+
def document_has_value? document, field_config
|
157
|
+
document.has?(field_config.field) ||
|
158
|
+
(document.has_highlight_field? field_config.field if field_config.highlight) ||
|
159
|
+
field_config.accessor
|
152
160
|
end
|
153
161
|
|
154
162
|
##
|
@@ -378,7 +386,7 @@ module Blacklight::BlacklightHelperBehavior
|
|
378
386
|
# @return [String]
|
379
387
|
def render_document_index documents = nil, locals = {}
|
380
388
|
documents ||= @document_list
|
381
|
-
render_document_index_with_view(document_index_view_type, documents)
|
389
|
+
render_document_index_with_view(document_index_view_type, documents, locals)
|
382
390
|
end
|
383
391
|
|
384
392
|
##
|
@@ -87,15 +87,6 @@ module Blacklight::CatalogHelperBehavior
|
|
87
87
|
(@response.rows if @response and @response.rows > 0) || params.fetch(:per_page, default_per_page).to_i
|
88
88
|
end
|
89
89
|
|
90
|
-
##
|
91
|
-
# Export to Refworks URL
|
92
|
-
#
|
93
|
-
# @param [SolrDocument]
|
94
|
-
# @return [String]
|
95
|
-
def refworks_export_url(document = @document)
|
96
|
-
"http://www.refworks.com/express/expressimport.asp?vendor=#{CGI.escape(application_name)}&filter=MARC%20Format&encoding=65001&url=#{CGI.escape(polymorphic_path(document, :format => 'refworks_marc_txt', :only_path => false))}"
|
97
|
-
end
|
98
|
-
|
99
90
|
##
|
100
91
|
# Get the classes to add to a document's div
|
101
92
|
#
|
@@ -205,4 +196,21 @@ module Blacklight::CatalogHelperBehavior
|
|
205
196
|
def default_view_type_group_icon_classes view
|
206
197
|
"glyphicon-#{view.to_s.parameterize } view-icon-#{view.to_s.parameterize}"
|
207
198
|
end
|
199
|
+
|
200
|
+
def current_bookmarks response = nil
|
201
|
+
response ||= @response
|
202
|
+
@current_bookmarks ||= current_or_guest_user.bookmarks_for_documents(response.documents).to_a
|
203
|
+
end
|
204
|
+
|
205
|
+
def render_marc_tools
|
206
|
+
return unless defined? Blacklight::Marc
|
207
|
+
|
208
|
+
begin
|
209
|
+
# blacklight-marc 5.4+
|
210
|
+
render 'marc_tools'
|
211
|
+
rescue ActionView::MissingTemplate
|
212
|
+
# blacklight-marc 5.0+
|
213
|
+
render('endnote') + render('refworks')
|
214
|
+
end
|
215
|
+
end
|
208
216
|
end
|
@@ -11,13 +11,26 @@ module Blacklight::ConfigurationHelperBehavior
|
|
11
11
|
|
12
12
|
# Used in the document_list partial (search view) for building a select element
|
13
13
|
def sort_fields
|
14
|
-
|
14
|
+
active_sort_fields.map { |key, x| [x.label, x.key] }
|
15
|
+
end
|
16
|
+
|
17
|
+
def active_sort_fields
|
18
|
+
blacklight_config.sort_fields.select { |sort_key, field_config| should_render_field?(field_config) }
|
15
19
|
end
|
16
20
|
|
17
21
|
# Used in the search form partial for building a select tag
|
18
22
|
def search_fields
|
19
23
|
search_field_options_for_select
|
20
24
|
end
|
25
|
+
|
26
|
+
# Returns suitable argument to options_for_select method, to create
|
27
|
+
# an html select based on #search_field_list. Skips search_fields
|
28
|
+
# marked :include_in_simple_select => false
|
29
|
+
def search_field_options_for_select
|
30
|
+
blacklight_config.search_fields.collect do |key, field_def|
|
31
|
+
[field_def.label, field_def.key] if should_render_field?(field_def)
|
32
|
+
end.compact
|
33
|
+
end
|
21
34
|
|
22
35
|
# used in the catalog/_show/_default partial
|
23
36
|
def document_show_fields document=nil
|
@@ -63,10 +76,10 @@ module Blacklight::ConfigurationHelperBehavior
|
|
63
76
|
##
|
64
77
|
# Look up the label for a solr field.
|
65
78
|
#
|
66
|
-
# @overload
|
79
|
+
# @overload label
|
67
80
|
# @param [Symbol] an i18n key
|
68
81
|
#
|
69
|
-
# @overload
|
82
|
+
# @overload label, i18n_key, another_i18n_key, and_another_i18n_key
|
70
83
|
# @param [String] default label to display if the i18n look up fails
|
71
84
|
# @param [Symbol] i18n keys to attempt to look up
|
72
85
|
# before falling back to the label
|
@@ -84,16 +97,22 @@ module Blacklight::ConfigurationHelperBehavior
|
|
84
97
|
t(first, default: rest)
|
85
98
|
end
|
86
99
|
|
100
|
+
def document_index_views
|
101
|
+
blacklight_config.view.select do |k, config|
|
102
|
+
should_render_field? config
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
87
106
|
##
|
88
107
|
# Get the default index view type
|
89
108
|
def default_document_index_view_type
|
90
|
-
|
109
|
+
document_index_views.select { |k,config| config.respond_to? :default and config.default }.keys.first || document_index_views.keys.first
|
91
110
|
end
|
92
111
|
|
93
112
|
##
|
94
113
|
# Check if there are alternative views configuration
|
95
114
|
def has_alternative_views?
|
96
|
-
|
115
|
+
document_index_views.keys.length > 1
|
97
116
|
end
|
98
117
|
|
99
118
|
##
|
@@ -104,13 +123,13 @@ module Blacklight::ConfigurationHelperBehavior
|
|
104
123
|
|
105
124
|
# Used in the document list partial (search view) for creating a link to the document show action
|
106
125
|
def document_show_link_field document=nil
|
107
|
-
blacklight_config.view_config(document_index_view_type).title_field.to_sym
|
126
|
+
blacklight_config.view_config(document_index_view_type).title_field.try(:to_sym) || document.id
|
108
127
|
end
|
109
128
|
|
110
129
|
##
|
111
130
|
# Default sort field
|
112
131
|
def default_sort_field
|
113
|
-
|
132
|
+
(active_sort_fields.select { |k,config| config.respond_to? :default and config.default }.first || active_sort_fields.first).try(:last)
|
114
133
|
end
|
115
134
|
|
116
135
|
##
|
@@ -126,4 +145,37 @@ module Blacklight::ConfigurationHelperBehavior
|
|
126
145
|
[t(:'blacklight.search.per_page.label', :count => count).html_safe, count]
|
127
146
|
end
|
128
147
|
end
|
148
|
+
|
149
|
+
##
|
150
|
+
# Determine whether to render a field by evaluating :if and :unless conditions
|
151
|
+
#
|
152
|
+
# @param [SolrDocument] document
|
153
|
+
# @param [Blacklight::Solr::Configuration::SolrField] solr_field
|
154
|
+
# @return [Boolean]
|
155
|
+
def should_render_field? field_config, *args
|
156
|
+
return field_config if field_config === true or field_config === false
|
157
|
+
|
158
|
+
if_value = !field_config.respond_to?(:if) || field_config.if.nil? || evaluate_configuration_conditional(field_config.if, field_config, *args)
|
159
|
+
|
160
|
+
unless_value = !field_config.respond_to?(:unless) || field_config.unless.nil? || !evaluate_configuration_conditional(field_config.unless, field_config, *args)
|
161
|
+
|
162
|
+
if_value && unless_value
|
163
|
+
end
|
164
|
+
|
165
|
+
def evaluate_configuration_conditional proc_helper_or_boolean, *args_for_procs_and_methods
|
166
|
+
case proc_helper_or_boolean
|
167
|
+
when Symbol
|
168
|
+
arity = method(proc_helper_or_boolean).arity
|
169
|
+
|
170
|
+
if arity == 0
|
171
|
+
send(proc_helper_or_boolean)
|
172
|
+
else
|
173
|
+
send(proc_helper_or_boolean, *args_for_procs_and_methods)
|
174
|
+
end
|
175
|
+
when Proc
|
176
|
+
proc_helper_or_boolean.call self, *args_for_procs_and_methods
|
177
|
+
else
|
178
|
+
proc_helper_or_boolean
|
179
|
+
end
|
180
|
+
end
|
129
181
|
end
|
@@ -60,22 +60,7 @@ module Blacklight::FacetsHelperBehavior
|
|
60
60
|
def should_render_facet? display_facet
|
61
61
|
# display when show is nil or true
|
62
62
|
facet_config = facet_configuration_for_field(display_facet.name)
|
63
|
-
|
64
|
-
display = case facet_config.show
|
65
|
-
when Symbol
|
66
|
-
arity = method(facet_config.show).arity
|
67
|
-
|
68
|
-
if arity == 0
|
69
|
-
send(facet_config.show)
|
70
|
-
else
|
71
|
-
send(facet_config.show, display_facet)
|
72
|
-
end
|
73
|
-
when Proc
|
74
|
-
facet_config.show.call self, facet_config, display_facet
|
75
|
-
else
|
76
|
-
facet_config.show
|
77
|
-
end
|
78
|
-
|
63
|
+
display = should_render_field?(facet_config, display_facet)
|
79
64
|
return display && display_facet.items.present?
|
80
65
|
end
|
81
66
|
|
@@ -7,11 +7,11 @@ module Blacklight::UrlHelperBehavior
|
|
7
7
|
# Extension point for downstream applications
|
8
8
|
# to provide more interesting routing to
|
9
9
|
# documents
|
10
|
-
def url_for_document doc
|
10
|
+
def url_for_document doc, options = {}
|
11
11
|
if respond_to?(:blacklight_config) and
|
12
12
|
blacklight_config.show.route and
|
13
13
|
(!doc.respond_to?(:to_model) or doc.to_model.is_a? SolrDocument)
|
14
|
-
route = blacklight_config.show.route.merge(action: :show, id: doc)
|
14
|
+
route = blacklight_config.show.route.merge(action: :show, id: doc).merge(options)
|
15
15
|
route[:controller] = controller_name if route[:controller] == :current
|
16
16
|
route
|
17
17
|
else
|
@@ -260,6 +260,25 @@ module Blacklight::UrlHelperBehavior
|
|
260
260
|
p.delete(:f) if p[:f].empty?
|
261
261
|
p
|
262
262
|
end
|
263
|
+
|
264
|
+
# A URL to refworks export, with an embedded callback URL to this app.
|
265
|
+
# the callback URL is to bookmarks#export, which delivers a list of
|
266
|
+
# user's bookmarks in 'refworks marc txt' format -- we tell refworks
|
267
|
+
# to expect that format.
|
268
|
+
def bookmarks_export_url(format, params = {})
|
269
|
+
bookmarks_url(params.merge(format: :format, encrypted_user_id: encrypt_user_id(current_or_guest_user.id) ))
|
270
|
+
end
|
271
|
+
|
272
|
+
# This method should move to BlacklightMarc in Blacklight 6.x
|
273
|
+
def refworks_export_url params = {}
|
274
|
+
if params.is_a? ::SolrDocument or (params.nil? and instance_variable_defined? :@document)
|
275
|
+
Deprecation.warn self, "#refworks_export_url with a SolrDocument is deprecated. Pass in { url: url_for_document(@document) } instead"
|
276
|
+
url = url_for_document(params || @document, format: :refworks_marc_txt, only_path: false)
|
277
|
+
params = { url: url }
|
278
|
+
end
|
279
|
+
|
280
|
+
"http://www.refworks.com/express/expressimport.asp?vendor=#{CGI.escape(params[:vendor] || application_name)}&filter=#{CGI.escape(params[:filter] || "MARC Format")}&encoding=65001" + (("&url=#{CGI.escape(params[:url])}" if params[:url]) || "")
|
281
|
+
end
|
263
282
|
|
264
283
|
if ::Rails.version < "4.0"
|
265
284
|
def asset_url *args
|
data/app/models/bookmark.rb
CHANGED
@@ -1,13 +1,22 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
class Bookmark < ActiveRecord::Base
|
3
3
|
|
4
|
-
belongs_to :user
|
5
|
-
|
6
|
-
attr_accessible :id, :document_id, :title if Rails::VERSION::MAJOR < 4
|
4
|
+
belongs_to :user, polymorphic: true
|
5
|
+
belongs_to :document, polymorphic: true
|
7
6
|
|
7
|
+
validates_presence_of :user_id, :scope=>:document_id
|
8
|
+
attr_accessible :id, :document_id, :document_type, :title if Rails::VERSION::MAJOR < 4
|
8
9
|
|
9
10
|
def document
|
10
|
-
|
11
|
+
document_type.new document_type.unique_key => document_id
|
12
|
+
end
|
13
|
+
|
14
|
+
def document_type
|
15
|
+
(super.constantize if defined?(super)) || default_document_type
|
16
|
+
end
|
17
|
+
|
18
|
+
def default_document_type
|
19
|
+
SolrDocument
|
11
20
|
end
|
12
21
|
|
13
22
|
end
|