mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 10:20:08 +00:00
tweaking and refactoring...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
fbb8860a49
commit
4fe084948d
@ -59,6 +59,8 @@ var CollectionActions = actions.Actions({
|
|||||||
// title: <title>,
|
// title: <title>,
|
||||||
// gid: <gid>,
|
// gid: <gid>,
|
||||||
//
|
//
|
||||||
|
// crop_stack: [ .. ],
|
||||||
|
//
|
||||||
// // base collection format -- raw data...
|
// // base collection format -- raw data...
|
||||||
// data: <data>,
|
// data: <data>,
|
||||||
//
|
//
|
||||||
@ -112,6 +114,8 @@ var CollectionActions = actions.Actions({
|
|||||||
// <format>: <action-name>,
|
// <format>: <action-name>,
|
||||||
// ...
|
// ...
|
||||||
// }
|
// }
|
||||||
|
//
|
||||||
|
// XXX should these get auto-sorted???
|
||||||
get collection_handlers(){
|
get collection_handlers(){
|
||||||
var handlers = this.__collection_handlers || {}
|
var handlers = this.__collection_handlers || {}
|
||||||
|
|
||||||
@ -139,11 +143,18 @@ var CollectionActions = actions.Actions({
|
|||||||
loaded as the collection.
|
loaded as the collection.
|
||||||
|
|
||||||
data is of the .collections item format.
|
data is of the .collections item format.
|
||||||
|
|
||||||
|
This will not clone .data, this all changes made to it are
|
||||||
|
persistent.
|
||||||
`,
|
`,
|
||||||
{collectionFormat: 'data'},
|
{collectionFormat: 'data'},
|
||||||
function(title, data){
|
function(title, data){
|
||||||
return new Promise(function(resolve){ resolve(data.data) }) }],
|
return new Promise(function(resolve){ resolve(data.data) }) }],
|
||||||
|
|
||||||
|
// XXX should a collection have its own crop stack???
|
||||||
|
// ...this would be logical as the base collection is persistent
|
||||||
|
// and crop state indicates that uncropping will lose the state...
|
||||||
|
// XXX should this be a crop or just use the same mechanic as crops???
|
||||||
loadCollection: ['- Collections/',
|
loadCollection: ['- Collections/',
|
||||||
core.doc`Load collection...
|
core.doc`Load collection...
|
||||||
|
|
||||||
@ -172,6 +183,8 @@ var CollectionActions = actions.Actions({
|
|||||||
non-data handler is done, it can set the .data which will be loaded
|
non-data handler is done, it can set the .data which will be loaded
|
||||||
directly the next time.
|
directly the next time.
|
||||||
To invalidate such a cache .data should simply be deleted.
|
To invalidate such a cache .data should simply be deleted.
|
||||||
|
|
||||||
|
NOTE: cached collection state is persistent.
|
||||||
`,
|
`,
|
||||||
function(collection){
|
function(collection){
|
||||||
var that = this
|
var that = this
|
||||||
@ -181,27 +194,39 @@ var CollectionActions = actions.Actions({
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var data = this.collections[collection]
|
var current = this.current
|
||||||
|
var ribbon = this.current_ribbon
|
||||||
|
|
||||||
|
var collection_data = this.collections[collection]
|
||||||
var handlers = this.collection_handlers
|
var handlers = this.collection_handlers
|
||||||
|
|
||||||
// XXX might be good to sort handlers...
|
|
||||||
// XXX
|
|
||||||
|
|
||||||
for(var format in handlers){
|
for(var format in handlers){
|
||||||
if(data[format]){
|
if(collection_data[format]){
|
||||||
return this[handlers[format]](collection, data)
|
return this[handlers[format]](collection, collection_data)
|
||||||
.then(function(data){
|
.then(function(data){
|
||||||
data
|
if(!data){
|
||||||
&& that.crop.chainCall(that, function(){
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// current...
|
||||||
|
data.current = data.getImage(current)
|
||||||
|
// current is not in collection -> try and keep the ribbon context...
|
||||||
|
|| that.data.getImage(current, data.getImages(that.data.getImages(ribbon)))
|
||||||
|
// get closest image from collection...
|
||||||
|
|| that.data.getImage(current, data.order)
|
||||||
|
|| data.current
|
||||||
|
|
||||||
|
that.crop.chainCall(that, function(){
|
||||||
// NOTE: the collection and .data may have different
|
// NOTE: the collection and .data may have different
|
||||||
// orders and/or sets of elements, this we need
|
// orders and/or sets of elements, this we need
|
||||||
// to sync, and do it BEFORE all the rendering
|
// to sync, and do it BEFORE all the rendering
|
||||||
// happens...
|
// happens...
|
||||||
that.data.updateImagePositions()
|
this.data.updateImagePositions()
|
||||||
}, data)
|
}, data)
|
||||||
|
|
||||||
// NOTE: we need this to sync the possible different
|
// NOTE: we need this to sync the possible different
|
||||||
// states (order, ...) of the collection and .data...
|
// states (order, ...) of the collection and .data...
|
||||||
&& that.collectionLoaded(collection)
|
that.collectionLoaded(collection)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -497,10 +522,6 @@ module.Collection = core.ImageGridFeatures.Feature({
|
|||||||
&& collection != this.data.collection
|
&& collection != this.data.collection
|
||||||
&& this.collectionUnloaded(collection) }
|
&& this.collectionUnloaded(collection) }
|
||||||
}],
|
}],
|
||||||
['collectionLoaded',
|
|
||||||
function(){
|
|
||||||
console.log('COLLECTION: LOADED')
|
|
||||||
}],
|
|
||||||
['collectionUnloaded',
|
['collectionUnloaded',
|
||||||
function(_, collection){
|
function(_, collection){
|
||||||
var collection = this.location.collection = this.data.collection
|
var collection = this.location.collection = this.data.collection
|
||||||
@ -510,10 +531,57 @@ module.Collection = core.ImageGridFeatures.Feature({
|
|||||||
delete this.location.collection
|
delete this.location.collection
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('COLLECTION: UNLOADED')
|
|
||||||
|
|
||||||
this.data.updateImagePositions()
|
this.data.updateImagePositions()
|
||||||
}],
|
}],
|
||||||
|
|
||||||
|
// XXX maintain changes...
|
||||||
|
// - collection-level: mark collections as changed...
|
||||||
|
// - in-collection:
|
||||||
|
// - save/restore parent changes when loading/exiting collections
|
||||||
|
// - move collection chnages to collections
|
||||||
|
[[
|
||||||
|
'collect',
|
||||||
|
'joinCollect',
|
||||||
|
'uncollect',
|
||||||
|
|
||||||
|
'saveCollection',
|
||||||
|
|
||||||
|
'removeCollection',
|
||||||
|
],
|
||||||
|
function(){
|
||||||
|
// XXX mark changed collections...
|
||||||
|
// XXX added/removed collection -> mark collection index as changed...
|
||||||
|
}],
|
||||||
|
|
||||||
|
|
||||||
|
['prepareIndexForWrite',
|
||||||
|
function(res, _, full){
|
||||||
|
var changed = full == true
|
||||||
|
|| res.changes === true
|
||||||
|
|| res.changes.collections
|
||||||
|
|
||||||
|
if(changed && res.raw.collections){
|
||||||
|
// select the actual changed collection list...
|
||||||
|
changed = changed === true ?
|
||||||
|
Object.keys(res.raw.collections)
|
||||||
|
: changed
|
||||||
|
|
||||||
|
// collection index...
|
||||||
|
res.index['collection-index'] = Object.keys(this.collections)
|
||||||
|
|
||||||
|
Object.keys(changed)
|
||||||
|
// skip the raw field...
|
||||||
|
.filter(function(k){ return changed.indexOf(k) >= 0 })
|
||||||
|
.forEach(function(k){
|
||||||
|
// XXX use collection gid...
|
||||||
|
res.index['collections/' + k] = res.raw.collections[k]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}],
|
||||||
|
['prepareJSONForLoad',
|
||||||
|
function(res, json, base_path){
|
||||||
|
// XXX
|
||||||
|
}],
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -521,8 +589,6 @@ module.Collection = core.ImageGridFeatures.Feature({
|
|||||||
|
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
|
|
||||||
// XXX make collections sortable...
|
|
||||||
// XXX do we need a collection button (like crop button?) ???
|
|
||||||
// XXX show collections in image metadata...
|
// XXX show collections in image metadata...
|
||||||
var UICollectionActions = actions.Actions({
|
var UICollectionActions = actions.Actions({
|
||||||
browseCollections: ['Collections|Crop/$Collec$tions...',
|
browseCollections: ['Collections|Crop/$Collec$tions...',
|
||||||
@ -740,52 +806,6 @@ module.FileSystemCollection = core.ImageGridFeatures.Feature({
|
|||||||
actions: FileSystemCollectionActions,
|
actions: FileSystemCollectionActions,
|
||||||
|
|
||||||
handlers: [
|
handlers: [
|
||||||
// XXX maintain changes...
|
|
||||||
// XXX
|
|
||||||
[[
|
|
||||||
'collect',
|
|
||||||
'joinCollect',
|
|
||||||
'uncollect',
|
|
||||||
|
|
||||||
'saveCollection',
|
|
||||||
|
|
||||||
'removeCollection',
|
|
||||||
],
|
|
||||||
function(){
|
|
||||||
// XXX mark changed collections...
|
|
||||||
// XXX added/removed collection -> mark collection index as changed...
|
|
||||||
}],
|
|
||||||
|
|
||||||
// XXX handle removed collections -- move to trash (???)
|
|
||||||
// ...might be a good idea to add something like index gc API...
|
|
||||||
['prepareIndexForWrite',
|
|
||||||
function(res, _, full){
|
|
||||||
var changed = full == true
|
|
||||||
|| res.changes === true
|
|
||||||
|| res.changes.collections
|
|
||||||
|
|
||||||
if(changed && res.raw.collections){
|
|
||||||
// select the actual changed collection list...
|
|
||||||
changed = changed === true ?
|
|
||||||
Object.keys(res.raw.collections)
|
|
||||||
: changed
|
|
||||||
|
|
||||||
// collection index...
|
|
||||||
res.index['collection-index'] = Object.keys(this.collections)
|
|
||||||
|
|
||||||
Object.keys(changed)
|
|
||||||
// skip the raw field...
|
|
||||||
.filter(function(k){ return changed.indexOf(k) >= 0 })
|
|
||||||
.forEach(function(k){
|
|
||||||
// XXX use collection gid...
|
|
||||||
res.index['collections/' + k] = res.raw.collections[k]
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}],
|
|
||||||
['prepareJSONForLoad',
|
|
||||||
function(res, json){
|
|
||||||
// XXX
|
|
||||||
}],
|
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@ -1761,7 +1761,9 @@ var ButtonsActions = actions.Actions({
|
|||||||
// }
|
// }
|
||||||
'main-buttons': {
|
'main-buttons': {
|
||||||
'☰': ['menu', 'browseActions -- Action menu...'],
|
'☰': ['menu', 'browseActions -- Action menu...'],
|
||||||
|
'◲<sub/>': ['collections', 'browseCollections -- Collections...'],
|
||||||
'C<sub/>': ['crop', 'browseActions: "Crop/" -- Crop menu...'],
|
'C<sub/>': ['crop', 'browseActions: "Crop/" -- Crop menu...'],
|
||||||
|
//'▤<sub/>': ['collections', 'browseCollections -- Collections...'],
|
||||||
//'⛶': ['view', 'toggleSingleImage -- Single image / ribbon toggle'],
|
//'⛶': ['view', 'toggleSingleImage -- Single image / ribbon toggle'],
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -1847,7 +1849,27 @@ module.Buttons = core.ImageGridFeatures.Feature({
|
|||||||
['load clear reload',
|
['load clear reload',
|
||||||
function(){
|
function(){
|
||||||
$('.main-buttons.buttons .crop.button sub')
|
$('.main-buttons.buttons .crop.button sub')
|
||||||
.text(this.crop_stack ? this.crop_stack.length : '') }],
|
// XXX should this be here or in CSS???
|
||||||
|
.css({
|
||||||
|
'display': 'inline-block',
|
||||||
|
'width': '0px',
|
||||||
|
'overflow': 'visible',
|
||||||
|
})
|
||||||
|
.text(this.crop_stack ? this.crop_stack.length : '')
|
||||||
|
}],
|
||||||
|
// update collection button status...
|
||||||
|
['load clear reload collectionLoaded collectionUnloaded',
|
||||||
|
function(){
|
||||||
|
$('.main-buttons.buttons .collections.button sub')
|
||||||
|
// XXX should this be here or in CSS???
|
||||||
|
.css({
|
||||||
|
'display': 'inline-block',
|
||||||
|
'width': '0px',
|
||||||
|
'overflow': 'visible',
|
||||||
|
'color': 'yellow',
|
||||||
|
})
|
||||||
|
.html(this.collection ? '●' : '')
|
||||||
|
}],
|
||||||
// update zoom button status...
|
// update zoom button status...
|
||||||
['viewScale',
|
['viewScale',
|
||||||
function(){
|
function(){
|
||||||
|
|||||||
@ -1253,7 +1253,7 @@ module.Cursor = core.ImageGridFeatures.Feature({
|
|||||||
// ...this is already done in widget.overlay, but I think should be
|
// ...this is already done in widget.overlay, but I think should be
|
||||||
// system-wide...
|
// system-wide...
|
||||||
|
|
||||||
// XXX STUB: needs more thought....
|
// XXX needs more thought....
|
||||||
var ControlActions = actions.Actions({
|
var ControlActions = actions.Actions({
|
||||||
config: {
|
config: {
|
||||||
'control-mode': 'indirect',
|
'control-mode': 'indirect',
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user