enju_biblio 0.3.6 → 0.3.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/items_controller.rb +5 -1
  3. data/app/controllers/manifestations_controller.rb +13 -7
  4. data/app/models/custom_property.rb +17 -0
  5. data/app/models/item.rb +51 -2
  6. data/app/models/manifestation.rb +110 -245
  7. data/app/models/resource_export_file.rb +3 -7
  8. data/app/models/resource_export_file_state_machine.rb +1 -1
  9. data/app/views/items/_custom_property_fields.html.erb +7 -0
  10. data/app/views/items/_form.html.erb +18 -6
  11. data/app/views/items/show.html.erb +7 -0
  12. data/app/views/manifestations/_custom_property_fields.html.erb +7 -0
  13. data/app/views/manifestations/_form.html.erb +10 -0
  14. data/app/views/manifestations/_manifestation.txt.erb +1 -1
  15. data/app/views/manifestations/_show_detail_librarian.html.erb +8 -0
  16. data/app/views/manifestations/index.txt.ruby +7 -0
  17. data/app/views/manifestations/show.txt.ruby +5 -0
  18. data/app/views/resource_import_files/_results.html.erb +6 -0
  19. data/app/views/resource_import_results/index.html.erb +0 -11
  20. data/app/views/series_statements/_form.html.erb +6 -8
  21. data/app/views/series_statements/show.html.erb +12 -0
  22. data/config/locales/translation_en.yml +7 -0
  23. data/config/locales/translation_ja.yml +10 -3
  24. data/db/migrate/20191219122214_create_custom_properties.rb +12 -0
  25. data/lib/enju_biblio/version.rb +1 -1
  26. data/spec/controllers/items_controller_spec.rb +25 -0
  27. data/spec/controllers/manifestations_controller_spec.rb +25 -0
  28. data/spec/dummy/db/schema.rb +10 -1
  29. data/spec/factories/custom_property.rb +18 -0
  30. data/spec/factories/series_statement.rb +4 -3
  31. data/spec/fixtures/items.yml +11 -10
  32. data/spec/fixtures/manifestations.yml +1 -0
  33. data/spec/models/custom_property_spec.rb +18 -0
  34. data/spec/models/item_spec.rb +1 -0
  35. data/spec/models/manifestation_spec.rb +33 -7
  36. data/spec/rails_helper.rb +3 -3
  37. data/spec/system/custom_properties_spec.rb +84 -0
  38. data/spec/system/series_statements_spec.rb +16 -0
  39. data/spec/views/manifestations/{index.txt.erb_spec.rb → index.txt.ruby_spec.rb} +1 -1
  40. data/spec/views/manifestations/{show.txt.erb_spec.rb → show.txt.ruby_spec.rb} +1 -1
  41. metadata +504 -492
  42. data/app/views/manifestations/index.txt.erb +0 -1
  43. data/app/views/manifestations/show.txt.erb +0 -1
@@ -30,13 +30,9 @@ class ResourceExportFile < ApplicationRecord
30
30
  def export!
31
31
  transition_to!(:started)
32
32
  role_name = user.try(:role).try(:name)
33
- tempfile = Tempfile.new(['resource_export_file_', '.txt'])
34
- tempfile.puts(Manifestation.csv_header(role_name, col_sep: "\t"))
35
- Manifestation.find_each do |manifestation|
36
- tempfile.puts(manifestation.to_csv(format: :txt, role: role_name))
37
- end
38
- tempfile.close
39
- self.resource_export = File.new(tempfile.path, "r")
33
+ tsv = Manifestation.export(role: role_name)
34
+ self.resource_export = StringIO.new(tsv)
35
+ self.resource_export.instance_write(:filename, "resource_export.txt")
40
36
  save!
41
37
  transition_to!(:completed)
42
38
  mailer = ResourceExportMailer.completed(self)
@@ -6,7 +6,7 @@ class ResourceExportFileStateMachine
6
6
  state :completed
7
7
  state :failed
8
8
 
9
- transition from: :pending, to: :started
9
+ transition from: :pending, to: [:started, :failed]
10
10
  transition from: :started, to: [:completed, :failed]
11
11
 
12
12
  after_transition(from: :pending, to: :started) do |resource_export_file|
