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){
|
function(tags, gids){
|
||||||
gids = gids || this.current
|
gids = gids || this.current
|
||||||
gids = gids instanceof Array ? gids : [gids]
|
gids = gids instanceof Array ? gids : [gids]
|
||||||
|
gids = this.data.getImages(gids)
|
||||||
|
|
||||||
tags = tags instanceof Array ? tags : [tags]
|
tags = tags instanceof Array ? tags : [tags]
|
||||||
|
|
||||||
var that = this
|
var that = this
|
||||||
gids = gids
|
|
||||||
.map(function(gid){ return that.data.getImage(gid) })
|
|
||||||
.filter(function(gid){ return gid != null })
|
|
||||||
|
|
||||||
if(gids.length == 0){
|
if(gids.length == 0){
|
||||||
return
|
return
|
||||||
@ -1234,13 +1233,8 @@ module.TagsEditActions = actions.Actions({
|
|||||||
// images...
|
// images...
|
||||||
var images = this.images
|
var images = this.images
|
||||||
gids.forEach(function(gid){
|
gids.forEach(function(gid){
|
||||||
var img = images[gid]
|
var img = images[gid] = images[gid] || {}
|
||||||
if(img == null){
|
img.tags = img.tags || []
|
||||||
img = images[gid] = {}
|
|
||||||
}
|
|
||||||
if(img.tags == null){
|
|
||||||
img.tags = []
|
|
||||||
}
|
|
||||||
|
|
||||||
img.tags = img.tags.concat(tags).unique()
|
img.tags = img.tags.concat(tags).unique()
|
||||||
|
|
||||||
@ -1344,11 +1338,9 @@ module.TagsEdit = core.ImageGridFeatures.Feature({
|
|||||||
var that = this
|
var that = this
|
||||||
var changes = []
|
var changes = []
|
||||||
|
|
||||||
gids = gids || [this.data.getImage()]
|
gids = gids || this.current
|
||||||
gids = gids instanceof Array ?
|
gids = gids instanceof Array ? gids : [gids]
|
||||||
gids
|
gids = this.data.getImages(gids)
|
||||||
.map(function(e){ return that.data.getImage(e) })
|
|
||||||
: [this.data.getImage(gids)]
|
|
||||||
|
|
||||||
tags = tags || []
|
tags = tags || []
|
||||||
tags = tags instanceof Array ? tags : [tags]
|
tags = tags instanceof Array ? tags : [tags]
|
||||||
@ -1417,6 +1409,8 @@ module.TagsEdit = core.ImageGridFeatures.Feature({
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
// Image Group...
|
// Image Group...
|
||||||
|
|
||||||
|
|||||||
@ -34,14 +34,15 @@ var ui = require('features/ui')
|
|||||||
// NOTE: of no data is defined this will not have any effect...
|
// 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
|
// NOTE: we are not using the vanilla toggler here as it can't handle
|
||||||
// toggling independently multiple elements...
|
// toggling independently multiple elements...
|
||||||
|
//
|
||||||
|
// XXX this is really slow on large sets of images...
|
||||||
function makeTagTogglerAction(tag){
|
function makeTagTogglerAction(tag){
|
||||||
// get actual target gids...
|
// get actual target gids...
|
||||||
var _getTarget = function(target){
|
var _getTarget = function(target){
|
||||||
target = target || this.current
|
target = target || this.current
|
||||||
target = target == 'all'
|
target = (target == 'all'
|
||||||
|| target == 'loaded'
|
|| target == 'loaded'
|
||||||
|| target in this.data.ribbons
|
|| target in this.data.ribbons) ?
|
||||||
?
|
|
||||||
this.data.getImages(target)
|
this.data.getImages(target)
|
||||||
: target == 'ribbon' ?
|
: target == 'ribbon' ?
|
||||||
this.data.getImages('current')
|
this.data.getImages('current')
|
||||||
@ -64,6 +65,7 @@ function makeTagTogglerAction(tag){
|
|||||||
|
|
||||||
} else if(action == 'on'){
|
} else if(action == 'on'){
|
||||||
this.tag(tag, target)
|
this.tag(tag, target)
|
||||||
|
|
||||||
} else if(action == 'off'){
|
} else if(action == 'off'){
|
||||||
this.untag(tag, target)
|
this.untag(tag, target)
|
||||||
}
|
}
|
||||||
@ -83,19 +85,25 @@ function makeTagTogglerAction(tag){
|
|||||||
|| action == '!')){
|
|| action == '!')){
|
||||||
var res = []
|
var res = []
|
||||||
var that = this
|
var that = this
|
||||||
|
var on = []
|
||||||
|
var off = []
|
||||||
target = _getTarget.call(this, target)
|
target = _getTarget.call(this, target)
|
||||||
target.forEach(function(t){
|
target.forEach(function(t){
|
||||||
if((that.data.getTags(t).indexOf(tag) < 0)
|
if((that.data.getTags(t).indexOf(tag) < 0)
|
||||||
// invert check if action is '!'...
|
// invert check if action is '!'...
|
||||||
+ (action == '!' ? -1 : 0)){
|
+ (action == '!' ? -1 : 0)){
|
||||||
that.tag(tag, t)
|
on.push(tag)
|
||||||
res.push('on')
|
res.push('on')
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
that.untag(tag, t)
|
off.push(tag)
|
||||||
res.push('off')
|
res.push('off')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
that.tag(t, on)
|
||||||
|
that.untag(t, off)
|
||||||
|
|
||||||
return res.length == 1 ? res[0] : res
|
return res.length == 1 ? res[0] : res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -319,6 +319,7 @@ var DataPrototype = {
|
|||||||
target = target == null ? [] : target
|
target = target == null ? [] : target
|
||||||
|
|
||||||
order = this.order
|
order = this.order
|
||||||
|
var order_idx = order.toKeys()
|
||||||
|
|
||||||
var rest = []
|
var rest = []
|
||||||
|
|
||||||
@ -333,7 +334,8 @@ var DataPrototype = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// try and avoid the expensive .indexOf(..) as much as possible...
|
// 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){
|
if(j >= 0){
|
||||||
// save overwritten target items if keep_target_items
|
// save overwritten target items if keep_target_items
|
||||||
@ -1095,15 +1097,15 @@ var DataPrototype = {
|
|||||||
// normalize target and build the source list...
|
// normalize target and build the source list...
|
||||||
|
|
||||||
// 'current' ribbon...
|
// 'current' ribbon...
|
||||||
target = target == 'current' ? this.current : target
|
target = target === 'current' ? this.current : target
|
||||||
|
|
||||||
// get all gids...
|
// get all gids...
|
||||||
if(target == 'all'){
|
if(target === 'all'){
|
||||||
list = this.order
|
list = this.order
|
||||||
target = null
|
target = null
|
||||||
|
|
||||||
// get loaded only gids...
|
// get loaded only gids...
|
||||||
} else if(target == 'loaded'){
|
} else if(target === 'loaded'){
|
||||||
var res = []
|
var res = []
|
||||||
var ribbons = this.ribbons
|
var ribbons = this.ribbons
|
||||||
for(var k in ribbons){
|
for(var k in ribbons){
|
||||||
@ -1113,8 +1115,8 @@ var DataPrototype = {
|
|||||||
target = null
|
target = null
|
||||||
|
|
||||||
// filter out the unloaded gids from given list...
|
// filter out the unloaded gids from given list...
|
||||||
} else if(target != null && target instanceof Array){
|
} else if(target instanceof Array){
|
||||||
var loaded = count == 'current' ?
|
var loaded = (count == 'current' ?
|
||||||
this.getImages('current')
|
this.getImages('current')
|
||||||
: count == 'all' || count == 'global' ?
|
: count == 'all' || count == 'global' ?
|
||||||
this.getImages('all')
|
this.getImages('all')
|
||||||
@ -1122,15 +1124,27 @@ var DataPrototype = {
|
|||||||
this.ribbons[count].compact()
|
this.ribbons[count].compact()
|
||||||
: typeof(count) == typeof(123) ?
|
: typeof(count) == typeof(123) ?
|
||||||
this.ribbons[this.getRibbon(count)].compact()
|
this.ribbons[this.getRibbon(count)].compact()
|
||||||
: this.getImages('loaded')
|
: this.getImages('loaded'))
|
||||||
|
// index the loaded gids for fast lookup...
|
||||||
|
.toKeys()
|
||||||
|
|
||||||
list = target
|
list = target
|
||||||
.map(function(e){
|
.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, 'global')
|
||||||
: that.getImage(e) })
|
: that.getImage(e)
|
||||||
.filter(function(e){
|
|
||||||
return loaded.indexOf(e) >= 0 })
|
return loaded[e] ? e : null
|
||||||
|
})
|
||||||
|
.filter(function(e){ return e !== null })
|
||||||
|
|
||||||
count = null
|
count = null
|
||||||
target = null
|
target = null
|
||||||
@ -3032,14 +3046,13 @@ var DataWithTagsPrototype = {
|
|||||||
|
|
||||||
var that = this
|
var that = this
|
||||||
var tagset = this.tags
|
var tagset = this.tags
|
||||||
var order = this.order
|
var order = this.order.toKeys()
|
||||||
tags.forEach(function(tag){
|
tags.forEach(function(tag){
|
||||||
|
var t = tagset[tag] = tagset[tag] || []
|
||||||
gids.forEach(function(gid){
|
gids.forEach(function(gid){
|
||||||
gid = that.getImage(gid)
|
var i = order[gid]
|
||||||
if(tagset[tag] == null){
|
gid = i != null ? gid : that.getImage(gid)
|
||||||
tagset[tag] = []
|
t[i != null ? i : order[gid]] = gid
|
||||||
}
|
|
||||||
tagset[tag][order.indexOf(gid)] = gid
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -3056,15 +3069,14 @@ var DataWithTagsPrototype = {
|
|||||||
|
|
||||||
var that = this
|
var that = this
|
||||||
var tagset = this.tags
|
var tagset = this.tags
|
||||||
var order = this.order
|
var order = this.order.toKeys()
|
||||||
tags.forEach(function(tag){
|
tags.forEach(function(tag){
|
||||||
if(tag in tagset){
|
if(tag in tagset){
|
||||||
gids.forEach(function(gid){
|
var t = tagset[tag]
|
||||||
if(tag in tagset){
|
gids
|
||||||
delete tagset[tag][order.indexOf(gid)]
|
.forEach(function(gid){
|
||||||
}
|
delete t[order[gid]] })
|
||||||
})
|
if(t.len == 0){
|
||||||
if(tagset[tag].len == 0){
|
|
||||||
delete tagset[tag]
|
delete tagset[tag]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -40,6 +40,12 @@ Object.defineProperty(Object.prototype, 'run', {
|
|||||||
Array.prototype.compact = function(){
|
Array.prototype.compact = function(){
|
||||||
return this.filter(function(){ return true })
|
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(){
|
Array.prototype.compact = function(){
|
||||||
var res = []
|
var res = []
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user