mirror of
				https://github.com/flynx/ImageGrid.git
				synced 2025-10-30 19:00:09 +00:00 
			
		
		
		
	reworking file API reporting, new scheme, almost sure about this...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									02f93f3067
								
							
						
					
					
						commit
						cd7128279a
					
				
							
								
								
									
										138
									
								
								ui/data.js
									
									
									
									
									
								
							
							
						
						
									
										138
									
								
								ui/data.js
									
									
									
									
									
								
							| @ -1196,7 +1196,7 @@ function loadLatestFile(path, dfl, pattern, diff_pattern){ | |||||||
| 	 | 	 | ||||||
| 	// can't find diffs if can't list dirs...
 | 	// can't find diffs if can't list dirs...
 | ||||||
| 	if(window.listDir == null && (pattern != null || diff_pattern != null)){ | 	if(window.listDir == null && (pattern != null || diff_pattern != null)){ | ||||||
| 		res.notify('unsupported', 'directory listing.') | 		res.notify('Unsupported', 'directory listing.') | ||||||
| 		return res.reject('listDir unsupported.') | 		return res.reject('listDir unsupported.') | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| @ -1223,10 +1223,11 @@ function loadLatestFile(path, dfl, pattern, diff_pattern){ | |||||||
| 					return $.getJSON(path +'/'+ e) | 					return $.getJSON(path +'/'+ e) | ||||||
| 						.done(function(data){ | 						.done(function(data){ | ||||||
| 							diff_data[i+1] = data | 							diff_data[i+1] = data | ||||||
| 							res.notify('loaded', e) | 							res.notify('Loaded', e) | ||||||
| 						}) | 						}) | ||||||
| 						.fail(function(){ | 						.fail(function(){ | ||||||
| 							res.notify('load_error', e) | 							// XXX should we kill the load here???
 | ||||||
|  | 							res.notify('Loading', e, 'Error') | ||||||
| 						}) | 						}) | ||||||
| 				})) | 				})) | ||||||
| 			// NOTE: .then(...) handlers get different signature args 
 | 			// NOTE: .then(...) handlers get different signature args 
 | ||||||
