enju_biblio 0.3.10.rc.1 → 0.3.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/item_custom_properties_controller.rb +8 -3
  3. data/app/controllers/items_controller.rb +13 -2
  4. data/app/controllers/manifestation_custom_properties_controller.rb +8 -3
  5. data/app/controllers/manifestations_controller.rb +36 -48
  6. data/app/models/item.rb +9 -5
  7. data/app/models/item_custom_property.rb +7 -7
  8. data/app/models/item_custom_value.rb +3 -3
  9. data/app/models/manifestation.rb +38 -12
  10. data/app/models/manifestation_custom_property.rb +7 -7
  11. data/app/models/manifestation_custom_value.rb +3 -3
  12. data/app/models/picture_file.rb +0 -2
  13. data/app/models/resource_export_file.rb +4 -2
  14. data/app/models/resource_import_file.rb +74 -56
  15. data/app/policies/item_custom_property_policy.rb +3 -3
  16. data/app/policies/manifestation_custom_property_policy.rb +3 -3
  17. data/app/views/item_custom_properties/edit.html.erb +12 -5
  18. data/app/views/item_custom_properties/index.html.erb +14 -7
  19. data/app/views/item_custom_properties/new.html.erb +11 -4
  20. data/app/views/item_custom_properties/show.html.erb +24 -17
  21. data/app/views/items/_item.json.jbuilder +17 -0
  22. data/app/views/items/index.json.jbuilder +5 -0
  23. data/app/views/items/show.json.jbuilder +1 -0
  24. data/app/views/manifestation_custom_properties/edit.html.erb +12 -5
  25. data/app/views/manifestation_custom_properties/index.html.erb +14 -7
  26. data/app/views/manifestation_custom_properties/new.html.erb +11 -4
  27. data/app/views/manifestation_custom_properties/show.html.erb +24 -17
  28. data/app/views/manifestations/_export_detail.html.erb +1 -0
  29. data/app/views/manifestations/_export_list.html.erb +1 -0
  30. data/app/views/manifestations/_form.html.erb +5 -0
  31. data/app/views/manifestations/_show_detail_librarian.html.erb +6 -0
  32. data/app/views/manifestations/_show_detail_user.html.erb +8 -0
  33. data/app/views/manifestations/show.json.jbuilder +2 -0
  34. data/config/locales/translation_en.yml +2 -0
  35. data/config/locales/translation_ja.yml +2 -0
  36. data/db/migrate/20081027150907_create_picture_files.rb +0 -2
  37. data/lib/enju_biblio.rb +0 -2
  38. data/lib/enju_biblio/openurl.rb +5 -1
  39. data/lib/enju_biblio/version.rb +1 -1
  40. data/spec/controllers/item_custom_properties_controller_spec.rb +449 -0
  41. data/spec/controllers/items_controller_spec.rb +36 -0
  42. data/spec/controllers/manifestation_custom_properties_controller_spec.rb +449 -0
  43. data/spec/controllers/manifestations_controller_spec.rb +0 -19
  44. data/spec/dummy/db/schema.rb +0 -2
  45. data/spec/fixtures/creates.yml +2 -0
  46. data/spec/fixtures/item_custom_properties.yml +7 -7
  47. data/spec/fixtures/manifestation_custom_properties.yml +7 -7
  48. data/spec/fixtures/picture_files.yml +0 -2
  49. data/spec/fixtures/produces.yml +2 -0
  50. data/spec/fixtures/realizes.yml +2 -0
  51. data/spec/models/item_custom_property_spec.rb +7 -7
  52. data/spec/models/item_custom_value_spec.rb +3 -3
  53. data/spec/models/manifestation_custom_property_spec.rb +7 -7
  54. data/spec/models/manifestation_custom_value_spec.rb +3 -3
  55. data/spec/models/manifestation_spec.rb +1 -66
  56. data/spec/models/picture_file_spec.rb +0 -2
  57. data/spec/models/resource_export_file_spec.rb +61 -8
  58. data/spec/models/resource_import_file_spec.rb +5 -1
  59. data/spec/views/item_custom_properties/index.html.erb_spec.rb +1 -0
  60. data/spec/views/items/index.json.jbuilder_spec.rb +15 -0
  61. data/spec/views/items/show.json.jbuilder_spec.rb +15 -0
  62. data/spec/views/manifestation_custom_properties/index.html.erb_spec.rb +1 -0
  63. data/spec/views/manifestations/show.json.jbuilder_spec.rb +16 -0
  64. metadata +535 -525
  65. data/app/views/manifestations/explain.sru +0 -9
  66. data/app/views/manifestations/index.sru.builder +0 -101
  67. data/lib/enju_biblio/porta_cql.rb +0 -282
  68. data/lib/enju_biblio/sru.rb +0 -83
