Browse Source

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

Martin Edenhofer 9 years ago
parent
commit
e6ac1bef1d

+ 7 - 7
app/assets/javascripts/app/controllers/import_otrs.coffee

@@ -74,7 +74,7 @@ class Index extends App.ControllerContent
         id:          'import_otrs_url',
         type:        'POST',
         url:         @apiPath + '/import/otrs/url_check',
-        data:        JSON.stringify( { url:url} )
+        data:        JSON.stringify(url: url)
         processData: true,
         success:     (data, status, xhr) =>
 
@@ -118,8 +118,11 @@ class Index extends App.ControllerContent
       processData: true,
       success:     (data, status, xhr) =>
 
-        # validate form
-        console.log(data)
+        if data.setup_done
+          @Config.set('system_init_done', true)
+          @navigate '#'
+          return
+
         for key, item of data.data
           element = @$('.js-' + key.toLowerCase() )
           element.find('.js-done').text(item.done)
@@ -130,10 +133,6 @@ class Index extends App.ControllerContent
             element.addClass('is-done')
           else
             element.removeClass('is-done')
-
-#js-finished
-#@Config.set('system_init_done', true)
-
         @delay( @updateMigration, 5000 )
     )
 
@@ -142,5 +141,6 @@ App.Config.set( 'otrs', {
   image: 'otrs-logo.png'
   title: 'OTRS'
   name:  'OTRS'
+  class: 'js-otrs'
   url:   '#import/otrs'
 }, 'ImportPlugins' )

+ 145 - 0
app/assets/javascripts/app/controllers/import_zendesk.coffee

@@ -0,0 +1,145 @@
+class Index extends App.ControllerContent
+  className: 'getstarted fit'
+  elements:
+    '.input-feedback':                      'urlStatus'
+    '[data-target=otrs-start-migration]':   'nextStartMigration'
+    '.otrs-link-error':                     'linkErrorMessage'
+  events:
+    'click .js-otrs-link':       'showLink'
+    'click .js-download':        'startDownload'
+    'click .js-migration-start': 'startMigration'
+    'keyup #otrs-link':          'updateUrl'
+
+  constructor: ->
+    super
+
+    # set title
+    @title 'Import'
+
+    @fetch()
+
+  fetch: ->
+
+    # get data
+    @ajax(
+      id:          'getting_started',
+      type:        'GET',
+      url:         @apiPath + '/getting_started',
+      processData: true,
+      success:     (data, status, xhr) =>
+
+        # redirect to login if master user already exists
+        if @Config.get('system_init_done')
+          @navigate '#login'
+          return
+
+        # check if import is active
+        if data.import_mode == true && data.import_backend != 'otrs'
+          @navigate '#import/' + data.import_backend
+          return
+
+        # render page
+        @render()
+
+        if data.import_mode == true
+          @showImportState()
+          @updateMigration()
+    )
+
+  render: ->
+    @html App.view('import/otrs')()
+
+  startDownload: (e) =>
+    e.preventDefault()
+    @$('.js-otrs-link').removeClass('hide')
+
+  showLink: (e) =>
+    e.preventDefault()
+    @$('[data-slide=otrs-plugin]').toggleClass('hide')
+    @$('[data-slide=otrs-link]').toggleClass('hide')
+
+  showImportState: =>
+    @$('[data-slide=otrs-plugin]').addClass('hide')
+    @$('[data-slide=otrs-link]').addClass('hide')
+    @$('[data-slide=otrs-import]').removeClass('hide')
+
+  updateUrl: (e) =>
+    url = $(e.target).val()
+    @urlStatus.attr('data-state', 'loading')
+    @linkErrorMessage.text('')
+
+    # get data
+    callback = =>
+      @ajax(
+        id:          'import_otrs_url',
+        type:        'POST',
+        url:         @apiPath + '/import/otrs/url_check',
+        data:        JSON.stringify(url: url)
+        processData: true,
+        success:     (data, status, xhr) =>
+
+          # validate form
+          console.log(data)
+          if data.result is 'ok'
+            @urlStatus.attr('data-state', 'success')
+            @linkErrorMessage.text('')
+            @nextStartMigration.removeClass('hide')
+          else
+            @urlStatus.attr('data-state', 'error')
+            @linkErrorMessage.text( data.message_human || data.message )
+            @nextStartMigration.addClass('hide')
+
+      )
+    @delay( callback, 700, 'import_otrs_url' )
+
+  startMigration: (e) =>
+    e.preventDefault()
+    @showImportState()
+    @ajax(
+      id:          'import_start',
+      type:        'POST',
+      url:         @apiPath + '/import/otrs/import_start',
+      processData: true,
+      success:     (data, status, xhr) =>
+
+        # validate form
+        console.log(data)
+        if data.result is 'ok'
+          @delay( @updateMigration, 3000 )
+    )
+
+
+  updateMigration: =>
+    @showImportState()
+    @ajax(
+      id:          'import_status',
+      type:        'GET',
+      url:         @apiPath + '/import/otrs/import_status',
+      processData: true,
+      success:     (data, status, xhr) =>
+
+        if data.setup_done
+          @Config.set('system_init_done', true)
+          @navigate '#'
+          return
+
+        for key, item of data.data
+          element = @$('.js-' + key.toLowerCase() )
+          element.find('.js-done').text(item.done)
+          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, 5000 )
+    )
+
+App.Config.set( 'import/zendesk', Index, 'Routes' )
+App.Config.set( 'zendesk', {
+  title: 'Zendesk'
+  name:  'Zendesk'
+  class: 'js-zendesk'
+  url:   '#import/zendesk'
+}, 'ImportPlugins' )

