reworked .collect(..) and .joinCollect(..)...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2017-12-14 23:37:43 +03:00
parent 3465334e7a
commit a3f5248b4c
3 changed files with 145 additions and 33 deletions

View File

@ -773,7 +773,17 @@ var CollectionActions = actions.Actions({
// Collection editing.... // Collection editing....
// //
// XXX should this add images that already exist??? // NOTE: Currently these are sync, and sequencing happens automatically as
// everything uses .ensureCollection(..)
// to explecitly sequence a call do:
// .collect(..)
// .ensureCollection(..)
// .then(function(){
// // this is run after .collect(..)
// ...
// })
//
// XXX need to figure out error handling for this scheme...
collect: ['- Collections/', collect: ['- Collections/',
core.doc`Add items to collection core.doc`Add items to collection
@ -826,10 +836,22 @@ var CollectionActions = actions.Actions({
|| that.collections[MAIN_COLLECTION_TITLE].data.getImage(gid) ] }) || that.collections[MAIN_COLLECTION_TITLE].data.getImage(gid) ] })
.reduce(function(a, b){ return a.concat(b) }, []) .reduce(function(a, b){ return a.concat(b) }, [])
this.ensureCollection(collection)
.then((function(c){
var remove = c.data.getImages(gids, 'all')
// only add gids that do not exist in collection...
gids = gids
.filter(function(g){ return remove.indexOf(g) < 0 })
if(gids.length == 0){
return
}
// add to collection... // add to collection...
var data = this.data.constructor.fromArray(gids) var data = this.data.constructor.fromArray(gids)
return this.joinCollect(null, collection, data) return this.joinCollect(null, collection, data)
}).bind(this))
}], }],
joinCollect: ['- Collections/Merge to collection', joinCollect: ['- Collections/Merge to collection',
core.doc`Merge/Join current state to collection core.doc`Merge/Join current state to collection
@ -865,21 +887,59 @@ var CollectionActions = actions.Actions({
align = align === collection ? null : align align = align === collection ? null : align
// create collection if it does not exist... // create collection if it does not exist...
// XXX should this be async???
//return this.ensureCollection(collection)
this.ensureCollection(collection) this.ensureCollection(collection)
.then((function(){ .then((function(c){
var target = c.crop_stack ?
c.crop_stack[0]
: c.data
//this.collections[collection].data.join(align, data || this.data.clone()) //this.collections[collection].data.join(align, data || this.data.clone())
var res = this.collections[collection].data = (data || this.data) var res = (data || this.data)
.clone() .clone()
.join(align, this.collections[collection].data) .join(align, target)
var rorder = res.order.slice().reverse()
// write to base data...
if(c.crop_stack){
c.crop_stack[0] = res
c.crop_stack
.concat([c.data])
.forEach(function(data){
data.order = data.order
.reverse()
.concat(rorder)
.unique()
.reverse()
data.updateImagePositions()
})
} else {
c.data = res
}
// joining into the current collection... // joining into the current collection...
if(collection == this.collection){ if(collection == this.collection){
if(this.crop_stack){
this.crop_stack[0] = res
this.crop_stack
.concat([this.data])
.forEach(function(data){
data.order = data.order
.reverse()
.concat(rorder)
.unique()
.reverse()
data.updateImagePositions()
})
} else {
var cur = this.current var cur = this.current
this.data = res this.data = res
this.data.current = cur this.data.current = cur
} }
}
}).bind(this)) }).bind(this))
}], }],
uncollect: ['Collections|Image/Remove from collection', uncollect: ['Collections|Image/Remove from collection',
@ -1260,7 +1320,7 @@ module.Collection = core.ImageGridFeatures.Feature({
'collection: ' 'collection: '
+JSON.stringify(this.collections[collection].gid || collection)) +JSON.stringify(this.collections[collection].gid || collection))
}], }],
// collection sort... // collection list sort...
['sortCollections.pre', ['sortCollections.pre',
function(){ function(){
var o = (this.collection_order || []).slice() var o = (this.collection_order || []).slice()
@ -1280,21 +1340,40 @@ module.Collection = core.ImageGridFeatures.Feature({
+ JSON.stringify(this.collections[to].gid), ['metadata']) }], + JSON.stringify(this.collections[to].gid), ['metadata']) }],
// basic collection edits... // basic collection edits...
// //
// XXX mark changed ONLY if actual changes made... // XXX .joinCollect(..) should set change for a collection if
// it changes the topology...
// ...this can happen when multiple ribbons are joined...
// Q: can this happen through .collect(..)???
[[ [[
// NOTE: no need to handle .collect(..) here as it calls .joinCollect(..) // NOTE: no need to handle .collect(..) here as it calls .joinCollect(..)
'joinCollect', 'joinCollect.pre',
'uncollect', 'uncollect.pre',
], ],
function(){ function(){
var args = [].slice.call(arguments, 1) var that = this
var collection = args.length == 1 ? args[0] : args[1] var args = [].slice.call(arguments)
var collections = this.collections || {} var title = args.length == 1 ? args[0] : args[1]
this.markChanged( var collection = (this.collections || {})[title] || {}
var count = collection.data ?
collection.data.length
: collection.count
return function(){
this.ensureCollection(title)
.then(function(){
var new_count = collection.data ?
collection.data.length
: collection.count
new_count != count
&& that.markChanged('collections')
&& that.markChanged(
'collection: ' 'collection: '
+JSON.stringify( +JSON.stringify(collection.gid || title),
(collections[collection || this.collection] || {}).gid || collection),
['data']) ['data'])
})
}
}], }],
// transfer changes on load/unload collection... // transfer changes on load/unload collection...
['collectionLoading.pre', ['collectionLoading.pre',
@ -1411,13 +1490,32 @@ module.Collection = core.ImageGridFeatures.Feature({
// //
// // Collection gid-title index... // // Collection gid-title index...
// // // //
// // NOTE: this is sorted via .collection_order... // // NOTE: this is sorted via .collection_order in .json(..)...
// //
// // NOTE: if .collections is undefined this is not returned...
// // XXX this may cause issues if after removing the
// // last collection and .collections is deleted,
// // then the last saved collection state will
// // get loaded instead of an empty collection list
// // ...currently this is not a problem as .collections
// // is never explicitly set to undefined, but is a
// // potential pitfall...
// // Q: should this return {} when .collections is undefined?
// collections: { // collections: {
// // normal collection...
// <gid>: { // <gid>: {
// title: <title>, // title: <title>,
// count: <count>, // count: <count>,
// ... // ...
// }, // },
//
// // un-initialise default collection...
// //
// // i.e. a collection that is included in
// // .config['default-collections'] and thus present in
// // .collection_order but not present in .collections
// <gid>: false,
//
// ... // ...
// } // }
// //
@ -1781,6 +1879,7 @@ module.CollectionTags = core.ImageGridFeatures.Feature({
;(this.crop_stack || []) ;(this.crop_stack || [])
.forEach(function(d){ d.tags = tags }) .forEach(function(d){ d.tags = tags })
this.data.tags = tags this.data.tags = tags
this.data.sortTags() this.data.sortTags()
} }
}], }],