@@ -45,9 +45,7 @@ end
45
45
  # id :integer not null, primary key
46
46
  # picture_attachable_id :integer
47
47
  # picture_attachable_type :string
48
- # content_type :string
49
48
  # title :text
50
- # thumbnail :string
51
49
  # position :integer
52
50
  # created_at :datetime
53
51
  # updated_at :datetime
@@ -31,8 +31,10 @@ class ResourceExportFile < ApplicationRecord
31
31
  transition_to!(:started)
32
32
  role_name = user.try(:role).try(:name)
33
33
  tsv = Manifestation.export(role: role_name)
34
- self.resource_export = StringIO.new(tsv)
35
- self.resource_export.instance_write(:filename, "resource_export.txt")
34
+ file = StringIO.new(tsv)
35
+ file.class.class_eval { attr_accessor :original_filename, :content_type }
36
+ file.original_filename = 'resource_export.txt'
37
+ self.resource_export = file
36
38
  save!
37
39
  transition_to!(:completed)
38
40
  mailer = ResourceExportMailer.completed(self)
@@ -322,55 +322,15 @@ class ResourceImportFile < ApplicationRecord
322
322
  rows.each do |row|
323
323
  row_num += 1
324
324
  import_result = ResourceImportResult.create!(resource_import_file_id: id, body: row.fields.join("\t"))
325
- item_identifier = row['item_identifier'].to_s.strip
326
- item = Item.find_by(item_identifier: item_identifier) if item_identifier.present?
325
+ item = Item.find_by(item_identifier: row['item_identifier'].to_s.strip) if row['item_identifier'].to_s.strip.present?
326
+ unless item
327
+ item = Item.find_by(id: row['item_id'].to_s.strip) if row['item_id'].to_s.strip.present?
328
+ end
329
+
327
330
  if item
328
331
  if item.manifestation
329
332
  fetch(row, edit_mode: 'update')
330
- end
331
-
332
- shelf = Shelf.find_by(name: row['shelf'].to_s.strip)
333
- bookstore = Bookstore.find_by(name: row['bookstore'])
334
- required_role = Role.find_by(name: row['required_role'])
335
-
336
- item.shelf = shelf if shelf
337
- item.bookstore = bookstore if bookstore
338
- item.required_role = required_role if required_role
339
-
340
- acquired_at = Time.zone.parse(row['acquired_at']) rescue nil
341
- binded_at = Time.zone.parse(row['binded_at']) rescue nil
342
- item.acquired_at = acquired_at if acquired_at
343
- item.binded_at = binded_at if binded_at
344
-
345
- if defined?(EnjuCirculation)
346
- circulation_status = CirculationStatus.find_by(name: row['circulation_status'])
347
- checkout_type = CheckoutType.find_by(name: row['checkout_type'])
348
- use_restriction = UseRestriction.find_by(name: row['use_restriction'].to_s.strip)
349
- item.circulation_status = circulation_status if circulation_status
350
- item.checkout_type = checkout_type if checkout_type
351
- item.use_restriction = use_restriction if use_restriction
352
- end
353
-
354
- item_columns = %w(
355
- call_number
356
- binding_item_identifier binding_call_number binded_at
357
- )
358
- item_columns.each do |column|
359
- if row[column].present?
360
- item.assign_attributes(:"#{column}" => row[column])
361
- end
362
- end
363
-
364
- item.price = row['item_price'] if row['item_price'].present?
365
- item.note = row['item_note'].try(:gsub, /\\n/, "\n") if row['item_note'].present?
366
- item.url = row['item_url'] if row['item_url'].present?
367
-
368
- if row['include_supplements']
369
- if %w(t true).include?(row['include_supplements'].downcase.strip)
370
- item.include_supplements = true
371
- else
372
- item.include_supplements = false if item.include_supplements
373
- end
333
+ item = update_item(item, row)
374
334
  end
