enju_biblio 0.3.8 → 0.3.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (129) 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 +69 -0
  4. data/app/controllers/items_controller.rb +2 -3
  5. data/app/controllers/manifestation_custom_properties_controller.rb +69 -0
  6. data/app/controllers/manifestations_controller.rb +12 -15
  7. data/app/controllers/resource_import_results_controller.rb +6 -2
  8. data/app/models/agent.rb +6 -6
  9. data/app/models/agent_import_file.rb +7 -7
  10. data/app/models/agent_type.rb +0 -1
  11. data/app/models/carrier_type.rb +0 -1
  12. data/app/models/content_type.rb +0 -1
  13. data/app/models/form_of_work.rb +1 -2
  14. data/app/models/frequency.rb +0 -1
  15. data/app/models/identifier_type.rb +0 -1
  16. data/app/models/item.rb +15 -16
  17. data/app/models/item_custom_property.rb +18 -0
  18. data/app/models/item_custom_value.rb +17 -0
  19. data/app/models/license.rb +0 -1
  20. data/app/models/manifestation.rb +54 -22
  21. data/app/models/manifestation_custom_property.rb +18 -0
  22. data/app/models/manifestation_custom_value.rb +17 -0
  23. data/app/models/medium_of_performance.rb +1 -2
  24. data/app/models/picture_file.rb +0 -2
  25. data/app/models/resource_export_file.rb +4 -2
  26. data/app/models/resource_import_file.rb +157 -67
  27. data/app/policies/item_custom_property_policy.rb +21 -0
  28. data/app/policies/manifestation_custom_property_policy.rb +21 -0
  29. data/app/views/agent_import_results/index.txt.ruby +5 -0
  30. data/app/views/agent_relationship_types/_form.html.erb +1 -1
  31. data/app/views/agent_types/_form.html.erb +1 -1
  32. data/app/views/carrier_types/_form.html.erb +1 -1
  33. data/app/views/create_types/_form.html.erb +1 -1
  34. data/app/views/form_of_works/_form.html.erb +1 -1
  35. data/app/views/frequencies/_form.html.erb +1 -1
  36. data/app/views/item_custom_properties/_form.html.erb +32 -0
  37. data/app/views/item_custom_properties/edit.html.erb +13 -0
  38. data/app/views/item_custom_properties/index.html.erb +43 -0
  39. data/app/views/item_custom_properties/new.html.erb +12 -0
  40. data/app/views/item_custom_properties/show.html.erb +28 -0
  41. data/app/views/items/_form.html.erb +13 -10
  42. data/app/views/items/show.html.erb +3 -4
  43. data/app/views/licenses/_form.html.erb +1 -1
  44. data/app/views/manifestation_custom_properties/_form.html.erb +32 -0
  45. data/app/views/manifestation_custom_properties/edit.html.erb +13 -0
  46. data/app/views/manifestation_custom_properties/index.html.erb +43 -0
  47. data/app/views/manifestation_custom_properties/new.html.erb +12 -0
  48. data/app/views/manifestation_custom_properties/show.html.erb +28 -0
  49. data/app/views/manifestation_relationship_types/_form.html.erb +1 -1
  50. data/app/views/manifestations/_export_detail.html.erb +1 -0
  51. data/app/views/manifestations/_export_list.html.erb +1 -0
  52. data/app/views/manifestations/_form.html.erb +18 -10
  53. data/app/views/manifestations/_show_detail_librarian.html.erb +9 -3
  54. data/app/views/manifestations/_show_detail_user.html.erb +8 -0
  55. data/app/views/manifestations/show.json.jbuilder +2 -0
  56. data/app/views/medium_of_performances/_form.html.erb +1 -1
  57. data/app/views/picture_files/edit.html.erb +4 -0
  58. data/app/views/produce_types/_form.html.erb +1 -1
  59. data/app/views/realize_types/_form.html.erb +1 -1
  60. data/app/views/resource_import_results/index.txt.ruby +5 -0
  61. data/app/views/series_statement_merges/_form.html.erb +1 -1
  62. data/config/locales/translation_en.yml +22 -8
  63. data/config/locales/translation_ja.yml +22 -8
  64. data/config/routes.rb +2 -0
  65. data/db/migrate/20081027150907_create_picture_files.rb +0 -2
  66. data/db/migrate/20200425072340_create_manifestation_custom_properties.rb +12 -0
  67. data/db/migrate/20200425072349_create_item_custom_properties.rb +12 -0
  68. data/db/migrate/20200425074758_create_manifestation_custom_values.rb +12 -0
  69. data/db/migrate/20200425074822_create_item_custom_values.rb +12 -0
  70. data/lib/enju_biblio/version.rb +1 -1
  71. data/spec/cassette_library/ResourceImportFile/when_its_mode_is_create_/when_it_is_written_in_utf-8/should_import_custom_values.yml +121 -0
  72. data/spec/cassette_library/resource_import_results/index_txt_ruby/renders_a_list_of_resource_import_results.yml +121 -0
  73. data/spec/controllers/content_types_controller_spec.rb +1 -1
  74. data/spec/controllers/item_custom_properties_controller_spec.rb +449 -0
  75. data/spec/controllers/items_controller_spec.rb +22 -25
  76. data/spec/controllers/manifestation_custom_properties_controller_spec.rb +449 -0
  77. data/spec/controllers/manifestations_controller_spec.rb +20 -23
  78. data/spec/dummy/db/schema.rb +43 -12
  79. data/spec/factories/item_custom_property.rb +6 -0
  80. data/spec/factories/item_custom_value.rb +6 -0
  81. data/spec/factories/manifestation_custom_property.rb +6 -0
  82. data/spec/factories/manifestation_custom_value.rb +6 -0
  83. data/spec/fixtures/creates.yml +2 -0
  84. data/spec/fixtures/item_custom_properties.yml +24 -0
  85. data/spec/fixtures/library_groups.yml +29 -15
  86. data/spec/fixtures/manifestation_custom_properties.yml +24 -0
  87. data/spec/fixtures/picture_files.yml +0 -2
  88. data/spec/fixtures/produces.yml +2 -0
  89. data/spec/fixtures/realizes.yml +2 -0
  90. data/spec/fixtures/resource_import_results.yml +2 -2
  91. data/spec/models/item_custom_property_spec.rb +18 -0
  92. data/spec/models/item_custom_value_spec.rb +17 -0
  93. data/spec/models/manifestation_custom_property_spec.rb +18 -0
  94. data/spec/models/manifestation_custom_value_spec.rb +17 -0
  95. data/spec/models/manifestation_spec.rb +11 -21
  96. data/spec/models/picture_file_spec.rb +0 -2
  97. data/spec/models/resource_export_file_spec.rb +61 -8
  98. data/spec/models/resource_import_file_spec.rb +43 -13
  99. data/spec/requests/item_custom_properties_spec.rb +129 -0
  100. data/spec/requests/manifestation_custom_properties_spec.rb +129 -0
  101. data/spec/routing/item_custom_properties_routing_spec.rb +38 -0
  102. data/spec/routing/manifestation_custom_properties_routing_spec.rb +38 -0
  103. data/spec/system/items_spec.rb +12 -0
  104. data/spec/system/manifestations_spec.rb +12 -0
  105. data/spec/views/agent_import_results/index.html.erb_spec.rb +29 -0
  106. data/spec/views/agent_import_results/index.txt.ruby_spec.rb +20 -0
  107. data/spec/views/agent_import_results/show.html.erb_spec.rb +24 -0
  108. data/spec/views/item_custom_properties/edit.html.erb_spec.rb +21 -0
  109. data/spec/views/item_custom_properties/index.html.erb_spec.rb +25 -0
  110. data/spec/views/item_custom_properties/new.html.erb_spec.rb +21 -0
  111. data/spec/views/item_custom_properties/show.html.erb_spec.rb +16 -0
  112. data/spec/views/manifestation_custom_properties/edit.html.erb_spec.rb +21 -0
  113. data/spec/views/manifestation_custom_properties/index.html.erb_spec.rb +25 -0
  114. data/spec/views/manifestation_custom_properties/new.html.erb_spec.rb +21 -0
  115. data/spec/views/manifestation_custom_properties/show.html.erb_spec.rb +16 -0
  116. data/spec/views/manifestations/show.json.jbuilder_spec.rb +16 -0
  117. data/spec/views/manifestations/show.txt.ruby_spec.rb +1 -1
  118. data/spec/views/resource_import_results/index.txt.ruby_spec.rb +22 -0
  119. data/spec/views/resource_import_results/show.html.erb_spec.rb +1 -1
  120. metadata +118 -37
  121. data/app/models/custom_property.rb +0 -17
  122. data/app/views/agent_import_results/index.txt.erb +0 -3
  123. data/app/views/items/_custom_property_fields.html.erb +0 -7
  124. data/app/views/manifestations/_custom_property_fields.html.erb +0 -7
  125. data/app/views/resource_import_results/index.txt.erb +0 -3
  126. data/db/migrate/20191219122214_create_custom_properties.rb +0 -12
  127. data/spec/factories/custom_property.rb +0 -18
  128. data/spec/models/custom_property_spec.rb +0 -18
  129. data/spec/system/custom_properties_spec.rb +0 -84
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 14f03cf53c6970882201d12cf5dce14dcd8299abe9b86a85395fc7a5469c0e65
4
- data.tar.gz: 62953ed2450999eb1622b5552d84fd845e6332de65ba4bd4b853a95fff5c5af3
3
+ metadata.gz: 3d531d406b5fda2fe6871aacfff5e40ee50b4b9e705011b48194043636435d4f
4
+ data.tar.gz: 254254c68a6ad93a6e05ca9db4bcc38dcb5abd6ba100cdb26dd9f1d6cc8a3ee1
5
5
  SHA512:
