Browse Source

Some improvements to admin translation.

Martin Edenhofer 9 years ago
parent
commit
9b12c6cc7b

+ 42 - 0
app/assets/javascripts/app/controllers/_application_controller_generic.js.coffee

@@ -228,6 +228,48 @@ class App.ControllerGenericDescription extends App.ControllerModal
     e.preventDefault()
     @hide()
 
+class App.ControllerModalLoading extends App.Controller
+  className: 'modal fade'
+
+  constructor: ->
+    super
+
+    if @container
+      @el.addClass('modal--local')
+
+    @render()
+
+    @el.modal
+      keyboard:  false
+      show:      true
+      backdrop:  false
+      container: @container
+
+  render: ->
+    @html App.view('generic/modal_loader')(
+      head: @head
+      message: App.i18n.translateContent(@message)
+    )
+
+  update: (message, translate = true) =>
+    if translate
+      message = App.i18n.translateContent(message)
+    @$('.js-loading').html(message)
+
+  hideIcon: =>
+    @$('.js-loadingIcon').addClass('hide')
+
+  showIcon: =>
+    @$('.js-loadingIcon').removeClass('hide')
+
+  hide: (delay) =>
+    remove = =>
+      @el.remove()
+    if !delay
+      remove()
+      return
+    App.Delay.set(remove, delay * 1000)
+
 class App.ControllerGenericDestroyConfirm extends App.ControllerModal
   constructor: ->
     super

+ 39 - 35
app/assets/javascripts/app/controllers/translation.js.coffee

@@ -52,80 +52,83 @@ class Index extends App.ControllerContent
   pushChanges: =>
     locale = @$('[name="locale"]').val()
 
