mirror of
				https://github.com/flynx/ImageGrid.git
				synced 2025-11-04 13:20:10 +00:00 
			
		
		
		
	added changes monitoring, now only what was touched is written...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									32211cbbe3
								
							
						
					
					
						commit
						2d77869306
					
				@ -555,24 +555,47 @@ module.buildIndex = function(index, base_path){
 | 
				
			|||||||
// 	.tags
 | 
					// 	.tags
 | 
				
			||||||
// 	.current
 | 
					// 	.current
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
// NOTE: this will prepare for version 2.0 file structure...
 | 
					 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
// XXX write tags, marks and bookmarks only if changed...
 | 
					// changes can be:
 | 
				
			||||||
// XXX this is not yet correct...
 | 
					// 	true | null		- write all
 | 
				
			||||||
 | 
					// 	false			- write only .current
 | 
				
			||||||
 | 
					// 	<detailed-format>
 | 
				
			||||||
 | 
					// 					- see below...
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					// changes detailed format:
 | 
				
			||||||
 | 
					// 	{
 | 
				
			||||||
 | 
					// 		data: <bool>,
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					// 		images: <bool> | { <gid>, ... }
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					// 		tags: <bool>,
 | 
				
			||||||
 | 
					// 		bookmarked: <bool>,
 | 
				
			||||||
 | 
					// 		selected: <bool>,
 | 
				
			||||||
 | 
					// 	}
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					// NOTE: this will prepare for version 2.0 file structure...
 | 
				
			||||||
var prepareIndex =
 | 
					var prepareIndex =
 | 
				
			||||||
module.prepareIndex =
 | 
					module.prepareIndex =
 | 
				
			||||||
function(json, changes){
 | 
					function(json, changes){
 | 
				
			||||||
	changes = changes || {}
 | 
						changes = changes === false ? false
 | 
				
			||||||
 | 
							: changes == null ? true
 | 
				
			||||||
 | 
							: changes
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// always save current...
 | 
				
			||||||
	var res = {
 | 
						var res = {
 | 
				
			||||||
		data: json.data,
 | 
					 | 
				
			||||||
		current: json.data.current,
 | 
							current: json.data.current,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if(json.data.tags != null){
 | 
						// data...
 | 
				
			||||||
 | 
						if(changes === true || changes && changes.data){
 | 
				
			||||||
 | 
							res.data = json.data
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// tags...
 | 
				
			||||||
 | 
						if(changes === true || changes && json.data.tags != null){
 | 
				
			||||||
		// NOTE: we write the whole set ONLY if an item is true or undefined
 | 
							// NOTE: we write the whole set ONLY if an item is true or undefined
 | 
				
			||||||
		// 		i.e. not false...
 | 
							// 		i.e. not false...
 | 
				
			||||||
		if(changes.bookmarked !== false){
 | 
							if(changes === true || changes.bookmarked){
 | 
				
			||||||
			res.bookmarked = [
 | 
								res.bookmarked = [
 | 
				
			||||||
				json.data.tags.bookmark || [], 
 | 
									json.data.tags.bookmark || [], 
 | 
				
			||||||
				// NOTE: this is for bookmark metadata line comments, text,
 | 
									// NOTE: this is for bookmark metadata line comments, text,
 | 
				
			||||||
@ -582,29 +605,31 @@ function(json, changes){
 | 
				
			|||||||
			]
 | 
								]
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if(changes.selected !== false){
 | 
							if(changes === true || changes.selected){
 | 
				
			||||||
			res.marked = json.data.tags.selected || []
 | 
								res.marked = json.data.tags.selected || []
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if(changes.tags !== false){
 | 
							if(changes === true || changes.tags){
 | 
				
			||||||
			res.tags = json.data.tags
 | 
								res.tags = json.data.tags
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// clean out some stuff from data...
 | 
							// clean out some stuff from data...
 | 
				
			||||||
		delete res.data.tags.bookmark
 | 
							if(res.data){
 | 
				
			||||||
		delete res.data.tags.bookmark_data
 | 
								delete res.data.tags.bookmark
 | 
				
			||||||
		delete res.data.tags.selected
 | 
								delete res.data.tags.bookmark_data
 | 
				
			||||||
		delete res.data.tags
 | 
								delete res.data.tags.selected
 | 
				
			||||||
 | 
								delete res.data.tags
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if(changes.images){
 | 
						if(changes === true || changes && changes.images === true){
 | 
				
			||||||
 | 
							res.images = json.images
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						} else if(changes && changes.images){
 | 
				
			||||||
		var diff = res['images-diff'] = {}
 | 
							var diff = res['images-diff'] = {}
 | 
				
			||||||
		changes.images.forEach(function(gid){
 | 
							changes.images.forEach(function(gid){
 | 
				
			||||||
			diff[gid] = json.images[gid]
 | 
								diff[gid] = json.images[gid]
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		res.images = json.images
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return res
 | 
						return res
 | 
				
			||||||
 | 
				
			|||||||
@ -3790,6 +3790,9 @@ var FileSystemWriterActions = actions.Actions({
 | 
				
			|||||||
		//'index-filename-template': '${DATE}-${KEYWORD}.${EXT}',
 | 
							//'index-filename-template': '${DATE}-${KEYWORD}.${EXT}',
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// XXX is this a good name???
 | 
				
			||||||
 | 
						chages: null,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// This is here so as other features can participate in index
 | 
						// This is here so as other features can participate in index
 | 
				
			||||||
	// preparation...
 | 
						// preparation...
 | 
				
			||||||
	// There are several stages features can control the output format:
 | 
						// There are several stages features can control the output format:
 | 
				
			||||||
@ -3814,11 +3817,12 @@ var FileSystemWriterActions = actions.Actions({
 | 
				
			|||||||
	// 	}
 | 
						// 	}
 | 
				
			||||||
	//
 | 
						//
 | 
				
			||||||
	prepareIndexForWrite: ['File/Prepare index for writing',
 | 
						prepareIndexForWrite: ['File/Prepare index for writing',
 | 
				
			||||||
		function(json){
 | 
							function(json, full){
 | 
				
			||||||
			json = json || this.json('base')
 | 
								json = json || this.json('base')
 | 
				
			||||||
 | 
								var changes = full ? null : this.changes
 | 
				
			||||||
			return {
 | 
								return {
 | 
				
			||||||
				raw: json,
 | 
									raw: json,
 | 
				
			||||||
				prepared: file.prepareIndex(json),
 | 
									prepared: file.prepareIndex(json, changes),
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}],
 | 
							}],
 | 
				
			||||||
	// XXX get real base path...
 | 
						// XXX get real base path...
 | 
				
			||||||
@ -3849,6 +3853,7 @@ var FileSystemWriterActions = actions.Actions({
 | 
				
			|||||||
	exportView: ['File/Export current view',
 | 
						exportView: ['File/Export current view',
 | 
				
			||||||
		function(){
 | 
							function(){
 | 
				
			||||||
		}],
 | 
							}],
 | 
				
			||||||
 | 
						// XXX not done yet...
 | 
				
			||||||
	// XXX export current state as a full loadable index
 | 
						// XXX export current state as a full loadable index
 | 
				
			||||||
	// XXX might be interesting to unify this and .exportView(..)
 | 
						// XXX might be interesting to unify this and .exportView(..)
 | 
				
			||||||
	// XXX local collections???
 | 
						// XXX local collections???
 | 
				
			||||||
@ -3917,6 +3922,109 @@ module.FileSystemWriter = ImageGridFeatures.Feature({
 | 
				
			|||||||
	isApplicable: function(){
 | 
						isApplicable: function(){
 | 
				
			||||||
		return window.nodejs != null
 | 
							return window.nodejs != null
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// monitor changes...
 | 
				
			||||||
 | 
						handlers: [
 | 
				
			||||||
 | 
							// loaders: clear changes...
 | 
				
			||||||
 | 
							// XXX currently if no args are passed then nothing is 
 | 
				
			||||||
 | 
							// 		done here, this might change...
 | 
				
			||||||
 | 
							[[
 | 
				
			||||||
 | 
								'loadIndex',
 | 
				
			||||||
 | 
								'saveIndex',
 | 
				
			||||||
 | 
							].join(' '), 
 | 
				
			||||||
 | 
								function(_, path){
 | 
				
			||||||
 | 
									// XXX currently if no args are passed then nothing is 
 | 
				
			||||||
 | 
									// 		done here, this might change...
 | 
				
			||||||
 | 
									if(path){
 | 
				
			||||||
 | 
										this.changes = false 
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}],
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// everything changed...
 | 
				
			||||||
 | 
							[[
 | 
				
			||||||
 | 
								'loadURLs',
 | 
				
			||||||
 | 
							].join(' '), 
 | 
				
			||||||
 | 
								function(_, target){
 | 
				
			||||||
 | 
									delete this.changes
 | 
				
			||||||
 | 
								}],
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// data...
 | 
				
			||||||
 | 
							[[
 | 
				
			||||||
 | 
								//'clear',
 | 
				
			||||||
 | 
								//'load',
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								'setBaseRibbon',
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								'shiftImageTo',
 | 
				
			||||||
 | 
								'shiftImageUp',
 | 
				
			||||||
 | 
								'shiftImageDown',
 | 
				
			||||||
 | 
								'shiftImageLeft',
 | 
				
			||||||
 | 
								'shiftImageRight',
 | 
				
			||||||
 | 
								'shiftRibbonUp',
 | 
				
			||||||
 | 
								'shiftRibbonDown',
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								'sortImages',
 | 
				
			||||||
 | 
								'reverseImages',
 | 
				
			||||||
 | 
								'reverseRibbons',
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								'group',
 | 
				
			||||||
 | 
								'ungroup',
 | 
				
			||||||
 | 
								'expandGroup',
 | 
				
			||||||
 | 
								'collapseGroup',
 | 
				
			||||||
 | 
							].join(' '), 
 | 
				
			||||||
 | 
								function(_, target){
 | 
				
			||||||
 | 
									var changes = this.changes = this.changes || {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									changes.data = true
 | 
				
			||||||
 | 
								}],
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// image specific...
 | 
				
			||||||
 | 
							[[
 | 
				
			||||||
 | 
								'rotateCW',
 | 
				
			||||||
 | 
								'rotateCCW',
 | 
				
			||||||
 | 
								'flipHorizontal',
 | 
				
			||||||
 | 
								'flipVertical',
 | 
				
			||||||
 | 
							].join(' '), 
 | 
				
			||||||
 | 
								function(_, target){
 | 
				
			||||||
 | 
									var changes = this.changes = this.changes || {}
 | 
				
			||||||
 | 
									var images = changes.images = changes.images || []
 | 
				
			||||||
 | 
									target = this.data.getImage(target)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									images.push(target)
 | 
				
			||||||
 | 
								}],
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// tags and images...
 | 
				
			||||||
 | 
							// NOTE: tags are also stored in images...
 | 
				
			||||||
 | 
							['tag untag',
 | 
				
			||||||
 | 
								function(_, tags, gids){
 | 
				
			||||||
 | 
									var changes = this.changes = this.changes || {}
 | 
				
			||||||
 | 
									var images = changes.images = changes.images || []
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									gids = gids || [this.data.getImage()]
 | 
				
			||||||
 | 
									gids = gids.constructor !== Array ? [this.data.getImage(gids)] : gids
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									tags = tags || []
 | 
				
			||||||
 | 
									tags = tags.constructor !== Array ? [tags] : tags
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									// images...
 | 
				
			||||||
 | 
									changes.images = images.concat(gids).unique()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									// tags...
 | 
				
			||||||
 | 
									if(tags.length > 0){
 | 
				
			||||||
 | 
										changes.tags = true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
										// selected...
 | 
				
			||||||
 | 
										if(tags.indexOf('selected') >= 0){
 | 
				
			||||||
 | 
											changes.selected = true
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
										// bookmark...
 | 
				
			||||||
 | 
										if(tags.indexOf('bookmark') >= 0){
 | 
				
			||||||
 | 
											changes.bookmarked = true
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}],
 | 
				
			||||||
 | 
						]
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user