From 2a75ed6530008de5aec6164b092d208a507a22ec Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Wed, 2 Dec 2020 04:47:53 +0300 Subject: [PATCH] now .readMetadata() is implemented via core.tasks... Signed-off-by: Alex A. Naanou --- Viewer/features/core.js | 32 +++++++++++++++++++++++++------- Viewer/features/examples.js | 2 +- Viewer/features/metadata.js | 30 ++++++------------------------ Viewer/imagegrid/images.js | 7 +++++-- 4 files changed, 37 insertions(+), 34 deletions(-) diff --git a/Viewer/features/core.js b/Viewer/features/core.js index ed8e2cbb..b7b7b7f9 100755 --- a/Viewer/features/core.js +++ b/Viewer/features/core.js @@ -35,7 +35,8 @@ * - workspace * XXX needs revision... * - tasks -* XXX not yet used +* tasks -- manage long running actions +* queue -- manage lots of small actions as a single task * - self-test * basic framework for running test actions at startup... * @@ -2494,11 +2495,25 @@ function(func){ func.__queued__ = true return func } +// +// queuedAction(name, func) +// queuedAction(name, options, func) +// -> action +// +// func(..) +// -> res +// +// action(..) +// -> promise(res) +// +// // NOTE: for examples see: // features/examples.js: // ExampleActions.exampleQueuedAction(..) // ExampleActions.exampleMultipleQueuedAction(..) - +// +// XXX need to pass a nice log prompt... +// XXX can we return anything other than a promise here??? // XXX the general use-case here is to call the queue method multiple // times for instance to handle array elements, might be nice to // automate this... @@ -2514,9 +2529,13 @@ function(name, func){ return object.mixin( Queued(function(...args){ var that = this - return this.queue(name, opts || {}) - .push(function(){ - return func.call(that, ...args) }) }), + // XXX handle errors... (???) + return new Promise(function(resolve, reject){ + that.queue(name, opts || {}) + .push(function(){ + var res = func.call(that, ...args) + resolve(res) + return res }) }) }), { toString: function(){ return `core.queuedAction('${name}',\n\t${ @@ -2547,10 +2566,8 @@ function(func){ // var action = taskAction('some title', 'sync', function(..){ .. }) // or // var action = taskAction('sync', 'some title', function(..){ .. }) -// // and on call: // action('sync', ..) -// // during the later form 'sync' is passed to .Task(..) in the correct // position... // (see ig-types' runner.TaskManager(..) for more info) @@ -2588,6 +2605,7 @@ function(title, func){ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // XXX add a task manager UI... +// XXX do we need to cache the lister props??? var TaskActions = actions.Actions({ config: { }, diff --git a/Viewer/features/examples.js b/Viewer/features/examples.js index f37e6b95..0915564e 100755 --- a/Viewer/features/examples.js +++ b/Viewer/features/examples.js @@ -270,7 +270,7 @@ var ExampleActions = actions.Actions({ // Tasks... exampleQueuedAction: ['- Test/', - core.queuedAction('exampleQueuedAction', function(timeout=500, ...args){ + core.queuedAction('exampleQueuedAction', {quiet: true}, function(timeout=500, ...args){ console.log('Queued action!!', ...args) return new Promise(function(resolve){ setTimeout(resolve, timeout) }) })], diff --git a/Viewer/features/metadata.js b/Viewer/features/metadata.js index dc864a52..5ca9ee70 100755 --- a/Viewer/features/metadata.js +++ b/Viewer/features/metadata.js @@ -119,7 +119,7 @@ var MetadataReaderActions = actions.Actions({ NOTE: also see: .cacheMetadata(..) `, - function(image, force){ + core.queuedAction('readMetadata', function(image, force){ var that = this var gid = this.data.getImage(image) @@ -179,33 +179,15 @@ var MetadataReaderActions = actions.Actions({ that.markChanged && that.markChanged('images', [gid]) } - resolve(data) }) }) }) }], + resolve(data) }) }) }) })], - // XXX make this abortable... - // XXX STUB: add support for this to .readMetadata(..) readAllMetadata: ['File/Read all metadata', function(){ var that = this - // XXX make this a global API... - var q = this.__reader_queue = this.__reader_queue || tasks.Queue() - - var logger = this.logger && this.logger.push('Read metadata') - - // XXX is this the right way to go??? - q.on('taskQueued', function(t){ logger.emit('queued', t) }) - q.on('taskDone', function(t){ logger.emit('done', t) }) - q.on('taskFailed', function(t){ logger.emit('error', t) }) - - var read = function(gid){ - return function(){ return that.readMetadata(gid) } } - - q.start() - - this.images - && this.images.forEach(function(gid){ - q.enqueue('metadata', read(gid)) }) - - return q }], + //var logger = this.logger && this.logger.push('Read metadata') + return this.images.keys() + .mapChunks(7, function(gid){ + return that.readMetadata(gid) }) }], // XXX take image Metadata and write it to target... writeMetadata: ['- Image/Set metadata data', diff --git a/Viewer/imagegrid/images.js b/Viewer/imagegrid/images.js index ff9294b0..226b81b8 100755 --- a/Viewer/imagegrid/images.js +++ b/Viewer/imagegrid/images.js @@ -447,10 +447,9 @@ module.ImagesPrototype = { for(e of this){ yield e } }, - // XXX remove version... keys: function(){ var keys = Object.keys(this) - var i = keys.indexOf('version') + var i = keys.lastIndexOf('version') i >= 0 && keys.splice(i, 1) return keys }, @@ -557,6 +556,7 @@ module.ImagesPrototype = { size: preview_size, } }, + // Get image filename... // // NOTE: this will default to gid if not filename (.path) is set... (???) @@ -604,7 +604,9 @@ module.ImagesPrototype = { return this }, + // Gid sorters... + // // XXX might be a good idea to add caching... // XXX chainCmp(..) is loaded from lib/jli.js sortImages: function(gids, cmp, reverse){ @@ -626,6 +628,7 @@ module.ImagesPrototype = { // XXX see ../ui/sort.js }, + // Actions... // Rotate image...