mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-28 18:00:09 +00:00
some refactoring (.collection_order)...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
54aef8ec16
commit
7c6cc73bee
@ -89,6 +89,11 @@ var CollectionActions = actions.Actions({
|
|||||||
// ...technically no, but we need this to resolve correctly
|
// ...technically no, but we need this to resolve correctly
|
||||||
// to a relevant feature...
|
// to a relevant feature...
|
||||||
'collection-transfer-changes': COLLECTION_TRANSFER_CHANGES.slice(),
|
'collection-transfer-changes': COLLECTION_TRANSFER_CHANGES.slice(),
|
||||||
|
|
||||||
|
// Global default collections...
|
||||||
|
//
|
||||||
|
// NOTE: delete or set to null for none...
|
||||||
|
//'default-collections': null,
|
||||||
},
|
},
|
||||||
|
|
||||||
// Format:
|
// Format:
|
||||||
@ -129,12 +134,16 @@ var CollectionActions = actions.Actions({
|
|||||||
this.collection = value },
|
this.collection = value },
|
||||||
|
|
||||||
// XXX should this check consistency???
|
// XXX should this check consistency???
|
||||||
|
// XXX would be nice for these to also include default collections...
|
||||||
get collection_order(){
|
get collection_order(){
|
||||||
|
var collections = this.collections
|
||||||
|
var defaults = this.config['default-collections'] || []
|
||||||
|
|
||||||
|
// no collections -> return defaults | []
|
||||||
if(this.collections == null){
|
if(this.collections == null){
|
||||||
return null
|
return defaults.slice()
|
||||||
}
|
}
|
||||||
|
|
||||||
var collections = this.collections
|
|
||||||
var keys = Object.keys(collections)
|
var keys = Object.keys(collections)
|
||||||
var order = this.__collection_order = this.__collection_order || []
|
var order = this.__collection_order = this.__collection_order || []
|
||||||
|
|
||||||
@ -145,6 +154,9 @@ var CollectionActions = actions.Actions({
|
|||||||
.unique()
|
.unique()
|
||||||
.reverse()
|
.reverse()
|
||||||
|
|
||||||
|
// XXX defaults...
|
||||||
|
res = res.concat(defaults).unique()
|
||||||
|
|
||||||
// keep MAIN_COLLECTION_TITLE out of the collection order...
|
// keep MAIN_COLLECTION_TITLE out of the collection order...
|
||||||
var m = res.indexOf(MAIN_COLLECTION_TITLE)
|
var m = res.indexOf(MAIN_COLLECTION_TITLE)
|
||||||
m >= 0
|
m >= 0
|
||||||
@ -152,7 +164,9 @@ var CollectionActions = actions.Actions({
|
|||||||
|
|
||||||
// remove stuff not present...
|
// remove stuff not present...
|
||||||
if(res.length > keys.length){
|
if(res.length > keys.length){
|
||||||
res = res.filter(function(e){ return e in collections })
|
res = res.filter(function(e){
|
||||||
|
return e in collections
|
||||||
|
|| defaults.indexOf(e) >= 0 })
|
||||||
}
|
}
|
||||||
|
|
||||||
this.__collection_order.splice(0, this.__collection_order.length, ...res)
|
this.__collection_order.splice(0, this.__collection_order.length, ...res)
|
||||||
@ -683,7 +697,7 @@ var CollectionActions = actions.Actions({
|
|||||||
`,
|
`,
|
||||||
function(cmp){
|
function(cmp){
|
||||||
// XXX handle the case when there's no .__collection_order
|
// XXX handle the case when there's no .__collection_order
|
||||||
if(!this.__collection_order && !this.collection_order){
|
if(!this.__collection_order){
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -720,7 +734,7 @@ var CollectionActions = actions.Actions({
|
|||||||
function(collection){
|
function(collection){
|
||||||
collection = collection || this.collection
|
collection = collection || this.collection
|
||||||
collection = this.collectionGIDs[collection] || collection
|
collection = this.collectionGIDs[collection] || collection
|
||||||
var o = this.collection_order || []
|
var o = this.collection_order
|
||||||
|
|
||||||
if(!collection || o.indexOf(collection) < 0){
|
if(!collection || o.indexOf(collection) < 0){
|
||||||
return
|
return
|
||||||
@ -735,13 +749,15 @@ var CollectionActions = actions.Actions({
|
|||||||
// XXX make this check offline collections -- use .ensureCollection(..)
|
// XXX make this check offline collections -- use .ensureCollection(..)
|
||||||
inCollections: ['- Image/',
|
inCollections: ['- Image/',
|
||||||
core.doc`Get list of collections containing item`,
|
core.doc`Get list of collections containing item`,
|
||||||
function(gid){
|
function(gid, collections){
|
||||||
var that = this
|
var that = this
|
||||||
gid = this.data.getImage(gid)
|
gid = this.data.getImage(gid)
|
||||||
//return Object.keys(this.collections || {})
|
collections = collections || this.collection_order
|
||||||
return (this.collection_order || [])
|
collections = collections instanceof Array ? collections : [collections]
|
||||||
|
return collections
|
||||||
.filter(function(c){
|
.filter(function(c){
|
||||||
return c != MAIN_COLLECTION_TITLE
|
return c != MAIN_COLLECTION_TITLE
|
||||||
|
&& that.collections[c]
|
||||||
&& that.collections[c].data
|
&& that.collections[c].data
|
||||||
&& (!gid
|
&& (!gid
|
||||||
|| that.collections[c].data.getImage(gid)) })
|
|| that.collections[c].data.getImage(gid)) })
|
||||||
@ -757,6 +773,7 @@ var CollectionActions = actions.Actions({
|
|||||||
|
|
||||||
// Collection editing....
|
// Collection editing....
|
||||||
//
|
//
|
||||||
|
// XXX should this add images that already exist???
|
||||||
collect: ['- Collections/',
|
collect: ['- Collections/',
|
||||||
core.doc`Add items to collection
|
core.doc`Add items to collection
|
||||||
|
|
||||||
@ -975,6 +992,10 @@ var CollectionActions = actions.Actions({
|
|||||||
}
|
}
|
||||||
|
|
||||||
Object.keys(c).forEach(function(title){
|
Object.keys(c).forEach(function(title){
|
||||||
|
if(c[title] === false){
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var state = collections[title] = { title: title }
|
var state = collections[title] = { title: title }
|
||||||
|
|
||||||
// load data...
|
// load data...
|
||||||
@ -1017,8 +1038,8 @@ var CollectionActions = actions.Actions({
|
|||||||
|
|
||||||
return function(){
|
return function(){
|
||||||
if(Object.keys(collections).length > 0){
|
if(Object.keys(collections).length > 0){
|
||||||
this.collection_order = order
|
|
||||||
this.collections = collections
|
this.collections = collections
|
||||||
|
this.collection_order = order
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}],
|
}],
|
||||||
@ -1042,11 +1063,11 @@ var CollectionActions = actions.Actions({
|
|||||||
json: [function(mode){ return function(res){
|
json: [function(mode){ return function(res){
|
||||||
mode = mode || 'current'
|
mode = mode || 'current'
|
||||||
|
|
||||||
var collections = this.collections
|
var collections = this.collections || {}
|
||||||
|
var order = this.collection_order
|
||||||
|
|
||||||
// NOTE: if mode is 'current' ignore collections...
|
// NOTE: if mode is 'current' ignore collections...
|
||||||
if(mode != 'current' && collections){
|
if(mode != 'current' && order.length > 0){
|
||||||
var order = this.collection_order
|
|
||||||
// NOTE: .collection_order does not return MAIN_COLLECTION_TITLE
|
// NOTE: .collection_order does not return MAIN_COLLECTION_TITLE
|
||||||
// so we have to add it in manually...
|
// so we have to add it in manually...
|
||||||
order = MAIN_COLLECTION_TITLE in collections ?
|
order = MAIN_COLLECTION_TITLE in collections ?
|
||||||
@ -1073,6 +1094,13 @@ var CollectionActions = actions.Actions({
|
|||||||
|
|
||||||
var state = collections[title]
|
var state = collections[title]
|
||||||
|
|
||||||
|
// collection does not exist (default collection)...
|
||||||
|
// XXX
|
||||||
|
if(state == null){
|
||||||
|
res.collections[title] = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// build the JSON...
|
// build the JSON...
|
||||||
var s = res.collections[title] = { title: title }
|
var s = res.collections[title] = { title: title }
|
||||||
if(state.gid){
|
if(state.gid){
|
||||||
@ -1836,21 +1864,25 @@ module.CollectionTags = core.ImageGridFeatures.Feature({
|
|||||||
['load',
|
['load',
|
||||||
function(_, json){
|
function(_, json){
|
||||||
var that = this
|
var that = this
|
||||||
Object.keys(json.collections || {})
|
this.collections
|
||||||
// skip loaded collections that are already Data objects...
|
&& Object.keys(json.collections || {})
|
||||||
// XXX not sure about this...
|
// skip loaded collections that are already Data objects...
|
||||||
.filter(function(title){
|
// XXX not sure about this...
|
||||||
return !(json.collections[title].data instanceof data.Data) })
|
.filter(function(title){
|
||||||
// do the loading...
|
return !(json.collections[title].data instanceof data.Data) })
|
||||||
.forEach(function(title){
|
// do the loading...
|
||||||
var c = that.collections[title]
|
.forEach(function(title){
|
||||||
var t = (c.data || {}).tags || {}
|
var c = that.collections[title]
|
||||||
|
if(!c){
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var t = (c.data || {}).tags || {}
|
||||||
|
|
||||||
c.local_tags = c.local_tags || {}
|
c.local_tags = c.local_tags || {}
|
||||||
;(that.config['collection-local-tags'] || [])
|
;(that.config['collection-local-tags'] || [])
|
||||||
.forEach(function(tag){
|
.forEach(function(tag){
|
||||||
c.local_tags[tag] = c.local_tags[tag] || t[tag] || [] })
|
c.local_tags[tag] = c.local_tags[tag] || t[tag] || [] })
|
||||||
})
|
})
|
||||||
}],
|
}],
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
@ -2023,6 +2055,10 @@ module.AutoCollections = core.ImageGridFeatures.Feature({
|
|||||||
var cur = c[title]
|
var cur = c[title]
|
||||||
var r = rc[title]
|
var r = rc[title]
|
||||||
|
|
||||||
|
if(!cur){
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// XXX is this the right way to go???
|
// XXX is this the right way to go???
|
||||||
if('tag_query' in cur){
|
if('tag_query' in cur){
|
||||||
r.tag_query = cur.tag_query
|
r.tag_query = cur.tag_query
|
||||||
@ -2048,11 +2084,6 @@ module.AutoCollections = core.ImageGridFeatures.Feature({
|
|||||||
// ...show the base ribbon from collection as background
|
// ...show the base ribbon from collection as background
|
||||||
var UICollectionActions = actions.Actions({
|
var UICollectionActions = actions.Actions({
|
||||||
config: {
|
config: {
|
||||||
// Global default collections...
|
|
||||||
//
|
|
||||||
// NOTE: delete or set to null for none...
|
|
||||||
//'default-collections': null,
|
|
||||||
|
|
||||||
// Last used collection (for adding merging)...
|
// Last used collection (for adding merging)...
|
||||||
//
|
//
|
||||||
// This will be auto-selected in .browseCollections(..) on next
|
// This will be auto-selected in .browseCollections(..) on next
|
||||||
@ -2060,23 +2091,6 @@ var UICollectionActions = actions.Actions({
|
|||||||
//'collection-last-used': null,
|
//'collection-last-used': null,
|
||||||
},
|
},
|
||||||
|
|
||||||
// XXX should this be in Collections/ ???
|
|
||||||
editDefaultCollections: ['Interface|Collections/Edit default collections...',
|
|
||||||
widgets.makeConfigListEditorDialog(
|
|
||||||
'default-collections',
|
|
||||||
{
|
|
||||||
cls: 'collection-list',
|
|
||||||
|
|
||||||
unique: true,
|
|
||||||
sortable: 'y',
|
|
||||||
|
|
||||||
normalize: function(title){
|
|
||||||
return title.trim() },
|
|
||||||
check: function(title){
|
|
||||||
return title.length > 0
|
|
||||||
&& title != MAIN_COLLECTION_TITLE },
|
|
||||||
})],
|
|
||||||
|
|
||||||
// XXX would be nice to make this nested (i.e. path list) -- collection grouping...
|
// XXX would be nice to make this nested (i.e. path list) -- collection grouping...
|
||||||
browseCollections: ['Collections/$Collections...',
|
browseCollections: ['Collections/$Collections...',
|
||||||
core.doc`Collection list...
|
core.doc`Collection list...
|
||||||
@ -2088,12 +2102,11 @@ var UICollectionActions = actions.Actions({
|
|||||||
var to_remove = []
|
var to_remove = []
|
||||||
|
|
||||||
var collections = that.collection_order =
|
var collections = that.collection_order =
|
||||||
(that.collection_order || []).slice()
|
//(that.collection_order || []).slice()
|
||||||
|
that.collection_order.slice()
|
||||||
|
|
||||||
var defaults = that.config['default-collections']
|
//var defaults = that.config['default-collections'] || []
|
||||||
if(defaults){
|
//collections = collections.concat(defaults).unique()
|
||||||
collections = collections.concat(defaults).unique()
|
|
||||||
}
|
|
||||||
|
|
||||||
return browse.makeLister(null,
|
return browse.makeLister(null,
|
||||||
function(path, make){
|
function(path, make){
|
||||||
@ -2264,6 +2277,7 @@ var UICollectionActions = actions.Actions({
|
|||||||
.forEach(function(title){ that.removeCollection(title) })
|
.forEach(function(title){ that.removeCollection(title) })
|
||||||
})
|
})
|
||||||
})],
|
})],
|
||||||
|
// XXX should this be able to add new collections???
|
||||||
browseImageCollections: ['Collections|Image/Image $collections...',
|
browseImageCollections: ['Collections|Image/Image $collections...',
|
||||||
widgets.makeUIDialog(function(gid){
|
widgets.makeUIDialog(function(gid){
|
||||||
var that = this
|
var that = this
|
||||||
@ -2407,6 +2421,23 @@ var UICollectionActions = actions.Actions({
|
|||||||
that.config['collection-last-used'] = title })
|
that.config['collection-last-used'] = title })
|
||||||
})],
|
})],
|
||||||
|
|
||||||
|
// XXX should this be in Collections/ ???
|
||||||
|
editDefaultCollections: ['Interface|Collections/Edit default collections...',
|
||||||
|
widgets.makeConfigListEditorDialog(
|
||||||
|
'default-collections',
|
||||||
|
{
|
||||||
|
cls: 'collection-list',
|
||||||
|
|
||||||
|
unique: true,
|
||||||
|
sortable: 'y',
|
||||||
|
|
||||||
|
normalize: function(title){
|
||||||
|
return title.trim() },
|
||||||
|
check: function(title){
|
||||||
|
return title.length > 0
|
||||||
|
&& title != MAIN_COLLECTION_TITLE },
|
||||||
|
})],
|
||||||
|
|
||||||
/*/ XXX this is not used by metadata yet...
|
/*/ XXX this is not used by metadata yet...
|
||||||
// XXX might be a nice idea to define a default make(..) function
|
// XXX might be a nice idea to define a default make(..) function
|
||||||
// to return JSON...
|
// to return JSON...
|
||||||
|
|||||||
@ -1302,6 +1302,7 @@ var BrowseActionsActions = actions.Actions({
|
|||||||
'Crop/-81:Uncrop all',
|
'Crop/-81:Uncrop all',
|
||||||
'Crop/-82:$Uncrop',
|
'Crop/-82:$Uncrop',
|
||||||
'Collec$tions',
|
'Collec$tions',
|
||||||
|
'Collections/-60:.*edit.*',
|
||||||
'Collections/-70:---',
|
'Collections/-70:---',
|
||||||
'Collections/-70:.*remove.*',
|
'Collections/-70:.*remove.*',
|
||||||
'$Mark',
|
'$Mark',
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user