mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 02:10:08 +00:00
added collection sorting + some tweaks...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
27fd29fa7e
commit
595e3499fe
@ -199,12 +199,24 @@ actions.Actions({
|
|||||||
//
|
//
|
||||||
// XXX do we need to call .syncTags(..) here???
|
// XXX do we need to call .syncTags(..) here???
|
||||||
load: ['- File|Interface/',
|
load: ['- File|Interface/',
|
||||||
|
core.doc`Load state...
|
||||||
|
|
||||||
|
Loading is done in two stages:
|
||||||
|
- A cleanup stage (pre)
|
||||||
|
In most cases nothing is needed on this stage because
|
||||||
|
the base .load(..) will call .clear()
|
||||||
|
- the load stage (post)
|
||||||
|
This is where all the loading should be handled in most
|
||||||
|
situations.
|
||||||
|
`,
|
||||||
{journal: true},
|
{journal: true},
|
||||||
function(d){
|
function(d){
|
||||||
this.clear()
|
this.clear()
|
||||||
|
|
||||||
this.images = images.Images(d.images)
|
return function(){
|
||||||
this.data = data.Data(d.data)
|
this.images = images.Images(d.images)
|
||||||
|
this.data = data.Data(d.data)
|
||||||
|
}
|
||||||
}],
|
}],
|
||||||
// XXX should this clear or load empty???
|
// XXX should this clear or load empty???
|
||||||
clear: ['File/Clear',
|
clear: ['File/Clear',
|
||||||
@ -1402,13 +1414,12 @@ module.CropActions = actions.Actions({
|
|||||||
|
|
||||||
// load the crop stack if present...
|
// load the crop stack if present...
|
||||||
load: [function(data){
|
load: [function(data){
|
||||||
// clear previous crop state...
|
return function(){
|
||||||
delete this.crop_stack
|
if(data.crop_stack){
|
||||||
|
this.crop_stack = data.crop_stack.map(function(j){
|
||||||
if(data.crop_stack){
|
return data.Data(j)
|
||||||
this.crop_stack = data.crop_stack.map(function(j){
|
})
|
||||||
return data.Data(j)
|
}
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}],
|
}],
|
||||||
clear: [function(){
|
clear: [function(){
|
||||||
|
|||||||
@ -68,11 +68,41 @@ var CollectionActions = actions.Actions({
|
|||||||
// }
|
// }
|
||||||
collections: null,
|
collections: null,
|
||||||
|
|
||||||
|
|
||||||
get collection(){
|
get collection(){
|
||||||
return this.location.collection },
|
return this.location.collection },
|
||||||
set collection(value){
|
set collection(value){
|
||||||
this.loadCollection(value) },
|
this.loadCollection(value) },
|
||||||
|
|
||||||
|
get collection_order(){
|
||||||
|
if(this.collections == null){
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
var collections = this.collections
|
||||||
|
var keys = Object.keys(collections)
|
||||||
|
var order = this.__collection_order = this.__collection_order || []
|
||||||
|
|
||||||
|
// add unsorted things to the head of the list...
|
||||||
|
var res = keys
|
||||||
|
.concat(order)
|
||||||
|
.reverse()
|
||||||
|
.unique()
|
||||||
|
.reverse()
|
||||||
|
|
||||||
|
// remove stuff not present...
|
||||||
|
if(res.length > keys.length){
|
||||||
|
res = res.filter(function(e){ return e in collections })
|
||||||
|
}
|
||||||
|
|
||||||
|
this.__collection_order.splice.apply(this.__collection_order,
|
||||||
|
[0, this.__collection_order.length].concat(res))
|
||||||
|
|
||||||
|
return this.__collection_order
|
||||||
|
},
|
||||||
|
set collection_order(value){
|
||||||
|
this.__collection_order = value },
|
||||||
|
|
||||||
// Format:
|
// Format:
|
||||||
// {
|
// {
|
||||||
// // NOTE: this is always the first handler...
|
// // NOTE: this is always the first handler...
|
||||||
@ -250,7 +280,8 @@ var CollectionActions = actions.Actions({
|
|||||||
function(gid){
|
function(gid){
|
||||||
var that = this
|
var that = this
|
||||||
gid = this.data.getImage(gid)
|
gid = this.data.getImage(gid)
|
||||||
return Object.keys(this.collections || {})
|
//return Object.keys(this.collections || {})
|
||||||
|
return this.collection_order
|
||||||
.filter(function(c){
|
.filter(function(c){
|
||||||
return !gid
|
return !gid
|
||||||
|| that.collections[c].data.getImage(gid) })
|
|| that.collections[c].data.getImage(gid) })
|
||||||
@ -381,28 +412,40 @@ var CollectionActions = actions.Actions({
|
|||||||
var that = this
|
var that = this
|
||||||
var collections = {}
|
var collections = {}
|
||||||
var c = json.collections || {}
|
var c = json.collections || {}
|
||||||
|
var order = json.collection_order || Object.keys(c)
|
||||||
|
|
||||||
Object.keys(c).forEach(function(title){
|
Object.keys(c).forEach(function(title){
|
||||||
var data = data.Data
|
var d = data.Data
|
||||||
.fromJSON(c[title].data)
|
.fromJSON(c[title].data)
|
||||||
|
|
||||||
// XXX make this reflect the format automatically...
|
// XXX make this reflect the format automatically...
|
||||||
collections[title] = {
|
collections[title] = {
|
||||||
title: title,
|
title: title,
|
||||||
|
|
||||||
data: data,
|
data: d,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
if(Object.keys(collections).length > 0){
|
return function(){
|
||||||
this.collections = collections
|
if(Object.keys(collections).length > 0){
|
||||||
|
this.collection_order = order
|
||||||
|
this.collections = collections
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}],
|
}],
|
||||||
|
// NOTE: we do not store .collection_order here, because we order
|
||||||
|
// the collections in the object.
|
||||||
|
// ...when saving a partial collection set, for example in
|
||||||
|
// .prepareIndexForWrite(..) it would be necessary to add it
|
||||||
|
// in to maintain the correct order when merging... (XXX)
|
||||||
json: [function(){ return function(res){
|
json: [function(){ return function(res){
|
||||||
var collections = this.collections
|
var collections = this.collections
|
||||||
|
|
||||||
if(collections){
|
if(collections){
|
||||||
|
var order = this.collection_order
|
||||||
|
|
||||||
res.collections = {}
|
res.collections = {}
|
||||||
Object.keys(this.collections).forEach(function(title){
|
order.forEach(function(title){
|
||||||
var data = collections[title].data.dumpJSON()
|
var data = collections[title].data.dumpJSON()
|
||||||
delete data.tags
|
delete data.tags
|
||||||
|
|
||||||
@ -419,6 +462,7 @@ var CollectionActions = actions.Actions({
|
|||||||
this.collection
|
this.collection
|
||||||
&& this.collectionUnloaded('*')
|
&& this.collectionUnloaded('*')
|
||||||
delete this.collections
|
delete this.collections
|
||||||
|
delete this.__collection_order
|
||||||
delete this.location.collection
|
delete this.location.collection
|
||||||
}],
|
}],
|
||||||
})
|
})
|
||||||
@ -493,7 +537,8 @@ var UICollectionActions = actions.Actions({
|
|||||||
.addClass('highlighted')
|
.addClass('highlighted')
|
||||||
})
|
})
|
||||||
|
|
||||||
var collections = Object.keys(that.collections || {})
|
//var collections = Object.keys(that.collections || {})
|
||||||
|
var collections = that.collection_order = that.collection_order || []
|
||||||
|
|
||||||
make.EditableList(collections,
|
make.EditableList(collections,
|
||||||
{
|
{
|
||||||
@ -513,6 +558,7 @@ var UICollectionActions = actions.Actions({
|
|||||||
check: function(title){
|
check: function(title){
|
||||||
return title.length > 0 },
|
return title.length > 0 },
|
||||||
|
|
||||||
|
// XXX should this be "on close"???
|
||||||
itemadded: function(title){
|
itemadded: function(title){
|
||||||
action ?
|
action ?
|
||||||
that.newCollection(title)
|
that.newCollection(title)
|
||||||
@ -548,7 +594,8 @@ var UICollectionActions = actions.Actions({
|
|||||||
.addClass('highlighted')
|
.addClass('highlighted')
|
||||||
})
|
})
|
||||||
|
|
||||||
all = Object.keys(that.collections || {})
|
//all = Object.keys(that.collections || {})
|
||||||
|
all = that.collection_order = that.collection_order || []
|
||||||
|
|
||||||
collections = collections
|
collections = collections
|
||||||
|| that.inCollections(gid || null)
|
|| that.inCollections(gid || null)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user