diff options
| -rw-r--r-- | app/controllers/stop_area_referentials_controller.rb | 9 | ||||
| -rw-r--r-- | app/models/stop_area_referential.rb | 2 | ||||
| -rw-r--r-- | app/views/stop_area_referentials/show.html.slim | 21 | ||||
| -rw-r--r-- | config/locales/stop_area_referential_syncs.en.yml | 18 | ||||
| -rw-r--r-- | config/locales/stop_area_referential_syncs.fr.yml | 16 | ||||
| -rw-r--r-- | config/locales/stop_area_referentials.en.yml | 3 | ||||
| -rw-r--r-- | config/locales/stop_area_referentials.fr.yml | 3 | ||||
| -rw-r--r-- | config/routes.rb | 1 | ||||
| -rw-r--r-- | lib/tasks/codifligne.rake | 3 | ||||
| -rw-r--r-- | lib/tasks/reflex.rake | 6 | ||||
| -rw-r--r-- | spec/models/line_referential_spec.rb | 1 | ||||
| -rw-r--r-- | spec/models/stop_area_referential_spec.rb | 9 |
12 files changed, 80 insertions, 12 deletions
diff --git a/app/controllers/stop_area_referentials_controller.rb b/app/controllers/stop_area_referentials_controller.rb index 3abd53892..d639d1bcf 100644 --- a/app/controllers/stop_area_referentials_controller.rb +++ b/app/controllers/stop_area_referentials_controller.rb @@ -1,6 +1,15 @@ class StopAreaReferentialsController < BreadcrumbController defaults :resource_class => StopAreaReferential + def sync + @sync = resource.stop_area_referential_syncs.build + if @sync.save + flash[:notice] = t('notice.stop_area_referential_sync.created') + else + flash[:error] = @sync.errors.full_messages.to_sentence + end + redirect_to resource + end protected diff --git a/app/models/stop_area_referential.rb b/app/models/stop_area_referential.rb index 58e0c559c..1de218793 100644 --- a/app/models/stop_area_referential.rb +++ b/app/models/stop_area_referential.rb @@ -3,7 +3,7 @@ class StopAreaReferential < ActiveRecord::Base has_many :organisations, through: :stop_area_referential_memberships has_many :stop_areas, class_name: 'Chouette::StopArea' - has_one :stop_area_referential_sync + has_many :stop_area_referential_syncs def add_member(organisation, options = {}) attributes = options.merge organisation: organisation diff --git a/app/views/stop_area_referentials/show.html.slim b/app/views/stop_area_referentials/show.html.slim index 761393013..80f98af61 100644 --- a/app/views/stop_area_referentials/show.html.slim +++ b/app/views/stop_area_referentials/show.html.slim @@ -9,12 +9,21 @@ span.badge = @stop_area_referential.stop_areas.size = link_to Referential.human_attribute_name("stop_areas"), stop_area_referential_stop_areas_path(@stop_area_referential) -/ - unless @stop_area_referential.stop_area_referential_sync.stop_area_sync_operations.empty? -/ h3 Historique des synchronisations - -/ ul.list-group width="75%" -/ - @stop_area_referential.stop_area_referential_sync.stop_area_sync_operations.each do |sync| -/ li = "#{sync.created_at.to_formatted_s(:short)} - #{sync.message}" +- unless @stop_area_referential.stop_area_referential_syncs.empty? + h3 Historique des synchronisations + ul.list-group width="75%" + - @stop_area_referential.stop_area_referential_syncs.each do |sync| + - sync.stop_area_referential_sync_messages.each do |log| + li + = log.criticity + br + = log.created_at + br + = t("stop_area_referential_sync.synchronization.message.#{log.message_key}", log.message_attributs.symbolize_keys!) + hr + end + end - content_for :sidebar do ul.actions + li = link_to t('stop_area_referentials.actions.sync'), sync_stop_area_referential_path(@stop_area_referential), class: 'sync', method: :post diff --git a/config/locales/stop_area_referential_syncs.en.yml b/config/locales/stop_area_referential_syncs.en.yml new file mode 100644 index 000000000..c07573b9c --- /dev/null +++ b/config/locales/stop_area_referential_syncs.en.yml @@ -0,0 +1,18 @@ +en: + activerecord: + errors: + models: + stop_area_referential_sync: + attributes: + base: + multiple_process: 'There is already an synchronisation in progress' + stop_area_referential_sync: + synchronization: + message: + pending: "Synchronization pending" + successful: "Synchronization successful after %{processing_time} with %{imported} objects. %{deleted} objects were deleted.." + failed: "Synchronization failed after %{processing_time} with error: %{error}." + notice: + stop_area_referential_sync: + created: 'Your synchronisation request has been created' + diff --git a/config/locales/stop_area_referential_syncs.fr.yml b/config/locales/stop_area_referential_syncs.fr.yml new file mode 100644 index 000000000..4a5ac616c --- /dev/null +++ b/config/locales/stop_area_referential_syncs.fr.yml @@ -0,0 +1,16 @@ +fr: + activerecord: + errors: + models: + stop_area_referential_sync: + attributes: + base: + multiple_process: 'Il y a déja une synchronisation en cours de traitement' + stop_area_referential_sync: + message: + pending: "Synchronisation en attente" + successful: "Synchronisation réussie après %{processing_time} secondes avec %{imported} éléments importés. %{deleted} éléments ont été supprimés." + failed: "Synchronisation interrompue après %{processing_time} secondes avec l'erreur : %{error}." + notice: + stop_area_referential_sync: + created: 'Votre demande de synchronisation a bien été créée' diff --git a/config/locales/stop_area_referentials.en.yml b/config/locales/stop_area_referentials.en.yml index 9ac0daede..db290430c 100644 --- a/config/locales/stop_area_referentials.en.yml +++ b/config/locales/stop_area_referentials.en.yml @@ -1,4 +1,7 @@ en: + stop_area_referentials: + actions: + sync: "Launch a new reflex synchronization" synchronization: reflex: message: "Synchronization successful in %{time} seconds with %{imported} objects from Reflex. %{deleted} objects were deleted." diff --git a/config/locales/stop_area_referentials.fr.yml b/config/locales/stop_area_referentials.fr.yml index 89254384f..543eb5e95 100644 --- a/config/locales/stop_area_referentials.fr.yml +++ b/config/locales/stop_area_referentials.fr.yml @@ -1,4 +1,7 @@ fr: + stop_area_referentials: + actions: + sync: "Lancer une synchronisation reflex" synchronization: reflex: message: diff --git a/config/routes.rb b/config/routes.rb index 4a2665e00..9bf7dcc2e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -52,6 +52,7 @@ ChouetteIhm::Application.routes.draw do end resources :stop_area_referentials, :only => [:show] do + post :sync, on: :member resources :stop_areas end diff --git a/lib/tasks/codifligne.rake b/lib/tasks/codifligne.rake index 4a108f789..dd5e99370 100644 --- a/lib/tasks/codifligne.rake +++ b/lib/tasks/codifligne.rake @@ -1,8 +1,7 @@ namespace :codifligne do desc "Sync lines, companies, networks, and group of lines from codifligne" task sync: :environment do - lref = LineReferential.find_by(name: 'CodifLigne') - sync = lref.line_referential_syncs.build + sync = LineReferential.find_by(name: 'CodifLigne').line_referential_syncs.build raise "Codifligne:sync aborted - There is already an synchronisation in progress" unless sync.valid? sync.save if sync.valid? end diff --git a/lib/tasks/reflex.rake b/lib/tasks/reflex.rake index 0020f1b60..67496cee0 100644 --- a/lib/tasks/reflex.rake +++ b/lib/tasks/reflex.rake @@ -1,8 +1,8 @@ namespace :reflex do desc "Sync data from Reflex api" task sync: :environment do - start = Time.now - Stif::ReflexSynchronization.synchronize - Rails.logger.debug "Reflex:sync done in #{Time.now - start} seconds !" + sync = StopAreaReferential.find_by(name: 'Reflex').stop_area_referential_syncs.build + raise "reflex:sync aborted - There is already an synchronisation in progress" unless sync.valid? + sync.save if sync.valid? end end diff --git a/spec/models/line_referential_spec.rb b/spec/models/line_referential_spec.rb index 677d61f77..8b06f07ad 100644 --- a/spec/models/line_referential_spec.rb +++ b/spec/models/line_referential_spec.rb @@ -6,5 +6,6 @@ RSpec.describe LineReferential, :type => :model do end it { should validate_presence_of(:name) } + it { is_expected.to have_many(:line_referential_syncs) } it { should validate_presence_of(:sync_interval) } end diff --git a/spec/models/stop_area_referential_spec.rb b/spec/models/stop_area_referential_spec.rb new file mode 100644 index 000000000..87b99b18b --- /dev/null +++ b/spec/models/stop_area_referential_spec.rb @@ -0,0 +1,9 @@ +require 'rails_helper' + +RSpec.describe StopAreaReferential, :type => :model do + it 'should have a valid factory' do + expect(FactoryGirl.build(:stop_area_referential)).to be_valid + end + + it { is_expected.to have_many(:stop_area_referential_syncs) } +end |
