enju_biblio 0.3.9 → 0.3.10.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/content_types_controller.rb +1 -1
- data/app/controllers/item_custom_properties_controller.rb +64 -0
- data/app/controllers/items_controller.rb +3 -0
- data/app/controllers/manifestation_custom_properties_controller.rb +64 -0
- data/app/controllers/manifestations_controller.rb +8 -5
- data/app/controllers/resource_import_results_controller.rb +6 -2
- data/app/models/agent_type.rb +0 -1
- data/app/models/carrier_type.rb +0 -1
- data/app/models/content_type.rb +0 -1
- data/app/models/form_of_work.rb +1 -2
- data/app/models/frequency.rb +0 -1
- data/app/models/identifier_type.rb +0 -1
- data/app/models/item.rb +8 -1
- data/app/models/item_custom_property.rb +18 -0
- data/app/models/item_custom_value.rb +17 -0
- data/app/models/license.rb +0 -1
- data/app/models/manifestation.rb +18 -0
- data/app/models/manifestation_custom_property.rb +18 -0
- data/app/models/manifestation_custom_value.rb +17 -0
- data/app/models/medium_of_performance.rb +1 -2
- data/app/models/resource_import_file.rb +81 -9
- data/app/policies/item_custom_property_policy.rb +21 -0
- data/app/policies/manifestation_custom_property_policy.rb +21 -0
- data/app/views/item_custom_properties/_form.html.erb +32 -0
- data/app/views/item_custom_properties/edit.html.erb +6 -0
- data/app/views/item_custom_properties/index.html.erb +36 -0
- data/app/views/item_custom_properties/new.html.erb +5 -0
- data/app/views/item_custom_properties/show.html.erb +21 -0
- data/app/views/items/_form.html.erb +13 -0
- data/app/views/items/show.html.erb +6 -0
- data/app/views/manifestation_custom_properties/_form.html.erb +32 -0
- data/app/views/manifestation_custom_properties/edit.html.erb +6 -0
- data/app/views/manifestation_custom_properties/index.html.erb +36 -0
- data/app/views/manifestation_custom_properties/new.html.erb +5 -0
- data/app/views/manifestation_custom_properties/show.html.erb +21 -0
- data/app/views/manifestations/_form.html.erb +13 -0
- data/app/views/manifestations/_show_detail_librarian.html.erb +8 -0
- data/app/views/picture_files/edit.html.erb +4 -0
- data/config/locales/translation_en.yml +20 -8
- data/config/locales/translation_ja.yml +20 -8
- data/config/routes.rb +2 -0
- data/db/migrate/20200425072340_create_manifestation_custom_properties.rb +12 -0
- data/db/migrate/20200425072349_create_item_custom_properties.rb +12 -0
- data/db/migrate/20200425074758_create_manifestation_custom_values.rb +12 -0
- data/db/migrate/20200425074822_create_item_custom_values.rb +12 -0
- data/lib/enju_biblio/version.rb +1 -1
- data/spec/cassette_library/ResourceImportFile/when_its_mode_is_create_/when_it_is_written_in_utf-8/should_import_custom_values.yml +121 -0
- data/spec/cassette_library/resource_import_results/index_txt_ruby/renders_a_list_of_resource_import_results.yml +121 -0
- data/spec/controllers/content_types_controller_spec.rb +1 -1
- data/spec/controllers/items_controller_spec.rb +22 -0
- data/spec/controllers/manifestations_controller_spec.rb +22 -0
- data/spec/dummy/db/schema.rb +43 -21
- data/spec/factories/item_custom_property.rb +6 -0
- data/spec/factories/item_custom_value.rb +6 -0
- data/spec/factories/manifestation_custom_property.rb +6 -0
- data/spec/factories/manifestation_custom_value.rb +6 -0
- data/spec/fixtures/item_custom_properties.yml +24 -0
- data/spec/fixtures/library_groups.yml +0 -2
- data/spec/fixtures/manifestation_custom_properties.yml +24 -0
- data/spec/models/item_custom_property_spec.rb +18 -0
- data/spec/models/item_custom_value_spec.rb +17 -0
- data/spec/models/manifestation_custom_property_spec.rb +18 -0
- data/spec/models/manifestation_custom_value_spec.rb +17 -0
- data/spec/models/manifestation_spec.rb +15 -0
- data/spec/models/resource_import_file_spec.rb +38 -12
- data/spec/requests/item_custom_properties_spec.rb +129 -0
- data/spec/requests/manifestation_custom_properties_spec.rb +129 -0
- data/spec/routing/item_custom_properties_routing_spec.rb +38 -0
- data/spec/routing/manifestation_custom_properties_routing_spec.rb +38 -0
- data/spec/system/items_spec.rb +12 -0
- data/spec/system/manifestations_spec.rb +12 -0
- data/spec/views/item_custom_properties/edit.html.erb_spec.rb +21 -0
- data/spec/views/item_custom_properties/index.html.erb_spec.rb +24 -0
- data/spec/views/item_custom_properties/new.html.erb_spec.rb +21 -0
- data/spec/views/item_custom_properties/show.html.erb_spec.rb +16 -0
- data/spec/views/manifestation_custom_properties/edit.html.erb_spec.rb +21 -0
- data/spec/views/manifestation_custom_properties/index.html.erb_spec.rb +24 -0
- data/spec/views/manifestation_custom_properties/new.html.erb_spec.rb +21 -0
- data/spec/views/manifestation_custom_properties/show.html.erb_spec.rb +16 -0
- data/spec/views/resource_import_results/index.txt.ruby_spec.rb +4 -4
- metadata +569 -497
- data/db/migrate/20200322053443_add_default_custom_label_to_library_group.rb +0 -6
- data/db/migrate/20200322083313_create_custom_labels.rb +0 -10
- data/db/migrate/20200322083458_create_custom_properties.rb +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77d5c642a35ec134208140ee6fbf038219d633619ba7a4a50927bcd14522e685
|
4
|
+
data.tar.gz: 814c6c8c7c795efa2cc55365805e1bbee2d7689d730593c56f00d012a7d4fa52
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 969d8e56c2adfdc2b82b63bf193d28092348c7cb01675cc19e59e936e9ab73ab9878f8403a82397420c3f9469d37bbbcdf610f3d465980c6d5607d9219be510b
|
7
|
+
data.tar.gz: be66e593d2fd98df02e694169b53554aadd7a9d3369e731a96eede7bd3ef7336a48372025d55a4de462156d8d6018c4ee5b02954b49676f0d9a20cd90e161c96
|
@@ -0,0 +1,64 @@
|
|
1
|
+
class ItemCustomPropertiesController < ApplicationController
|
2
|
+
before_action :set_item_custom_property, only: [:show, :edit, :update, :destroy]
|
3
|
+
before_action :check_policy, only: [:index, :new, :create ]
|
4
|
+
|
5
|
+
# GET /item_custom_properties
|
6
|
+
def index
|
7
|
+
@item_custom_properties = ItemCustomProperty.order(:position)
|
8
|
+
end
|
9
|
+
|
10
|
+
# GET /item_custom_properties/1
|
11
|
+
def show
|
12
|
+
end
|
13
|
+
|
14
|
+
# GET /item_custom_properties/new
|
15
|
+
def new
|
16
|
+
@item_custom_property = ItemCustomProperty.new
|
17
|
+
end
|
18
|
+
|
19
|
+
# GET /item_custom_properties/1/edit
|
20
|
+
def edit
|
21
|
+
end
|
22
|
+
|
23
|
+
# POST /item_custom_properties
|
24
|
+
def create
|
25
|
+
@item_custom_property = ItemCustomProperty.new(item_custom_property_params)
|
26
|
+
|
27
|
+
if @item_custom_property.save
|
28
|
+
redirect_to @item_custom_property, notice: 'Item custom property was successfully created.'
|
29
|
+
else
|
30
|
+
render :new
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# PATCH/PUT /item_custom_properties/1
|
35
|
+
def update
|
36
|
+
if @item_custom_property.update(item_custom_property_params)
|
37
|
+
redirect_to @item_custom_property, notice: 'Item custom property was successfully updated.'
|
38
|
+
else
|
39
|
+
render :edit
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# DELETE /item_custom_properties/1
|
44
|
+
def destroy
|
45
|
+
@item_custom_property.destroy
|
46
|
+
redirect_to item_custom_properties_url, notice: 'Item custom property was successfully destroyed.'
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
# Use callbacks to share common setup or constraints between actions.
|
51
|
+
def set_item_custom_property
|
52
|
+
@item_custom_property = ItemCustomProperty.find(params[:id])
|
53
|
+
authorize @item_custom_property
|
54
|
+
end
|
55
|
+
|
56
|
+
def check_policy
|
57
|
+
authorize ItemCustomProperty
|
58
|
+
end
|
59
|
+
|
60
|
+
# Only allow a trusted parameter "white list" through.
|
61
|
+
def item_custom_property_params
|
62
|
+
params.require(:item_custom_property).permit(:name, :display_name, :note)
|
63
|
+
end
|
64
|
+
end
|
@@ -274,6 +274,9 @@ class ItemsController < ApplicationController
|
|
274
274
|
:binding_item_identifier, :binding_call_number, :binded_at,
|
275
275
|
:use_restriction_id, :memo,
|
276
276
|
{item_has_use_restriction_attributes: :use_restriction_id}, # EnjuCirculation
|
277
|
+
{item_custom_values_attributes: [
|
278
|
+
:id, :item_custom_property_id, :item_id, :value,:_destroy
|
279
|
+
]}
|
277
280
|
)
|
278
281
|
end
|
279
282
|
|
@@ -0,0 +1,64 @@
|
|
1
|
+
class ManifestationCustomPropertiesController < ApplicationController
|
2
|
+
before_action :set_manifestation_custom_property, only: [:show, :edit, :update, :destroy]
|
3
|
+
before_action :check_policy, only: [:index, :new, :create ]
|
4
|
+
|
5
|
+
# GET /manifestation_custom_properties
|
6
|
+
def index
|
7
|
+
@manifestation_custom_properties = ManifestationCustomProperty.order(:position)
|
8
|
+
end
|
9
|
+
|
10
|
+
# GET /manifestation_custom_properties/1
|
11
|
+
def show
|
12
|
+
end
|
13
|
+
|
14
|
+
# GET /manifestation_custom_properties/new
|
15
|
+
def new
|
16
|
+
@manifestation_custom_property = ManifestationCustomProperty.new
|
17
|
+
end
|
18
|
+
|
19
|
+
# GET /manifestation_custom_properties/1/edit
|
20
|
+
def edit
|
21
|
+
end
|
22
|
+
|
23
|
+
# POST /manifestation_custom_properties
|
24
|
+
def create
|
25
|
+
@manifestation_custom_property = ManifestationCustomProperty.new(manifestation_custom_property_params)
|
26
|
+
|
27
|
+
if @manifestation_custom_property.save
|
28
|
+
redirect_to @manifestation_custom_property, notice: 'Manifestation custom property was successfully created.'
|
29
|
+
else
|
30
|
+
render :new
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# PATCH/PUT /manifestation_custom_properties/1
|
35
|
+
def update
|
36
|
+
if @manifestation_custom_property.update(manifestation_custom_property_params)
|
37
|
+
redirect_to @manifestation_custom_property, notice: 'Manifestation custom property was successfully updated.'
|
38
|
+
else
|
39
|
+
render :edit
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# DELETE /manifestation_custom_properties/1
|
44
|
+
def destroy
|
45
|
+
@manifestation_custom_property.destroy
|
46
|
+
redirect_to manifestation_custom_properties_url, notice: 'Manifestation custom property was successfully destroyed.'
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
# Use callbacks to share common setup or constraints between actions.
|
51
|
+
def set_manifestation_custom_property
|
52
|
+
@manifestation_custom_property = ManifestationCustomProperty.find(params[:id])
|
53
|
+
authorize @manifestation_custom_property
|
54
|
+
end
|
55
|
+
|
56
|
+
def check_policy
|
57
|
+
authorize ManifestationCustomProperty
|
58
|
+
end
|
59
|
+
|
60
|
+
# Only allow a trusted parameter "white list" through.
|
61
|
+
def manifestation_custom_property_params
|
62
|
+
params.require(:manifestation_custom_property).permit(:name, :display_name, :note)
|
63
|
+
end
|
64
|
+
end
|
@@ -549,6 +549,9 @@ class ManifestationsController < ApplicationController
|
|
549
549
|
{identifiers_attributes: [
|
550
550
|
:id, :body, :identifier_type_id,
|
551
551
|
:_destroy
|
552
|
+
]},
|
553
|
+
{manifestation_custom_values_attributes: [
|
554
|
+
:id, :manifestation_custom_property_id, :manifestation_id, :value,:_destroy
|
552
555
|
]}
|
553
556
|
)
|
554
557
|
end
|
@@ -734,12 +737,12 @@ class ManifestationsController < ApplicationController
|
|
734
737
|
end
|
735
738
|
|
736
739
|
def prepare_options
|
737
|
-
@carrier_types = CarrierType.select([:id, :display_name, :position])
|
738
|
-
@content_types = ContentType.select([:id, :display_name, :position])
|
740
|
+
@carrier_types = CarrierType.order(:position).select([:id, :display_name, :position])
|
741
|
+
@content_types = ContentType.order(:position).select([:id, :display_name, :position])
|
739
742
|
@roles = Role.select([:id, :display_name, :position])
|
740
|
-
@languages = Language.select([:id, :display_name, :position])
|
741
|
-
@frequencies = Frequency.select([:id, :display_name, :position])
|
742
|
-
@identifier_types = IdentifierType.select([:id, :display_name, :position])
|
743
|
+
@languages = Language.order(:position).select([:id, :display_name, :position])
|
744
|
+
@frequencies = Frequency.order(:position).select([:id, :display_name, :position])
|
745
|
+
@identifier_types = IdentifierType.order(:position).select([:id, :display_name, :position])
|
743
746
|
@nii_types = NiiType.select([:id, :display_name, :position]) if defined?(EnjuNii)
|
744
747
|
if defined?(EnjuSubject)
|
745
748
|
@subject_types = SubjectType.select([:id, :display_name, :position])
|
@@ -5,9 +5,13 @@ class ResourceImportResultsController < ApplicationController
|
|
5
5
|
# GET /resource_import_results
|
6
6
|
# GET /resource_import_results.json
|
7
7
|
def index
|
8
|
-
@resource_import_file = ResourceImportFile.
|
8
|
+
@resource_import_file = ResourceImportFile.find_by(id: params[:resource_import_file_id])
|
9
9
|
if @resource_import_file
|
10
|
-
|
10
|
+
if params[:format].to_s.downcase == 'txt'
|
11
|
+
@resource_import_results = @resource_import_file.resource_import_results
|
12
|
+
else
|
13
|
+
@resource_import_results = @resource_import_file.resource_import_results.page(params[:page])
|
14
|
+
end
|
11
15
|
else
|
12
16
|
@resource_import_results = ResourceImportResult.page(params[:page])
|
13
17
|
end
|
data/app/models/agent_type.rb
CHANGED
data/app/models/carrier_type.rb
CHANGED
data/app/models/content_type.rb
CHANGED
data/app/models/form_of_work.rb
CHANGED
data/app/models/frequency.rb
CHANGED
data/app/models/item.rb
CHANGED
@@ -19,10 +19,12 @@ 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
|
-
|
22
|
+
has_many :item_custom_values, -> { joins(:item_custom_property).order(:position) }
|
23
23
|
|
24
24
|
belongs_to :shelf, counter_cache: true
|
25
|
+
accepts_nested_attributes_for :item_custom_values, reject_if: :all_blank
|
25
26
|
|
27
|
+
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)}
|
26
28
|
validates_associated :bookstore
|
27
29
|
validates :manifestation_id, presence: true
|
28
30
|
validates :item_identifier, allow_blank: true, uniqueness: true,
|
@@ -122,6 +124,11 @@ class Item < ApplicationRecord
|
|
122
124
|
memo: memo
|
123
125
|
})
|
124
126
|
|
127
|
+
ItemCustomProperty.order(:position).each do |custom_property|
|
128
|
+
custom_value = item_custom_values.find_by(item_custom_property: custom_property)
|
129
|
+
record[:"item:#{custom_property.name}"] = custom_value.try(:value)
|
130
|
+
end
|
131
|
+
|
125
132
|
if defined?(EnjuCirculation)
|
126
133
|
record.merge!({
|
127
134
|
use_restriction: use_restriction.try(:name),
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class ItemCustomProperty < ApplicationRecord
|
2
|
+
include MasterModel
|
3
|
+
validates :name, presence: true, uniqueness: true
|
4
|
+
acts_as_list
|
5
|
+
end
|
6
|
+
|
7
|
+
# == Schema Information
|
8
|
+
#
|
9
|
+
# Table name: item_custom_properties
|
10
|
+
#
|
11
|
+
# id :bigint not null, primary key
|
12
|
+
# name :string not null
|
13
|
+
# display_name_translations :jsonb not null
|
14
|
+
# note :text
|
15
|
+
# position :integer default(1), not null
|
16
|
+
# created_at :datetime not null
|
17
|
+
# updated_at :datetime not null
|
18
|
+
#
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class ItemCustomValue < ApplicationRecord
|
2
|
+
belongs_to :item_custom_property
|
3
|
+
belongs_to :item, required: false
|
4
|
+
validates :item_custom_property, uniqueness: {scope: :item_id}
|
5
|
+
end
|
6
|
+
|
7
|
+
# == Schema Information
|
8
|
+
#
|
9
|
+
# Table name: item_custom_values
|
10
|
+
#
|
11
|
+
# id :bigint not null, primary key
|
12
|
+
# item_custom_property_id :bigint not null
|
13
|
+
# item_id :bigint not null
|
14
|
+
# value :text
|
15
|
+
# created_at :datetime not null
|
16
|
+
# updated_at :datetime not null
|
17
|
+
#
|
data/app/models/license.rb
CHANGED
data/app/models/manifestation.rb
CHANGED
@@ -25,11 +25,13 @@ class Manifestation < ApplicationRecord
|
|
25
25
|
belongs_to :required_role, class_name: 'Role', foreign_key: 'required_role_id'
|
26
26
|
has_one :resource_import_result
|
27
27
|
has_many :identifiers, dependent: :destroy
|
28
|
+
has_many :manifestation_custom_values, -> { joins(:manifestation_custom_property).order(:position) }
|
28
29
|
accepts_nested_attributes_for :creators, allow_destroy: true, reject_if: :all_blank
|
29
30
|
accepts_nested_attributes_for :contributors, allow_destroy: true, reject_if: :all_blank
|
30
31
|
accepts_nested_attributes_for :publishers, allow_destroy: true, reject_if: :all_blank
|
31
32
|
accepts_nested_attributes_for :series_statements, allow_destroy: true, reject_if: :all_blank
|
32
33
|
accepts_nested_attributes_for :identifiers, allow_destroy: true, reject_if: :all_blank
|
34
|
+
accepts_nested_attributes_for :manifestation_custom_values, reject_if: :all_blank
|
33
35
|
|
34
36
|
searchable do
|
35
37
|
text :title, default_boost: 2 do
|
@@ -606,6 +608,10 @@ class Manifestation < ApplicationRecord
|
|
606
608
|
record.merge!({
|
607
609
|
memo: memo
|
608
610
|
})
|
611
|
+
ManifestationCustomProperty.order(:position).each do |custom_property|
|
612
|
+
custom_value = manifestation_custom_values.find_by(manifestation_custom_property: custom_property)
|
613
|
+
record[:"manifestation:#{custom_property.name}"] = custom_value.try(:value)
|
614
|
+
end
|
609
615
|
end
|
610
616
|
|
611
617
|
if defined?(EnjuSubject)
|
@@ -659,6 +665,18 @@ class Manifestation < ApplicationRecord
|
|
659
665
|
]
|
660
666
|
}.flatten
|
661
667
|
end
|
668
|
+
|
669
|
+
def set_custom_property(row)
|
670
|
+
ManifestationCustomProperty.all.each do |property|
|
671
|
+
if row[property]
|
672
|
+
custom_value = ManifestationCustomValue.new(
|
673
|
+
manifestation: self,
|
674
|
+
manifestation_custom_property: property,
|
675
|
+
value: row[property]
|
676
|
+
)
|
677
|
+
end
|
678
|
+
end
|
679
|
+
end
|
662
680
|
end
|
663
681
|
|
664
682
|
# == Schema Information
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class ManifestationCustomProperty < ApplicationRecord
|
2
|
+
include MasterModel
|
3
|
+
validates :name, presence: true, uniqueness: true
|
4
|
+
acts_as_list
|
5
|
+
end
|
6
|
+
|
7
|
+
# == Schema Information
|
8
|
+
#
|
9
|
+
# Table name: manifestation_custom_properties
|
10
|
+
#
|
11
|
+
# id :bigint not null, primary key
|
12
|
+
# name :string not null
|
13
|
+
# display_name_translations :jsonb not null
|
14
|
+
# note :text
|
15
|
+
# position :integer default(1), not null
|
16
|
+
# created_at :datetime not null
|
17
|
+
# updated_at :datetime not null
|
18
|
+
#
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class ManifestationCustomValue < ApplicationRecord
|
2
|
+
belongs_to :manifestation_custom_property
|
3
|
+
belongs_to :manifestation, required: false
|
4
|
+
validates :manifestation_custom_property, uniqueness: {scope: :manifestation_id}
|
5
|
+
end
|
6
|
+
|
7
|
+
# == Schema Information
|
8
|
+
#
|
9
|
+
# Table name: manifestation_custom_values
|
10
|
+
#
|
11
|
+
# id :bigint not null, primary key
|
12
|
+
# manifestation_custom_property_id :bigint not null
|
13
|
+
# manifestation_id :bigint not null
|
14
|
+
# value :text
|
15
|
+
# created_at :datetime not null
|
16
|
+
# updated_at :datetime not null
|
17
|
+
#
|
@@ -76,12 +76,13 @@ class ResourceImportFile < ApplicationRecord
|
|
76
76
|
#end
|
77
77
|
row_num = 1
|
78
78
|
|
79
|
-
ResourceImportResult.create!(resource_import_file_id: id, body: rows.headers.join("\t"))
|
79
|
+
ResourceImportResult.create!(resource_import_file_id: id, body: (%w( imported_manifestation_id imported_item_id ) + rows.headers).join("\t"))
|
80
80
|
rows.each do |row|
|
81
81
|
row_num += 1
|
82
|
-
import_result = ResourceImportResult.
|
82
|
+
import_result = ResourceImportResult.new(resource_import_file_id: id)
|
83
83
|
if row['dummy'].to_s.strip.present?
|
84
84
|
import_result.error_message = "line #{row_num}: #{I18n.t('import.dummy')}"
|
85
|
+
import_result.body = ([nil, nil] + row.fields).join("\t")
|
85
86
|
import_result.save!
|
86
87
|
next
|
87
88
|
end
|
@@ -92,6 +93,7 @@ class ResourceImportFile < ApplicationRecord
|
|
92
93
|
import_result.item = item
|
93
94
|
import_result.manifestation = item.manifestation
|
94
95
|
import_result.error_message = "line #{row_num}: #{I18n.t('import.item_found')}"
|
96
|
+
import_result.body = ([item.manifestation.id, item.id] + row.fields).join("\t")
|
95
97
|
import_result.save!
|
96
98
|
num[:item_found] += 1
|
97
99
|
next
|
@@ -187,8 +189,13 @@ class ResourceImportFile < ApplicationRecord
|
|
187
189
|
import_result.manifestation = manifestation
|
188
190
|
|
189
191
|
if manifestation
|
192
|
+
ResourceImportFile.import_manifestation_custom_value(row, manifestation).each do |value|
|
193
|
+
value.update!(manifestation: manifestation)
|
194
|
+
end
|
195
|
+
|
196
|
+
item = nil
|
190
197
|
if item_identifier.present? || row['shelf'].present? || row['call_number'].present?
|
191
|
-
|
198
|
+
item = create_item(row, manifestation)
|
192
199
|
else
|
193
200
|
if manifestation.fulltext_content?
|
194
201
|
item = create_item(row, manifestation)
|
@@ -200,17 +207,21 @@ class ResourceImportFile < ApplicationRecord
|
|
200
207
|
end
|
201
208
|
num[:failed] += 1
|
202
209
|
end
|
210
|
+
|
211
|
+
if item
|
212
|
+
ResourceImportFile.import_item_custom_value(row, item).each do |value|
|
213
|
+
value.update!(item: item)
|
214
|
+
end
|
215
|
+
|
216
|
+
import_result.item = item
|
217
|
+
end
|
203
218
|
else
|
204
219
|
num[:failed] += 1
|
205
220
|
end
|
206
221
|
|
222
|
+
import_result.body = ([manifestation.try(:id), item.try(:id)] + row.fields).join("\t")
|
207
223
|
import_result.save!
|
208
|
-
num[:item_imported] +=1 if import_result.item
|
209
|
-
|
210
|
-
if row_num % 50 == 0
|
211
|
-
Sunspot.commit
|
212
|
-
GC.start
|
213
|
-
end
|
224
|
+
num[:item_imported] += 1 if import_result.item
|
214
225
|
end
|
215
226
|
|
216
227
|
Sunspot.commit
|
@@ -361,6 +372,14 @@ class ResourceImportFile < ApplicationRecord
|
|
361
372
|
item.include_supplements = false if item.include_supplements
|
362
373
|
end
|
363
374
|
end
|
375
|
+
|
376
|
+
ResourceImportFile.import_item_custom_value(row, item).each do |value|
|
377
|
+
value.update!(item: item)
|
378
|
+
end
|
379
|
+
ResourceImportFile.import_manifestation_custom_value(row, item.manifestation).each do |value|
|
380
|
+
value.update!(manifestation: item.manifestation)
|
381
|
+
end
|
382
|
+
|
364
383
|
item.manifestation.reload
|
365
384
|
item.save!
|
366
385
|
import_result.item = item
|
@@ -372,6 +391,9 @@ class ResourceImportFile < ApplicationRecord
|
|
372
391
|
end
|
373
392
|
if manifestation
|
374
393
|
fetch(row, edit_mode: 'update')
|
394
|
+
ResourceImportFile.import_manifestation_custom_value(row, manifestation).each do |value|
|
395
|
+
value.update!(manifestation: manifestation)
|
396
|
+
end
|
375
397
|
import_result.manifestation = manifestation
|
376
398
|
end
|
377
399
|
end
|
@@ -482,6 +504,9 @@ class ResourceImportFile < ApplicationRecord
|
|
482
504
|
use_restriction include_supplements item_note item_url
|
483
505
|
dummy
|
484
506
|
)
|
507
|
+
header_columns += ManifestationCustomProperty.order(:position).pluck(:name).map{|c| "manifestation:#{c}"}
|
508
|
+
header_columns += ItemCustomProperty.order(:position).pluck(:name).map{|c| "item:#{c}"}
|
509
|
+
|
485
510
|
if defined?(EnjuSubject)
|
486
511
|
header_columns += ClassificationType.order(:position).pluck(:name).map{|c| "classification:#{c}"}
|
487
512
|
header_columns += SubjectHeadingType.order(:position).pluck(:name).map{|s| "subject:#{s}"}
|
@@ -764,6 +789,7 @@ class ResourceImportFile < ApplicationRecord
|
|
764
789
|
manifestation.set_agent_role_type(publishers_list, scope: :publisher)
|
765
790
|
end
|
766
791
|
end
|
792
|
+
|
767
793
|
manifestation
|
768
794
|
end
|
769
795
|
|
@@ -790,6 +816,52 @@ class ResourceImportFile < ApplicationRecord
|
|
790
816
|
end
|
791
817
|
identifiers
|
792
818
|
end
|
819
|
+
|
820
|
+
def self.import_manifestation_custom_value(row, manifestation)
|
821
|
+
values = []
|
822
|
+
ManifestationCustomProperty.order(:position).pluck(:name).map{|c| "manifestation:#{c}"}.each do |column_name|
|
823
|
+
value = nil
|
824
|
+
property = column_name.split(':').last
|
825
|
+
next if row[column_name].blank?
|
826
|
+
if manifestation
|
827
|
+
value = manifestation.manifestation_custom_values.find_by(manifestation_custom_property: property)
|
828
|
+
end
|
829
|
+
|
830
|
+
if value
|
831
|
+
value.value = row[column_name]
|
832
|
+
else
|
833
|
+
value = ManifestationCustomValue.new(
|
834
|
+
manifestation_custom_property: ManifestationCustomProperty.find_by(name: property),
|
835
|
+
value: row[column_name]
|
836
|
+
)
|
837
|
+
end
|
838
|
+
values << value
|
839
|
+
end
|
840
|
+
values
|
841
|
+
end
|
842
|
+
|
843
|
+
def self.import_item_custom_value(row, item)
|
844
|
+
values = []
|
845
|
+
ItemCustomProperty.order(:position).pluck(:name).map{|c| "item:#{c}"}.each do |column_name|
|
846
|
+
value = nil
|
847
|
+
property = column_name.split(':').last
|
848
|
+
next if row[column_name].blank?
|
849
|
+
if item
|
850
|
+
value = item.item_custom_values.find_by(item_custom_property: property)
|
851
|
+
end
|
852
|
+
|
853
|
+
if value
|
854
|
+
value.value = row[column_name]
|
855
|
+
else
|
856
|
+
value = ItemCustomValue.new(
|
857
|
+
item_custom_property: ItemCustomProperty.find_by(name: property),
|
858
|
+
value: row[column_name]
|
859
|
+
)
|
860
|
+
end
|
861
|
+
values << value
|
862
|
+
end
|
863
|
+
values
|
864
|
+
end
|
793
865
|
end
|
794
866
|
|
795
867
|
# == Schema Information
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class ItemCustomPropertyPolicy < ApplicationPolicy
|
2
|
+
def index?
|
3
|
+
true if user.try(:has_role?, 'Librarian')
|
4
|
+
end
|
5
|
+
|
6
|
+
def show?
|
7
|
+
true if user.try(:has_role?, 'Librarian')
|
8
|
+
end
|
9
|
+
|
10
|
+
def create?
|
11
|
+
true if user.try(:has_role?, 'Librarian')
|
12
|
+
end
|
13
|
+
|
14
|
+
def update?
|
15
|
+
true if user.try(:has_role?, 'Librarian')
|
16
|
+
end
|
17
|
+
|
18
|
+
def destroy?
|
19
|
+
true if user.try(:has_role?, 'Librarian')
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class ManifestationCustomPropertyPolicy < ApplicationPolicy
|
2
|
+
def index?
|
3
|
+
true if user.try(:has_role?, 'Librarian')
|
4
|
+
end
|
5
|
+
|
6
|
+
def show?
|
7
|
+
true if user.try(:has_role?, 'Librarian')
|
8
|
+
end
|
9
|
+
|
10
|
+
def create?
|
11
|
+
true if user.try(:has_role?, 'Librarian')
|
12
|
+
end
|
13
|
+
|
14
|
+
def update?
|
15
|
+
true if user.try(:has_role?, 'Librarian')
|
16
|
+
end
|
17
|
+
|
18
|
+
def destroy?
|
19
|
+
true if user.try(:has_role?, 'Librarian')
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
<%= form_with(model: item_custom_property, local: true) do |form| %>
|
2
|
+
<% if item_custom_property.errors.any? %>
|
3
|
+
<div id="error_explanation">
|
4
|
+
<h2><%= pluralize(item_custom_property.errors.count, "error") %> prohibited this item_custom_property from being saved:</h2>
|
5
|
+
|
6
|
+
<ul>
|
7
|
+
<% item_custom_property.errors.full_messages.each do |message| %>
|
8
|
+
<li><%= message %></li>
|
9
|
+
<% end %>
|
10
|
+
</ul>
|
11
|
+
</div>
|
12
|
+
<% end %>
|
13
|
+
|
14
|
+
<div class="form-group">
|
15
|
+
<%= form.label :name %>
|
16
|
+
<%= form.text_field :name, class: 'form-control' %>
|
17
|
+
</div>
|
18
|
+
|
19
|
+
<div class="form-group">
|
20
|
+
<%= form.label :display_name %>
|
21
|
+
<%= form.text_area :display_name, class: 'form-control' %>
|
22
|
+
</div>
|
23
|
+
|
24
|
+
<div class="form-group">
|
25
|
+
<%= form.label :note %>
|
26
|
+
<%= form.text_area :note, class: 'form-control' %>
|
27
|
+
</div>
|
28
|
+
|
29
|
+
<div class="actions">
|
30
|
+
<%= form.submit class: 'btn btn-primary' -%>
|
31
|
+
</div>
|
32
|
+
<% end %>
|
@@ -0,0 +1,6 @@
|
|
1
|
+
<h1><%= t('page.editing', model: t('activerecord.models.item_custom_property')) -%></h1>
|
2
|
+
|
3
|
+
<%= render 'form', item_custom_property: @item_custom_property %>
|
4
|
+
|
5
|
+
<%= link_to t('page.show'), @item_custom_property %> |
|
6
|
+
<%= link_to t('page.back'), item_custom_properties_path %>
|