diff options
| -rw-r--r-- | app/controllers/line_referentials_controller.rb | 10 | ||||
| -rw-r--r-- | app/views/line_referentials/show.html.slim | 3 | ||||
| -rw-r--r-- | config/locales/line_referential_syncs.en.yml | 12 | ||||
| -rw-r--r-- | config/locales/line_referential_syncs.fr.yml | 11 | ||||
| -rw-r--r-- | config/locales/line_referentials.en.yml | 1 | ||||
| -rw-r--r-- | config/locales/line_referentials.fr.yml | 1 | ||||
| -rw-r--r-- | config/routes.rb | 1 | ||||
| -rw-r--r-- | lib/tasks/codifligne.rake | 8 | 
8 files changed, 42 insertions, 5 deletions
| diff --git a/app/controllers/line_referentials_controller.rb b/app/controllers/line_referentials_controller.rb index e28019eed..fc4ab3cf5 100644 --- a/app/controllers/line_referentials_controller.rb +++ b/app/controllers/line_referentials_controller.rb @@ -2,6 +2,16 @@ class LineReferentialsController < BreadcrumbController    defaults :resource_class => LineReferential +  def sync +    @sync = resource.line_referential_syncs.build +    if @sync.save +      flash[:notice] = t('notice.line_referential_sync.created') +    else +      flash[:error] = @sync.errors.full_messages.to_sentence +    end +    redirect_to resource +  end +    protected    def begin_of_chain diff --git a/app/views/line_referentials/show.html.slim b/app/views/line_referentials/show.html.slim index a3dcdf192..ee78cd378 100644 --- a/app/views/line_referentials/show.html.slim +++ b/app/views/line_referentials/show.html.slim @@ -39,4 +39,5 @@  - content_for :sidebar do    ul.actions -    = link_to t('line_referentials.actions.edit'), edit_line_referential_path(@line_referential), class: 'edit' +    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 diff --git a/config/locales/line_referential_syncs.en.yml b/config/locales/line_referential_syncs.en.yml new file mode 100644 index 000000000..c690a4369 --- /dev/null +++ b/config/locales/line_referential_syncs.en.yml @@ -0,0 +1,12 @@ +en: +  activerecord: +    errors: +      models: +        line_referential_sync: +          attributes: +            base: +              multiple_process: 'There is already an synchronisation in progress' +  notice: +    line_referential_sync: +      created: 'Your synchronisation request has been created' + diff --git a/config/locales/line_referential_syncs.fr.yml b/config/locales/line_referential_syncs.fr.yml new file mode 100644 index 000000000..e688d0b0a --- /dev/null +++ b/config/locales/line_referential_syncs.fr.yml @@ -0,0 +1,11 @@ +fr: +  activerecord: +    errors: +      models: +        line_referential_sync: +          attributes: +            base: +              multiple_process: 'Il y a déja une synchronisation en cours de traitement' +  notice: +    line_referential_sync: +      created: 'Votre demande de synchronisation a bien été créée' diff --git a/config/locales/line_referentials.en.yml b/config/locales/line_referentials.en.yml index 443a9a90d..fb66cf0c4 100644 --- a/config/locales/line_referentials.en.yml +++ b/config/locales/line_referentials.en.yml @@ -2,6 +2,7 @@ en:    line_referentials:      actions:        edit: "Edit this referential" +      sync: "Launch a new codifligne synchronization"      edit:        title: "Edit %{line_referential} referential"    synchronization: diff --git a/config/locales/line_referentials.fr.yml b/config/locales/line_referentials.fr.yml index da89fef63..2f9c14866 100644 --- a/config/locales/line_referentials.fr.yml +++ b/config/locales/line_referentials.fr.yml @@ -2,6 +2,7 @@ fr:    line_referentials:      actions:        edit: "Modifier ce référentiel" +      sync: "Lancer une synchronisation codifligne"      edit:        title: "Modifier le référentiel %{line_referential}"      synchronization: diff --git a/config/routes.rb b/config/routes.rb index 1d9354991..4a2665e00 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -56,6 +56,7 @@ ChouetteIhm::Application.routes.draw do    end    resources :line_referentials, :only => [:show, :edit, :update] do +    post :sync, on: :member      resources :lines      resources :group_of_lines      resources :companies diff --git a/lib/tasks/codifligne.rake b/lib/tasks/codifligne.rake index f306ee484..4a108f789 100644 --- a/lib/tasks/codifligne.rake +++ b/lib/tasks/codifligne.rake @@ -1,9 +1,9 @@  namespace :codifligne do    desc "Sync lines, companies, networks, and group of lines from codifligne"    task sync: :environment  do -    lref      = LineReferential.find_by(name: 'CodifLigne') -    lref_sync = LineReferentialSync.create(line_referential: lref) -    raise "Codifligne:sync aborted - an sync is already running" unless lref_sync.valid? -    lref_sync.save if lref_sync.valid? +    lref = LineReferential.find_by(name: 'CodifLigne') +    sync = lref.line_referential_syncs.build +    raise "Codifligne:sync aborted - There is already an synchronisation in progress" unless sync.valid? +    sync.save if sync.valid?    end  end | 