@@ -0,0 +1,7 @@
1
+ <div class="nested-fields">
2
+ <%= f.label :label %>
3
+ <%= f.text_field :label, class: 'resource_custom_property_body' -%>
4
+ <%= f.label :value %>
5
+ <%= f.text_field :value, class: 'resource_custom_property_body' -%>
6
+ <%= link_to_remove_association t('page.remove'), f, data: {confirm: t('page.are_you_sure')} %><br />
7
+ </div>
@@ -1,10 +1,12 @@
1
1
  <%= render 'manifestations/title', manifestation: @item.manifestation -%>
2
- <p>
3
- <%= t('activerecord.models.classification') -%>:
4
- <%- @item.manifestation.classifications.each do |classification| -%>
5
- <%= link_to "#{classification.classification_type.display_name.localize}: #{classification.category}", manifestations_path(query: "classification_sm:#{classification.classification_type.name}_#{classification.category}") -%>
6
- <%- end -%>
7
- </p>
2
+ <% if defined?(EnjuSubject) %>
3
+ <p>
4
+ <%= t('activerecord.models.classification') -%>:
5
+ <%- @item.manifestation.classifications.each do |classification| -%>
6
+ <%= link_to "#{classification.classification_type.display_name}: #{classification.category}", manifestations_path(query: "classification_sm:#{classification.classification_type.name}_#{classification.category}") -%>
7
+ <%- end -%>
8
+ </p>
9
+ <% end %>
8
10
  <%= render 'page/required_field' %>
9
11
  <%= simple_form_for(@item) do |f| -%>
10
12
  <%= f.error_messages -%>
@@ -87,6 +89,16 @@
87
89
  <%= f.text_field :binding_item_identifier, class: 'resource_identifier' -%>
88
90
  </div>
89
91
 
92
+ <div class="field">
93
+ <%= f.label :custom_property -%><br />
94
+ <%= f.fields_for :custom_properties do |custom_property_form| %>
95
+ <%= render 'custom_property_fields', f: custom_property_form %>
96
+ <% end %>
97
+ <div class="links">
98
+ <p><%= link_to_add_association t('page.add'), f, :custom_properties %></p>
99
+ </div>
100
+ </div>
101
+
90
102
  <div class="field">
91
103
  <%= f.label :note -%><br />
92
104
  <%= f.text_area :note, class: 'resource_textarea' -%>
@@ -112,6 +112,13 @@
112
112
  </p>
113
113
 
114
114
  <% if current_user.try(:has_role?, 'Librarian') %>
115
+ <% @item.custom_properties.each do |custom_property| %>
116
+ <p>
117
+ <strong><%= custom_property.label -%>:</strong>
118
+ <%= custom_property.value -%>
119
+ </p>
120
+ <% end %>
121
+
115
122
  <p>
116
123
  <strong><%= t('activerecord.attributes.item.memo') -%>:</strong>
117
124
  <%= simple_format(@item.memo) %>
@@ -0,0 +1,7 @@
1
+ <div class="nested-fields">
2
+ <%= f.label :label %>
3
+ <%= f.text_field :label, class: 'resource_custom_property_body' -%>
4
+ <%= f.label :value %>
5
+ <%= f.text_field :value, class: 'resource_custom_property_body' -%>
6
+ <%= link_to_remove_association t('page.remove'), f, data: {confirm: t('page.are_you_sure')} %><br />
7
+ </div>
@@ -192,6 +192,16 @@
192
192
  <%= f.text_area :description, class: 'resource_textarea' -%>
193
193
  </div>
194
194
 
195
+ <div class="field">
196
+ <%= f.label :custom_property -%><br />
197
+ <%= f.fields_for :custom_properties do |custom_property_form| %>
198
+ <%= render 'custom_property_fields', f: custom_property_form %>
199
+ <% end %>
200
+ <div class="links">
201
+ <p><%= link_to_add_association t('page.add'), f, :custom_properties %></p>
202
+ </div>
203
+ </div>
204
+
195
205
  <div class="field">
196
206
  <%= f.label :note -%><br />
197
207
  <%= f.text_area :note, class: 'resource_textarea' -%>
