enju_biblio 0.3.9 → 0.3.10.rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/content_types_controller.rb +1 -1
  3. data/app/controllers/item_custom_properties_controller.rb +64 -0
  4. data/app/controllers/items_controller.rb +3 -0
  5. data/app/controllers/manifestation_custom_properties_controller.rb +64 -0
  6. data/app/controllers/manifestations_controller.rb +8 -5
  7. data/app/controllers/resource_import_results_controller.rb +6 -2
  8. data/app/models/agent_type.rb +0 -1
  9. data/app/models/carrier_type.rb +0 -1
  10. data/app/models/content_type.rb +0 -1
  11. data/app/models/form_of_work.rb +1 -2
  12. data/app/models/frequency.rb +0 -1
  13. data/app/models/identifier_type.rb +0 -1
  14. data/app/models/item.rb +8 -1
  15. data/app/models/item_custom_property.rb +18 -0
  16. data/app/models/item_custom_value.rb +17 -0
  17. data/app/models/license.rb +0 -1
  18. data/app/models/manifestation.rb +18 -0
  19. data/app/models/manifestation_custom_property.rb +18 -0
  20. data/app/models/manifestation_custom_value.rb +17 -0
  21. data/app/models/medium_of_performance.rb +1 -2
  22. data/app/models/resource_import_file.rb +81 -9
  23. data/app/policies/item_custom_property_policy.rb +21 -0
  24. data/app/policies/manifestation_custom_property_policy.rb +21 -0
  25. data/app/views/item_custom_properties/_form.html.erb +32 -0
  26. data/app/views/item_custom_properties/edit.html.erb +6 -0
  27. data/app/views/item_custom_properties/index.html.erb +36 -0
  28. data/app/views/item_custom_properties/new.html.erb +5 -0
  29. data/app/views/item_custom_properties/show.html.erb +21 -0
  30. data/app/views/items/_form.html.erb +13 -0
  31. data/app/views/items/show.html.erb +6 -0
  32. data/app/views/manifestation_custom_properties/_form.html.erb +32 -0
  33. data/app/views/manifestation_custom_properties/edit.html.erb +6 -0
  34. data/app/views/manifestation_custom_properties/index.html.erb +36 -0
  35. data/app/views/manifestation_custom_properties/new.html.erb +5 -0
  36. data/app/views/manifestation_custom_properties/show.html.erb +21 -0
  37. data/app/views/manifestations/_form.html.erb +13 -0
  38. data/app/views/manifestations/_show_detail_librarian.html.erb +8 -0
  39. data/app/views/picture_files/edit.html.erb +4 -0
  40. data/config/locales/translation_en.yml +20 -8
  41. data/config/locales/translation_ja.yml +20 -8
  42. data/config/routes.rb +2 -0
  43. data/db/migrate/20200425072340_create_manifestation_custom_properties.rb +12 -0
  44. data/db/migrate/20200425072349_create_item_custom_properties.rb +12 -0
  45. data/db/migrate/20200425074758_create_manifestation_custom_values.rb +12 -0
  46. data/db/migrate/20200425074822_create_item_custom_values.rb +12 -0
  47. data/lib/enju_biblio/version.rb +1 -1
  48. data/spec/cassette_library/ResourceImportFile/when_its_mode_is_create_/when_it_is_written_in_utf-8/should_import_custom_values.yml +121 -0
  49. data/spec/cassette_library/resource_import_results/index_txt_ruby/renders_a_list_of_resource_import_results.yml +121 -0
  50. data/spec/controllers/content_types_controller_spec.rb +1 -1
  51. data/spec/controllers/items_controller_spec.rb +22 -0
  52. data/spec/controllers/manifestations_controller_spec.rb +22 -0
  53. data/spec/dummy/db/schema.rb +43 -21
  54. data/spec/factories/item_custom_property.rb +6 -0
  55. data/spec/factories/item_custom_value.rb +6 -0
  56. data/spec/factories/manifestation_custom_property.rb +6 -0
  57. data/spec/factories/manifestation_custom_value.rb +6 -0
  58. data/spec/fixtures/item_custom_properties.yml +24 -0
  59. data/spec/fixtures/library_groups.yml +0 -2
  60. data/spec/fixtures/manifestation_custom_properties.yml +24 -0
  61. data/spec/models/item_custom_property_spec.rb +18 -0
  62. data/spec/models/item_custom_value_spec.rb +17 -0
  63. data/spec/models/manifestation_custom_property_spec.rb +18 -0
  64. data/spec/models/manifestation_custom_value_spec.rb +17 -0
  65. data/spec/models/manifestation_spec.rb +15 -0
  66. data/spec/models/resource_import_file_spec.rb +38 -12
  67. data/spec/requests/item_custom_properties_spec.rb +129 -0
  68. data/spec/requests/manifestation_custom_properties_spec.rb +129 -0
  69. data/spec/routing/item_custom_properties_routing_spec.rb +38 -0
  70. data/spec/routing/manifestation_custom_properties_routing_spec.rb +38 -0
  71. data/spec/system/items_spec.rb +12 -0
  72. data/spec/system/manifestations_spec.rb +12 -0
  73. data/spec/views/item_custom_properties/edit.html.erb_spec.rb +21 -0
  74. data/spec/views/item_custom_properties/index.html.erb_spec.rb +24 -0
  75. data/spec/views/item_custom_properties/new.html.erb_spec.rb +21 -0
  76. data/spec/views/item_custom_properties/show.html.erb_spec.rb +16 -0
  77. data/spec/views/manifestation_custom_properties/edit.html.erb_spec.rb +21 -0
  78. data/spec/views/manifestation_custom_properties/index.html.erb_spec.rb +24 -0
  79. data/spec/views/manifestation_custom_properties/new.html.erb_spec.rb +21 -0
  80. data/spec/views/manifestation_custom_properties/show.html.erb_spec.rb +16 -0
  81. data/spec/views/resource_import_results/index.txt.ruby_spec.rb +4 -4
  82. metadata +569 -497
  83. data/db/migrate/20200322053443_add_default_custom_label_to_library_group.rb +0 -6
  84. data/db/migrate/20200322083313_create_custom_labels.rb +0 -10
  85. 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: 26edca170abbc3255a6a2f00579b4da714df3bbe174873e4b110c79da9c59a87