6
- metadata.gz: ce8d9794d43731afcd91bdc6e84a5f49ef3f98ab17a80016b306956fc4ecfebec23a9f7ace9e992d1cea0eb8d76d2a12ef9c151edc773d587bf7db75787f642a
7
- data.tar.gz: 6981d61da93ea05bb04bb3d218b6152bc2db9bbed3365049748fc7df5442d82ef2ae5de904d3cf3f479bdadd67346d31f52bba1f03fffe181cc2f6114dc79aa8
6
+ metadata.gz: ab53272b3a84a1970be279892113c5296ca7eb3ee5fa8058d807b716737597dabe1d4a087e1abfed6763853920a922096ba0d932de6e2645bb3dfb96040e3f50
7
+ data.tar.gz: 9967b069e6d50dd77c0ed2f1d42c06d574d1138164e569043fb00861bd4b6246105288f052fb0351993a60531e87f9c79266def019ac45e749f548caf1162e02
@@ -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,69 @@
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: t('controller.successfully_created', model: t('activerecord.models.item_custom_property'))
29
+ else
30
+ render :new
31
+ end
32
+ end
33
+
34
+ # PATCH/PUT /item_custom_properties/1
35
+ def update
36
+ if params[:move]
37
+ move_position(@item_custom_property, params[:move])
38
+ return
39
+ end
40
+
41
+ if @item_custom_property.update(item_custom_property_params)
42
+ redirect_to @item_custom_property, notice: t('controller.successfully_updated', model: t('activerecord.models.item_custom_property'))
43
+ else
44
+ render :edit
45
+ end
46
+ end
47
+
48
+ # DELETE /item_custom_properties/1
49
+ def destroy
50
+ @item_custom_property.destroy
51
+ redirect_to item_custom_properties_url, notice: t('controller.successfully_deleted', model: t('activerecord.models.item_custom_property'))
52
+ end
53
+
54
+ private
55
+ # Use callbacks to share common setup or constraints between actions.
56
+ def set_item_custom_property
57
+ @item_custom_property = ItemCustomProperty.find(params[:id])
58
+ authorize @item_custom_property
59
+ end
60
+
61
+ def check_policy
62
+ authorize ItemCustomProperty
63
+ end
64
+
65
+ # Only allow a trusted parameter "white list" through.
66
+ def item_custom_property_params
67
+ params.require(:item_custom_property).permit(:name, :display_name, :note)
68
+ end
69
+ end
@@ -274,9 +274,8 @@ 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
- {custom_properties_attributes: [
278
- :id, :label, :value,
279
- :_destroy
277
+ {item_custom_values_attributes: [
278
+ :id, :item_custom_property_id, :item_id, :value,:_destroy
280
279
  ]}
281
280
  )
282
281
  end
@@ -0,0 +1,69 @@
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: t('controller.successfully_created', model: t('activerecord.models.manifestation_custom_property'))
29
+ else
30
+ render :new
31
+ end
32
+ end
33
+
34
+ # PATCH/PUT /manifestation_custom_properties/1
35
+ def update
36
+ if params[:move]
37
+ move_position(@manifestation_custom_property, params[:move])
38
+ return
39
+ end
40
+
41
+ if @manifestation_custom_property.update(manifestation_custom_property_params)
42
+ redirect_to @manifestation_custom_property, notice: t('controller.successfully_updated', model: t('activerecord.models.manifestation_custom_property'))
43
+ else
44
+ render :edit
45
+ end
46
+ end
47
+
48
+ # DELETE /manifestation_custom_properties/1
49
+ def destroy
50
+ @manifestation_custom_property.destroy
51
+ redirect_to manifestation_custom_properties_url, notice: t('controller.successfully_deleted', model: t('activerecord.models.manifestation_custom_property'))
52
+ end
53
+
54
+ private
55
+ # Use callbacks to share common setup or constraints between actions.
56
+ def set_manifestation_custom_property
57
+ @manifestation_custom_property = ManifestationCustomProperty.find(params[:id])
58
+ authorize @manifestation_custom_property
59
+ end
60
+
61
+ def check_policy
62
+ authorize ManifestationCustomProperty
63
+ end
64
+
65
+ # Only allow a trusted parameter "white list" through.
66
+ def manifestation_custom_property_params
67
+ params.require(:manifestation_custom_property).permit(:name, :display_name, :note)
68
+ end
69
+ end
@@ -332,7 +332,7 @@ class ManifestationsController < ApplicationController
332
332
  }
