more refactoring, cleanup and tweaks...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2017-08-30 00:27:43 +03:00
parent 4fa38da17c
commit 9cc62b7aa3
2 changed files with 47 additions and 65 deletions

View File

@ -400,7 +400,7 @@ var CollectionActions = actions.Actions({
// overwrite them anyway later... // overwrite them anyway later...
delete this.tags delete this.tags
}) })
.removeUnloadedGIDs()), .clear('unloaded')),
} }
if(mode == 'crop' && this.crop_stack && depth != 0){ if(mode == 'crop' && this.crop_stack && depth != 0){

View File

@ -460,6 +460,11 @@ var DataPrototype = {
// .clear('empty') // .clear('empty')
// -> data // -> data
// //
// Clear images from .order that are not in any ribbon...
// .clear('unloaded')
// -> data
// NOTE: this may result in empty ribbons...
//
// Clear duplicate gids... // Clear duplicate gids...
// .clear('dup') // .clear('dup')
// .clear('duplicates') // .clear('duplicates')
@ -467,8 +472,9 @@ var DataPrototype = {
// //
// Clear gid(s) form data... // Clear gid(s) form data...
// .clear(gid) // .clear(gid)
// .clear([gid, gid, ..]) // .clear([gid, ..])
// -> data // -> data
// NOTE: gid can be either image or ribbon gid in any order...
// //
// //
// Two extra arguments are considered: // Two extra arguments are considered:
@ -496,6 +502,12 @@ var DataPrototype = {
if(gids == '*' || gids == 'all'){ if(gids == '*' || gids == 'all'){
this._reset() this._reset()
// clear empty ribbons only...
} else if(gids == 'unloaded'){
this.order = this.getImages('loaded')
this.updateImagePositions('remove')
// clear duplicates...
} else if(gids == 'dup' || gids == 'duplicates'){ } else if(gids == 'dup' || gids == 'duplicates'){
// horizontal... // horizontal...
this.removeDuplicates(this.order) this.removeDuplicates(this.order)
@ -601,54 +613,23 @@ var DataPrototype = {
return this return this
}, },
// Remove duplicate gids...
//
// If a gid is in more than one ribbon, this will keep the top
// occurrence only...
//
// NOTE: this may result in empty ribbons...
// NOTE: this is slow-ish...
removeDuplicateGIDs: function(){
var that = this
// horizontal...
this.removeDuplicates(this.order)
this.updateImagePositions()
// vertical...
// if a gid is in more than one ribbon keep only the top occurence...
this.order.forEach(function(gid, i){
var found = false
that.ribbon_order.forEach(function(r){
r = that.ribbons[r]
if(found){
delete r[i]
} else if(r[i] != null){
found = true
}
})
})
return this
},
// Remove unloaded gids...
//
// This removes:
// - images from .data that are not in any ribbon
//
// NOTE: this may result in empty ribbons...
removeUnloadedGIDs: function(){
this.order = this.getImages('loaded')
this.updateImagePositions('remove')
return this
},
// Replace image gid... // Replace image gid...
// //
// XXX should this work for ribbon gids??? // NOTE: if to exists then it will get overwritten.
replaceGid: function(from, to){ replaceGid: function(from, to){
if(from in this.ribbons){
// ribbons...
var ribbon = this.ribbons[from]
delete this.ribbons[from]
this.ribbons[to] = ribbon
// ribbon order...
this.ribbon_order.splice(this.ribbon_order.indexOf(from), 1, to)
// base ribbon...
this.__base = this.__base == from ? to : this.__base
} else {
from = this.getImage(from) from = this.getImage(from)
var i = this.getImageOrder(from) var i = this.getImageOrder(from)
@ -670,7 +651,7 @@ var DataPrototype = {
list[i] = to list[i] = to
} }
}) })
}
return this return this
}, },
@ -2444,7 +2425,8 @@ var DataPrototype = {
base base
// XXX this is slow-ish... // XXX this is slow-ish...
.removeDuplicateGIDs() //.removeDuplicateGIDs()
.clear('duplicates')
.clear('empty') .clear('empty')
return base return base