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.
Files changed (203) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/event_import_files_controller.rb +7 -2
  3. data/app/controllers/event_import_results_controller.rb +1 -1
  4. data/app/models/event.rb +11 -13
  5. data/app/models/event_import_file.rb +52 -73
  6. data/app/models/event_import_file_state_machine.rb +19 -0
  7. data/app/models/event_import_file_transition.rb +20 -0
  8. data/app/views/calendar/index.html.erb +2 -2
  9. data/app/views/event_categories/edit.html.erb +2 -2
  10. data/app/views/event_categories/index.html.erb +2 -2
  11. data/app/views/event_categories/new.html.erb +2 -2
  12. data/app/views/event_categories/show.html.erb +2 -2
  13. data/app/views/event_import_files/edit.html.erb +2 -2
  14. data/app/views/event_import_files/index.html.erb +4 -4
  15. data/app/views/event_import_files/new.html.erb +17 -4
  16. data/app/views/event_import_files/show.html.erb +13 -3
  17. data/app/views/event_import_results/index.html.erb +6 -6
  18. data/app/views/event_import_results/{index.csv.erb → index.tsv.erb} +0 -0
  19. data/app/views/event_import_results/show.html.erb +2 -2
  20. data/app/views/events/edit.html.erb +2 -2
  21. data/app/views/events/index.html.erb +2 -2
  22. data/app/views/events/new.html.erb +2 -2
  23. data/app/views/events/show.html.erb +8 -3
  24. data/app/views/participates/edit.html.erb +2 -2
  25. data/app/views/participates/index.html.erb +2 -2
  26. data/app/views/participates/new.html.erb +2 -2
  27. data/app/views/participates/show.html.erb +2 -2
  28. data/app/workers/event_import_file_queue.rb +7 -0
  29. data/config/locales/translation_en.yml +1 -0
  30. data/config/locales/translation_ja.yml +1 -0
  31. data/db/migrate/20081028093607_create_event_import_files.rb +0 -2
  32. data/db/migrate/20140523171309_create_event_import_file_transitions.rb +14 -0
  33. data/db/migrate/20140628071719_add_user_encoding_to_event_import_file.rb +5 -0
  34. data/lib/enju_event/engine.rb +1 -1
  35. data/lib/enju_event/version.rb +1 -1
  36. data/spec/dummy/db/migrate/005_create_manifestations.rb +0 -12
  37. data/spec/dummy/db/migrate/006_create_items.rb +2 -2
  38. data/spec/dummy/db/migrate/029_create_subjects.rb +27 -0
  39. data/spec/dummy/db/migrate/032_create_checkins.rb +17 -0
  40. data/spec/dummy/db/migrate/033_create_checkouts.rb +25 -0
  41. data/spec/dummy/db/migrate/035_create_reserves.rb +27 -0
  42. data/spec/dummy/db/migrate/059_create_libraries.rb +1 -7
  43. data/spec/dummy/db/migrate/069_create_shelves.rb +1 -5
  44. data/spec/dummy/db/migrate/{20111201163342_create_user_groups.rb → 077_create_user_groups.rb} +2 -2
  45. data/spec/dummy/db/migrate/080_create_library_groups.rb +2 -9
  46. data/spec/dummy/db/migrate/120_create_baskets.rb +12 -0
  47. data/spec/dummy/db/migrate/121_create_checked_items.rb +17 -0
  48. data/spec/dummy/db/migrate/124_create_bookstores.rb +17 -0
  49. data/spec/dummy/db/migrate/127_create_use_restrictions.rb +16 -0
  50. data/spec/dummy/db/migrate/129_create_item_has_use_restrictions.rb +16 -0
  51. data/spec/dummy/db/migrate/130_create_request_status_types.rb +12 -0
  52. data/spec/dummy/db/migrate/131_create_request_types.rb +12 -0
  53. data/spec/dummy/db/migrate/132_create_circulation_statuses.rb +16 -0
  54. data/spec/dummy/db/migrate/142_create_classifications.rb +19 -0
  55. data/spec/dummy/db/migrate/143_create_subject_has_classifications.rb +16 -0
  56. data/spec/dummy/db/migrate/144_create_classification_types.rb +16 -0
  57. data/spec/dummy/db/migrate/145_create_subject_heading_types.rb +16 -0
  58. data/spec/dummy/db/migrate/146_create_subject_types.rb +16 -0
  59. data/spec/dummy/db/migrate/149_create_message_templates.rb +18 -0
  60. data/spec/dummy/db/migrate/154_create_messages.rb +24 -0
  61. data/spec/dummy/db/migrate/20080606052544_create_work_has_subjects.rb +18 -0
  62. data/spec/dummy/db/migrate/20080819181903_create_message_requests.rb +20 -0
  63. data/spec/dummy/db/migrate/20081006090811_create_subscriptions.rb +17 -0
  64. data/spec/dummy/db/migrate/20081006093246_create_subscribes.rb +14 -0
  65. data/spec/dummy/db/migrate/20081023092436_create_search_engines.rb +17 -0
  66. data/spec/dummy/db/migrate/20081030023412_create_checkout_types.rb +17 -0
  67. data/spec/dummy/db/migrate/20081030023518_create_user_group_has_checkout_types.rb +25 -0
  68. data/spec/dummy/db/migrate/20081030023615_create_carrier_type_has_checkout_types.rb +18 -0
  69. data/spec/dummy/db/migrate/20081212075554_create_checkout_stat_has_manifestations.rb +17 -0
  70. data/spec/dummy/db/migrate/20081212080038_create_manifestation_checkout_stats.rb +16 -0
  71. data/spec/dummy/db/migrate/20081215094302_create_user_checkout_stats.rb +16 -0
  72. data/spec/dummy/db/migrate/20081215094955_create_checkout_stat_has_users.rb +17 -0
  73. data/spec/dummy/db/migrate/20081216190517_create_reserve_stat_has_manifestations.rb +17 -0
  74. data/spec/dummy/db/migrate/20081216190724_create_manifestation_reserve_stats.rb +16 -0
  75. data/spec/dummy/db/migrate/20081220023628_create_user_reserve_stats.rb +16 -0
  76. data/spec/dummy/db/migrate/20081220034117_create_reserve_stat_has_users.rb +17 -0
  77. data/spec/dummy/db/migrate/20090208044541_create_subject_heading_type_has_subjects.rb +16 -0
  78. data/spec/dummy/db/migrate/20090321130448_add_completed_at_to_user_checkout_stat.rb +27 -0
  79. data/spec/dummy/db/migrate/20090831220301_create_lending_policies.rb +21 -0
  80. data/spec/dummy/db/migrate/20100314190054_add_opening_hour_to_library.rb +9 -0
  81. data/spec/dummy/db/migrate/20110301134521_add_expire_date_to_reserve.rb +9 -0
  82. data/spec/dummy/db/migrate/20110318183304_add_valid_period_for_new_user_to_user_group.rb +11 -0
  83. data/spec/dummy/db/migrate/20110328130826_add_current_checkout_count_to_user_group_has_checkout_type.rb +9 -0
  84. data/spec/dummy/db/migrate/20110603184217_add_edit_mode_to_resource_import_file.rb +9 -0
  85. data/spec/dummy/db/migrate/20110621093332_remove_expire_date_from_reserve.rb +9 -0
  86. data/spec/dummy/db/migrate/20110627122938_add_number_of_day_to_notify_overdue_to_user_group.rb +13 -0
  87. data/spec/dummy/db/migrate/20110913115320_add_lft_and_rgt_to_message.rb +11 -0
  88. data/spec/dummy/db/migrate/20110913120629_add_lft_and_rgt_to_classification.rb +11 -0
  89. data/spec/dummy/db/migrate/20111201155456_devise_create_users.rb +42 -0
  90. data/spec/dummy/db/migrate/20111217234412_add_save_checkout_history_to_user.rb +5 -0
  91. data/spec/dummy/db/migrate/20111218002349_add_checkout_icalendar_token_to_user.rb +6 -0
  92. data/spec/dummy/db/migrate/20120125050502_add_depth_to_message.rb +6 -0
  93. data/spec/dummy/db/migrate/20120129014038_create_budget_types.rb +12 -0
  94. data/spec/dummy/db/migrate/20120319173203_create_accepts.rb +14 -0
  95. data/spec/dummy/db/migrate/20120406020752_add_url_to_subject.rb +5 -0
  96. data/spec/dummy/db/migrate/20120424103932_add_librarian_id_to_checked_item.rb +5 -0
  97. data/spec/dummy/db/migrate/20120510140958_add_closed_to_shelf.rb +5 -0
  98. data/spec/dummy/db/migrate/20121116033446_add_doi_to_manifestation.rb +6 -0
  99. data/spec/dummy/db/migrate/20130221154434_add_additional_attributes_to_user.rb +26 -0
  100. data/spec/dummy/db/migrate/20130303104849_add_state_index_to_reserve.rb +5 -0
  101. data/spec/dummy/db/migrate/20130303124821_add_retained_at_to_reserve.rb +5 -0
  102. data/spec/dummy/db/migrate/20130304015019_add_postponed_at_to_reserve.rb +5 -0
  103. data/spec/dummy/db/migrate/20130412083556_add_latitude_and_longitude_to_library.rb +6 -0
  104. data/spec/dummy/db/migrate/20130416054135_add_circulation_status_id_to_item.rb +8 -0
  105. data/spec/dummy/db/migrate/20130421093852_add_periodical_to_manifestation.rb +5 -0
  106. data/spec/dummy/db/migrate/20130421155019_add_creator_string_to_series_statement.rb +7 -0
  107. data/spec/dummy/db/migrate/20130421164124_add_series_master_to_series_statement.rb +5 -0
  108. data/spec/dummy/db/migrate/20130429020822_add_root_manifestation_id_to_series_statement.rb +6 -0
  109. data/spec/dummy/db/migrate/20130504133816_add_manifestation_id_to_subject.rb +6 -0
  110. data/spec/dummy/db/migrate/20130504143515_add_manifestation_id_to_classification.rb +6 -0
  111. data/spec/dummy/db/migrate/20130504195916_add_subject_heading_type_id_to_subject.rb +5 -0
  112. data/spec/dummy/db/migrate/20130506175303_create_identifier_types.rb +12 -0
  113. data/spec/dummy/db/migrate/20130506175834_create_identifiers.rb +15 -0
  114. data/spec/dummy/db/migrate/20130509185724_add_statement_of_responsibility_to_manifestation.rb +5 -0
  115. data/spec/dummy/db/migrate/20130519065638_add_lock_version_to_reserve.rb +5 -0
  116. data/spec/dummy/db/migrate/20130519065837_add_lock_version_to_checkin.rb +5 -0
  117. data/spec/dummy/db/migrate/20140610123439_drop_email_unique_constraint_enju_leaf_rc10.rb +11 -0
  118. data/spec/dummy/db/schema.rb +613 -92
  119. data/spec/dummy/db/test.sqlite3 +0 -0
  120. data/spec/dummy/private/system/event_import_files/event_imports/000/000/004/original/event_import_file_sample1.tsv +7 -7
  121. data/spec/dummy/solr/default/data/index/_b2.fdt +0 -0
  122. data/spec/dummy/solr/default/data/index/{_14y.fdx → _b2.fdx} +0 -0
  123. data/spec/dummy/solr/default/data/index/{_14y.fnm → _b2.fnm} +0 -0
  124. data/spec/dummy/solr/default/data/index/{_14y.nvd → _b2.nvd} +0 -0
  125. data/spec/dummy/solr/default/data/index/{_14y.nvm → _b2.nvm} +0 -0
  126. data/spec/dummy/solr/default/data/index/{_14y.si → _b2.si} +0 -0
  127. data/spec/dummy/solr/default/data/index/{_14y_Lucene41_0.doc → _b2_Lucene41_0.doc} +0 -0
  128. data/spec/dummy/solr/default/data/index/{_14y_Lucene41_0.pos → _b2_Lucene41_0.pos} +0 -0
  129. data/spec/dummy/solr/default/data/index/{_14y_Lucene41_0.tim → _b2_Lucene41_0.tim} +0 -0
  130. data/spec/dummy/solr/default/data/index/{_14y_Lucene41_0.tip → _b2_Lucene41_0.tip} +0 -0
  131. data/spec/dummy/solr/default/data/index/_b3.fdt +0 -0
  132. data/spec/dummy/solr/default/data/index/{_14z.fdx → _b3.fdx} +0 -0
  133. data/spec/dummy/solr/default/data/index/{_14z.fnm → _b3.fnm} +0 -0
  134. data/spec/dummy/solr/default/data/index/{_14z.nvd → _b3.nvd} +0 -0
  135. data/spec/dummy/solr/default/data/index/{_14z.nvm → _b3.nvm} +0 -0
  136. data/spec/dummy/solr/default/data/index/{_14z.si → _b3.si} +0 -0
  137. data/spec/dummy/solr/default/data/index/{_14z_Lucene41_0.doc → _b3_Lucene41_0.doc} +0 -0
  138. data/spec/dummy/solr/default/data/index/_b3_Lucene41_0.pos +0 -0
  139. data/spec/dummy/solr/default/data/index/_b3_Lucene41_0.tim +0 -0
  140. data/spec/dummy/solr/default/data/index/_b3_Lucene41_0.tip +0 -0
  141. data/spec/dummy/solr/default/data/index/segments.gen +0 -0
  142. data/spec/dummy/solr/default/data/index/segments_ht +0 -0
  143. data/spec/dummy/solr/default/data/tlog/tlog.0000000000000000630 +0 -0
  144. data/spec/dummy/solr/default/data/tlog/tlog.0000000000000000631 +0 -0
  145. data/spec/dummy/solr/default/data/tlog/{tlog.0000000000000002010 → tlog.0000000000000000632} +0 -0
  146. data/spec/dummy/solr/default/data/tlog/tlog.0000000000000000633 +0 -0
  147. data/spec/dummy/solr/default/data/tlog/tlog.0000000000000000634 +0 -0
  148. data/spec/dummy/solr/default/data/tlog/{tlog.0000000000000002013 → tlog.0000000000000000635} +0 -0
  149. data/spec/dummy/solr/default/data/tlog/tlog.0000000000000000636 +0 -0
  150. data/spec/dummy/solr/default/data/tlog/tlog.0000000000000000637 +0 -0
  151. data/spec/dummy/solr/default/data/tlog/{tlog.0000000000000002016 → tlog.0000000000000000638} +0 -0
  152. data/spec/dummy/solr/default/data/tlog/tlog.0000000000000000639 +0 -0
  153. data/spec/dummy/solr/test/data/index/segments.gen +0 -0
  154. data/spec/dummy/solr/test/data/index/segments_1 +0 -0
  155. data/spec/fixtures/event_import_files.yml +1 -4
  156. data/spec/fixtures/libraries.yml +0 -5
  157. data/spec/models/event_import_file_spec.rb +14 -6
  158. data/spec/models/event_spec.rb +1 -1
  159. data/spec/spec_helper.rb +3 -0
  160. data/spec/support/resque.rb +32 -0
  161. metadata +271 -140
  162. data/spec/dummy/db/development.sqlite3 +0 -0
  163. data/spec/dummy/db/migrate/20100222124420_add_allow_bookmark_external_url_to_library_group.rb +0 -9
  164. data/spec/dummy/db/migrate/20100527113752_create_delayed_jobs.rb +0 -21
  165. data/spec/dummy/db/migrate/20110115022329_add_position_to_library_group.rb +0 -9
  166. data/spec/dummy/db/migrate/20110627034940_create_series_statement_merge_lists.rb +0 -9
  167. data/spec/dummy/db/migrate/20110627035057_create_series_statement_merges.rb +0 -12
  168. data/spec/dummy/db/migrate/20111020063828_remove_dsbl_from_library_group.rb +0 -11
  169. data/spec/dummy/db/migrate/20111201155456_create_users.rb +0 -14
  170. data/spec/dummy/db/migrate/20111201155513_add_devise_to_users.rb +0 -52
  171. data/spec/dummy/solr/default/data/index/_14y.fdt +0 -0
  172. data/spec/dummy/solr/default/data/index/_14z.fdt +0 -0
  173. data/spec/dummy/solr/default/data/index/_14z_Lucene41_0.pos +0 -0
  174. data/spec/dummy/solr/default/data/index/_14z_Lucene41_0.tim +0 -0
  175. data/spec/dummy/solr/default/data/index/_14z_Lucene41_0.tip +0 -0
  176. data/spec/dummy/solr/default/data/index/segments_1k3 +0 -0
  177. data/spec/dummy/solr/default/data/tlog/tlog.0000000000000002008 +0 -0
  178. data/spec/dummy/solr/default/data/tlog/tlog.0000000000000002009 +0 -0
  179. data/spec/dummy/solr/default/data/tlog/tlog.0000000000000002011 +0 -0
  180. data/spec/dummy/solr/default/data/tlog/tlog.0000000000000002012 +0 -0
  181. data/spec/dummy/solr/default/data/tlog/tlog.0000000000000002014 +0 -0
  182. data/spec/dummy/solr/default/data/tlog/tlog.0000000000000002015 +0 -0
  183. data/spec/dummy/solr/default/data/tlog/tlog.0000000000000002017 +0 -0
  184. data/spec/dummy/solr/test/data/index/_a.fdt +0 -0
  185. data/spec/dummy/solr/test/data/index/_a.fdx +0 -0
  186. data/spec/dummy/solr/test/data/index/_a.fnm +0 -0
  187. data/spec/dummy/solr/test/data/index/_a.nvd +0 -0
  188. data/spec/dummy/solr/test/data/index/_a.nvm +0 -0
  189. data/spec/dummy/solr/test/data/index/_a.si +0 -0
  190. data/spec/dummy/solr/test/data/index/_a_Lucene41_0.doc +0 -0
  191. data/spec/dummy/solr/test/data/index/_a_Lucene41_0.pos +0 -0
  192. data/spec/dummy/solr/test/data/index/_a_Lucene41_0.tim +0 -0
  193. data/spec/dummy/solr/test/data/index/_a_Lucene41_0.tip +0 -0
  194. data/spec/dummy/solr/test/data/index/segments_n +0 -0
  195. data/spec/dummy/solr/test/data/tlog/tlog.0000000000000000013 +0 -0
  196. data/spec/dummy/solr/test/data/tlog/tlog.0000000000000000014 +0 -0
  197. data/spec/dummy/solr/test/data/tlog/tlog.0000000000000000015 +0 -0
  198. data/spec/dummy/solr/test/data/tlog/tlog.0000000000000000016 +0 -0
  199. data/spec/dummy/solr/test/data/tlog/tlog.0000000000000000017 +0 -0
  200. data/spec/dummy/solr/test/data/tlog/tlog.0000000000000000018 +0 -0
  201. data/spec/dummy/solr/test/data/tlog/tlog.0000000000000000019 +0 -0
  202. data/spec/dummy/solr/test/data/tlog/tlog.0000000000000000020 +0 -0
  203. 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: 2bb07ab59c8323bb442f799092633366e0ea90a8
