mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 02:10:08 +00:00
more tweaking...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
861cef15b8
commit
948607690c
@ -42,6 +42,7 @@ var widgets = require('features/ui-widgets')
|
|||||||
// XXX handle tags here???
|
// XXX handle tags here???
|
||||||
// ...keep them global or local to collection???
|
// ...keep them global or local to collection???
|
||||||
// global sounds better...
|
// global sounds better...
|
||||||
|
// XXX undo...
|
||||||
var CollectionActions = actions.Actions({
|
var CollectionActions = actions.Actions({
|
||||||
|
|
||||||
// Format:
|
// Format:
|
||||||
@ -49,6 +50,8 @@ var CollectionActions = actions.Actions({
|
|||||||
// <title>: {
|
// <title>: {
|
||||||
// title: <title>,
|
// title: <title>,
|
||||||
// gid: <gid>,
|
// gid: <gid>,
|
||||||
|
//
|
||||||
|
// // base collection format -- raw data...
|
||||||
// data: <data>,
|
// data: <data>,
|
||||||
// ...
|
// ...
|
||||||
// },
|
// },
|
||||||
@ -61,11 +64,36 @@ var CollectionActions = actions.Actions({
|
|||||||
set collection(value){
|
set collection(value){
|
||||||
this.loadCollection(value) },
|
this.loadCollection(value) },
|
||||||
|
|
||||||
// XXX need a way to prevent multiple loads...
|
// Format:
|
||||||
// ...checking if .collection is set to collection is logical but
|
// {
|
||||||
// may prevent reloading of collections -- i.e. loading a collection
|
// <format>: <action-name>,
|
||||||
// anew if it is already loaded...
|
// ...
|
||||||
// XXX doc the protocol...
|
// }
|
||||||
|
//
|
||||||
|
// NOTE: the 'data' handler is always first...
|
||||||
|
get collection_handlers(){
|
||||||
|
var handlers = this.__collection_handlers || {}
|
||||||
|
|
||||||
|
if(Object.keys(handlers).length == 0){
|
||||||
|
var that = this
|
||||||
|
handlers['data'] = null
|
||||||
|
this.actions.forEach(function(action){
|
||||||
|
var fmt = that.getActionAttr(action, 'collectionFormat')
|
||||||
|
if(fmt){
|
||||||
|
handlers[fmt] = action
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return handlers
|
||||||
|
},
|
||||||
|
|
||||||
|
collectionDataLoader: ['- Collections/',
|
||||||
|
core.doc`Collection data loader`,
|
||||||
|
{collectionFormat: 'data'},
|
||||||
|
function(title, data){
|
||||||
|
return new Promise(function(resolve){ resolve(data.data) }) }],
|
||||||
|
|
||||||
loadCollection: ['- Collections/',
|
loadCollection: ['- Collections/',
|
||||||
core.doc`Load collection...
|
core.doc`Load collection...
|
||||||
|
|
||||||
@ -75,28 +103,58 @@ var CollectionActions = actions.Actions({
|
|||||||
this enables extending actions to handle the collection in
|
this enables extending actions to handle the collection in
|
||||||
different ways.
|
different ways.
|
||||||
|
|
||||||
The extending action if compatible must:
|
Protocol:
|
||||||
- construct data
|
- collection format handlers: .collection_handlers
|
||||||
- load data via:
|
- built from actions that define .collectionFormat attr to
|
||||||
this.crop(data)
|
contain the target format string.
|
||||||
- when done call:
|
- format is determined by matching it to a key in .collections[collection]
|
||||||
this.collectionLoaded(collection)
|
e.g. 'data' is applicable if .collections[collection].data is not null
|
||||||
|
- the format key's value is passed to the handler action
|
||||||
|
- the handler is expected to return a promise
|
||||||
|
- only the first matching handler is called
|
||||||
|
- the data handler is always first to get checked
|
||||||
|
|
||||||
XXX would be good to have a way to check if loading was done
|
For an example handler see:
|
||||||
within this .loadCollection(..) call...
|
.collectionDataLoader(..)
|
||||||
|
|
||||||
|
|
||||||
|
The .data handler is always first to enable caching, i.e. once some
|
||||||
|
non-data handler is done, it can set the .data which will be loaded
|
||||||
|
directly the next time.
|
||||||
|
To invalidate such a cache .data should simply be deleted.
|
||||||
`,
|
`,
|
||||||
function(collection){
|
function(collection){
|
||||||
|
var that = this
|
||||||
if(collection == null
|
if(collection == null
|
||||||
|| this.collections == null
|
|| this.collections == null
|
||||||
|| !(collection in this.collections)){
|
|| !(collection in this.collections)){
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var data = this.collections[collection].data
|
var data = this.collections[collection]
|
||||||
|
var handlers = this.collection_handlers
|
||||||
|
|
||||||
data
|
// XXX might be good to sort handlers...
|
||||||
&& this.crop(data)
|
// XXX
|
||||||
&& this.collectionLoaded(collection)
|
|
||||||
|
for(var format in handlers){
|
||||||
|
if(data[format]){
|
||||||
|
return this[handlers[format]](collection, data)
|
||||||
|
.then(function(data){
|
||||||
|
data
|
||||||
|
&& that.crop.chainCall(that, function(){
|
||||||
|
// NOTE: the collection and .data may have different
|
||||||
|
// orders and/or sets of elements, this we need
|
||||||
|
// to sync, and do it BEFORE all the rendering
|
||||||
|
// happens...
|
||||||
|
that.data.updateImagePositions()
|
||||||
|
}, data)
|
||||||
|
// NOTE: we need this to sync the possible different
|
||||||
|
// states (order, ...) of the collection and .data...
|
||||||
|
&& that.collectionLoaded(collection)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
}],
|
}],
|
||||||
|
|
||||||
collectionLoaded: ['- Collections/',
|
collectionLoaded: ['- Collections/',
|
||||||
@ -148,9 +206,14 @@ var CollectionActions = actions.Actions({
|
|||||||
data: (empty ?
|
data: (empty ?
|
||||||
(new this.data.constructor())
|
(new this.data.constructor())
|
||||||
: this.data
|
: this.data
|
||||||
.crop())
|
.clone()
|
||||||
|
.removeUnloadedGIDs())
|
||||||
.run(function(){
|
.run(function(){
|
||||||
this.collection = collection
|
this.collection = collection
|
||||||
|
// NOTE: we are doing this manually after .removeUnloadedGIDs(..)
|
||||||
|
// as the later will mess-up the structures
|
||||||
|
// inherited from the main .data, namely tags...
|
||||||
|
this.tags = that.data.tags
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
}],
|
}],
|
||||||
@ -166,7 +229,6 @@ var CollectionActions = actions.Actions({
|
|||||||
.filter(function(c){
|
.filter(function(c){
|
||||||
return !gid
|
return !gid
|
||||||
|| that.collections[c].data.getImage(gid) })
|
|| that.collections[c].data.getImage(gid) })
|
||||||
//|| that.collections[c].data.order.indexOf(gid) >= 0 })
|
|
||||||
}],
|
}],
|
||||||
|
|
||||||
collect: ['- Collections/',
|
collect: ['- Collections/',
|
||||||
@ -258,7 +320,7 @@ var CollectionActions = actions.Actions({
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: we are not using .data.updateImagePositions(gids, 'hide')
|
/*/ NOTE: we are not using .data.updateImagePositions(gids, 'hide')
|
||||||
// here because it will remove the gids from everything
|
// here because it will remove the gids from everything
|
||||||
// while we need them removed only from ribbons...
|
// while we need them removed only from ribbons...
|
||||||
var hideGIDs = function(){
|
var hideGIDs = function(){
|
||||||
@ -270,15 +332,18 @@ var CollectionActions = actions.Actions({
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
//*/
|
||||||
|
|
||||||
if(this.collection == collection){
|
if(this.collection == collection){
|
||||||
this.data
|
this.data
|
||||||
.run(hideGIDs)
|
//.run(hideGIDs)
|
||||||
|
.removeGIDs(gids)
|
||||||
.removeEmptyRibbons()
|
.removeEmptyRibbons()
|
||||||
}
|
}
|
||||||
|
|
||||||
this.collections[collection].data
|
this.collections[collection].data
|
||||||
.run(hideGIDs)
|
//.run(hideGIDs)
|
||||||
|
.removeGIDs(gids)
|
||||||
.removeEmptyRibbons()
|
.removeEmptyRibbons()
|
||||||
}],
|
}],
|
||||||
|
|
||||||
@ -329,12 +394,14 @@ var CollectionActions = actions.Actions({
|
|||||||
}
|
}
|
||||||
} }],
|
} }],
|
||||||
clear: [function(){
|
clear: [function(){
|
||||||
this.collectionUnloaded('*')
|
this.collection
|
||||||
|
&& this.collectionUnloaded('*')
|
||||||
delete this.collections
|
delete this.collections
|
||||||
delete this.location.collection
|
delete this.location.collection
|
||||||
}],
|
}],
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
// XXX manage format...
|
// XXX manage format...
|
||||||
// XXX manage changes...
|
// XXX manage changes...
|
||||||
var Collection =
|
var Collection =
|
||||||
@ -360,20 +427,26 @@ module.Collection = core.ImageGridFeatures.Feature({
|
|||||||
function(){
|
function(){
|
||||||
var collection = this.collection
|
var collection = this.collection
|
||||||
return function(){
|
return function(){
|
||||||
collection != this.data.collection
|
collection != null
|
||||||
|
&& collection != this.data.collection
|
||||||
&& this.collectionUnloaded(collection) }
|
&& this.collectionUnloaded(collection) }
|
||||||
}],
|
}],
|
||||||
['collectionLoaded',
|
['collectionLoaded',
|
||||||
function(){
|
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
|
||||||
|
|
||||||
// cleanup...
|
// cleanup...
|
||||||
if(collection == null){
|
if(collection == null){
|
||||||
delete this.location.collection
|
delete this.location.collection
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('COLLECTION: UNLOADED')
|
||||||
|
|
||||||
|
this.data.updateImagePositions()
|
||||||
}],
|
}],
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
@ -551,10 +624,27 @@ module.UICollection = core.ImageGridFeatures.Feature({
|
|||||||
// - lazy load collections (load list, lazy-load data)
|
// - lazy load collections (load list, lazy-load data)
|
||||||
// - load directories as collections...
|
// - load directories as collections...
|
||||||
// - export collections to directories...
|
// - export collections to directories...
|
||||||
|
// - collection history...
|
||||||
|
|
||||||
// XXX lazy load collections...
|
|
||||||
var FileSystemCollectionActions = actions.Actions({
|
var FileSystemCollectionActions = actions.Actions({
|
||||||
|
|
||||||
|
// Format:
|
||||||
|
// {
|
||||||
|
// path: <string>,
|
||||||
|
// ...
|
||||||
|
// }
|
||||||
|
collections: null,
|
||||||
|
|
||||||
|
collectionPathLoader: ['- Collections/',
|
||||||
|
{collectionFormat: 'path'},
|
||||||
|
function(data, loader){
|
||||||
|
// XXX
|
||||||
|
}],
|
||||||
|
|
||||||
|
loadPathCollections: ['- Collections/',
|
||||||
|
function(){
|
||||||
|
// XXX
|
||||||
|
}],
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -741,7 +741,8 @@ var DataPrototype = {
|
|||||||
// invalid gid...
|
// invalid gid...
|
||||||
// XXX need a better way to report errors...
|
// XXX need a better way to report errors...
|
||||||
if(i == -1){
|
if(i == -1){
|
||||||
return -1
|
//return -1
|
||||||
|
return undefined
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1326,7 +1327,7 @@ var DataPrototype = {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// maintain focus...
|
// maintain focus...
|
||||||
if(from.indexOf(this.current) >= 0){
|
if(from && from.indexOf(this.current) >= 0){
|
||||||
this.focusImage('r')
|
this.focusImage('r')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user