enju_event 0.3.2 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +11 -0
  3. data/app/controllers/concerns/enju_event/enju_libraries_controller.rb +17 -0
  4. data/app/controllers/event_categories_controller.rb +1 -1
  5. data/app/controllers/event_export_files_controller.rb +1 -1
  6. data/app/controllers/event_import_files_controller.rb +3 -2
  7. data/app/controllers/event_import_results_controller.rb +4 -4
  8. data/app/controllers/events_controller.rb +8 -2
  9. data/app/controllers/participates_controller.rb +1 -1
  10. data/app/controllers/places_controller.rb +1 -1
  11. data/app/jobs/event_export_file_job.rb +1 -1
  12. data/app/jobs/event_import_file_job.rb +1 -1
  13. data/app/mailers/event_export_mailer.rb +17 -0
  14. data/app/mailers/event_import_mailer.rb +17 -0
  15. data/app/models/concerns/enju_event/enju_library.rb +15 -0
  16. data/app/models/event.rb +37 -24
  17. data/app/models/event_category.rb +1 -1
  18. data/app/models/event_export_file.rb +15 -10
  19. data/app/models/event_export_file_transition.rb +1 -1
  20. data/app/models/event_import_file.rb +18 -12
  21. data/app/models/event_import_file_transition.rb +1 -1
  22. data/app/models/event_import_result.rb +7 -2
  23. data/app/models/participate.rb +1 -1
  24. data/app/models/place.rb +1 -1
  25. data/app/views/event_categories/_form.html.erb +1 -1
  26. data/app/views/event_export_mailer/completed.en.text.erb +9 -0
  27. data/app/views/event_export_mailer/completed.ja.text.erb +9 -0
  28. data/app/views/event_export_mailer/failed.en.text.erb +9 -0
  29. data/app/views/event_export_mailer/failed.ja.text.erb +9 -0
  30. data/app/views/event_import_files/_results.html.erb +26 -0
  31. data/app/views/event_import_files/show.html.erb +70 -74
  32. data/app/views/event_import_mailer/completed.en.text.erb +9 -0
  33. data/app/views/event_import_mailer/completed.ja.text.erb +9 -0
  34. data/app/views/event_import_mailer/failed.en.text.erb +9 -0
  35. data/app/views/event_import_mailer/failed.ja.text.erb +9 -0
  36. data/app/views/event_import_results/index.html.erb +0 -11
  37. data/app/views/event_import_results/index.text.ruby +5 -0
  38. data/app/views/events/index.html.erb +22 -22
  39. data/app/views/events/index.text.ruby +7 -0
  40. data/app/views/layouts/mailer.html.erb +13 -0
  41. data/app/views/layouts/mailer.text.erb +1 -0
  42. data/config/brakeman.ignore +66 -0
  43. data/config/locales/translation_en.yml +12 -0
  44. data/config/locales/translation_ja.yml +12 -0
  45. data/lib/enju_event/engine.rb +0 -1
  46. data/lib/enju_event/version.rb +1 -1
  47. data/lib/generators/enju_event/setup/setup_generator.rb +1 -1
  48. data/spec/controllers/event_import_files_controller_spec.rb +2 -2
  49. data/spec/controllers/event_import_results_controller_spec.rb +2 -2
  50. data/spec/controllers/events_controller_spec.rb +2 -2
  51. data/spec/controllers/libraries_controller_spec.rb +41 -0
  52. data/spec/dummy/app/assets/config/manifest.js +5 -0
  53. data/spec/dummy/app/jobs/application_job.rb +7 -0
  54. data/spec/dummy/app/mailers/application_mailer.rb +4 -0
  55. data/spec/dummy/app/models/application_record.rb +3 -0
  56. data/spec/dummy/app/models/user.rb +1 -1
  57. data/spec/dummy/config/application.rb +1 -1
  58. data/spec/dummy/config/initializers/assets.rb +1 -0
  59. data/spec/dummy/config/initializers/mime_types.rb +1 -0
  60. data/spec/dummy/config/storage.yml +34 -0
  61. data/spec/dummy/db/migrate/20081025083323_create_countries.rb +4 -4
  62. data/spec/dummy/db/migrate/20100606065209_create_user_has_roles.rb +2 -4
  63. data/spec/dummy/db/migrate/20140122054321_create_profiles.rb +4 -5
  64. data/spec/dummy/db/migrate/20150421023923_create_identities.rb +14 -0
  65. data/spec/dummy/db/migrate/20151126005552_add_provider_to_identity.rb +5 -0
  66. data/spec/dummy/db/migrate/20151213070943_add_translation_table_to_library_group.rb +0 -8
  67. data/spec/dummy/db/migrate/20160506144040_create_isbn_records.rb +11 -0
  68. data/spec/dummy/db/migrate/20180107162659_add_constraints_to_most_recent_for_message_transitions.rb +13 -0
  69. data/spec/dummy/db/migrate/20180107162711_add_constraints_to_most_recent_for_message_request_transitions.rb +13 -0
  70. data/spec/dummy/db/migrate/20181026064038_add_login_banner_to_library_group.rb +6 -0
  71. data/spec/dummy/db/migrate/20181030072731_add_not_null_to_position_on_carrier_type.rb +14 -0
  72. data/spec/dummy/db/migrate/20181030074920_add_not_null_to_position_on_library.rb +14 -0
  73. data/spec/dummy/db/migrate/20190208135957_create_active_storage_tables.active_storage.rb +27 -0
  74. data/spec/dummy/db/migrate/20190311154610_create_periodicals.rb +10 -0
  75. data/spec/dummy/db/migrate/20190314151124_add_full_name_translations_to_create.rb +7 -0
  76. data/spec/dummy/db/migrate/20190818075603_add_memo_to_manifestation.rb +5 -0
  77. data/spec/dummy/db/migrate/20190818075628_add_memo_to_item.rb +5 -0
  78. data/spec/dummy/db/migrate/20191219122214_create_custom_properties.rb +12 -0
  79. data/spec/dummy/db/migrate/20200425072340_create_manifestation_custom_properties.rb +12 -0
  80. data/spec/dummy/db/migrate/20200425072349_create_item_custom_properties.rb +12 -0
  81. data/spec/dummy/db/migrate/20200425074758_create_manifestation_custom_values.rb +12 -0
  82. data/spec/dummy/db/migrate/20200425074822_create_item_custom_values.rb +12 -0
  83. data/spec/dummy/db/schema.rb +131 -304
  84. data/spec/factories/event_export_file.rb +5 -0
  85. data/spec/factories/event_import_file.rb +7 -0
  86. data/spec/factories/event_import_result.rb +6 -0
  87. data/spec/mailers/event_export_spec.rb +5 -0
  88. data/spec/mailers/event_import_spec.rb +5 -0
  89. data/spec/mailers/previews/event_export_preview.rb +4 -0
  90. data/spec/mailers/previews/event_import_preview.rb +4 -0
  91. data/spec/models/event_export_file_spec.rb +1 -1
  92. data/spec/models/event_import_file_spec.rb +1 -1
  93. data/spec/rails_helper.rb +6 -0
  94. data/spec/system/event_import_results_spec.rb +17 -0
  95. data/spec/system/events_spec.rb +22 -0
  96. data/spec/views/event_import_results/index.text.ruby_spec.rb +22 -0
  97. data/spec/views/events/index.json.jbuilder_spec.rb +22 -0
  98. metadata +405 -315
  99. data/README.rdoc +0 -10
  100. data/app/views/event_import_results/index.txt.erb +0 -3
  101. data/app/views/events/index.txt.erb +0 -4
  102. data/spec/dummy/db/migrate/032_create_checkins.rb +0 -17
  103. data/spec/dummy/db/migrate/033_create_checkouts.rb +0 -25
  104. data/spec/dummy/db/migrate/035_create_reserves.rb +0 -26
  105. data/spec/dummy/db/migrate/121_create_checked_items.rb +0 -17
  106. data/spec/dummy/db/migrate/127_create_use_restrictions.rb +0 -16
  107. data/spec/dummy/db/migrate/129_create_item_has_use_restrictions.rb +0 -16
  108. data/spec/dummy/db/migrate/132_create_circulation_statuses.rb +0 -16
  109. data/spec/dummy/db/migrate/20081030023412_create_checkout_types.rb +0 -17
  110. data/spec/dummy/db/migrate/20081030023518_create_user_group_has_checkout_types.rb +0 -25
  111. data/spec/dummy/db/migrate/20081030023615_create_carrier_type_has_checkout_types.rb +0 -18
  112. data/spec/dummy/db/migrate/20081212075554_create_checkout_stat_has_manifestations.rb +0 -17
  113. data/spec/dummy/db/migrate/20081212080038_create_manifestation_checkout_stats.rb +0 -15
  114. data/spec/dummy/db/migrate/20081215094302_create_user_checkout_stats.rb +0 -15
  115. data/spec/dummy/db/migrate/20081215094955_create_checkout_stat_has_users.rb +0 -17
  116. data/spec/dummy/db/migrate/20081216190517_create_reserve_stat_has_manifestations.rb +0 -17
  117. data/spec/dummy/db/migrate/20081216190724_create_manifestation_reserve_stats.rb +0 -15
  118. data/spec/dummy/db/migrate/20081220023628_create_user_reserve_stats.rb +0 -15
  119. data/spec/dummy/db/migrate/20081220034117_create_reserve_stat_has_users.rb +0 -17
  120. data/spec/dummy/db/migrate/20090321130448_add_completed_at_to_user_checkout_stat.rb +0 -23
  121. data/spec/dummy/db/migrate/20110301134521_add_expire_date_to_reserve.rb +0 -9
  122. data/spec/dummy/db/migrate/20110328130826_add_current_checkout_count_to_user_group_has_checkout_type.rb +0 -9
  123. data/spec/dummy/db/migrate/20110621093332_remove_expire_date_from_reserve.rb +0 -9
  124. data/spec/dummy/db/migrate/20111217234412_add_save_checkout_history_to_user.rb +0 -5
  125. data/spec/dummy/db/migrate/20111218002349_add_checkout_icalendar_token_to_user.rb +0 -6
  126. data/spec/dummy/db/migrate/20120424103932_add_librarian_id_to_checked_item.rb +0 -5
  127. data/spec/dummy/db/migrate/20130303124821_add_retained_at_to_reserve.rb +0 -5
  128. data/spec/dummy/db/migrate/20130304015019_add_postponed_at_to_reserve.rb +0 -5
  129. data/spec/dummy/db/migrate/20130416054135_add_circulation_status_id_to_item.rb +0 -8
  130. data/spec/dummy/db/migrate/20130519065638_add_lock_version_to_reserve.rb +0 -5
  131. data/spec/dummy/db/migrate/20130519065837_add_lock_version_to_checkin.rb +0 -5
  132. data/spec/dummy/db/migrate/20140518050147_create_reserve_transitions.rb +0 -18
  133. data/spec/dummy/db/migrate/20140528045518_create_user_checkout_stat_transitions.rb +0 -18
  134. data/spec/dummy/db/migrate/20140528045539_create_user_reserve_stat_transitions.rb +0 -18
  135. data/spec/dummy/db/migrate/20140528045600_create_manifestation_checkout_stat_transitions.rb +0 -18
  136. data/spec/dummy/db/migrate/20140528045617_create_manifestation_reserve_stat_transitions.rb +0 -18
  137. data/spec/dummy/db/migrate/20140810061942_add_user_id_to_user_checkout_stat.rb +0 -12
  138. data/spec/dummy/db/migrate/20140810091231_add_checkout_icalendar_token_to_profile.rb +0 -6
  139. data/spec/dummy/db/migrate/20140810091417_add_save_checkout_history_to_profile.rb +0 -5
  140. data/spec/dummy/db/migrate/20141014065831_add_shelf_id_to_checkout.rb +0 -6
  141. data/spec/support/resque.rb +0 -32
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fe8972f33249e3c93091453371867af2aaad982ff8e5556f98965b3986bdba47
4
- data.tar.gz: 384fd3ed3fbcfc45c2e42547688376feb12b45971175261f8efd7cb68339ea88
3
+ metadata.gz: 27b0c9dc4dc6da8c3186d98a1f4c6c99b9f95e4305f8c96b50297a5e692e3d86
4
+ data.tar.gz: c5298009340080f52bce7d1f9a698cf10b5772071b8ca4348b9129c348127a1b
5
5
  SHA512:
6
- metadata.gz: 4989defc134bdfb65c0a72f29b7a46811beda71d73eb630515eaa5932dcbcd9dbb7e72324dc814f221bddde485dbc5e688af278b37dc89eb4510e0f03bb552ed
7
- data.tar.gz: 2604ba288359404444ac06c3be9c18c6b3067d666f14ec42ecb67f78d9406ff1d3d0c4ff10ecfa54152e3b3e176e898b2add1a8be2a0c8b3ff1a840756f2bcdd
6
+ metadata.gz: 63640ab077e20f166c74c854980d1e7763d9c985a725a2d5e1cedf10030808e14d4ce7c36d19f34224cae9e4e84e556f06c89eedd8637ad5f812a2592dc4c00f
7
+ data.tar.gz: f171242671fd67136c9a5e1fe83fb36cfc0a03a40c8b704ad45f4de63145f5ea84e1406087b230c4799d86038f42879cd723e7cc5ddcc40d1980bf31e73620da
data/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # EnjuEvent
2
+ [![Travis CI](https://travis-ci.com/next-l/enju_event.svg?branch=1.3)](https://travis-ci.com/next-l/enju_event)
3
+ [![Coverage Status](https://coveralls.io/repos/github/next-l/enju_event/badge.svg?branch=1.3)](https://coveralls.io/github/next-l/enju_event?branch=1.3)
4
+ [![security](https://hakiri.io/github/next-l/enju_event/1.3.svg)](https://hakiri.io/github/next-l/enju_event/1.3)
5
+
6
+ This project rocks and uses MIT-LICENSE.
7
+
8
+ ## 製作者・貢献者 (Authors and contributors)
9
+ * [TANABE, Kosuke](https://github.com/nabeta) ([@nabeta](https://twitter.com/nabeta))
10
+ * [Project Next-L](https://www.next-l.jp) ([@ProjectNextL](https://twitter.com/ProjectNextL))
11
+
@@ -0,0 +1,17 @@
1
+ module EnjuEvent
2
+ module EnjuLibrariesController
3
+ extend ActiveSupport::Concern
4
+
5
+ def show
6
+ search = Sunspot.new_search(Event)
7
+ library_id = @library.id
8
+ search.build do
9
+ with(:library_id).equal_to library_id
10
+ order_by(:start_at, :desc)
11
+ end
12
+ page = params[:event_page] || 1
13
+ search.query.paginate(page.to_i, Event.default_per_page)
14
+ @events = search.execute!.results
15
+ end
16
+ end
17
+ end
@@ -62,7 +62,7 @@ class EventCategoriesController < ApplicationController
62
62
  end
63
63
 
64
64
  respond_to do |format|
65
- if @event_category.update_attributes(event_category_params)
65
+ if @event_category.update(event_category_params)
66
66
  format.html { redirect_to @event_category, notice: t('controller.successfully_updated', model: t('activerecord.models.event_category')) }
67
67
  format.json { head :no_content }
68
68
  else
@@ -76,7 +76,7 @@ class EventExportFilesController < ApplicationController
76
76
  # PUT /event_export_files/1.json
77
77
  def update
78
78
  respond_to do |format|
79
- if @event_export_file.update_attributes(event_export_file_params)
79
+ if @event_export_file.update(event_export_file_params)
80
80
  if @event_export_file.mode == 'export'
81
81
  EventExportFileJob.perform_later(@event_export_file)
82
82
  end
@@ -6,7 +6,7 @@ class EventImportFilesController < ApplicationController
6
6
  # GET /event_import_files
7
7
  # GET /event_import_files.json
8
8
  def index
9
- @event_import_files = EventImportFile.page(params[:page])
9
+ @event_import_files = EventImportFile.order(created_at: :desc).page(params[:page])
10
10
 
11
11
  respond_to do |format|
12
12
  format.html # index.html.erb
@@ -22,6 +22,7 @@ class EventImportFilesController < ApplicationController
22
22
  file = @event_import_file.event_import.path
23
23
  end
24
24
  end
25
+ @event_import_results = @event_import_file.event_import_results.page(params[:page])
25
26
 
26
27
  respond_to do |format|
27
28
  format.html # show.html.erb
@@ -78,7 +79,7 @@ class EventImportFilesController < ApplicationController
78
79
  # PUT /event_import_files/1.json
79
80
  def update
80
81
  respond_to do |format|
81
- if @event_import_file.update_attributes(event_import_file_params)
82
+ if @event_import_file.update(event_import_file_params)
82
83
  if @event_import_file.mode == 'import'
83
84
  EventImportFileJob.perform_later(@event_import_file)
84
85
  end
@@ -5,17 +5,17 @@ class EventImportResultsController < ApplicationController
5
5
  # GET /event_import_results
6
6
  # GET /event_import_results.json
7
7
  def index
8
- @event_import_file = EventImportFile.where(id: params[:event_import_file_id]).first
8
+ @event_import_file = EventImportFile.find_by(id: params[:event_import_file_id])
9
9
  if @event_import_file
10
- @event_import_results = @event_import_file.event_import_results.page(params[:page])
10
+ @event_import_results = @event_import_file.event_import_results.order(created_at: :asc).page(params[:page])
11
11
  else
12
- @event_import_results = EventImportResult.page(params[:page])
12
+ @event_import_results = EventImportResult.order(created_at: :desc).page(params[:page])
13
13
  end
14
14
 
15
15
  respond_to do |format|
16
16
  format.html # index.html.erb
17
17
  format.json { render json: @event_import_results }
18
- format.txt
18
+ format.text
19
19
  end
20
20
  end
21
21
 
@@ -52,7 +52,7 @@ class EventsController < ApplicationController
52
52
  format.html.phone
53
53
  format.json
54
54
  format.rss { render layout: false }
55
- format.txt
55
+ format.text
56
56
  format.atom
57
57
  format.ics
58
58
  end
@@ -125,7 +125,7 @@ class EventsController < ApplicationController
125
125
  @event.set_date
126
126
 
127
127
  respond_to do |format|
128
- if @event.update_attributes(event_params)
128
+ if @event.update(event_params)
129
129
 
130
130
  flash[:notice] = t('controller.successfully_updated', model: t('activerecord.models.event'))
131
131
  format.html { redirect_to(@event) }
@@ -169,4 +169,10 @@ class EventsController < ApplicationController
169
169
  def prepare_options
170
170
  @event_categories = EventCategory.all
171
171
  end
172
+
173
+ def filtered_params
174
+ params.permit([:format, :library_id, :mode, :query, :page, :per_page])
175
+ end
176
+
177
+ helper_method :filtered_params
172
178
  end
@@ -58,7 +58,7 @@ class ParticipatesController < ApplicationController
58
58
  # PUT /participates/1.json
59
59
  def update
60
60
  respond_to do |format|
61
- if @participate.update_attributes(participate_params)
61
+ if @participate.update(participate_params)
62
62
  flash[:notice] = 'Participate was successfully updated.'
63
63
  format.html { redirect_to(@participate) }
64
64
  format.json { head :no_content }
@@ -50,7 +50,7 @@ class PlacesController < ApplicationController
50
50
  # Use callbacks to share common setup or constraints between actions.
51
51
  def set_place
52
52
  @place = Place.find(params[:id])
53
- autorize @place
53
+ authorize @place
54
54
  end
55
55
 
56
56
  def check_policy
@@ -1,4 +1,4 @@
1
- class EventExportFileJob < ActiveJob::Base
1
+ class EventExportFileJob < ApplicationJob
2
2
  queue_as :enju_leaf
3
3
 
4
4
  def perform(event_export_file)
@@ -1,4 +1,4 @@
1
- class EventImportFileJob < ActiveJob::Base
1
+ class EventImportFileJob < ApplicationJob
2
2
  queue_as :enju_leaf
3
3
 
4
4
  def perform(event_import_file)
@@ -0,0 +1,17 @@
1
+ class EventExportMailer < ApplicationMailer
2
+ def completed(event_export_file)
3
+ @event_export_file = event_export_file
4
+ @library_group = LibraryGroup.site_config
5
+ from = "#{LibraryGroup.system_name(event_export_file.user.profile.locale)} <#{@library_group.user.email}>"
6
+ subject = "#{I18n.t('event_export_mailer.completed.subject')}: #{@event_export_file.id}"
7
+ mail(from: from, to: event_export_file.user.email, subject: subject)
8
+ end
9
+
10
+ def failed(event_export_file)
11
+ @event_export_file = event_export_file
12
+ @library_group = LibraryGroup.site_config
13
+ from = "#{LibraryGroup.system_name(event_export_file.user.profile.locale)} <#{@library_group.user.email}>"
14
+ subject = "#{I18n.t('event_export_mailer.failed.subject')}: #{@event_export_file.id}"
15
+ mail(from: from, to: event_export_file.user.email, subject: subject)
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ class EventImportMailer < ApplicationMailer
2
+ def completed(event_import_file)
3
+ @event_import_file = event_import_file
4
+ @library_group = LibraryGroup.site_config
5
+ from = "#{LibraryGroup.system_name(event_import_file.user.profile.locale)} <#{@library_group.user.email}>"
6
+ subject = "#{I18n.t('event_import_mailer.completed.subject')}: #{@event_import_file.id}"
7
+ mail(from: from, to: event_import_file.user.email, subject: subject)
8
+ end
9
+
10
+ def failed(event_import_file)
11
+ @event_import_file = event_import_file
12
+ @library_group = LibraryGroup.site_config
13
+ from = "#{LibraryGroup.system_name(event_import_file.user.profile.locale)} <#{@library_group.user.email}>"
14
+ subject = "#{I18n.t('event_import_mailer.failed.subject')}: #{@event_import_file.id}"
15
+ mail(from: from, to: event_import_file.user.email, subject: subject)
16
+ end
17
+ end
@@ -0,0 +1,15 @@
1
+ module EnjuEvent
2
+ module EnjuLibrary
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ has_many :events
7
+ end
8
+
9
+ def closed?(date)
10
+ events.closing_days.map{ |c|
11
+ c.start_at.beginning_of_day
12
+ }.include?(date.beginning_of_day)
13
+ end
14
+ end
15
+ end
data/app/models/event.rb CHANGED
@@ -1,4 +1,4 @@
1
- class Event < ActiveRecord::Base
1
+ class Event < ApplicationRecord
2
2
  scope :closing_days, -> { includes(:event_category).where('event_categories.name' => 'closed') }
3
3
  scope :on, lambda {|datetime| where('start_at >= ? AND start_at < ?', datetime.beginning_of_day, datetime.tomorrow.beginning_of_day + 1)}
4
4
  scope :past, lambda {|datetime| where('end_at <= ?', Time.zone.parse(datetime).beginning_of_day)}
@@ -56,30 +56,43 @@ class Event < ActiveRecord::Base
56
56
  self.display_name = name if display_name.blank?
57
57
  end
58
58
 
59
- def self.export(options = {format: :txt})
60
- header = %w(
61
- name
62
- event_category
63
- library
64
- start_at
65
- end_at
66
- all_day
67
- )
68
- lines = []
69
- Event.find_each.map{|e|
70
- line = []
71
- line << e.name
72
- line << e.event_category.name
73
- line << e.library.name
74
- line << e.start_at
75
- line << e.end_at
76
- line << e.all_day
77
- lines << line
59
+ # CSVのヘッダ
60
+ # @param [String] role 権限
61
+ def self.csv_header(role: 'Guest')
62
+ Event.new.to_hash(role: role).keys
63
+ end
64
+
65
+ # CSV出力用のハッシュ
66
+ # @param [String] role 権限
67
+ def to_hash(role: 'Guest')
68
+ record = {
69
+ name: name,
70
+ display_name: display_name,
71
+ event_category: event_category.try(:name),
72
+ library: library.try(:name),
73
+ start_at: start_at,
74
+ end_at: end_at,
75
+ all_day: all_day,
76
+ note: note,
77
+ created_at: created_at,
78
+ updated_at: updated_at
78
79
  }
79
- if options[:format] == :txt
80
- lines.map{|line| line.to_csv(col_sep: "\t")}.unshift(header.to_csv(col_sep: "\t")).join
81
- else
82
- event
80
+
81
+ record
82
+ end
83
+
84
+ # TSVでのエクスポート
85
+ # @param [String] role 権限
86
+ # @param [String] col_sep 区切り文字
87
+ def self.export(role: 'Guest', col_sep: "\t")
88
+ file = Tempfile.create('event_export') do |f|
89
+ f.write Event.csv_header(role: role).to_csv(col_sep: col_sep)
90
+ Event.find_each do |event|
91
+ f.write event.to_hash(role: role).values.to_csv(col_sep: col_sep)
92
+ end
93
+
94
+ f.rewind
95
+ f.read
83
96
  end
84
97
  end
85
98
  end
@@ -1,4 +1,4 @@
1
- class EventCategory < ActiveRecord::Base
1
+ class EventCategory < ApplicationRecord
2
2
  include MasterModel
3
3
  default_scope { order('position') }
4
4
  has_many :events
@@ -1,4 +1,4 @@
1
- class EventExportFile < ActiveRecord::Base
1
+ class EventExportFile < ApplicationRecord
2
2
  include Statesman::Adapters::ActiveRecordQueries
3
3
  include ExportFile
4
4
 
@@ -26,18 +26,23 @@ class EventExportFile < ActiveRecord::Base
26
26
  to: :state_machine
27
27
 
28
28
  def export!
29
- transition_to!(:started)
30
- tempfile = Tempfile.new(['event_export_file_', '.txt'])
31
- file = Event.export(format: :txt)
32
- tempfile.puts(file)
33
- tempfile.close
34
- self.event_export = File.new(tempfile.path, "r")
35
- if save
36
- send_message
29
+ role_name = user.try(:role).try(:name)
30
+ tsv = Event.export(role: role_name)
31
+
32
+ EventExportFile.transaction do
33
+ transition_to!(:started)
34
+ role_name = user.try(:role).try(:name)
35
+ self.event_export = StringIO.new(tsv)
36
+ self.event_export.instance_write(:filename, "event_export.txt")
37
+ save!
38
+ transition_to!(:completed)
37
39
  end
38
- transition_to!(:completed)
40
+ mailer = EventExportMailer.completed(self)
41
+ send_message(mailer)
39
42
  rescue => e
40
43
  transition_to!(:failed)
44
+ mailer = EventExportMailer.failed(self)
45
+ send_message(mailer)
41
46
  raise e
42
47
  end
43
48
 
@@ -1,4 +1,4 @@
1
- class EventExportFileTransition < ActiveRecord::Base
1
+ class EventExportFileTransition < ApplicationRecord
2
2
  include Statesman::Adapters::ActiveRecordTransition
3
3
 
4
4
 
@@ -1,7 +1,6 @@
1
- class EventImportFile < ActiveRecord::Base
1
+ class EventImportFile < ApplicationRecord
2
2
  include Statesman::Adapters::ActiveRecordQueries
3
3
  include ImportFile
4
- default_scope {order('event_import_files.id DESC')}
5
4
  scope :not_imported, -> {in_state(:pending)}
6
5
  scope :stucked, -> {in_state(:pending).where('event_import_files.created_at < ?', 1.hour.ago)}
7
6
 
@@ -52,9 +51,7 @@ class EventImportFile < ActiveRecord::Base
52
51
  rows.each do |row|
53
52
  row_num += 1
54
53
  next if row['dummy'].to_s.strip.present?
55
- event_import_result = EventImportResult.new
56
- event_import_result.assign_attributes({ event_import_file_id: id, body: row.fields.join("\t") })
57
- event_import_result.save!
54
+ event_import_result = EventImportResult.new(event_import_file_id: id, body: row.fields.join("\t"))
58
55
 
59
56
  event = Event.new
60
57
  event.name = row['name'].to_s.strip
@@ -68,10 +65,10 @@ class EventImportFile < ActiveRecord::Base
68
65
  else
69
66
  event.all_day = false
70
67
  end
71
- library = Library.where(name: row['library']).first
68
+ library = Library.find_by(name: row['library'])
72
69
  library = default_library || Library.web if library.blank?
73
70
  event.library = library
74
- event_category = EventCategory.where(name: row['event_category']).first
71
+ event_category = EventCategory.find_by(name: row['event_category'])
75
72
  event_category = default_event_category if event_category.blank?
76
73
  event.event_category = event_category
77
74
 
@@ -90,12 +87,15 @@ class EventImportFile < ActiveRecord::Base
90
87
  Sunspot.commit
91
88
  rows.close
92
89
  transition_to!(:completed)
93
- send_message
90
+ mailer = EventImportMailer.completed(self)
91
+ send_message(mailer)
94
92
  num
95
93
  rescue => e
96
94
  self.error_message = "line #{row_num}: #{e.message}"
97
95
  save
98
96
  transition_to!(:failed)
97
+ mailer = EventImportMailer.failed(self)
98
+ send_message(mailer)
99
99
  raise e
100
100
  end
101
101
 
@@ -111,7 +111,7 @@ class EventImportFile < ActiveRecord::Base
111
111
  event = Event.find(row['id'].to_s.strip)
112
112
  event_category = EventCategory.where(name: row['event_category'].to_s.strip).first
113
113
  event.event_category = event_category if event_category
114
- library = Library.where(name: row['library'].to_s.strip).first
114
+ library = Library.find_by(name: row['library'].to_s.strip)
115
115
  event.library = library if library
116
116
  event.name = row['name'] if row['name'].to_s.strip.present?
117
117
  event.start_at = Time.zone.parse(row['start_at']) if row['start_at'].present?
@@ -125,10 +125,14 @@ class EventImportFile < ActiveRecord::Base
125
125
  event.save!
126
126
  end
127
127
  transition_to!(:completed)
128
+ mailer = EventImportMailer.completed(self)
129
+ send_message(mailer)
128
130
  rescue => e
129
131
  self.error_message = "line #{row_num}: #{e.message}"
130
132
  save
131
133
  transition_to!(:failed)
134
+ mailer = EventImportMailer.failed(self)
135
+ send_message(mailer)
132
136
  raise e
133
137
  end
134
138
 
@@ -147,10 +151,14 @@ class EventImportFile < ActiveRecord::Base
147
151
  event.destroy
148
152
  end
149
153
  transition_to!(:completed)
154
+ mailer = EventImportMailer.completed(self)
155
+ send_message(mailer)
150
156
  rescue => e
151
157
  self.error_message = "line #{row_num}: #{e.message}"
152
158
  save
153
159
  transition_to!(:failed)
160
+ mailer = EventImportMailer.failed(self)
161
+ send_message(mailer)
154
162
  raise e
155
163
  end
156
164
 
@@ -173,9 +181,7 @@ class EventImportFile < ActiveRecord::Base
173
181
 
174
182
  def open_import_file(tempfile)
175
183
  file = CSV.open(tempfile, col_sep: "\t")
176
- header_columns = %w(
177
- id name display_name library event_category start_at end_at all_day note dummy
178
- )
184
+ header_columns = EventImportResult.header
179
185
  header = file.first
180
186
  ignored_columns = header - header_columns
181
187
  unless ignored_columns.empty?
@@ -1,4 +1,4 @@
1
- class EventImportFileTransition < ActiveRecord::Base
1
+ class EventImportFileTransition < ApplicationRecord
2
2
  include Statesman::Adapters::ActiveRecordTransition
3
3
 
4
4
 
@@ -1,5 +1,4 @@
1
- class EventImportResult < ActiveRecord::Base
2
- default_scope { order('event_import_results.id') }
1
+ class EventImportResult < ApplicationRecord
3
2
  scope :file_id, proc{|file_id| where(event_import_file_id: file_id)}
4
3
  scope :failed, -> { where(event_id: nil) }
5
4
 
@@ -7,6 +6,12 @@ class EventImportResult < ActiveRecord::Base
7
6
  belongs_to :event, optional: true
8
7
 
9
8
  validates :event_import_file_id, presence: true
9
+
10
+ def self.header
11
+ %w(
12
+ id name display_name library event_category start_at end_at all_day note dummy
13
+ )
14
+ end
10
15
  end
11
16
 
12
17
  # == Schema Information
@@ -1,4 +1,4 @@
1
- class Participate < ActiveRecord::Base
1
+ class Participate < ApplicationRecord
2
2
  belongs_to :agent
3
3
  belongs_to :event
4
4
 
data/app/models/place.rb CHANGED
@@ -1,4 +1,4 @@
1
- class Place < ActiveRecord::Base
1
+ class Place < ApplicationRecord
2
2
  has_many :events
3
3
  validates :term, presence: true
4
4
  end
@@ -3,7 +3,7 @@
3
3
 
4
4
  <div class="field">
5
5
  <%= f.label :name %><br />
6
- <%= f.text_field :name %>
6
+ <%= f.text_field :name, required: true %>
7
7
  </div>
8
8
  <div class="field">
9
9
  <%= f.label :display_name %><br />
@@ -0,0 +1,9 @@
1
+ The following export task is completed.
2
+
3
+ ID: <%= @event_export_file.id %>
4
+ Created at: <%= @event_export_file.created_at %>
5
+ Detail: <%= event_export_file_url(@event_export_file) %>
6
+
7
+ --
8
+ <%= @library_group.display_name %>
9
+ <%= root_url %>
@@ -0,0 +1,9 @@
1
+ 以下の資料のインポートが完了しました。
2
+
3
+ ID: <%= @event_export_file.id %>
4
+ 作成時刻: <%= @event_export_file.created_at %>
5
+ 詳細: <%= event_export_file_url(@event_export_file) %>
6
+
7
+ --
8
+ <%= @library_group.display_name %>
9
+ <%= root_url %>
@@ -0,0 +1,9 @@
1
+ The following export task failed.
2
+
3
+ ID: <%= @event_export_file.id %>
4
+ Created at: <%= @event_export_file.created_at %>
5
+ Detail: <%= event_export_file_url(@event_export_file) %>
6
+
7
+ --
8
+ <%= @library_group.display_name %>
9
+ <%= root_url %>
@@ -0,0 +1,9 @@
1
+ 以下の資料のインポートに失敗しました。
2
+
3
+ ID: <%= @event_export_file.id %>
4
+ 作成時刻: <%= @event_export_file.created_at %>
5
+ 詳細: <%= event_export_file_url(@event_export_file) %>
6
+
7
+ --
8
+ <%= @library_group.display_name %>
9
+ <%= root_url %>
@@ -0,0 +1,26 @@
1
+ <h2><%= t('activerecord.models.event_import_result') %></h2>
2
+ <p>
3
+ <%= link_to((image_tag 'icons/page_white_excel.png', size: '16x16', class: 'enju_icon', alt: 'TSV'), event_import_results_path(event_import_file_id: @event_import_file.id, format: :txt, locale: @locale.to_s)) -%>
4
+ (<%= link_to 'TSV', event_import_results_path(event_import_file_id: @event_import_file.id, format: :txt, locale: @locale.to_s) -%>)
5
+ </p>
6
+
7
+ <table class="table table-striped index">
8
+ <tr>
9
+ <th><%= t('activerecord.attributes.event_import_result.lineno') %></th>
10
+ <th><%= t('activerecord.attributes.event_import_result.body') %></th>
11
+ <th><%= t('activerecord.models.event') %></th>
12
+ <th></th>
13
+ </tr>
14
+ <% @event_import_results.each_with_index do |event_import_result, idx| %>
15
+ <tr class="line<%= cycle("0", "1") -%>">
16
+ <td><%= @event_import_results.offset_value + idx + 1 %></td>
17
+ <td><%= event_import_result.body.inspect %></td>
18
+ <td><%= link_to event_import_result.event.display_name, event_import_result.event if event_import_result.event %></td>
19
+ <td>
20
+ <%= link_to t('page.show'), event_import_result %>
21
+ <%= link_to t('page.destroy'), event_import_result, data: {confirm: t('page.are_you_sure')}, method: :delete %>
22
+ </td>
23
+ </tr>
24
+ <% end %>
25
+ </table>
26
+ <%= paginate(@event_import_results) %>