@@ -1 +1 @@
1
- <%= manifestation.to_csv(format: :txt, role: current_user_role_name) -%>
1
+ <%= manifestation.to_hash(role: current_user_role_name).values.to_csv(col_sep: "\t") -%>
@@ -101,6 +101,14 @@
101
101
  <%= raw simple_format(h(manifestation.description)) -%>
102
102
  </td>
103
103
  </tr>
104
+ <% @manifestation.custom_properties.each do |custom_property| %>
105
+ <tr>
106
+ <td><%= custom_property.label -%>:</td>
107
+ <td>
108
+ <%= custom_property.value -%>
109
+ </td>
110
+ </tr>
111
+ <% end %>
104
112
  <tr>
105
113
  <td><%= t('activerecord.attributes.manifestation.note') -%>:</td>
106
114
  <td>
@@ -0,0 +1,7 @@
1
+ Manifestation.csv_header(
2
+ role: current_user_role_name
3
+ ).to_csv(col_sep: "\t") + @manifestations.map{|manifestation|
4
+ manifestation.to_hash(
5
+ role: current_user_role_name
6
+ ).values.to_csv(col_sep: "\t")
7
+ }.join
@@ -0,0 +1,5 @@
1
+ Manifestation.csv_header(
2
+ role: current_user_role_name
3
+ ).to_csv(col_sep: "\t") + @manifestation.to_hash(
4
+ role: current_user_role_name
5
+ ).values.to_csv(col_sep: "\t")
@@ -1,4 +1,10 @@
1
1
  <h2><%= t('activerecord.models.resource_import_result') %></h2>
2
+
3
+ <p>
4
+ <%= link_to((image_tag 'icons/page_white_excel.png', size: '16x16', alt: 'TSV', class: 'enju_icon'), resource_import_results_path(resource_import_file_id: @resource_import_file.id, format: :txt)) -%>
5
+ (<%= link_to 'TSV', resource_import_results_path(resource_import_file_id: @resource_import_file.id, format: :txt) -%>)
6
+ </p>
7
+
2
8
  <table class="table table-striped index">
3
9
  <tr>
4
10
  <th><%= t('activerecord.attributes.resource_import_result.lineno') %></th>
@@ -13,15 +13,4 @@
13
13
  </div>
14
14
 
15
15
  <div id="submenu" class="ui-corner-all ui-widget-content">
16
- <ul>
17
- <li>
18
- <% if @resource_import_file %>
19
- <%= link_to((image_tag 'icons/page_white_excel.png', size: '16x16', alt: 'TSV', class: 'enju_icon'), resource_import_results_path(resource_import_file_id: @resource_import_file.id, format: :txt)) -%>
20
- (<%= link_to 'TSV', resource_import_results_path(resource_import_file_id: @resource_import_file.id, format: :txt) -%>)
21
- <% else %>
22
- <%= link_to((image_tag 'icons/page_white_excel.png', size: '16x16', alt: 'TSV', class: 'enju_icon'), resource_import_results_path(format: :txt)) -%>
23
- (<%= link_to 'TSV', resource_import_results_path(format: :txt) -%>)
24
- <% end %>
25
- </li>
26
- </ul>
27
16
  </div>
@@ -24,20 +24,18 @@
24
24
  <%= f.label :title_subseries_transcription %><br />
25
25
  <%= f.text_field :title_subseries_transcription %>
26
26
  </div>
27
- <!--
28
27
  <div class="field">
29
- <%= f.label :numbering %><br />
30
- <%= f.text_field :numbering %>
28
+ <%= f.label :creator_string %><br />
29
+ <%= f.text_field :creator_string %>
31
30
  </div>
32
31
  <div class="field">
33
- <%= f.label :numbering_subseries -%><br />
34
- <%= f.text_field :numbering_subseries %>
32
+ <%= f.label :volume_number_string %><br />
33
+ <%= f.text_field :volume_number_string %>
35
34
  </div>
36
35
  <div class="field">
37
- <%= f.label :series_statement_identifier -%><br />
38
- <%= f.text_field :series_statement_identifier, class: 'resource_identifier' %>
36
+ <%= f.label :series_master %><br />
37
+ <%= f.check_box :series_master %>
39
38
  </div>
40
- -->
41
39
  <div class="field">
42
40
  <%= f.label :note -%><br />
43
41
  <%= f.text_area :note, class: 'resource_textarea' -%>
