added experimental .order_list to data (find a better name?)...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2014-08-12 17:24:56 +04:00
parent 2ed83bbb4c
commit 12dcb83353
2 changed files with 68 additions and 7 deletions

View File

@ -9,6 +9,9 @@ define(function(require){ var module = {}
console.log('>>> data')
var formats = require('formats')
module.DATA_VERSION = '3.0'
@ -149,6 +152,19 @@ module.DataPrototype = {
// NOTE: this list may contain gids not loaded at the moment,
// a common case for this is when data is cropped.
//
// .order_list EXPERIMENTAL
// Dict of named user defined order lists
//
// format:
// { name: [ gid, .. ], .. }
//
// reserved order names:
// 'last' - stores the last order before cange
// 'manual' - stores the last user-defined orderbefore
// resort
//
// NOTE: this attr is optional...
//
// .ribbon_order
// List of ribbon gids setting the ribbon order.
//
@ -823,6 +839,23 @@ module.DataPrototype = {
return this
},
// XXX should these be here or in a pligin???
saveOrderAs: function(name, order){
if(this.order_list == null){
this.order_list = {}
}
this.order_list[name] = order != null ? order : this.order.slice()
return this
},
loadOrder: function(name){
var order = name.constructor.name == 'Array' ? name : this.order_list[name].slice()
if(order == null){
return this
}
this.order = order
return this.sortImages()
},
// Shift image...
//
// Shift image to target position:
@ -1402,12 +1435,14 @@ module.DataPrototype = {
// Load data from JSON...
//
// NOTE: this loads in-place, use .fromJSON(..) to create new data...
// XXX should this process defaults for unset values???
loadJSON: function(data){
data = typeof(data) == typeof('str') ? JSON.parse(data) : data
data = formats.updateData(data)
this.base = data.base
this.current = data.current
this.order = data.order.slice()
this.order_list = data.order_list != null ? JSON.parse(JSON.stringify(data.order_list)) : null
this.ribbon_order = data.ribbon_order.slice()
this.ribbons = {}
// make ribbons sparse...
@ -1430,6 +1465,10 @@ module.DataPrototype = {
ribbon_order: this.ribbon_order.slice(),
ribbons: {},
}
if(this.order_list != null && Object.keys(this.order_list).length > 0){
// do a deep copy...
res.order_list = JSON.parse(JSON.stringify(this.order_list))
}
// compact ribbons...
for(var k in this.ribbons){
res.ribbons[k] = this.ribbons[k].compact()

View File

@ -71,10 +71,11 @@ function(data, cmp){
// the Data object...
// NOTE: this uses require('data').Data().newGid(..) for ribbon gid
// generation...
// XXX test...
//module.convertDataGen3 =
module.VERSIONS['3.0'] =
function(data){
data = data.version == null ? module.VERSIONS['2.0'](data) : data
data = data.version < '3.0' ? module.VERSIONS['2.0'](data) : data
// XXX is this the right way to go???
var that = require('data').Data()
@ -83,20 +84,41 @@ function(data){
res.version = '3.0'
res.current = data.current
res.order = data.order.slice()
res.ribbon_order = []
res.ribbons = {}
res.ribbon_order = data.ribbon_order == null ? [] : data.ribbon_order.slice()
res.ribbons = {}
// generate gids...
data.ribbons.forEach(function(e){
var gid = that.newGid('R')
// NOTE: this will use the structures stored in data if available,
// otherwise new structures will be generated...
// NOTE: we need to do this anyway as we also need to deep-copy the
// ribbons...
var keys = data.ribbon_order != null
? data.ribbon_order
: Object.keys(data.ribbons)
keys.forEach(function(k){
var gid = k*1 == null ? k : that.newGid('R')
res.ribbon_order.push(gid)
res.ribbons[gid] = e.slice()
res.ribbons[gid] = data.ribbons[k].slice()
})
// we set the base to the first ribbon...
res.base = res.ribbon_order[0]
res.base = data.base == null ? res.ribbon_order[0] : res.base
return res
}
// XXX EXPERIMENTAL...
module.VERSIONS['3.1'] =
function(data){
res = module.VERSIONS['3.0'](data)
res.version = '3.1'
res.order_list = data.order_list != null ? JSON.parse(JSON.stringify(data.order_list)) : null
return res
}
// Get latest updater version...
//
module.getLatestUpdaterVersion = function(){