375
335
 
376
336
  ResourceImportFile.import_item_custom_value(row, item).each do |value|
@@ -419,8 +379,11 @@ class ResourceImportFile < ApplicationRecord
419
379
 
420
380
  rows.each do |row|
421
381
  row_num += 1
422
- item_identifier = row['item_identifier'].to_s.strip
423
- item = Item.find_by(item_identifier: item_identifier)
382
+ item = Item.find_by(item_identifier: row['item_identifier'].to_s.strip) if row['item_identifier'].to_s.strip.present?
383
+ unless item
384
+ item = Item.find_by(id: row['item_id'].to_s.strip) if row['item_id'].to_s.strip.present?
385
+ end
386
+
424
387
  if item
425
388
  item.destroy if item.removable?
426
389
  end
@@ -444,10 +407,9 @@ class ResourceImportFile < ApplicationRecord
444
407
  row_num = 1
445
408
 
446
409
  rows.each do |row|
447
- item_identifier = row['item_identifier'].to_s.strip
448
- item = Item.find_by(item_identifier: item_identifier)
410
+ item = Item.find_by(item_identifier: row['item_identifier'].to_s.strip) if row['item_identifier'].to_s.strip.present?
449
411
  unless item
450
- item = Item.find_by(id: row['item_id'].to_s.strip)
412
+ item = Item.find_by(id: row['item_id'].to_s.strip) if row['item_id'].to_s.strip.present?
451
413
  end
452
414
 
453
415
  manifestation_identifier = row['manifestation_identifier'].to_s.strip
@@ -603,12 +565,68 @@ class ResourceImportFile < ApplicationRecord
603
565
  item
604
566
  end
605
567
 
568
+ def update_item(item, row)
569
+ shelf = Shelf.find_by(name: row['shelf'].to_s.strip)
570
+ bookstore = Bookstore.find_by(name: row['bookstore'])
571
+ required_role = Role.find_by(name: row['required_role'])
572
+
573
+ item.shelf = shelf if shelf
574
+ item.bookstore = bookstore if bookstore
575
+ item.required_role = required_role if required_role
576
+
577
+ acquired_at = Time.zone.parse(row['acquired_at']) rescue nil
578
+ binded_at = Time.zone.parse(row['binded_at']) rescue nil
579
+ item.acquired_at = acquired_at if acquired_at
580
+ item.binded_at = binded_at if binded_at
581
+
582
+ if defined?(EnjuCirculation)
583
+ circulation_status = CirculationStatus.find_by(name: row['circulation_status'])
584
+ checkout_type = CheckoutType.find_by(name: row['checkout_type'])
585
+ use_restriction = UseRestriction.find_by(name: row['use_restriction'].to_s.strip)
586
+ item.circulation_status = circulation_status if circulation_status
587
+ item.checkout_type = checkout_type if checkout_type
588
+ item.use_restriction = use_restriction if use_restriction
589
+ end
590
+
591
+ item_columns = %w(
592
+ call_number
593
+ binding_item_identifier binding_call_number binded_at
594
+ )
595
+ item_columns.each do |column|
596
+ if row[column].present?
597
+ item.assign_attributes(:"#{column}" => row[column])
598
+ end
599
+ end
600
+
601
+ item.price = row['item_price'] if row['item_price'].present?
602
+ item.note = row['item_note'].try(:gsub, /\\n/, "\n") if row['item_note'].present?
603
+ item.url = row['item_url'] if row['item_url'].present?
604
+
605
+ if row['include_supplements']
606
+ if %w(t true).include?(row['include_supplements'].downcase.strip)
607
+ item.include_supplements = true
608
+ else
609
+ item.include_supplements = false if item.include_supplements
610
+ end
611
+ end
612
+
613
+ item
614
+ end
615
+
606
616
  def fetch(row, options = {edit_mode: 'create'})
