new sort now online, still needs testing and revision...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2018-10-22 11:47:10 +03:00
parent d554876f4c
commit 76cbfd80a2

View File

@ -78,7 +78,7 @@ module.SortActions = actions.Actions({
// var st = s.trim() // var st = s.trim()
// st[0].toUpperCase() == st[0] // st[0].toUpperCase() == st[0]
'Date': 'Date':
'metadata.createDate birthtime ctime name-sequence keep-position reverse', 'image-date name-sequence keep-position reverse',
'File date': 'File date':
'birthtime ctime keep-position reverse', 'birthtime ctime keep-position reverse',
'File sequence number (with overflow)': 'File sequence number (with overflow)':
@ -118,12 +118,13 @@ module.SortActions = actions.Actions({
__sort_methods__: { __sort_methods__: {
// aliases... // aliases...
'image-date': 'image-date':
'image-create-date image-modify-date', //'image-create-date image-modify-date',
'image-create-date',
'image-create-date': 'image-create-date':
'metadata.createDate birthtime ctime name-sequence keep-position', 'metadata.createDate birthtime ctime name-sequence keep-position',
// XXX // XXX
'image-modify-date': //'image-modify-date':
'metadata.createDate birthtime ctime name-sequence keep-position', // 'metadata.createDate birthtime ctime name-sequence keep-position',
// XXX make sequence sort methods compatible with repeating numbers, // XXX make sequence sort methods compatible with repeating numbers,
// i.e. for file names like DSC_1234 sorting more than 10K files // i.e. for file names like DSC_1234 sorting more than 10K files
@ -292,56 +293,40 @@ module.SortActions = actions.Actions({
this.data.sort_method = typeof(method) == typeof('str') ? method : method.join(' ') this.data.sort_method = typeof(method) == typeof('str') ? method : method.join(' ')
var splitMethods = function(m){ var splitMethods = function(m){
return m instanceof Array ? m : return (m instanceof Array ?
m
: typeof(m) == typeof('str') ?
m m
.split(/'([^']*)'|"([^"]*)"| +/) .split(/'([^']*)'|"([^"]*)"| +/)
.filter(function(e){ .filter(function(e){
return e && e.trim() != '' && !/['"]/.test(e) }) } return e && e.trim() != '' && !/['"]/.test(e) })
// XXX : [])
.reduce(function(r, e){
return r.concat(e instanceof Array ? e : [e]) }, []) }
var expandMethods = function(m, seen){ var expandMethods = function(m, seen){
seen = seen || new Set() seen = seen || []
if(seen.has(m)){ if(seen.indexOf(m) >= 0){
throw new Error('Sort method loop detected.') throw new Error('Sort method loop detected.')
} else {
seen.add(m)
} }
var methods = that.config['sort-methods'] || []
return (m instanceof Array ? m : splitMethods(m)) return (m instanceof Array ? m : splitMethods(m))
.map(function(m){ .map(function(m){
var a = SortActions.__sort_methods__[m] var a = SortActions.__sort_methods__[m]
|| (that.__sort_methods__ && that.__sort_methods__[m]) || (that.__sort_methods__ && that.__sort_methods__[m])
// expand local aliases... // expand local aliases...
return m in that.config['sort-methods'] ? return m in methods ?
expandMethods(that.config['split-methods'], seen) expandMethods(methods[m], seen.concat([m]))
// expand system aliases... // expand system aliases...
: typeof(a) == typeof('str') ? : typeof(a) == typeof('str') ?
expandMethods(a, seen) expandMethods(a, seen.concat([m]))
: a instanceof Array ? : a instanceof Array ?
a a
: m }) : m })
// merge... // merge...
.reduce(function(r, e){ .reduce(function(r, e){
return e instanceof Array ? r.concat(e) : r.push(e) }, []) } return r.concat(e instanceof Array ? e : [e]) }, []) }
// expand method names... method = expandMethods(method)
// XXX should this be recursive???
method = splitMethods(method)
.map(function(m){
return m in that.config['sort-methods'] ?
splitMethods(that.config['split-methods']) : m })
// expand system aliases...
/*
method = method
.map(function(m){
var a = (SortActions.__sort_methods__[m]
|| (that.__sort_methods__ && that.__sort_methods__[m])
return typeof(a) == typeof('str') ?
splitMethods(a)
: a instanceof Array ?
a
: m })
.reduce(function(r, e){
return e instanceof Array ? r.concat(e) : r.push(e) }, [])
//*/
// get the reverse arity... // get the reverse arity...
var i = method.indexOf('reverse') var i = method.indexOf('reverse')
@ -360,6 +345,7 @@ module.SortActions = actions.Actions({
// build the compare routine... // build the compare routine...
method = method method = method
// remove duplicate methods... // remove duplicate methods...
// XXX should we keep the last occurrence or the first occurrence???
.unique() .unique()
.map(function(m){ .map(function(m){
return (SortActions.__sort_methods__[m] return (SortActions.__sort_methods__[m]