refactoring and minor fixes...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2017-12-12 03:40:46 +03:00
parent 119b4d39f2
commit 17a3ea4930

View File

@ -1261,10 +1261,11 @@ module.Collection = core.ImageGridFeatures.Feature({
function(){ function(){
var args = [].slice.call(arguments, 1) var args = [].slice.call(arguments, 1)
var collection = args.length == 1 ? args[0] : args[1] var collection = args.length == 1 ? args[0] : args[1]
var collections = this.collections || {}
this.markChanged( this.markChanged(
'collection: ' 'collection: '
+JSON.stringify( +JSON.stringify(
this.collections[collection || this.collection].gid || collection), (collections[collection || this.collection] || {}).gid || collection),
['data']) ['data'])
}], }],
// transfer changes on load/unload collection... // transfer changes on load/unload collection...
@ -2273,6 +2274,7 @@ var UICollectionActions = actions.Actions({
var all var all
var collections var collections
var to_remove var to_remove
var t
return browse.makeLister(null, return browse.makeLister(null,
function(path, make){ function(path, make){
@ -2291,30 +2293,33 @@ var UICollectionActions = actions.Actions({
} }
// load collections... // load collections...
var loading = all.filter(function(c){ var loading = all
return !that.collections[c].data }) .filter(function(c){
if(loading.length > 0){ return (that.collections || {})[c]
Promise && !that.collections[c].data })
.all(loading.map(function(c){ .map(function(c){
return that.ensureCollection(c) })) that
.then(function(){ .ensureCollection(c)
// update state... .then(function(collection){
var c = that.inCollections(gid || null) collection.data.getImage(gid || that.current) ?
loading.forEach(function(t){ collections.push(c)
c.indexOf(t) >= 0 ? : to_remove.push(c.replace(/\$/g, ''))
collections.push(t)
: to_remove.push(t.replace(/\$/g, ''))
})
dialog.update() // NOTE: we'll avoid calling update
}) // too often...
} clearTimeout(t)
t = setTimeout(function(){
dialog.update()
}, 100)
})
return c
})
// containing collections... // containing collections...
collections = collections collections = collections
|| that.inCollections(gid || null) || that.inCollections(gid || null)
.filter(function(){ return loading.indexOf(title) >= 0 }) .filter(function(title){
return loading.indexOf(title) < 0 })
// build the disabled list... // build the disabled list...
if(!to_remove){ if(!to_remove){
@ -2357,12 +2362,10 @@ var UICollectionActions = actions.Actions({
all.forEach(function(title){ all.forEach(function(title){
collections.indexOf(title) < 0 collections.indexOf(title) < 0
&& to_remove.indexOf(title) < 0 && to_remove.indexOf(title.replace(/\$/g, '')) < 0
&& that.collect(gid, title) && that.collect(gid, title) })
})
to_remove.forEach(function(title){ to_remove.forEach(function(title){
that.uncollect(gid, title) that.uncollect(gid, title) })
})
}) })
})], })],