From ec6a4a199ccf485fc42085a6907434c833180efd Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Wed, 10 May 2017 16:47:31 +0200 Subject: [PATCH] Working on issue #981 - Added possibility to manually start LDAP import. --- .../app/controllers/_integration/ldap.coffee | 33 ++++++++++++++----- .../integration/ldap_last_import.jst.eco | 3 ++ .../integration/ldap_controller.rb | 7 ++-- 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/app/assets/javascripts/app/controllers/_integration/ldap.coffee b/app/assets/javascripts/app/controllers/_integration/ldap.coffee index c6ca0e2b1..cda274205 100644 --- a/app/assets/javascripts/app/controllers/_integration/ldap.coffee +++ b/app/assets/javascripts/app/controllers/_integration/ldap.coffee @@ -24,12 +24,26 @@ class Index extends App.ControllerIntegrationBase facility: 'ldap' ) + switch: => + super + active = @$('.js-switch input').prop('checked') + if active + @ajax( + id: 'jobs_config' + type: 'POST' + url: "#{@apiPath}/integration/ldap/job_start" + processData: true + success: (data, status, xhr) => + @render(true) + ) + class Form extends App.Controller elements: '.js-lastImport': 'lastImport' '.js-wizard': 'wizardButton' events: 'click .js-wizard': 'startWizard' + 'click .js-start-sync': 'startSync' constructor: -> super @@ -42,14 +56,7 @@ class Form extends App.Controller setConfig: (value) => App.Setting.set('ldap_config', value, {notify: true}) - @ajax( - id: 'jobs_config' - type: 'POST' - url: "#{@apiPath}/integration/ldap/job_start" - processData: true - success: (data, status, xhr) => - @render(true) - ) + @startSync() render: (top = false) => @config = @currentConfig() @@ -69,6 +76,16 @@ class Form extends App.Controller @scrollToIfNeeded($('.content.active .page-header')) @delay(a, 500) + startSync: => + @ajax( + id: 'jobs_config' + type: 'POST' + url: "#{@apiPath}/integration/ldap/job_start" + processData: true + success: (data, status, xhr) => + @render(true) + ) + startWizard: (e) => e.preventDefault() new ConnectionWizard( diff --git a/app/assets/javascripts/app/views/integration/ldap_last_import.jst.eco b/app/assets/javascripts/app/views/integration/ldap_last_import.jst.eco index 163f59277..2fb84f854 100644 --- a/app/assets/javascripts/app/views/integration/ldap_last_import.jst.eco +++ b/app/assets/javascripts/app/views/integration/ldap_last_import.jst.eco @@ -45,5 +45,8 @@ <% end %> <% end %> + <% if @job.finished_at: %> + + <% end %> <% end %> diff --git a/app/controllers/integration/ldap_controller.rb b/app/controllers/integration/ldap_controller.rb index 0fff21396..ff91b292f 100644 --- a/app/controllers/integration/ldap_controller.rb +++ b/app/controllers/integration/ldap_controller.rb @@ -71,8 +71,11 @@ class Integration::LdapController < ApplicationController end def job_start_create - job = ImportJob.create(name: 'Import::Ldap', payload: Setting.get('ldap_config')) - job.delay.start + backend = 'Import::Ldap' + if !ImportJob.exists?(name: backend, finished_at: nil) + job = ImportJob.create(name: backend, payload: Setting.get('ldap_config')) + job.delay.start + end render json: { result: 'ok', }