View File

@ -162,8 +162,6 @@ module.SortActions = actions.Actions({
return e return e
}) })
console.log('>>>>', lst, l, gap)
// rotate index blocks... // rotate index blocks...
if(l > 1){ if(l > 1){
var tail = lst.splice(gap+1, lst.length) var tail = lst.splice(gap+1, lst.length)

View File

@ -269,13 +269,13 @@ var DataPrototype = {
// -> list // -> list
// NOTE: this sets drop_non_order_gids... // NOTE: this sets drop_non_order_gids...
// //
// Plase gids into their .order positions into target... // Place gids into their .order positions into target...
// .makeSparseImages(gids, target) // .makeSparseImages(gids, target)
// -> list // -> list
// NOTE: items in target on given gid .order positions will // NOTE: items in target on given gid .order positions will
// get overwritten... // get overwritten...
// //
// Plase gids into their .order positions into target and reposition // Place gids into their .order positions into target and reposition
// overwritten target items... // overwritten target items...
// .makeSparseImages(gids, target, true) // .makeSparseImages(gids, target, true)
// -> list // -> list
@ -1027,7 +1027,16 @@ var DataPrototype = {
// .getImages(list, 'loaded') // .getImages(list, 'loaded')
// -> list // -> list
// //
// Filter the list and return images present in data...
// .getImages(list, 'all')
// .getImages(list, 'global')
// -> list
//
// Filter the list and return images in current ribbon only...
// .getImages(list, 'current') // .getImages(list, 'current')
// -> list
//
// Filter the list and return images in specific ribbon only...
// .getImages(list, order|ribbon) // .getImages(list, order|ribbon)
// -> list // -> list
// //
@ -1100,19 +1109,25 @@ var DataPrototype = {
// 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 != null && target instanceof Array){
var loaded = count == 'current' ? this.getImages('current') var loaded = count == 'current' ?
: count in this.ribbons ? this.ribbons[count].compact() this.getImages('current')
: count == 'all' || count == 'global' ?
this.getImages('all')
: count in this.ribbons ?
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')
count = null
list = target list = target
.map(function(e){ .map(function(e){
return that.getImage(e) }) return count == 'all' || count == 'global' ?
that.getImage(e, 'global')
: that.getImage(e) })
.filter(function(e){ .filter(function(e){
return loaded.indexOf(e) >= 0 }) return loaded.indexOf(e) >= 0 })
count = null
target = null target = null
// target is ribbon gid... // target is ribbon gid...