enju_biblio 0.4.0.beta.2 → 0.4.0.rc.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/items_controller.rb +5 -1
- data/app/controllers/manifestations_controller.rb +12 -6
- data/app/mailers/agent_import_mailer.rb +2 -2
- data/app/mailers/resource_export_mailer.rb +2 -2
- data/app/mailers/resource_import_mailer.rb +2 -2
- data/app/models/agent.rb +3 -4
- data/app/models/agent_import_file.rb +1 -8
- data/app/models/custom_property.rb +17 -0
- data/app/models/import_request.rb +0 -9
- data/app/models/isbn_record.rb +1 -1
- data/app/models/issn_record.rb +1 -1
- data/app/models/item.rb +49 -2
- data/app/models/manifestation.rb +109 -247
- data/app/models/resource_export_file.rb +3 -16
- data/app/models/resource_export_file_state_machine.rb +1 -1
- data/app/models/resource_import_file.rb +1 -9
- data/app/views/items/_custom_property_fields.html.erb +7 -0
- data/app/views/items/_form.html.erb +18 -6
- data/app/views/items/show.html.erb +8 -1
- data/app/views/layouts/items.html.erb +1 -1
- data/app/views/layouts/manifestations.html.erb +1 -1
- data/app/views/manifestations/_custom_property_fields.html.erb +7 -0
- data/app/views/manifestations/_form.html.erb +10 -0
- data/app/views/manifestations/_manifestation.txt.erb +1 -1
- data/app/views/manifestations/_paginate_id_link.html.erb +1 -1
- data/app/views/manifestations/_show_detail_librarian.html.erb +9 -1
- data/app/views/manifestations/_show_detail_user.html.erb +1 -1
- data/app/views/manifestations/index.txt.ruby +7 -0
- data/app/views/manifestations/show.txt.ruby +5 -0
- data/app/views/resource_import_files/_results.html.erb +6 -0
- data/app/views/resource_import_results/index.html.erb +0 -11
- data/app/views/series_statements/_form.html.erb +6 -8
- data/app/views/series_statements/show.html.erb +12 -0
- data/config/locales/translation_en.yml +12 -1
- data/config/locales/translation_ja.yml +14 -3
- data/db/migrate/001_create_agents.rb +0 -1
- data/db/migrate/005_create_manifestations.rb +0 -1
- data/db/migrate/006_create_items.rb +0 -1
- data/db/migrate/20191219122214_create_custom_properties.rb +12 -0
- data/lib/enju_biblio/version.rb +1 -1
- data/lib/generators/enju_biblio/setup/setup_generator.rb +2 -0
- data/spec/controllers/items_controller_spec.rb +25 -0
- data/spec/controllers/manifestations_controller_spec.rb +52 -0
- data/spec/dummy/app/controllers/application_controller.rb +0 -1
- data/spec/dummy/app/models/user.rb +0 -2
- data/spec/dummy/config/environments/development.rb +11 -24
- data/spec/dummy/config/environments/production.rb +16 -28
- data/spec/dummy/config/environments/test.rb +6 -6
- data/spec/dummy/config/initializers/assets.rb +1 -1
- data/spec/dummy/db/migrate/059_create_libraries.rb +1 -2
- data/spec/dummy/db/migrate/069_create_shelves.rb +1 -2
- data/spec/dummy/db/migrate/077_create_user_groups.rb +1 -2
- data/spec/dummy/db/migrate/080_create_library_groups.rb +1 -1
- data/spec/dummy/db/migrate/120_create_baskets.rb +1 -1
- data/spec/dummy/db/migrate/124_create_bookstores.rb +1 -2
- data/spec/dummy/db/migrate/130_create_request_status_types.rb +1 -1
- data/spec/dummy/db/migrate/131_create_request_types.rb +1 -1
- data/spec/dummy/db/migrate/20081006090811_create_subscriptions.rb +1 -2
- data/spec/dummy/db/migrate/20081006093246_create_subscribes.rb +1 -1
- data/spec/dummy/db/migrate/20081023092436_create_search_engines.rb +1 -1
- data/spec/dummy/db/migrate/20100211105551_add_admin_networks_to_library_group.rb +1 -1
- data/spec/dummy/db/migrate/20100314190054_add_opening_hour_to_library.rb +1 -1
- data/spec/dummy/db/migrate/20110222073537_add_url_to_library_group.rb +1 -1
- data/spec/dummy/db/migrate/20110318183304_add_valid_period_for_new_user_to_user_group.rb +1 -1
- data/spec/dummy/db/migrate/20120105074911_add_isil_to_library.rb +1 -1
- data/spec/dummy/db/migrate/20120129014038_create_budget_types.rb +1 -1
- data/spec/dummy/db/migrate/20120319173203_create_accepts.rb +1 -1
- data/spec/dummy/db/migrate/20120510140958_add_closed_to_shelf.rb +1 -1
- data/spec/dummy/db/migrate/20130412083556_add_latitude_and_longitude_to_library.rb +1 -1
- data/spec/dummy/db/migrate/20140110122216_create_user_import_files.rb +1 -1
- data/spec/dummy/db/migrate/20140110131010_create_user_import_results.rb +1 -1
- data/spec/dummy/db/migrate/20140524074813_create_user_import_file_transitions.rb +2 -6
- data/spec/dummy/db/migrate/20140628072217_add_user_encoding_to_user_import_file.rb +1 -1
- data/spec/dummy/db/migrate/20140709113413_create_user_export_files.rb +1 -1
- data/spec/dummy/db/migrate/20140709113905_create_user_export_file_transitions.rb +2 -6
- data/spec/dummy/db/migrate/20140720170714_add_default_library_id_to_user_import_file.rb +1 -1
- data/spec/dummy/db/migrate/20140720170735_add_default_user_group_id_to_user_import_file.rb +1 -1
- data/spec/dummy/db/migrate/20140821151023_create_colors.rb +1 -1
- data/spec/dummy/db/migrate/20150221063719_add_settings_to_library_group.rb +1 -1
- data/spec/dummy/db/migrate/20150506105356_add_error_message_to_user_import_result.rb +1 -1
- data/spec/dummy/db/migrate/20150924115059_create_withdraws.rb +1 -1
- data/spec/dummy/db/migrate/20160610093229_add_html_snippet_to_library_group.rb +1 -1
- data/spec/dummy/db/migrate/20160627232219_add_most_recent_to_user_import_file_transitions.rb +1 -1
- data/spec/dummy/db/migrate/20160627232316_add_most_recent_to_user_export_file_transitions.rb +1 -1
- data/spec/dummy/db/migrate/20160813191647_add_max_number_of_results_to_library_group.rb +1 -1
- data/spec/dummy/db/migrate/20160813191733_add_family_name_first_to_library_group.rb +1 -1
- data/spec/dummy/db/migrate/20160813192542_add_pub_year_facet_range_interval_to_library_group.rb +1 -1
- data/spec/dummy/db/migrate/20160813203039_add_user_id_to_library_group.rb +1 -1
- data/spec/dummy/db/migrate/20170305064014_add_csv_charset_conversion_to_library_group.rb +1 -1
- data/spec/dummy/db/migrate/20171014084528_add_header_logo_to_library_group.rb +1 -1
- data/spec/dummy/db/migrate/20171126133835_rename_login_banner_to_old_login_banner.rb +1 -1
- data/spec/dummy/db/migrate/20171126135238_add_foreign_key_to_library_group_id_on_library.rb +1 -1
- data/spec/dummy/db/migrate/20180102162311_add_header_logo_meta_to_library_group.rb +1 -1
- data/spec/dummy/db/migrate/20180107160726_add_constraints_to_most_recent_for_user_import_file_transitions.rb +1 -1
- data/spec/dummy/db/migrate/20180107160740_add_constraints_to_most_recent_for_user_export_file_transitions.rb +1 -1
- data/spec/dummy/db/migrate/20191216131755_add_email_to_library_group.rb +6 -0
- data/spec/dummy/db/schema.rb +96 -91
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/public/500.html +1 -0
- data/spec/factories/custom_property.rb +18 -0
- data/spec/factories/series_statement.rb +4 -3
- data/spec/fixtures/agents.yml +0 -1
- data/spec/fixtures/bookstores.yml +0 -8
- data/spec/fixtures/budget_types.yml +10 -9
- data/spec/fixtures/events.yml +0 -9
- data/spec/fixtures/items.yml +10 -11
- data/spec/fixtures/library_groups.yml +6 -11
- data/spec/fixtures/manifestations.yml +0 -1
- data/spec/models/agent_spec.rb +0 -1
- data/spec/models/custom_property_spec.rb +18 -0
- data/spec/models/item_spec.rb +0 -1
- data/spec/models/manifestation_spec.rb +32 -8
- data/spec/rails_helper.rb +3 -3
- data/spec/system/custom_properties_spec.rb +84 -0
- data/spec/system/items_spec.rb +60 -0
- data/spec/system/series_statements_spec.rb +16 -0
- data/spec/views/manifestations/index.json.jbuilder_spec.rb +18 -0
- data/spec/views/manifestations/{index.txt.erb_spec.rb → index.txt.ruby_spec.rb} +1 -1
- data/spec/views/manifestations/{show.txt.erb_spec.rb → show.txt.ruby_spec.rb} +1 -1
- metadata +56 -58
- data/app/views/manifestations/index.txt.erb +0 -1
- data/app/views/manifestations/show.txt.erb +0 -1
- data/spec/dummy/db/migrate/20180709023037_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb +0 -20
- data/spec/dummy/db/migrate/20180709023039_change_collation_for_tag_names.acts_as_taggable_on_engine.rb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c83f8e766a5af14cf7076a1c2b1fbe7f1b619f6c8ced04004f3505cae263e8e
|
4
|
+
data.tar.gz: 39c74c2f0a2c87e720b733b33cc94e7b9eae427155b9797331717e4fb5b94520
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2efc7c8cf5f2ae73312a9e38a8202de3fd2abbec1edb74d4c773904242e4544507318c38ba5a28c70db954d19897725ecc3ec9476fa30a155e50da6d1f8d9e01
|
7
|
+
data.tar.gz: 316e936de7994a9e873af69ebda3874aab882471be1bc64519bbf135397bc7b0ab8888bf38cf3f5d886ee25406cb65680867226678f81e081f01c7a8ceacca91
|
@@ -273,7 +273,11 @@ class ItemsController < ApplicationController
|
|
273
273
|
:lock_version, :manifestation_id, :library_id, :required_role_id,
|
274
274
|
:binding_item_identifier, :binding_call_number, :binded_at,
|
275
275
|
:use_restriction_id, :memo,
|
276
|
-
item_has_use_restriction_attributes: :use_restriction_id # EnjuCirculation
|
276
|
+
{item_has_use_restriction_attributes: :use_restriction_id}, # EnjuCirculation
|
277
|
+
{custom_properties_attributes: [
|
278
|
+
:id, :label, :value,
|
279
|
+
:_destroy
|
280
|
+
]}
|
277
281
|
)
|
278
282
|
end
|
279
283
|
|
@@ -429,15 +429,17 @@ class ManifestationsController < ApplicationController
|
|
429
429
|
# PUT /manifestations/1.json
|
430
430
|
def update
|
431
431
|
creators_params = manifestation_params[:creators_attributes]
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
})
|
436
|
-
@manifestation.creators = Agent.new_agents(creators_params)
|
437
|
-
end
|
432
|
+
@manifestation.assign_attributes(manifestation_params.delete_if{|k, v|
|
433
|
+
k == 'creators_attributes'
|
434
|
+
})
|
438
435
|
|
439
436
|
respond_to do |format|
|
440
437
|
if @manifestation.valid?
|
438
|
+
Manifestation.transaction do
|
439
|
+
@manifestation.creators = Agent.new_agents(creators_params)
|
440
|
+
@manifestation.save!
|
441
|
+
end
|
442
|
+
|
441
443
|
format.html { redirect_to @manifestation, notice: t('controller.successfully_updated', model: t('activerecord.models.manifestation')) }
|
442
444
|
format.json { head :no_content }
|
443
445
|
else
|
@@ -547,6 +549,10 @@ class ManifestationsController < ApplicationController
|
|
547
549
|
{identifiers_attributes: [
|
548
550
|
:id, :body, :identifier_type_id,
|
549
551
|
:_destroy
|
552
|
+
]},
|
553
|
+
{custom_properties_attributes: [
|
554
|
+
:id, :label, :value,
|
555
|
+
:_destroy
|
550
556
|
]}
|
551
557
|
)
|
552
558
|
end
|
@@ -2,7 +2,7 @@ class AgentImportMailer < ApplicationMailer
|
|
2
2
|
def completed(agent_import_file)
|
3
3
|
@agent_import_file = agent_import_file
|
4
4
|
@library_group = LibraryGroup.site_config
|
5
|
-
from = "#{LibraryGroup.system_name(agent_import_file.user.profile.locale)} <#{@library_group.
|
5
|
+
from = "#{LibraryGroup.system_name(agent_import_file.user.profile.locale)} <#{@library_group.email}>"
|
6
6
|
subject = "#{I18n.t('agent_import_mailer.completed.subject')}: #{@agent_import_file.id}"
|
7
7
|
mail(from: from, to: agent_import_file.user.email, subject: subject)
|
8
8
|
end
|
@@ -10,7 +10,7 @@ class AgentImportMailer < ApplicationMailer
|
|
10
10
|
def failed(agent_import_file)
|
11
11
|
@agent_import_file = agent_import_file
|
12
12
|
@library_group = LibraryGroup.site_config
|
13
|
-
from = "#{LibraryGroup.system_name(agent_import_file.user.profile.locale)} <#{@library_group.
|
13
|
+
from = "#{LibraryGroup.system_name(agent_import_file.user.profile.locale)} <#{@library_group.email}>"
|
14
14
|
subject = "#{I18n.t('agent_import_mailer.failed.subject')}: #{@agent_import_file.id}"
|
15
15
|
mail(from: from, to: agent_import_file.user.email, subject: subject)
|
16
16
|
end
|
@@ -2,7 +2,7 @@ class ResourceExportMailer < ApplicationMailer
|
|
2
2
|
def completed(resource_export_file)
|
3
3
|
@resource_export_file = resource_export_file
|
4
4
|
@library_group = LibraryGroup.site_config
|
5
|
-
from = "#{LibraryGroup.system_name(resource_export_file.user.profile.locale)} <#{@library_group.
|
5
|
+
from = "#{LibraryGroup.system_name(resource_export_file.user.profile.locale)} <#{@library_group.email}>"
|
6
6
|
subject = "#{I18n.t('resource_export_mailer.completed.subject')}: #{@resource_export_file.id}"
|
7
7
|
mail(from: from, to: resource_export_file.user.email, subject: subject)
|
8
8
|
end
|
@@ -10,7 +10,7 @@ class ResourceExportMailer < ApplicationMailer
|
|
10
10
|
def failed(resource_export_file)
|
11
11
|
@resource_export_file = resource_export_file
|
12
12
|
@library_group = LibraryGroup.site_config
|
13
|
-
from = "#{LibraryGroup.system_name(resource_export_file.user.profile.locale)} <#{@library_group.
|
13
|
+
from = "#{LibraryGroup.system_name(resource_export_file.user.profile.locale)} <#{@library_group.email}>"
|
14
14
|
subject = "#{I18n.t('resource_export_mailer.failed.subject')}: #{@resource_export_file.id}"
|
15
15
|
mail(from: from, to: resource_export_file.user.email, subject: subject)
|
16
16
|
end
|
@@ -2,7 +2,7 @@ class ResourceImportMailer < ApplicationMailer
|
|
2
2
|
def completed(resource_import_file)
|
3
3
|
@resource_import_file = resource_import_file
|
4
4
|
@library_group = LibraryGroup.site_config
|
5
|
-
from = "#{LibraryGroup.system_name(resource_import_file.user.profile.locale)} <#{@library_group.
|
5
|
+
from = "#{LibraryGroup.system_name(resource_import_file.user.profile.locale)} <#{@library_group.email}>"
|
6
6
|
subject = "#{I18n.t('resource_import_mailer.completed.subject')}: #{@resource_import_file.id}"
|
7
7
|
mail(from: from, to: resource_import_file.user.email, subject: subject)
|
8
8
|
end
|
@@ -10,7 +10,7 @@ class ResourceImportMailer < ApplicationMailer
|
|
10
10
|
def failed(resource_import_file)
|
11
11
|
@resource_import_file = resource_import_file
|
12
12
|
@library_group = LibraryGroup.site_config
|
13
|
-
from = "#{LibraryGroup.system_name(resource_import_file.user.profile.locale)} <#{@library_group.
|
13
|
+
from = "#{LibraryGroup.system_name(resource_import_file.user.profile.locale)} <#{@library_group.email}>"
|
14
14
|
subject = "#{I18n.t('resource_import_mailer.failed.subject')}: #{@resource_import_file.id}"
|
15
15
|
mail(from: from, to: resource_import_file.user.email, subject: subject)
|
16
16
|
end
|
data/app/models/agent.rb
CHANGED
@@ -17,7 +17,7 @@ class Agent < ApplicationRecord
|
|
17
17
|
has_many :derived_agents, through: :children, source: :child
|
18
18
|
has_many :original_agents, through: :parents, source: :parent
|
19
19
|
has_many :picture_files, as: :picture_attachable, dependent: :destroy
|
20
|
-
has_many :donates
|
20
|
+
has_many :donates, dependent: :destroy
|
21
21
|
has_many :donated_items, through: :donates, source: :item
|
22
22
|
has_many :owns, dependent: :destroy
|
23
23
|
has_many :items, through: :owns
|
@@ -97,7 +97,7 @@ class Agent < ApplicationRecord
|
|
97
97
|
def set_date_of_birth
|
98
98
|
return if birth_date.blank?
|
99
99
|
begin
|
100
|
-
date = Time.zone.parse(
|
100
|
+
date = Time.zone.parse(birth_date.to_s)
|
101
101
|
rescue ArgumentError
|
102
102
|
begin
|
103
103
|
date = Time.zone.parse("#{birth_date}-01")
|
@@ -115,7 +115,7 @@ class Agent < ApplicationRecord
|
|
115
115
|
def set_date_of_death
|
116
116
|
return if death_date.blank?
|
117
117
|
begin
|
118
|
-
date = Time.zone.parse(
|
118
|
+
date = Time.zone.parse(death_date.to_s)
|
119
119
|
rescue ArgumentError
|
120
120
|
begin
|
121
121
|
date = Time.zone.parse("#{death_date}-01")
|
@@ -289,7 +289,6 @@ end
|
|
289
289
|
# full_name_alternative :text
|
290
290
|
# created_at :datetime
|
291
291
|
# updated_at :datetime
|
292
|
-
# deleted_at :datetime
|
293
292
|
# zip_code_1 :string
|
294
293
|
# zip_code_2 :string
|
295
294
|
# address_1 :text
|
@@ -154,7 +154,7 @@ class AgentImportFile < ApplicationRecord
|
|
154
154
|
rows.each do |row|
|
155
155
|
row_num += 1
|
156
156
|
next if row['dummy'].to_s.strip.present?
|
157
|
-
agent = Agent.
|
157
|
+
agent = Agent.find_by(id: row['id'].to_s.strip)
|
158
158
|
if agent
|
159
159
|
agent.picture_files.destroy_all
|
160
160
|
agent.reload
|
@@ -173,13 +173,6 @@ class AgentImportFile < ApplicationRecord
|
|
173
173
|
end
|
174
174
|
|
175
175
|
private
|
176
|
-
def self.transition_class
|
177
|
-
AgentImportFileTransition
|
178
|
-
end
|
179
|
-
|
180
|
-
def self.initial_state
|
181
|
-
:pending
|
182
|
-
end
|
183
176
|
|
184
177
|
def open_import_file
|
185
178
|
tempfile = Tempfile.new(self.class.name.underscore)
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class CustomProperty < ApplicationRecord
|
2
|
+
belongs_to :resource, polymorphic: true
|
3
|
+
validates :label, presence: true
|
4
|
+
end
|
5
|
+
|
6
|
+
# == Schema Information
|
7
|
+
#
|
8
|
+
# Table name: custom_properties
|
9
|
+
#
|
10
|
+
# id :bigint not null, primary key
|
11
|
+
# resource_id :integer not null
|
12
|
+
# resource_type :string not null
|
13
|
+
# label :text not null
|
14
|
+
# value :text
|
15
|
+
# created_at :datetime not null
|
16
|
+
# updated_at :datetime not null
|
17
|
+
#
|
data/app/models/isbn_record.rb
CHANGED
data/app/models/issn_record.rb
CHANGED
data/app/models/item.rb
CHANGED
@@ -10,7 +10,7 @@ class Item < ApplicationRecord
|
|
10
10
|
delegate :display_name, to: :shelf, prefix: true
|
11
11
|
has_many :owns
|
12
12
|
has_many :agents, through: :owns
|
13
|
-
has_many :donates
|
13
|
+
has_many :donates, dependent: :destroy
|
14
14
|
has_many :donors, through: :donates, source: :agent
|
15
15
|
has_one :resource_import_result
|
16
16
|
belongs_to :manifestation, touch: true
|
@@ -19,6 +19,8 @@ class Item < ApplicationRecord
|
|
19
19
|
belongs_to :budget_type, optional: true
|
20
20
|
has_one :accept, dependent: :destroy
|
21
21
|
has_one :withdraw, dependent: :destroy
|
22
|
+
has_many :custom_properties, as: :resource, dependent: :destroy
|
23
|
+
accepts_nested_attributes_for :custom_properties, allow_destroy: true, reject_if: :all_blank
|
22
24
|
scope :accepted_between, lambda{|from, to| includes(:accept).where('items.created_at BETWEEN ? AND ?', Time.zone.parse(from).beginning_of_day, Time.zone.parse(to).end_of_day)}
|
23
25
|
|
24
26
|
belongs_to :shelf, counter_cache: true
|
@@ -96,6 +98,52 @@ class Item < ApplicationRecord
|
|
96
98
|
true
|
97
99
|
end
|
98
100
|
end
|
101
|
+
|
102
|
+
def self.csv_header(role: 'Guest')
|
103
|
+
Item.new.to_hash(role: role).keys
|
104
|
+
end
|
105
|
+
|
106
|
+
def to_hash(role: 'Guest')
|
107
|
+
record = {
|
108
|
+
item_id: id,
|
109
|
+
item_identifier: item_identifier,
|
110
|
+
call_number: call_number,
|
111
|
+
shelf: shelf.name,
|
112
|
+
item_note: note,
|
113
|
+
accepted_at: accept.try(:created_at),
|
114
|
+
acquired_at: acquired_at,
|
115
|
+
item_created_at: created_at,
|
116
|
+
item_updated_at: updated_at
|
117
|
+
}
|
118
|
+
|
119
|
+
if ['Administrator', 'Librarian'].include?(role)
|
120
|
+
record.merge!({
|
121
|
+
bookstore: bookstore.try(:name),
|
122
|
+
budget_type: budget_type.try(:name),
|
123
|
+
item_price: price,
|
124
|
+
memo: memo
|
125
|
+
})
|
126
|
+
|
127
|
+
# 最もカスタム項目の多い資料について、カスタム項目の個数を取得する
|
128
|
+
ActiveRecord::Base.connection.execute('SELECT max(record_count) FROM (SELECT count(*) AS record_count, resource_id, resource_type FROM custom_properties GROUP BY resource_id, resource_type) AS type_count ;').first.values[0].to_i.times do |i|
|
129
|
+
property = custom_properties[i]
|
130
|
+
if property
|
131
|
+
record[:"item_custom_property_#{i + 1}"] = "#{property.label}: #{property.value}"
|
132
|
+
else
|
133
|
+
record[:"item_custom_property_#{i + 1}"] = nil
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
if defined?(EnjuCirculation)
|
138
|
+
record.merge!({
|
139
|
+
use_restriction: use_restriction.try(:name),
|
140
|
+
total_checkouts: checkouts.count
|
141
|
+
})
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
record
|
146
|
+
end
|
99
147
|
end
|
100
148
|
|
101
149
|
# == Schema Information
|
@@ -107,7 +155,6 @@ end
|
|
107
155
|
# item_identifier :string
|
108
156
|
# created_at :datetime
|
109
157
|
# updated_at :datetime
|
110
|
-
# deleted_at :datetime
|
111
158
|
# shelf_id :integer default(1), not null
|
112
159
|
# include_supplements :boolean default(FALSE), not null
|
113
160
|
# note :text
|
data/app/models/manifestation.rb
CHANGED
@@ -26,11 +26,13 @@ class Manifestation < ApplicationRecord
|
|
26
26
|
has_one :doi_record
|
27
27
|
has_one :periodical_and_manifestation, dependent: :destroy
|
28
28
|
has_one :periodical, through: :periodical_and_manifestation
|
29
|
+
has_many :custom_properties, as: :resource, dependent: :destroy
|
29
30
|
accepts_nested_attributes_for :creators, allow_destroy: true, reject_if: :all_blank
|
30
31
|
accepts_nested_attributes_for :contributors, allow_destroy: true, reject_if: :all_blank
|
31
32
|
accepts_nested_attributes_for :publishers, allow_destroy: true, reject_if: :all_blank
|
32
33
|
accepts_nested_attributes_for :series_statements, allow_destroy: true, reject_if: :all_blank
|
33
34
|
accepts_nested_attributes_for :identifiers, allow_destroy: true, reject_if: :all_blank
|
35
|
+
accepts_nested_attributes_for :custom_properties, allow_destroy: true, reject_if: :all_blank
|
34
36
|
|
35
37
|
searchable do
|
36
38
|
text :title, default_boost: 2 do
|
@@ -109,7 +111,6 @@ class Manifestation < ApplicationRecord
|
|
109
111
|
end
|
110
112
|
time :created_at
|
111
113
|
time :updated_at
|
112
|
-
time :deleted_at
|
113
114
|
time :pub_date, multiple: true do
|
114
115
|
if series_master?
|
115
116
|
root_series_statement.root_manifestation.pub_dates
|
@@ -529,266 +530,128 @@ class Manifestation < ApplicationRecord
|
|
529
530
|
end
|
530
531
|
end
|
531
532
|
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
533
|
+
# CSVのヘッダ
|
534
|
+
# @param [String] role 権限
|
535
|
+
def self.csv_header(role: 'Guest')
|
536
|
+
Manifestation.new.to_hash(role: role).keys
|
537
|
+
end
|
538
|
+
|
539
|
+
# CSV出力用のハッシュ
|
540
|
+
# @param [String] role 権限
|
541
|
+
def to_hash(role: 'Guest')
|
542
|
+
record = {
|
543
|
+
manifestation_id: id,
|
544
|
+
title: original_title,
|
545
|
+
title_alternative: title_alternative,
|
546
|
+
title_transcription: title_transcription,
|
547
|
+
statement_of_responsibility: statement_of_responsibility,
|
548
|
+
serial: serial,
|
549
|
+
manifestation_identifier: manifestation_identifier,
|
550
|
+
creator: creators.pluck(:full_name).join('//'),
|
551
|
+
contributor: contributors.pluck(:full_name).join('//'),
|
552
|
+
publisher: publishers.pluck(:full_name).join('//'),
|
553
|
+
date_of_publication: date_of_publication,
|
554
|
+
year_of_publication: year_of_publication,
|
555
|
+
publication_place: publication_place,
|
556
|
+
manifestation_created_at: created_at,
|
557
|
+
manifestation_updated_at: updated_at,
|
558
|
+
carrier_type: carrier_type.name,
|
559
|
+
content_type: manifestation_content_type.name,
|
560
|
+
frequency: frequency.name,
|
561
|
+
language: language.name,
|
562
|
+
isbn: identifier_contents(:isbn).join('//'),
|
563
|
+
issn: identifier_contents(:issn).join('//'),
|
564
|
+
volume_number: volume_number,
|
565
|
+
volume_number_string: volume_number_string,
|
566
|
+
edition: edition,
|
567
|
+
edition_string: edition_string,
|
568
|
+
issue_number: issue_number,
|
569
|
+
issue_number_string: issue_number_string,
|
570
|
+
serial_number: serial_number,
|
571
|
+
extent: extent,
|
572
|
+
start_page: start_page,
|
573
|
+
end_page: end_page,
|
574
|
+
dimensions: dimensions,
|
575
|
+
height: height,
|
576
|
+
width: width,
|
577
|
+
depth: depth,
|
578
|
+
price: price,
|
579
|
+
access_address: access_address,
|
580
|
+
required_role: required_role.name,
|
581
|
+
description: description,
|
582
|
+
note: note
|
583
|
+
}
|
584
|
+
|
585
|
+
IdentifierType.find_each do |type|
|
586
|
+
record[type.name.to_sym] = identifiers.where(identifier_type: type).pluck(:body).join('//')
|
587
|
+
end
|
588
|
+
|
589
|
+
series = series_statements.order(:position)
|
590
|
+
record.merge!(
|
591
|
+
series_statement_id: series.pluck(:id).join('//'),
|
592
|
+
series_statement_original_title: series.pluck(:original_title).join('.//'),
|
593
|
+
series_statement_title_subseries: series.pluck(:title_subseries).join('//'),
|
594
|
+
series_statement_title_subseries_transcription: series.pluck(:title_subseries_transcription).join('//'),
|
595
|
+
series_statement_title_transcription: series.pluck(:title_transcription).join('//'),
|
596
|
+
series_statement_creator: series.pluck(:creator_string).join('//'),
|
597
|
+
series_statement_volume_number: series.pluck(:volume_number_string).join('//'),
|
598
|
+
series_statement_series_master: series.pluck(:series_master).join('//'),
|
599
|
+
series_statement_root_manifestation_id: series.pluck(:root_manifestation_id).join('//'),
|
600
|
+
series_statement_manifestation_id: series.pluck(:manifestation_id).join('//'),
|
601
|
+
series_statement_position: series.pluck(:position).join('//'),
|
602
|
+
series_statement_note: series.pluck(:note).join('//'),
|
603
|
+
series_statement_created_at: series.pluck(:created_at).join('//'),
|
604
|
+
series_statement_updated_at: series.pluck(:updated_at).join('//')
|
559
605
|
)
|
560
606
|
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
end
|
607
|
+
if ['Administrator', 'Librarian'].include?(role)
|
608
|
+
record.merge!({
|
609
|
+
memo: memo
|
610
|
+
})
|
566
611
|
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
612
|
+
# 最もカスタム項目の多い資料について、カスタム項目の個数を取得する
|
613
|
+
ActiveRecord::Base.connection.execute('SELECT max(record_count) FROM (SELECT count(*) AS record_count, resource_id, resource_type FROM custom_properties GROUP BY resource_id, resource_type) AS type_count ;').first.values[0].to_i.times do |i|
|
614
|
+
property = custom_properties[i]
|
615
|
+
if property
|
616
|
+
record[:"manifestation_custom_property_#{i + 1}"] = "#{property.label}: #{property.value}"
|
617
|
+
else
|
618
|
+
record[:"manifestation_custom_property_#{i + 1}"] = nil
|
619
|
+
end
|
620
|
+
end
|
576
621
|
end
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
budget_type
|
586
|
-
total_checkouts
|
587
|
-
)
|
588
|
-
end
|
589
|
-
header += %w(
|
590
|
-
circulation_status
|
591
|
-
shelf
|
592
|
-
library
|
593
|
-
item_created_at
|
594
|
-
item_updated_at
|
595
|
-
)
|
596
|
-
case role.to_sym
|
597
|
-
when :Administrator, :Librarian
|
598
|
-
header << "use_restriction"
|
622
|
+
|
623
|
+
if defined?(EnjuSubject)
|
624
|
+
SubjectHeadingType.find_each do |type|
|
625
|
+
record[:"subject:#{type.name}"] = subjects.where(subject_heading_type: type).pluck(:term).join('//')
|
626
|
+
end
|
627
|
+
ClassificationType.find_each do |type|
|
628
|
+
record[:"classification:#{type.name}"] = classifications.where(classification_type: type).pluck(:category).join('//')
|
629
|
+
end
|
599
630
|
end
|
600
631
|
|
601
|
-
|
632
|
+
record
|
602
633
|
end
|
603
634
|
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
else
|
615
|
-
item_lines << nil
|
616
|
-
end
|
617
|
-
if contributors.exists?
|
618
|
-
item_lines << contributors.pluck(:full_name).join("//")
|
619
|
-
else
|
620
|
-
item_lines << nil
|
621
|
-
end
|
622
|
-
if publishers.exists?
|
623
|
-
item_lines << publishers.pluck(:full_name).join("//")
|
624
|
-
else
|
625
|
-
item_lines << nil
|
626
|
-
end
|
627
|
-
item_lines << pub_date
|
628
|
-
item_lines << statement_of_responsibility
|
629
|
-
item_lines << price
|
630
|
-
item_lines << created_at
|
631
|
-
item_lines << updated_at
|
632
|
-
item_lines << manifestation_identifier
|
633
|
-
item_lines << access_address
|
634
|
-
item_lines << description.try(:gsub, /\r?\n/, '\n')
|
635
|
-
item_lines << note.try(:gsub, /\r?\n/, '\n')
|
636
|
-
item_lines << extent
|
637
|
-
item_lines << dimensions
|
638
|
-
item_lines << carrier_type.name
|
639
|
-
item_lines << edition
|
640
|
-
item_lines << edition_string
|
641
|
-
item_lines << volume_number
|
642
|
-
item_lines << volume_number_string
|
643
|
-
item_lines << issue_number
|
644
|
-
item_lines << issue_number_string
|
645
|
-
item_lines << serial_number
|
646
|
-
|
647
|
-
IdentifierType.order(:position).pluck(:name).each do |identifier_type|
|
648
|
-
identifier_list = identifier_contents(identifier_type.to_sym)
|
649
|
-
if identifier_list
|
650
|
-
item_lines << identifier_list.join("//")
|
651
|
-
else
|
652
|
-
item_lines << nil
|
635
|
+
# TSVでのエクスポート
|
636
|
+
# @param [String] role 権限
|
637
|
+
# @param [String] col_sep 区切り文字
|
638
|
+
def self.export(role: 'Guest', col_sep: "\t")
|
639
|
+
file = Tempfile.create('manifestation_export') do |f|
|
640
|
+
f.write (Manifestation.csv_header(role: role) + Item.csv_header(role: role)).to_csv(col_sep: col_sep)
|
641
|
+
Manifestation.find_each do |manifestation|
|
642
|
+
if manifestation.items.exists?
|
643
|
+
manifestation.items.each do |item|
|
644
|
+
f.write (manifestation.to_hash(role: role).values + item.to_hash(role: role).values).to_csv(col_sep: col_sep)
|
653
645
|
end
|
654
|
-
end
|
655
|
-
if defined?(EnjuSubject)
|
656
|
-
SubjectHeadingType.order(:position).each do |subject_heading_type|
|
657
|
-
if subjects.exists?
|
658
|
-
item_lines << subjects.where(subject_heading_type: subject_heading_type).pluck(:term).join('//')
|
659
|
-
else
|
660
|
-
item_lines << nil
|
661
|
-
end
|
662
|
-
end
|
663
|
-
ClassificationType.order(:position).each do |classification_type|
|
664
|
-
if classifications.exists?
|
665
|
-
item_lines << classifications.where(classification_type: classification_type).pluck(:category).join('//')
|
666
|
-
else
|
667
|
-
item_lines << nil
|
668
|
-
end
|
669
|
-
end
|
670
|
-
end
|
671
|
-
|
672
|
-
item_lines << i.id
|
673
|
-
item_lines << i.item_identifier
|
674
|
-
item_lines << i.call_number
|
675
|
-
item_lines << i.note.try(:gsub, /\r?\n/, '\n')
|
676
|
-
case options[:role].to_sym
|
677
|
-
when :Administrator, :Librarian
|
678
|
-
item_lines << i.price
|
679
|
-
end
|
680
|
-
item_lines << i.acquired_at
|
681
|
-
item_lines << i.accept.try(:created_at)
|
682
|
-
case options[:role].to_sym
|
683
|
-
when :Administrator, :Librarian
|
684
|
-
item_lines << i.bookstore.try(:name)
|
685
|
-
item_lines << i.budget_type.try(:name)
|
686
|
-
if defined?(EnjuCirculation)
|
687
|
-
item_lines << Checkout.where(item_id: i.id).count
|
688
|
-
else
|
689
|
-
item_lines << ''
|
690
|
-
end
|
691
|
-
end
|
692
|
-
if defined?(EnjuCirculation)
|
693
|
-
item_lines << i.circulation_status.try(:name)
|
694
|
-
else
|
695
|
-
item_lines << ''
|
696
|
-
end
|
697
|
-
item_lines << i.shelf.name
|
698
|
-
item_lines << i.shelf.library.name
|
699
|
-
item_lines << i.created_at
|
700
|
-
item_lines << i.updated_at
|
701
|
-
case options[:role].to_sym
|
702
|
-
when :Administrator, :Librarian
|
703
|
-
if defined?(EnjuCirculation)
|
704
|
-
item_lines << i.use_restriction.try(:name)
|
705
|
-
else
|
706
|
-
item_lines << ''
|
707
|
-
end
|
708
|
-
end
|
709
|
-
lines << item_lines
|
710
|
-
end
|
711
|
-
else
|
712
|
-
line = []
|
713
|
-
line << id
|
714
|
-
line << original_title
|
715
|
-
line << title_transcription
|
716
|
-
if creators.exists?
|
717
|
-
line << creators.pluck(:full_name).join("//")
|
718
|
-
else
|
719
|
-
line << nil
|
720
|
-
end
|
721
|
-
if contributors.exists?
|
722
|
-
line << contributors.pluck(:full_name).join("//")
|
723
|
-
else
|
724
|
-
line << nil
|
725
|
-
end
|
726
|
-
if publishers.exists?
|
727
|
-
line << publishers.pluck(:full_name).join("//")
|
728
|
-
else
|
729
|
-
line << nil
|
730
|
-
end
|
731
|
-
line << pub_date
|
732
|
-
line << statement_of_responsibility
|
733
|
-
line << price
|
734
|
-
line << created_at
|
735
|
-
line << updated_at
|
736
|
-
line << manifestation_identifier
|
737
|
-
line << access_address
|
738
|
-
line << description.try(:gsub, /\r?\n/, '\n')
|
739
|
-
line << note.try(:gsub, /\r?\n/, '\n')
|
740
|
-
line << extent
|
741
|
-
line << dimensions
|
742
|
-
line << carrier_type.name
|
743
|
-
line << edition
|
744
|
-
line << edition_string
|
745
|
-
line << volume_number
|
746
|
-
line << volume_number_string
|
747
|
-
line << issue_number
|
748
|
-
line << issue_number_string
|
749
|
-
line << serial_number
|
750
|
-
|
751
|
-
IdentifierType.order(:position).pluck(:name).each do |identifier_type|
|
752
|
-
identifier_list = identifier_contents(identifier_type.to_sym)
|
753
|
-
if identifier_list
|
754
|
-
line << identifier_list.join("//")
|
755
646
|
else
|
756
|
-
|
757
|
-
end
|
758
|
-
end
|
759
|
-
if defined?(EnjuSubject)
|
760
|
-
SubjectHeadingType.order(:position).each do |subject_heading_type|
|
761
|
-
if subjects.exists?
|
762
|
-
line << subjects.where(subject_heading_type: subject_heading_type).pluck(:term).join('//')
|
763
|
-
else
|
764
|
-
line << nil
|
765
|
-
end
|
766
|
-
end
|
767
|
-
ClassificationType.order(:position).each do |classification_type|
|
768
|
-
if classifications.exists?
|
769
|
-
line << classifications.where(classification_type: classification_type).pluck(:category).join('//')
|
770
|
-
else
|
771
|
-
line << nil
|
772
|
-
end
|
647
|
+
f.write manifestation.to_hash(role: role).values.to_csv(col_sep: col_sep)
|
773
648
|
end
|
774
649
|
end
|
775
650
|
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
if options[:format] == :txt
|
780
|
-
lines.map{|i| i.to_csv(col_sep: "\t")}.join
|
781
|
-
else
|
782
|
-
lines
|
651
|
+
f.rewind
|
652
|
+
f.read
|
783
653
|
end
|
784
|
-
end
|
785
654
|
|
786
|
-
def self.export(options = {format: :txt, role: :Guest})
|
787
|
-
file = ''
|
788
|
-
file += Manifestation.csv_header(options[:role], col_sep: "\t") if options[:format].to_sym == :txt
|
789
|
-
Manifestation.find_each do |manifestation|
|
790
|
-
file += manifestation.to_csv(options)
|
791
|
-
end
|
792
655
|
file
|
793
656
|
end
|
794
657
|
|
@@ -824,7 +687,6 @@ end
|
|
824
687
|
# date_copyrighted :datetime
|
825
688
|
# created_at :datetime
|
826
689
|
# updated_at :datetime
|
827
|
-
# deleted_at :datetime
|
828
690
|
# access_address :string
|
829
691
|
# language_id :integer default(1), not null
|
830
692
|
# carrier_type_id :integer default(1), not null
|