now loading self-corrects data...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2017-03-08 19:34:49 +03:00
parent 11bbbf4458
commit d1caf1a0d6
2 changed files with 42 additions and 4 deletions

View File

@ -325,10 +325,22 @@ var FileSystemLoaderActions = actions.Actions({
// skip empty indexes...
// XXX should we rebuild or list here???
if(res[k].data == null || res[k].images == null){
if(res[k].data == null && res[k].images == null){
continue
}
// build the data from images...
// XXX
if(res[k].data == null){
var g = data.Data().newGid()
res[k].data = {
order: Object.keys(res[k].images),
//ribbons: {},
//ribbon_order: [g],
}
//res[k].data.ribbons[g] = res[k].data.order.slice()
}
var part = that.prepareJSONForLoad(res[k], k)
// load the first index...

View File

@ -13,6 +13,26 @@ module.VERSIONS = []
/*********************************************************************/
var completeData =
module.completeData =
function(data){
// XXX is this the right way to go???
var that = require('imagegrid/data').Data()
var ribbons = data.ribbons = data.ribbons || {}
if(Object.keys(ribbons).length == 0){
ribbons[that.newGid()] = data.order.slice()
}
data.ribbon_order = data.ribbon_order || Object.keys(ribbons)
return data
}
/*********************************************************************/
// Convert legacy Gen1 data format to Gen3 format version 2.0+
//
@ -21,6 +41,8 @@ module.VERSIONS = []
//module.convertDataGen1 =
module.VERSIONS['2.0'] =
function(data, cmp){
//data = data.version < '2.0' ? module.VERSIONS['2.0'](data) : data
var res = {
data: {
version: '2.0',
@ -125,7 +147,11 @@ function(data){
// Get latest updater version...
//
module.getLatestUpdaterVersion = function(){
return Object.keys(module.VERSIONS).sort().pop()
return Object.keys(module.VERSIONS)
.map(function(v){ return [v, parseFloat(v)] })
.sort(function(a, b){ return a[1] - b[1] })
.map(function(e){ return e[0] })
.pop()
}
@ -144,7 +170,7 @@ module.updateData = function(data, clean){
var v = module.getLatestUpdaterVersion()
var res = data.version < v
? module.VERSIONS[v](data)
: data
: completeData(data)
!clean
&& Object.keys(data).forEach(function(k){