@@ -23,6 +23,18 @@
23
23
  <% end %>
24
24
  </td>
25
25
  </tr>
26
+ <tr>
27
+ <td><%= t('activerecord.attributes.series_statement.volume_number_string') -%></td>
28
+ <td><%= @series_statement.volume_number_string %></td>
29
+ </tr>
30
+ <tr>
31
+ <td><%= t('activerecord.attributes.series_statement.creator_string') -%></td>
32
+ <td><%= @series_statement.creator_string %></td>
33
+ </tr>
34
+ <tr>
35
+ <td><%= t('activerecord.attributes.series_statement.series_master') -%></td>
36
+ <td><%= localized_boolean(@series_statement.series_master) %></td>
37
+ </tr>
26
38
  <tr>
27
39
  <td><%= t('activerecord.attributes.series_statement.note') -%></td>
28
40
  <td><%= @series_statement.note %></td>
@@ -99,12 +99,16 @@ en:
99
99
  extent: Extent
100
100
  dimensions: Dimensions
101
101
  fulltext_content: Fulltext content
102
+ custom_property: Custom property
102
103
  manifestation/subjects:
103
104
  term: Subject
104
105
  manifestation/classifications:
105
106
  category: Classification
106
107
  manifestation/identifiers:
107
108
  body: Identifier
109
+ manifestation/custom_properties:
110
+ label: Label
111
+ value: Value
108
112
  item:
109
113
  call_number: Call number
110
114
  item_identifier: Item identifier
@@ -333,6 +337,9 @@ en:
333
337
  series_statement_merge_list:
334
338
  title: Title
335
339
  series_statement_merge:
340
+ custom_property:
341
+ label: Label
342
+ value: Value
336
343
 
337
344
  resource_import_file:
338
345
  update_relationship: Update relationship
@@ -99,12 +99,16 @@ ja:
99
99
  extent: ページ数
100
100
  dimensions: 大きさ
101
101
  fulltext_content: 全文あり
102
+ custom_property: カスタム項目
102
103
  manifestation/subjects:
103
- term: 件名
104
+ term: 件名
104
105
  manifestation/classifications:
105
- category: 分類
106
+ category: 分類
106
107
  manifestation/identifiers:
107
- body: 識別子
108
+ body: 識別子
109
+ manifestation/custom_properties:
110
+ label: 項目名
111
+ value: 値
108
112
  item:
109
113
  call_number: 請求記号
110
114
  item_identifier: 所蔵情報ID
@@ -337,6 +341,9 @@ ja:
337
341
  series_statement_merge_list:
338
342
  title: タイトル
339
343
  series_statement_merge:
344
+ custom_property:
345
+ label: 項目名
346
+ value: 値
340
347
 
341
348
  resource_import_file:
342
349
  update_relationship: 関連を更新
@@ -0,0 +1,12 @@
1
+ class CreateCustomProperties < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table :custom_properties do |t|
4
+ t.integer :resource_id, null: false
5
+ t.string :resource_type, null: false
6
+ t.text :label, null: false
7
+ t.text :value
8
+
9
+ t.timestamps
10
+ end
11
+ end
12
+ end
@@ -1,3 +1,3 @@
1
1
  module EnjuBiblio
2
- VERSION = "0.3.6"
2
+ VERSION = "0.3.7"
3
3
  end
@@ -265,6 +265,19 @@ describe ItemsController do
265
265
  assigns(:item).manifestation.should_not be_nil
266
266
  expect(response).to redirect_to(item_url(assigns(:item)))
267
267
  end
268
+
269
+ it 'assigns custom properties to @item' do
270
+ item = FactoryBot.create(:item_custom_property).resource
271
+ custom_properties_attrs = {
272
+ custom_properties_attributes: [{label: 'test', value: 'テスト'}]
273
+ }
274
+ put :update, params: {
275
+ id: item.id, item: @attrs.merge(custom_properties_attrs)
276
+ }
277
+ expect(assigns(:item)).to eq item
278
+ expect(assigns(:item).custom_properties.map{|property| property.label}).to eq ['custom property 1', 'test']
279
+ expect(assigns(:item).custom_properties.map{|property| property.value}).to eq ['カスタム項目 1', 'テスト']
280
+ end
268
281
  end
269
282
 
