Merge branch 'develop' of github.com:martini/zammad into develop

This commit is contained in:
Martin Edenhofer 2016-01-13 22:24:11 +01:00
commit ed5e0ff4d4
9 changed files with 179 additions and 65 deletions

View file

@ -601,6 +601,9 @@ class ChatWindow extends App.Controller
@el.addClass('is-offline') @el.addClass('is-offline')
@input.attr('disabled', true) @input.attr('disabled', true)
# add footer with create ticket button
@body.append App.view('customer_chat/chat_footer')()
maybeAddTimestamp: -> maybeAddTimestamp: ->
timestamp = Date.now() timestamp = Date.now()

View file

@ -79,7 +79,6 @@ class Index extends App.ControllerContent
success: (data, status, xhr) => success: (data, status, xhr) =>
# validate form # validate form
console.log(data)
if data.result is 'ok' if data.result is 'ok'
@urlStatus.attr('data-state', 'success') @urlStatus.attr('data-state', 'success')
@linkErrorMessage.text('') @linkErrorMessage.text('')
@ -90,7 +89,7 @@ class Index extends App.ControllerContent
@nextStartMigration.addClass('hide') @nextStartMigration.addClass('hide')
) )
@delay( callback, 700, 'import_otrs_url' ) @delay(callback, 700, 'import_otrs_url')
startMigration: (e) => startMigration: (e) =>
e.preventDefault() e.preventDefault()
@ -101,11 +100,8 @@ class Index extends App.ControllerContent
url: @apiPath + '/import/otrs/import_start', url: @apiPath + '/import/otrs/import_start',
processData: true, processData: true,
success: (data, status, xhr) => success: (data, status, xhr) =>
# validate form
console.log(data)
if data.result is 'ok' if data.result is 'ok'
@delay( @updateMigration, 3000 ) @delay(@updateMigration, 3000)
) )
@ -118,22 +114,28 @@ class Index extends App.ControllerContent
processData: true, processData: true,
success: (data, status, xhr) => success: (data, status, xhr) =>
if data.setup_done if data.result is 'import_done'
@Config.set('system_init_done', true) window.location.reload()
@navigate '#'
return return
for key, item of data.data if data.result is 'error'
element = @$('.js-' + key.toLowerCase() ) @$('.js-error').removeClass('hide')
element.find('.js-done').text(item.done) @$('.js-error').html(App.i18n.translateContent(data.message))
element.find('.js-total').text(item.total) else
element.find('progress').attr('max', item.total ) @$('.js-error').addClass('hide')
element.find('progress').attr('value', item.done )
if item.total <= item.done if data.result is 'in_progress'
element.addClass('is-done') for key, item of data.data
else element = @$('.js-' + key.toLowerCase() )
element.removeClass('is-done') element.find('.js-done').text(item.done)
@delay( @updateMigration, 5000 ) element.find('.js-total').text(item.total)
element.find('progress').attr('max', item.total )
element.find('progress').attr('value', item.done )
if item.total <= item.done
element.addClass('is-done')
else
element.removeClass('is-done')
@delay(@updateMigration, 6500)
) )
App.Config.set( 'import/otrs', Index, 'Routes' ) App.Config.set( 'import/otrs', Index, 'Routes' )

View file

@ -0,0 +1,3 @@
<div class="chat-footer">
<div class="btn btn--primary js-createTicket">Turn chat into ticket</div>
</div>

View file

@ -41,6 +41,8 @@
<div class="wizard-slide vertical hide" data-slide="otrs-import"> <div class="wizard-slide vertical hide" data-slide="otrs-import">
<h2><%- @T('OTRS Migration') %></h2> <h2><%- @T('OTRS Migration') %></h2>
<div class="alert alert--danger hide js-error" role="alert"></div>
<div class="wizard-body flex vertical justified"> <div class="wizard-body flex vertical justified">
<table class="progressTable"> <table class="progressTable">
<tr class="js-config"> <tr class="js-config">

View file

