diff --git a/app/assets/javascripts/app/controllers/_application_controller_generic.js.coffee b/app/assets/javascripts/app/controllers/_application_controller_generic.js.coffee index 0123a8ecd..6fd2f6b22 100644 --- a/app/assets/javascripts/app/controllers/_application_controller_generic.js.coffee +++ b/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 diff --git a/app/assets/javascripts/app/controllers/translation.js.coffee b/app/assets/javascripts/app/controllers/translation.js.coffee index 38627565c..50e2779d7 100644 --- a/app/assets/javascripts/app/controllers/translation.js.coffee +++ b/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 = [] diff --git a/app/assets/javascripts/app/views/generic/modal_loader.jst.eco b/app/assets/javascripts/app/views/generic/modal_loader.jst.eco new file mode 100644 index 000000000..a8a18aac1 --- /dev/null +++ b/app/assets/javascripts/app/views/generic/modal_loader.jst.eco @@ -0,0 +1,20 @@ + \ No newline at end of file diff --git a/app/assets/javascripts/app/views/translation/index.jst.eco b/app/assets/javascripts/app/views/translation/index.jst.eco index 953e02f94..77c2a1684 100644 --- a/app/assets/javascripts/app/views/translation/index.jst.eco +++ b/app/assets/javascripts/app/views/translation/index.jst.eco @@ -3,9 +3,9 @@

<%- @T('Translations') %>

- <%- @T('Sync with latest') %> - - + <%- @T('Get latest translations') %> + +
diff --git a/app/controllers/translations_controller.rb b/app/controllers/translations_controller.rb index 5c98afbfc..1cead7961 100644 --- a/app/controllers/translations_controller.rb +++ b/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 diff --git a/app/models/locale.rb b/app/models/locale.rb index 6381e3b9f..fb7981dd6 100644 --- a/app/models/locale.rb +++ b/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' diff --git a/app/models/translation.rb b/app/models/translation.rb index d36c05ad8..41ca2718a 100644 --- a/app/models/translation.rb +++ b/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 diff --git a/config/routes/translation.rb b/config/routes/translation.rb index c7281fbad..38eec40fe 100644 --- a/config/routes/translation.rb +++ b/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 diff --git a/test/browser/agent_ticket_actions_level3_test.rb b/test/browser/agent_ticket_actions_level3_test.rb index 2e0ae75ad..db80092ec 100644 --- a/test/browser/agent_ticket_actions_level3_test.rb +++ b/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,