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:
Alex A. Naanou 2015-12-07 07:07:50 +03:00
parent 32211cbbe3
commit 2d77869306
2 changed files with 152 additions and 19 deletions

View File

@ -555,24 +555,47 @@ module.buildIndex = function(index, base_path){
// .tags
// .current
//
// NOTE: this will prepare for version 2.0 file structure...
//
// XXX write tags, marks and bookmarks only if changed...
// XXX this is not yet correct...
// changes can be:
// 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 =
module.prepareIndex =
function(json, changes){
changes = changes || {}
changes = changes === false ? false
: changes == null ? true
: changes
// always save current...
var res = {
data: json.data,
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
// i.e. not false...
if(changes.bookmarked !== false){
if(changes === true || changes.bookmarked){
res.bookmarked = [
json.data.tags.bookmark || [],
// 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 || []
}
if(changes.tags !== false){
if(changes === true || changes.tags){
res.tags = json.data.tags
}
// clean out some stuff from data...
delete res.data.tags.bookmark
delete res.data.tags.bookmark_data
delete res.data.tags.selected
delete res.data.tags
if(res.data){
delete res.data.tags.bookmark
delete res.data.tags.bookmark_data
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'] = {}
changes.images.forEach(function(gid){
diff[gid] = json.images[gid]
})
} else {
res.images = json.images
}
return res

View File

@ -3790,6 +3790,9 @@ var FileSystemWriterActions = actions.Actions({
//'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
// preparation...
// There are several stages features can control the output format:
@ -3814,11 +3817,12 @@ var FileSystemWriterActions = actions.Actions({
// }
//
prepareIndexForWrite: ['File/Prepare index for writing',
function(json){
function(json, full){
json = json || this.json('base')
var changes = full ? null : this.changes
return {
raw: json,
prepared: file.prepareIndex(json),
prepared: file.prepareIndex(json, changes),
}
}],
// XXX get real base path...
@ -3849,6 +3853,7 @@ var FileSystemWriterActions = actions.Actions({
exportView: ['File/Export current view',
function(){
}],
// XXX not done yet...
// XXX export current state as a full loadable index
// XXX might be interesting to unify this and .exportView(..)
// XXX local collections???
@ -3917,6 +3922,109 @@ module.FileSystemWriter = ImageGridFeatures.Feature({
isApplicable: function(){
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
}
}
}],
]
})