mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 18:30:09 +00:00
refactoring...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
90d0fe6b31
commit
83404e9714
@ -120,8 +120,7 @@ var CollectionActions = actions.Actions({
|
|||||||
var c = this.collections || {}
|
var c = this.collections || {}
|
||||||
Object.keys(c)
|
Object.keys(c)
|
||||||
.forEach(function(title){
|
.forEach(function(title){
|
||||||
res[c[title].gid || title] = title
|
res[c[title].gid || title] = title })
|
||||||
})
|
|
||||||
return res },
|
return res },
|
||||||
|
|
||||||
get collection(){
|
get collection(){
|
||||||
@ -141,8 +140,7 @@ var CollectionActions = actions.Actions({
|
|||||||
|
|
||||||
// no collections -> return defaults | []
|
// no collections -> return defaults | []
|
||||||
if(this.collections == null){
|
if(this.collections == null){
|
||||||
return defaults.slice()
|
return defaults.slice() }
|
||||||
}
|
|
||||||
|
|
||||||
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 || []
|
||||||
@ -166,14 +164,14 @@ var CollectionActions = actions.Actions({
|
|||||||
if(res.length > keys.length){
|
if(res.length > keys.length){
|
||||||
res = res.filter(function(e){
|
res = res.filter(function(e){
|
||||||
return e in collections
|
return e in collections
|
||||||
|| defaults.indexOf(e) >= 0 })
|
|| defaults.indexOf(e) >= 0 }) }
|
||||||
}
|
|
||||||
|
|
||||||
this.__collection_order.splice(0, this.__collection_order.length, ...res)
|
this.__collection_order.splice(0, this.__collection_order.length, ...res)
|
||||||
|
|
||||||
return this.__collection_order.slice() },
|
return this.__collection_order.slice() },
|
||||||
set collection_order(value){
|
set collection_order(value){
|
||||||
value && this.sortCollections(value) },
|
value
|
||||||
|
&& this.sortCollections(value) },
|
||||||
|
|
||||||
// NOTE: this accounts only for actual collections and does not counts
|
// NOTE: this accounts only for actual collections and does not counts
|
||||||
// MAIN_COLLECTION_TITLE that can be contained in .collections,
|
// MAIN_COLLECTION_TITLE that can be contained in .collections,
|
||||||
@ -202,8 +200,7 @@ var CollectionActions = actions.Actions({
|
|||||||
return this.cache('collection_handlers', function(handlers){
|
return this.cache('collection_handlers', function(handlers){
|
||||||
// cached value...
|
// cached value...
|
||||||
if(handlers){
|
if(handlers){
|
||||||
return Object.assign({}, handlers)
|
return Object.assign({}, handlers) }
|
||||||
}
|
|
||||||
|
|
||||||
var that = this
|
var that = this
|
||||||
handlers = {}
|
handlers = {}
|
||||||
@ -214,14 +211,11 @@ var CollectionActions = actions.Actions({
|
|||||||
handlers[fmt]
|
handlers[fmt]
|
||||||
&& console.warn('Multiple handlers for collection format:', store)
|
&& console.warn('Multiple handlers for collection format:', store)
|
||||||
if(fmt){
|
if(fmt){
|
||||||
handlers[fmt] = action
|
handlers[fmt] = action } })
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// cleanup...
|
// cleanup...
|
||||||
if(handlers['data'] == null){
|
if(handlers['data'] == null){
|
||||||
delete handlers['data']
|
delete handlers['data'] }
|
||||||
}
|
|
||||||
|
|
||||||
return handlers }) },
|
return handlers }) },
|
||||||
|
|
||||||
@ -321,7 +315,7 @@ var CollectionActions = actions.Actions({
|
|||||||
return running[collection] }
|
return running[collection] }
|
||||||
|
|
||||||
// handle collection...
|
// handle collection...
|
||||||
p = running[collection] = new Promise(function(resolve, reject){
|
return (running[collection] = new Promise(function(resolve, reject){
|
||||||
// NOTE: we do not need to return this as we'll resolve/reject
|
// NOTE: we do not need to return this as we'll resolve/reject
|
||||||
// manually in .then(..) / .catch(..)
|
// manually in .then(..) / .catch(..)
|
||||||
Promise
|
Promise
|
||||||
@ -337,9 +331,7 @@ var CollectionActions = actions.Actions({
|
|||||||
resolve(collection_data) })
|
resolve(collection_data) })
|
||||||
.catch(function(err){
|
.catch(function(err){
|
||||||
delete running[collection]
|
delete running[collection]
|
||||||
reject(err) }) })
|
reject(err) }) })) }],
|
||||||
|
|
||||||
return p }],
|
|
||||||
|
|
||||||
|
|
||||||
// Collection life-cycle...
|
// Collection life-cycle...
|
||||||
@ -474,8 +466,8 @@ var CollectionActions = actions.Actions({
|
|||||||
that.load.chainCall(that,
|
that.load.chainCall(that,
|
||||||
function(){
|
function(){
|
||||||
that.collectionUnloaded(
|
that.collectionUnloaded(
|
||||||
prev || MAIN_COLLECTION_TITLE)
|
prev || MAIN_COLLECTION_TITLE) },
|
||||||
}, {
|
{
|
||||||
location: that.location,
|
location: that.location,
|
||||||
|
|
||||||
data: data,
|
data: data,
|
||||||
@ -496,15 +488,13 @@ var CollectionActions = actions.Actions({
|
|||||||
// locations...
|
// locations...
|
||||||
delete that.collections[MAIN_COLLECTION_TITLE]
|
delete that.collections[MAIN_COLLECTION_TITLE]
|
||||||
delete this.location.collection
|
delete this.location.collection
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
that.data.collection =
|
that.data.collection =
|
||||||
that.location.collection =
|
that.location.collection =
|
||||||
collection
|
collection
|
||||||
// cleanup...
|
// cleanup...
|
||||||
if(collection == null){
|
if(collection == null){
|
||||||
delete this.location.collection } }
|
delete this.location.collection } } },
|
||||||
},
|
|
||||||
collection) }) }],
|
collection) }) }],
|
||||||
// XXX should this call .loadCollection('!') when saving to current
|
// XXX should this call .loadCollection('!') when saving to current
|
||||||
// collection???
|
// collection???
|
||||||
@ -584,8 +574,11 @@ var CollectionActions = actions.Actions({
|
|||||||
&& collection != MAIN_COLLECTION_TITLE
|
&& collection != MAIN_COLLECTION_TITLE
|
||||||
|
|
||||||
// save the data...
|
// save the data...
|
||||||
var state = collections[collection] = collections[collection] || {}
|
var state = collections[collection] =
|
||||||
state.title = state.title || collection
|
collections[collection]
|
||||||
|
|| {}
|
||||||
|
state.title = state.title
|
||||||
|
|| collection
|
||||||
state.gid = state.gid
|
state.gid = state.gid
|
||||||
// maintain the GID of MAIN_COLLECTION_TITLE as MAIN_COLLECTION_GID...
|
// maintain the GID of MAIN_COLLECTION_TITLE as MAIN_COLLECTION_GID...
|
||||||
|| (collection == MAIN_COLLECTION_TITLE ?
|
|| (collection == MAIN_COLLECTION_TITLE ?
|
||||||
@ -596,8 +589,7 @@ var CollectionActions = actions.Actions({
|
|||||||
do{
|
do{
|
||||||
var gid = that.data.newGID()
|
var gid = that.data.newGID()
|
||||||
} while(gids[gid] != null)
|
} while(gids[gid] != null)
|
||||||
return gid
|
return gid })())
|
||||||
})())
|
|
||||||
// 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' ?
|
||||||
@ -610,8 +602,7 @@ var CollectionActions = actions.Actions({
|
|||||||
: this.data.clone()
|
: this.data.clone()
|
||||||
.run(function(){
|
.run(function(){
|
||||||
var d = this
|
var d = this
|
||||||
this.collection = collection
|
this.collection = collection })
|
||||||
})
|
|
||||||
.clear('unloaded'))
|
.clear('unloaded'))
|
||||||
|
|
||||||
// crop mode -> handle crop stack...
|
// crop mode -> handle crop stack...
|
||||||
@ -649,8 +640,7 @@ var CollectionActions = actions.Actions({
|
|||||||
just remove it from .collections and do nothing...`,
|
just remove it from .collections and do nothing...`,
|
||||||
function(collection){
|
function(collection){
|
||||||
if(!this.collections || collection == MAIN_COLLECTION_TITLE){
|
if(!this.collections || collection == MAIN_COLLECTION_TITLE){
|
||||||
return
|
return }
|
||||||
}
|
|
||||||
collection = this.collectionGIDs[collection] || collection
|
collection = this.collectionGIDs[collection] || collection
|
||||||
if(collection in this.collections){
|
if(collection in this.collections){
|
||||||
delete this.collections[collection]
|
delete this.collections[collection]
|
||||||
@ -699,21 +689,16 @@ 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){
|
if(!this.__collection_order){
|
||||||
return
|
return }
|
||||||
}
|
|
||||||
|
|
||||||
// sort via list...
|
// sort via list...
|
||||||
if(cmp instanceof Array){
|
if(cmp instanceof Array){
|
||||||
this.__collection_order = cmp.slice()
|
this.__collection_order = cmp.slice()
|
||||||
|
|
||||||
// cmp...
|
// cmp...
|
||||||
} else if(cmp instanceof Function){
|
} else if(cmp instanceof Function){
|
||||||
this.__collection_order.sort(cmp)
|
this.__collection_order.sort(cmp)
|
||||||
|
|
||||||
// basic sort...
|
// basic sort...
|
||||||
} else {
|
} else {
|
||||||
this.__collection_order.sort()
|
this.__collection_order.sort() }
|
||||||
}
|
|
||||||
this.collection_order }],
|
this.collection_order }],
|
||||||
collectionToTop: ['Collections/Bring collection to $top',
|
collectionToTop: ['Collections/Bring collection to $top',
|
||||||
core.doc`Bring collection to top...
|
core.doc`Bring collection to top...
|
||||||
@ -737,8 +722,7 @@ var CollectionActions = actions.Actions({
|
|||||||
var o = this.collection_order
|
var o = this.collection_order
|
||||||
|
|
||||||
if(!collection || o.indexOf(collection) < 0){
|
if(!collection || o.indexOf(collection) < 0){
|
||||||
return
|
return }
|
||||||
}
|
|
||||||
|
|
||||||
this.collection_order = [collection].concat(o).unique() }],
|
this.collection_order = [collection].concat(o).unique() }],
|
||||||
|
|
||||||
@ -1055,7 +1039,9 @@ var CollectionActions = actions.Actions({
|
|||||||
var that = this
|
var that = this
|
||||||
gids = gids || 'current'
|
gids = gids || 'current'
|
||||||
gids = gids instanceof Array ? gids : [gids]
|
gids = gids instanceof Array ? gids : [gids]
|
||||||
gids = gids.map(function(gid){ return that.data.getRibbon(gid) })
|
gids = gids
|
||||||
|
.map(function(gid){
|
||||||
|
return that.data.getRibbon(gid) })
|
||||||
return this.uncollect(gids, collection) }],
|
return this.uncollect(gids, collection) }],
|
||||||
|
|
||||||
|
|
||||||
@ -1111,8 +1097,7 @@ var CollectionActions = actions.Actions({
|
|||||||
.forEach(function(key){
|
.forEach(function(key){
|
||||||
if(key in state){
|
if(key in state){
|
||||||
return }
|
return }
|
||||||
state[key] = c[title][key]
|
state[key] = c[title][key] }) })
|
||||||
}) })
|
|
||||||
|
|
||||||
return function(){
|
return function(){
|
||||||
if(Object.keys(collections).length > 0){
|
if(Object.keys(collections).length > 0){
|
||||||
@ -1177,8 +1162,7 @@ var CollectionActions = actions.Actions({
|
|||||||
// 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){
|
||||||
s.gid = state.gid
|
s.gid = state.gid }
|
||||||
}
|
|
||||||
var data = ((mode == 'base' && state.crop_stack) ?
|
var data = ((mode == 'base' && state.crop_stack) ?
|
||||||
(state.crop_stack[0] || state.data)
|
(state.crop_stack[0] || state.data)
|
||||||
: state.data)
|
: state.data)
|
||||||
@ -1193,16 +1177,14 @@ var CollectionActions = actions.Actions({
|
|||||||
// NOTE: in base mode, crop_stack is ignored...
|
// NOTE: in base mode, crop_stack is ignored...
|
||||||
if(mode != 'base' && state.crop_stack){
|
if(mode != 'base' && state.crop_stack){
|
||||||
s.crop_stack = state.crop_stack
|
s.crop_stack = state.crop_stack
|
||||||
.map(function(d){ return d.json() }) }
|
.map(function(d){ return d.json() }) } }) } } }],
|
||||||
}) } } }],
|
|
||||||
clone: [function(full){
|
clone: [function(full){
|
||||||
return function(res){
|
return function(res){
|
||||||
if(this.collections){
|
if(this.collections){
|
||||||
var cur = this.collections
|
var cur = this.collections
|
||||||
|
|
||||||
if(this.collection){
|
if(this.collection){
|
||||||
res.location.collection = this.collection
|
res.location.collection = this.collection }
|
||||||
}
|
|
||||||
|
|
||||||
collections = res.collections = {}
|
collections = res.collections = {}
|
||||||
this.collection_order
|
this.collection_order
|
||||||
@ -1335,9 +1317,7 @@ module.Collection = core.ImageGridFeatures.Feature({
|
|||||||
return function(){
|
return function(){
|
||||||
;(this.collection_order || [])
|
;(this.collection_order || [])
|
||||||
.filter(function(e, i){ return e != o[i] }).length > 0
|
.filter(function(e, i){ return e != o[i] }).length > 0
|
||||||
&& this.markChanged('collections')
|
&& this.markChanged('collections') } }],
|
||||||
}
|
|
||||||
}],
|
|
||||||
// collection title/list...
|
// collection title/list...
|
||||||
['renameCollection',
|
['renameCollection',
|
||||||
function(_, from, to){
|
function(_, from, to){
|
||||||
@ -1378,9 +1358,7 @@ module.Collection = core.ImageGridFeatures.Feature({
|
|||||||
&& that.markChanged(
|
&& that.markChanged(
|
||||||
'collection: '
|
'collection: '
|
||||||
+JSON.stringify(collection.gid || title),
|
+JSON.stringify(collection.gid || title),
|
||||||
['data'])
|
['data']) }) } }],
|
||||||
}) }
|
|
||||||
}],
|
|
||||||
['joinCollect',
|
['joinCollect',
|
||||||
function(_, align, collection, data){
|
function(_, align, collection, data){
|
||||||
var args = [...arguments]
|
var args = [...arguments]
|
||||||
@ -1393,16 +1371,14 @@ module.Collection = core.ImageGridFeatures.Feature({
|
|||||||
&& this.markChanged(
|
&& this.markChanged(
|
||||||
'collection: '
|
'collection: '
|
||||||
+JSON.stringify(collection.gid || title),
|
+JSON.stringify(collection.gid || title),
|
||||||
['data'])
|
['data']) }],
|
||||||
}],
|
|
||||||
// transfer changes on load/unload collection...
|
// transfer changes on load/unload collection...
|
||||||
['collectionLoading.pre',
|
['collectionLoading.pre',
|
||||||
function(to){
|
function(to){
|
||||||
var that = this
|
var that = this
|
||||||
var from = this.collection || MAIN_COLLECTION_TITLE
|
var from = this.collection || MAIN_COLLECTION_TITLE
|
||||||
if(from == to || this.changes === undefined || this.changes === true){
|
if(from == to || this.changes === undefined || this.changes === true){
|
||||||
return
|
return }
|
||||||
}
|
|
||||||
|
|
||||||
var change_tags = this.config['collection-transfer-changes']
|
var change_tags = this.config['collection-transfer-changes']
|
||||||
|| COLLECTION_TRANSFER_CHANGES
|
|| COLLECTION_TRANSFER_CHANGES
|
||||||
@ -1413,8 +1389,7 @@ module.Collection = core.ImageGridFeatures.Feature({
|
|||||||
|
|
||||||
return function(){
|
return function(){
|
||||||
if(to == from){
|
if(to == from){
|
||||||
return
|
return }
|
||||||
}
|
|
||||||
var gid = (this.collections[to] || {}).gid || to
|
var gid = (this.collections[to] || {}).gid || to
|
||||||
var changes = this.changes !== false ?
|
var changes = this.changes !== false ?
|
||||||
this.changes['collection: '+JSON.stringify(gid)]
|
this.changes['collection: '+JSON.stringify(gid)]
|
||||||
@ -1426,8 +1401,7 @@ module.Collection = core.ImageGridFeatures.Feature({
|
|||||||
|
|
||||||
// everything has changed, no need to bother with details...
|
// everything has changed, no need to bother with details...
|
||||||
if(changes === true){
|
if(changes === true){
|
||||||
return
|
return }
|
||||||
}
|
|
||||||
|
|
||||||
// save changes to 'from'...
|
// save changes to 'from'...
|
||||||
from_changes.length > 0
|
from_changes.length > 0
|
||||||
@ -1439,11 +1413,7 @@ module.Collection = core.ImageGridFeatures.Feature({
|
|||||||
that.markChanged(item)
|
that.markChanged(item)
|
||||||
|
|
||||||
} else if(that.changes && that.changes[item]){
|
} else if(that.changes && that.changes[item]){
|
||||||
delete that.changes[item]
|
delete that.changes[item] } }) } }],
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}],
|
|
||||||
// update current collection changes...
|
// update current collection changes...
|
||||||
//
|
//
|
||||||
// This will:
|
// This will:
|
||||||
@ -1457,15 +1427,13 @@ module.Collection = core.ImageGridFeatures.Feature({
|
|||||||
function(mode){
|
function(mode){
|
||||||
var cur = this.collection || MAIN_COLLECTION_TITLE
|
var cur = this.collection || MAIN_COLLECTION_TITLE
|
||||||
if(cur == null || cur == MAIN_COLLECTION_TITLE){
|
if(cur == null || cur == MAIN_COLLECTION_TITLE){
|
||||||
return
|
return }
|
||||||
}
|
|
||||||
|
|
||||||
var changes = this.changes
|
var changes = this.changes
|
||||||
|
|
||||||
// everything/nothing changed -- nothing to do...
|
// everything/nothing changed -- nothing to do...
|
||||||
if(!changes || changes === true || changes[cur] === true){
|
if(!changes || changes === true || changes[cur] === true){
|
||||||
return
|
return }
|
||||||
}
|
|
||||||
|
|
||||||
var gid = this.collectionGID
|
var gid = this.collectionGID
|
||||||
var id = 'collection: '+ JSON.stringify(gid)
|
var id = 'collection: '+ JSON.stringify(gid)
|
||||||
@ -1479,8 +1447,7 @@ module.Collection = core.ImageGridFeatures.Feature({
|
|||||||
if(changed.length > 0 && this.changes[id] !== true){
|
if(changed.length > 0 && this.changes[id] !== true){
|
||||||
this.changes[id] = (this.changes[id] || [])
|
this.changes[id] = (this.changes[id] || [])
|
||||||
.concat(changed)
|
.concat(changed)
|
||||||
.unique()
|
.unique() }
|
||||||
}
|
|
||||||
|
|
||||||
// reset the base change tags to the base data (from collection data)...
|
// reset the base change tags to the base data (from collection data)...
|
||||||
if(mode == 'base'){
|
if(mode == 'base'){
|
||||||
@ -1496,10 +1463,7 @@ module.Collection = core.ImageGridFeatures.Feature({
|
|||||||
delete res.changes[tag] })
|
delete res.changes[tag] })
|
||||||
// set...
|
// set...
|
||||||
base.forEach(function(tag){
|
base.forEach(function(tag){
|
||||||
res.changes[tag] = true })
|
res.changes[tag] = true }) } } }],
|
||||||
}
|
|
||||||
}
|
|
||||||
}],
|
|
||||||
|
|
||||||
|
|
||||||
// Handle collection serialization format...
|
// Handle collection serialization format...
|
||||||
@ -1580,8 +1544,7 @@ module.Collection = core.ImageGridFeatures.Feature({
|
|||||||
['prepareIndexForWrite',
|
['prepareIndexForWrite',
|
||||||
function(res){
|
function(res){
|
||||||
if(!res.changes){
|
if(!res.changes){
|
||||||
return
|
return }
|
||||||
}
|
|
||||||
var that = this
|
var that = this
|
||||||
var changes = res.changes
|
var changes = res.changes
|
||||||
var collections = this.collections
|
var collections = this.collections
|
||||||
@ -1622,15 +1585,11 @@ module.Collection = core.ImageGridFeatures.Feature({
|
|||||||
var m = index[gid] = { title: title }
|
var m = index[gid] = { title: title }
|
||||||
|
|
||||||
if(res.raw.collections[title].count){
|
if(res.raw.collections[title].count){
|
||||||
m['count'] = res.raw.collections[title].count
|
m['count'] = res.raw.collections[title].count }
|
||||||
}
|
|
||||||
|
|
||||||
// empty / default collections (placeholders)...
|
// empty / default collections (placeholders)...
|
||||||
} else {
|
} else {
|
||||||
index[title] = false
|
index[title] = false } }) }
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// collections...
|
// collections...
|
||||||
if((full.length > 0 || partial.length > 0)
|
if((full.length > 0 || partial.length > 0)
|
||||||
@ -1658,15 +1617,14 @@ module.Collection = core.ImageGridFeatures.Feature({
|
|||||||
var local_changes = partial.indexOf(k) < 0 || {}
|
var local_changes = partial.indexOf(k) < 0 || {}
|
||||||
if(local_changes !== true && res.changes[id] !== true){
|
if(local_changes !== true && res.changes[id] !== true){
|
||||||
(res.changes[id] || [])
|
(res.changes[id] || [])
|
||||||
.forEach(function(c){ local_changes[c] = true })
|
.forEach(function(c){
|
||||||
}
|
local_changes[c] = true }) }
|
||||||
|
|
||||||
// collections/<gid>/metadata
|
// collections/<gid>/metadata
|
||||||
var metadata = {}
|
var metadata = {}
|
||||||
if(full.indexOf(k) >= 0
|
if(full.indexOf(k) >= 0
|
||||||
|| res.changes[id].indexOf('metadata') >= 0){
|
|| res.changes[id].indexOf('metadata') >= 0){
|
||||||
res.index[path +'/metadata'] = metadata
|
res.index[path +'/metadata'] = metadata }
|
||||||
}
|
|
||||||
Object.keys(raw)
|
Object.keys(raw)
|
||||||
.forEach(function(key){ metadata[key] = raw[key] })
|
.forEach(function(key){ metadata[key] = raw[key] })
|
||||||
|
|
||||||
@ -1678,16 +1636,11 @@ module.Collection = core.ImageGridFeatures.Feature({
|
|||||||
.filter(function(key){ return key != 'collections' })
|
.filter(function(key){ return key != 'collections' })
|
||||||
.forEach(function(key){
|
.forEach(function(key){
|
||||||
res.index[path +'/'+ key] = prepared[key]
|
res.index[path +'/'+ key] = prepared[key]
|
||||||
delete metadata[key]
|
delete metadata[key] })
|
||||||
})
|
|
||||||
// cleanup metadata...
|
// cleanup metadata...
|
||||||
// XXX do we need this???
|
// XXX do we need this???
|
||||||
change_tags.forEach(function(key){
|
change_tags.forEach(function(key){
|
||||||
delete metadata[key]
|
delete metadata[key] }) }) } }],
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}],
|
|
||||||
// XXX merge multiple collections...
|
// XXX merge multiple collections...
|
||||||
// ...this can be called multiple times pre single load, once
|
// ...this can be called multiple times pre single load, once
|
||||||
// per merged index...
|
// per merged index...
|
||||||
@ -1705,14 +1658,12 @@ module.Collection = core.ImageGridFeatures.Feature({
|
|||||||
.map(function(k){
|
.map(function(k){
|
||||||
return index[k] ? index[k].gid || index[k].title || k : k })
|
return index[k] ? index[k].gid || index[k].title || k : k })
|
||||||
if(order.length > 0){
|
if(order.length > 0){
|
||||||
res.collection_order = order
|
res.collection_order = order }
|
||||||
}
|
|
||||||
|
|
||||||
// collection data...
|
// collection data...
|
||||||
Object.keys(index).forEach(function(gid){
|
Object.keys(index).forEach(function(gid){
|
||||||
if(index[gid] === false){
|
if(index[gid] === false){
|
||||||
return
|
return }
|
||||||
}
|
|
||||||
|
|
||||||
//var title = index[gid]
|
//var title = index[gid]
|
||||||
var title = index[gid].title || index[gid]
|
var title = index[gid].title || index[gid]
|
||||||
@ -1727,14 +1678,10 @@ module.Collection = core.ImageGridFeatures.Feature({
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(index[gid].count){
|
if(index[gid].count){
|
||||||
m.count = index[gid].count
|
m.count = index[gid].count } }) }
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if(Object.keys(collections).length > 0){
|
if(Object.keys(collections).length > 0){
|
||||||
res.collections = collections
|
res.collections = collections }
|
||||||
}
|
|
||||||
|
|
||||||
// group collection data...
|
// group collection data...
|
||||||
//
|
//
|
||||||
@ -1764,10 +1711,7 @@ module.Collection = core.ImageGridFeatures.Feature({
|
|||||||
|
|
||||||
// other stuff -> collection data...
|
// other stuff -> collection data...
|
||||||
} else {
|
} else {
|
||||||
data[key] = json[k]
|
data[key] = json[k] } } })
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// XXX prepare collection data for loading...
|
// XXX prepare collection data for loading...
|
||||||
Object.keys(collection_data)
|
Object.keys(collection_data)
|
||||||
@ -1959,17 +1903,13 @@ module.CollectionTags = core.ImageGridFeatures.Feature({
|
|||||||
|
|
||||||
;(this.crop_stack || [])
|
;(this.crop_stack || [])
|
||||||
.forEach(function(d){ d.tags = tags })
|
.forEach(function(d){ d.tags = tags })
|
||||||
this.data.tags = tags
|
this.data.tags = tags } }],
|
||||||
}
|
|
||||||
}],
|
|
||||||
// remove tags from unloaded collections...
|
// remove tags from unloaded collections...
|
||||||
['collectionUnloaded',
|
['collectionUnloaded',
|
||||||
function(_, title){
|
function(_, title){
|
||||||
if(title in this.collections
|
if(title in this.collections
|
||||||
&& 'data' in this.collections[title]){
|
&& 'data' in this.collections[title]){
|
||||||
delete this.collections[title].data.tags
|
delete this.collections[title].data.tags } }],
|
||||||
}
|
|
||||||
}],
|
|
||||||
// remove tags when saving...
|
// remove tags when saving...
|
||||||
['saveCollection.pre',
|
['saveCollection.pre',
|
||||||
function(title, mode, force){
|
function(title, mode, force){
|
||||||
@ -1979,8 +1919,7 @@ module.CollectionTags = core.ImageGridFeatures.Feature({
|
|||||||
|
|
||||||
// do not do anything for main collection unless force is true...
|
// do not do anything for main collection unless force is true...
|
||||||
if(title == MAIN_COLLECTION_TITLE && !force){
|
if(title == MAIN_COLLECTION_TITLE && !force){
|
||||||
return
|
return }
|
||||||
}
|
|
||||||
|
|
||||||
// we need this to prevent copy of tags on first save...
|
// we need this to prevent copy of tags on first save...
|
||||||
var new_set = !(title in (this.collections || {}))
|
var new_set = !(title in (this.collections || {}))
|
||||||
@ -2006,8 +1945,7 @@ module.CollectionTags = core.ImageGridFeatures.Feature({
|
|||||||
})
|
})
|
||||||
|
|
||||||
// delete the .data.tags of the collections...
|
// delete the .data.tags of the collections...
|
||||||
delete (this.collections[title].data || {}).__tags || {}
|
delete (this.collections[title].data || {}).__tags || {} }
|
||||||
}
|
|
||||||
}],
|
}],
|
||||||
// prevent .uncollect(..) from removing global tags...
|
// prevent .uncollect(..) from removing global tags...
|
||||||
// XXX this seems a bit hacky (???)
|
// XXX this seems a bit hacky (???)
|
||||||
@ -2023,9 +1961,7 @@ module.CollectionTags = core.ImageGridFeatures.Feature({
|
|||||||
|
|
||||||
return function(){
|
return function(){
|
||||||
// update local tags...
|
// update local tags...
|
||||||
tags.untag(local_tag_names, gids)
|
tags.untag(local_tag_names, gids) } }],
|
||||||
}
|
|
||||||
}],
|
|
||||||
// save .local_tags to json...
|
// save .local_tags to json...
|
||||||
// NOTE: we do not need to explicitly load anything as .load()
|
// NOTE: we do not need to explicitly load anything as .load()
|
||||||
// will load everything we need...
|
// will load everything we need...
|
||||||
@ -2052,8 +1988,7 @@ module.CollectionTags = core.ImageGridFeatures.Feature({
|
|||||||
.forEach(function(tag){ rtags[tag] = tags.tags[tag] })
|
.forEach(function(tag){ rtags[tag] = tags.tags[tag] })
|
||||||
// overwrite the local tags for the base...
|
// overwrite the local tags for the base...
|
||||||
Object.keys(ltags)
|
Object.keys(ltags)
|
||||||
.forEach(function(tag){ rtags[tag] = ltags[tag] })
|
.forEach(function(tag){ rtags[tag] = ltags[tag] }) }
|
||||||
}
|
|
||||||
|
|
||||||
// clear tags for all collections...
|
// clear tags for all collections...
|
||||||
rc
|
rc
|
||||||
@ -2061,8 +1996,7 @@ module.CollectionTags = core.ImageGridFeatures.Feature({
|
|||||||
// XXX skip unloaded collections...
|
// XXX skip unloaded collections...
|
||||||
.filter(function(title){ return !!rc[title].data })
|
.filter(function(title){ return !!rc[title].data })
|
||||||
.forEach(function(title){
|
.forEach(function(title){
|
||||||
rc[title].data.tags.tags = c[title].local_tags })
|
rc[title].data.tags.tags = c[title].local_tags }) }],
|
||||||
}],
|
|
||||||
// load collection local tags from .data.tags to .local_tags...
|
// load collection local tags from .data.tags to .local_tags...
|
||||||
// ...this is needed if the collections are fully loaded as part
|
// ...this is needed if the collections are fully loaded as part
|
||||||
// of the index...
|
// of the index...
|
||||||
@ -2081,17 +2015,14 @@ module.CollectionTags = core.ImageGridFeatures.Feature({
|
|||||||
var c = that.collections[title]
|
var c = that.collections[title]
|
||||||
|
|
||||||
if(!c || !c.data){
|
if(!c || !c.data){
|
||||||
return
|
return }
|
||||||
}
|
|
||||||
|
|
||||||
var t = (c.data.tags || {}).tags || {}
|
var t = (c.data.tags || {}).tags || {}
|
||||||
var lt = c.local_tags = c.local_tags || {}
|
var lt = c.local_tags = c.local_tags || {}
|
||||||
|
|
||||||
;(that.config['collection-local-tags'] || [])
|
;(that.config['collection-local-tags'] || [])
|
||||||
.forEach(function(tag){
|
.forEach(function(tag){
|
||||||
lt[tag] = new Set(lt[tag] || t[tag] || []) })
|
lt[tag] = new Set(lt[tag] || t[tag] || []) }) }) }],
|
||||||
})
|
|
||||||
}],
|
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -2169,8 +2100,7 @@ var AutoCollectionsActions = actions.Actions({
|
|||||||
this.saveCollection(title, 'empty')
|
this.saveCollection(title, 'empty')
|
||||||
|
|
||||||
this.collections[title].level_query = query
|
this.collections[title].level_query = query
|
||||||
this.collections[title].source = source
|
this.collections[title].source = source }],
|
||||||
}],
|
|
||||||
|
|
||||||
// XXX do we need real tag queries???
|
// XXX do we need real tag queries???
|
||||||
collectionAutoTagsLoader: ['- Collections/',
|
collectionAutoTagsLoader: ['- Collections/',
|
||||||
@ -2221,13 +2151,9 @@ var AutoCollectionsActions = actions.Actions({
|
|||||||
tags = tags instanceof Array ? tags : [tags]
|
tags = tags instanceof Array ? tags : [tags]
|
||||||
|
|
||||||
if(tags.length == 0){
|
if(tags.length == 0){
|
||||||
return
|
return }
|
||||||
}
|
|
||||||
|
|
||||||
this.saveCollection(title, 'empty')
|
this.saveCollection(title, 'empty')
|
||||||
|
this.collections[title].tag_query = tags }],
|
||||||
this.collections[title].tag_query = tags
|
|
||||||
}],
|
|
||||||
})
|
})
|
||||||
|
|
||||||
var AutoCollections =
|
var AutoCollections =
|
||||||
@ -2263,8 +2189,7 @@ module.AutoCollections = core.ImageGridFeatures.Feature({
|
|||||||
var r = rc[title]
|
var r = rc[title]
|
||||||
|
|
||||||
if(!cur){
|
if(!cur){
|
||||||
return
|
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){
|
||||||
@ -2273,11 +2198,7 @@ module.AutoCollections = core.ImageGridFeatures.Feature({
|
|||||||
} else if('level_query' in cur){
|
} else if('level_query' in cur){
|
||||||
r.level_query = cur.level_query
|
r.level_query = cur.level_query
|
||||||
if(cur.source){
|
if(cur.source){
|
||||||
r.source = cur.source
|
r.source = cur.source } } }) }],
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}],
|
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -2540,9 +2461,8 @@ var UICollectionActions = actions.Actions({
|
|||||||
|
|
||||||
// rename was successful...
|
// rename was successful...
|
||||||
if(to in that.collections){
|
if(to in that.collections){
|
||||||
collections[collections.indexOf(from)] = to } },
|
collections[collections.indexOf(from)] = to } }, }) },
|
||||||
})
|
{
|
||||||
}, {
|
|
||||||
cls: 'collection-list',
|
cls: 'collection-list',
|
||||||
// focus current collection...
|
// focus current collection...
|
||||||
selected: (last_used
|
selected: (last_used
|
||||||
@ -2580,8 +2500,7 @@ var UICollectionActions = actions.Actions({
|
|||||||
.on('update', function(){
|
.on('update', function(){
|
||||||
dialog.filter(JSON.stringify((that.collection || MAIN_COLLECTION_TITLE)
|
dialog.filter(JSON.stringify((that.collection || MAIN_COLLECTION_TITLE)
|
||||||
.replace(/\$/g, '')))
|
.replace(/\$/g, '')))
|
||||||
.addClass('highlighted')
|
.addClass('highlighted') })
|
||||||
})
|
|
||||||
|
|
||||||
all = all || that.collection_order || []
|
all = all || that.collection_order || []
|
||||||
if(defaults){
|
if(defaults){
|
||||||
@ -2606,9 +2525,7 @@ var UICollectionActions = actions.Actions({
|
|||||||
// too often...
|
// too often...
|
||||||
clearTimeout(t)
|
clearTimeout(t)
|
||||||
t = setTimeout(function(){
|
t = setTimeout(function(){
|
||||||
dialog.update()
|
dialog.update() }, 100) })
|
||||||
}, 100)
|
|
||||||
})
|
|
||||||
return c })
|
return c })
|
||||||
|
|
||||||
// containing collections...
|
// containing collections...
|
||||||
@ -2634,23 +2551,16 @@ var UICollectionActions = actions.Actions({
|
|||||||
to_remove: to_remove,
|
to_remove: to_remove,
|
||||||
itemopen: function(_, title){
|
itemopen: function(_, title){
|
||||||
var i = to_remove.indexOf(title)
|
var i = to_remove.indexOf(title)
|
||||||
|
|
||||||
i >= 0 ?
|
i >= 0 ?
|
||||||
to_remove.splice(i, 1)
|
to_remove.splice(i, 1)
|
||||||
: to_remove.push(title)
|
: to_remove.push(title)
|
||||||
|
dialog.update() },
|
||||||
dialog.update()
|
|
||||||
},
|
|
||||||
itemedit: function(_, from, to){
|
itemedit: function(_, from, to){
|
||||||
that.renameCollection(from, to)
|
that.renameCollection(from, to)
|
||||||
|
|
||||||
all[all.indexOf(from)] = to
|
all[all.indexOf(from)] = to
|
||||||
|
that.collection_order = all },
|
||||||
that.collection_order = all
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
: make.Empty('No collections...')
|
: make.Empty('No collections...') })
|
||||||
})
|
|
||||||
.close(function(){
|
.close(function(){
|
||||||
that.collection_order = all
|
that.collection_order = all
|
||||||
|
|
||||||
@ -2659,9 +2569,7 @@ var UICollectionActions = actions.Actions({
|
|||||||
&& to_remove.indexOf(title.replace(/\$/g, '')) < 0
|
&& to_remove.indexOf(title.replace(/\$/g, '')) < 0
|
||||||
&& that.collect(gid, title) })
|
&& that.collect(gid, title) })
|
||||||
to_remove.forEach(function(title){
|
to_remove.forEach(function(title){
|
||||||
that.uncollect(gid, title) })
|
that.uncollect(gid, title) }) }) })],
|
||||||
})
|
|
||||||
})],
|
|
||||||
|
|
||||||
|
|
||||||
// Collection actions with collection selection...
|
// Collection actions with collection selection...
|
||||||
@ -2717,9 +2625,7 @@ var UICollectionActions = actions.Actions({
|
|||||||
this.ensureCollection(title)
|
this.ensureCollection(title)
|
||||||
.then(function(collection){
|
.then(function(collection){
|
||||||
var images = collection.data.getImages('all')
|
var images = collection.data.getImages('all')
|
||||||
|
that.crop(images, false) }) },
|
||||||
that.crop(images, false)
|
|
||||||
}) },
|
|
||||||
null,
|
null,
|
||||||
{ last_used: false })],
|
{ last_used: false })],
|
||||||
cropOutImagesInCollection: ['Collections|Crop/Remove collection images from crop...',
|
cropOutImagesInCollection: ['Collections|Crop/Remove collection images from crop...',
|
||||||
@ -2731,8 +2637,7 @@ var UICollectionActions = actions.Actions({
|
|||||||
var to_remove = collection.data.getImages('all')
|
var to_remove = collection.data.getImages('all')
|
||||||
var images = that.data.getImages('loaded')
|
var images = that.data.getImages('loaded')
|
||||||
.filter(function(gid){ return to_remove.indexOf(gid) < 0 })
|
.filter(function(gid){ return to_remove.indexOf(gid) < 0 })
|
||||||
that.crop(images, false)
|
that.crop(images, false) }) },
|
||||||
}) },
|
|
||||||
null,
|
null,
|
||||||
{ last_used: false })],
|
{ last_used: false })],
|
||||||
|
|
||||||
@ -2865,23 +2770,19 @@ module.UICollection = core.ImageGridFeatures.Feature({
|
|||||||
],
|
],
|
||||||
function(_, gids, collection){
|
function(_, gids, collection){
|
||||||
(collection == null || this.collection == collection)
|
(collection == null || this.collection == collection)
|
||||||
&& this.reload(true)
|
&& this.reload(true) }],
|
||||||
}],
|
|
||||||
|
|
||||||
// maintain crop viewer state when loading/unloading collections...
|
// maintain crop viewer state when loading/unloading collections...
|
||||||
['load clear reload collectionLoading collectionUnloaded',
|
['load clear reload collectionLoading collectionUnloaded',
|
||||||
function(){
|
function(){
|
||||||
if(!this.dom){
|
if(!this.dom){
|
||||||
return
|
return }
|
||||||
}
|
|
||||||
this.dom[this.collection ?
|
this.dom[this.collection ?
|
||||||
'addClass'
|
'addClass'
|
||||||
: 'removeClass']('collection-mode')
|
: 'removeClass']('collection-mode')
|
||||||
|
|
||||||
this.dom[this.cropped ?
|
this.dom[this.cropped ?
|
||||||
'addClass'
|
'addClass'
|
||||||
: 'removeClass']('crop-mode')
|
: 'removeClass']('crop-mode') }],
|
||||||
}],
|
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -2917,7 +2818,9 @@ var CollectionMarksActions = actions.Actions({
|
|||||||
return this.collect(this.marked, collection) }],
|
return this.collect(this.marked, collection) }],
|
||||||
uncollectMarked: ['Collections|Mark/Remove marked from collection',
|
uncollectMarked: ['Collections|Mark/Remove marked from collection',
|
||||||
{mode: function(){
|
{mode: function(){
|
||||||
return (!this.collection || this.marked.length == 0) && 'disabled' }},
|
return (!this.collection
|
||||||
|
|| this.marked.length == 0)
|
||||||
|
&& 'disabled' }},
|
||||||
function(collection){
|
function(collection){
|
||||||
return this.uncollect(this.marked, collection) }],
|
return this.uncollect(this.marked, collection) }],
|
||||||
|
|
||||||
@ -2964,7 +2867,8 @@ var UICollectionMarksActions = actions.Actions({
|
|||||||
that.toggleMark(images, 'on') }) })],
|
that.toggleMark(images, 'on') }) })],
|
||||||
addMarkedToCollection: ['Collections|Mark/Add marked to $collection...',
|
addMarkedToCollection: ['Collections|Mark/Add marked to $collection...',
|
||||||
{mode: function(){
|
{mode: function(){
|
||||||
return this.marked.length == 0 && 'disabled' }},
|
return this.marked.length == 0
|
||||||
|
&& 'disabled' }},
|
||||||
mixedModeCollectionAction(function(title){
|
mixedModeCollectionAction(function(title){
|
||||||
this.collectMarked(title) })],
|
this.collectMarked(title) })],
|
||||||
})
|
})
|
||||||
@ -3015,8 +2919,7 @@ var FileSystemCollectionActions = actions.Actions({
|
|||||||
|
|
||||||
// if data is present, do not reload...
|
// if data is present, do not reload...
|
||||||
if(state.data){
|
if(state.data){
|
||||||
return
|
return }
|
||||||
}
|
|
||||||
|
|
||||||
// XXX get a logger...
|
// XXX get a logger...
|
||||||
logger = logger || this.logger
|
logger = logger || this.logger
|
||||||
@ -3035,10 +2938,7 @@ var FileSystemCollectionActions = actions.Actions({
|
|||||||
.then(function(res){
|
.then(function(res){
|
||||||
// load the collection data...
|
// load the collection data...
|
||||||
that.collections[title].data =
|
that.collections[title].data =
|
||||||
that.prepareIndexForLoad(res[path]).data
|
that.prepareIndexForLoad(res[path]).data }) })) }],
|
||||||
})
|
|
||||||
}))
|
|
||||||
}],
|
|
||||||
|
|
||||||
// XXX revise...
|
// XXX revise...
|
||||||
// XXX this should be generic... (???)
|
// XXX this should be generic... (???)
|
||||||
@ -3050,8 +2950,7 @@ var FileSystemCollectionActions = actions.Actions({
|
|||||||
var that = this
|
var that = this
|
||||||
|
|
||||||
if(this.changes === true || this.changes === undefined){
|
if(this.changes === true || this.changes === undefined){
|
||||||
return
|
return }
|
||||||
}
|
|
||||||
|
|
||||||
// XXX get a logger...
|
// XXX get a logger...
|
||||||
logger = logger || this.logger
|
logger = logger || this.logger
|
||||||
@ -3073,10 +2972,7 @@ var FileSystemCollectionActions = actions.Actions({
|
|||||||
logger && logger.emit('title', title)
|
logger && logger.emit('title', title)
|
||||||
|
|
||||||
c.count = c.data.length
|
c.count = c.data.length
|
||||||
delete c.data
|
delete c.data } }) }],
|
||||||
}
|
|
||||||
})
|
|
||||||
}],
|
|
||||||
|
|
||||||
importCollectionsFromPath: ['- Collections|File/Import collections from path',
|
importCollectionsFromPath: ['- Collections|File/Import collections from path',
|
||||||
function(path){
|
function(path){
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user