Fixed issue #2204 - Max size of tabs is not recognised

This commit is contained in:
Martin Edenhofer 2018-08-22 23:17:41 +02:00
parent 4dec6209dc
commit 61b1a8733f
4 changed files with 94 additions and 19 deletions

View file

@ -1,9 +1,10 @@
class App.TestController1 extends App.Controller class App.TestController1 extends App.Controller
constructor: -> constructor: ->
super super
@showState = false @showState = false
@hideState = false @hideState = false
@activeState = false @activeState = false
@changedState ||= false
@render() @render()
meta: -> meta: ->
@ -21,6 +22,9 @@ class App.TestController1 extends App.Controller
@activeState = state @activeState = state
@render() @render()
changed: =>
@changedState
render: -> render: ->
@html "<div>some test controller message:'#{@message}',show:'#{@showState}',hide:'#{@hideState}',active:'#{@activeState}'</div>" @html "<div>some test controller message:'#{@message}',show:'#{@showState}',hide:'#{@hideState}',active:'#{@activeState}'</div>"

View file

@ -83,6 +83,18 @@ class App.TaskManager
return if !_instance return if !_instance
_instance.preferencesTrigger(key) _instance.preferencesTrigger(key)
@tasksAutoCleanupDelayTime: (key) ->
return if !_instance
if !key
return _instance.tasksAutoCleanupDelayTime
_instance.tasksAutoCleanupDelayTime = key
@tasksAutoCleanupTaskMax: (key) ->
return if !_instance
if !key
return _instance.maxTaskCount
_instance.maxTaskCount = key
class _taskManagerSingleton extends App.Controller class _taskManagerSingleton extends App.Controller
@include App.LogInclude @include App.LogInclude
@ -108,9 +120,11 @@ class _taskManagerSingleton extends App.Controller
@tasksToUpdate = {} @tasksToUpdate = {}
@tasksPreferences = {} @tasksPreferences = {}
@tasksPreferencesCallbacks = {} @tasksPreferencesCallbacks = {}
@tasksAutoCleanupDelayTime = 12000
@activeTaskHistory = [] @activeTaskHistory = []
@queue = [] @queue = []
@queueRunning = false @queueRunning = false
@maxTaskCount = 30
all: -> all: ->
@ -599,7 +613,7 @@ class _taskManagerSingleton extends App.Controller
tasksAutoCleanupDelay: => tasksAutoCleanupDelay: =>
delay = => delay = =>
@tasksAutoCleanup() @tasksAutoCleanup()
App.Delay.set(delay, 12000, 'task-autocleanup', undefined, true) App.Delay.set(delay, @tasksAutoCleanupDelayTime, 'task-autocleanup', undefined, true)
tasksAutoCleanup: => tasksAutoCleanup: =>
@ -607,13 +621,19 @@ class _taskManagerSingleton extends App.Controller
currentTaskCount = => currentTaskCount = =>
Object.keys(@allTasksByKey).length Object.keys(@allTasksByKey).length
maxTaskCount = 30 if currentTaskCount() > @maxTaskCount
if currentTaskCount() > maxTaskCount if @offlineModus
for task in App.Taskbar.search(sortBy:'updated_at', order:'ASC') tasks = @all()
if currentTaskCount() > maxTaskCount else
tasks = App.Taskbar.search(sortBy:'updated_at', order:'ASC')
for task in tasks
if currentTaskCount() > @maxTaskCount
if !task.active if !task.active
if _.isEmpty(task.state) || (_.isEmpty(task.state.ticket) && _.isEmpty(task.state.article)) worker = App.TaskManager.worker(task.key)
@log 'notice', "More then #{maxTaskCount} tasks open, close oldest untouched task #{task.key}" if worker
if worker.changed && worker.changed()
continue
@log 'notice', "More then #{@maxTaskCount} tasks open, close oldest untouched task #{task.key}"
@remove(task.key) @remove(task.key)
tasksInitial: => tasksInitial: =>