4
- data.tar.gz: 2e7d74038d3e5bfb1f2fb44f54a6e86aad624b84e8f20c55cb818a4bf74e8bf0
3
+ metadata.gz: 77d5c642a35ec134208140ee6fbf038219d633619ba7a4a50927bcd14522e685
4
+ data.tar.gz: 814c6c8c7c795efa2cc55365805e1bbee2d7689d730593c56f00d012a7d4fa52
5
5
  SHA512:
6
- metadata.gz: b6e053f60b7a611c81ddc0b052def4209d96d1fd23044dc81296dc755e19409d64b625109f34da67588c7984fce670cc4b74973b99af927a459ea910b6d9f4c5
7
- data.tar.gz: 1d920ee17e99acf17fd92e18ff3186139daf93940e1be813b5b1f99ffdc0d008029bde5735c05a4978363b185d32090b4f683f3abc63786d7641285f903924f2
6
+ metadata.gz: 969d8e56c2adfdc2b82b63bf193d28092348c7cb01675cc19e59e936e9ab73ab9878f8403a82397420c3f9469d37bbbcdf610f3d465980c6d5607d9219be510b
7
+ data.tar.gz: be66e593d2fd98df02e694169b53554aadd7a9d3369e731a96eede7bd3ef7336a48372025d55a4de462156d8d6018c4ee5b02954b49676f0d9a20cd90e161c96
@@ -5,7 +5,7 @@ class ContentTypesController < ApplicationController
5
5
  # GET /content_types
6
6
  # GET /content_types.json
7
7
  def index
8
- @content_types = ContentType.all
8
+ @content_types = ContentType.order(:position)
9
9
 
10
10
  respond_to do |format|
11
11
  format.html # index.html.erb
@@ -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.where(id: params[:resource_import_file_id]).first
8
+ @resource_import_file = ResourceImportFile.find_by(id: params[:resource_import_file_id])
9
9
  if @resource_import_file
10
- @resource_import_results = @resource_import_file.resource_import_results.page(params[:page])
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
@@ -1,6 +1,5 @@
1
1
  class AgentType < ApplicationRecord
2
2
  include MasterModel
3
- default_scope { order('agent_types.position') }
4
3
  has_many :agents
5
4
  end
6
5
 
@@ -1,6 +1,5 @@
1
1
  class CarrierType < ApplicationRecord
2
2
  include MasterModel
3
- default_scope { order("carrier_types.position") }
4
3
  has_many :manifestations
5
4
  if ENV['ENJU_STORAGE'] == 's3'
6
5
  has_attached_file :attachment, storage: :s3,
@@ -1,6 +1,5 @@
1
1
  class ContentType < ApplicationRecord
2
2
  include MasterModel
3
- default_scope { order('content_types.position') }
4
3
  has_many :manifestations
5
4
  end
6
5
 
@@ -1,7 +1,6 @@
1
1
  class FormOfWork < ApplicationRecord
2
2
  include MasterModel
3
- default_scope { order('form_of_works.position') }
4
- has_many :works
3
+ has_many :works, class_name: 'Manifestation'
5
4
  end
6
5
 
7
6
  # == Schema Information
@@ -1,6 +1,5 @@
1
1
  class Frequency < ApplicationRecord
2
2
  include MasterModel
3
- default_scope { order('frequencies.position') }
4
3
  has_many :manifestations
5
4
  end
6
5
 
@@ -1,6 +1,5 @@
1
1
  class IdentifierType < ApplicationRecord
2
2
  include MasterModel
3
- default_scope { order('identifier_types.position') }
4
3
  has_many :identifiers
5
4
  validates :name, format: { with: /\A[0-9a-z][0-9a-z_\-]*[0-9a-z]\Z/ }
6
5
  end
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
- 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)}
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
+ #
@@ -1,6 +1,5 @@
1
1
  class License < ApplicationRecord
2
2
  include MasterModel
3
- default_scope { order('licenses.position') }
4
3
  end
5
4
 
6
5
  # == Schema Information
@@ -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
+ #
@@ -1,7 +1,6 @@
1
1
  class MediumOfPerformance < ApplicationRecord
2
2
  include MasterModel
3
- default_scope { order('medium_of_performances.position') }
4
- has_many :works
3
+ has_many :works, class_name: 'Manifestation'
5
4
  end
6
5
 
7
6
  # == Schema Information
@@ -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.create!(resource_import_file_id: id, body: row.fields.join("\t"))
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
- import_result.item = create_item(row, manifestation)
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 %>