mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 10:20:08 +00:00
some drastic speedups... (not done yet)
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
b5e0b03491
commit
e836eee6e3
@ -1217,12 +1217,11 @@ module.TagsEditActions = actions.Actions({
|
||||
function(tags, gids){
|
||||
gids = gids || this.current
|
||||
gids = gids instanceof Array ? gids : [gids]
|
||||
gids = this.data.getImages(gids)
|
||||
|
||||
tags = tags instanceof Array ? tags : [tags]
|
||||
|
||||
var that = this
|
||||
gids = gids
|
||||
.map(function(gid){ return that.data.getImage(gid) })
|
||||
.filter(function(gid){ return gid != null })
|
||||
|
||||
if(gids.length == 0){
|
||||
return
|
||||
@ -1234,13 +1233,8 @@ module.TagsEditActions = actions.Actions({
|
||||
// images...
|
||||
var images = this.images
|
||||
gids.forEach(function(gid){
|
||||
var img = images[gid]
|
||||
if(img == null){
|
||||
img = images[gid] = {}
|
||||
}
|
||||
if(img.tags == null){
|
||||
img.tags = []
|
||||
}
|
||||
var img = images[gid] = images[gid] || {}
|
||||
img.tags = img.tags || []
|
||||
|
||||
img.tags = img.tags.concat(tags).unique()
|
||||
|
||||
@ -1344,11 +1338,9 @@ module.TagsEdit = core.ImageGridFeatures.Feature({
|
||||
var that = this
|
||||
var changes = []
|
||||
|
||||
gids = gids || [this.data.getImage()]
|
||||
gids = gids instanceof Array ?
|
||||
gids
|
||||
.map(function(e){ return that.data.getImage(e) })
|
||||
: [this.data.getImage(gids)]
|
||||
gids = gids || this.current
|
||||
gids = gids instanceof Array ? gids : [gids]
|
||||
gids = this.data.getImages(gids)
|
||||
|
||||
tags = tags || []
|
||||
tags = tags instanceof Array ? tags : [tags]
|
||||
@ -1417,6 +1409,8 @@ module.TagsEdit = core.ImageGridFeatures.Feature({
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// Image Group...
|
||||
|
||||
|
||||
@ -34,14 +34,15 @@ var ui = require('features/ui')
|
||||
// NOTE: of no data is defined this will not have any effect...
|
||||
// NOTE: we are not using the vanilla toggler here as it can't handle
|
||||
// toggling independently multiple elements...
|
||||
//
|
||||
// XXX this is really slow on large sets of images...
|
||||
function makeTagTogglerAction(tag){
|
||||
// get actual target gids...
|
||||
var _getTarget = function(target){
|
||||
target = target || this.current
|
||||
target = target == 'all'
|
||||
target = (target == 'all'
|
||||
|| target == 'loaded'
|
||||
|| target in this.data.ribbons
|
||||
?
|
||||
|| target in this.data.ribbons) ?
|
||||
this.data.getImages(target)
|
||||
: target == 'ribbon' ?
|
||||
this.data.getImages('current')
|
||||
@ -64,6 +65,7 @@ function makeTagTogglerAction(tag){
|
||||
|
||||
} else if(action == 'on'){
|
||||
this.tag(tag, target)
|
||||
|
||||
} else if(action == 'off'){
|
||||
this.untag(tag, target)
|
||||
}
|
||||
@ -83,19 +85,25 @@ function makeTagTogglerAction(tag){
|
||||
|| action == '!')){
|
||||
var res = []
|
||||
var that = this
|
||||
var on = []
|
||||
var off = []
|
||||
target = _getTarget.call(this, target)
|
||||
target.forEach(function(t){
|
||||
if((that.data.getTags(t).indexOf(tag) < 0)
|
||||
// invert check if action is '!'...
|
||||
+ (action == '!' ? -1 : 0)){
|
||||
that.tag(tag, t)
|
||||
on.push(tag)
|
||||
res.push('on')
|
||||
|
||||
} else {
|
||||
that.untag(tag, t)
|
||||
off.push(tag)
|
||||
res.push('off')
|
||||
}
|
||||
})
|
||||
|
||||
that.tag(t, on)
|
||||
that.untag(t, off)
|
||||
|
||||
return res.length == 1 ? res[0] : res
|
||||
}
|
||||
|
||||
|
||||
@ -319,6 +319,7 @@ var DataPrototype = {
|
||||
target = target == null ? [] : target
|
||||
|
||||
order = this.order
|
||||
var order_idx = order.toKeys()
|
||||
|
||||
var rest = []
|
||||
|
||||
@ -333,7 +334,8 @@ var DataPrototype = {
|
||||
}
|
||||
|
||||
// try and avoid the expensive .indexOf(..) as much as possible...
|
||||
var j = e != order[i] ? order.indexOf(e) : i
|
||||
//var j = e != order[i] ? order.indexOf(e) : i
|
||||
var j = order_idx[e]
|
||||
|
||||
if(j >= 0){
|
||||
// save overwritten target items if keep_target_items
|
||||
@ -1095,15 +1097,15 @@ var DataPrototype = {
|
||||
// normalize target and build the source list...
|
||||
|
||||
// 'current' ribbon...
|
||||
target = target == 'current' ? this.current : target
|
||||
target = target === 'current' ? this.current : target
|
||||
|
||||
// get all gids...
|
||||
if(target == 'all'){
|
||||
if(target === 'all'){
|
||||
list = this.order
|
||||
target = null
|
||||
|
||||
// get loaded only gids...
|
||||
} else if(target == 'loaded'){
|
||||
} else if(target === 'loaded'){
|
||||
var res = []
|
||||
var ribbons = this.ribbons
|
||||
for(var k in ribbons){
|
||||
@ -1113,24 +1115,36 @@ var DataPrototype = {
|
||||
target = null
|
||||
|
||||
// filter out the unloaded gids from given list...
|
||||
} else if(target != null && target instanceof Array){
|
||||
var loaded = count == 'current' ?
|
||||
this.getImages('current')
|
||||
: count == 'all' || count == 'global' ?
|
||||
this.getImages('all')
|
||||
: count in this.ribbons ?
|
||||
this.ribbons[count].compact()
|
||||
: typeof(count) == typeof(123) ?
|
||||
this.ribbons[this.getRibbon(count)].compact()
|
||||
: this.getImages('loaded')
|
||||
} else if(target instanceof Array){
|
||||
var loaded = (count == 'current' ?
|
||||
this.getImages('current')
|
||||
: count == 'all' || count == 'global' ?
|
||||
this.getImages('all')
|
||||
: count in this.ribbons ?
|
||||
this.ribbons[count].compact()
|
||||
: typeof(count) == typeof(123) ?
|
||||
this.ribbons[this.getRibbon(count)].compact()
|
||||
: this.getImages('loaded'))
|
||||
// index the loaded gids for fast lookup...
|
||||
.toKeys()
|
||||
|
||||
list = target
|
||||
.map(function(e){
|
||||
return count == 'all' || count == 'global' ?
|
||||
// primary path -- gids...
|
||||
// NOTE: this is the most probable path...
|
||||
if(loaded[e]){
|
||||
return e
|
||||
}
|
||||
|
||||
// in case we are not dealing with a gid...
|
||||
// NOTE: this is a less likely path so it is secondary...
|
||||
e = count == 'all' || count == 'global' ?
|
||||
that.getImage(e, 'global')
|
||||
: that.getImage(e) })
|
||||
.filter(function(e){
|
||||
return loaded.indexOf(e) >= 0 })
|
||||
: that.getImage(e)
|
||||
|
||||
return loaded[e] ? e : null
|
||||
})
|
||||
.filter(function(e){ return e !== null })
|
||||
|
||||
count = null
|
||||
target = null
|
||||
@ -3032,14 +3046,13 @@ var DataWithTagsPrototype = {
|
||||
|
||||
var that = this
|
||||
var tagset = this.tags
|
||||
var order = this.order
|
||||
var order = this.order.toKeys()
|
||||
tags.forEach(function(tag){
|
||||
var t = tagset[tag] = tagset[tag] || []
|
||||
gids.forEach(function(gid){
|
||||
gid = that.getImage(gid)
|
||||
if(tagset[tag] == null){
|
||||
tagset[tag] = []
|
||||
}
|
||||
tagset[tag][order.indexOf(gid)] = gid
|
||||
var i = order[gid]
|
||||
gid = i != null ? gid : that.getImage(gid)
|
||||
t[i != null ? i : order[gid]] = gid
|
||||
})
|
||||
})
|
||||
|
||||
@ -3056,15 +3069,14 @@ var DataWithTagsPrototype = {
|
||||
|
||||
var that = this
|
||||
var tagset = this.tags
|
||||
var order = this.order
|
||||
var order = this.order.toKeys()
|
||||
tags.forEach(function(tag){
|
||||
if(tag in tagset){
|
||||
gids.forEach(function(gid){
|
||||
if(tag in tagset){
|
||||
delete tagset[tag][order.indexOf(gid)]
|
||||
}
|
||||
})
|
||||
if(tagset[tag].len == 0){
|
||||
var t = tagset[tag]
|
||||
gids
|
||||
.forEach(function(gid){
|
||||
delete t[order[gid]] })
|
||||
if(t.len == 0){
|
||||
delete tagset[tag]
|
||||
}
|
||||
}
|
||||
|
||||
@ -40,6 +40,12 @@ Object.defineProperty(Object.prototype, 'run', {
|
||||
Array.prototype.compact = function(){
|
||||
return this.filter(function(){ return true })
|
||||
}
|
||||
Array.prototype.toKeys = function(){
|
||||
return this.reduce(function(r, e, i){
|
||||
r[e] = i
|
||||
return r
|
||||
}, {})
|
||||
}
|
||||
/*
|
||||
Array.prototype.compact = function(){
|
||||
var res = []
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user