enju_event 0.1.17.pre17 → 0.1.17.pre18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/event_import_files_controller.rb +7 -2
- data/app/controllers/event_import_results_controller.rb +1 -1
- data/app/models/event.rb +11 -13
- data/app/models/event_import_file.rb +52 -73
- data/app/models/event_import_file_state_machine.rb +19 -0
- data/app/models/event_import_file_transition.rb +20 -0
- data/app/views/calendar/index.html.erb +2 -2
- data/app/views/event_categories/edit.html.erb +2 -2
- data/app/views/event_categories/index.html.erb +2 -2
- data/app/views/event_categories/new.html.erb +2 -2
- data/app/views/event_categories/show.html.erb +2 -2
- data/app/views/event_import_files/edit.html.erb +2 -2
- data/app/views/event_import_files/index.html.erb +4 -4
- data/app/views/event_import_files/new.html.erb +17 -4
- data/app/views/event_import_files/show.html.erb +13 -3
- data/app/views/event_import_results/index.html.erb +6 -6
- data/app/views/event_import_results/{index.csv.erb → index.tsv.erb} +0 -0
- data/app/views/event_import_results/show.html.erb +2 -2
- data/app/views/events/edit.html.erb +2 -2
- data/app/views/events/index.html.erb +2 -2
- data/app/views/events/new.html.erb +2 -2
- data/app/views/events/show.html.erb +8 -3
- data/app/views/participates/edit.html.erb +2 -2
- data/app/views/participates/index.html.erb +2 -2
- data/app/views/participates/new.html.erb +2 -2
- data/app/views/participates/show.html.erb +2 -2
- data/app/workers/event_import_file_queue.rb +7 -0
- data/config/locales/translation_en.yml +1 -0
- data/config/locales/translation_ja.yml +1 -0
- data/db/migrate/20081028093607_create_event_import_files.rb +0 -2
- data/db/migrate/20140523171309_create_event_import_file_transitions.rb +14 -0
- data/db/migrate/20140628071719_add_user_encoding_to_event_import_file.rb +5 -0
- data/lib/enju_event/engine.rb +1 -1
- data/lib/enju_event/version.rb +1 -1
- data/spec/dummy/db/migrate/005_create_manifestations.rb +0 -12
- data/spec/dummy/db/migrate/006_create_items.rb +2 -2
- data/spec/dummy/db/migrate/029_create_subjects.rb +27 -0
- data/spec/dummy/db/migrate/032_create_checkins.rb +17 -0
- data/spec/dummy/db/migrate/033_create_checkouts.rb +25 -0
- data/spec/dummy/db/migrate/035_create_reserves.rb +27 -0
- data/spec/dummy/db/migrate/059_create_libraries.rb +1 -7
- data/spec/dummy/db/migrate/069_create_shelves.rb +1 -5
- data/spec/dummy/db/migrate/{20111201163342_create_user_groups.rb → 077_create_user_groups.rb} +2 -2
- data/spec/dummy/db/migrate/080_create_library_groups.rb +2 -9
- data/spec/dummy/db/migrate/120_create_baskets.rb +12 -0
- data/spec/dummy/db/migrate/121_create_checked_items.rb +17 -0
- data/spec/dummy/db/migrate/124_create_bookstores.rb +17 -0
- data/spec/dummy/db/migrate/127_create_use_restrictions.rb +16 -0
- data/spec/dummy/db/migrate/129_create_item_has_use_restrictions.rb +16 -0
- data/spec/dummy/db/migrate/130_create_request_status_types.rb +12 -0
- data/spec/dummy/db/migrate/131_create_request_types.rb +12 -0
- data/spec/dummy/db/migrate/132_create_circulation_statuses.rb +16 -0
- data/spec/dummy/db/migrate/142_create_classifications.rb +19 -0
- data/spec/dummy/db/migrate/143_create_subject_has_classifications.rb +16 -0
- data/spec/dummy/db/migrate/144_create_classification_types.rb +16 -0
- data/spec/dummy/db/migrate/145_create_subject_heading_types.rb +16 -0
- data/spec/dummy/db/migrate/146_create_subject_types.rb +16 -0
- data/spec/dummy/db/migrate/149_create_message_templates.rb +18 -0
- data/spec/dummy/db/migrate/154_create_messages.rb +24 -0
- data/spec/dummy/db/migrate/20080606052544_create_work_has_subjects.rb +18 -0
- data/spec/dummy/db/migrate/20080819181903_create_message_requests.rb +20 -0
- data/spec/dummy/db/migrate/20081006090811_create_subscriptions.rb +17 -0
- data/spec/dummy/db/migrate/20081006093246_create_subscribes.rb +14 -0
- data/spec/dummy/db/migrate/20081023092436_create_search_engines.rb +17 -0
- data/spec/dummy/db/migrate/20081030023412_create_checkout_types.rb +17 -0
- data/spec/dummy/db/migrate/20081030023518_create_user_group_has_checkout_types.rb +25 -0
- data/spec/dummy/db/migrate/20081030023615_create_carrier_type_has_checkout_types.rb +18 -0
- data/spec/dummy/db/migrate/20081212075554_create_checkout_stat_has_manifestations.rb +17 -0
- data/spec/dummy/db/migrate/20081212080038_create_manifestation_checkout_stats.rb +16 -0
- data/spec/dummy/db/migrate/20081215094302_create_user_checkout_stats.rb +16 -0
- data/spec/dummy/db/migrate/20081215094955_create_checkout_stat_has_users.rb +17 -0
- data/spec/dummy/db/migrate/20081216190517_create_reserve_stat_has_manifestations.rb +17 -0
- data/spec/dummy/db/migrate/20081216190724_create_manifestation_reserve_stats.rb +16 -0
- data/spec/dummy/db/migrate/20081220023628_create_user_reserve_stats.rb +16 -0
- data/spec/dummy/db/migrate/20081220034117_create_reserve_stat_has_users.rb +17 -0
- data/spec/dummy/db/migrate/20090208044541_create_subject_heading_type_has_subjects.rb +16 -0
- data/spec/dummy/db/migrate/20090321130448_add_completed_at_to_user_checkout_stat.rb +27 -0
- data/spec/dummy/db/migrate/20090831220301_create_lending_policies.rb +21 -0
- data/spec/dummy/db/migrate/20100314190054_add_opening_hour_to_library.rb +9 -0
- data/spec/dummy/db/migrate/20110301134521_add_expire_date_to_reserve.rb +9 -0
- data/spec/dummy/db/migrate/20110318183304_add_valid_period_for_new_user_to_user_group.rb +11 -0
- data/spec/dummy/db/migrate/20110328130826_add_current_checkout_count_to_user_group_has_checkout_type.rb +9 -0
- data/spec/dummy/db/migrate/20110603184217_add_edit_mode_to_resource_import_file.rb +9 -0
- data/spec/dummy/db/migrate/20110621093332_remove_expire_date_from_reserve.rb +9 -0
- data/spec/dummy/db/migrate/20110627122938_add_number_of_day_to_notify_overdue_to_user_group.rb +13 -0
- data/spec/dummy/db/migrate/20110913115320_add_lft_and_rgt_to_message.rb +11 -0
- data/spec/dummy/db/migrate/20110913120629_add_lft_and_rgt_to_classification.rb +11 -0
- data/spec/dummy/db/migrate/20111201155456_devise_create_users.rb +42 -0
- data/spec/dummy/db/migrate/20111217234412_add_save_checkout_history_to_user.rb +5 -0
- data/spec/dummy/db/migrate/20111218002349_add_checkout_icalendar_token_to_user.rb +6 -0
- data/spec/dummy/db/migrate/20120125050502_add_depth_to_message.rb +6 -0
- data/spec/dummy/db/migrate/20120129014038_create_budget_types.rb +12 -0
- data/spec/dummy/db/migrate/20120319173203_create_accepts.rb +14 -0
- data/spec/dummy/db/migrate/20120406020752_add_url_to_subject.rb +5 -0
- data/spec/dummy/db/migrate/20120424103932_add_librarian_id_to_checked_item.rb +5 -0
- data/spec/dummy/db/migrate/20120510140958_add_closed_to_shelf.rb +5 -0
- data/spec/dummy/db/migrate/20121116033446_add_doi_to_manifestation.rb +6 -0
- data/spec/dummy/db/migrate/20130221154434_add_additional_attributes_to_user.rb +26 -0
- data/spec/dummy/db/migrate/20130303104849_add_state_index_to_reserve.rb +5 -0
- data/spec/dummy/db/migrate/20130303124821_add_retained_at_to_reserve.rb +5 -0
- data/spec/dummy/db/migrate/20130304015019_add_postponed_at_to_reserve.rb +5 -0
- data/spec/dummy/db/migrate/20130412083556_add_latitude_and_longitude_to_library.rb +6 -0
- data/spec/dummy/db/migrate/20130416054135_add_circulation_status_id_to_item.rb +8 -0
- data/spec/dummy/db/migrate/20130421093852_add_periodical_to_manifestation.rb +5 -0
- data/spec/dummy/db/migrate/20130421155019_add_creator_string_to_series_statement.rb +7 -0
- data/spec/dummy/db/migrate/20130421164124_add_series_master_to_series_statement.rb +5 -0
- data/spec/dummy/db/migrate/20130429020822_add_root_manifestation_id_to_series_statement.rb +6 -0
- data/spec/dummy/db/migrate/20130504133816_add_manifestation_id_to_subject.rb +6 -0
- data/spec/dummy/db/migrate/20130504143515_add_manifestation_id_to_classification.rb +6 -0
- data/spec/dummy/db/migrate/20130504195916_add_subject_heading_type_id_to_subject.rb +5 -0
- data/spec/dummy/db/migrate/20130506175303_create_identifier_types.rb +12 -0
- data/spec/dummy/db/migrate/20130506175834_create_identifiers.rb +15 -0
- data/spec/dummy/db/migrate/20130509185724_add_statement_of_responsibility_to_manifestation.rb +5 -0
- data/spec/dummy/db/migrate/20130519065638_add_lock_version_to_reserve.rb +5 -0
- data/spec/dummy/db/migrate/20130519065837_add_lock_version_to_checkin.rb +5 -0
- data/spec/dummy/db/migrate/20140610123439_drop_email_unique_constraint_enju_leaf_rc10.rb +11 -0
- data/spec/dummy/db/schema.rb +613 -92
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/private/system/event_import_files/event_imports/000/000/004/original/event_import_file_sample1.tsv +7 -7
- data/spec/dummy/solr/default/data/index/_b2.fdt +0 -0
- data/spec/dummy/solr/default/data/index/{_14y.fdx → _b2.fdx} +0 -0
- data/spec/dummy/solr/default/data/index/{_14y.fnm → _b2.fnm} +0 -0
- data/spec/dummy/solr/default/data/index/{_14y.nvd → _b2.nvd} +0 -0
- data/spec/dummy/solr/default/data/index/{_14y.nvm → _b2.nvm} +0 -0
- data/spec/dummy/solr/default/data/index/{_14y.si → _b2.si} +0 -0
- data/spec/dummy/solr/default/data/index/{_14y_Lucene41_0.doc → _b2_Lucene41_0.doc} +0 -0
- data/spec/dummy/solr/default/data/index/{_14y_Lucene41_0.pos → _b2_Lucene41_0.pos} +0 -0
- data/spec/dummy/solr/default/data/index/{_14y_Lucene41_0.tim → _b2_Lucene41_0.tim} +0 -0
- data/spec/dummy/solr/default/data/index/{_14y_Lucene41_0.tip → _b2_Lucene41_0.tip} +0 -0
- data/spec/dummy/solr/default/data/index/_b3.fdt +0 -0
- data/spec/dummy/solr/default/data/index/{_14z.fdx → _b3.fdx} +0 -0
- data/spec/dummy/solr/default/data/index/{_14z.fnm → _b3.fnm} +0 -0
- data/spec/dummy/solr/default/data/index/{_14z.nvd → _b3.nvd} +0 -0
- data/spec/dummy/solr/default/data/index/{_14z.nvm → _b3.nvm} +0 -0
- data/spec/dummy/solr/default/data/index/{_14z.si → _b3.si} +0 -0
- data/spec/dummy/solr/default/data/index/{_14z_Lucene41_0.doc → _b3_Lucene41_0.doc} +0 -0
- data/spec/dummy/solr/default/data/index/_b3_Lucene41_0.pos +0 -0
- data/spec/dummy/solr/default/data/index/_b3_Lucene41_0.tim +0 -0
- data/spec/dummy/solr/default/data/index/_b3_Lucene41_0.tip +0 -0
- data/spec/dummy/solr/default/data/index/segments.gen +0 -0
- data/spec/dummy/solr/default/data/index/segments_ht +0 -0
- data/spec/dummy/solr/default/data/tlog/tlog.0000000000000000630 +0 -0
- data/spec/dummy/solr/default/data/tlog/tlog.0000000000000000631 +0 -0
- data/spec/dummy/solr/default/data/tlog/{tlog.0000000000000002010 → tlog.0000000000000000632} +0 -0
- data/spec/dummy/solr/default/data/tlog/tlog.0000000000000000633 +0 -0
- data/spec/dummy/solr/default/data/tlog/tlog.0000000000000000634 +0 -0
- data/spec/dummy/solr/default/data/tlog/{tlog.0000000000000002013 → tlog.0000000000000000635} +0 -0
- data/spec/dummy/solr/default/data/tlog/tlog.0000000000000000636 +0 -0
- data/spec/dummy/solr/default/data/tlog/tlog.0000000000000000637 +0 -0
- data/spec/dummy/solr/default/data/tlog/{tlog.0000000000000002016 → tlog.0000000000000000638} +0 -0
- data/spec/dummy/solr/default/data/tlog/tlog.0000000000000000639 +0 -0
- data/spec/dummy/solr/test/data/index/segments.gen +0 -0
- data/spec/dummy/solr/test/data/index/segments_1 +0 -0
- data/spec/fixtures/event_import_files.yml +1 -4
- data/spec/fixtures/libraries.yml +0 -5
- data/spec/models/event_import_file_spec.rb +14 -6
- data/spec/models/event_spec.rb +1 -1
- data/spec/spec_helper.rb +3 -0
- data/spec/support/resque.rb +32 -0
- metadata +271 -140
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20100222124420_add_allow_bookmark_external_url_to_library_group.rb +0 -9
- data/spec/dummy/db/migrate/20100527113752_create_delayed_jobs.rb +0 -21
- data/spec/dummy/db/migrate/20110115022329_add_position_to_library_group.rb +0 -9
- data/spec/dummy/db/migrate/20110627034940_create_series_statement_merge_lists.rb +0 -9
- data/spec/dummy/db/migrate/20110627035057_create_series_statement_merges.rb +0 -12
- data/spec/dummy/db/migrate/20111020063828_remove_dsbl_from_library_group.rb +0 -11
- data/spec/dummy/db/migrate/20111201155456_create_users.rb +0 -14
- data/spec/dummy/db/migrate/20111201155513_add_devise_to_users.rb +0 -52
- data/spec/dummy/solr/default/data/index/_14y.fdt +0 -0
- data/spec/dummy/solr/default/data/index/_14z.fdt +0 -0
- data/spec/dummy/solr/default/data/index/_14z_Lucene41_0.pos +0 -0
- data/spec/dummy/solr/default/data/index/_14z_Lucene41_0.tim +0 -0
- data/spec/dummy/solr/default/data/index/_14z_Lucene41_0.tip +0 -0
- data/spec/dummy/solr/default/data/index/segments_1k3 +0 -0
- data/spec/dummy/solr/default/data/tlog/tlog.0000000000000002008 +0 -0
- data/spec/dummy/solr/default/data/tlog/tlog.0000000000000002009 +0 -0
- data/spec/dummy/solr/default/data/tlog/tlog.0000000000000002011 +0 -0
- data/spec/dummy/solr/default/data/tlog/tlog.0000000000000002012 +0 -0
- data/spec/dummy/solr/default/data/tlog/tlog.0000000000000002014 +0 -0
- data/spec/dummy/solr/default/data/tlog/tlog.0000000000000002015 +0 -0
- data/spec/dummy/solr/default/data/tlog/tlog.0000000000000002017 +0 -0
- data/spec/dummy/solr/test/data/index/_a.fdt +0 -0
- data/spec/dummy/solr/test/data/index/_a.fdx +0 -0
- data/spec/dummy/solr/test/data/index/_a.fnm +0 -0
- data/spec/dummy/solr/test/data/index/_a.nvd +0 -0
- data/spec/dummy/solr/test/data/index/_a.nvm +0 -0
- data/spec/dummy/solr/test/data/index/_a.si +0 -0
- data/spec/dummy/solr/test/data/index/_a_Lucene41_0.doc +0 -0
- data/spec/dummy/solr/test/data/index/_a_Lucene41_0.pos +0 -0
- data/spec/dummy/solr/test/data/index/_a_Lucene41_0.tim +0 -0
- data/spec/dummy/solr/test/data/index/_a_Lucene41_0.tip +0 -0
- data/spec/dummy/solr/test/data/index/segments_n +0 -0
- data/spec/dummy/solr/test/data/tlog/tlog.0000000000000000013 +0 -0
- data/spec/dummy/solr/test/data/tlog/tlog.0000000000000000014 +0 -0
- data/spec/dummy/solr/test/data/tlog/tlog.0000000000000000015 +0 -0
- data/spec/dummy/solr/test/data/tlog/tlog.0000000000000000016 +0 -0
- data/spec/dummy/solr/test/data/tlog/tlog.0000000000000000017 +0 -0
- data/spec/dummy/solr/test/data/tlog/tlog.0000000000000000018 +0 -0
- data/spec/dummy/solr/test/data/tlog/tlog.0000000000000000019 +0 -0
- data/spec/dummy/solr/test/data/tlog/tlog.0000000000000000020 +0 -0
- data/spec/dummy/solr/test/data/tlog/tlog.0000000000000000021 +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19d8e03ae2f152bb7bd62973d11643c6c9584142
|
4
|
+
data.tar.gz: d81b4c9c0736f99728e333b39403bc5b1b1d78ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8d99e42d2685c5f0d4b3efd2f867f1758cab20215203e5b567a9ff984177f1ca7b5e5010e2d0fb0dfa5352ac1f992672fc43ed11e790023cbfae8f343122981
|
7
|
+
data.tar.gz: f9a6a667c97accb06e93a3741425629457635aaec5f4faa7fb932a2ac23e767a82ef7c652e4d8ea683cde09a8ab1c9144c3a365a7cc561fe187a198cb05f3ba4
|
@@ -57,6 +57,9 @@ class EventImportFilesController < ApplicationController
|
|
57
57
|
|
58
58
|
respond_to do |format|
|
59
59
|
if @event_import_file.save
|
60
|
+
if @event_import_file.mode == 'import'
|
61
|
+
Resque.enqueue(EventImportFileQueue, @event_import_file.id)
|
62
|
+
end
|
60
63
|
flash[:notice] = t('controller.successfully_created', :model => t('activerecord.models.event_import_file'))
|
61
64
|
format.html { redirect_to(@event_import_file) }
|
62
65
|
format.json { render :json => @event_import_file, :status => :created, :location => @event_import_file }
|
@@ -72,8 +75,10 @@ class EventImportFilesController < ApplicationController
|
|
72
75
|
def update
|
73
76
|
respond_to do |format|
|
74
77
|
if @event_import_file.update_attributes(params[:event_import_file])
|
75
|
-
|
76
|
-
|
78
|
+
if @event_import_file.mode == 'import'
|
79
|
+
Resque.enqueue(EventImportFileQueue, @event_import_file.id)
|
80
|
+
end
|
81
|
+
format.html { redirect_to @event_import_file, :notice => t('controller.successfully_updated', :model => t('activerecord.models.event_import_file')) }
|
77
82
|
format.json { head :no_content }
|
78
83
|
else
|
79
84
|
format.html { render :action => "edit" }
|
data/app/models/event.rb
CHANGED
@@ -36,26 +36,24 @@ class Event < ActiveRecord::Base
|
|
36
36
|
paginates_per 10
|
37
37
|
|
38
38
|
def set_date
|
39
|
-
if
|
40
|
-
|
41
|
-
end
|
42
|
-
if self.end_at.blank?
|
43
|
-
self.end_at = Time.zone.today.end_of_day
|
39
|
+
if all_day
|
40
|
+
set_all_day
|
44
41
|
end
|
45
|
-
|
46
|
-
set_all_day
|
47
42
|
end
|
48
43
|
|
49
44
|
def set_all_day
|
50
|
-
|
51
|
-
|
52
|
-
|
45
|
+
return false unless start_at
|
46
|
+
self.start_at = start_at.beginning_of_day
|
47
|
+
if end_at
|
48
|
+
self.end_at = end_at.end_of_day
|
49
|
+
else
|
50
|
+
self.end_at = start_at.end_of_day
|
53
51
|
end
|
54
52
|
end
|
55
53
|
|
56
54
|
def check_date
|
57
|
-
if
|
58
|
-
if
|
55
|
+
if start_at and end_at
|
56
|
+
if start_at >= end_at
|
59
57
|
errors.add(:start_at)
|
60
58
|
errors.add(:end_at)
|
61
59
|
end
|
@@ -63,7 +61,7 @@ class Event < ActiveRecord::Base
|
|
63
61
|
end
|
64
62
|
|
65
63
|
def set_display_name
|
66
|
-
self.display_name =
|
64
|
+
self.display_name = name if display_name.blank?
|
67
65
|
end
|
68
66
|
end
|
69
67
|
|
@@ -1,12 +1,14 @@
|
|
1
1
|
class EventImportFile < ActiveRecord::Base
|
2
|
-
|
2
|
+
include Statesman::Adapters::ActiveRecordModel
|
3
3
|
include ImportFile
|
4
|
-
|
5
|
-
|
6
|
-
scope :
|
4
|
+
attr_accessible :event_import, :edit_mode, :user_encoding, :mode
|
5
|
+
default_scope {order('event_import_files.id DESC')}
|
6
|
+
scope :not_imported, -> {in_state(:pending)}
|
7
|
+
scope :stucked, -> {in_state(:pending).where('created_at < ?', 1.hour.ago)}
|
7
8
|
|
8
9
|
if Setting.uploaded_file.storage == :s3
|
9
|
-
has_attached_file :event_import, :storage => :s3,
|
10
|
+
has_attached_file :event_import, :storage => :s3,
|
11
|
+
:s3_credentials => "#{Setting.amazon}",
|
10
12
|
:s3_permissions => :private
|
11
13
|
else
|
12
14
|
has_attached_file :event_import,
|
@@ -23,54 +25,30 @@ class EventImportFile < ActiveRecord::Base
|
|
23
25
|
belongs_to :user, :validate => true
|
24
26
|
has_many :event_import_results
|
25
27
|
|
26
|
-
|
27
|
-
event :sm_start do
|
28
|
-
transition [:pending, :started] => :started
|
29
|
-
end
|
30
|
-
|
31
|
-
event :sm_complete do
|
32
|
-
transition :started => :completed
|
33
|
-
end
|
28
|
+
has_many :event_import_file_transitions
|
34
29
|
|
35
|
-
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
before_transition any => :started do |agent_import_file|
|
40
|
-
agent_import_file.executed_at = Time.zone.now
|
41
|
-
end
|
30
|
+
enju_import_file_model
|
31
|
+
attr_accessor :mode
|
42
32
|
|
43
|
-
|
44
|
-
|
45
|
-
end
|
33
|
+
def state_machine
|
34
|
+
@state_machine ||= EventImportFileStateMachine.new(self, transition_class: EventImportFileTransition)
|
46
35
|
end
|
47
36
|
|
48
|
-
|
49
|
-
|
50
|
-
sm_start!
|
51
|
-
case edit_mode
|
52
|
-
when 'create'
|
53
|
-
import
|
54
|
-
when 'update'
|
55
|
-
modify
|
56
|
-
when 'destroy'
|
57
|
-
remove
|
58
|
-
else
|
59
|
-
import
|
60
|
-
end
|
61
|
-
end
|
37
|
+
delegate :can_transition_to?, :transition_to!, :transition_to, :current_state,
|
38
|
+
to: :state_machine
|
62
39
|
|
63
40
|
def import
|
64
|
-
|
41
|
+
transition_to!(:started)
|
65
42
|
num = {:imported => 0, :failed => 0}
|
66
|
-
rows = open_import_file
|
43
|
+
rows = open_import_file(create_import_temp_file)
|
67
44
|
check_field(rows.first)
|
68
|
-
row_num =
|
45
|
+
row_num = 1
|
69
46
|
|
70
47
|
rows.each do |row|
|
48
|
+
row_num += 1
|
71
49
|
next if row['dummy'].to_s.strip.present?
|
72
50
|
event_import_result = EventImportResult.new
|
73
|
-
event_import_result.assign_attributes({:event_import_file_id => id, :body => row.fields.join("\t")}, :
|
51
|
+
event_import_result.assign_attributes({:event_import_file_id => id, :body => row.fields.join("\t")}, as: :admin)
|
74
52
|
event_import_result.save!
|
75
53
|
|
76
54
|
event = Event.new
|
@@ -90,34 +68,36 @@ class EventImportFile < ActiveRecord::Base
|
|
90
68
|
event_category = EventCategory.where(:name => category).first || EventCategory.where(:name => 'unknown').first
|
91
69
|
event.event_category = event_category
|
92
70
|
|
93
|
-
if event.save
|
71
|
+
if event.save
|
94
72
|
event_import_result.event = event
|
95
73
|
num[:imported] += 1
|
96
74
|
if row_num % 50 == 0
|
97
75
|
Sunspot.commit
|
98
76
|
GC.start
|
99
77
|
end
|
78
|
+
else
|
79
|
+
num[:failed] += 1
|
100
80
|
end
|
101
81
|
event_import_result.save!
|
102
|
-
row_num += 1
|
103
82
|
end
|
104
|
-
rows.close
|
105
|
-
sm_complete!
|
106
83
|
Sunspot.commit
|
107
|
-
|
84
|
+
rows.close
|
85
|
+
transition_to!(:completed)
|
86
|
+
return num
|
108
87
|
rescue => e
|
109
88
|
self.error_message = "line #{row_num}: #{e.message}"
|
110
|
-
|
89
|
+
transition_to!(:failed)
|
111
90
|
raise e
|
112
91
|
end
|
113
92
|
|
114
93
|
def modify
|
115
|
-
|
116
|
-
rows = open_import_file
|
94
|
+
transition_to!(:started)
|
95
|
+
rows = open_import_file(create_import_temp_file)
|
117
96
|
check_field(rows.first)
|
118
|
-
row_num =
|
97
|
+
row_num = 1
|
119
98
|
|
120
99
|
rows.each do |row|
|
100
|
+
row_num += 1
|
121
101
|
next if row['dummy'].to_s.strip.present?
|
122
102
|
event = Event.find(row['id'].to_s.strip)
|
123
103
|
event_category = EventCategory.where(:name => row['category'].to_s.strip).first
|
@@ -134,31 +114,32 @@ class EventImportFile < ActiveRecord::Base
|
|
134
114
|
event.all_day = true
|
135
115
|
end
|
136
116
|
event.save!
|
137
|
-
row_num += 1
|
138
117
|
end
|
139
|
-
|
118
|
+
transition_to!(:completed)
|
140
119
|
rescue => e
|
141
120
|
self.error_message = "line #{row_num}: #{e.message}"
|
142
|
-
|
121
|
+
transition_to!(:failed)
|
143
122
|
raise e
|
144
123
|
end
|
145
124
|
|
146
125
|
def remove
|
147
|
-
|
148
|
-
rows = open_import_file
|
126
|
+
transition_to!(:started)
|
127
|
+
rows = open_import_file(create_import_temp_file)
|
149
128
|
rows.shift
|
150
|
-
row_num =
|
129
|
+
row_num = 1
|
151
130
|
|
152
131
|
rows.each do |row|
|
132
|
+
row_num += 1
|
153
133
|
next if row['dummy'].to_s.strip.present?
|
154
134
|
event = Event.find(row['id'].to_s.strip)
|
135
|
+
event.picture_files.destroy_all # workaround
|
136
|
+
event.reload
|
155
137
|
event.destroy
|
156
|
-
row_num += 1
|
157
138
|
end
|
158
|
-
|
139
|
+
transition_to!(:completed)
|
159
140
|
rescue => e
|
160
141
|
self.error_message = "line #{row_num}: #{e.message}"
|
161
|
-
|
142
|
+
transition_to!(:failed)
|
162
143
|
raise e
|
163
144
|
end
|
164
145
|
|
@@ -171,8 +152,12 @@ class EventImportFile < ActiveRecord::Base
|
|
171
152
|
end
|
172
153
|
|
173
154
|
private
|
174
|
-
def
|
175
|
-
|
155
|
+
def self.transition_class
|
156
|
+
EventImportFileTransition
|
157
|
+
end
|
158
|
+
|
159
|
+
def create_import_temp_file
|
160
|
+
tempfile = Tempfile.new(self.class.name.underscore)
|
176
161
|
if Setting.uploaded_file.storage == :s3
|
177
162
|
uploaded_file_path = event_import.expiring_url(10)
|
178
163
|
else
|
@@ -180,25 +165,19 @@ class EventImportFile < ActiveRecord::Base
|
|
180
165
|
end
|
181
166
|
open(uploaded_file_path){|f|
|
182
167
|
f.each{|line|
|
183
|
-
|
184
|
-
begin
|
185
|
-
string = line.encode('UTF-8', CharlockHolmes::EncodingDetector.detect(line)[:encoding], universal_newline: true)
|
186
|
-
rescue StandardError
|
187
|
-
string = NKF.nkf('-w -Lu', line)
|
188
|
-
end
|
189
|
-
else
|
190
|
-
string = NKF.nkf('-w -Lu', line)
|
191
|
-
end
|
192
|
-
tempfile.puts(string)
|
168
|
+
tempfile.puts(convert_encoding(line))
|
193
169
|
}
|
194
170
|
}
|
195
171
|
tempfile.close
|
172
|
+
tempfile
|
173
|
+
end
|
196
174
|
|
175
|
+
def open_import_file(tempfile)
|
197
176
|
file = CSV.open(tempfile, :col_sep => "\t")
|
198
177
|
header = file.first
|
199
178
|
rows = CSV.open(tempfile, :headers => header, :col_sep => "\t")
|
200
179
|
event_import_result = EventImportResult.new
|
201
|
-
event_import_result.assign_attributes({:event_import_file_id => id, :body => header.join("\t")}, :
|
180
|
+
event_import_result.assign_attributes({:event_import_file_id => id, :body => header.join("\t")}, as: :admin)
|
202
181
|
event_import_result.save!
|
203
182
|
tempfile.close(true)
|
204
183
|
file.close
|
@@ -226,7 +205,6 @@ end
|
|
226
205
|
# user_id :integer
|
227
206
|
# note :text
|
228
207
|
# executed_at :datetime
|
229
|
-
# state :string(255)
|
230
208
|
# event_import_file_name :string(255)
|
231
209
|
# event_import_content_type :string(255)
|
232
210
|
# event_import_file_size :integer
|
@@ -236,5 +214,6 @@ end
|
|
236
214
|
# updated_at :datetime not null
|
237
215
|
# event_import_fingerprint :string(255)
|
238
216
|
# error_message :text
|
217
|
+
# user_encoding :string(255)
|
239
218
|
#
|
240
219
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class EventImportFileStateMachine
|
2
|
+
include Statesman::Machine
|
3
|
+
|
4
|
+
state :pending, initial: true
|
5
|
+
state :started
|
6
|
+
state :completed
|
7
|
+
state :failed
|
8
|
+
|
9
|
+
transition from: :pending, to: :started
|
10
|
+
transition from: :started, to: [:completed, :failed]
|
11
|
+
|
12
|
+
after_transition(from: :pending, to: :started) do |event_import_file|
|
13
|
+
event_import_file.update_column(:executed_at, Time.zone.now)
|
14
|
+
end
|
15
|
+
|
16
|
+
before_transition(from: :started, to: :completed) do |event_import_file|
|
17
|
+
event_import_file.error_message = nil
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class EventImportFileTransition < ActiveRecord::Base
|
2
|
+
include Statesman::Adapters::ActiveRecordTransition
|
3
|
+
|
4
|
+
|
5
|
+
belongs_to :event_import_file, inverse_of: :event_import_file_transitions
|
6
|
+
attr_accessible :to_state, :sort_key, :metadata
|
7
|
+
end
|
8
|
+
|
9
|
+
# == Schema Information
|
10
|
+
#
|
11
|
+
# Table name: event_import_file_transitions
|
12
|
+
#
|
13
|
+
# id :integer not null, primary key
|
14
|
+
# to_state :string(255)
|
15
|
+
# metadata :text default("{}")
|
16
|
+
# sort_key :integer
|
17
|
+
# event_import_file_id :integer
|
18
|
+
# created_at :datetime not null
|
19
|
+
# updated_at :datetime not null
|
20
|
+
#
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<div id="content_detail" class="ui-corner-all">
|
1
|
+
<div id="content_detail" class="ui-corner-all ui-widget-content">
|
2
2
|
<%- if @library -%>
|
3
3
|
<h1 class="title">
|
4
4
|
<%= t('calendar.library_calendar', :library_name => @library.display_name.localize) -%>
|
@@ -34,7 +34,7 @@
|
|
34
34
|
</div>
|
35
35
|
</div>
|
36
36
|
|
37
|
-
<div id="submenu" class="ui-corner-all">
|
37
|
+
<div id="submenu" class="ui-corner-all ui-widget-content">
|
38
38
|
<ul>
|
39
39
|
<li><%= link_to t('page.listing', :model => t('activerecord.models.event')), events_path -%></li>
|
40
40
|
<li><%= link_to t('page.show_all'), :controller => :calendar, :action => :index -%></li>
|
@@ -1,11 +1,11 @@
|
|
1
|
-
<div id="content_detail" class="ui-corner-all">
|
1
|
+
<div id="content_detail" class="ui-corner-all ui-widget-content">
|
2
2
|
<h1 class="title"><%= t('page.editing', :model => t('activerecord.models.event_category')) -%></h1>
|
3
3
|
<div id="content_list">
|
4
4
|
<%= render 'form' %>
|
5
5
|
</div>
|
6
6
|
</div>
|
7
7
|
|
8
|
-
<div id="submenu" class="ui-corner-all">
|
8
|
+
<div id="submenu" class="ui-corner-all ui-widget-content">
|
9
9
|
<ul>
|
10
10
|
<li><%= link_to t('page.show'), @event_category -%></li>
|
11
11
|
<li><%= link_to t('page.back'), event_categories_path -%></li>
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<div id="content_detail" class="ui-corner-all">
|
1
|
+
<div id="content_detail" class="ui-corner-all ui-widget-content">
|
2
2
|
<h1 class="title"><%= t('page.listing', :model => t('activerecord.models.event_category')) -%></h1>
|
3
3
|
<div id="content_list">
|
4
4
|
|
@@ -37,7 +37,7 @@
|
|
37
37
|
</div>
|
38
38
|
</div>
|
39
39
|
|
40
|
-
<div id="submenu" class="ui-corner-all">
|
40
|
+
<div id="submenu" class="ui-corner-all ui-widget-content">
|
41
41
|
<ul>
|
42
42
|
<%- if can? :create, EventCategory -%>
|
43
43
|
<li><%= link_to t('page.new', :model => t('activerecord.models.event_category')), new_event_category_path -%></li>
|
@@ -1,11 +1,11 @@
|
|
1
|
-
<div id="content_detail" class="ui-corner-all">
|
1
|
+
<div id="content_detail" class="ui-corner-all ui-widget-content">
|
2
2
|
<h1 class="title"><%= t('page.new', :model => t('activerecord.models.event_category')) -%></h1>
|
3
3
|
<div id="content_list">
|
4
4
|
<%= render 'form' %>
|
5
5
|
</div>
|
6
6
|
</div>
|
7
7
|
|
8
|
-
<div id="submenu" class="ui-corner-all">
|
8
|
+
<div id="submenu" class="ui-corner-all ui-widget-content">
|
9
9
|
<ul>
|
10
10
|
<li><%= link_to t('page.back'), event_categories_path -%></li>
|
11
11
|
</ul>
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<div id="content_detail" class="ui-corner-all">
|
1
|
+
<div id="content_detail" class="ui-corner-all ui-widget-content">
|
2
2
|
<h1 class="title"><%= t('page.showing', :model => t('activerecord.models.event_category')) -%></h1>
|
3
3
|
<div id="content_list">
|
4
4
|
<p id="notice"><%= notice %></p>
|
@@ -21,7 +21,7 @@
|
|
21
21
|
</div>
|
22
22
|
</div>
|
23
23
|
|
24
|
-
<div id="submenu" class="ui-corner-all">
|
24
|
+
<div id="submenu" class="ui-corner-all ui-widget-content">
|
25
25
|
<ul>
|
26
26
|
<li><%= link_to t('page.edit'), edit_event_category_path(@event_category) -%></li>
|
27
27
|
<li><%= back_to_index(flash[:page_info]) -%></li>
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<div id="content_detail" class="ui-corner-all">
|
1
|
+
<div id="content_detail" class="ui-corner-all ui-widget-content">
|
2
2
|
<h1 class="title"><%= t('page.editing', :model => t('activerecord.models.event_import_file')) -%></h1>
|
3
3
|
<div id="content_list">
|
4
4
|
|
@@ -17,7 +17,7 @@
|
|
17
17
|
</div>
|
18
18
|
</div>
|
19
19
|
|
20
|
-
<div id="submenu" class="ui-corner-all">
|
20
|
+
<div id="submenu" class="ui-corner-all ui-widget-content">
|
21
21
|
<ul>
|
22
22
|
<li><%= link_to t('page.show'), @event_import_file -%></li>
|
23
23
|
<li><%= link_to t('page.back'), event_import_files_path -%></li>
|