607
- case options[:edit_mode]
608
- when 'create'
609
- manifestation = nil
610
- when 'update'
611
- manifestation = Item.find_by(item_identifier: row['item_identifier'].to_s.strip).try(:manifestation)
617
+ manifestation = nil
618
+ item = nil
619
+
620
+ if options[:edit_mode] == 'update'
621
+ if row['item_identifier'].to_s.strip.present?
622
+ item = Item.find_by(item_identifier: row['item_identifier'].to_s.strip)
623
+ end
624
+ if row['item_id'].to_s.strip.present?
625
+ item = Item.find_by(id: row['item_id'].to_s.strip)
626
+ end
627
+
628
+ manifestation = item.manifestation if item
629
+
612
630
  unless manifestation
613
631
  manifestation_identifier = row['manifestation_identifier'].to_s.strip
614
632
  manifestation = Manifestation.find_by(manifestation_identifier: manifestation_identifier) if manifestation_identifier
@@ -8,14 +8,14 @@ class ItemCustomPropertyPolicy < ApplicationPolicy
8
8
  end
9
9
 
10
10
  def create?
11
- true if user.try(:has_role?, 'Librarian')
11
+ true if user.try(:has_role?, 'Administrator')
12
12
  end
13
13
 
14
14
  def update?
15
- true if user.try(:has_role?, 'Librarian')
15
+ true if user.try(:has_role?, 'Administrator')
16
16
  end
17
17
 
18
18
  def destroy?
19
- true if user.try(:has_role?, 'Librarian')
19
+ true if user.try(:has_role?, 'Administrator')
20
20
  end
21
21
  end
@@ -8,14 +8,14 @@ class ManifestationCustomPropertyPolicy < ApplicationPolicy
8
8
  end
9
9
 
10
10
  def create?
11
- true if user.try(:has_role?, 'Librarian')
11
+ true if user.try(:has_role?, 'Administrator')
12
12
  end
13
13
 
14
14
  def update?
15
- true if user.try(:has_role?, 'Librarian')
15
+ true if user.try(:has_role?, 'Administrator')
16
16
  end
17
17
 
18
18
  def destroy?
19
- true if user.try(:has_role?, 'Librarian')
19
+ true if user.try(:has_role?, 'Administrator')
20
20
  end
21
21
  end
@@ -1,6 +1,13 @@
1
- <h1><%= t('page.editing', model: t('activerecord.models.item_custom_property')) -%></h1>
1
+ <div id="content_detail" class="ui-corner-all ui-widget-content">
2
+ <h1 class="title"><%= t('page.editing', model: t('activerecord.models.item_custom_property')) -%></h1>
3
+ <div id="content_list">
4
+ <%= render 'form', item_custom_property: @item_custom_property %>
5
+ </div>
6
+ </div>
2
7
 
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 %>
8
+ <div id="submenu" class="ui-corner-all ui-widget-content">
9
+ <ul>
10
+ <li><%= link_to t('page.show'), @item_custom_property %></li>
11
+ <li><%= link_to t('page.back'), item_custom_properties_path %></li>
12
+ </ul>
13
+ </div>
@@ -1,5 +1,6 @@
1
- <div class="row">
2
- <div class="col-md-9">
1
+ <div id="content_detail" class="ui-corner-all ui-widget-content">
2
+ <h1 class="title"><%= t('page.listing', model: t('activerecord.models.item_custom_property')) -%></h1>
3
+ <div id="content_list">
3
4
  <p id="notice"><%= notice %></p>
4
5
 
5
6
  <h1><%= t('page.listing', model: t('activerecord.models.item_custom_property')) -%></h1>
@@ -7,6 +8,7 @@
7
8
  <table class='table table-striped index'>
8
9
  <thead>
9
10
  <tr>
11
+ <th id="position"></th>
10
12
  <th><%= t('activerecord.attributes.item_custom_property.name') %></th>
11
13
  <th><%= t('activerecord.attributes.item_custom_property.display_name') %></th>
12
14
  <th><%= t('activerecord.attributes.item_custom_property.note') %></th>
@@ -17,6 +19,11 @@
17
19
  <tbody>
18
20
  <% @item_custom_properties.each do |item_custom_property| %>
19
21
  <tr>