333
333
  format.rdf
334
334
  format.mods
335
- format.json { render json: @manifestation }
335
+ format.json
336
336
  format.txt
337
337
  format.js
338
338
  format.download {
@@ -355,8 +355,8 @@ class ManifestationsController < ApplicationController
355
355
  # GET /manifestations/new.json
356
356
  def new
357
357
  @manifestation = Manifestation.new
358
- @manifestation.language = Language.where(iso_639_1: @locale).first
359
- @parent = Manifestation.where(id: params[:parent_id]).first if params[:parent_id].present?
358
+ @manifestation.language = Language.find_by(iso_639_1: @locale)
359
+ @parent = Manifestation.find_by(id: params[:parent_id]) if params[:parent_id].present?
360
360
  if @parent
361
361
  @manifestation.parent_id = @parent.id
362
362
  [ :original_title, :title_transcription,
@@ -550,9 +550,8 @@ class ManifestationsController < ApplicationController
550
550
  :id, :body, :identifier_type_id,
551
551
  :_destroy
552
552
  ]},
553
- {custom_properties_attributes: [
554
- :id, :label, :value,
555
- :_destroy
553
+ {manifestation_custom_values_attributes: [
554
+ :id, :manifestation_custom_property_id, :manifestation_id, :value,:_destroy
556
555
  ]}
557
556
  )
558
557
  end
@@ -738,12 +737,12 @@ class ManifestationsController < ApplicationController
738
737
  end
739
738
 
740
739
  def prepare_options
741
- @carrier_types = CarrierType.select([:id, :display_name, :position])
742
- @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])
743
742
  @roles = Role.select([:id, :display_name, :position])