+ 7 - 3
app/assets/javascripts/app/views/import/index.jst.eco

@@ -4,11 +4,15 @@
     <div class="wizard-slide vertical">
       <h2><%- @T('Import from') %></h2>
       <div class="wizard-body flex vertical justified">
-        <div class="import-source centered">
           <% for key, item of @items: %>
-            <a href="<%= item.url %>"><img class="logo" src="<%= @C('image_path') + '/' + item.image %>" alt="<%= item.name %>" height="37"></a>
+            <a href="<%= item.url %>" class="import-source centered <%= item.class %>">
+              <% if item.image: %>
+                <img class="logo" src="<%= @C('image_path') + '/' + item.image %>" alt="<%= item.name %>" height="37">
+              <% else: %>
+                <%= item.name %>
+              <% end %>
+            </a>
           <% end %>
-        </div>
       </div>
       <div class="wizard-controls horizontal center">
         <a class="btn btn--text btn--secondary" href="#getting_started"><%- @T('Go Back') %></a>

+ 1 - 1
app/assets/javascripts/app/views/import/otrs.jst.eco

@@ -48,7 +48,7 @@
             <td><span><%- @T('Configuration') %></span>
             <td class="progressTable-progressCell">
               <div class="horizontal center">
-                <div class="flex"><progress value="0.3"></progress></div><!-- if there is no max, the value is between 0..1 -->
+                <div class="flex"><progress value="1"></progress></div>
                 <%- @Icon('checkmark') %>
               </div>
           </tr>

+ 6 - 2
app/controllers/import_otrs_controller.rb

@@ -91,10 +91,14 @@ class ImportOtrsController < ApplicationController
   end
 
   def import_status
-    # return if setup_done_response
+    if !Setting.get('import_mode')
+      render json: {
+        setup_done: true,
+      }
+      return
+    end
 
     state = Import::OTRS.current_state
-
     render json: {
       data: state,
       result: 'in_progress',

+ 5 - 0
app/models/calendar.rb

@@ -27,6 +27,11 @@ returns calendar object
       ip = nil
     end
 
+    # prevent multible setups for same ip
+    cache = Cache.get('Calendar.init_setup.done')
+    return if cache && cache[:ip] == ip
+    Cache.write('Calendar.init_setup.done', { ip: ip }, { expires_in: 1.hour })
+
     # call for calendar suggestion
     calendar_details = Service::GeoCalendar.location(ip)
     return if !calendar_details

+ 5 - 7
lib/cache.rb

@@ -8,8 +8,8 @@ delete a cache
 
 =end
 
-  def self.delete( key )
-    Rails.cache.delete( key.to_s )
+  def self.delete(key)
+    Rails.cache.delete(key.to_s)
   end
 
 =begin
@@ -19,14 +19,12 @@ write a cache
   Cache.write(
     'some_key',
     { some: { data: { 'structure' } } },
-    {
-      expires_in: 24.hours, # optional, default 7 days
-    }
+    { expires_in: 24.hours, # optional, default 7 days }
   )
 
 =end
 
-  def self.write( key, data, params = {} )
+  def self.write(key, data, params = {})
     if !params[:expires_in]
       params[:expires_in] = 7.days
     end
@@ -45,7 +43,7 @@ get a cache
 
 =end
 
-  def self.get( key )
+  def self.get(key)
     Rails.cache.read(key.to_s)
   end
 

+ 2 - 2
lib/import/otrs.rb

@@ -409,8 +409,8 @@ module Import::OTRS
       threads[thread].join
     }
 
-    Setting.set( 'system_init_done', true )
-    #Setting.set( 'import_mode', false )
+    Setting.set('system_init_done', true)
+    Setting.set('import_mode', false)
 
     true
   end

+ 2 - 0
script/bootstrap.sh

@@ -4,6 +4,8 @@ bundle install
 
 rm -rf tmp/cache*
 
+export Z_LOCALES='en-us:de-de'
+
 rake db:drop
 rake db:create
 rake db:migrate