mirror of
				https://github.com/flynx/ImageGrid.git
				synced 2025-10-31 03:10:07 +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 | ||||
| * 		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: { | ||||
| 	}, | ||||
|  | ||||
| @ -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) }) })], | ||||
|  | ||||
| @ -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', | ||||
|  | ||||
| @ -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...
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user