| 
									
										
										
										
											2016-11-04 23:00:34 +03:00
										 |  |  | /********************************************************************** | 
					
						
							|  |  |  | *  | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | **********************************************************************/ | 
					
						
							|  |  |  | ((typeof define)[0]=='u'?function(f){module.exports=f(require)}:define)( | 
					
						
							|  |  |  | function(require){ var module={} // makes module AMD/node compatible...
 | 
					
						
							|  |  |  | /*********************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var actions = require('lib/actions') | 
					
						
							|  |  |  | var features = require('lib/features') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var core = require('features/core') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*********************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var ProgressActions = actions.Actions({ | 
					
						
							|  |  |  | 	config: { | 
					
						
							|  |  |  | 		'progress-fade-duration': 200, | 
					
						
							|  |  |  | 		'progress-done-delay': 1000, | 
					
						
							| 
									
										
										
										
											2020-07-09 02:19:43 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		'progress-update-min': 200, | 
					
						
							| 
									
										
										
										
											2016-11-04 23:00:34 +03:00
										 |  |  | 	}, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Progress bar widget...
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// 	Create progress bar...
 | 
					
						
							| 
									
										
										
										
											2016-12-12 15:29:37 +03:00
										 |  |  | 	// 	.showProgress('text')
 | 
					
						
							| 
									
										
										
										
											2016-11-04 23:00:34 +03:00
										 |  |  | 	//
 | 
					
						
							|  |  |  | 	// 	Update progress bar (value, max, msg)...
 | 
					
						
							| 
									
										
										
										
											2016-12-12 15:29:37 +03:00
										 |  |  | 	// 	.showProgress('text', 0, 10)
 | 
					
						
							|  |  |  | 	// 	.showProgress('text', 10, 50, 'message')
 | 
					
						
							| 
									
										
										
										
											2016-11-04 23:00:34 +03:00
										 |  |  | 	//
 | 
					
						
							|  |  |  | 	// 	Update progress bar value (has no effect if max is not set)...
 | 
					
						
							| 
									
										
										
										
											2016-12-12 15:29:37 +03:00
										 |  |  | 	// 	.showProgress('text', 10)
 | 
					
						
							| 
									
										
										
										
											2016-11-04 23:00:34 +03:00
										 |  |  | 	//
 | 
					
						
							|  |  |  | 	// 	Close progress bar...
 | 
					
						
							| 
									
										
										
										
											2016-12-12 15:29:37 +03:00
										 |  |  | 	// 	.showProgress('text', 'close')
 | 
					
						
							| 
									
										
										
										
											2016-11-04 23:00:34 +03:00
										 |  |  | 	//
 | 
					
						
							|  |  |  | 	// 	Relative progress modification...
 | 
					
						
							| 
									
										
										
										
											2016-12-12 15:29:37 +03:00
										 |  |  | 	// 	.showProgress('text', '+1')
 | 
					
						
							|  |  |  | 	// 	.showProgress('text', '+0', '+1')
 | 
					
						
							| 
									
										
										
										
											2016-11-04 23:00:34 +03:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2020-07-09 02:19:43 +03:00
										 |  |  | 	// 	.showProgress(logger)
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2016-11-04 23:00:34 +03:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2020-04-07 18:13:52 +03:00
										 |  |  | 	// XXX add message to be shown...
 | 
					
						
							| 
									
										
										
										
											2016-11-04 23:00:34 +03:00
										 |  |  | 	// XXX should we report errors and stoppages??? (error state??)
 | 
					
						
							|  |  |  | 	// XXX multiple containers...
 | 
					
						
							| 
									
										
										
										
											2016-11-06 01:58:32 +03:00
										 |  |  | 	// XXX shorten the nested css class names...
 | 
					
						
							| 
									
										
										
										
											2016-11-04 23:00:34 +03:00
										 |  |  | 	// XXX revise styles...
 | 
					
						
							| 
									
										
										
										
											2020-07-09 02:19:43 +03:00
										 |  |  | 	__progress_cache: null, | 
					
						
							| 
									
										
										
										
											2016-11-04 23:00:34 +03:00
										 |  |  | 	showProgress: ['- Interface/Show progress bar...', | 
					
						
							|  |  |  | 		function(text, value, max){ | 
					
						
							|  |  |  | 			var that = this | 
					
						
							| 
									
										
										
										
											2020-07-09 02:19:43 +03:00
										 |  |  | 			var viewer = this.dom | 
					
						
							| 
									
										
										
										
											2016-11-04 23:00:34 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			var msg = text instanceof Array ? text.slice(1).join(': ') : null | 
					
						
							|  |  |  | 			text = text instanceof Array ? text[0] : text | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-09 02:19:43 +03:00
										 |  |  | 			// make sure we do not update too often...
 | 
					
						
							|  |  |  | 			if(value != 'close'){ | 
					
						
							|  |  |  | 				var cache = (this.__progress_cache = this.__progress_cache || {}) | 
					
						
							|  |  |  | 				cache = cache[text] = cache[text] || {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				var updateValue = function(name, value){ | 
					
						
							|  |  |  | 					var v = cache[name] || 0 | 
					
						
							|  |  |  | 					return (cache[name] =  | 
					
						
							|  |  |  | 						value != null ?  | 
					
						
							|  |  |  | 							(typeof(value) == typeof('str') && /[+-][0-9]+/.test(value) ?  | 
					
						
							|  |  |  | 								v + parseInt(value) | 
					
						
							|  |  |  | 								: parseInt(value)) | 
					
						
							|  |  |  | 							: v) } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				value = updateValue('value', value) | 
					
						
							|  |  |  | 				max = updateValue('max', max) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				// update not due yet...
 | 
					
						
							|  |  |  | 				if('timeout' in cache){ | 
					
						
							|  |  |  | 					cache.update = true | 
					
						
							|  |  |  | 					return  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				// set next update point and continue...
 | 
					
						
							|  |  |  | 				} else { | 
					
						
							|  |  |  | 					delete cache.update | 
					
						
							|  |  |  | 					cache.timeout = setTimeout( | 
					
						
							|  |  |  | 						function(){ | 
					
						
							|  |  |  | 							var cache = that.__progress_cache[text] || {} | 
					
						
							|  |  |  | 							delete cache.timeout | 
					
						
							|  |  |  | 							cache.update | 
					
						
							|  |  |  | 								&& that.showProgress(text) },  | 
					
						
							|  |  |  | 						this.config['progress-update-min'] || 200) } } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-04 23:00:34 +03:00
										 |  |  | 			// container...
 | 
					
						
							|  |  |  | 			var container = viewer.find('.progress-container') | 
					
						
							|  |  |  | 			container = container.length == 0 ? | 
					
						
							|  |  |  | 				$('<div/>') | 
					
						
							|  |  |  | 					.addClass('progress-container') | 
					
						
							|  |  |  | 					.appendTo(viewer) | 
					
						
							|  |  |  | 				: container | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// widget...
 | 
					
						
							|  |  |  | 			var widget = container.find('.progress-bar[name="'+text+'"]') | 
					
						
							|  |  |  | 			// close action...
 | 
					
						
							|  |  |  | 			if(value == 'close'){ | 
					
						
							|  |  |  | 				widget.trigger('progressClose') | 
					
						
							| 
									
										
										
										
											2020-07-09 02:19:43 +03:00
										 |  |  | 				return } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-04 23:00:34 +03:00
										 |  |  | 			widget = widget.length == 0 ? | 
					
						
							|  |  |  | 				$('<div/>') | 
					
						
							|  |  |  | 					.addClass('progress-bar') | 
					
						
							|  |  |  | 					.attr('name', text) | 
					
						
							|  |  |  | 					.text(text) | 
					
						
							|  |  |  | 					// close button...
 | 
					
						
							|  |  |  | 					.append($('<span class="close">×</span>') | 
					
						
							|  |  |  | 						.on('click', function(){ widget.trigger('progressClose') })) | 
					
						
							|  |  |  | 					// state...
 | 
					
						
							|  |  |  | 					.append($('<span/>') | 
					
						
							|  |  |  | 						.addClass('progress-details')) | 
					
						
							|  |  |  | 					// bar...
 | 
					
						
							|  |  |  | 					.append($('<progress/>')) | 
					
						
							|  |  |  | 					// events...
 | 
					
						
							|  |  |  | 					.on('progressClose', function(){  | 
					
						
							|  |  |  | 						widget | 
					
						
							|  |  |  | 							.fadeOut(that.config['progress-fade-duration'] || 200, function(){ | 
					
						
							| 
									
										
										
										
											2020-07-09 02:19:43 +03:00
										 |  |  | 								var cache = (that.__progress_cache || {}) | 
					
						
							|  |  |  | 								cache[text].timeout  | 
					
						
							|  |  |  | 									&& clearTimeout(cache[text].timeout) | 
					
						
							|  |  |  | 								delete cache[text] | 
					
						
							| 
									
										
										
										
											2020-04-09 23:34:28 +03:00
										 |  |  | 								$(this).remove() }) }) | 
					
						
							| 
									
										
										
										
											2016-11-04 23:00:34 +03:00
										 |  |  | 					.appendTo(container) | 
					
						
							|  |  |  | 				: widget | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// reset closing timeout...
 | 
					
						
							|  |  |  | 			var timeout = widget.attr('close-timeout') | 
					
						
							|  |  |  | 			timeout && clearTimeout(JSON.parse(timeout)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// get the widget parts we are updating...
 | 
					
						
							|  |  |  | 			var bar = widget.find('progress') | 
					
						
							|  |  |  | 			var state = widget.find('.progress-details') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// format the message...
 | 
					
						
							|  |  |  | 			msg = msg ? ': '+msg : '' | 
					
						
							|  |  |  | 			msg = ' '+ msg  | 
					
						
							|  |  |  | 				+ (value && value >= (max || 0) ? ' (done)'  | 
					
						
							| 
									
										
										
										
											2020-07-09 02:19:43 +03:00
										 |  |  | 					: max && value != max ? ' ('+ (value || 0) +' of '+ max +')' | 
					
						
							| 
									
										
										
										
											2016-11-04 23:00:34 +03:00
										 |  |  | 					: '...') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// update widget...
 | 
					
						
							|  |  |  | 			bar.attr({ | 
					
						
							|  |  |  | 				value: value || '', | 
					
						
							|  |  |  | 				max: max || '', | 
					
						
							|  |  |  | 			}) | 
					
						
							|  |  |  | 			state.text(msg) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// auto-close...
 | 
					
						
							|  |  |  | 			if(value && value >= (max || 0)){ | 
					
						
							|  |  |  | 				widget.attr('close-timeout',  | 
					
						
							|  |  |  | 					JSON.stringify(setTimeout(function(){  | 
					
						
							|  |  |  | 						widget.trigger('progressClose')  | 
					
						
							| 
									
										
										
										
											2020-07-09 02:19:43 +03:00
										 |  |  | 					}, this.config['progress-done-delay'] || 1000))) } | 
					
						
							| 
									
										
										
										
											2016-11-04 23:00:34 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-07 09:34:49 +03:00
										 |  |  | 			// XXX force the browser to render...
 | 
					
						
							|  |  |  | 			//bar.hide(0).show(0)
 | 
					
						
							| 
									
										
										
										
											2016-11-04 23:00:34 +03:00
										 |  |  | 		}], | 
					
						
							| 
									
										
										
										
											2020-04-10 19:10:21 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// handle logger progress...
 | 
					
						
							|  |  |  | 	// XXX revise...
 | 
					
						
							|  |  |  | 	handleLogItem: ['- System/', | 
					
						
							|  |  |  | 		function(path, status, ...rest){ | 
					
						
							| 
									
										
										
										
											2020-07-09 02:19:43 +03:00
										 |  |  | 			var msg = path.join(': ') | 
					
						
							|  |  |  | 			var l = (rest.length == 1 && rest[0] instanceof Array) ? | 
					
						
							|  |  |  | 				rest[0].length | 
					
						
							|  |  |  | 				: rest.length | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// XXX should we move these to a more accessible spot???
 | 
					
						
							|  |  |  | 			var add = [ | 
					
						
							|  |  |  | 				'added', | 
					
						
							|  |  |  | 				'queued', | 
					
						
							|  |  |  | 				'found', | 
					
						
							|  |  |  | 			] | 
					
						
							|  |  |  | 			var done = [ | 
					
						
							|  |  |  | 				'loaded', | 
					
						
							|  |  |  | 				'done', | 
					
						
							|  |  |  | 				'written', | 
					
						
							|  |  |  | 				'index', | 
					
						
							|  |  |  | 			] | 
					
						
							|  |  |  | 			var skipped = [ | 
					
						
							|  |  |  | 				'skipping', | 
					
						
							|  |  |  | 				'skipped', | 
					
						
							|  |  |  | 				'removed', | 
					
						
							|  |  |  | 			] | 
					
						
							| 
									
										
										
										
											2020-04-10 19:10:21 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-10 04:07:45 +03:00
										 |  |  | 			// close...
 | 
					
						
							|  |  |  | 			// XXX is the right keyword...
 | 
					
						
							|  |  |  | 			if(status == 'done' && rest.length == 0){ | 
					
						
							|  |  |  | 				this.showProgress(path, 'close') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-10 19:10:21 +03:00
										 |  |  | 			// report progress...
 | 
					
						
							|  |  |  | 			// XXX HACK -- need meaningful status...
 | 
					
						
							| 
									
										
										
										
											2020-07-10 04:07:45 +03:00
										 |  |  | 			} else if(add.includes(status)){ | 
					
						
							|  |  |  | 				this.showProgress(path, '+0', '+'+l) | 
					
						
							| 
									
										
										
										
											2020-04-10 19:10:21 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-09 02:19:43 +03:00
										 |  |  | 			} else if(done.includes(status)){ | 
					
						
							| 
									
										
										
										
											2020-07-10 04:07:45 +03:00
										 |  |  | 				this.showProgress(path, '+'+l) | 
					
						
							| 
									
										
										
										
											2020-04-10 19:10:21 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-09 02:19:43 +03:00
										 |  |  | 			} else if(skipped.includes(status)){ | 
					
						
							| 
									
										
										
										
											2020-04-10 19:10:21 +03:00
										 |  |  | 				// XXX if everything is skipped the indicator does not 
 | 
					
						
							|  |  |  | 				// 		get hidden...
 | 
					
						
							| 
									
										
										
										
											2020-07-10 04:07:45 +03:00
										 |  |  | 				this.showProgress(path, '+'+l) | 
					
						
							| 
									
										
										
										
											2020-04-10 19:10:21 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			// XXX STUB...
 | 
					
						
							|  |  |  | 			} else if(status == 'error' ){ | 
					
						
							| 
									
										
										
										
											2020-07-09 02:19:43 +03:00
										 |  |  | 				this.showProgress(['Error'].concat(msg), '+0', '+'+l) | 
					
						
							| 
									
										
										
										
											2020-04-10 19:10:21 +03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		}], | 
					
						
							| 
									
										
										
										
											2016-11-04 23:00:34 +03:00
										 |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var Progress =  | 
					
						
							|  |  |  | module.Progress = core.ImageGridFeatures.Feature({ | 
					
						
							|  |  |  | 	title: '', | 
					
						
							|  |  |  | 	doc: '', | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	tag: 'ui-progress', | 
					
						
							|  |  |  | 	depends: [ | 
					
						
							|  |  |  | 		'ui', | 
					
						
							|  |  |  | 	], | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	actions: ProgressActions,  | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /********************************************************************** | 
					
						
							|  |  |  | * vim:set ts=4 sw=4 :                               */ return module }) |