744
- @languages = Language.select([:id, :display_name, :position])
745
- @frequencies = Frequency.select([:id, :display_name, :position])
746
- @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])
747
746
  @nii_types = NiiType.select([:id, :display_name, :position]) if defined?(EnjuNii)
748
747
  if defined?(EnjuSubject)
749
748
  @subject_types = SubjectType.select([:id, :display_name, :position])
@@ -783,7 +782,7 @@ class ManifestationsController < ApplicationController
783
782
  if options[:pub_date_from].blank?
784
783
  pub_date[:from] = "*"
785
784
  else
786
- year = options[:pub_date_from].rjust(4, "0")
785
+ year = options[:pub_date_from].to_s.gsub(/\D/, '').rjust(4, "0")
787
786
  if year.length == 4
788
787
  pub_date[:from] = Time.zone.parse(Time.utc(year).to_s).beginning_of_year.utc.iso8601
789
788
  else
@@ -797,7 +796,7 @@ class ManifestationsController < ApplicationController
797
796
  if options[:pub_date_until].blank?
798
797
  pub_date[:until] = "*"
799
798
  else
800
- year = options[:pub_date_until].rjust(4, "0")
799
+ year = options[:pub_date_until].to_s.gsub(/\D/, '').rjust(4, "0")
801
800
  if year.length == 4
