enju_flower 0.1.0.pre12 → 0.1.0.pre13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/manifestations_controller.rb +771 -0
- data/app/views/layouts/{patrons.html.erb → agents.html.erb} +0 -0
- data/app/views/layouts/{patrons.mobile.erb → agents.mobile.erb} +0 -0
- data/app/views/manifestations/_manifestation.html.erb +5 -5
- data/app/views/manifestations/_show_holding.html.erb +1 -1
- data/app/views/manifestations/_show_holding.mobile.erb +1 -1
- data/lib/enju_flower/version.rb +1 -1
- data/spec/dummy/config/initializers/inflections.rb +0 -5
- data/spec/dummy/db/migrate/20130303104849_add_state_index_to_reserve.rb +5 -0
- data/spec/dummy/db/migrate/20130303124821_add_retained_at_to_reserve.rb +5 -0
- data/spec/dummy/db/migrate/20130304015019_add_postponed_at_to_reserve.rb +5 -0
- data/spec/dummy/db/migrate/20130416054135_add_circulation_status_id_to_item.rb +8 -0
- data/spec/dummy/db/migrate/20130519065638_add_lock_version_to_reserve.rb +5 -0
- data/spec/dummy/db/migrate/20130519065837_add_lock_version_to_checkin.rb +5 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/solr/data/test/index/{_23i.fdt → _20.fdt} +0 -0
- data/spec/dummy/solr/data/test/index/{_23i.fdx → _20.fdx} +0 -0
- data/spec/dummy/solr/data/test/index/{_23i.fnm → _20.fnm} +0 -0
- data/spec/dummy/solr/data/test/index/{_23i.frq → _20.frq} +0 -0
- data/spec/dummy/solr/data/test/index/{_23i.nrm → _20.nrm} +0 -0
- data/spec/dummy/solr/data/test/index/{_23i.prx → _20.prx} +0 -0
- data/spec/dummy/solr/data/test/index/{_23i.tii → _20.tii} +0 -0
- data/spec/dummy/solr/data/test/index/{_23i.tis → _20.tis} +0 -0
- data/spec/dummy/solr/data/test/index/{_23j.fdt → _21.fdt} +0 -0
- data/spec/dummy/solr/data/test/index/{_23j.fdx → _21.fdx} +0 -0
- data/spec/dummy/solr/data/test/index/{_23j.fnm → _21.fnm} +0 -0
- data/spec/dummy/solr/data/test/index/{_23j.frq → _21.frq} +0 -0
- data/spec/dummy/solr/data/test/index/{_23j.nrm → _21.nrm} +0 -0
- data/spec/dummy/solr/data/test/index/{_23j.prx → _21.prx} +0 -0
- data/spec/dummy/solr/data/test/index/{_23j.tii → _21.tii} +0 -0
- data/spec/dummy/solr/data/test/index/{_23j.tis → _21.tis} +0 -0
- data/spec/dummy/solr/data/test/index/{_23k.fdt → _22.fdt} +0 -0
- data/spec/dummy/solr/data/test/index/{_23k.fdx → _22.fdx} +0 -0
- data/spec/dummy/solr/data/test/index/{_23k.fnm → _22.fnm} +1 -1
- data/spec/dummy/solr/data/test/index/_22.frq +0 -0
- data/spec/dummy/solr/data/test/index/{_23k.nrm → _22.nrm} +1 -1
- data/spec/dummy/solr/data/test/index/_22.prx +0 -0
- data/spec/dummy/solr/data/test/index/_22.tii +0 -0
- data/spec/dummy/solr/data/test/index/_22.tis +0 -0
- data/spec/dummy/solr/data/test/index/segments.gen +0 -0
- data/spec/dummy/solr/data/test/index/{segments_2u7 → segments_2s} +0 -0
- data/spec/dummy/solr/data/test/spellchecker/segments_1 +0 -0
- data/spec/dummy/tmp/cache/4F7/F90/default_role +0 -0
- data/spec/dummy/tmp/cache/6E4/420/search_engine_all +0 -0
- data/spec/fixtures/agent_import_files.yml +47 -0
- data/spec/fixtures/agent_import_results.yml +29 -0
- data/spec/fixtures/agent_relationships.yml +6 -6
- data/spec/fixtures/agents.yml +2 -2
- data/spec/fixtures/circulation_statuses.yml +136 -0
- data/spec/fixtures/creates.yml +1 -1
- data/spec/fixtures/donates.yml +1 -1
- data/spec/fixtures/event_categories.yml +55 -0
- data/spec/fixtures/events.yml +142 -0
- data/spec/fixtures/identifier_types.yml +7 -0
- data/spec/fixtures/item_has_use_restrictions.yml +61 -0
- data/spec/fixtures/items.yml +48 -1
- data/spec/fixtures/manifestations.yml +1 -1
- data/spec/fixtures/owns.yml +1 -1
- data/spec/fixtures/produces.yml +1 -1
- data/spec/fixtures/realizes.yml +1 -1
- data/spec/fixtures/series_statements.yml +15 -2
- metadata +82 -57
- data/spec/dummy/solr/data/test/index/_23k.frq +0 -0
- data/spec/dummy/solr/data/test/index/_23k.prx +0 -0
- data/spec/dummy/solr/data/test/index/_23k.tii +0 -0
- data/spec/dummy/solr/data/test/index/_23k.tis +0 -0
@@ -0,0 +1,771 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
class ManifestationsController < ApplicationController
|
3
|
+
load_and_authorize_resource :except => :index
|
4
|
+
authorize_resource :only => :index
|
5
|
+
before_filter :authenticate_user!, :only => :edit
|
6
|
+
before_filter :get_agent, :get_manifestation, :except => [:create, :update, :destroy]
|
7
|
+
before_filter :get_expression, :only => :new
|
8
|
+
if defined?(EnjuSubject)
|
9
|
+
before_filter :get_subject, :except => [:create, :update, :destroy]
|
10
|
+
end
|
11
|
+
before_filter :get_series_statement, :only => [:index, :new, :edit]
|
12
|
+
before_filter :get_item, :get_libraries, :only => :index
|
13
|
+
before_filter :prepare_options, :only => [:new, :edit]
|
14
|
+
before_filter :get_version, :only => [:show]
|
15
|
+
after_filter :solr_commit, :only => :destroy
|
16
|
+
after_filter :convert_charset, :only => :index
|
17
|
+
cache_sweeper :manifestation_sweeper, :only => [:create, :update, :destroy]
|
18
|
+
include EnjuOai::OaiController if defined?(EnjuOai)
|
19
|
+
include EnjuSearchLog if defined?(EnjuSearchLog)
|
20
|
+
|
21
|
+
# GET /manifestations
|
22
|
+
# GET /manifestations.json
|
23
|
+
def index
|
24
|
+
mode = params[:mode]
|
25
|
+
if mode == 'add'
|
26
|
+
unless current_user.try(:has_role?, 'Librarian')
|
27
|
+
access_denied; return
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
@seconds = Benchmark.realtime do
|
32
|
+
if defined?(EnjuOai)
|
33
|
+
@oai = check_oai_params(params)
|
34
|
+
next if @oai[:need_not_to_search]
|
35
|
+
if params[:format] == 'oai'
|
36
|
+
oai_search = true
|
37
|
+
from_and_until_times = set_from_and_until(Manifestation, params[:from], params[:until])
|
38
|
+
from_time = @from_time = from_and_until_times[:from]
|
39
|
+
until_time = @until_time = from_and_until_times[:until]
|
40
|
+
# OAI-PMHのデフォルトの件数
|
41
|
+
per_page = 200
|
42
|
+
if params[:resumptionToken]
|
43
|
+
current_token = get_resumption_token(params[:resumptionToken])
|
44
|
+
if current_token
|
45
|
+
page = (current_token[:cursor].to_i + per_page).div(per_page) + 1
|
46
|
+
else
|
47
|
+
@oai[:errors] << 'badResumptionToken'
|
48
|
+
end
|
49
|
+
end
|
50
|
+
page ||= 1
|
51
|
+
|
52
|
+
if params[:verb] == 'GetRecord' and params[:identifier]
|
53
|
+
begin
|
54
|
+
@manifestation = Manifestation.find_by_oai_identifier(params[:identifier])
|
55
|
+
rescue ActiveRecord::RecordNotFound
|
56
|
+
@oai[:errors] << "idDoesNotExist"
|
57
|
+
render :formats => :oai, :layout => false
|
58
|
+
return
|
59
|
+
end
|
60
|
+
render :template => 'manifestations/show', :formats => :oai, :layout => false
|
61
|
+
return
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
set_reservable if defined?(EnjuCirculation)
|
67
|
+
|
68
|
+
manifestations, sort, @count = {}, {}, {}
|
69
|
+
query = ""
|
70
|
+
|
71
|
+
if params[:format] == 'csv'
|
72
|
+
per_page = 65534
|
73
|
+
end
|
74
|
+
|
75
|
+
if params[:format] == 'sru'
|
76
|
+
if params[:operation] == 'searchRetrieve'
|
77
|
+
sru = Sru.new(params)
|
78
|
+
query = sru.cql.to_sunspot
|
79
|
+
sort = sru.sort_by
|
80
|
+
else
|
81
|
+
render :template => 'manifestations/explain', :layout => false
|
82
|
+
return
|
83
|
+
end
|
84
|
+
else
|
85
|
+
if params[:api] == 'openurl'
|
86
|
+
openurl = Openurl.new(params)
|
87
|
+
@manifestations = openurl.search
|
88
|
+
query = openurl.query_text
|
89
|
+
sort = set_search_result_order(params[:sort_by], params[:order])
|
90
|
+
else
|
91
|
+
query = make_query(params[:query], params)
|
92
|
+
sort = set_search_result_order(params[:sort_by], params[:order])
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
# 絞り込みを行わない状態のクエリ
|
97
|
+
@query = query.dup
|
98
|
+
query = query.gsub(' ', ' ')
|
99
|
+
|
100
|
+
includes = [:carrier_type, :series_statements]
|
101
|
+
includes << :bookmarks if defined?(EnjuBookmark)
|
102
|
+
search = Manifestation.search(:include => includes)
|
103
|
+
role = current_user.try(:role) || Role.default_role
|
104
|
+
case @reservable
|
105
|
+
when 'true'
|
106
|
+
reservable = true
|
107
|
+
when 'false'
|
108
|
+
reservable = false
|
109
|
+
else
|
110
|
+
reservable = nil
|
111
|
+
end
|
112
|
+
|
113
|
+
agent = get_index_agent
|
114
|
+
@index_agent = agent
|
115
|
+
manifestation = @manifestation if @manifestation
|
116
|
+
series_statement = @series_statement if @series_statement
|
117
|
+
parent = @parent = Manifestation.where(:id => params[:parent_id]).first if params[:parent_id].present?
|
118
|
+
|
119
|
+
if defined?(EnjuSubject)
|
120
|
+
subject = @subject if @subject
|
121
|
+
end
|
122
|
+
|
123
|
+
unless mode == 'add'
|
124
|
+
search.build do
|
125
|
+
with(:creator_ids).equal_to agent[:creator].id if agent[:creator]
|
126
|
+
with(:contributor_ids).equal_to agent[:contributor].id if agent[:contributor]
|
127
|
+
with(:publisher_ids).equal_to agent[:publisher].id if agent[:publisher]
|
128
|
+
with(:series_statement_ids).equal_to series_statement.id if series_statement
|
129
|
+
with(:parent_ids).equal_to parent.id if parent
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
search.build do
|
134
|
+
fulltext query unless query.blank?
|
135
|
+
order_by sort[:sort_by], sort[:order] unless oai_search
|
136
|
+
order_by :updated_at, :desc if oai_search
|
137
|
+
if defined?(EnjuSubject)
|
138
|
+
with(:subject_ids).equal_to subject.id if subject
|
139
|
+
end
|
140
|
+
unless parent
|
141
|
+
if params[:periodical].to_s.downcase == "true"
|
142
|
+
with(:series_master).equal_to true unless parent
|
143
|
+
with(:periodical).equal_to true
|
144
|
+
#if series_statement.periodical?
|
145
|
+
# if mode != 'add'
|
146
|
+
# order_by :volume_number, sort[:order]
|
147
|
+
# order_by :issue_number, sort[:order]
|
148
|
+
# order_by :serial_number, sort[:order]
|
149
|
+
# end
|
150
|
+
#else
|
151
|
+
# with(:periodical).equal_to false
|
152
|
+
#end
|
153
|
+
else
|
154
|
+
if mode != 'add'
|
155
|
+
with(:resource_master).equal_to true
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
order_by sort[:sort_by], sort[:order] unless oai_search
|
160
|
+
facet :reservable if defined?(EnjuCirculation)
|
161
|
+
end
|
162
|
+
search = make_internal_query(search)
|
163
|
+
search.data_accessor_for(Manifestation).select = [
|
164
|
+
:id,
|
165
|
+
:original_title,
|
166
|
+
:title_transcription,
|
167
|
+
:required_role_id,
|
168
|
+
:carrier_type_id,
|
169
|
+
:access_address,
|
170
|
+
:volume_number_string,
|
171
|
+
:issue_number_string,
|
172
|
+
:serial_number_string,
|
173
|
+
:date_of_publication,
|
174
|
+
:pub_date,
|
175
|
+
:language_id,
|
176
|
+
:created_at,
|
177
|
+
:updated_at,
|
178
|
+
:volume_number_string,
|
179
|
+
:volume_number,
|
180
|
+
:issue_number_string,
|
181
|
+
:issue_number,
|
182
|
+
:serial_number,
|
183
|
+
:edition_string,
|
184
|
+
:edition,
|
185
|
+
:periodical,
|
186
|
+
:statement_of_responsibility
|
187
|
+
] if params[:format] == 'html' or params[:format].nil?
|
188
|
+
all_result = search.execute
|
189
|
+
@count[:query_result] = all_result.total
|
190
|
+
@reservable_facet = all_result.facet(:reservable).rows if defined?(EnjuCirculation)
|
191
|
+
|
192
|
+
if session[:search_params]
|
193
|
+
unless search.query.to_params == session[:search_params]
|
194
|
+
clear_search_sessions
|
195
|
+
end
|
196
|
+
else
|
197
|
+
clear_search_sessions
|
198
|
+
session[:params] = params
|
199
|
+
session[:search_params] == search.query.to_params
|
200
|
+
session[:query] = @query
|
201
|
+
end
|
202
|
+
|
203
|
+
if params[:format] == 'html' or params[:format].nil?
|
204
|
+
@search_query = Digest::SHA1.hexdigest(Marshal.dump(search.query.to_params).force_encoding('UTF-8'))
|
205
|
+
if flash[:search_query] == @search_query
|
206
|
+
flash.keep(:search_query)
|
207
|
+
else
|
208
|
+
if @series_statement
|
209
|
+
flash.keep(:search_query)
|
210
|
+
else
|
211
|
+
flash[:search_query] = @search_query
|
212
|
+
@manifestation_ids = search.build do
|
213
|
+
paginate :page => 1, :per_page => Setting.max_number_of_results
|
214
|
+
end.execute.raw_results.collect(&:primary_key).map{|i| i.to_i}
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
if defined?(EnjuBookmark)
|
219
|
+
if params[:view] == 'tag_cloud'
|
220
|
+
unless @manifestation_ids
|
221
|
+
@manifestation_ids = search.build do
|
222
|
+
paginate :page => 1, :per_page => Setting.max_number_of_results
|
223
|
+
end.execute.raw_results.collect(&:primary_key).map{|i| i.to_i}
|
224
|
+
end
|
225
|
+
#bookmark_ids = Bookmark.where(:manifestation_id => flash[:manifestation_ids]).limit(1000).pluck(:id)
|
226
|
+
bookmark_ids = Bookmark.where(:manifestation_id => @manifestation_ids).limit(1000).pluck(:id)
|
227
|
+
@tags = Tag.bookmarked(bookmark_ids)
|
228
|
+
render :partial => 'manifestations/tag_cloud'
|
229
|
+
return
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
page ||= params[:page] || 1
|
235
|
+
per_page ||= Manifestation.default_per_page
|
236
|
+
if params[:format] == 'sru'
|
237
|
+
search.query.start_record(params[:startRecord] || 1, params[:maximumRecords] || 200)
|
238
|
+
else
|
239
|
+
pub_dates = parse_pub_date(params)
|
240
|
+
pub_date_range = {}
|
241
|
+
if pub_dates[:from] == '*'
|
242
|
+
pub_date_range[:from] = 0
|
243
|
+
else
|
244
|
+
pub_date_range[:from] = Time.zone.parse(pub_dates[:from]).year
|
245
|
+
end
|
246
|
+
if pub_dates[:to] == '*'
|
247
|
+
pub_date_range[:to] = 10000
|
248
|
+
else
|
249
|
+
pub_date_range[:to] = Time.zone.parse(pub_dates[:to]).year
|
250
|
+
end
|
251
|
+
if params[:pub_year_range_interval]
|
252
|
+
pub_year_range_interval = params[:pub_year_range_interval].to_i
|
253
|
+
else
|
254
|
+
pub_year_range_interval = Setting.manifestation.facet.pub_year_range_interval
|
255
|
+
end
|
256
|
+
|
257
|
+
search.build do
|
258
|
+
facet :reservable if defined?(EnjuCirculation)
|
259
|
+
facet :carrier_type
|
260
|
+
facet :library
|
261
|
+
facet :language
|
262
|
+
facet :pub_year, :range => pub_date_range[:from]..pub_date_range[:to], :range_interval => pub_year_range_interval
|
263
|
+
facet :subject_ids if defined?(EnjuSubject)
|
264
|
+
paginate :page => page.to_i, :per_page => per_page
|
265
|
+
end
|
266
|
+
end
|
267
|
+
search_result = search.execute
|
268
|
+
if @count[:query_result] > Setting.max_number_of_results
|
269
|
+
max_count = Setting.max_number_of_results
|
270
|
+
else
|
271
|
+
max_count = @count[:query_result]
|
272
|
+
end
|
273
|
+
@manifestations = Kaminari.paginate_array(
|
274
|
+
search_result.results, :total_count => max_count
|
275
|
+
).page(page)
|
276
|
+
|
277
|
+
if params[:format].blank? or params[:format] == 'html'
|
278
|
+
@carrier_type_facet = search_result.facet(:carrier_type).rows
|
279
|
+
@language_facet = search_result.facet(:language).rows
|
280
|
+
@library_facet = search_result.facet(:library).rows
|
281
|
+
@pub_year_facet = search_result.facet(:pub_year).rows.reverse
|
282
|
+
end
|
283
|
+
|
284
|
+
@search_engines = Rails.cache.fetch('search_engine_all'){SearchEngine.all}
|
285
|
+
|
286
|
+
if defined?(EnjuBookmark)
|
287
|
+
# TODO: 検索結果が少ない場合にも表示させる
|
288
|
+
if @manifestation_ids.blank?
|
289
|
+
if query.respond_to?(:suggest_tags)
|
290
|
+
@suggested_tag = query.suggest_tags.first
|
291
|
+
end
|
292
|
+
end
|
293
|
+
end
|
294
|
+
|
295
|
+
if defined?(EnjuSearchLog)
|
296
|
+
if current_user.try(:save_search_history)
|
297
|
+
current_user.save_history(query, @manifestations.offset_value + 1, @count[:query_result], params[:format])
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
if defined?(EnjuOai)
|
302
|
+
if params[:format] == 'oai'
|
303
|
+
unless @manifestations.empty?
|
304
|
+
@resumption = set_resumption_token(
|
305
|
+
params[:resumptionToken],
|
306
|
+
@from_time || Manifestation.last.updated_at,
|
307
|
+
@until_time || Manifestation.first.updated_at,
|
308
|
+
@manifestations.limit_value
|
309
|
+
)
|
310
|
+
else
|
311
|
+
@oai[:errors] << 'noRecordsMatch'
|
312
|
+
end
|
313
|
+
end
|
314
|
+
end
|
315
|
+
end
|
316
|
+
|
317
|
+
store_location # before_filter ではファセット検索のURLを記憶してしまう
|
318
|
+
|
319
|
+
respond_to do |format|
|
320
|
+
format.html
|
321
|
+
format.mobile
|
322
|
+
format.xml { render :xml => @manifestations }
|
323
|
+
format.sru { render :layout => false }
|
324
|
+
format.rss { render :layout => false }
|
325
|
+
format.csv { render :layout => false }
|
326
|
+
format.rdf { render :layout => false }
|
327
|
+
format.atom
|
328
|
+
format.mods
|
329
|
+
format.json { render :json => @manifestations }
|
330
|
+
format.js
|
331
|
+
if defined?(EnjuOai)
|
332
|
+
format.oai {
|
333
|
+
case params[:verb]
|
334
|
+
when 'Identify'
|
335
|
+
render :template => 'manifestations/identify'
|
336
|
+
when 'ListMetadataFormats'
|
337
|
+
render :template => 'manifestations/list_metadata_formats'
|
338
|
+
when 'ListSets'
|
339
|
+
@series_statements = SeriesStatement.select([:id, :original_title])
|
340
|
+
render :template => 'manifestations/list_sets'
|
341
|
+
when 'ListIdentifiers'
|
342
|
+
render :template => 'manifestations/list_identifiers'
|
343
|
+
when 'ListRecords'
|
344
|
+
render :template => 'manifestations/list_records'
|
345
|
+
end
|
346
|
+
}
|
347
|
+
end
|
348
|
+
end
|
349
|
+
end
|
350
|
+
|
351
|
+
# GET /manifestations/1
|
352
|
+
# GET /manifestations/1.json
|
353
|
+
def show
|
354
|
+
if @version
|
355
|
+
@manifestation = @manifestation.versions.find(@version).item if @version
|
356
|
+
end
|
357
|
+
|
358
|
+
case params[:mode]
|
359
|
+
when 'send_email'
|
360
|
+
if user_signed_in?
|
361
|
+
Notifier.manifestation_info(current_user.id, @manifestation.id).deliver
|
362
|
+
flash[:notice] = t('page.sent_email')
|
363
|
+
redirect_to @manifestation
|
364
|
+
return
|
365
|
+
else
|
366
|
+
access_denied; return
|
367
|
+
end
|
368
|
+
end
|
369
|
+
|
370
|
+
return if render_mode(params[:mode])
|
371
|
+
|
372
|
+
flash.keep(:search_query)
|
373
|
+
store_location
|
374
|
+
|
375
|
+
if @manifestation.series_master?
|
376
|
+
flash.keep(:notice) if flash[:notice]
|
377
|
+
flash[:manifestation_id] = @manifestation.id
|
378
|
+
redirect_to manifestations_url(:parent_id => @manifestation.id)
|
379
|
+
return
|
380
|
+
end
|
381
|
+
|
382
|
+
if defined?(EnjuCirculation)
|
383
|
+
@reserved_count = Reserve.waiting.where(:manifestation_id => @manifestation.id, :checked_out_at => nil).count
|
384
|
+
@reserve = current_user.reserves.where(:manifestation_id => @manifestation.id).first if user_signed_in?
|
385
|
+
end
|
386
|
+
|
387
|
+
if defined?(EnjuQuestion)
|
388
|
+
@questions = @manifestation.questions(:user => current_user, :page => params[:question_page])
|
389
|
+
end
|
390
|
+
|
391
|
+
if @manifestation.attachment.path
|
392
|
+
if Setting.uploaded_file.storage == :s3
|
393
|
+
data = open(@manifestation.attachment.url).read.force_encoding('UTF-8')
|
394
|
+
else
|
395
|
+
file = @manifestation.attachment.path
|
396
|
+
end
|
397
|
+
end
|
398
|
+
|
399
|
+
respond_to do |format|
|
400
|
+
format.html # show.html.erb
|
401
|
+
format.mobile
|
402
|
+
format.xml {
|
403
|
+
case params[:mode]
|
404
|
+
when 'related'
|
405
|
+
render :template => 'manifestations/related'
|
406
|
+
else
|
407
|
+
render :xml => @manifestation
|
408
|
+
end
|
409
|
+
}
|
410
|
+
format.rdf
|
411
|
+
format.mods
|
412
|
+
format.json { render :json => @manifestation }
|
413
|
+
#format.atom { render :template => 'manifestations/oai_ore' }
|
414
|
+
#format.js
|
415
|
+
format.download {
|
416
|
+
if @manifestation.attachment.path
|
417
|
+
if Setting.uploaded_file.storage == :s3
|
418
|
+
send_data @manifestation.attachment.data, :filename => File.basename(@manifestation.attachment_file_name), :type => 'application/octet-stream'
|
419
|
+
else
|
420
|
+
if File.exist?(file) and File.file?(file)
|
421
|
+
send_file file, :filename => File.basename(@manifestation.attachment_file_name), :type => 'application/octet-stream'
|
422
|
+
end
|
423
|
+
end
|
424
|
+
else
|
425
|
+
render :template => 'page/404', :status => 404
|
426
|
+
end
|
427
|
+
}
|
428
|
+
if defined?(EnjuOai)
|
429
|
+
format.oai
|
430
|
+
end
|
431
|
+
end
|
432
|
+
end
|
433
|
+
|
434
|
+
# GET /manifestations/new
|
435
|
+
# GET /manifestations/new.json
|
436
|
+
def new
|
437
|
+
@manifestation = Manifestation.new
|
438
|
+
@manifestation.language = Language.where(:iso_639_1 => @locale).first
|
439
|
+
parent = Manifestation.where(:id => params[:parent_id]).first if params[:parent_id].present?
|
440
|
+
if parent
|
441
|
+
@manifestation.parent_id = parent.id
|
442
|
+
@manifestation.original_title = parent.original_title
|
443
|
+
@manifestation.title_transcription = parent.title_transcription
|
444
|
+
@manifestation.periodical = true if parent.periodical
|
445
|
+
end
|
446
|
+
|
447
|
+
respond_to do |format|
|
448
|
+
format.html # new.html.erb
|
449
|
+
format.json { render :json => @manifestation }
|
450
|
+
end
|
451
|
+
end
|
452
|
+
|
453
|
+
# GET /manifestations/1/edit
|
454
|
+
def edit
|
455
|
+
unless current_user.has_role?('Librarian')
|
456
|
+
unless params[:mode] == 'tag_edit'
|
457
|
+
access_denied; return
|
458
|
+
end
|
459
|
+
end
|
460
|
+
if defined?(EnjuBookmark)
|
461
|
+
if params[:mode] == 'tag_edit'
|
462
|
+
@bookmark = current_user.bookmarks.where(:manifestation_id => @manifestation.id).first if @manifestation rescue nil
|
463
|
+
render :partial => 'manifestations/tag_edit', :locals => {:manifestation => @manifestation}
|
464
|
+
end
|
465
|
+
store_location unless params[:mode] == 'tag_edit'
|
466
|
+
end
|
467
|
+
end
|
468
|
+
|
469
|
+
# POST /manifestations
|
470
|
+
# POST /manifestations.json
|
471
|
+
def create
|
472
|
+
@manifestation = Manifestation.new(params[:manifestation])
|
473
|
+
parent = Manifestation.where(:id => @manifestation.parent_id).first
|
474
|
+
unless @manifestation.original_title?
|
475
|
+
@manifestation.original_title = @manifestation.attachment_file_name
|
476
|
+
end
|
477
|
+
|
478
|
+
respond_to do |format|
|
479
|
+
if @manifestation.save
|
480
|
+
if parent
|
481
|
+
parent.derived_manifestations << @manifestation
|
482
|
+
parent.index
|
483
|
+
@manifestation.index
|
484
|
+
end
|
485
|
+
Sunspot.commit
|
486
|
+
|
487
|
+
format.html { redirect_to @manifestation, :notice => t('controller.successfully_created', :model => t('activerecord.models.manifestation')) }
|
488
|
+
format.json { render :json => @manifestation, :status => :created, :location => @manifestation }
|
489
|
+
else
|
490
|
+
prepare_options
|
491
|
+
format.html { render :action => "new" }
|
492
|
+
format.json { render :json => @manifestation.errors, :status => :unprocessable_entity }
|
493
|
+
end
|
494
|
+
end
|
495
|
+
end
|
496
|
+
|
497
|
+
# PUT /manifestations/1
|
498
|
+
# PUT /manifestations/1.json
|
499
|
+
def update
|
500
|
+
respond_to do |format|
|
501
|
+
if @manifestation.update_attributes(params[:manifestation])
|
502
|
+
Sunspot.commit
|
503
|
+
format.html { redirect_to @manifestation, :notice => t('controller.successfully_updated', :model => t('activerecord.models.manifestation')) }
|
504
|
+
format.json { head :no_content }
|
505
|
+
else
|
506
|
+
prepare_options
|
507
|
+
format.html { render :action => "edit" }
|
508
|
+
format.json { render :json => @manifestation.errors, :status => :unprocessable_entity }
|
509
|
+
end
|
510
|
+
end
|
511
|
+
end
|
512
|
+
|
513
|
+
# DELETE /manifestations/1
|
514
|
+
# DELETE /manifestations/1.json
|
515
|
+
def destroy
|
516
|
+
@manifestation.destroy
|
517
|
+
|
518
|
+
respond_to do |format|
|
519
|
+
format.html { redirect_to manifestations_url, :notice => t('controller.successfully_deleted', :model => t('activerecord.models.manifestation')) }
|
520
|
+
format.json { head :no_content }
|
521
|
+
end
|
522
|
+
end
|
523
|
+
|
524
|
+
private
|
525
|
+
|
526
|
+
def make_query(query, options = {})
|
527
|
+
# TODO: integerやstringもqfに含める
|
528
|
+
query = query.to_s.strip
|
529
|
+
|
530
|
+
if query.size == 1
|
531
|
+
query = "#{query}*"
|
532
|
+
end
|
533
|
+
|
534
|
+
if options[:mode] == 'recent'
|
535
|
+
query = "#{query} created_at_d:[NOW-1MONTH TO NOW]"
|
536
|
+
end
|
537
|
+
|
538
|
+
#unless options[:carrier_type].blank?
|
539
|
+
# query = "#{query} carrier_type_s:#{options[:carrier_type]}"
|
540
|
+
#end
|
541
|
+
|
542
|
+
#unless options[:library].blank?
|
543
|
+
# library_list = options[:library].split.uniq.join(' and ')
|
544
|
+
# query = "#{query} library_sm:#{library_list}"
|
545
|
+
#end
|
546
|
+
|
547
|
+
#unless options[:language].blank?
|
548
|
+
# query = "#{query} language_sm:#{options[:language]}"
|
549
|
+
#end
|
550
|
+
|
551
|
+
#unless options[:subject].blank?
|
552
|
+
# query = "#{query} subject_sm:#{options[:subject]}"
|
553
|
+
#end
|
554
|
+
|
555
|
+
if options[:tag].present?
|
556
|
+
query = "#{query} tag_sm:#{options[:tag]}"
|
557
|
+
end
|
558
|
+
|
559
|
+
if options[:creator].present?
|
560
|
+
query = "#{query} creator_text:#{options[:creator]}"
|
561
|
+
end
|
562
|
+
|
563
|
+
if options[:contributor].present?
|
564
|
+
query = "#{query} contributor_text:#{options[:contributor]}"
|
565
|
+
end
|
566
|
+
|
567
|
+
if options[:isbn].present?
|
568
|
+
query = "#{query} isbn_sm:#{options[:isbn].gsub('-', '')}"
|
569
|
+
end
|
570
|
+
|
571
|
+
if options[:issn].present?
|
572
|
+
query = "#{query} issn_sm:#{options[:issn].gsub('-', '')}"
|
573
|
+
end
|
574
|
+
|
575
|
+
if options[:lccn].present?
|
576
|
+
query = "#{query} lccn_s:#{options[:lccn]}"
|
577
|
+
end
|
578
|
+
|
579
|
+
if options[:jpno].present?
|
580
|
+
query = "#{query} jpno_s:#{options[:jpno]}"
|
581
|
+
end
|
582
|
+
|
583
|
+
if options[:publisher].present?
|
584
|
+
query = "#{query} publisher_text:#{options[:publisher]}"
|
585
|
+
end
|
586
|
+
|
587
|
+
if options[:item_identifier].present?
|
588
|
+
query = "#{query} item_identifier_sm:#{options[:item_identifier]}"
|
589
|
+
end
|
590
|
+
|
591
|
+
unless options[:number_of_pages_at_least].blank? and options[:number_of_pages_at_most].blank?
|
592
|
+
number_of_pages = {}
|
593
|
+
number_of_pages[:at_least] = options[:number_of_pages_at_least].to_i
|
594
|
+
number_of_pages[:at_most] = options[:number_of_pages_at_most].to_i
|
595
|
+
number_of_pages[:at_least] = "*" if number_of_pages[:at_least] == 0
|
596
|
+
number_of_pages[:at_most] = "*" if number_of_pages[:at_most] == 0
|
597
|
+
|
598
|
+
query = "#{query} number_of_pages_i:[#{number_of_pages[:at_least]} TO #{number_of_pages[:at_most]}]"
|
599
|
+
end
|
600
|
+
|
601
|
+
query = set_pub_date(query, options)
|
602
|
+
query = set_acquisition_date(query, options)
|
603
|
+
|
604
|
+
query = query.strip
|
605
|
+
if query == '[* TO *]'
|
606
|
+
# unless params[:advanced_search]
|
607
|
+
query = ''
|
608
|
+
# end
|
609
|
+
end
|
610
|
+
|
611
|
+
return query
|
612
|
+
end
|
613
|
+
|
614
|
+
def set_search_result_order(sort_by, order)
|
615
|
+
sort = {}
|
616
|
+
# TODO: ページ数や大きさでの並べ替え
|
617
|
+
case sort_by
|
618
|
+
when 'title'
|
619
|
+
sort[:sort_by] = 'sort_title'
|
620
|
+
sort[:order] = 'asc'
|
621
|
+
when 'pub_date'
|
622
|
+
sort[:sort_by] = 'date_of_publication'
|
623
|
+
sort[:order] = 'desc'
|
624
|
+
else
|
625
|
+
# デフォルトの並び方
|
626
|
+
sort[:sort_by] = 'created_at'
|
627
|
+
sort[:order] = 'desc'
|
628
|
+
end
|
629
|
+
if order == 'asc'
|
630
|
+
sort[:order] = 'asc'
|
631
|
+
elsif order == 'desc'
|
632
|
+
sort[:order] = 'desc'
|
633
|
+
end
|
634
|
+
sort
|
635
|
+
end
|
636
|
+
|
637
|
+
def render_mode(mode)
|
638
|
+
case mode
|
639
|
+
when 'holding'
|
640
|
+
render :partial => 'manifestations/show_holding', :locals => {:manifestation => @manifestation}
|
641
|
+
when 'barcode'
|
642
|
+
if defined?(EnjuBarcode)
|
643
|
+
barcode = Barby::QrCode.new(@manifestation.id)
|
644
|
+
send_data(barcode.to_svg, :disposition => 'inline', :type => 'image/svg+xml')
|
645
|
+
end
|
646
|
+
when 'tag_edit'
|
647
|
+
if defined?(EnjuBookmark)
|
648
|
+
render :partial => 'manifestations/tag_edit', :locals => {:manifestation => @manifestation}
|
649
|
+
end
|
650
|
+
when 'tag_list'
|
651
|
+
if defined?(EnjuBookmark)
|
652
|
+
render :partial => 'manifestations/tag_list', :locals => {:manifestation => @manifestation}
|
653
|
+
end
|
654
|
+
when 'show_index'
|
655
|
+
render :partial => 'manifestations/show_index', :locals => {:manifestation => @manifestation}
|
656
|
+
when 'show_creators'
|
657
|
+
render :partial => 'manifestations/show_creators', :locals => {:manifestation => @manifestation}
|
658
|
+
when 'show_all_creators'
|
659
|
+
render :partial => 'manifestations/show_creators', :locals => {:manifestation => @manifestation}
|
660
|
+
when 'pickup'
|
661
|
+
render :partial => 'manifestations/pickup', :locals => {:manifestation => @manifestation}
|
662
|
+
when 'calil_list'
|
663
|
+
if defined?(EnjuCalil)
|
664
|
+
render :partial => 'manifestations/calil_list', :locals => {:manifestation => @manifestation}
|
665
|
+
end
|
666
|
+
else
|
667
|
+
false
|
668
|
+
end
|
669
|
+
end
|
670
|
+
|
671
|
+
def prepare_options
|
672
|
+
@carrier_types = CarrierType.select([:id, :display_name, :position])
|
673
|
+
@content_types = ContentType.select([:id, :display_name, :position])
|
674
|
+
@roles = Role.select([:id, :display_name, :position])
|
675
|
+
@languages = Language.select([:id, :display_name, :position])
|
676
|
+
@frequencies = Frequency.select([:id, :display_name, :position])
|
677
|
+
@identifier_types = IdentifierType.select([:id, :display_name, :position])
|
678
|
+
@nii_types = NiiType.select([:id, :display_name, :position]) if defined?(EnjuNii)
|
679
|
+
if defined?(EnjuSubject)
|
680
|
+
@subject_types = SubjectType.select([:id, :display_name, :position])
|
681
|
+
@subject_heading_types = SubjectHeadingType.select([:id, :display_name, :position])
|
682
|
+
@classification_types = ClassificationType.select([:id, :display_name, :position])
|
683
|
+
end
|
684
|
+
end
|
685
|
+
|
686
|
+
def get_index_agent
|
687
|
+
agent = {}
|
688
|
+
case
|
689
|
+
when params[:agent_id]
|
690
|
+
agent[:agent] = Agent.find(params[:agent_id])
|
691
|
+
when params[:creator_id]
|
692
|
+
agent[:creator] = @creator = Agent.find(params[:creator_id])
|
693
|
+
when params[:contributor_id]
|
694
|
+
agent[:contributor] = @contributor = Agent.find(params[:contributor_id])
|
695
|
+
when params[:publisher_id]
|
696
|
+
agent[:publisher] = @publisher = Agent.find(params[:publisher_id])
|
697
|
+
end
|
698
|
+
agent
|
699
|
+
end
|
700
|
+
|
701
|
+
def set_reservable
|
702
|
+
case params[:reservable].to_s
|
703
|
+
when 'true'
|
704
|
+
@reservable = true
|
705
|
+
when 'false'
|
706
|
+
@reservable = false
|
707
|
+
else
|
708
|
+
@reservable = nil
|
709
|
+
end
|
710
|
+
end
|
711
|
+
|
712
|
+
def parse_pub_date(options)
|
713
|
+
pub_date = {}
|
714
|
+
if options[:pub_date_from].blank?
|
715
|
+
pub_date[:from] = "*"
|
716
|
+
else
|
717
|
+
pub_date[:from] = Time.zone.parse(options[:pub_date_from]).beginning_of_day.utc.iso8601 rescue nil
|
718
|
+
unless pub_date[:from]
|
719
|
+
pub_date[:from] = Time.zone.parse(Time.mktime(options[:pub_date_from]).to_s).beginning_of_day.utc.iso8601
|
720
|
+
end
|
721
|
+
end
|
722
|
+
|
723
|
+
if options[:pub_date_to].blank?
|
724
|
+
pub_date[:to] = "*"
|
725
|
+
else
|
726
|
+
pub_date[:to] = Time.zone.parse(options[:pub_date_to]).end_of_day.utc.iso8601 rescue nil
|
727
|
+
unless pub_date[:to]
|
728
|
+
pub_date[:to] = Time.zone.parse(Time.mktime(options[:pub_date_to]).to_s).end_of_year.utc.iso8601
|
729
|
+
end
|
730
|
+
end
|
731
|
+
pub_date
|
732
|
+
end
|
733
|
+
|
734
|
+
def set_pub_date(query, options)
|
735
|
+
unless options[:pub_date_from].blank? and options[:pub_date_to].blank?
|
736
|
+
options[:pub_date_from].to_s.gsub!(/\D/, '')
|
737
|
+
options[:pub_date_to].to_s.gsub!(/\D/, '')
|
738
|
+
pub_date = parse_pub_date(options)
|
739
|
+
query = "#{query} date_of_publication_d:[#{pub_date[:from]} TO #{pub_date[:to]}]"
|
740
|
+
end
|
741
|
+
query
|
742
|
+
end
|
743
|
+
|
744
|
+
def set_acquisition_date(query, options)
|
745
|
+
unless options[:acquired_from].blank? and options[:acquired_to].blank?
|
746
|
+
options[:acquired_from].to_s.gsub!(/\D/, '')
|
747
|
+
options[:acquired_to].to_s.gsub!(/\D/, '')
|
748
|
+
|
749
|
+
acquisition_date = {}
|
750
|
+
if options[:acquired_from].blank?
|
751
|
+
acquisition_date[:from] = "*"
|
752
|
+
else
|
753
|
+
acquisition_date[:from] = Time.zone.parse(options[:acquired_from]).beginning_of_day.utc.iso8601 rescue nil
|
754
|
+
unless acquisition_date[:from]
|
755
|
+
acquisition_date[:from] = Time.zone.parse(Time.mktime(options[:acquired_from]).to_s).beginning_of_day.utc.iso8601
|
756
|
+
end
|
757
|
+
end
|
758
|
+
|
759
|
+
if options[:acquired_to].blank?
|
760
|
+
acquisition_date[:to] = "*"
|
761
|
+
else
|
762
|
+
acquisition_date[:to] = Time.zone.parse(options[:acquired_to]).end_of_day.utc.iso8601 rescue nil
|
763
|
+
unless acquisition_date[:to]
|
764
|
+
acquisition_date[:to] = Time.zone.parse(Time.mktime(options[:acquired_to]).to_s).end_of_year.utc.iso8601
|
765
|
+
end
|
766
|
+
end
|
767
|
+
query = "#{query} acquired_at_d:[#{acquisition_date[:from]} TO #{acquisition_date[:to]}]"
|
768
|
+
end
|
769
|
+
query
|
770
|
+
end
|
771
|
+
end
|