View file

@ -40,7 +40,6 @@ test( "taskbar basic tests", function() {
deepEqual(task.state, 'abc') deepEqual(task.state, 'abc')
deepEqual(task.params, { "a": 12 }) deepEqual(task.params, { "a": 12 })
App.TaskManager.execute({ App.TaskManager.execute({
key: 'TestKey2', key: 'TestKey2',
controller: 'TestController1', controller: 'TestController1',
@ -258,12 +257,60 @@ test( "taskbar basic tests", function() {
equal(App.TaskManager.nextTaskUrl(), false) equal(App.TaskManager.nextTaskUrl(), false)
equal(App.TaskManager.nextTaskUrl(), false) equal(App.TaskManager.nextTaskUrl(), false)
// destroy task bar // check max tabs
App.TaskManager.reset() var times = 5;
App.TaskManager.tasksAutoCleanupDelayTime(200)
App.TaskManager.tasksAutoCleanupTaskMax(3)
// check if any taskar exists for(var i=0; i < times; i++){
equal($('#taskbars .content').length, 0, "check available active contents") App.TaskManager.execute({
key: 'TestKeyLoop' + i,
controller: 'TestController1',
params: {
message: "#" + i,
},
show: true,
persistent: false,
})
}
equal(App.TaskManager.all().length, 5)
}) })
App.Delay.set(function() {
test( "taskbar check max tabs 2", function() {
equal(App.TaskManager.all().length, 3)
var times = 5;
for(var i=0; i < times; i++){
App.TaskManager.execute({
key: 'TestKeyLoop2' + i,
controller: 'TestController1',
params: {
message: "#" + i,
changedState: true
},
show: true,
persistent: false,
})
}
equal(App.TaskManager.all().length, 8)
})
}, 1000);
App.Delay.set(function() {
test( "taskbar check max tabs 5", function() {
equal(App.TaskManager.all().length, 5)
// destroy task bar
App.TaskManager.reset()
// check if any taskar exists
equal($('#taskbars .content').length, 0, "check available active contents")
})
}, 2000);
} }

View file

@ -5,10 +5,11 @@ class AAbUnitTest < TestCase
def test_core def test_core
@browser = browser_instance @browser = browser_instance
location(url: browser_url + '/tests_core') location(url: browser_url + '/tests_core')
sleep 5
watch_for( watch_for(
css: '.result', css: '.result',
value: 'Tests completed', value: 'Tests completed',
timeout: 8, timeout: 4,
) )
match( match(
css: '.result .failed', css: '.result .failed',
@ -30,10 +31,11 @@ class AAbUnitTest < TestCase
) )
location(url: browser_url + '/tests_model') location(url: browser_url + '/tests_model')
sleep 5
watch_for( watch_for(
css: '.result', css: '.result',
value: 'Tests completed', value: 'Tests completed',
timeout: 8, timeout: 3,
) )
match( match(
css: '.result .failed', css: '.result .failed',
@ -77,10 +79,11 @@ class AAbUnitTest < TestCase
def test_form def test_form
@browser = browser_instance @browser = browser_instance
location(url: browser_url + '/tests_form') location(url: browser_url + '/tests_form')
sleep 5
watch_for( watch_for(
css: '.result', css: '.result',
value: 'Tests completed', value: 'Tests completed',
timeout: 8, timeout: 2,
) )
match( match(
css: '.result .failed', css: '.result .failed',
@ -212,10 +215,11 @@ class AAbUnitTest < TestCase
) )
location(url: browser_url + '/tests_taskbar') location(url: browser_url + '/tests_taskbar')
sleep 5
watch_for( watch_for(
css: '.result', css: '.result',
value: 'Tests completed', value: 'Tests completed',
timeout: 8, timeout: 3,
) )
match( match(
css: '.result .failed', css: '.result .failed',