270
283
  describe 'with invalid params' do
@@ -435,6 +448,18 @@ describe ItemsController do
435
448
  put :update, params: { id: @item, item: @invalid_attrs }
436
449
  expect(response).to render_template('edit')
437
450
  end
451
+
452
+ it 'assigns custom properties to @item' do
453
+ item = FactoryBot.create(:item_custom_property).resource
454
+ custom_properties_attrs = {
455
+ custom_properties_attributes: [{name: 'test', value: 'テスト'}]
456
+ }
457
+ put :update, params: {
458
+ id: item.id, item: @invalid_attrs.merge(custom_properties_attrs)
459
+ }
460
+ expect(assigns(:item).custom_properties.count).to eq 1
461
+ expect(assigns(:item)).to_not be_valid
462
+ end
438
463
  end
439
464
  end
440
465
 
@@ -716,6 +716,19 @@ describe ManifestationsController do
716
716
  }
717
717
  expect(assigns(:manifestation)).to eq @manifestation
718
718
  end
719
+
720
+ it 'assigns custom properties to @manifestation' do
721
+ manifestation = FactoryBot.create(:manifestation_custom_property).resource
722
+ custom_properties_attrs = {
723
+ custom_properties_attributes: [{label: 'test', value: 'テスト'}]
724
+ }
725
+ put :update, params: {
726
+ id: manifestation.id, manifestation: @attrs.merge(custom_properties_attrs)
727
+ }
728
+ expect(assigns(:manifestation)).to eq manifestation
729
+ expect(assigns(:manifestation).custom_properties.map{|property| property.label}).to eq ['custom property 1', 'test']
730
+ expect(assigns(:manifestation).custom_properties.map{|property| property.value}).to eq ['カスタム項目 1', 'テスト']
731
+ end
719
732
  end
720
733
 
721
734
  describe 'with invalid params' do
@@ -741,6 +754,18 @@ describe ManifestationsController do
741
754
  }
742
755
  expect(assigns(:manifestation)).to_not be_valid
743
756
  end
757
+
758
+ it 'assigns custom properties to @manifestation' do
759
+ manifestation = FactoryBot.create(:manifestation_custom_property).resource
760
+ custom_properties_attrs = {
761
+ custom_properties_attributes: [{name: 'test', value: 'テスト'}]
762
+ }
763
+ put :update, params: {
764
+ id: manifestation.id, manifestation: @invalid_attrs.merge(custom_properties_attrs)
765
+ }
766
+ expect(assigns(:manifestation).custom_properties.count).to eq 1
767
+ expect(assigns(:manifestation)).to_not be_valid
768
+ end
744
769
  end
745
770
  end
746
771
 
@@ -10,7 +10,7 @@
10
10
  #
11
11
  # It's strongly recommended that you check this file into your version control system.
12
12
 
13
- ActiveRecord::Schema.define(version: 2019_08_18_075628) do
13
+ ActiveRecord::Schema.define(version: 2019_12_19_122214) do
14
14
 
15
15
  create_table "accepts", force: :cascade do |t|
16
16
  t.integer "basket_id"
@@ -433,6 +433,15 @@ ActiveRecord::Schema.define(version: 2019_08_18_075628) do
433
433
  t.index ["work_id"], name: "index_creates_on_work_id"
434
434
  end
435
435
 
436
+ create_table "custom_properties", force: :cascade do |t|
437
+ t.integer "resource_id", null: false
438
+ t.string "resource_type", null: false
439
+ t.text "label", null: false
440
+ t.text "value"
441
+ t.datetime "created_at", null: false
442
+ t.datetime "updated_at", null: false
443
+ end
444
+
436
445
  create_table "demands", force: :cascade do |t|
437
446
  t.integer "user_id"
438
447
  t.integer "item_id"
@@ -0,0 +1,18 @@
1
+ FactoryBot.define do
2
+ factory :custom_property do
3
+ sequence(:label){|n| "custom property #{n}"}
4
+ sequence(:value){|n| "カスタム項目 #{n}"}
5
+ end
6
+
7
+ factory :manifestation_custom_property, class: CustomProperty do
8
+ association :resource, factory: :manifestation
9
+ sequence(:label){|n| "custom property #{n}"}
10
+ sequence(:value){|n| "カスタム項目 #{n}"}
11
+ end
12
+
13
+ factory :item_custom_property, class: CustomProperty do
14
+ association :resource, factory: :item
15
+ sequence(:label){|n| "custom property #{n}"}
16
+ sequence(:value){|n| "カスタム項目 #{n}"}
17
+ end
18
+ end
@@ -2,9 +2,10 @@ FactoryBot.define do
2
2
  factory :series_statement do |f|
