moving to new read/write format...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2017-02-15 05:21:28 +03:00
parent 84b02c8f7a
commit 3aa03faea6
3 changed files with 48 additions and 29 deletions

View File

@ -1111,6 +1111,15 @@ module.Tags = core.ImageGridFeatures.Feature({
this.markChanged('images', gids)
}],
// XXX
['prepareIndexForWrite',
function(res, _, full){
// XXX move code here from file.buildIndex(..)
// - res.raw.tags -> res.index.tags
// - ..tags.selected -> .selected
// - ..tags.bookmark -> .bookmarked
// XXX will need a symmetrical action to reverse all of this...
}],
],
})

View File

@ -130,6 +130,16 @@ var FileSystemLoaderActions = actions.Actions({
'default-load-method': 'loadIndex',
},
// NOTE: this is the reverse of .prepareIndexForWrite(..)
//
// XXX do we need both this and file.buildIndex(..), we essentially create
// a Data object and then create it again in .load()...
prepareJSONForLoad: ['- File/Prepare JSON for loading',
function(json, base_path){
// XXX move the code up here from file.js...
return file.buildIndex(json, base_path) }],
// XXX is this a hack???
// XXX need a more generic form...
checkPath: ['- File/',
@ -147,8 +157,6 @@ var FileSystemLoaderActions = actions.Actions({
// NOTE: this will add a .from field to .location, this will indicate
// the date starting from which saves are loaded.
//
// XXX do we need both this and file.buildIndex(..), we essentially create
// a Data object and then create it again in .load()...
// XXX look inside...
loadIndex: ['- File/Load index',
function(path, from_date, logger){
@ -220,7 +228,7 @@ var FileSystemLoaderActions = actions.Actions({
continue
}
var part = file.buildIndex(res[k], k)
var part = that.prepareJSONForLoad(res[k], k)
// load the first index...
if(index == null){
@ -1588,6 +1596,7 @@ var FileSystemWriterActions = actions.Actions({
//
// For more info see file.writeIndex(..) and file.loadIndex(..).
//
// NOTE: this is the reverse of .prepareJSONForLoad(..)
prepareIndexForWrite: ['- File/Prepare index for writing',
function(json, full){
json = json || this.json('base')

View File

@ -380,10 +380,9 @@ module.SortActions = actions.Actions({
// XXX add drop/load actions...
saveOrder: ['- Sort/',
function(title){
if(title){
title = title || 'Manual'
var cache = this.data.sort_order = this.data.sort_order || {}
cache[title] = this.data.order.slice()
}
}],
loadOrder: ['- Srot/',
function(title, reverse){
@ -413,35 +412,32 @@ module.SortActions = actions.Actions({
// .data.sort_cache - cached sort order (optional)
load: [function(data){
return function(){
if(data.data && data.data.sort_method){
this.data.sort_method = data.data.sort_method
}
var that = this
if(data.data && data.sort_order){
this.data.sort_order = data.sort_order
}
if(data.data && data.sort_cache){
this.data.sort_cache = data.sort_cache
data.data
&& ['sort_method', 'sort_order', 'sort_cache']
.forEach(function(attr){
if(data.data[attr]){
that.data[attr] = data.data[attr]
}
})
}
}],
// XXX should .sort_cache be stored separately???
json: [function(){
return function(res){
if(this.data.sort_method){
res.data.sort_method = this.data.sort_method
}
var that = this
if(this.data.sort_order){
res.sort_order = this.data.sort_order
}
if(this.data.sort_cache){
res.sort_cache = this.data.sort_cache
;['sort_method', 'sort_order', 'sort_cache']
.forEach(function(attr){
if(that.data[attr]){
res.data[attr] = that.data[attr]
}
})
// special case: unsaved manual order...
if(this.toggleImageSort('?') == 'Manual'){
res.sort_order = res.sort_order || {}
res.sort_order['Manual'] = this.data.order.slice()
res.data.sort_order = res.sort_order || {}
res.data.sort_order['Manual'] = this.data.order.slice()
}
}
}],
@ -490,6 +486,11 @@ module.Sort = core.ImageGridFeatures.Feature({
save('sort_order')
save('sort_cache')
}],
['prepareJSONForLoad',
function(res){
// XXX
//res.data.sort_cache = res.sort_cache
}],
// manage changes...
['sortImages',