diff --git a/Viewer/features/core.js b/Viewer/features/core.js index 6b2b157f..f28ad8d2 100755 --- a/Viewer/features/core.js +++ b/Viewer/features/core.js @@ -2456,38 +2456,34 @@ module.taskAction = function(title, func){ var action return (action = Object.assign( - task(function(){ + task(function(...args){ var that = this // XXX - var ticket = { - // XXX revise naming... - start: eventMethod('start', function(handle, ...args){ - if(this.state == 'ready'){ - that.resumeTask(title, action) - handle(...args) } }), - pause: eventMethod('pause', function(handle, ...args){ - if(this.state == 'running'){ - that.pauseTask(title, action) - handle(...args) } }), - abort: eventMethod('abort', function(handle, ...args){ - if(!this.state != 'done'){ - that.abortTask(title, action) - handle(...args) } }), - + var ticket = events.EventMixin({ // can be: // - ready // - running // - done - get state(){ - }, - } + state: null, - return func.call(this, ticket, ...args) - .then(function(){ - }) - .catch(function(){ - }) }), + start: events.Event('start', function(handle, ...args){ + if(this.state == 'ready'){ + that.resumeTask(title, action) + handle(...args) } }), + pause: events.Event('pause', function(handle, ...args){ + if(this.state == 'running'){ + that.pauseTask(title, action) + handle(...args) } }), + abort: events.Event('abort', function(handle, ...args){ + if(!this.state != 'done'){ + that.abortTask(title, action) + handle(...args) } }), + }) + + // XXX + + return func.call(this, ticket, ...args) }), { toString: function(){ return `core.taskAction('${ title }', \n${ func.toString() })` }, diff --git a/Viewer/features/examples.js b/Viewer/features/examples.js index 65dafa42..887035e1 100755 --- a/Viewer/features/examples.js +++ b/Viewer/features/examples.js @@ -266,6 +266,15 @@ var ExampleActions = actions.Actions({ // XXX inner/outer action... + + exampleTask: ['- Test/', + core.taskAction('Example task', function(ticket, ...args){ + + // XXX + console.log('>>>>', ticket, ...args) + + return Promise.cooperative() + })], }) var Example = diff --git a/Viewer/features/sharp.js b/Viewer/features/sharp.js index dce9b473..9f5a8d4b 100755 --- a/Viewer/features/sharp.js +++ b/Viewer/features/sharp.js @@ -329,7 +329,7 @@ var SharpActions = actions.Actions({ return images .mapChunks(CHUNK_SIZE, function(gid){ if(abort.isAborted){ - throw array.StopIteration('aborted') } + throw array.STOP('aborted') } // skip non-images... if(!['image', null, undefined] @@ -503,7 +503,7 @@ var SharpActions = actions.Actions({ return images .mapChunks(CHUNK_SIZE, function(gid){ if(abort.isAborted){ - throw array.StopIteration('aborted') } + throw array.STOP('aborted') } var img = that.images[gid] var base = base_path @@ -513,7 +513,7 @@ var SharpActions = actions.Actions({ return sizes .map(function(size, i){ if(abort.isAborted){ - throw array.StopIteration('aborted') } + throw array.STOP('aborted') } var name = path = path_tpl .replace(/\$RESOLUTION|\$\{RESOLUTION\}/g, parseInt(size)) @@ -685,7 +685,7 @@ var SharpActions = actions.Actions({ .mapChunks(CHUNK_SIZE, function(gid){ // abort... if(abort.isAborted){ - throw array.StopIteration('aborted') } + throw array.STOP('aborted') } var img = cached_images[gid] var path = img && that.getImagePath(gid) diff --git a/Viewer/features/ui-progress.js b/Viewer/features/ui-progress.js index 7455733b..29dd6637 100755 --- a/Viewer/features/ui-progress.js +++ b/Viewer/features/ui-progress.js @@ -128,7 +128,7 @@ var ProgressActions = actions.Actions({ var msg = text instanceof Array ? text.slice(1).join(': ') : null text = text instanceof Array ? text[0] : text - // make sure we do not update too often... + // cache -- make sure we do not update too often... if(value != 'close'){ var cache = (this.__progress_cache = this.__progress_cache || {}) cache = cache[text] = @@ -140,7 +140,8 @@ var ProgressActions = actions.Actions({ var v = cache[name] || 0 return (cache[name] = value != null ? - (typeof(value) == typeof('str') && /[+-][0-9]+/.test(value) ? + ((typeof(value) == typeof('str') + && /[+-][0-9]+/.test(value)) ? v + parseInt(value) : parseInt(value)) : v) } @@ -151,18 +152,17 @@ var ProgressActions = actions.Actions({ // update not due yet... if('timeout' in cache){ cache.update = true - return + return } // set next update point and continue... - } else { - delete cache.update - cache.timeout = setTimeout( - function(){ - var cache = that.__progress_cache[text] || {} - delete cache.timeout - cache.update - && that.showProgress(text) }, - this.config['progress-update-min'] || 200) } } + delete cache.update + cache.timeout = setTimeout( + function(){ + var cache = that.__progress_cache[text] || {} + delete cache.timeout + cache.update + && that.showProgress(text) }, + this.config['progress-update-min'] || 200) } // container... var container = viewer.find('.progress-container') @@ -190,7 +190,6 @@ var ProgressActions = actions.Actions({ .append($('×') .on('click', function(){ var cache = (that.__progress_cache || {})[text] - // XXX do we need both close and done callbacks??? cache.onclose && cache.onclose() widget.trigger('progressClose') })) @@ -206,21 +205,19 @@ var ProgressActions = actions.Actions({ var cache = (that.__progress_cache || {})[text] cache.timeout && clearTimeout(cache.timeout) - // XXX do we need both close and done callbacks??? cache.ondone && cache.ondone() + // clear cache... delete (that.__progress_cache || {})[text] - $(this).remove() }) }) + $(this).remove() }) + widget = null }) .appendTo(container) : widget // reset closing timeout... var timeout = widget.attr('close-timeout') - timeout && clearTimeout(JSON.parse(timeout)) - - // get the widget parts we are updating... - var bar = widget.find('progress') - var state = widget.find('.progress-details') + timeout + && clearTimeout(JSON.parse(timeout)) // format the message... msg = msg ? ': '+msg : '' @@ -230,23 +227,22 @@ var ProgressActions = actions.Actions({ : '...') // update widget... - bar.attr({ - value: value || '', - max: max || '', - }) - state.text(msg) + widget.find('progress') + .attr({ + value: value || '', + max: max || '', + }) + widget.find('.progress-details') + .text(msg) // auto-close... if(value && value >= (max || 0)){ widget.attr('close-timeout', - // XXX BUG: this appears to get triggered after we close progress... - JSON.stringify(setTimeout(function(){ - widget.trigger('progressClose') - }, this.config['progress-done-delay'] || 1000))) } - - // XXX force the browser to render... - //bar.hide(0).show(0) - }], + JSON.stringify(setTimeout( + function(){ + widget + && widget.trigger('progressClose') }, + this.config['progress-done-delay'] || 1000))) } }], // handle logger progress... // XXX revise... @@ -257,6 +253,13 @@ var ProgressActions = actions.Actions({ rest[0].length : rest.length + // only pass the relevant stuff... + var attrs = {} + logger.ondone + && (attrs.ondone = logger.ondone) + logger.onclose + && (attrs.onclose = logger.onclose) + // get keywords... var {add, done, skip, close, error} = this.config['progress-logger-keywords'] @@ -270,23 +273,23 @@ var ProgressActions = actions.Actions({ // close... if(status == 'close' || close.has(status)){ - this.showProgress(path, 'close', logger) + this.showProgress(path, 'close', attrs) // added new item -- increase max... - // XXX show msg in the progress bar... + // XXX show msg in the progress bar??? } else if(status == 'add' || add.has(status)){ - this.showProgress(path, '+0', '+'+l, logger) + this.showProgress(path, '+0', '+'+l, attrs) // resolved item -- increase done... } else if(status == 'done' || done.has(status)){ - this.showProgress(path, '+'+l, logger) + this.showProgress(path, '+'+l, attrs) // skipped item -- increase done... // XXX should we instead decrease max here??? // ...if not this is the same as done -- merge... } else if(status == 'skip' || skip.has(status)){ - this.showProgress(path, '+'+l, logger) + this.showProgress(path, '+'+l, attrs) // error... // XXX STUB... } else if(status == 'error' || error.has(status)){ - this.showProgress(['Error'].concat(msg), '+0', '+'+l, logger) } + this.showProgress(['Error'].concat(msg), '+0', '+'+l, attrs) } }], }) diff --git a/Viewer/package-lock.json b/Viewer/package-lock.json index f9a5f8d5..d029eaff 100755 --- a/Viewer/package-lock.json +++ b/Viewer/package-lock.json @@ -1112,16 +1112,16 @@ } }, "ig-object": { - "version": "5.4.9", - "resolved": "https://registry.npmjs.org/ig-object/-/ig-object-5.4.9.tgz", - "integrity": "sha512-dmwTla11Kme9pSq7hUjHVNNnbJGg1fQZCm3bquuuTIj5KlI1OLgka14fAhjWOf3kGtHJ2x5Nznvd7yxka26OzQ==" + "version": "5.4.11", + "resolved": "https://registry.npmjs.org/ig-object/-/ig-object-5.4.11.tgz", + "integrity": "sha512-WPPQ5C41c6q3tPfa2fBbWE2xcLF7LoGRu2E6Wr/aoA5oxAyl8lAuE7Kqt4TyPwfW9jVI0+ifBztg9e1tR5mG1Q==" }, "ig-types": { - "version": "3.7.12", - "resolved": "https://registry.npmjs.org/ig-types/-/ig-types-3.7.12.tgz", - "integrity": "sha512-Qp5N79XLq+BvLyxJAn/JNVwt+IWmedQdHBUCImeZ57MJiX6e2I/EZ79D16xU4r866RAEwFFBSsm7q9RWoVNuBg==", + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/ig-types/-/ig-types-4.1.0.tgz", + "integrity": "sha512-FTpXOA5bZUkRup1vJ4cD76/zkXPtjaFHLp9oNbP18qDUc0pEB/pLx8fdgNDwYGDWnFhetx0pMTuP11KOh2urTA==", "requires": { - "ig-object": "^5.4.2", + "ig-object": "^5.4.11", "object-run": "^1.0.1" } }, diff --git a/Viewer/package.json b/Viewer/package.json index 849c348e..49a306f1 100755 --- a/Viewer/package.json +++ b/Viewer/package.json @@ -31,8 +31,8 @@ "ig-actions": "^3.24.11", "ig-argv": "^2.15.0", "ig-features": "^3.4.2", - "ig-object": "^5.4.9", - "ig-types": "^3.7.12", + "ig-object": "^5.4.11", + "ig-types": "^4.1.0", "moment": "^2.29.1", "object-run": "^1.0.1", "requirejs": "^2.3.6",