mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 10:20:08 +00:00
started work on sort order caching...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
b888d279ea
commit
f5b9687d3f
@ -22,6 +22,7 @@ var browse = require('lib/widget/browse')
|
|||||||
/*********************************************************************/
|
/*********************************************************************/
|
||||||
|
|
||||||
// XXX add sorting on load....
|
// XXX add sorting on load....
|
||||||
|
// XXX keep a cached sort order for each method in .data...
|
||||||
var SortActions =
|
var SortActions =
|
||||||
module.SortActions = actions.Actions({
|
module.SortActions = actions.Actions({
|
||||||
config: {
|
config: {
|
||||||
@ -309,7 +310,7 @@ module.SortActions = actions.Actions({
|
|||||||
function(){
|
function(){
|
||||||
return Object.keys(this.config['sort-methods'])
|
return Object.keys(this.config['sort-methods'])
|
||||||
.concat((this.data
|
.concat((this.data
|
||||||
&& (this.data.manual_order
|
&& ((this.data.sort_cache || {})['Manual']
|
||||||
|| this.data.sort_method == 'Manual')) ?
|
|| this.data.sort_method == 'Manual')) ?
|
||||||
['Manual']
|
['Manual']
|
||||||
: [])},
|
: [])},
|
||||||
@ -317,20 +318,21 @@ module.SortActions = actions.Actions({
|
|||||||
function(mode){
|
function(mode){
|
||||||
return !!this.images
|
return !!this.images
|
||||||
&& (mode != 'none'
|
&& (mode != 'none'
|
||||||
|| (mode == 'Manual' && this.data.manual_order)) },
|
|| (mode == 'Manual' && (this.data.sort_cache || {})['Manual'])) },
|
||||||
// XXX need to refactor the toggler a bit to make the
|
// XXX need to refactor the toggler a bit to make the
|
||||||
// signature simpler... (???)
|
// signature simpler... (???)
|
||||||
function(mode, _, reverse){
|
function(mode, _, reverse){
|
||||||
reverse = reverse == 'reverse' || reverse
|
reverse = reverse == 'reverse' || reverse
|
||||||
|
var cache = this.data.sort_cache = this.data.sort_cache || {}
|
||||||
|
|
||||||
// save manual order...
|
// save manual order...
|
||||||
if(this.data.sort_method == 'Manual'){
|
if(this.data.sort_method == 'Manual'){
|
||||||
this.data.manual_order = this.data.order.slice()
|
cache['Manual'] = this.data.order.slice()
|
||||||
}
|
}
|
||||||
|
|
||||||
// special case: manual order...
|
// special case: manual order...
|
||||||
if(mode == 'Manual'){
|
if(mode == 'Manual'){
|
||||||
this.data.order = this.data.manual_order.slice()
|
this.data.order = cache['Manual'].slice()
|
||||||
this.sortImages('update' + (reverse ? ' reverse' : ''))
|
this.sortImages('update' + (reverse ? ' reverse' : ''))
|
||||||
this.data.sort_method = mode
|
this.data.sort_method = mode
|
||||||
|
|
||||||
@ -341,29 +343,31 @@ module.SortActions = actions.Actions({
|
|||||||
|
|
||||||
// Store/load sort data:
|
// Store/load sort data:
|
||||||
// .data.sort_method - current sort mode (optional)
|
// .data.sort_method - current sort mode (optional)
|
||||||
// .data.manual_order - manual sort order (optional)
|
// .data.sort_cache - manual sort order (optional)
|
||||||
load: [function(data){
|
load: [function(data){
|
||||||
return function(){
|
return function(){
|
||||||
if(data.data && data.data.sort_method){
|
if(data.data && data.data.sort_method){
|
||||||
this.data.sort_method = data.data.sort_method
|
this.data.sort_method = data.data.sort_method
|
||||||
}
|
}
|
||||||
|
|
||||||
if(data.data && data.data.manual_order){
|
if(data.data && data.data.sort_cache){
|
||||||
this.data.manual_order = data.data.manual_order
|
this.data.sort_cache = data.data.sort_cache
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}],
|
}],
|
||||||
|
// XXX should .sort_cache be stored separately???
|
||||||
json: [function(){
|
json: [function(){
|
||||||
return function(res){
|
return function(res){
|
||||||
if(this.data.sort_method){
|
if(this.data.sort_method){
|
||||||
res.data.sort_method = this.data.sort_method
|
res.data.sort_method = this.data.sort_method
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.data.manual_order){
|
if(this.data.sort_cache){
|
||||||
res.data.manual_order = this.data.manual_order
|
res.data.sort_cache = this.data.sort_cache
|
||||||
|
|
||||||
} else if(this.toggleImageSort('?') == 'Manual'){
|
} else if(this.toggleImageSort('?') == 'Manual'){
|
||||||
res.data.manual_order = this.data.order
|
res.data.sort_cache = res.data.sort_cache || {}
|
||||||
|
res.data.sort_cache['Manual'] = this.data.order
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}],
|
}],
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user