mirror of
				https://github.com/flynx/ImageGrid.git
				synced 2025-10-31 11:20:09 +00:00 
			
		
		
		
	now .readMetadata() is implemented via core.tasks...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									fa8b6d57cd
								
							
						
					
					
						commit
						2a75ed6530
					
				| @ -35,7 +35,8 @@ | |||||||
| * 	- workspace | * 	- workspace | ||||||
| * 		XXX needs revision... | * 		XXX needs revision... | ||||||
| * 	- tasks | * 	- tasks | ||||||
| * 		XXX not yet used | * 		tasks -- manage long running actions | ||||||
|  | * 		queue -- manage lots of small actions as a single task | ||||||
| * 	- self-test | * 	- self-test | ||||||
| * 		basic framework for running test actions at startup... | * 		basic framework for running test actions at startup... | ||||||
| * | * | ||||||
| @ -2494,11 +2495,25 @@ function(func){ | |||||||
| 	func.__queued__ = true | 	func.__queued__ = true | ||||||
| 	return func } | 	return func } | ||||||
| 
 | 
 | ||||||
|  | // 
 | ||||||
|  | //	queuedAction(name, func)
 | ||||||
|  | //	queuedAction(name, options, func)
 | ||||||
|  | //		-> action
 | ||||||
|  | //
 | ||||||
|  | //	func(..)
 | ||||||
|  | //		-> res
 | ||||||
|  | //
 | ||||||
|  | //	action(..)
 | ||||||
|  | //		-> promise(res)
 | ||||||
|  | //
 | ||||||
|  | //
 | ||||||
| // NOTE: for examples see:
 | // NOTE: for examples see:
 | ||||||
| // 		features/examples.js: 
 | // 		features/examples.js: 
 | ||||||
| // 			ExampleActions.exampleQueuedAction(..)
 | // 			ExampleActions.exampleQueuedAction(..)
 | ||||||
| // 			ExampleActions.exampleMultipleQueuedAction(..)
 | // 			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 
 | // XXX the general use-case here is to call the queue method multiple 
 | ||||||
| // 		times for instance to handle array elements, might be nice to
 | // 		times for instance to handle array elements, might be nice to
 | ||||||
| // 		automate this...
 | // 		automate this...
 | ||||||
