tweaking, cleanup + started work on export...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2015-12-06 06:21:37 +03:00
parent 6df64958ed
commit 07ff3f9b38
4 changed files with 123 additions and 41 deletions

View File

@ -569,31 +569,33 @@ function(json, changes){
current: json.data.current, current: json.data.current,
} }
// NOTE: we write the whole set ONLY if an item is true or undefined if(json.data.tags != null){
// i.e. not false... // NOTE: we write the whole set ONLY if an item is true or undefined
if(changes.bookmarked !== false){ // i.e. not false...
res.bookmarked = [ if(changes.bookmarked !== false){
json.data.tags.bookmark, res.bookmarked = [
// NOTE: this is for bookmark metadata line comments, text, json.data.tags.bookmark || [],
// tags, ... etc. // NOTE: this is for bookmark metadata line comments, text,
// XXX currently this is not used... // tags, ... etc.
json.data.bookmark_data || {}, // XXX currently this is not used...
] json.data.bookmark_data || {},
} ]
}
if(changes.selected !== false){ if(changes.selected !== false){
res.marked = json.data.tags.selected res.marked = json.data.tags.selected || []
} }
if(changes.tags !== false){ if(changes.tags !== false){
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 delete res.data.tags.bookmark
delete res.data.tags.bookmark_data delete res.data.tags.bookmark_data
delete res.data.tags.selected delete res.data.tags.selected
delete res.data.tags delete res.data.tags
}
if(changes.images){ if(changes.images){
var diff = res['images-diff'] = {} var diff = res['images-diff'] = {}

View File

@ -279,16 +279,23 @@ module.makeImageSeqOrNameCmp = function(data, get, seq){
var ImagesClassPrototype = var ImagesClassPrototype =
module.ImagesClassPrototype = { module.ImagesClassPrototype = {
// XXX populate the image doc better... // XXX populate the image doc better...
fromArray: function(data){ // NOTE: if base is given then it will be set as .base_path and
// removed from each url if present...
fromArray: function(data, base){
var images = new this() var images = new this()
// XXX stub... // XXX stub...
var i = 0 var i = 0
var base_pattern = base ? RegExp('^' + base) : null
data.forEach(function(path){ data.forEach(function(path){
var gid = hash('I'+i) var gid = hash('I'+i)
// XXX populate the image doc better... // XXX populate the image doc better...
images[gid] = { images[gid] = {
id: gid, id: gid,
path: path, path: base_pattern ? path.replace(base_pattern, './') : path,
}
// remove only of base path is given and in path...
if(base && base_pattern.test(path)){
images[gid].base_path = base
} }
i += 1 i += 1
}) })

View File

@ -254,7 +254,7 @@ function Action(name, doc, ldoc, func){
//res = h.apply(that, args) //res = h.apply(that, args)
res = h.apply(that, res = h.apply(that,
[results[0] !== undefined ? [results[0] !== undefined ?
reults[0] results[0]
: that].concat(args)) : that].concat(args))
// deferred... // deferred...

View File

@ -263,10 +263,10 @@ actions.Actions({
// XXX should this be here??? // XXX should this be here???
loadURLs: ['File/Load a URL list', loadURLs: ['File/Load a URL list',
function(lst){ function(lst, base){
this.clear() this.clear()
this.images = images.Images.fromArray(lst) this.images = images.Images.fromArray(lst, base)
this.data = data.Data.fromArray(this.images.keys()) this.data = data.Data.fromArray(this.images.keys())
}], }],
@ -675,8 +675,6 @@ actions.Actions({
// crop... // crop...
// //
// XXX should we keep this isolated or should we connect stuff like
// tags, ...
crop: ['Crop/Crop image list', crop: ['Crop/Crop image list',
function(list, flatten){ function(list, flatten){
list = list || this.data.order list = list || this.data.order
@ -3338,12 +3336,31 @@ if(window.nodejs != null){
// .loaded_paths // .loaded_paths
var FileSystemLoaderActions = actions.Actions({ var FileSystemLoaderActions = actions.Actions({
config: { config: {
//'index-dir': '.ImageGrid', 'index-dir': '.ImageGrid',
}, },
// NOTE: these will remove the trailing '/' (or '\') unless the path
// is root...
// ...this is mainly to facilitate better browse support, i.e.
// to open the dir (open parent + select current) and not
// within the dir
// XXX need to revise these... // XXX need to revise these...
// XXX should there be a loaded path and a requested path??? // XXX should there be a loaded path and a requested path???
base_path: null, get base_path(){
var b = this._base_path
if(b && b != '/' && b != '\\'){
b = b.replace(/[\/\\]+$/, '')
}
return b
},
// XXX use .loadPath(..)
set base_path(value){
if(value != '/' && value != '\\'){
value = value.replace(/[\/\\]+$/, '')
}
this._base_path = value
this.loadIndex(value)
},
loaded_paths: null, loaded_paths: null,
// NOTE: when passed no path this will not do anything... // NOTE: when passed no path this will not do anything...
@ -3450,7 +3467,7 @@ var FileSystemLoaderActions = actions.Actions({
that.loaded_paths = loaded that.loaded_paths = loaded
// XXX should we get the requested path or the base path currently loaded // XXX should we get the requested path or the base path currently loaded
//that.base_path = loaded.length == 1 ? loaded[0] : path //that.base_path = loaded.length == 1 ? loaded[0] : path
that.base_path = loaded.length == 1 ? loaded[0] : path that._base_path = loaded.length == 1 ? loaded[0] : path
that.load(index) that.load(index)
}) })
@ -3468,20 +3485,29 @@ var FileSystemLoaderActions = actions.Actions({
return glob(path + '/*+(jpg|png)') return glob(path + '/*+(jpg|png)')
.on('end', function(lst){ .on('end', function(lst){
that.loadURLs(lst) that.loadURLs(lst, path)
// XXX not sure if this is the way to go... // XXX not sure if this is the way to go...
that.base_path = path that._base_path = path
}) })
}], }],
// XXX auto-detect format or let the user chose... // XXX auto-detect format or let the user chose...
loadPath: ['File/Load path (STUB)', loadPath: ['File/Load path (STUB)',
function(path, logger){
// XXX check if this.config['index-dir'] exists, if yes then
// .loadIndex(..) else .loadImages(..)
}],
// XXX
loadNewImages: ['File/Load new and not indexed images',
function(){ function(){
// XXX list images and add ones that are not in .images
// XXX
}], }],
clear: [function(){ clear: [function(){
delete this.base_path delete this._base_path
delete this.loaded_paths delete this.loaded_paths
}], }],
}) })
@ -3663,6 +3689,7 @@ var FileSystemWriterActions = actions.Actions({
// // saved. // // saved.
// prepared: <prepared-json>, // prepared: <prepared-json>,
// } // }
//
prepareIndexForWrite: ['File/Prepare index for writing', prepareIndexForWrite: ['File/Prepare index for writing',
function(json){ function(json){
json = json || this.json('base') json = json || this.json('base')
@ -3671,7 +3698,6 @@ var FileSystemWriterActions = actions.Actions({
prepared: file.prepareIndex(json), prepared: file.prepareIndex(json),
} }
}], }],
// XXX should this get the base uncropped state or the current state???
// XXX get real base path... // XXX get real base path...
saveIndex: ['File/Save index', saveIndex: ['File/Save index',
function(path, logger){ function(path, logger){
@ -3689,7 +3715,9 @@ var FileSystemWriterActions = actions.Actions({
file.writeIndex( file.writeIndex(
this.prepareIndexForWrite().prepared, this.prepareIndexForWrite().prepared,
path, // XXX should we check if index dir is present in path???
//path,
path +'/'+ this.config['index-dir'],
this.config['index-filename-template'], this.config['index-filename-template'],
logger || this.logger) logger || this.logger)
}], }],
@ -3699,9 +3727,55 @@ var FileSystemWriterActions = actions.Actions({
function(){ function(){
}], }],
// XXX export current state as a full loadable index // XXX export current state as a full loadable index
// XXX might be interresting to unify this and .exportView(..) // XXX might be interesting to unify this and .exportView(..)
// XXX local collections???
exportCollection: ['File/Export as collection', exportCollection: ['File/Export as collection',
function(){ function(path, logger){
var json = this.json()
// get all loaded gids...
var gids = []
for(var r in json.data.ribbons){
this.data.makeSparseImages(json.data.ribbons[r], gids)
}
gids = gids.compact()
// build .images with loaded images...
// XXX list of previews should be configurable (max size)
var images = {}
gids.forEach(function(gid){
var img = json.images[gid]
if(img){
images[gid] = json.images[gid]
// remove un-needed previews...
// XXX
}
})
// prepare and save index to target path...
json.data.order = gids
json.images = images
// XXX should we check if index dir is present in path???
path = path +'/'+ this.config['index-dir']
file.writeIndex(
this.prepareIndexForWrite(json).prepared,
path,
this.config['index-filename-template'],
logger || this.logger)
// copy previews for the loaded images...
// XXX should also optionally populate the base dir and nested favs...
var base_dir = this.base_dir
gids.forEach(function(gid){
json.images[gid].base_path = path
var previews = json.images[gid].preview
for(var res in previews){
// XXX copy from .base_dir +'/'+ preview_path to path +'/'+ preview_path
// XXX
}
})
}], }],
}) })
@ -3761,7 +3835,6 @@ module.FileSystemWriterUI = ImageGridFeatures.Feature({
ImageGridFeatures.Feature('viewer-testing', [ ImageGridFeatures.Feature('viewer-testing', [
'base', 'base',
'ui', 'ui',
// features... // features...