4
- data.tar.gz: 0f17afccd53715fc1b1d11acc0562fc956a43d2a
3
+ metadata.gz: 19d8e03ae2f152bb7bd62973d11643c6c9584142
4
+ data.tar.gz: d81b4c9c0736f99728e333b39403bc5b1b1d78ce
5
5
  SHA512:
6
- metadata.gz: 3ffbaac20359166dffe3c975e39570ec97bc4f029dbaa2e04b470f3b33b72b0c258c80f7eb22c7109910ae553cf475c519b08175a05f9380cec99ffb3e864665
7
- data.tar.gz: 114b5002a79ea5ab32e28ebaa67f0c9597976ccdcf27b0d8be092796377db9a0a7abded1b1bc43945f71ee148b178b3c45886d86efae34c944415281183a8df2
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
- flash[:notice] = t('controller.successfully_updated', :model => t('activerecord.models.event_import_file'))
76
- format.html { redirect_to(@event_import_file) }
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" }
@@ -1,5 +1,5 @@
1
1
  class EventImportResultsController < InheritedResources::Base
2
- respond_to :html, :json, :csv
2
+ respond_to :html, :json, :tsv
3
3
  load_and_authorize_resource
4
4
  has_scope :file_id
5
5
  actions :index, :show, :destroy
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 self.start_at.blank?
40
- self.start_at = Time.zone.today.beginning_of_day
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
- if all_day
51
- self.start_at = self.start_at.beginning_of_day
52
- self.end_at = self.end_at.end_of_day
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 self.start_at and self.end_at
58
- if self.start_at >= self.end_at
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 = self.name if self.display_name.blank?
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
- attr_accessible :event_import, :edit_mode
2
+ include Statesman::Adapters::ActiveRecordModel
3
3
  include ImportFile
