mirror of
				https://github.com/flynx/ImageGrid.git
				synced 2025-10-31 03:10:07 +00:00 
			
		
		
		
	tweaking and refactoring...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									b64bbba033
								
							
						
					
					
						commit
						966977faa8
					
				| @ -653,6 +653,7 @@ jQuery.fn.sortChildren = function(func){ | ||||
| //
 | ||||
| //
 | ||||
| // XXX should this be an object or a factory???
 | ||||
| // XXX add a clean handler removal scheme (a-la jQuery event on/off)
 | ||||
| function makeDeferredPool(size, paused){ | ||||
| 	size = size == null ? POOL_SIZE : size | ||||
| 	size = size < 0 ? 1  | ||||
| @ -660,6 +661,15 @@ function makeDeferredPool(size, paused){ | ||||
| 		: size | ||||
| 	paused = paused == null ? false : paused | ||||
| 
 | ||||
| 	var event_names = [ | ||||
| 		'deplete', | ||||
| 		'progress', | ||||
| 		'pause', | ||||
| 		// XXX
 | ||||
| 		//'resume',
 | ||||
| 		'fail', | ||||
| 	] | ||||
| 
 | ||||
| 	var Pool = { | ||||
| 		pool: [], | ||||
| 		queue: [], | ||||
| @ -834,6 +844,17 @@ function makeDeferredPool(size, paused){ | ||||
| 		return this | ||||
| 	} | ||||
| 
 | ||||
| 
 | ||||
| 	// Generic event handlers...
 | ||||
| 	Pool.on = function(evt, handler){ | ||||
| 		// XXX
 | ||||
| 		return this | ||||
| 	} | ||||
| 	Pool.off = function(evt, handler){ | ||||
| 		// XXX
 | ||||
| 		return this | ||||
| 	} | ||||
| 
 | ||||
| 	// Register a queue depleted handler...
 | ||||
| 	//
 | ||||
| 	// This occurs when a populated queue is depleted and the last worker
 | ||||
|  | ||||
							
								
								
									
										147
									
								
								ui/workers.js
									
									
									
									
									
								
							
							
						
						
									
										147
									
								
								ui/workers.js
									
									
									
									
									
								
							| @ -12,87 +12,106 @@ var WORKERS = {} | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| /**************************************************** Progress bar ***/ | ||||
| 
 | ||||
| // NOTE: if the progress widget gets removed without removing the worker
 | ||||
| // 		this will result in dangling handlers for the previous widget...
 | ||||
| // 		i.e. handlers that still reverence the original widget...
 | ||||
| //
 | ||||
| // XXX add a clean removal scheme...
 | ||||
| // XXX should this have a pause button???
 | ||||
| function makeWorkerProgressBar(name, worker, parent){ | ||||
| 	parent = parent == null ? $('.viewer') : parent | ||||
| 
 | ||||
| 	// widget container...
 | ||||
| 	var container = parent.find('.progress-container') | ||||
| 	if(container.length == 0){ | ||||
| 		container = $('<div class="progress-container"/>') | ||||
| 			.appendTo(parent) | ||||
| 	} | ||||
| 
 | ||||
| 	var widget = $('.progress-bar[name="'+name+'"]') | ||||
| 
 | ||||
| 	// a progress bar already exists, reset it and return...
 | ||||
| 	if(widget.length > 0){ | ||||
| 		widget | ||||
| 			.css('display', '') | ||||
| 			.find('.close') | ||||
| 				.css('display', '') | ||||
| 		widget.find('progress') | ||||
| 			.attr({ | ||||
| 				value: '', | ||||
| 				max: '' | ||||
| 			}) | ||||
| 		return worker | ||||
| 	} | ||||
| 
 | ||||
| 	// fields we'll need to update...
 | ||||
| 	var state = $('<span class="state"/>') | ||||
| 	var bar = $('<progress/>') | ||||
| 
 | ||||
| 	// the progress bar widget...
 | ||||
| 	var widget = $('<div class="progress-bar" name="'+name+'">'+name+'</div>') | ||||
| 		// progress state...
 | ||||
| 		.append(state) | ||||
| 		// the close button...
 | ||||
| 		.append($('<span class="close">×</span>') | ||||
| 			.click(function(){ | ||||
| 				$(this).hide() | ||||
| 				WORKERS[name] | ||||
| 					.dropQueue() | ||||
| 			})) | ||||
| 		.append(bar) | ||||
| 		.appendTo(container) | ||||
| 
 | ||||
| 	// re get the fields...
 | ||||
| 	bar = $(bar[0]) | ||||
| 	state = $(state[0]) | ||||
| 
 | ||||
| 	worker | ||||
| 		.progress(function(done, total){ | ||||
| 			bar.attr({ | ||||
| 				value: done, | ||||
| 				max: total | ||||
| 			}) | ||||
| 			state.text(' ('+done+' of '+total+')') | ||||
| 		}) | ||||
| 		.depleted(function(done){ | ||||
| 			bar.attr('value', done) | ||||
| 			state.text(' (done)') | ||||
| 
 | ||||
| 			setTimeout(function(){ | ||||
| 				widget.hide() | ||||
| 			}, 1500) | ||||
| 		}) | ||||
| 
 | ||||
| 	return worker | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| /********************************************************* Workers ***/ | ||||
| 
 | ||||
| // get/create a named worker queue...
 | ||||
| //
 | ||||
| // XXX rename this to something task-related.... (???)
 | ||||
| function getWorkerQueue(name, pool_size, no_auto_start, no_progress){ | ||||
| 	// XXX 1 is the default for compatibility...
 | ||||
| 	pool_size = pool_size == null ? 1 : pool_size | ||||
| 
 | ||||
| 	// XXX experimental -- STUB...
 | ||||
| 	if(!no_progress){ | ||||
| 		// widget container...
 | ||||
| 		var container = $('.progress-container') | ||||
| 		if(container.length == 0){ | ||||
| 			container = $('<div class="progress-container"/>') | ||||
| 				.appendTo($('.viewer')) | ||||
| 		} | ||||
| 		// the progress bar widget...
 | ||||
| 		var progress = $('<div class="progress-bar">'+name+'</div>') | ||||
| 			.appendTo(container) | ||||
| 		// progress state...
 | ||||
| 		var progress_state = $('<span class="state"/>') | ||||
| 			.appendTo(progress) | ||||
| 		// the close button...
 | ||||
| 		$('<span class="close">×</span>') | ||||
| 			.click(function(){ | ||||
| 				$(this).remove() | ||||
| 				WORKERS[name] | ||||
| 					.dropQueue() | ||||
| 					/* | ||||
| 					.depleted(function(){ | ||||
| 						delete WORKERS[name] | ||||
| 					}) | ||||
| 					*/ | ||||
| 			}) | ||||
| 			.appendTo(progress) | ||||
| 
 | ||||
| 		var progress_bar = $('<progress id="'+name+'"/>') | ||||
| 			.appendTo(progress) | ||||
| 
 | ||||
| 		// XXX for some reason without this, here the progress handlers 
 | ||||
| 		// 		later lose context...
 | ||||
| 		progress = $(progress[0]) | ||||
| 		progress_bar = $(progress_bar[0]) | ||||
| 	} | ||||
| 
 | ||||
| 	// create a new worker queue...
 | ||||
| 	if(WORKERS[name] == null){ | ||||
| 		var queue = makeDeferredPool(pool_size, no_auto_start) | ||||
| 		WORKERS[name] = queue | ||||
| 
 | ||||
| 		// XXX experimental...
 | ||||
| 		if(!no_progress){ | ||||
| 			queue | ||||
| 				.progress(function(done, total){ | ||||
| 					progress_bar | ||||
| 						.attr({ | ||||
| 							value: done, | ||||
| 							max: total | ||||
| 						}) | ||||
| 					progress_state | ||||
| 						.text(' ('+done+' of '+total+')') | ||||
| 				}) | ||||
| 				.depleted(function(done){ | ||||
| 					progress_bar | ||||
| 						.attr('value', done) | ||||
| 					progress_state | ||||
| 						.text(' (done)') | ||||
| 
 | ||||
| 					setTimeout(function(){ | ||||
| 						progress | ||||
| 							.remove() | ||||
| 					}, 1500) | ||||
| 				}) | ||||
| 		} | ||||
| 
 | ||||
| 	// return existing worker queue...
 | ||||
| 	} else { | ||||
| 		var queue = WORKERS[name] | ||||
| 	} | ||||
| 
 | ||||
| 	if(!no_progress){ | ||||
| 		makeWorkerProgressBar(name, queue) | ||||
| 	} | ||||
| 
 | ||||
| 	return queue | ||||
| } | ||||
| 
 | ||||
| @ -107,6 +126,7 @@ function getWorkerQueue(name, pool_size, no_auto_start, no_progress){ | ||||
| // 		actually stop...
 | ||||
| // NOTE: if no workers are loaded or all are already done, the deferred
 | ||||
| // 		returned will be resolved...
 | ||||
| // NOTE: this will also kill paused workers...
 | ||||
| function killAllWorkers(){ | ||||
| 	var res = $.Deferred() | ||||
| 	var w = [] | ||||
| @ -131,6 +151,7 @@ function killAllWorkers(){ | ||||
| 		.done(function(){ | ||||
| 			console.log('Worker: All workers stopped.') | ||||
| 			res.resolve() | ||||
| 			$('.progress-bar').remove() | ||||
| 		}) | ||||
| 
 | ||||
| 	return res | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user