3
3
  f.sequence(:original_title){|n| "series_statement_#{n}"}
4
4
  end
5
- factory :series_statement_serial, class: SeriesStatement do |f|
6
- f.sequence(:original_title){|n| "series_statement_serial_#{n}" }
5
+ factory :series_statement_serial, class: SeriesStatement do
6
+ sequence(:original_title){|n| "series_statement_serial_#{n}" }
7
+ sequence(:creator_string){|n| "シリーズの著者 #{n}" }
7
8
  #f.root_manifestation_id{FactoryBot.create(:manifestation_serial).id}
8
- f.series_master{true}
9
+ series_master{true}
9
10
  end
10
11
  end
@@ -231,7 +231,7 @@ item_00021:
231
231
  include_supplements: false
232
232
  created_at: 2007-08-24 23:46:20.484813 +09:00
233
233
  item_00022:
234
- updated_at: 2007-08-24 23:46:20.484813 +09:00
234
+ updated_at: 2007-08-24 23:46:21.484813 +09:00
235
235
  item_identifier: '00022'
236
236
  circulation_status_id: 2
237
237
  checkout_type_id: 3
@@ -240,9 +240,9 @@ item_00022:
240
240
  manifestation_id: 11
241
241
  id: 22
242
242
  include_supplements: false
243
- created_at: 2007-08-24 23:46:20.484813 +09:00
243
+ created_at: 2007-08-24 23:46:21.484813 +09:00
244
244
  item_00023:
245
- updated_at: 2007-08-24 23:46:20.484813 +09:00
245
+ updated_at: 2007-08-24 23:46:22.484813 +09:00
246
246
  item_identifier: '00023'
247
247
  circulation_status_id: 15
248
248
  checkout_type_id: 3
@@ -251,9 +251,9 @@ item_00023:
251
251
  manifestation_id: 11
252
252
  id: 23
253
253
  include_supplements: false
254
- created_at: 2007-08-24 23:46:20.484813 +09:00
254
+ created_at: 2007-08-24 23:46:22.484813 +09:00
255
255
  item_00024:
256
- updated_at: 2007-08-24 23:46:08.607081 +09:00
256
+ updated_at: 2007-08-24 23:46:23.607081 +09:00
257
257
  item_identifier: '00024'
258
258
  circulation_status_id: 2
259
259
  checkout_type_id: 1
@@ -262,10 +262,10 @@ item_00024:
262
262
  manifestation_id: 102
263
263
  id: 24
264
264
  include_supplements: false
265
- created_at: 2007-08-24 23:46:08.607081 +09:00
266
- acquired_at: 2015-08-25 23:46:08.607081 +09:00
265
+ created_at: 2007-08-24 23:23:08.607081 +09:00
266
+ acquired_at: 2015-08-25 23:23:08.607081 +09:00
267
267
  item_00025:
268
- updated_at: 2007-08-24 23:46:08.607081 +09:00
268
+ updated_at: 2007-08-24 23:46:24.607081 +09:00
269
269
  item_identifier: '00025'
270
270
  circulation_status_id: 2
271
271
  checkout_type_id: 1
@@ -274,8 +274,8 @@ item_00025:
274
274
  manifestation_id: 102
275
275
  id: 25
276
276
  include_supplements: false
277
- created_at: 2007-08-24 23:46:08.607081 +09:00
278
- acquired_at: 2015-09-25 23:46:08.607081 +09:00
277
+ created_at: 2007-08-24 23:46:24.607081 +09:00
278
+ acquired_at: 2015-09-25 23:46:24.607081 +09:00
279
279
 
280
280
  # == Schema Information
281
281
  #
@@ -304,4 +304,5 @@ item_00025:
304
304
  # binding_call_number :string
305
305
  # binded_at :datetime
306
306
  # manifestation_id :integer not null
307
+ # memo :text
307
308
  #