-    @modal = new App.ControllerModal(
-      head:      'Pushing own translations...'
-      message:   'Pushing own translations to i18n.zammad.com, Thanks for contributing!'
-      cancel:    false
-      close:     false
-      shown:     true
+    @loader = new App.ControllerModalLoading(
+      head:      'Push my changes'
+      message:   'Pushing translations to i18n.zammad.com'
       container: @el.closest('.content')
     )
 
     @ajax(
       id:          'translations'
       type:        'PUT'
-      url:         @apiPath + '/translations/push'
+      url:         "#{@apiPath}/translations/push"
       data:        JSON.stringify(locale: locale)
       processData: false
       success: (data, status, xhr) =>
-        @modal.hide()
+        @loader.update('Thanks for contributing!')
+        @loader.hideIcon()
+        @loader.hide(2)
       error: =>
-        @modal.hide()
+        @loader.hide()
     )
 
   resetChanges: =>
     locale = @$('[name="locale"]').val()
 
-    @modal = new App.ControllerModal(
-      head:      'Reseting changes...'
-      message:   'Reseting changes own translation changes...'
-      cancel:    false
-      close:     false
-      shown:     true
+    @loader = new App.ControllerModalLoading(
+      head:      'Reset changes'
+      message:   'Reseting changes...'
       container: @el.closest('.content')
     )
 
     @ajax(
       id:          'translations'
       type:        'POST'
-      url:         @apiPath + '/translations/reset'
+      url:         "#{@apiPath}/translations/reset"
       data:        JSON.stringify(locale: locale)
       processData: false
       success: (data, status, xhr) =>
         App.Event.trigger('i18n:translation_todo_reload')
         App.Event.trigger('i18n:translation_list_reload')
         @hideAction()
-        @modal.hide()
+        @loader.hide()
       error: =>
-        @modal.hide()
+        @loader.hide()
     )
 
   syncChanges: =>
     locale = @$('[name="locale"]').val()
 
-    @modal = new App.ControllerModal(
-      head:      'Syncing with latest translations...'
-      message:   'Syncing with latest translations!'
-      cancel:    false
-      close:     false
-      shown:     true
+    @loader = new App.ControllerModalLoading(
+      head:      'Get latest translations'
+      message:   'Getting latest translations from i18n.zammad.com'
       container: @el.closest('.content')
     )
 
+    hide = =>
+      @hideAction()
+      App.Event.trigger('i18n:translation_todo_reload')
+      App.Event.trigger('i18n:translation_list_reload')
+      @loader.hide(1)
+
+    locales = App.Locale.all()
+    locale = locales.shift()
+    @_syncChanges(locale, locales, @loader, hide)
+
+  _syncChanges: (locale, locales, loader, hide) =>
     @ajax(
       id:          'translations'
-      type:        'POST'
-      url:         @apiPath + '/translations/sync'
-      data:        JSON.stringify(locale: locale)
+      type:        'GET'
+      url:         "#{@apiPath}/translations/sync/#{locale.locale}"
       processData: false
-      success: (data, status, xhr) =>
-        App.Event.trigger('i18n:translation_todo_reload')
-        App.Event.trigger('i18n:translation_list_reload')
-        @hideAction()
-        @modal.hide()
-      error: =>
-        @modal.hide()
-    )
+      complete: (data, status, xhr) =>
+        loader.update(locale.name, false)
+        locale = locales.shift()
+        if _.isEmpty(locales)
+          hide()
+          return
+        @_syncChanges(locale, locales, loader, hide)
+      )
 
 class TranslationToDo extends App.Controller
   hasChanges: false
@@ -149,6 +152,7 @@ class TranslationToDo extends App.Controller
       return
 
     if !App.i18n.getNotTranslated(@locale)
+      @html ''
       return
 
     listNotTranslated = []

+ 20 - 0
app/assets/javascripts/app/views/generic/modal_loader.jst.eco

@@ -0,0 +1,20 @@
+<div class="modal-dialog wizard">
+
+  <form class="modal-content setup wizard">
+    <div class="modal-header">
+      <!--<div class="modal-close js-close">
+        <%- @Icon('diagonal-cross') %>
+      </div>-->
+      <h1 class="modal-title"><%- @T(@head) %></h1>
+    </div>
+    <div class="modal-body">
+      <div class="wizard-body vertical justified">
+        <p class="wizard-loadingText">
+          <span class="loading icon js-loadingIcon"></span> <span class="js-loading"><%- @message %> </span>
+        </p>
+      </div>
+    </div>
+    <div class="modal-footer"></div>
+  </form>
+
+</div>

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

@@ -3,9 +3,9 @@
     <h1><%- @T('Translations') %> <small></small></h1>
   </div>
   <div class="page-header-meta">
-    <a class="btn btn--success js-syncChanges"><%- @T('Sync with latest') %></a>
-    <a class="btn btn--danger hidden js-changes js-resetChanges"><%- @T('Reset Changes') %></a>
-    <a class="btn btn--primary hidden js-changes js-pushChanges"><%- @T('Push Changes') %></a>
+    <a class="btn btn--success js-syncChanges"><%- @T('Get latest translations') %></a>
+    <a class="btn btn--danger hidden js-changes js-resetChanges"><%- @T('Reset changes') %></a>
+    <a class="btn btn--primary hidden js-changes js-pushChanges"><%- @T('Push my changes') %></a>
     <div class="language"></div>
   </div>
 </div>

+ 2 - 3
app/controllers/translations_controller.rb

@@ -19,11 +19,10 @@ class TranslationsController < ApplicationController
     render json: { message: 'ok' }, status: :ok
   end
 
-  # POST /translations/sync
+  # POST /translations/sync/:locale
   def sync
     return if deny_if_not_role(Z_ROLENAME_ADMIN)
-    Locale.load
-    Translation.load
+    Translation.load(params[:locale])
     render json: { message: 'ok' }, status: :ok
   end
 

+ 8 - 0
app/models/locale.rb

@@ -2,6 +2,14 @@
 
 class Locale < ApplicationModel
 
+  def self.to_sync
+    locales = Locale.where(active: true)
+    if Rails.env.test?
+      locales = Locale.where(active: true, locale: ['en-us', 'de-de'])
+    end
+    locales
+  end
+
   def self.load
     url = 'https://i18n.zammad.com/api/v1/locales'
 

+ 17 - 6
app/models/translation.rb

@@ -10,17 +10,28 @@ class Translation < ApplicationModel
 
 load translations from online
 
+all:
+
   Translation.load
 
+dedicated:
+
+  Translation.load(locale) # e. g. en-us or de-de
+
 =end
 
-  def self.load
-    locales = Locale.where(active: true)
-    if Rails.env.test?
-      locales = Locale.where(active: true, locale: ['en-us', 'de-de'])
+  def self.load(dedicated_locale = nil)
+    locales_list = []
+    if !dedicated_locale
+      locales = Locale.to_sync
+      locales.each {|locale|
+        locales_list.push locale.locale
+      }
+    else
+      locales_list = [dedicated_locale]
     end
-    locales.each {|locale|
-      url = "https://i18n.zammad.com/api/v1/translations/#{locale.locale}"
+    locales_list.each {|locale|
+      url = "https://i18n.zammad.com/api/v1/translations/#{locale}"
       if !UserInfo.current_user_id
         UserInfo.current_user_id = 1
       end

+ 1 - 1
config/routes/translation.rb

@@ -2,7 +2,7 @@ Zammad::Application.routes.draw do
   api_path = Rails.configuration.api_path
 
   match api_path + '/translations/push',               to: 'translations#push',  via: :put
-  match api_path + '/translations/sync',               to: 'translations#sync',  via: :post
+  match api_path + '/translations/sync/:locale',       to: 'translations#sync',  via: :get
   match api_path + '/translations/reset',              to: 'translations#reset', via: :post
   match api_path + '/translations/lang/:locale',       to: 'translations#load',  via: :get
   match api_path + '/translations/admin/lang/:locale', to: 'translations#admin', via: :get

+ 1 - 0
test/browser/agent_ticket_actions_level3_test.rb

@@ -202,6 +202,7 @@ class AgentTicketActionsLevel3Test < TestCase
     reload(
       browser: browser2,
     )
+    sleep 2
     click(
       css: '.content.active .js-reset',
       browser: browser2,