mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-28 18:00:09 +00:00
some work on auto-collections...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
91b8d0bce0
commit
71ac19f5a0
@ -644,6 +644,7 @@ var CollectionActions = actions.Actions({
|
|||||||
// NOTE: currently this only stores title and data, it is the
|
// NOTE: currently this only stores title and data, it is the
|
||||||
// responsibility of extending features to store their specific
|
// responsibility of extending features to store their specific
|
||||||
// data in collections...
|
// data in collections...
|
||||||
|
// XXX is this the right way to go???
|
||||||
json: [function(mode){ return function(res){
|
json: [function(mode){ return function(res){
|
||||||
mode = mode || 'current'
|
mode = mode || 'current'
|
||||||
|
|
||||||
@ -769,7 +770,7 @@ module.Collection = core.ImageGridFeatures.Feature({
|
|||||||
],
|
],
|
||||||
suggested: [
|
suggested: [
|
||||||
'collection-tags',
|
'collection-tags',
|
||||||
'auto-collection-tags',
|
'auto-collections',
|
||||||
|
|
||||||
'ui-collections',
|
'ui-collections',
|
||||||
'fs-collections',
|
'fs-collections',
|
||||||
@ -1021,19 +1022,78 @@ module.CollectionTags = core.ImageGridFeatures.Feature({
|
|||||||
|
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
|
|
||||||
// XXX should we ignore .local_tags here or get them from main collection
|
// XXX add UI...
|
||||||
// only???
|
var AutoCollectionsActions = actions.Actions({
|
||||||
// XXX do we need real tag queries???
|
collectionAutoLevelLoader: ['- Collections/',
|
||||||
var AutoTagCollectionsActions = actions.Actions({
|
core.doc`
|
||||||
config: {
|
|
||||||
// Can be:
|
|
||||||
// 'ignore-local' (default)
|
|
||||||
// 'main-collection-local'
|
|
||||||
//'auto-collection-tags-mode': 'ignore-local',
|
|
||||||
'auto-collection-tags-mode': 'main-collection-local',
|
|
||||||
},
|
|
||||||
|
|
||||||
|
`,
|
||||||
|
{collectionFormat: 'level_query'},
|
||||||
|
function(title, state){
|
||||||
|
return new Promise((function(resolve){
|
||||||
|
var source = state.source || MAIN_COLLECTION_TITLE
|
||||||
|
source = source == MAIN_COLLECTION_TITLE ?
|
||||||
|
((this.crop_stack || [])[0]
|
||||||
|
|| this.data)
|
||||||
|
// XXX need a way to preload collection data...
|
||||||
|
: ((this.collection[source].crop_stack || [])[0]
|
||||||
|
|| this.collections[source].data)
|
||||||
|
|
||||||
|
var query = state.level_query
|
||||||
|
query = query == 'top' ?
|
||||||
|
[0, 1]
|
||||||
|
: query == 'bottom' ?
|
||||||
|
[-1]
|
||||||
|
: query instanceof Array ?
|
||||||
|
query
|
||||||
|
: typeof(query) == typeof('str') ?
|
||||||
|
query.split('+').map(function(e){ return e.trim() })
|
||||||
|
: query > 0 ?
|
||||||
|
[0, query]
|
||||||
|
: [query]
|
||||||
|
query = query[0] == 'top' ?
|
||||||
|
[0, parseInt(query[1])+1]
|
||||||
|
: query[0] == 'bottom' ?
|
||||||
|
[-parseInt(query[1])-1]
|
||||||
|
: query
|
||||||
|
|
||||||
|
var levels = source.ribbon_order.slice.apply(source.ribbon_order, query)
|
||||||
|
|
||||||
|
var gids = []
|
||||||
|
levels.forEach(function(gid){
|
||||||
|
source.makeSparseImages(source.ribbons[gid], gids) })
|
||||||
|
gids = gids.compact()
|
||||||
|
|
||||||
|
// get items that topped matching the query...
|
||||||
|
var remove = state.data ?
|
||||||
|
state.data.order
|
||||||
|
.filter(function(gid){ return gids.indexOf(gid) < 0 })
|
||||||
|
: []
|
||||||
|
|
||||||
|
// build data...
|
||||||
|
state.data = data.Data.fromArray(gids)
|
||||||
|
// join with saved state...
|
||||||
|
.join(state.data || data.Data())
|
||||||
|
// remove unmatching...
|
||||||
|
.clear(remove)
|
||||||
|
|
||||||
|
resolve()
|
||||||
|
}).bind(this)) }],
|
||||||
|
makeAutoLevelCollection: ['- Collections/',
|
||||||
|
core.doc`Make level auto-collection...
|
||||||
|
|
||||||
|
`,
|
||||||
|
function(title, source, a, b){
|
||||||
|
// XXX query
|
||||||
|
var query = b != null ? [a, b] : a
|
||||||
|
|
||||||
|
this.saveCollection(title, 'empty')
|
||||||
|
|
||||||
|
this.collections[title].level_query = query
|
||||||
|
this.collections[title].source = source
|
||||||
|
}],
|
||||||
|
|
||||||
|
// XXX do we need real tag queries???
|
||||||
collectionAutoTagsLoader: ['- Collections/',
|
collectionAutoTagsLoader: ['- Collections/',
|
||||||
core.doc`
|
core.doc`
|
||||||
|
|
||||||
@ -1043,7 +1103,6 @@ var AutoTagCollectionsActions = actions.Actions({
|
|||||||
{collectionFormat: 'tag_query'},
|
{collectionFormat: 'tag_query'},
|
||||||
function(title, state){
|
function(title, state){
|
||||||
return new Promise((function(resolve){
|
return new Promise((function(resolve){
|
||||||
var local_tags_mode = this.config['auto-collection-tags-mode'] || 'ignore-local'
|
|
||||||
var local_tag_names = this.config['collection-local-tags'] || []
|
var local_tag_names = this.config['collection-local-tags'] || []
|
||||||
|
|
||||||
var tags = (state.tag_query || [])
|
var tags = (state.tag_query || [])
|
||||||
@ -1068,8 +1127,6 @@ var AutoTagCollectionsActions = actions.Actions({
|
|||||||
|
|
||||||
resolve()
|
resolve()
|
||||||
}).bind(this)) }],
|
}).bind(this)) }],
|
||||||
|
|
||||||
// XXX add UI...
|
|
||||||
makeAutoTagCollection: ['- Collections/',
|
makeAutoTagCollection: ['- Collections/',
|
||||||
core.doc`Make tag auto-collection...
|
core.doc`Make tag auto-collection...
|
||||||
|
|
||||||
@ -1082,7 +1139,7 @@ var AutoTagCollectionsActions = actions.Actions({
|
|||||||
NOTE: at least one tag must be supplied...
|
NOTE: at least one tag must be supplied...
|
||||||
`,
|
`,
|
||||||
function(title, tags){
|
function(title, tags){
|
||||||
tags = arguments.length > 2 ? [].slice.call(arguments) : tags
|
tags = arguments.length > 2 ? [].slice.call(arguments, 1) : tags
|
||||||
tags = tags instanceof Array ? tags : [tags]
|
tags = tags instanceof Array ? tags : [tags]
|
||||||
|
|
||||||
if(tags.length == 0){
|
if(tags.length == 0){
|
||||||
@ -1095,9 +1152,9 @@ var AutoTagCollectionsActions = actions.Actions({
|
|||||||
}],
|
}],
|
||||||
})
|
})
|
||||||
|
|
||||||
var AutoTagCollections =
|
var AutoCollections =
|
||||||
module.AutoTagCollections = core.ImageGridFeatures.Feature({
|
module.AutoCollections = core.ImageGridFeatures.Feature({
|
||||||
title: 'Auto tag collection',
|
title: 'Auto collections',
|
||||||
doc: core.doc`
|
doc: core.doc`
|
||||||
A collection is different from a crop in that it:
|
A collection is different from a crop in that it:
|
||||||
- preserves ribbon state
|
- preserves ribbon state
|
||||||
@ -1109,12 +1166,12 @@ module.AutoTagCollections = core.ImageGridFeatures.Feature({
|
|||||||
images to collection.
|
images to collection.
|
||||||
`,
|
`,
|
||||||
|
|
||||||
tag: 'auto-collection-tags',
|
tag: 'auto-collections',
|
||||||
depends: [
|
depends: [
|
||||||
'collections',
|
'collections',
|
||||||
],
|
],
|
||||||
|
|
||||||
actions: AutoTagCollectionsActions,
|
actions: AutoCollectionsActions,
|
||||||
|
|
||||||
handlers: [
|
handlers: [
|
||||||
['json',
|
['json',
|
||||||
@ -1124,9 +1181,18 @@ module.AutoTagCollections = core.ImageGridFeatures.Feature({
|
|||||||
|
|
||||||
Object.keys(rc)
|
Object.keys(rc)
|
||||||
.forEach(function(title){
|
.forEach(function(title){
|
||||||
var q = c[title].tag_query
|
var cur = c[title]
|
||||||
if(q){
|
var r = rc[title]
|
||||||
rc[title].tag_query = q
|
|
||||||
|
// XXX is this the right way to go???
|
||||||
|
if('tag_query' in cur){
|
||||||
|
r.tag_query = cur.tag_query
|
||||||
|
|
||||||
|
} else if('level_query' in cur){
|
||||||
|
r.level_query = cur.level_query
|
||||||
|
if(cur.source){
|
||||||
|
r.source = cur.source
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}],
|
}],
|
||||||
|
|||||||
@ -597,11 +597,15 @@ var DataPrototype = {
|
|||||||
// do the actual removal...
|
// do the actual removal...
|
||||||
// NOTE: splicing fixed image indexes is faster than
|
// NOTE: splicing fixed image indexes is faster than
|
||||||
// .updateImagePositions('remove')
|
// .updateImagePositions('remove')
|
||||||
gids.forEach(function(gid){
|
this.makeSparseImages(gids)
|
||||||
var i = that.order.indexOf(gid)
|
// NOTE: we move from the tail to account for shifting
|
||||||
that.eachImageList(function(lst){
|
// indexes on removal...
|
||||||
lst.splice(i, 1) })
|
.reverse()
|
||||||
})
|
.forEach(function(gid){
|
||||||
|
var i = that.order.indexOf(gid)
|
||||||
|
that.eachImageList(function(lst){
|
||||||
|
lst.splice(i, 1) })
|
||||||
|
})
|
||||||
this.order = order
|
this.order = order
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user