mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 10:20:08 +00:00
more work on collection changes...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
af10366c22
commit
ba32b2cce2
@ -191,6 +191,26 @@ var CollectionActions = actions.Actions({
|
|||||||
//
|
//
|
||||||
// Not for direct use.
|
// Not for direct use.
|
||||||
})],
|
})],
|
||||||
|
collectionCreated: ['- Collections/',
|
||||||
|
core.doc`This is called when a collection is created.
|
||||||
|
|
||||||
|
NOTE: this is not triggered for the "${MAIN_COLLECTION_TITLE}" collection...
|
||||||
|
`,
|
||||||
|
core.notUserCallable(function(collection){
|
||||||
|
// This is the window resize event...
|
||||||
|
//
|
||||||
|
// Not for direct use.
|
||||||
|
})],
|
||||||
|
collectionRemoved: ['- Collections/',
|
||||||
|
core.doc`This is called when a collection is removed.
|
||||||
|
|
||||||
|
NOTE: this is not triggered for the "${MAIN_COLLECTION_TITLE}" collection...
|
||||||
|
`,
|
||||||
|
core.notUserCallable(function(collection){
|
||||||
|
// This is the window resize event...
|
||||||
|
//
|
||||||
|
// Not for direct use.
|
||||||
|
})],
|
||||||
|
|
||||||
|
|
||||||
// Collection life-cycle...
|
// Collection life-cycle...
|
||||||
@ -200,6 +220,7 @@ var CollectionActions = actions.Actions({
|
|||||||
|
|
||||||
Load collection...
|
Load collection...
|
||||||
.loadCollection(collection)
|
.loadCollection(collection)
|
||||||
|
.loadCollection(gid)
|
||||||
-> this
|
-> this
|
||||||
|
|
||||||
Force reload current collection...
|
Force reload current collection...
|
||||||
@ -438,12 +459,17 @@ var CollectionActions = actions.Actions({
|
|||||||
'crop'
|
'crop'
|
||||||
: 'current'
|
: 'current'
|
||||||
}
|
}
|
||||||
|
var new_collection =
|
||||||
|
!collections[collection]
|
||||||
|
&& collection != MAIN_COLLECTION_TITLE
|
||||||
|
|
||||||
|
|
||||||
// save the data...
|
// save the data...
|
||||||
var state = collections[collection] = collections[collection] || {}
|
var state = collections[collection] = collections[collection] || {}
|
||||||
state.title = state.title || collection
|
state.title = state.title || collection
|
||||||
state.gid = state.gid || this.data.newGID()
|
state.gid = state.gid
|
||||||
|
// maintain the GID of MAIN_COLLECTION_TITLE as '0'...
|
||||||
|
|| (collection == MAIN_COLLECTION_TITLE ? '0' : this.data.newGID())
|
||||||
// NOTE: we do not need to care about tags here as they
|
// NOTE: we do not need to care about tags here as they
|
||||||
// will get overwritten on load...
|
// will get overwritten on load...
|
||||||
state.data = (mode == 'empty' ?
|
state.data = (mode == 'empty' ?
|
||||||
@ -480,11 +506,19 @@ var CollectionActions = actions.Actions({
|
|||||||
// XXX should we be doing this here or on case by case basis externally...
|
// XXX should we be doing this here or on case by case basis externally...
|
||||||
//collection == this.collection
|
//collection == this.collection
|
||||||
// && this.loadCollection('!')
|
// && this.loadCollection('!')
|
||||||
|
|
||||||
|
new_collection
|
||||||
|
&& this.collectionCreated(collection)
|
||||||
}],
|
}],
|
||||||
newCollection: ['- Collections/',
|
newCollection: ['- Collections/',
|
||||||
|
core.doc` Shorthand to .saveCollection(collection, 'empty')`,
|
||||||
function(collection){ return this.saveCollection(collection, 'empty') }],
|
function(collection){ return this.saveCollection(collection, 'empty') }],
|
||||||
removeCollection: ['- Collections/',
|
removeCollection: ['- Collections/',
|
||||||
core.doc`
|
core.doc`
|
||||||
|
|
||||||
|
.removeCollection(collection)
|
||||||
|
.removeCollection(gid)
|
||||||
|
-> this
|
||||||
|
|
||||||
NOTE: when removing the currently loaded collection this will
|
NOTE: when removing the currently loaded collection this will
|
||||||
just remove it from .collections and do nothing...`,
|
just remove it from .collections and do nothing...`,
|
||||||
@ -492,7 +526,11 @@ var CollectionActions = actions.Actions({
|
|||||||
if(!this.collections || collection == MAIN_COLLECTION_TITLE){
|
if(!this.collections || collection == MAIN_COLLECTION_TITLE){
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
delete this.collections[this.collectionGIDs[collection] || collection]
|
collection = this.collectionGIDs[collection] || collection
|
||||||
|
if(collection in this.collections){
|
||||||
|
delete this.collections[collection]
|
||||||
|
this.collectionRemoved(collection)
|
||||||
|
}
|
||||||
}],
|
}],
|
||||||
|
|
||||||
|
|
||||||
@ -538,6 +576,8 @@ var CollectionActions = actions.Actions({
|
|||||||
|
|
||||||
NOTE: this will not account for item topology. To merge accounting
|
NOTE: this will not account for item topology. To merge accounting
|
||||||
for topology use .joinCollect(..)
|
for topology use .joinCollect(..)
|
||||||
|
NOTE: if an image gid is not found locally it will be searched in
|
||||||
|
base data...
|
||||||
`,
|
`,
|
||||||
function(gids, collection){
|
function(gids, collection){
|
||||||
var that = this
|
var that = this
|
||||||
@ -564,7 +604,9 @@ var CollectionActions = actions.Actions({
|
|||||||
return gid in that.data.ribbons ?
|
return gid in that.data.ribbons ?
|
||||||
// when adding a ribbon gid expand to images...
|
// when adding a ribbon gid expand to images...
|
||||||
that.data.ribbons[gid].compact()
|
that.data.ribbons[gid].compact()
|
||||||
: [that.data.getImage(gid)] })
|
: [ that.data.getImage(gid)
|
||||||
|
// check base data for image 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) }, [])
|
||||||
|
|
||||||
// add to collection...
|
// add to collection...
|
||||||
@ -611,10 +653,17 @@ var CollectionActions = actions.Actions({
|
|||||||
|
|
||||||
if(this.collections && this.collections[collection]){
|
if(this.collections && this.collections[collection]){
|
||||||
//this.collections[collection].data.join(align, data || this.data.clone())
|
//this.collections[collection].data.join(align, data || this.data.clone())
|
||||||
this.collections[collection].data = (data || this.data)
|
var res = this.collections[collection].data = (data || this.data)
|
||||||
.clone()
|
.clone()
|
||||||
.join(align, this.collections[collection].data)
|
.join(align, this.collections[collection].data)
|
||||||
|
|
||||||
|
// joining into the current collection...
|
||||||
|
if(collection == this.collection){
|
||||||
|
var cur = this.current
|
||||||
|
this.data = res
|
||||||
|
this.data.current = cur
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
this.saveCollection(collection)
|
this.saveCollection(collection)
|
||||||
}
|
}
|
||||||
@ -933,33 +982,84 @@ module.Collection = core.ImageGridFeatures.Feature({
|
|||||||
// changes...
|
// changes...
|
||||||
//
|
//
|
||||||
// format:
|
// format:
|
||||||
// XXX we need:
|
// 'collections' - collection list changes
|
||||||
// - mark collection list changes
|
// 'collection: <gid>' - holds collection-specific changes
|
||||||
// collection-list: true
|
|
||||||
// - mark whole collection change
|
|
||||||
// 'collection: <gid>': true
|
|
||||||
// - mark changes local to collection
|
|
||||||
// 'collection: <gid>': [<change>, ..]
|
|
||||||
//
|
//
|
||||||
// XXX maintain changes...
|
// XXX need to maintain changes when loading / unloading collections...
|
||||||
// - collection-level: mark collections as changed...
|
// changes['data'] <-> changes['collection: <gid>': ['data']]
|
||||||
// - in-collection:
|
// collection-list...
|
||||||
// - save/restore parent changes when loading/exiting collections
|
[[
|
||||||
// - move collection chnages to collections
|
'collectionCreated',
|
||||||
// XXX on sriwthicng collections, need to transfer changes + maintain
|
'collectionRemoved',
|
||||||
// global changes...
|
],
|
||||||
|
function(_, collection){
|
||||||
|
// collection list changed...
|
||||||
|
this.markChanged('collections')
|
||||||
|
// collection changed...
|
||||||
|
collection in this.collections
|
||||||
|
&& this.markChanged(
|
||||||
|
'collection: '
|
||||||
|
+JSON.stringify(this.collections[collection].gid || collection))
|
||||||
|
}],
|
||||||
|
// basic collection edits...
|
||||||
[[
|
[[
|
||||||
'collect',
|
'collect',
|
||||||
'joinCollect',
|
'joinCollect',
|
||||||
'uncollect',
|
'uncollect',
|
||||||
|
|
||||||
'saveCollection',
|
|
||||||
|
|
||||||
'removeCollection',
|
|
||||||
],
|
],
|
||||||
function(){
|
function(_, collection){
|
||||||
// XXX mark changed collections...
|
this.markChanged(
|
||||||
// XXX added/removed collection -> mark collection index as changed...
|
'collection: '
|
||||||
|
+JSON.stringify(
|
||||||
|
this.collections[collection || this.collection].gid || collection),
|
||||||
|
['data'])
|
||||||
|
}],
|
||||||
|
// transfer changes on load/unload collection...
|
||||||
|
// XXX also need to account for changes when doing .prepareIndexForWrite(..)
|
||||||
|
// in 'base' mode...
|
||||||
|
//['collectionLoading.pre',
|
||||||
|
['loadCollection.pre',
|
||||||
|
function(collection){
|
||||||
|
var from = this.collection || MAIN_COLLECTION_TITLE
|
||||||
|
var to = collection
|
||||||
|
if(from == to || this.changes === undefined || this.changes === true){
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var data = this.changes === true || (this.changes || {}).data
|
||||||
|
|
||||||
|
return function(){
|
||||||
|
if(to == from){
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var gid = this.collections[to].gid || to
|
||||||
|
var changes = this.changes !== false ?
|
||||||
|
this.changes['collection: '+JSON.stringify(gid)]
|
||||||
|
: []
|
||||||
|
|
||||||
|
// XXX
|
||||||
|
if(changes === true){
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// save data to 'from'...
|
||||||
|
if(data){
|
||||||
|
this.markChanged(
|
||||||
|
'collection: '
|
||||||
|
+JSON.stringify(from == MAIN_COLLECTION_TITLE ?
|
||||||
|
'0'
|
||||||
|
: this.collections[from].gid || from),
|
||||||
|
['data'])
|
||||||
|
}
|
||||||
|
|
||||||
|
// load data from 'to'..
|
||||||
|
if(changes && changes.indexOf('data') >= 0){
|
||||||
|
this.markChanged('data')
|
||||||
|
|
||||||
|
} else if(this.changes && this.changes.data){
|
||||||
|
delete this.changes.data
|
||||||
|
}
|
||||||
|
}
|
||||||
}],
|
}],
|
||||||
|
|
||||||
|
|
||||||
@ -1729,8 +1829,11 @@ module.UICollection = core.ImageGridFeatures.Feature({
|
|||||||
this.reload()
|
this.reload()
|
||||||
}],
|
}],
|
||||||
|
|
||||||
// update view when removing from current collection...
|
// update view when editing current collection...
|
||||||
['uncollect',
|
[[
|
||||||
|
'uncollect',
|
||||||
|
'joinCollect',
|
||||||
|
],
|
||||||
function(_, gids, collection){
|
function(_, gids, collection){
|
||||||
(collection == null || this.collection == collection)
|
(collection == null || this.collection == collection)
|
||||||
&& this.reload(true)
|
&& this.reload(true)
|
||||||
|
|||||||
@ -940,6 +940,9 @@ var ChangesActions = actions.Actions({
|
|||||||
|
|
||||||
// section items...
|
// section items...
|
||||||
} else if(items instanceof Array) {
|
} else if(items instanceof Array) {
|
||||||
|
if(changes[section] === true){
|
||||||
|
return
|
||||||
|
}
|
||||||
changes[section] = (changes[section] || []).concat(items).unique()
|
changes[section] = (changes[section] || []).concat(items).unique()
|
||||||
this.changes = changes
|
this.changes = changes
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user