now progress bar will not show for tasks too small...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2020-12-06 05:34:28 +03:00
parent 9f4b877e37
commit 7750620935

View File

@ -18,8 +18,9 @@ var core = require('features/core')
var ProgressActions = actions.Actions({ var ProgressActions = actions.Actions({
config: { config: {
'progress-fade-duration': 200, 'progress-pre-delay': 1000,
'progress-done-delay': 1000, 'progress-done-delay': 1000,
'progress-fade-duration': 200,
'progress-update-min': 200, 'progress-update-min': 200,
@ -117,7 +118,11 @@ var ProgressActions = actions.Actions({
.showProgress(logger) .showProgress(logger)
The progress bar is going to be shown to the user if:
- max is greater than 1, or
- it did not close before .config['progress-pre-delay'] ms of start
This is done to avoid spamming the user with single point progress bars.
`, `,
function(text, value, max, attrs){ function(text, value, max, attrs){
var that = this var that = this
@ -189,6 +194,9 @@ var ProgressActions = actions.Actions({
widget = widget.length == 0 ? widget = widget.length == 0 ?
$('<div/>') $('<div/>')
.addClass('progress-bar') .addClass('progress-bar')
.css({
display: 'none',
})
.attr('name', text) .attr('name', text)
.text(text) .text(text)
// close button... // close button...
@ -205,19 +213,33 @@ var ProgressActions = actions.Actions({
.append($('<progress/>')) .append($('<progress/>'))
// events... // events...
.on('progressClose', function(){ .on('progressClose', function(){
$(this) var elem = $(this)
.fadeOut(that.config['progress-fade-duration'] || 200, function(){
var cache = (that.__progress_cache || {})[text] var clear = function(){
cache.timeout var cache = (that.__progress_cache || {})[text]
&& clearTimeout(cache.timeout) cache.timeout
cache.ondone && clearTimeout(cache.timeout)
&& cache.ondone() cache.ondone
// clear cache... && cache.ondone()
delete (that.__progress_cache || {})[text] // clear cache...
$(this).remove() }) delete (that.__progress_cache || {})[text]
elem.remove() }
// widget was not shown...
if(elem.attr('closing') == null
|| elem.css('display') == 'none'){
clear()
// fade...
} else {
elem[0].setAttribute('closing', '')
elem
.fadeOut(
that.config['progress-fade-duration'] || 200,
clear) }
widget = null }) widget = null })
.appendTo(container) .appendTo(container)
: widget : widget
.removeAttr('closing')
// reset closing timeout... // reset closing timeout...
var timeout = widget.attr('close-timeout') var timeout = widget.attr('close-timeout')
@ -240,13 +262,25 @@ var ProgressActions = actions.Actions({
widget.find('.progress-details') widget.find('.progress-details')
.text(msg) .text(msg)
// auto-show...
if(max > 1
|| !this.config['progress-pre-delay']){
widget.css({display: ''})
} else {
setTimeout(
function(){
widget
&& widget.attr('closing') == undefined
&& widget.css({display: ''}) },
this.config['progress-pre-delay'] || 1000) }
// auto-close... // auto-close...
if(value != null && value >= (max || 0)){ if(value != null && value >= (max || 0)){
widget.attr('close-timeout', widget.attr('close-timeout',
JSON.stringify(setTimeout( JSON.stringify(setTimeout(
function(){ function(){
widget if(widget){
&& widget.trigger('progressClose') }, widget.trigger('progressClose') } },
this.config['progress-done-delay'] || 1000))) } }], this.config['progress-done-delay'] || 1000))) } }],
// handle logger progress... // handle logger progress...