@ -7275,7 +7275,6 @@ output {
} }
&.is-offline { &.is-offline {
.chat-body-holder,
.chat-controls { .chat-controls {
opacity: 0.5; opacity: 0.5;
} }
@ -7286,7 +7285,7 @@ output {
background: hsl(210,8%,95%); background: hsl(210,8%,95%);
border: 1px solid hsl(0,0%,91%); border: 1px solid hsl(0,0%,91%);
border-radius: 3px 3px 0 0; border-radius: 3px 3px 0 0;
height: 37px; height: 43px;
line-height: 13px; line-height: 13px;
flex-shrink: 0; flex-shrink: 0;
display: flex; display: flex;
@ -7336,7 +7335,7 @@ output {
.chat-disconnect, .chat-disconnect,
.chat-close { .chat-close {
cursor: pointer; cursor: pointer;
padding: 0 4px; padding: 10px;
.btn { .btn {
min-width: 80px; min-width: 80px;
@ -7437,6 +7436,15 @@ output {
67% { opacity: 1; transform: scale(1); } 67% { opacity: 1; transform: scale(1); }
} }
.chat-footer {
border-top: 1px solid hsl(0,0%,93%);
padding: 10px;
display: flex;
justify-content: center;
align-self: stretch;
margin: 0 -10px;
}
.chat-controls { .chat-controls {
display: flex; display: flex;
align-items: flex-start; align-items: flex-start;

View file

@ -22,9 +22,7 @@ class ImportOtrsController < ApplicationController
'Connection refused' => 'Connection refused!', 'Connection refused' => 'Connection refused!',
} }
url_parts = params[:url].split(';') response = UserAgent.request( params[:url] )
response = UserAgent.request( url_parts[0] )
if !response.success? && response.code.to_s !~ /^40.$/ if !response.success? && response.code.to_s !~ /^40.$/
message_human = '' message_human = ''
@ -44,16 +42,27 @@ class ImportOtrsController < ApplicationController
result = {} result = {}
if response.body =~ /zammad migrator/ if response.body =~ /zammad migrator/
key_parts = url_parts[1].split('=') migrator_response = JSON.parse(response.body)
Setting.set('import_backend', 'otrs') if migrator_response['Success'] == 1
Setting.set('import_otrs_endpoint', url_parts[0])
Setting.set('import_otrs_endpoint_key', key_parts[1])
result = { url_parts = params[:url].split(';')
result: 'ok', key_parts = url_parts[1].split('=')
url: params[:url],
} Setting.set('import_backend', 'otrs')
Setting.set('import_otrs_endpoint', url_parts[0])
Setting.set('import_otrs_endpoint_key', key_parts[1])
result = {
result: 'ok',
url: params[:url],
}
else
result = {
result: 'invalid',
message_human: migrator_response['Error']
}
end
elsif response.body =~ /(otrs\sag|otrs\.com|otrs\.org)/i elsif response.body =~ /(otrs\sag|otrs\.com|otrs\.org)/i
result = { result = {
result: 'invalid', result: 'invalid',
@ -71,7 +80,6 @@ class ImportOtrsController < ApplicationController
def import_start def import_start
return if setup_done_response return if setup_done_response
Setting.set('import_mode', true) Setting.set('import_mode', true)
welcome = Import::OTRS.connection_test welcome = Import::OTRS.connection_test
if !welcome if !welcome
@ -83,7 +91,7 @@ class ImportOtrsController < ApplicationController
end end
# start migration # start migration
Import::OTRS.delay.start Import::OTRS.delay.start_bg
render json: { render json: {
result: 'ok', result: 'ok',
@ -91,18 +99,11 @@ class ImportOtrsController < ApplicationController
end end
def import_status def import_status
if !Setting.get('import_mode') result = Import::OTRS.status_bg
render json: { if result[:result] == 'import_done'
setup_done: true, Setting.reload
}
return
end end
render json: result
state = Import::OTRS.current_state
render json: {
data: state,
result: 'in_progress',
}
end end
private private

View file

@ -77,13 +77,25 @@ reset config setting to default
@@current[:settings_config][name] @@current[:settings_config][name]
end end
=begin
reload config settings
Setting.reload
=end
def self.reload
load(true)
end
private private
# load values and cache them # load values and cache them
def self.load def self.load(force = false)
# check if config is already generated # check if config is already generated
if @@current[:settings_config] if !force && @@current[:settings_config]
return false if cache_valid? return false if cache_valid?
end end

View file

@ -214,7 +214,7 @@ module Import::OTRS
=begin =begin
get object statistic from server ans save it in cache get object statistic from remote server ans save it in cache
result = statistic('Subaction=List') result = statistic('Subaction=List')
@ -409,10 +409,77 @@ module Import::OTRS
threads[thread].join threads[thread].join
} }
true
end
=begin
start import in background
Import::OTRS.start_bg
=end
def self.start_bg
Setting.reload
Import::OTRS.connection_test
# start thread to observe current state
status_update_thread = Thread.new {
loop do
result = {
data: current_state,
result: 'in_progress',
}
Cache.write('import:state', result, expires_in: 10.minutes)
sleep 8
end
}
sleep 2
# start thread to import data
begin
import_thread = Thread.new {
Import::OTRS.start
}
rescue => e
status_update_thread.exit
status_update_thread.join
Rails.logger.error e.message
Rails.logger.error e.backtrace.inspect
result = {
message: e.message,
result: 'error',
}
Cache.write('import:state', result, expires_in: 10.hours)
return false
end
import_thread.join
status_update_thread.exit
status_update_thread.join
result = {
result: 'import_done',
}
Cache.write('import:state', result, expires_in: 10.hours)
Setting.set('system_init_done', true) Setting.set('system_init_done', true)
Setting.set('import_mode', false) Setting.set('import_mode', false)
end
true =begin
get import state from background process
result = Import::OTRS.status_bg
=end
def self.status_bg
state = Cache.get('import:state')
return state if state
{
message: 'not running',
}
end end
def self.diff_worker def self.diff_worker

View file

@ -11,8 +11,6 @@ class OtrsImportBrowserTest < TestCase
fail "ERROR: Need IMPORT_BT_OTRS_ENDPOINT_KEY - hint IMPORT_BT_OTRS_ENDPOINT_KEY='01234567899876543210'" fail "ERROR: Need IMPORT_BT_OTRS_ENDPOINT_KEY - hint IMPORT_BT_OTRS_ENDPOINT_KEY='01234567899876543210'"
end end
import_url = "#{ENV['IMPORT_BT_OTRS_ENDPOINT']};Key=#{ENV['IMPORT_BT_OTRS_ENDPOINT_KEY']}"
@browser = browser_instance @browser = browser_instance
location(url: browser_url) location(url: browser_url)
@ -20,26 +18,44 @@ class OtrsImportBrowserTest < TestCase
click(css: 'a[href="#import/otrs"]') click(css: 'a[href="#import/otrs"]')
click(css: '.js-download')
click(css: '.js-otrs-link')
invalid_key_url = "#{ENV['IMPORT_BT_OTRS_ENDPOINT']};Key=31337"
set(
css: '#otrs-link',
value: invalid_key_url
)
sleep 5
watch_for(
css: '.otrs-link-error',
value: 'Invalid API key.',
)
import_url = "#{ENV['IMPORT_BT_OTRS_ENDPOINT']};Key=#{ENV['IMPORT_BT_OTRS_ENDPOINT_KEY']}"
set( set(
css: '#otrs-link', css: '#otrs-link',
value: import_url value: import_url
) )
watch_for( sleep 5
css: 'body',
value: 'xxxx', watch_for_disappear(
timeout: 10, css: '.otrs-link-error',
value: 'Invalid API key.',
) )
# click import click(css: '.js-migration-start')
# click otrs watch_for(
css: 'body',
# enter otrs url + key value: 'login',
timeout: 300,
# watch for import start )
# watch for import end
end end