4
- default_scope :order => 'event_import_files.id DESC'
5
- scope :not_imported, where(:state => 'pending')
6
- scope :stucked, where('created_at < ? AND state = ?', 1.hour.ago, 'pending')
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, :s3_credentials => "#{Rails.root.to_s}/config/s3.yml",
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
- state_machine :initial => :pending do
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
- event :sm_fail do
36
- transition :started => :failed
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
- before_transition any => :completed do |agent_import_file|
44
- agent_import_file.error_message = nil
45
- end
33
+ def state_machine
34
+ @state_machine ||= EventImportFileStateMachine.new(self, transition_class: EventImportFileTransition)
46
35
  end
47
36
 
48
- def import_start
49
- executed_at = Time.zone.now
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
- self.reload
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 = 2
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")}, :as => :admin)
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
- num
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
- sm_fail!
89
+ transition_to!(:failed)
111
90
  raise e
112
91
  end
113
92
 
114
93
  def modify
115
- sm_start!
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 = 2
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
- sm_complete!
118
+ transition_to!(:completed)
140
119
  rescue => e
141
120
  self.error_message = "line #{row_num}: #{e.message}"
142
- sm_fail!
121
+ transition_to!(:failed)
143
122
  raise e
144
123
  end
145
124
 
146
125
  def remove
147
- sm_start!
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 = 2
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
- sm_complete!
139
+ transition_to!(:completed)
159
140
  rescue => e
160
141
  self.error_message = "line #{row_num}: #{e.message}"
161
- sm_fail!
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 open_import_file
175
- tempfile = Tempfile.new('event_import_file')
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
- if defined?(CharlockHolmes::EncodingDetector)
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")}, :as => :admin)
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>