now exporting image size limiting works...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2019-04-15 15:44:28 +03:00
parent 1191d49b21
commit dd9759035f
2 changed files with 63 additions and 22 deletions

View File

@ -1603,6 +1603,7 @@ var FileSystemWriterActions = actions.Actions({
'export-preview-size': 1000, 'export-preview-size': 1000,
'export-preview-size-limits': [ 'export-preview-size-limits': [
'no limit',
'900', '900',
'1000', '1000',
'1280', '1280',
@ -1707,9 +1708,12 @@ var FileSystemWriterActions = actions.Actions({
// Export current state as a full loadable index // Export current state as a full loadable index
// //
//
// NOTE: if max_size is given the base image in the target path will
// be replaced with the largest preview under max_size.
//
// XXX resolve env variables in path... // XXX resolve env variables in path...
// XXX what should happen if no path is given??? // XXX what should happen if no path is given???
// XXX add preview selection...
// XXX handle .image.path and other stack files... // XXX handle .image.path and other stack files...
// XXX local collections??? // XXX local collections???
exportIndex: ['- File/Export/Export index', exportIndex: ['- File/Export/Export index',
@ -1723,6 +1727,7 @@ var FileSystemWriterActions = actions.Actions({
include_orig = include_orig || true include_orig = include_orig || true
// XXX is this correct??? // XXX is this correct???
// ...get this from config...
path = path || './exported' path = path || './exported'
path = util.normalizePath(path) path = util.normalizePath(path)
@ -1830,29 +1835,45 @@ var FileSystemWriterActions = actions.Actions({
if(previews || img.path){ if(previews || img.path){
var seen = new Set() var seen = new Set()
var max
var replace_orig = false
Object.keys(previews || {}) Object.keys(previews || {})
// limit preview size... // limit preview size...
// NOTE: also remove the preview resolution if // NOTE: also remove the preview resolution if
// it's smaller... // it's smaller...
// XXX if we are limiting preview size then we
// need to also update .path to the correct
// preview size (use a preview as source)
.filter(function(res){ .filter(function(res){
// no size limit or match... // no size limit or match...
if(!max_size || parseInt(res) <= max_size){ if(!max_size || parseInt(res) <= max_size){
// get the biggest remaining preview...
max = max == null || parseInt(res) > parseInt(max) ?
res
: max
return true return true
}
// skip and remove... // skip and remove...
} else { replace_orig = true
delete previews[res]
return false
}
}) })
// get paths... // get paths...
.map(function(res){ return decodeURI(previews[res]) }) .map(function(res){
// XXX might be a good idea to include the max return res != max ?
// preview if hires is too large... decodeURI(previews[res])
.concat(include_orig && img.path ? [[from_path, img.path]] : []) // NOTE: we will skip including the preview
// we are using as the primary image to
// save space...
: null })
// add primary image...
.concat(include_orig && img.path ?
[[
(replace_orig && max != null) ?
// replace the base image with the
// largest available preview...
previews[max]
: from_path,
img.path
]]
: null)
// build the from/to paths...
.forEach(function(preview_path){ .forEach(function(preview_path){
var to var to
if(preview_path == null){ if(preview_path == null){
@ -2402,7 +2423,8 @@ var FileSystemWriterUIActions = actions.Actions({
function(){ function(){
return actions.config['export-preview-size-limit'] || 'no limit' }], return actions.config['export-preview-size-limit'] || 'no limit' }],
{ buttons: [ { buttons: [
['&times;', function(p){ //['&times;', function(p){
['clear', function(p){
actions.config['export-preview-size-limit'] = 'no limit' actions.config['export-preview-size-limit'] = 'no limit'
parent.update() parent.update()
}], }],
@ -2414,7 +2436,18 @@ var FileSystemWriterUIActions = actions.Actions({
'export-preview-size-limit', 'export-preview-size-limit',
{ {
length_limit: 10, length_limit: 10,
sort: function(a, b){ return parseInt(a) - parseInt(b) }, // sort ascending + keep 'no limit' at top...
sort: function(a, b){
return a == 'no limit' ?
-1
: b == 'no limit' ?
1
: parseInt(a) - parseInt(b) },
check: function(e){
return e == 'no limit'
|| !!parseInt(e) },
remove: function(e){
return e != 'no limit' },
})) }))
}, },
// XXX BUG: history closing errors -- non-critical... // XXX BUG: history closing errors -- non-critical...

View File

@ -644,6 +644,9 @@ function(data, options){
// // list length limit is reached... // // list length limit is reached...
// overflow: function(selected){ ... }, // overflow: function(selected){ ... },
// //
// // predicate to test if an item is to be removed...
// remove: null | function(item){ ... },
//
// // list of items to remove, if not given this will be maintained // // list of items to remove, if not given this will be maintained
// // internally // // internally
// to_remove: null | <list>, // to_remove: null | <list>,
@ -731,6 +734,8 @@ function(data, options){
// properly... // properly...
// XXX the problem with this is that it adds elements live while removing // XXX the problem with this is that it adds elements live while removing
// elements on close, either both should be live or both on close... // elements on close, either both should be live or both on close...
// XXX can we avoid creating the remove button on items that do not pass
// the options.remove(..) predicate???
Items.EditableList = Items.EditableList =
function(list, options){ function(list, options){
var make = this var make = this
@ -1141,7 +1146,7 @@ function(list, options){
function(){ $(this).trigger('itemedit') }) function(){ $(this).trigger('itemedit') })
} }
// new button... // new item...
if(options.new_item !== false){ if(options.new_item !== false){
var new_item = options.new_item || true var new_item = options.new_item || true
new_item = new_item === true ? '$New...' : new_item new_item = new_item === true ? '$New...' : new_item
@ -1159,8 +1164,8 @@ function(list, options){
dialog.update() dialog.update()
.done(function(){ .done(function(){
//dialog.select('"'+txt+'"') //dialog.select('"'+txt+'"')
dialog.select('"'+txt.replace(/\$/g, '')+'"') txt
}) && dialog.select('"'+txt.replace(/\$/g, '')+'"') })
} }
})) }))
} }
@ -1187,11 +1192,14 @@ function(list, options){
lst = dialog.__list[id] lst = dialog.__list[id]
// remove items... // remove items...
to_remove.forEach(function(e){ to_remove
var i = lst.indexOf(e) .filter(options.remove
i >= 0 || function(){ return true })
&& lst.splice(i, 1) .forEach(function(e){
}) var i = lst.indexOf(e)
i >= 0
&& lst.splice(i, 1)
})
// sort... // sort...
if(options.sort){ if(options.sort){