802
801
  pub_date[:until] = Time.zone.parse(Time.utc(year).to_s).end_of_year.utc.iso8601
803
802
  else
@@ -812,8 +811,6 @@ class ManifestationsController < ApplicationController
812
811
 
813
812
  def set_pub_date(query, options)
814
813
  unless options[:pub_date_from].blank? && options[:pub_date_until].blank?
815
- options[:pub_date_from].to_s.gsub!(/\D/, '')
816
- options[:pub_date_until].to_s.gsub!(/\D/, '')
817
814
  pub_date = parse_pub_date(options)
818
815
  query = "#{query} date_of_publication_d:[#{pub_date[:from]} TO #{pub_date[:until]}]"
819
816
  end
@@ -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
@@ -76,7 +76,7 @@ class Agent < ApplicationRecord
76
76
  paginates_per 10
77
77
 
78
78
  def set_role_and_name
79
- self.required_role = Role.where(name: 'Librarian').first if required_role_id.nil?
79
+ self.required_role = Role.find_by(name: 'Librarian') if required_role_id.nil?
80
80
  set_full_name
81
81
  end
82
82
 
@@ -202,15 +202,15 @@ class Agent < ApplicationRecord
202
202
  end
203
203
 
204
204
  def created(work)
205
- creates.where(work_id: work.id).first
205
+ creates.find_by(work_id: work.id)
206
206
  end
207
207
 
208
208
  def realized(expression)
209
- realizes.where(expression_id: expression.id).first
209
+ realizes.find_by(expression_id: expression.id)
210
210
  end
211
211
 
212
212
  def produced(manifestation)
213
- produces.where(manifestation_id: manifestation.id).first
213
+ produces.find_by(manifestation_id: manifestation.id)
214
214
  end
215
215
 
216
216
  def owned(item)
@@ -222,7 +222,7 @@ class Agent < ApplicationRecord
222
222
  agent_lists.each do |agent_list|
223
223
  name_and_role = agent_list[:full_name].split('||')
224
224
  if agent_list[:agent_identifier].present?
225
- agent = Agent.where(agent_identifier: agent_list[:agent_identifier]).first
225
+ agent = Agent.find_by(agent_identifier: agent_list[:agent_identifier])
226
226
  else
227
227
  agents_matched = Agent.where(full_name: name_and_role[0])
228
228
  agents_matched = agents_matched.where(place: agent_list[:place]) if agent_list[:place]
@@ -237,7 +237,7 @@ class Agent < ApplicationRecord
237
237
  place: agent_list[:place],
238
238
  language_id: 1,
239
239
  )
240
- agent.required_role = Role.where(name: 'Guest').first
240
+ agent.required_role = Role.find_by(name: 'Guest')
241
241
  agent.save
242
242
  end
243
243
  agents << agent
@@ -116,7 +116,7 @@ class AgentImportFile < ApplicationRecord
116
116
  rows.each do |row|
117
117
  row_num += 1
118
118
  next if row['dummy'].to_s.strip.present?
119
- agent = Agent.where(id: row['id']).first
119
+ agent = Agent.find_by(id: row['id'])
120
120
  if agent
121
121
  agent.full_name = row['full_name'] if row['full_name'].to_s.strip.present?
122
122
  agent.full_name_transcription = row['full_name_transcription'] if row['full_name_transcription'].to_s.strip.present?
@@ -151,7 +151,7 @@ class AgentImportFile < ApplicationRecord
151
151
  rows.each do |row|
