From c05970bde5b3110128ae197221e855268bd689d8 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sat, 24 Oct 2020 14:52:39 +0300 Subject: [PATCH] fixed sort via collection... Signed-off-by: Alex A. Naanou --- Viewer/features/collections.js | 134 +++++++++++++++++++-------------- Viewer/features/sort.js | 2 + 2 files changed, 79 insertions(+), 57 deletions(-) diff --git a/Viewer/features/collections.js b/Viewer/features/collections.js index a7af2b72..0ed7fd32 100755 --- a/Viewer/features/collections.js +++ b/Viewer/features/collections.js @@ -2276,31 +2276,28 @@ module.AutoCollections = core.ImageGridFeatures.Feature({ // // NOTE: if n > 1 and dialog + + options format: + { + new_message: null | false | , + + last_used: | , + + show_main: null | <bool> | <func>, + } + + 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 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. 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 - 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') - : last_used_collection === true ? + : options.last_used === true ? 'collection-last-used' - : last_used_collection + : options.last_used var to_remove = [] var collections = that.collection_order = @@ -2442,12 +2453,13 @@ var UICollectionActions = actions.Actions({ .unique())) // main collection... - // XXX add option to force show this... - !action + var main = typeof(show_main) == 'function' ? + show_main.call(that) + : show_main + ;(main === true + || (main == null && !action)) && collections.indexOf(MAIN_COLLECTION_TITLE) < 0 - && make([ - MAIN_COLLECTION_TITLE, - ], + && make([MAIN_COLLECTION_TITLE], { events: { update: function(_, title){ @@ -2500,7 +2512,8 @@ var UICollectionActions = actions.Actions({ that.newCollection(title) : that.saveCollection(title) }, - disabled: action ? + disabled: (main === false + || (main == null && action)) ? [MAIN_COLLECTION_TITLE] : false, @@ -2517,17 +2530,17 @@ var UICollectionActions = actions.Actions({ }, { cls: 'collection-list', // focus current collection... - selected: (last_used_collection - && that.config[last_used_collection]) ? - that.config[last_used_collection] + selected: (last_used + && that.config[last_used]) ? + that.config[last_used] : JSON.stringify( (that.collection || MAIN_COLLECTION_TITLE) // XXX not sure it is good that we have to do this... .replace(/\$/g, '')), }) .open(function(_, title){ - last_used_collection - && (that.config[last_used_collection] = title) }) + last_used + && (that.config[last_used] = title) }) .close(function(){ that.collection_order = collections to_remove @@ -2669,8 +2682,7 @@ var UICollectionActions = actions.Actions({ collectionGetterWrapper(function(gids, title){ if(title == null){ title = gids - gids = null - } + gids = null } this.collect(gids || 'current', title) }, 2)], collectRibbon: ['Collections|Ribbon/Add $ribbon to collection...', 'collect: "ribbon"'], @@ -2686,25 +2698,28 @@ var UICollectionActions = actions.Actions({ || Object.keys(this.collections).length == 0) && 'disabled' }}, mixedModeCollectionAction(function(title){ - var that = this - this.ensureCollection(title) - .then(function(collection){ - var images = collection.data.getImages('all') + var that = this + this.ensureCollection(title) + .then(function(collection){ + var images = collection.data.getImages('all') - that.crop(images, false) - }) }, null, false)], + that.crop(images, false) + }) }, + null, + { last_used: false })], cropOutImagesInCollection: ['Collections|Crop/Remove collection images from crop...', {mode: 'cropImagesInCollection'}, mixedModeCollectionAction(function(title){ - var that = this - this.ensureCollection(title) - .then(function(collection){ - var to_remove = collection.data.getImages('all') - var images = that.data.getImages('loaded') - .filter(function(gid){ return to_remove.indexOf(gid) < 0 }) - that.crop(images, false) - }) - }, null, false)], + var that = this + this.ensureCollection(title) + .then(function(collection){ + var to_remove = collection.data.getImages('all') + var images = that.data.getImages('loaded') + .filter(function(gid){ return to_remove.indexOf(gid) < 0 }) + that.crop(images, false) + }) }, + null, + { last_used: false })], // XXX should this be in 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(..) ??? sortAsCollection: ['Collections/Sort as collection...', {sortMethod: true, mode: function(){ return this.collections_length > 0 || 'disabled' }, }, - mixedModeCollectionAction(function(title){ - var that = this - this.ensureCollection(title) - .then(function(collection){ - that.data.order.inplaceSortAs(collection.data.order) - that.sortImages('update') }) })], + mixedModeCollectionAction( + function(title){ + var that = this + this.ensureCollection(title) + .then(function(collection){ + that.data.order.inplaceSortAs(collection.data.order) + that.sortImages('update') }) }, + null, + { show_main: function(){ + return !!this.collection } })], }) var UICollection = @@ -2888,14 +2910,12 @@ var UICollectionMarksActions = actions.Actions({ this.ensureCollection(title) .then(function(collection){ var images = collection.data.getImages('all') - - that.toggleMark(images, 'on') - }) - })], + that.toggleMark(images, 'on') }) })], addMarkedToCollection: ['Collections|Mark/Add marked to $collection...', {mode: function(){ return this.marked.length == 0 && 'disabled' }}, - mixedModeCollectionAction(function(title){ this.collectMarked(title) })], + mixedModeCollectionAction(function(title){ + this.collectMarked(title) })], }) var UICollectionMarks = diff --git a/Viewer/features/sort.js b/Viewer/features/sort.js index d0fcd7c6..593ddb54 100755 --- a/Viewer/features/sort.js +++ b/Viewer/features/sort.js @@ -896,6 +896,8 @@ var SortUIActions = actions.Actions({ lister.parent.close() }) }) // action sort methods... if(sort_actions.size > 0){ + // XXX do we need this?? + //make('---', {style: { opacity: 0.1, }}) ;[...sort_actions.entries()] .forEach(function([n, a]){ make(n, {