fixed sort via collection...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2020-10-24 14:52:39 +03:00
parent 34395a9145
commit c05970bde5
2 changed files with 79 additions and 57 deletions

View File

@ -2276,31 +2276,28 @@ module.AutoCollections = core.ImageGridFeatures.Feature({
// //
// NOTE: if n > 1 and <n args are given then the given args will get // NOTE: if n > 1 and <n args are given then the given args will get
// passed to func with an appended title... // passed to func with an appended title...
var mixedModeCollectionAction = function(func, n, last_used_collection){ // XXX should we use options object here a-la .browseCollections(..)???
var mixedModeCollectionAction = function(func, n, options){
return widgets.uiDialog(function(){ return widgets.uiDialog(function(){
var args = [...arguments] var args = [...arguments]
// check if minimum number of arguments is reached... // check if minimum number of arguments is reached...
return args.length < (n || 1) ? return args.length < (n || 1) ?
// show the dialog... // show the dialog...
//this.browseCollections(func)
this.browseCollections(function(title){ this.browseCollections(function(title){
return func.call(this, ...args.concat([title])) }, return func.call(this, ...args.concat([title])) }, options)
null,
last_used_collection)
: func.apply(this, args) }) } : func.apply(this, args) }) }
// Like mixedModeCollectionAction(..) but will do nothing if enough args // Like mixedModeCollectionAction(..) but will do nothing if enough args
// are given... // are given...
var collectionGetterWrapper = function(func, n, last_used_collection){ var collectionGetterWrapper = function(func, n, options){
return widgets.uiDialog(function(){ return widgets.uiDialog(function(){
var args = [...arguments] var args = [...arguments]
// check if minimum number of arguments is reached... // check if minimum number of arguments is reached...
return args.length < (n || 1) return args.length < (n || 1)
// show the dialog... // show the dialog...
&& this.browseCollections(function(title){ && this.browseCollections(function(title){
return func.call(this, ...args.concat([title])) }, return func.call(this, ...args.concat([title])) },
null, options) }) }
last_used_collection) }) }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -2326,28 +2323,42 @@ var UICollectionActions = actions.Actions({
browseCollections: ['Collections/$Collections...', browseCollections: ['Collections/$Collections...',
core.doc`Collection list... core.doc`Collection list...
.browseCollections(action, new_message, last_used_collection) .browseCollections(action, options)
-> dialog -> dialog
options format:
{
new_message: null | false | <str>,
last_used: <bool> | <title>,
show_main: null | <bool> | <func>,
}
All arguments are optional. All arguments are optional.
If action is given last_used_collection defaults to true. If action is given options.last_used defaults to true.
If last_used_collection is true then .config['collection-last-used'] If options.last_used is true then .config['collection-last-used']
is used to select the last used collection and set when selecting is used to select the last used collection and set when selecting
an item. an item.
It last_used_collection is a string, then .config[last_used_collection] It options.last_used is a string, then .config[options.last_used]
will be used to store the last used collection title. will be used to store the last used collection title.
NOTE: collections are added live and not on dialog close... NOTE: collections are added live and not on dialog close...
`, `,
widgets.makeUIDialog(function(action, new_message, last_used_collection){ //widgets.makeUIDialog(function(action, new_message, last_used_collection){
widgets.makeUIDialog(function(action, options={}){
var that = this var that = this
last_used_collection = last_used_collection == null ?
var {new_message, last_used, show_main} = options
last_used = options.last_used == null ?
(action && 'collection-last-used') (action && 'collection-last-used')
: last_used_collection === true ? : options.last_used === true ?
'collection-last-used' 'collection-last-used'
: last_used_collection : options.last_used
var to_remove = [] var to_remove = []
var collections = that.collection_order = var collections = that.collection_order =
@ -2442,12 +2453,13 @@ var UICollectionActions = actions.Actions({
.unique())) .unique()))
// main collection... // main collection...
// XXX add option to force show this... var main = typeof(show_main) == 'function' ?
!action show_main.call(that)
: show_main
;(main === true
|| (main == null && !action))
&& collections.indexOf(MAIN_COLLECTION_TITLE) < 0 && collections.indexOf(MAIN_COLLECTION_TITLE) < 0
&& make([ && make([MAIN_COLLECTION_TITLE],
MAIN_COLLECTION_TITLE,
],
{ {
events: { events: {
update: function(_, title){ update: function(_, title){
@ -2500,7 +2512,8 @@ var UICollectionActions = actions.Actions({
that.newCollection(title) that.newCollection(title)
: that.saveCollection(title) }, : that.saveCollection(title) },
disabled: action ? disabled: (main === false
|| (main == null && action)) ?
[MAIN_COLLECTION_TITLE] [MAIN_COLLECTION_TITLE]
: false, : false,
@ -2517,17 +2530,17 @@ var UICollectionActions = actions.Actions({
}, { }, {
cls: 'collection-list', cls: 'collection-list',
// focus current collection... // focus current collection...
selected: (last_used_collection selected: (last_used
&& that.config[last_used_collection]) ? && that.config[last_used]) ?
that.config[last_used_collection] that.config[last_used]
: JSON.stringify( : JSON.stringify(
(that.collection || MAIN_COLLECTION_TITLE) (that.collection || MAIN_COLLECTION_TITLE)
// XXX not sure it is good that we have to do this... // XXX not sure it is good that we have to do this...
.replace(/\$/g, '')), .replace(/\$/g, '')),
}) })
.open(function(_, title){ .open(function(_, title){
last_used_collection last_used
&& (that.config[last_used_collection] = title) }) && (that.config[last_used] = title) })
.close(function(){ .close(function(){
that.collection_order = collections that.collection_order = collections
to_remove to_remove
@ -2669,8 +2682,7 @@ var UICollectionActions = actions.Actions({
collectionGetterWrapper(function(gids, title){ collectionGetterWrapper(function(gids, title){
if(title == null){ if(title == null){
title = gids title = gids
gids = null gids = null }
}
this.collect(gids || 'current', title) }, 2)], this.collect(gids || 'current', title) }, 2)],
collectRibbon: ['Collections|Ribbon/Add $ribbon to collection...', collectRibbon: ['Collections|Ribbon/Add $ribbon to collection...',
'collect: "ribbon"'], 'collect: "ribbon"'],
@ -2686,25 +2698,28 @@ var UICollectionActions = actions.Actions({
|| Object.keys(this.collections).length == 0) || Object.keys(this.collections).length == 0)
&& 'disabled' }}, && 'disabled' }},
mixedModeCollectionAction(function(title){ mixedModeCollectionAction(function(title){
var that = this var that = this
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, false)], }) },
null,
{ last_used: false })],
cropOutImagesInCollection: ['Collections|Crop/Remove collection images from crop...', cropOutImagesInCollection: ['Collections|Crop/Remove collection images from crop...',
{mode: 'cropImagesInCollection'}, {mode: 'cropImagesInCollection'},
mixedModeCollectionAction(function(title){ mixedModeCollectionAction(function(title){
var that = this var that = this
this.ensureCollection(title) this.ensureCollection(title)
.then(function(collection){ .then(function(collection){
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, false)], null,
{ last_used: false })],
// XXX should this be in Collections/ ??? // XXX should this be in Collections/ ???
editDefaultCollections: ['Interface|Collections/Edit default collections...', editDefaultCollections: ['Interface|Collections/Edit default collections...',
@ -2747,18 +2762,25 @@ var UICollectionActions = actions.Actions({
}], }],
//*/ //*/
// XXX need to show MAIN_COLLECTION_TITLE... // XXX need to force show MAIN_COLLECTION_TITLE...
// -> mixedModeCollectionAction(..)
// -> .browseCollections(..)
// XXX might be a good idea to add a reverse of this, i.e. .sortCollectionAsThis(..)
// XXX do we need to have an option/shorthand to .sortAs(..) and .inplaceSortAs(..) ??? // XXX do we need to have an option/shorthand to .sortAs(..) and .inplaceSortAs(..) ???
sortAsCollection: ['Collections/Sort as collection...', sortAsCollection: ['Collections/Sort as collection...',
{sortMethod: true, {sortMethod: true,
mode: function(){ mode: function(){
return this.collections_length > 0 || 'disabled' }, }, return this.collections_length > 0 || 'disabled' }, },
mixedModeCollectionAction(function(title){ mixedModeCollectionAction(
var that = this function(title){
this.ensureCollection(title) var that = this
.then(function(collection){ this.ensureCollection(title)
that.data.order.inplaceSortAs(collection.data.order) .then(function(collection){
that.sortImages('update') }) })], that.data.order.inplaceSortAs(collection.data.order)
that.sortImages('update') }) },
null,
{ show_main: function(){
return !!this.collection } })],
}) })
var UICollection = var UICollection =
@ -2888,14 +2910,12 @@ var UICollectionMarksActions = 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.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){ this.collectMarked(title) })], mixedModeCollectionAction(function(title){
this.collectMarked(title) })],
}) })
var UICollectionMarks = var UICollectionMarks =

View File

@ -896,6 +896,8 @@ var SortUIActions = actions.Actions({
lister.parent.close() }) }) lister.parent.close() }) })
// action sort methods... // action sort methods...
if(sort_actions.size > 0){ if(sort_actions.size > 0){
// XXX do we need this??
//make('---', {style: { opacity: 0.1, }})
;[...sort_actions.entries()] ;[...sort_actions.entries()]
.forEach(function([n, a]){ .forEach(function([n, a]){
make(n, { make(n, {