152
152
  row_num += 1
153
153
  next if row['dummy'].to_s.strip.present?
154
- agent = Agent.where(id: row['id'].to_s.strip).first
154
+ agent = Agent.find_by(id: row['id'].to_s.strip)
155
155
  if agent
156
156
  agent.picture_files.destroy_all
157
157
  agent.reload
@@ -225,15 +225,15 @@ class AgentImportFile < ApplicationRecord
225
225
 
226
226
  #if row['username'].to_s.strip.blank?
227
227
  agent.email = row['email'].to_s.strip
228
- agent.required_role = Role.where(name: row['required_role'].to_s.strip.camelize).first || Role.where(name: 'Guest').first
228
+ agent.required_role = Role.find_by(name: row['required_role'].to_s.strip.camelize) || Role.find_by(name: 'Guest')
229
229
  #else
230
230
  # agent.required_role = Role.where(name: row['required_role'].to_s.strip.camelize).first || Role.where('Librarian').first
231
231
  #end
232
- language = Language.where(name: row['language'].to_s.strip.camelize).first
233
- language = Language.where(iso_639_2: row['language'].to_s.strip.downcase).first unless language
234
- language = Language.where(iso_639_1: row['language'].to_s.strip.downcase).first unless language
232
+ language = Language.find_by(name: row['language'].to_s.strip.camelize)
233
+ language = Language.find_by(iso_639_2: row['language'].to_s.strip.downcase) unless language
234
+ language = Language.find_by(iso_639_1: row['language'].to_s.strip.downcase) unless language
235
235
  agent.language = language if language
236
- country = Country.where(name: row['country'].to_s.strip).first
236
+ country = Country.find_by(name: row['country'].to_s.strip)
237
237
  agent.country = country if country
238
238
  agent
239
239
  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
@@ -19,12 +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
- has_many :custom_properties, as: :resource, dependent: :destroy
23
- accepts_nested_attributes_for :custom_properties, allow_destroy: true, reject_if: :all_blank
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)}
22
+ has_many :item_custom_values, -> { joins(:item_custom_property).order(:position) }
25
23
 
26
24
  belongs_to :shelf, counter_cache: true
25
+ accepts_nested_attributes_for :item_custom_values, reject_if: :all_blank
27
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)}
28
28
  validates_associated :bookstore
29
29
  validates :manifestation_id, presence: true
30
30
  validates :item_identifier, allow_blank: true, uniqueness: true,
@@ -107,10 +107,11 @@ class Item < ApplicationRecord
107
107
  record = {
108
108
  item_id: id,
109
109
  item_identifier: item_identifier,
110
+ binding_item_identifier: binding_item_identifier,
110
111
  call_number: call_number,
111
- shelf: shelf.name,
112
+ shelf: shelf&.name,
112
113
  item_note: note,
113
- accepted_at: accept.try(:created_at),
114
+ accepted_at: accept&.created_at,
114
115
  acquired_at: acquired_at,
115
116
  item_created_at: created_at,
116
117
  item_updated_at: updated_at
@@ -118,25 +119,23 @@ class Item < ApplicationRecord
118
119
 
119
120
  if ['Administrator', 'Librarian'].include?(role)
120
121
  record.merge!({
121
- bookstore: bookstore.try(:name),
122
- budget_type: budget_type.try(:name),
122
+ bookstore: bookstore&.name,
123
+ budget_type: budget_type&.name,
124
+ item_required_role: required_role.name,
123
125
  item_price: price,
124
126
  memo: memo
125
127
  })
126
128
 
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
129
+ ItemCustomProperty.order(:position).each do |custom_property|
130
+ custom_value = item_custom_values.find_by(item_custom_property: custom_property)
131
+ record[:"item:#{custom_property.name}"] = custom_value.try(:value)
135
132
  end
136
133
 
137
134
  if defined?(EnjuCirculation)
138
135
  record.merge!({
139
- use_restriction: use_restriction.try(:name),
136
+ use_restriction: use_restriction&.name,
137
+ circulation_status: circulation_status&.name,
138
+ checkout_type: checkout_type&.name,
140
139
  total_checkouts: checkouts.count
141
140
  })
142
141
  end