22
+ <td>
23
+ <%- if policy(item_custom_property).update? -%>
24
+ <%= move_position(item_custom_property) -%>
25
+ <%- end -%>
26
+ </td>
20
27
  <td><%= link_to item_custom_property.name, item_custom_property %></td>
21
28
  <td><%= item_custom_property.display_name.localize %></td>
22
29
  <td><%= item_custom_property.note %></td>
@@ -27,10 +34,10 @@
27
34
  </tbody>
28
35
  </table>
29
36
  </div>
37
+ </div>
30
38
 
31
- <div class="col">
32
- <div class="card card-body">
33
- <%= link_to t('page.new', model: t('activerecord.models.item_custom_property')), new_item_custom_property_path -%>
34
- </div>
35
- </div>
39
+ <div id="submenu" class="ui-corner-all ui-widget-content">
40
+ <ul>
41
+ <li><%= link_to t('page.new', model: t('activerecord.models.item_custom_property')), new_item_custom_property_path -%></li>
42
+ </ul>
36
43
  </div>
@@ -1,5 +1,12 @@
1
- <h1><%= t('page.new', model: t('activerecord.models.item_custom_property')) -%></h1>
1
+ <div id="content_detail" class="ui-corner-all ui-widget-content">
2
+ <h1 class="title"><%= t('page.new', model: t('activerecord.models.item_custom_property')) -%></h1>
3
+ <div id="content_list">
4
+ <%= render 'form', item_custom_property: @item_custom_property %>
5
+ </div>
6
+ </div>
2
7
 
3
- <%= render 'form', item_custom_property: @item_custom_property %>
4
-
5
- <%= link_to t('page.back'), item_custom_properties_path %>
8
+ <div id="submenu" class="ui-corner-all ui-widget-content">
9
+ <ul>
10
+ <li><%= link_to t('page.back'), item_custom_properties_path %></li>
11
+ </ul>
12
+ </div>
@@ -1,21 +1,28 @@
1
- <h1><%= t('page.showing', model: t('activerecord.models.item_custom_property')) -%></h1>
1
+ <div id="content_detail" class="ui-corner-all ui-widget-content">
2
+ <h1 class="title"><%= t('page.showing', model: t('activerecord.models.item_custom_property')) -%></h1>
3
+ <div id="content_list">
4
+ <p id="notice"><%= notice %></p>
2
5
 
3
- <p id="notice"><%= notice %></p>
6
+ <p>
7
+ <strong><%= t('activerecord.attributes.item_custom_property.name') %>:</strong>
8
+ <%= @item_custom_property.name %>
9
+ </p>
4
10
 
5
- <p>
6
- <strong><%= t('activerecord.attributes.item_custom_property.name') %>:</strong>
7
- <%= @item_custom_property.name %>
8
- </p>
11
+ <p>
12
+ <strong><%= t('activerecord.attributes.item_custom_property.display_name') %>:</strong>
13
+ <%= @item_custom_property.display_name.localize %>
14
+ </p>
9
15
 
10
- <p>
11
- <strong><%= t('activerecord.attributes.item_custom_property.display_name') %>:</strong>
12
- <%= @item_custom_property.display_name.localize %>
13
- </p>
16
+ <p>
17
+ <strong><%= t('activerecord.attributes.item_custom_property.note') %>:</strong>
18
+ <%= @item_custom_property.note %>
19
+ </p>
20
+ </div>
21
+ </div>
14
22
 