| @ -1242,18 +1243,18 @@ function loadLatestFile(path, dfl, pattern, diff_pattern){ | |||||||
| 		.done(function(_, json){ | 		.done(function(_, json){ | ||||||
| 			json = json[0] | 			json = json[0] | ||||||
| 
 | 
 | ||||||
| 			res.notify('loaded', file) | 			res.notify('Loaded', file) | ||||||
| 
 | 
 | ||||||
| 			// merge diffs...
 | 			// merge diffs...
 | ||||||
| 			if(Object.keys(diff_data).length != 0){ | 			if(Object.keys(diff_data).length != 0){ | ||||||
| 				$.extend(json, diff_data) | 				$.extend(json, diff_data) | ||||||
| 				res.notify('merged') | 				res.notify('Merged') | ||||||
| 			} | 			} | ||||||
| 
 | 
 | ||||||
| 			res.resolve(json) | 			res.resolve(json) | ||||||
| 		}) | 		}) | ||||||
| 		.fail(function(){ | 		.fail(function(){ | ||||||
| 			res.notify('load_error', file) | 			res.notify('Loading', file, 'Error') | ||||||
| 
 | 
 | ||||||
| 			return res.reject(file) | 			return res.reject(file) | ||||||
| 		}) | 		}) | ||||||
| @ -1264,37 +1265,41 @@ function loadLatestFile(path, dfl, pattern, diff_pattern){ | |||||||
| 
 | 
 | ||||||
| function statusNotify(prefix, loader){ | function statusNotify(prefix, loader){ | ||||||
| 	return loader | 	return loader | ||||||
| 		.progress(function(a, b, c){ | 		.progress(function(){ | ||||||
| 			if(c != null){ | 			var args = Array.apply(null, arguments) | ||||||
| 				prefix = prefix +' '+ a | 			args.splice(0, 0, prefix) | ||||||
| 				var action = b | 			if(args.indexOf('Error') >= 0){ | ||||||
| 				var data = c | 				args.pop() | ||||||
| 			} else { | 				return showErrorStatus(args.join(': ')) | ||||||
| 				var action = a | 			} | ||||||
| 				var data = b | 			return showStatus(args.join(': ')) | ||||||
|  | 		}) | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | // XXX do we need other actions here???
 | ||||||
|  | function bubbleProgress(prefix, from, to, only_progress){ | ||||||
|  | 	from | ||||||
|  | 		.progress(function(){  | ||||||
|  | 			var args = Array.apply(null, arguments) | ||||||
|  | 			prefix != null && args.splice(0, 0, prefix) | ||||||
|  | 			to.notify.apply(to, args)  | ||||||
|  | 		}) | ||||||
|  | 
 | ||||||
|  | 	if(only_progress == null){ | ||||||
|  | 		from | ||||||
|  | 			.done(function(){ | ||||||
|  | 				var args = Array.apply(null, arguments) | ||||||
|  | 				to.resolve.apply(to, args)  | ||||||
|  | 			}) | ||||||
|  | 			.fail(function(){ | ||||||
|  | 				var args = Array.apply(null, arguments) | ||||||
|  | 				prefix != null && args.splice(0, 0, prefix) | ||||||
|  | 				to.reject.apply(to, args)  | ||||||
|  | 			}) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 			({ | 	return from | ||||||
| 				load: function(data){  |  | ||||||
| 					showStatus(prefix, 'Loading:', data)  |  | ||||||
| 				}, |  | ||||||
| 				loaded: function(data){  |  | ||||||
| 					showStatus(prefix, 'Loaded:', data)  |  | ||||||
| 				}, |  | ||||||
| 				merged: function(data){  |  | ||||||
| 					showStatus(prefix, 'Merging:', 'Done.')  |  | ||||||
| 				}, |  | ||||||
| 				load_error: function(data){  |  | ||||||
| 					showErrorStatus(prefix, 'Loading:', data)  |  | ||||||
| 				}, |  | ||||||
| 				unsupported: function(data){  |  | ||||||
| 					showErrorStatus(prefix, 'Unsupported:', data)  |  | ||||||
| 				}, |  | ||||||
| 			})[action](data) |  | ||||||
| 		}) |  | ||||||
| 		.done(function(){ |  | ||||||
| 			showStatus(prefix, 'Done.') |  | ||||||
| 		}) |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @ -1311,7 +1316,7 @@ if(window.CEF_dumpJSON != null){ | |||||||
| // Load images from file
 | // Load images from file
 | ||||||
| //
 | //
 | ||||||
| // This will also merge all diff files.
 | // This will also merge all diff files.
 | ||||||
| function loadFileImages(path, no_load_diffs, callback){ | function loadFileImages(path, no_load_diffs){ | ||||||
| 	no_load_diffs = window.listDir == null ? true : no_load_diffs  | 	no_load_diffs = window.listDir == null ? true : no_load_diffs  | ||||||
| 
 | 
 | ||||||
| 	var res = $.Deferred() | 	var res = $.Deferred() | ||||||
| @ -1337,18 +1342,10 @@ function loadFileImages(path, no_load_diffs, callback){ | |||||||
| 				RegExp(path.split(base)[0])) | 				RegExp(path.split(base)[0])) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	loader | 	bubbleProgress('Images', loader, res) | ||||||
| 		// XXX find a good way to propagate...
 |  | ||||||
| 		.progress(function(action, data){  |  | ||||||
| 			res.notify('Images:', action, data)  |  | ||||||
| 		}) |  | ||||||
| 		.done(function(data){ |  | ||||||
| 			res.resolve(data) |  | ||||||
| 		}) |  | ||||||
| 
 | 
 | ||||||
| 	res.done(function(images){ | 	res.done(function(images){ | ||||||
| 		IMAGES = images | 		IMAGES = images | ||||||
| 		callback != null ? callback() : null |  | ||||||
| 	}) | 	}) | ||||||
| 
 | 
 | ||||||
| 	return res | 	return res | ||||||
| @ -1387,14 +1384,14 @@ function saveFileImages(name){ | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| function loadFileMarks(path, callback){ | function loadFileMarks(path){ | ||||||
|  | 	var res = $.Deferred() | ||||||
| 	// default locations...
 | 	// default locations...
 | ||||||
| 	if(path == null){ | 	if(path == null){ | ||||||
| 		var base = normalizePath(CACHE_DIR) | 		var base = normalizePath(CACHE_DIR) | ||||||
| 		var res = statusNotify('Marks:', | 		var loader = loadLatestFile(base,  | ||||||
| 			loadLatestFile(base,  |  | ||||||
| 				MARKED_FILE_DEFAULT,  | 				MARKED_FILE_DEFAULT,  | ||||||
| 				MARKED_FILE_PATTERN)) | 				MARKED_FILE_PATTERN) | ||||||
| 	 | 	 | ||||||
| 	// explicit path...
 | 	// explicit path...
 | ||||||
| 	// XXX need to account for paths without a CACHE_DIR
 | 	// XXX need to account for paths without a CACHE_DIR
 | ||||||
| @ -1404,15 +1401,15 @@ function loadFileMarks(path, callback){ | |||||||
| 		base += '/'+ CACHE_DIR | 		base += '/'+ CACHE_DIR | ||||||
| 
 | 
 | ||||||
| 		// XXX is this correct???
 | 		// XXX is this correct???
 | ||||||
| 		var res = statusNotify('Marks:', | 		var loader = loadLatestFile(base,  | ||||||
| 			loadLatestFile(base,  |  | ||||||
| 				path.split(base)[0],  | 				path.split(base)[0],  | ||||||
| 				RegExp(path.split(base)[0]))) | 				RegExp(path.split(base)[0])) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | 	bubbleProgress('Marks', loader, res) | ||||||
|  | 
 | ||||||
| 	res.done(function(images){ | 	res.done(function(images){ | ||||||
| 		MARKED = images | 		MARKED = images | ||||||
| 		callback != null ? callback() : null |  | ||||||
| 	}) | 	}) | ||||||
| 
 | 
 | ||||||
| 	return res | 	return res | ||||||
| @ -1438,10 +1435,10 @@ function loadFileState(path){ | |||||||
| 
 | 
 | ||||||
| 	var res = $.Deferred() | 	var res = $.Deferred() | ||||||
| 
 | 
 | ||||||
| 	statusNotify('Data:',  | 	bubbleProgress('Data', | ||||||
| 			loadLatestFile(path,  | 			loadLatestFile(path,  | ||||||
| 				DATA_FILE_DEFAULT,  | 				DATA_FILE_DEFAULT,  | ||||||
| 				DATA_FILE_PATTERN)) | 				DATA_FILE_PATTERN), res, true) | ||||||
| 		.done(function(json){ | 		.done(function(json){ | ||||||
| 			BASE_URL = base | 			BASE_URL = base | ||||||
| 
 | 
 | ||||||
| @ -1457,6 +1454,7 @@ function loadFileState(path){ | |||||||
| 			// version 2.0
 | 			// version 2.0
 | ||||||
| 			} else if(json.version == '2.0') { | 			} else if(json.version == '2.0') { | ||||||
| 				DATA = json | 				DATA = json | ||||||
|  | 				bubbleProgress('Data', | ||||||
| 						$.when( | 						$.when( | ||||||
| 								// XXX load config...
 | 								// XXX load config...
 | ||||||
| 								// load images...
 | 								// load images...
 | ||||||
| @ -1464,7 +1462,7 @@ function loadFileState(path){ | |||||||
| 										normalizePath(DATA.image_file, base)  | 										normalizePath(DATA.image_file, base)  | ||||||
| 										: null), | 										: null), | ||||||
| 								// load marks if available...
 | 								// load marks if available...
 | ||||||
| 						loadFileMarks()) | 								loadFileMarks()), res, true) | ||||||
| 					.done(function(){ | 					.done(function(){ | ||||||
| 						reloadViewer() | 						reloadViewer() | ||||||
| 						res.resolve() | 						res.resolve() | ||||||
| @ -1474,10 +1472,9 @@ function loadFileState(path){ | |||||||
| 			} else { | 			} else { | ||||||
| 				res.reject('unknown format.') | 				res.reject('unknown format.') | ||||||
| 			} | 			} | ||||||
| 
 |  | ||||||
| 		}) | 		}) | ||||||
| 		.fail(function(){ | 		.fail(function(){ | ||||||
| 			res.reject('load_error', path) | 			res.reject('Loading', path, 'Error') | ||||||
| 		}) | 		}) | ||||||
| 
 | 
 | ||||||
| 	return res | 	return res | ||||||
| @ -1524,21 +1521,21 @@ function loadRawDir(path){ | |||||||
| 	}) | 	}) | ||||||
| 
 | 
 | ||||||
| 	if(image_paths.length == 0){ | 	if(image_paths.length == 0){ | ||||||
| 		//showErrorStatus('No images in:', path)
 | 		// no images in path...
 | ||||||
| 		res.notify('load_error', path) | 		res.notify('Load', path, 'Error') | ||||||
| 		return res.reject() | 		return res.reject() | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	BASE_URL = path | 	BASE_URL = path | ||||||
| 
 | 
 | ||||||
| 	IMAGES = imagesFromUrls(image_paths) | 	IMAGES = imagesFromUrls(image_paths) | ||||||
| 	res.notify('loaded', 'images.') | 	res.notify('Loaded', 'Images.') | ||||||
| 
 | 
 | ||||||
| 	DATA = dataFromImages(IMAGES) | 	DATA = dataFromImages(IMAGES) | ||||||
| 	res.notify('loaded', 'data.') | 	res.notify('Loaded', 'Data.') | ||||||
| 
 | 
 | ||||||
| 	DATA.ribbons = ribbonsFromFavDirs() | 	DATA.ribbons = ribbonsFromFavDirs() | ||||||
| 	res.notify('loaded', 'fav dirs.') | 	res.notify('Loaded', 'Fav dirs.') | ||||||
| 
 | 
 | ||||||
| 	MARKED = [] | 	MARKED = [] | ||||||
| 
 | 
 | ||||||
| @ -1585,22 +1582,13 @@ function loadDir(path){ | |||||||
| 		path = path +'/'+ CACHE_DIR | 		path = path +'/'+ CACHE_DIR | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	statusNotify('Dir:', loadFileState(path)) | 	bubbleProgress('Dir:',  | ||||||
| 		//.progress(function(action, data){
 | 			loadFileState(path), res, true) | ||||||
| 		//	res.notify(action, data)
 |  | ||||||
| 		//})
 |  | ||||||
| 		.done(function(){ | 		.done(function(){ | ||||||
| 			res.resolve() | 			res.resolve() | ||||||
| 		}) | 		}) | ||||||
| 		.fail(function(){ | 		.fail(function(){ | ||||||
| 			statusNotify('Raw dir:', loadRawDir(orig_path)) | 			bubbleProgress('Raw dir:', loadRawDir(orig_path), res) | ||||||
| 				.done(function(){ |  | ||||||
| 					res.resolve() |  | ||||||
| 				}) |  | ||||||
| 				.fail(function(){ |  | ||||||
| 					res.reject() |  | ||||||
| 				}) |  | ||||||
| 				 |  | ||||||
| 		}) | 		}) | ||||||
| 
 | 
 | ||||||
| 	return res | 	return res | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user