aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/line_referentials_controller.rb7
-rw-r--r--app/controllers/stop_area_referentials_controller.rb7
-rw-r--r--app/models/line_referential.rb4
-rw-r--r--app/models/line_referential_sync.rb4
-rw-r--r--app/models/stop_area_referential.rb3
-rw-r--r--app/models/stop_area_referential_sync.rb4
-rw-r--r--app/views/line_referentials/show.html.slim2
-rw-r--r--app/views/stop_area_referentials/show.html.slim5
-rw-r--r--config/locales/line_referentials.en.yml7
-rw-r--r--config/locales/line_referentials.fr.yml6
-rw-r--r--config/locales/stop_area_referentials.en.yml5
-rw-r--r--config/locales/stop_area_referentials.fr.yml2
-rw-r--r--config/routes.rb2
13 files changed, 42 insertions, 16 deletions
diff --git a/app/controllers/line_referentials_controller.rb b/app/controllers/line_referentials_controller.rb
index fc4ab3cf5..4cd11b31b 100644
--- a/app/controllers/line_referentials_controller.rb
+++ b/app/controllers/line_referentials_controller.rb
@@ -12,6 +12,13 @@ class LineReferentialsController < BreadcrumbController
redirect_to resource
end
+ # Todo
+ # For testing, remove me
+ def cancel_sync
+ resource.last_sync.destroy
+ redirect_to resource
+ end
+
protected
def begin_of_chain
diff --git a/app/controllers/stop_area_referentials_controller.rb b/app/controllers/stop_area_referentials_controller.rb
index d639d1bcf..5d66c8e90 100644
--- a/app/controllers/stop_area_referentials_controller.rb
+++ b/app/controllers/stop_area_referentials_controller.rb
@@ -11,6 +11,13 @@ class StopAreaReferentialsController < BreadcrumbController
redirect_to resource
end
+ # Todo
+ # For testing, remove me
+ def cancel_sync
+ resource.last_sync.destroy
+ redirect_to resource
+ end
+
protected
def begin_of_chain
diff --git a/app/models/line_referential.rb b/app/models/line_referential.rb
index f33934dfc..fcee9c5c9 100644
--- a/app/models/line_referential.rb
+++ b/app/models/line_referential.rb
@@ -22,4 +22,8 @@ class LineReferential < ActiveRecord::Base
def operating_lines
lines.where(deactivated: false)
end
+
+ def last_sync
+ line_referential_syncs.last
+ end
end
diff --git a/app/models/line_referential_sync.rb b/app/models/line_referential_sync.rb
index 03fea6a97..7d0c1ba1f 100644
--- a/app/models/line_referential_sync.rb
+++ b/app/models/line_referential_sync.rb
@@ -6,6 +6,10 @@ class LineReferentialSync < ActiveRecord::Base
after_commit :perform_sync, :on => :create
validate :multiple_process_validation, :on => :create
+ def can_be_canceled?
+ [:new, :pending].include? self.status.to_sym
+ end
+
private
def perform_sync
create_sync_message :info, :new
diff --git a/app/models/stop_area_referential.rb b/app/models/stop_area_referential.rb
index 1de218793..44ef94277 100644
--- a/app/models/stop_area_referential.rb
+++ b/app/models/stop_area_referential.rb
@@ -10,4 +10,7 @@ class StopAreaReferential < ActiveRecord::Base
stop_area_referential_memberships.build attributes
end
+ def last_sync
+ stop_area_referential_syncs.last
+ end
end
diff --git a/app/models/stop_area_referential_sync.rb b/app/models/stop_area_referential_sync.rb
index ad99dbb8c..840a159b7 100644
--- a/app/models/stop_area_referential_sync.rb
+++ b/app/models/stop_area_referential_sync.rb
@@ -6,6 +6,10 @@ class StopAreaReferentialSync < ActiveRecord::Base
after_commit :perform_sync, :on => :create
validate :multiple_process_validation, :on => :create
+ def can_be_canceled?
+ [:new, :pending].include? self.status.to_sym
+ end
+
private
def perform_sync
create_sync_message :info, :new
diff --git a/app/views/line_referentials/show.html.slim b/app/views/line_referentials/show.html.slim
index f4328bfb5..793acc7bb 100644
--- a/app/views/line_referentials/show.html.slim
+++ b/app/views/line_referentials/show.html.slim
@@ -39,3 +39,5 @@
ul.actions
li = link_to t('line_referentials.actions.edit'), edit_line_referential_path(@line_referential), class: 'edit'
li = link_to t('line_referentials.actions.sync'), sync_line_referential_path(@line_referential), class: 'sync', method: :post
+ - if @line_referential.last_sync && @line_referential.last_sync.can_be_canceled?
+ li = link_to t('line_referentials.actions.cancel_sync'), cancel_sync_line_referential_path(@line_referential), class: 'cancel_sync', method: :post
diff --git a/app/views/stop_area_referentials/show.html.slim b/app/views/stop_area_referentials/show.html.slim
index c9a1b50fa..44ed6e4b2 100644
--- a/app/views/stop_area_referentials/show.html.slim
+++ b/app/views/stop_area_referentials/show.html.slim
@@ -13,7 +13,8 @@
h3 Historique des synchronisations
ul.list-group width="75%"
- - @stop_area_referential.stop_area_referential_syncs.last.stop_area_referential_sync_messages.last.tap do |log|
+ - if @stop_area_referential.last_sync.stop_area_referential_sync_messages.empty?
+ - @stop_area_referential.last_sync.stop_area_referential_sync_messages.last.tap do |log|
li
= log.criticity
br
@@ -25,3 +26,5 @@
- 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
+ - if @stop_area_referential.last_sync
+ li = link_to t('stop_area_referentials.actions.cancel_sync'), cancel_sync_stop_area_referential_path(@stop_area_referential), class: 'cancel_sync', method: :post
diff --git a/config/locales/line_referentials.en.yml b/config/locales/line_referentials.en.yml
index fb66cf0c4..4c30d90e3 100644
--- a/config/locales/line_referentials.en.yml
+++ b/config/locales/line_referentials.en.yml
@@ -3,14 +3,9 @@ en:
actions:
edit: "Edit this referential"
sync: "Launch a new codifligne synchronization"
+ cancel_sync: "Cancel codifligne synchronization"
edit:
title: "Edit %{line_referential} referential"
- synchronization:
- codifligne:
- 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}."
activerecord:
models:
line_referential:
diff --git a/config/locales/line_referentials.fr.yml b/config/locales/line_referentials.fr.yml
index 2f9c14866..9e885aa52 100644
--- a/config/locales/line_referentials.fr.yml
+++ b/config/locales/line_referentials.fr.yml
@@ -3,13 +3,9 @@ fr:
actions:
edit: "Modifier ce référentiel"
sync: "Lancer une synchronisation codifligne"
+ cancel_sync: "Annuler la synchronisation codifligne"
edit:
title: "Modifier le référentiel %{line_referential}"
- synchronization:
- 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}."
activerecord:
models:
line_referential:
diff --git a/config/locales/stop_area_referentials.en.yml b/config/locales/stop_area_referentials.en.yml
index db290430c..057b32c7c 100644
--- a/config/locales/stop_area_referentials.en.yml
+++ b/config/locales/stop_area_referentials.en.yml
@@ -2,7 +2,4 @@ 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."
- failure: "Synchronization interrupted after %{time} seconds."
+ cancel_sync: "Cancel reflex synchronization"
diff --git a/config/locales/stop_area_referentials.fr.yml b/config/locales/stop_area_referentials.fr.yml
index d0c96cd80..b56e77f60 100644
--- a/config/locales/stop_area_referentials.fr.yml
+++ b/config/locales/stop_area_referentials.fr.yml
@@ -2,3 +2,5 @@ fr:
stop_area_referentials:
actions:
sync: "Lancer une synchronisation reflex"
+ cancel_sync: "Anuller la synchronization reflex"
+
diff --git a/config/routes.rb b/config/routes.rb
index f89b5c630..701e8491c 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -55,11 +55,13 @@ ChouetteIhm::Application.routes.draw do
resources :stop_area_referentials, :only => [:show] do
post :sync, on: :member
+ post :cancel_sync, on: :member
resources :stop_areas
end
resources :line_referentials, :only => [:show, :edit, :update] do
post :sync, on: :member
+ post :cancel_sync, on: :member
resources :lines
resources :group_of_lines
resources :companies