| @ -2514,9 +2529,13 @@ function(name, func){ | |||||||
| 	return object.mixin( | 	return object.mixin( | ||||||
| 		Queued(function(...args){ | 		Queued(function(...args){ | ||||||
| 			var that = this | 			var that = this | ||||||
| 			return this.queue(name, opts || {}) | 			// XXX handle errors... (???)
 | ||||||
| 				.push(function(){ | 			return new Promise(function(resolve, reject){ | ||||||
| 					return func.call(that, ...args) }) }), | 				that.queue(name, opts || {}) | ||||||
|  | 					.push(function(){ | ||||||
|  | 						var res = func.call(that, ...args)  | ||||||
|  | 						resolve(res) | ||||||
|  | 						return res }) }) }), | ||||||
|    		{ |    		{ | ||||||
| 			toString: function(){ | 			toString: function(){ | ||||||
| 				return `core.queuedAction('${name}',\n\t${  | 				return `core.queuedAction('${name}',\n\t${  | ||||||
| @ -2547,10 +2566,8 @@ function(func){ | |||||||
| // 			var action = taskAction('some title', 'sync', function(..){ .. })
 | // 			var action = taskAction('some title', 'sync', function(..){ .. })
 | ||||||
| // 		or
 | // 		or
 | ||||||
| // 			var action = taskAction('sync', 'some title', function(..){ .. })
 | // 			var action = taskAction('sync', 'some title', function(..){ .. })
 | ||||||
| //
 |  | ||||||
| // 		and on call:
 | // 		and on call:
 | ||||||
| // 			action('sync', ..)
 | // 			action('sync', ..)
 | ||||||
| //
 |  | ||||||
| // 		during the later form 'sync' is passed to .Task(..) in the correct
 | // 		during the later form 'sync' is passed to .Task(..) in the correct
 | ||||||
| // 		position...
 | // 		position...
 | ||||||
| // 		(see ig-types' runner.TaskManager(..) for more info)
 | // 		(see ig-types' runner.TaskManager(..) for more info)
 | ||||||
| @ -2588,6 +2605,7 @@ function(title, func){ | |||||||
| // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 | ||||||
| 
 | 
 | ||||||
| // XXX add a task manager UI...
 | // XXX add a task manager UI...
 | ||||||
|  | // XXX do we need to cache the lister props???
 | ||||||
| var TaskActions = actions.Actions({ | var TaskActions = actions.Actions({ | ||||||
| 	config: { | 	config: { | ||||||
| 	}, | 	}, | ||||||
|  | |||||||
| @ -270,7 +270,7 @@ var ExampleActions = actions.Actions({ | |||||||
| 	// Tasks...
 | 	// Tasks...
 | ||||||
| 	 | 	 | ||||||
| 	exampleQueuedAction: ['- Test/', | 	exampleQueuedAction: ['- Test/', | ||||||
| 		core.queuedAction('exampleQueuedAction', function(timeout=500, ...args){ | 		core.queuedAction('exampleQueuedAction', {quiet: true}, function(timeout=500, ...args){ | ||||||
| 			console.log('Queued action!!', ...args) | 			console.log('Queued action!!', ...args) | ||||||
| 			return new Promise(function(resolve){ | 			return new Promise(function(resolve){ | ||||||
| 				setTimeout(resolve, timeout) }) })], | 				setTimeout(resolve, timeout) }) })], | ||||||
|  | |||||||
| @ -119,7 +119,7 @@ var MetadataReaderActions = actions.Actions({ | |||||||
| 
 | 
 | ||||||
| 		NOTE: also see: .cacheMetadata(..) | 		NOTE: also see: .cacheMetadata(..) | ||||||
| 		`,
 | 		`,
 | ||||||
| 		function(image, force){ | 		core.queuedAction('readMetadata', function(image, force){ | ||||||
| 			var that = this | 			var that = this | ||||||
| 
 | 
 | ||||||
| 			var gid = this.data.getImage(image) | 			var gid = this.data.getImage(image) | ||||||
| @ -179,33 +179,15 @@ var MetadataReaderActions = actions.Actions({ | |||||||
| 							that.markChanged  | 							that.markChanged  | ||||||
| 								&& that.markChanged('images', [gid]) } | 								&& 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', | 	readAllMetadata: ['File/Read all metadata', | ||||||
| 		function(){ | 		function(){ | ||||||
| 			var that = this | 			var that = this | ||||||
| 			// XXX make this a global API...
 | 			//var logger = this.logger && this.logger.push('Read metadata')
 | ||||||
| 			var q = this.__reader_queue = this.__reader_queue || tasks.Queue() | 			return this.images.keys() | ||||||
| 
 | 				.mapChunks(7, function(gid){ | ||||||
| 			var logger = this.logger && this.logger.push('Read metadata') | 					return that.readMetadata(gid) }) }], | ||||||
| 
 |  | ||||||
| 			// 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 }], |  | ||||||
| 
 | 
 | ||||||
| 	// XXX take image Metadata and write it to target...
 | 	// XXX take image Metadata and write it to target...
 | ||||||
| 	writeMetadata: ['- Image/Set metadata data', | 	writeMetadata: ['- Image/Set metadata data', | ||||||
|  | |||||||
| @ -447,10 +447,9 @@ module.ImagesPrototype = { | |||||||
| 		for(e of this){ | 		for(e of this){ | ||||||
| 			yield e } }, | 			yield e } }, | ||||||
| 
 | 
 | ||||||
| 	// XXX remove version...
 |  | ||||||
| 	keys: function(){ | 	keys: function(){ | ||||||
| 		var keys = Object.keys(this) | 		var keys = Object.keys(this) | ||||||
| 		var i = keys.indexOf('version') | 		var i = keys.lastIndexOf('version') | ||||||
| 		i >= 0 | 		i >= 0 | ||||||
| 			&& keys.splice(i, 1) | 			&& keys.splice(i, 1) | ||||||
| 		return keys }, | 		return keys }, | ||||||
| @ -557,6 +556,7 @@ module.ImagesPrototype = { | |||||||
| 			size: preview_size, | 			size: preview_size, | ||||||
| 		} }, | 		} }, | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| 	// Get image filename...
 | 	// Get image filename...
 | ||||||
| 	//
 | 	//
 | ||||||
| 	// NOTE: this will default to gid if not filename (.path) is set... (???)
 | 	// NOTE: this will default to gid if not filename (.path) is set... (???)
 | ||||||
| @ -604,7 +604,9 @@ module.ImagesPrototype = { | |||||||
| 		return this | 		return this | ||||||
| 	}, | 	}, | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| 	// Gid sorters...
 | 	// Gid sorters...
 | ||||||
|  | 	//
 | ||||||
| 	// XXX might be a good idea to add caching...
 | 	// XXX might be a good idea to add caching...
 | ||||||
| 	// XXX chainCmp(..) is loaded from lib/jli.js
 | 	// XXX chainCmp(..) is loaded from lib/jli.js
 | ||||||
| 	sortImages: function(gids, cmp, reverse){ | 	sortImages: function(gids, cmp, reverse){ | ||||||
| @ -626,6 +628,7 @@ module.ImagesPrototype = { | |||||||
| 		// XXX see ../ui/sort.js
 | 		// XXX see ../ui/sort.js
 | ||||||
| 	}, | 	}, | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| 	// Actions...
 | 	// Actions...
 | ||||||
| 
 | 
 | ||||||
| 	// Rotate image...
 | 	// Rotate image...
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user