From cbca4fa849416a533a6b94c93b6ddd4250940907 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Fri, 20 Nov 2015 15:10:50 +0100 Subject: [PATCH] Removed not needed render events. --- .../app/controllers/taskbar_widget.coffee | 8 ++- .../app/lib/app_post/task_manager.coffee | 71 +++++++++---------- test/browser_test_helper.rb | 7 +- 3 files changed, 41 insertions(+), 45 deletions(-) diff --git a/app/assets/javascripts/app/controllers/taskbar_widget.coffee b/app/assets/javascripts/app/controllers/taskbar_widget.coffee index 04f4dc15b..4f5cc7380 100644 --- a/app/assets/javascripts/app/controllers/taskbar_widget.coffee +++ b/app/assets/javascripts/app/controllers/taskbar_widget.coffee @@ -81,7 +81,7 @@ class App.TaskbarWidget extends App.Controller throw 'No such key attributes found for task item' # check if input has changed - worker = App.TaskManager.worker( key ) + worker = App.TaskManager.worker(key) if !force && worker && worker.changed if worker.changed() new Remove( @@ -91,7 +91,7 @@ class App.TaskbarWidget extends App.Controller return # check if active task is closed - currentTask = App.TaskManager.get( key ) + currentTask = App.TaskManager.get(key) tasks = App.TaskManager.all() active_is_closed = false for task in tasks @@ -99,7 +99,9 @@ class App.TaskbarWidget extends App.Controller active_is_closed = true # remove task - App.TaskManager.remove( key ) + App.TaskManager.remove(key, false) + + $(e.target).closest('.task').remove() # if we do not need to move to an other task return if !active_is_closed diff --git a/app/assets/javascripts/app/lib/app_post/task_manager.coffee b/app/assets/javascripts/app/lib/app_post/task_manager.coffee index 757077590..009805abc 100644 --- a/app/assets/javascripts/app/lib/app_post/task_manager.coffee +++ b/app/assets/javascripts/app/lib/app_post/task_manager.coffee @@ -24,10 +24,10 @@ class App.TaskManager _instance ?= new _taskManagerSingleton _instance.update( key, params ) - @remove: ( key ) -> + @remove: (key, rerender = true) -> if _instance == undefined _instance ?= new _taskManagerSingleton - _instance.remove( key ) + _instance.remove(key, rerender) @notify: ( key ) -> if _instance == undefined @@ -77,23 +77,19 @@ class _taskManagerSingleton extends Spine.Module @tasksInitial() # render on login - App.Event.bind( - 'auth:login' - => - @tasksInitial() + App.Event.bind('auth:login', => + @tasksInitial() 'task' ) # render on logout - App.Event.bind( - 'auth:logout' - => - @reset() + App.Event.bind('auth:logout', => + @reset() 'task' ) # 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 = {} @@ -123,11 +119,11 @@ class _taskManagerSingleton extends Spine.Module domID: (key) -> "content_permanent_#{key}" - worker: ( key ) -> + worker: (key) -> return @workers[ key ] if @workers[ key ] return - execute: ( params ) -> + execute: (params) -> # input validation params.key = App.Utils.htmlAttributeCleanup(params.key) @@ -159,7 +155,7 @@ class _taskManagerSingleton extends Spine.Module @activeTaskHistory.push _.clone(params) # 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 @@ -220,7 +216,8 @@ class _taskManagerSingleton extends Spine.Module # start worker for task if not exists @startController(params) - App.Event.trigger 'task:render' + if !params.init + App.Event.trigger 'task:render' startController: (params) => @@ -238,7 +235,7 @@ class _taskManagerSingleton extends Spine.Module @workersStarted[params.key] = true # create new controller instanz - @workers[params.key] = new App[params.controller]( params_app ) + @workers[params.key] = new App[params.controller](params_app) # if controller is started hidden, call hide of controller if !params.show @@ -246,9 +243,9 @@ class _taskManagerSingleton extends Spine.Module # hide all other controller / show current controller else - @showControllerHideOthers( params.key, params_app ) + @showControllerHideOthers(params.key, params_app) - showControllerHideOthers: ( thisKey, params_app ) => + showControllerHideOthers: (thisKey, params_app) => for key of @workersStarted if key is thisKey @show(key, params_app) @@ -269,7 +266,6 @@ class _taskManagerSingleton extends Spine.Module # execute controllers show if controller.show controller.show(params_app) - App.Event.trigger('ui:rerender:task') true @@ -291,27 +287,27 @@ class _taskManagerSingleton extends Spine.Module true # get task - get: ( key ) => + get: (key) => for task in @allTasks if task.key is key return task # update task - update: ( key, params ) => - task = @get( key ) + update: (key, params) => + task = @get(key) if !task throw "No such task with '#{key}' to update" for item, value of params task[item] = value - @taskUpdate( task ) + @taskUpdate(task) # remove task certain task from tasks - remove: ( key ) => + remove: (key, rerender) => # remember started task delete @tasksStarted[key] - task = @get( key ) + task = @get(key) return if !task # update @allTasks @@ -327,44 +323,45 @@ class _taskManagerSingleton extends Spine.Module @release(key) # rerender taskbar - App.Event.trigger 'task:render' + if rerender + App.Event.trigger 'task:render' # destroy in backend storage @taskDestroy(task) # set notify of task - notify: ( key ) => - task = @get( key ) + notify: (key) => + task = @get(key) if !task throw "No such task with '#{key}' to notify" task.notify = true - @taskUpdate( task ) + @taskUpdate(task) # unset notify of task - mute: ( key ) => - task = @get( key ) + mute: (key) => + task = @get(key) if !task throw "No such task with '#{key}' to mute" task.notify = false - @taskUpdate( task ) + @taskUpdate(task) # set new order of tasks (needed for dnd) - reorder: ( order ) => + reorder: (order) => prio = 0 for key in order - task = @get( key ) + task = @get(key) if !task throw "No such task with '#{key}' of order" prio++ if task.prio isnt prio task.prio = prio - @taskUpdate( task ) + @taskUpdate(task) # release one task release: (key) => try - @el.find( "##{@domID(key)}" ).html('') - @el.find( "##{@domID(key)}" ).remove() + @el.find("##{@domID(key)}").html('') + @el.find("##{@domID(key)}").remove() catch @log 'notice', "invalid key '#{key}'" diff --git a/test/browser_test_helper.rb b/test/browser_test_helper.rb index 7ae563836..84cfc5d31 100644 --- a/test/browser_test_helper.rb +++ b/test/browser_test_helper.rb @@ -964,8 +964,8 @@ wait untill text in selector disabppears =begin tasks_close_all( - :browser => browser1, - :discard_changes => true, + browser: browser1, + discard_changes: true, ) =end @@ -980,11 +980,8 @@ wait untill text in selector disabppears begin if instance.find_elements( { css: '.navigation .tasks .task:first-child' } )[0] instance.mouse.move_to( instance.find_elements( { css: '.navigation .tasks .task:first-child' } )[0] ) - sleep 0.2 - click_element = instance.find_elements( { css: '.navigation .tasks .task:first-child .js-close' } )[0] if click_element - sleep 0.1 click_element.click # accept task close warning