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.
- checksums.yaml +4 -4
- data/README.md +11 -0
- data/app/controllers/concerns/enju_event/enju_libraries_controller.rb +17 -0
- data/app/controllers/event_categories_controller.rb +1 -1
- data/app/controllers/event_export_files_controller.rb +1 -1
- data/app/controllers/event_import_files_controller.rb +3 -2
- data/app/controllers/event_import_results_controller.rb +4 -4
- data/app/controllers/events_controller.rb +8 -2
- data/app/controllers/participates_controller.rb +1 -1
- data/app/controllers/places_controller.rb +1 -1
- data/app/jobs/event_export_file_job.rb +1 -1
- data/app/jobs/event_import_file_job.rb +1 -1
- data/app/mailers/event_export_mailer.rb +17 -0
- data/app/mailers/event_import_mailer.rb +17 -0
- data/app/models/concerns/enju_event/enju_library.rb +15 -0
- data/app/models/event.rb +37 -24
- data/app/models/event_category.rb +1 -1
- data/app/models/event_export_file.rb +15 -10
- data/app/models/event_export_file_transition.rb +1 -1
- data/app/models/event_import_file.rb +18 -12
- data/app/models/event_import_file_transition.rb +1 -1
- data/app/models/event_import_result.rb +7 -2
- data/app/models/participate.rb +1 -1
- data/app/models/place.rb +1 -1
- data/app/views/event_categories/_form.html.erb +1 -1
- data/app/views/event_export_mailer/completed.en.text.erb +9 -0
- data/app/views/event_export_mailer/completed.ja.text.erb +9 -0
- data/app/views/event_export_mailer/failed.en.text.erb +9 -0
- data/app/views/event_export_mailer/failed.ja.text.erb +9 -0
- data/app/views/event_import_files/_results.html.erb +26 -0
- data/app/views/event_import_files/show.html.erb +70 -74
- data/app/views/event_import_mailer/completed.en.text.erb +9 -0
- data/app/views/event_import_mailer/completed.ja.text.erb +9 -0
- data/app/views/event_import_mailer/failed.en.text.erb +9 -0
- data/app/views/event_import_mailer/failed.ja.text.erb +9 -0
- data/app/views/event_import_results/index.html.erb +0 -11
- data/app/views/event_import_results/index.text.ruby +5 -0
- data/app/views/events/index.html.erb +22 -22
- data/app/views/events/index.text.ruby +7 -0
- data/app/views/layouts/mailer.html.erb +13 -0
- data/app/views/layouts/mailer.text.erb +1 -0
- data/config/brakeman.ignore +66 -0
- data/config/locales/translation_en.yml +12 -0
- data/config/locales/translation_ja.yml +12 -0
- data/lib/enju_event/engine.rb +0 -1
- data/lib/enju_event/version.rb +1 -1
- data/lib/generators/enju_event/setup/setup_generator.rb +1 -1
- data/spec/controllers/event_import_files_controller_spec.rb +2 -2
- data/spec/controllers/event_import_results_controller_spec.rb +2 -2
- data/spec/controllers/events_controller_spec.rb +2 -2
- data/spec/controllers/libraries_controller_spec.rb +41 -0
- data/spec/dummy/app/assets/config/manifest.js +5 -0
- data/spec/dummy/app/jobs/application_job.rb +7 -0
- data/spec/dummy/app/mailers/application_mailer.rb +4 -0
- data/spec/dummy/app/models/application_record.rb +3 -0
- data/spec/dummy/app/models/user.rb +1 -1
- data/spec/dummy/config/application.rb +1 -1
- data/spec/dummy/config/initializers/assets.rb +1 -0
- data/spec/dummy/config/initializers/mime_types.rb +1 -0
- data/spec/dummy/config/storage.yml +34 -0
- data/spec/dummy/db/migrate/20081025083323_create_countries.rb +4 -4
- data/spec/dummy/db/migrate/20100606065209_create_user_has_roles.rb +2 -4
- data/spec/dummy/db/migrate/20140122054321_create_profiles.rb +4 -5
- data/spec/dummy/db/migrate/20150421023923_create_identities.rb +14 -0
- data/spec/dummy/db/migrate/20151126005552_add_provider_to_identity.rb +5 -0
- data/spec/dummy/db/migrate/20151213070943_add_translation_table_to_library_group.rb +0 -8
- data/spec/dummy/db/migrate/20160506144040_create_isbn_records.rb +11 -0
- data/spec/dummy/db/migrate/20180107162659_add_constraints_to_most_recent_for_message_transitions.rb +13 -0
- data/spec/dummy/db/migrate/20180107162711_add_constraints_to_most_recent_for_message_request_transitions.rb +13 -0
- data/spec/dummy/db/migrate/20181026064038_add_login_banner_to_library_group.rb +6 -0
- data/spec/dummy/db/migrate/20181030072731_add_not_null_to_position_on_carrier_type.rb +14 -0
- data/spec/dummy/db/migrate/20181030074920_add_not_null_to_position_on_library.rb +14 -0
- data/spec/dummy/db/migrate/20190208135957_create_active_storage_tables.active_storage.rb +27 -0
- data/spec/dummy/db/migrate/20190311154610_create_periodicals.rb +10 -0
- data/spec/dummy/db/migrate/20190314151124_add_full_name_translations_to_create.rb +7 -0
- data/spec/dummy/db/migrate/20190818075603_add_memo_to_manifestation.rb +5 -0
- data/spec/dummy/db/migrate/20190818075628_add_memo_to_item.rb +5 -0
- data/spec/dummy/db/migrate/20191219122214_create_custom_properties.rb +12 -0
- data/spec/dummy/db/migrate/20200425072340_create_manifestation_custom_properties.rb +12 -0
- data/spec/dummy/db/migrate/20200425072349_create_item_custom_properties.rb +12 -0
- data/spec/dummy/db/migrate/20200425074758_create_manifestation_custom_values.rb +12 -0
- data/spec/dummy/db/migrate/20200425074822_create_item_custom_values.rb +12 -0
- data/spec/dummy/db/schema.rb +131 -304
- data/spec/factories/event_export_file.rb +5 -0
- data/spec/factories/event_import_file.rb +7 -0
- data/spec/factories/event_import_result.rb +6 -0
- data/spec/mailers/event_export_spec.rb +5 -0
- data/spec/mailers/event_import_spec.rb +5 -0
- data/spec/mailers/previews/event_export_preview.rb +4 -0
- data/spec/mailers/previews/event_import_preview.rb +4 -0
- data/spec/models/event_export_file_spec.rb +1 -1
- data/spec/models/event_import_file_spec.rb +1 -1
- data/spec/rails_helper.rb +6 -0
- data/spec/system/event_import_results_spec.rb +17 -0
- data/spec/system/events_spec.rb +22 -0
- data/spec/views/event_import_results/index.text.ruby_spec.rb +22 -0
- data/spec/views/events/index.json.jbuilder_spec.rb +22 -0
- metadata +405 -315
- data/README.rdoc +0 -10
- data/app/views/event_import_results/index.txt.erb +0 -3
- data/app/views/events/index.txt.erb +0 -4
- data/spec/dummy/db/migrate/032_create_checkins.rb +0 -17
- data/spec/dummy/db/migrate/033_create_checkouts.rb +0 -25
- data/spec/dummy/db/migrate/035_create_reserves.rb +0 -26
- data/spec/dummy/db/migrate/121_create_checked_items.rb +0 -17
- data/spec/dummy/db/migrate/127_create_use_restrictions.rb +0 -16
- data/spec/dummy/db/migrate/129_create_item_has_use_restrictions.rb +0 -16
- data/spec/dummy/db/migrate/132_create_circulation_statuses.rb +0 -16
- data/spec/dummy/db/migrate/20081030023412_create_checkout_types.rb +0 -17
- data/spec/dummy/db/migrate/20081030023518_create_user_group_has_checkout_types.rb +0 -25
- data/spec/dummy/db/migrate/20081030023615_create_carrier_type_has_checkout_types.rb +0 -18
- data/spec/dummy/db/migrate/20081212075554_create_checkout_stat_has_manifestations.rb +0 -17
- data/spec/dummy/db/migrate/20081212080038_create_manifestation_checkout_stats.rb +0 -15
- data/spec/dummy/db/migrate/20081215094302_create_user_checkout_stats.rb +0 -15
- data/spec/dummy/db/migrate/20081215094955_create_checkout_stat_has_users.rb +0 -17
- data/spec/dummy/db/migrate/20081216190517_create_reserve_stat_has_manifestations.rb +0 -17
- data/spec/dummy/db/migrate/20081216190724_create_manifestation_reserve_stats.rb +0 -15
- data/spec/dummy/db/migrate/20081220023628_create_user_reserve_stats.rb +0 -15
- data/spec/dummy/db/migrate/20081220034117_create_reserve_stat_has_users.rb +0 -17
- data/spec/dummy/db/migrate/20090321130448_add_completed_at_to_user_checkout_stat.rb +0 -23
- data/spec/dummy/db/migrate/20110301134521_add_expire_date_to_reserve.rb +0 -9
- data/spec/dummy/db/migrate/20110328130826_add_current_checkout_count_to_user_group_has_checkout_type.rb +0 -9
- data/spec/dummy/db/migrate/20110621093332_remove_expire_date_from_reserve.rb +0 -9
- data/spec/dummy/db/migrate/20111217234412_add_save_checkout_history_to_user.rb +0 -5
- data/spec/dummy/db/migrate/20111218002349_add_checkout_icalendar_token_to_user.rb +0 -6
- data/spec/dummy/db/migrate/20120424103932_add_librarian_id_to_checked_item.rb +0 -5
- data/spec/dummy/db/migrate/20130303124821_add_retained_at_to_reserve.rb +0 -5
- data/spec/dummy/db/migrate/20130304015019_add_postponed_at_to_reserve.rb +0 -5
- data/spec/dummy/db/migrate/20130416054135_add_circulation_status_id_to_item.rb +0 -8
- data/spec/dummy/db/migrate/20130519065638_add_lock_version_to_reserve.rb +0 -5
- data/spec/dummy/db/migrate/20130519065837_add_lock_version_to_checkin.rb +0 -5
- data/spec/dummy/db/migrate/20140518050147_create_reserve_transitions.rb +0 -18
- data/spec/dummy/db/migrate/20140528045518_create_user_checkout_stat_transitions.rb +0 -18
- data/spec/dummy/db/migrate/20140528045539_create_user_reserve_stat_transitions.rb +0 -18
- data/spec/dummy/db/migrate/20140528045600_create_manifestation_checkout_stat_transitions.rb +0 -18
- data/spec/dummy/db/migrate/20140528045617_create_manifestation_reserve_stat_transitions.rb +0 -18
- data/spec/dummy/db/migrate/20140810061942_add_user_id_to_user_checkout_stat.rb +0 -12
- data/spec/dummy/db/migrate/20140810091231_add_checkout_icalendar_token_to_profile.rb +0 -6
- data/spec/dummy/db/migrate/20140810091417_add_save_checkout_history_to_profile.rb +0 -5
- data/spec/dummy/db/migrate/20141014065831_add_shelf_id_to_checkout.rb +0 -6
- data/spec/support/resque.rb +0 -32
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27b0c9dc4dc6da8c3186d98a1f4c6c99b9f95e4305f8c96b50297a5e692e3d86
|
4
|
+
data.tar.gz: c5298009340080f52bce7d1f9a698cf10b5772071b8ca4348b9129c348127a1b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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 }
|
@@ -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 <
|
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
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
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
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
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 EventExportFile <
|
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
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
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
|
-
|
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,7 +1,6 @@
|
|
1
|
-
class EventImportFile <
|
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.
|
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.
|
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
|
-
|
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.
|
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 =
|
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,5 +1,4 @@
|
|
1
|
-
class EventImportResult <
|
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
|
data/app/models/participate.rb
CHANGED
data/app/models/place.rb
CHANGED
@@ -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) %>
|