15
- <p>
16
- <strong><%= t('activerecord.attributes.item_custom_property.note') %>:</strong>
17
- <%= @item_custom_property.note %>
18
- </p>
19
-
20
- <%= link_to t('page.edit'), edit_item_custom_property_path(@item_custom_property) %> |
21
- <%= link_to t('page.back'), item_custom_properties_path %>
23
+ <div id="submenu" class="ui-corner-all ui-widget-content">
24
+ <ul>
25
+ <li><%= link_to t('page.edit'), edit_item_custom_property_path(@item_custom_property) %></li>
26
+ <li><%= link_to t('page.back'), item_custom_properties_path %></li>
27
+ </ul>
28
+ </div>
@@ -0,0 +1,17 @@
1
+ json.id item.id
2
+ json.manifestation_id item.manifestation_id
3
+ json.item_identifier item.item_identifier
4
+ json.call_number item.call_number
5
+ json.shelf item.shelf.name
6
+ if defined?(EnjuCirculation)
7
+ json.circulation_status item.circulation_status&.name
8
+ end
9
+ json.binding_item_identifier item.binding_item_identifier
10
+ json.binding_call_number item.binding_call_number
11
+ json.binded_at item.binded_at
12
+ json.acquired_at item.acquired_at
13
+ json.include_supplements item.include_supplements
14
+ json.url item.url
15
+ json.note item.note
16
+ json.created_at item.created_at
17
+ json.updated_at item.updated_at
@@ -0,0 +1,5 @@
1
+ json.results do
2
+ json.array!(@items) do |item|
3
+ json.partial!(item)
4
+ end
5
+ end
@@ -0,0 +1 @@
1
+ json.partial!(@item)
@@ -1,6 +1,13 @@
1
- <h1><%= t('page.editing', model: t('activerecord.models.manifestation_custom_property')) -%></h1>
1
+ <div id="content_detail" class="ui-corner-all ui-widget-content">
2
+ <h1 class="title"><%= t('page.editing', model: t('activerecord.models.manifestation_custom_property')) -%></h1>
3
+ <div id="content_list">
4
+ <%= render 'form', manifestation_custom_property: @manifestation_custom_property %>
5
+ </div>
6
+ </div>
2
7
 
3
- <%= render 'form', manifestation_custom_property: @manifestation_custom_property %>
4
-
5
- <%= link_to t('page.show'), @manifestation_custom_property %> |
6
- <%= link_to t('page.back'), manifestation_custom_properties_path %>
8
+ <div id="submenu" class="ui-corner-all ui-widget-content">
9
+ <ul>
10
+ <li><%= link_to t('page.show'), @manifestation_custom_property %></li>
11
+ <li><%= link_to t('page.back'), manifestation_custom_properties_path %></li>
12
+ </ul>
13
+ </div>
@@ -1,5 +1,6 @@
1
- <div class="row">
2
- <div class="col-md-9">
1
+ <div id="content_detail" class="ui-corner-all ui-widget-content">
2
+ <h1 class="title"><%= t('page.listing', model: t('activerecord.models.manifestation_custom_property')) -%></h1>
3
+ <div id="content_list">
3
4
  <p id="notice"><%= notice %></p>
4
5
 
5
6
  <h1><%= t('page.listing', model: t('activerecord.models.manifestation_custom_property')) -%></h1>
@@ -7,6 +8,7 @@
7
8
  <table class='table table-striped index'>
8
9
  <thead>
9
10
  <tr>
11
+ <th id="position"></th>
10
12
  <th><%= t('activerecord.attributes.manifestation_custom_property.name') %></th>
11
13
  <th><%= t('activerecord.attributes.manifestation_custom_property.display_name') %></th>
12
14
  <th><%= t('activerecord.attributes.manifestation_custom_property.note') %></th>
@@ -17,6 +19,11 @@
17
19
  <tbody>
18
20
  <% @manifestation_custom_properties.each do |manifestation_custom_property| %>
19
21
  <tr>
22
+ <td>
23
+ <%- if policy(manifestation_custom_property).update? -%>
24
+ <%= move_position(manifestation_custom_property) -%>
25
+ <%- end -%>
26
+ </td>
20
27
  <td><%= link_to manifestation_custom_property.name, manifestation_custom_property %></td>
21
28
  <td><%= manifestation_custom_property.display_name.localize %></td>
22
29
  <td><%= manifestation_custom_property.note %></td>
@@ -27,10 +34,10 @@
27
34
  </tbody>
28
35
  </table>
29
36
  </div>
37
+ </div>
30
38
 
31
- <div class="col">
32
- <div class="card card-body">
33
- <%= link_to t('page.new', model: t('activerecord.models.manifestation_custom_property')), new_manifestation_custom_property_path -%>
34
- </div>
35
- </div>
39
+ <div id="submenu" class="ui-corner-all ui-widget-content">
40
+ <ul>
41
+ <li><%= link_to t('page.new', model: t('activerecord.models.manifestation_custom_property')), new_manifestation_custom_property_path -%></li>
42
+ </ul>
36
43
  </div>