Improved controller rerender after language change.

This commit is contained in:
Martin Edenhofer 2015-03-02 14:39:27 +01:00
parent 2269ef8e4e
commit 10b1fe0690
14 changed files with 340 additions and 38 deletions

View file

@ -50,7 +50,6 @@ class Index extends App.Controller
=> =>
App.i18n.set( @locale ) App.i18n.set( @locale )
App.Event.trigger( 'ui:rerender' ) App.Event.trigger( 'ui:rerender' )
App.Event.trigger( 'ui:page:rerender' )
@notify( @notify(
type: 'success' type: 'success'
msg: App.i18n.translateContent( 'Successfully!' ) msg: App.i18n.translateContent( 'Successfully!' )

View file

@ -129,7 +129,6 @@ class Index extends App.Controller
App.Session.get( 'id' ), App.Session.get( 'id' ),
=> =>
App.Event.trigger( 'ui:rerender' ) App.Event.trigger( 'ui:rerender' )
App.Event.trigger( 'ui:page:rerender' )
@notify( @notify(
type: 'success' type: 'success'
msg: App.i18n.translateContent( 'Successfully!' ) msg: App.i18n.translateContent( 'Successfully!' )

View file

@ -37,6 +37,11 @@ class App.TicketCreate extends App.Controller
@log 'notice', 'error', defaults @log 'notice', 'error', defaults
@render(defaults) @render(defaults)
# rerender view, e. g. on langauge change
@bind 'ui:rerender', =>
return if !@authenticate(true)
@render()
changeFormType: (e) => changeFormType: (e) =>
type = $(e.target).data('type') type = $(e.target).data('type')
if !type if !type

View file

@ -53,6 +53,11 @@ class App.Dashboard extends App.Controller
# render page # render page
@render() @render()
# rerender view, e. g. on langauge change
@bind 'ui:rerender', =>
return if !@authenticate(true)
@render()
render: -> render: ->
@html App.view('dashboard')( @html App.view('dashboard')(
@ -83,7 +88,7 @@ class App.Dashboard extends App.Controller
renderWidgetClockFace: (time) => renderWidgetClockFace: (time) =>
canvas = @el.find 'canvas' canvas = @el.find 'canvas'
ctx = canvas.get(0).getContext '2d' ctx = canvas.get(0).getContext '2d'
radius = 26 radius = 26
@el.find('.time.stat-widget .stat-amount').text time @el.find('.time.stat-widget .stat-amount').text time

View file

@ -5,7 +5,7 @@ class App.Navigation extends App.Controller
super super
@render() @render()
# rerender view # rerender view, e. g. on langauge change
@bind 'ui:rerender', (data) => @bind 'ui:rerender', (data) =>
@renderMenu() @renderMenu()
@renderPersonal() @renderPersonal()

View file

@ -7,11 +7,14 @@ class App.OrganizationProfile extends App.Controller
App.TaskManager.remove( @task_key ) App.TaskManager.remove( @task_key )
return return
@navupdate '#'
# fetch new data if needed # fetch new data if needed
App.Organization.full( @organization_id, @render ) App.Organization.full( @organization_id, @render )
# rerender view, e. g. on langauge change
@bind 'ui:rerender', =>
return if !@authenticate(true)
@render( App.Organization.fullLocal( @organization_id ) )
meta: => meta: =>
meta = meta =
url: @url() url: @url()

View file

@ -102,6 +102,11 @@ class Table extends App.Controller
@bind 'ticket_overview_local', => @bind 'ticket_overview_local', =>
@render(true) @render(true)
# rerender view, e. g. on langauge change
@bind 'ui:rerender', =>
return if !@authenticate(true)
@render()
update: (params) => update: (params) =>
for key, value of params for key, value of params
@[key] = value @[key] = value

View file

@ -53,6 +53,11 @@ class App.TicketZoom extends App.Controller
@delay( update, 1800, 'ticket-zoom-' + @ticket_id ) @delay( update, 1800, 'ticket-zoom-' + @ticket_id )
) )
# rerender view, e. g. on langauge change
@bind 'ui:rerender', =>
return if !@authenticate(true)
@render(true)
meta: => meta: =>
# default attributes # default attributes
@ -239,7 +244,7 @@ class App.TicketZoom extends App.Controller
App.Event.trigger 'task:render' App.Event.trigger 'task:render'
@formEnable( @$('.submit') ) @formEnable( @$('.submit') )
if !@renderDone if force || !@renderDone
@renderDone = true @renderDone = true
@html App.view('ticket_zoom')( @html App.view('ticket_zoom')(
ticket: @ticket ticket: @ticket

View file

@ -7,11 +7,14 @@ class App.UserProfile extends App.Controller
App.TaskManager.remove( @task_key ) App.TaskManager.remove( @task_key )
return return
@navupdate '#'
# fetch new data if needed # fetch new data if needed
@subscribeId = App.User.full( @user_id, @render ) @subscribeId = App.User.full( @user_id, @render )
# rerender view, e. g. on langauge change
@bind 'ui:rerender', =>
return if !@authenticate(true)
@render( App.User.fullLocal( @user_id ) )
release: => release: =>
App.User.unsubscribe(@subscribeId) App.User.unsubscribe(@subscribeId)

View file

@ -91,13 +91,6 @@ class App.Content extends App.Controller
new callback( params ) new callback( params )
controller( params ) controller( params )
# rerender view on ui:rerender event
App.Event.bind(
'ui:page:rerender', =>
controller( params )
'page'
)
# scroll to top / remember last screen position # scroll to top / remember last screen position
# @scrollTo( 0, 0, 100 ) # @scrollTo( 0, 0, 100 )
) )

View file

@ -68,19 +68,13 @@ class _taskManagerSingleton extends Spine.Module
@el = params.el @el = params.el
else else
@el = $('#app') @el = $('#app')
@offlineModus = params.offlineModus @offlineModus = params.offlineModus
@workers = {}
@workersStarted = {}
@allTasks = []
@tasksToUpdate = {}
@activeTaskHistory = []
@tasksInitial() @tasksInitial()
# render on login # render on login
App.Event.bind( App.Event.bind(
'auth:login' 'auth:login'
=> =>
@reset()
@tasksInitial() @tasksInitial()
'task' 'task'
) )
@ -96,6 +90,14 @@ class _taskManagerSingleton extends Spine.Module
# send updates to server # send updates to server
App.Interval.set( @taskUpdateLoop, 2500, 'check_update_to_server_pending', 'task' ) App.Interval.set( @taskUpdateLoop, 2500, 'check_update_to_server_pending', 'task' )
init: ->
@workers = {}
@workersStarted = {}
@tasksStarted = {}
@allTasks = []
@tasksToUpdate = {}
@activeTaskHistory = []
all: -> all: ->
# sort by prio # sort by prio
@ -125,6 +127,12 @@ class _taskManagerSingleton extends Spine.Module
# input validation # input validation
params.key = App.Utils.htmlAttributeCleanup(params.key) params.key = App.Utils.htmlAttributeCleanup(params.key)
# remember started task / prevent to open task twice
createNewTask = true
if @tasksStarted[params.key]
createNewTask = false
@tasksStarted[params.key] = true
# if we have init task startups, let the controller know this # if we have init task startups, let the controller know this
if params.init if params.init
params.params.init = true params.params.init = true
@ -138,13 +146,14 @@ class _taskManagerSingleton extends Spine.Module
if params.show if params.show
@activeTaskHistory.push _.clone(params) @activeTaskHistory.push _.clone(params)
# create new task if not exists # check if task already exists in storage / e. g. from last session
task = @get( params.key ) task = @get( params.key )
#console.log 'debug', 'execute', params, 'task', task #console.log 'debug', 'execute', params, 'task', task
# create new online task if not exists and if not persistent # create new online task if not exists and if not persistent
if !task && !params.persistent if !task && createNewTask && !params.persistent
@log 'debug', 'add, create new taskbar in backend' #console.log 'debug', 'add, create new taskbar in backend'
task = new App.Taskbar task = new App.Taskbar
task.load( task.load(
key: params.key key: params.key
@ -286,6 +295,10 @@ class _taskManagerSingleton extends Spine.Module
# remove task certain task from tasks # remove task certain task from tasks
remove: ( key ) => remove: ( key ) =>
# remember started task
delete @tasksStarted[key]
task = @get( key ) task = @get( key )
return if !task return if !task
@ -337,6 +350,7 @@ class _taskManagerSingleton extends Spine.Module
delete @workersStarted[ key ] delete @workersStarted[ key ]
delete @workers[ key ] delete @workers[ key ]
delete @tasksStarted[ key ]
# reset while tasks # reset while tasks
reset: => reset: =>
@ -350,9 +364,7 @@ class _taskManagerSingleton extends Spine.Module
@release(key) @release(key)
# clear instance vars # clear instance vars
@tasksToUpdate = {} @init()
@allTasks = []
@activeTaskHistory = []
# clear in mem tasks # clear in mem tasks
App.Taskbar.deleteAll() App.Taskbar.deleteAll()
@ -434,10 +446,10 @@ class _taskManagerSingleton extends Spine.Module
return return
tasksInitial: => tasksInitial: =>
@init()
# set taskbar collection stored in database # set taskbar collection stored in database
tasks = App.Taskbar.all() tasks = App.Taskbar.all()
@allTasks = []
for task in tasks for task in tasks
@allTasks.push task.attributes() @allTasks.push task.attributes()

View file

@ -1,8 +1,8 @@
<div class="dashboard main flex center"> <div class="dashboard main flex center">
<div class="tabs wide-tabs horizontal"> <div class="tabs wide-tabs horizontal">
<div class="tab my-stats active">My Stats</div> <div class="tab my-stats active"><%- @T('My Stats') %></div>
<div class="tab my-groups">My Group</div> <div class="tab my-groups"><%- @T('My Group') %></div>
<div class="tab all-stats">All</div> <div class="tab all-stats"><%- @T('All') %></div>
</div> </div>
<div class="stat-widgets three-columns horizontal"> <div class="stat-widgets three-columns horizontal">

View file

@ -5,10 +5,43 @@ class PreferencesTest < TestCase
def test_preferences def test_preferences
@browser = browser_instance @browser = browser_instance
login( login(
:username => 'nicole.braun@zammad.org', :username => 'master@example.com',
:password => 'test', :password => 'test',
:url => browser_url, :url => browser_url,
) )
tasks_close_all()
# start ticket create
ticket_create(
:data => {
:customer => 'nicole',
:group => 'Users',
:title => 'preferences lang check #1',
:body => 'preferences lang check #1',
},
:do_not_submit => true,
)
# start ticket zoom
ticket = ticket_create(
:data => {
:customer => 'nicole',
:group => 'Users',
:title => 'preferences lang check #2',
:body => 'preferences lang check #2',
},
)
# start user profile
user_open_by_search(
:value => 'Nicole',
)
# start organization profile
organization_open_by_search(
:value => 'Zammad Foundation',
)
click( :css => 'a[href="#current_user"]' ) click( :css => 'a[href="#current_user"]' )
click( :css => 'a[href="#profile"]' ) click( :css => 'a[href="#profile"]' )
click( :css => 'a[href="#profile/language"]' ) click( :css => 'a[href="#profile/language"]' )
@ -21,6 +54,103 @@ class PreferencesTest < TestCase
:css => 'body', :css => 'body',
:value => 'Sprache', :value => 'Sprache',
) )
# check language in navbar
watch_for(
:css => '#navigation',
:value => 'Übersicht'
)
# check language in dashboard
click( :css => '#navigation a[href="#dashboard"]' )
watch_for(
:css => '.content.active',
:value => 'Meine zugewiesenen'
)
# check language in overview
click( :css => '#navigation a[href="#ticket/view"]' )
watch_for(
:css => '.content.active',
:value => 'Meine'
)
verify_title(
:value => 'Meine zugewiesenen',
)
# check language in ticket create
verify_task(
:data => {
:title => 'anruf',
}
)
open_task(
:data => {
:title => 'preferences lang check #1',
}
)
watch_for(
:css => '.content.active',
:value => 'kunde'
)
watch_for(
:css => '.content.active',
:value => 'priorität'
)
watch_for(
:css => '.content.active [data-name="body"]',
:value => 'preferences lang check #1'
)
verify_title(
:value => 'anruf',
)
# check language in ticket zoom
ticket_open_by_search(
:number => ticket[:number],
)
watch_for(
:css => '.content.active',
:value => 'erstellt'
)
watch_for(
:css => '.content.active',
:value => 'priorität'
)
# check language in user profile
open_task(
:data => {
:title => 'Nicole',
}
)
watch_for(
:css => '.content.active',
:value => 'notiz'
)
watch_for(
:css => '.content.active',
:value => 'e-mail'
)
watch_for(
:css => '.content.active',
:value => 'aktion'
)
# check language in organization profile
open_task(
:data => {
:title => 'Zammad',
}
)
watch_for(
:css => '.content.active',
:value => 'notiz'
)
click( :css => 'a[href="#current_user"]' )
click( :css => 'a[href="#profile"]' )
click( :css => 'a[href="#profile/language"]' )
select( select(
:css => '.language_item select[name="locale"]', :css => '.language_item select[name="locale"]',
:value => 'English (United States)', :value => 'English (United States)',
@ -31,6 +161,104 @@ class PreferencesTest < TestCase
:css => 'body', :css => 'body',
:value => 'Language', :value => 'Language',
) )
# check language in navbar
watch_for(
:css => '#navigation',
:value => 'Overview'
)
# check language in dashboard
click( :css => '#navigation a[href="#dashboard"]' )
watch_for(
:css => '.content.active',
:value => 'My assig'
)
# check language in overview
click( :css => '#navigation a[href="#ticket/view"]' )
watch_for(
:css => '.content.active',
:value => 'My'
)
verify_title(
:value => 'My assig',
)
# check language in ticket create
verify_task(
:data => {
:title => 'call',
}
)
open_task(
:data => {
:title => 'preferences lang check #1',
}
)
watch_for(
:css => '.content.active',
:value => 'customer'
)
watch_for(
:css => '.content.active',
:value => 'priority'
)
watch_for(
:css => '.content.active [data-name="body"]',
:value => 'preferences lang check #1'
)
verify_title(
:value => 'call',
)
# check language in ticket zoom
ticket_open_by_search(
:number => ticket[:number],
)
watch_for(
:css => '.content.active',
:value => 'create'
)
watch_for(
:css => '.content.active',
:value => 'priority'
)
# check language in user profile
open_task(
:data => {
:title => 'Nicole',
}
)
watch_for(
:css => '.content.active',
:value => 'note'
)
watch_for(
:css => '.content.active',
:value => 'email'
)
# check language in organization profile
open_task(
:data => {
:title => 'Zammad',
}
)
watch_for(
:css => '.content.active',
:value => 'note'
)
watch_for(
:css => '.content.active',
:value => 'action'
)
# switch to de again
click( :css => 'a[href="#current_user"]' )
click( :css => 'a[href="#profile"]' )
click( :css => 'a[href="#profile/language"]' )
select( select(
:css => '.language_item select[name="locale"]', :css => '.language_item select[name="locale"]',
:value => 'Deutsch', :value => 'Deutsch',
@ -41,11 +269,33 @@ class PreferencesTest < TestCase
:css => 'body', :css => 'body',
:value => 'Sprache', :value => 'Sprache',
) )
sleep 2 sleep 4
# check if language is still used after reload
reload() reload()
watch_for( watch_for(
:css => 'body', :css => 'body',
:value => 'Sprache', :value => 'Sprache',
) )
# check language in navbar
watch_for(
:css => '#navigation',
:value => 'Übersicht'
)
# check language in dashboard
click( :css => '#navigation a[href="#dashboard"]' )
watch_for(
:css => '.content.active',
:value => 'Meine'
)
# check language in overview
click( :css => '#navigation a[href="#ticket/view"]' )
watch_for(
:css => '.content.active',
:value => 'Meine'
)
end end
end end

View file

@ -571,6 +571,29 @@ class TestCase < Test::Unit::TestCase
true true
end end
=begin
open_task(
:browser => browser1,
:data => {
:title => 'some title',
}
)
=end
def open_task(params = {}, fallback = false)
instance = params[:browser] || @browser
data = params[:data]
element = instance.find_elements( { :partial_link_text => data[:title] } )[0]
if !element
raise "no task with title '#{data[:title]}' found"
end
element.click
true
end
=begin =begin
file_upload( file_upload(
@ -614,7 +637,7 @@ class TestCase < Test::Unit::TestCase
if params[:timeout] if params[:timeout]
timeout = params[:timeout] timeout = params[:timeout]
end end
loops = (timeout).to_i loops = (timeout).to_i * 2
text = '' text = ''
(1..loops).each { |loop| (1..loops).each { |loop|
element = instance.find_elements( { :css => params[:css] } )[0] element = instance.find_elements( { :css => params[:css] } )[0]
@ -638,7 +661,7 @@ class TestCase < Test::Unit::TestCase
# just try again # just try again
end end
end end
sleep 1 sleep 0.5
} }
raise "'#{params[:value]}' found in '#{text}'" raise "'#{params[:value]}' found in '#{text}'"
end end