now new collections are added to top of list by default (+option)...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2021-02-25 16:03:33 +03:00
parent 83404e9714
commit 3e3cd7665f
2 changed files with 56 additions and 50 deletions

View File

@ -146,13 +146,12 @@ var CollectionActions = actions.Actions({
var order = this.__collection_order = this.__collection_order || [] var order = this.__collection_order = this.__collection_order || []
// add unsorted things to the head of the list... // add unsorted things to the head of the list...
var res = keys var res = [
.concat(order) ...keys,
.reverse() ...order,
.unique() ].tailUnique()
.reverse()
// XXX defaults... // defaults...
res = res.concat(defaults).unique() res = res.concat(defaults).unique()
// keep MAIN_COLLECTION_TITLE out of the collection order... // keep MAIN_COLLECTION_TITLE out of the collection order...
@ -574,6 +573,8 @@ var CollectionActions = actions.Actions({
&& collection != MAIN_COLLECTION_TITLE && collection != MAIN_COLLECTION_TITLE
// save the data... // save the data...
// XXX would be nice to be able to add new collections both
// to the start and end of list...
var state = collections[collection] = var state = collections[collection] =
collections[collection] collections[collection]
|| {} || {}
@ -2249,6 +2250,13 @@ var UICollectionActions = actions.Actions({
// This will be auto-selected in .browseCollections(..) on next // This will be auto-selected in .browseCollections(..) on next
// add/edit operation... // add/edit operation...
//'collection-last-used': null, //'collection-last-used': null,
// can be:
// 'end' | null - place new items at end of list
// 'start' - place new items at start of list
//
// XXX make this configurable???
'collection-ui-place-new': 'start',
}, },
// UI... // UI...
@ -2375,6 +2383,7 @@ var UICollectionActions = actions.Actions({
i && $(this).attr('count', i) } i && $(this).attr('count', i) }
// update collection list if changed externally... // update collection list if changed externally...
/* XXX
collections.splice.apply(collections, collections.splice.apply(collections,
// NOTE: if the length calculation here looks a "bit" // NOTE: if the length calculation here looks a "bit"
// convoluted, that's because it is, this fixes // convoluted, that's because it is, this fixes
@ -2387,6 +2396,15 @@ var UICollectionActions = actions.Actions({
.concat(collections .concat(collections
.concat(that.collection_order || []) .concat(that.collection_order || [])
.unique())) .unique()))
/*/
console.log('>>>>', that.collection_order)
collections
.splice(0, collections.length,
...[
...collections,
...(that.collection_order || []),
].tailUnique())
//*/
// main collection... // main collection...
var main = typeof(show_main) == 'function' ? var main = typeof(show_main) == 'function' ?
@ -2429,6 +2447,7 @@ var UICollectionActions = actions.Actions({
: action ? : action ?
'$New...' '$New...'
: '$New from current state...', : '$New from current state...',
place_new_item: that.config['collection-ui-place-new'],
unique: true, unique: true,
sortable: 'y', sortable: 'y',

View File

@ -568,6 +568,8 @@ function(data, options){
// // it as item text... // // it as item text...
// new_item: <text>|<bool>, // new_item: <text>|<bool>,
// //
// place_new_item: null | 'end' | 'start',
//
// // If true (default), enable direct editing of items... // // If true (default), enable direct editing of items...
// // // //
// editable_items: <bool>, // editable_items: <bool>,
@ -755,8 +757,7 @@ function(list, options){
// save item to lst... // save item to lst...
var saveItem = function(txt, replace){ var saveItem = function(txt, replace){
if(txt == replace || txt.trim() == ''){ if(txt == replace || txt.trim() == ''){
return txt return txt }
}
txt = options.normalize ? txt = options.normalize ?
options.normalize(txt) options.normalize(txt)
: txt : txt
@ -770,8 +771,7 @@ function(list, options){
// invalid format... // invalid format...
if(options.check && !options.check(txt)){ if(options.check && !options.check(txt)){
dialog.update() dialog.update()
return return }
}
lst = dialog.__list[id] lst = dialog.__list[id]
var normalized = lst.map(function(e){ var normalized = lst.map(function(e){
@ -784,13 +784,11 @@ function(list, options){
options.overflow options.overflow
&& options.overflow.call(dialog, txt) && options.overflow.call(dialog, txt)
return return }
}
// prevent editing non-arrays... // prevent editing non-arrays...
if(!editable || !lst){ if(!editable || !lst){
return return }
}
// check if item pre-existed... // check if item pre-existed...
var preexisted = utxt ? var preexisted = utxt ?
@ -802,8 +800,11 @@ function(list, options){
|| normalized.indexOf(ntxt) >= 0) || normalized.indexOf(ntxt) >= 0)
// add new value and sort list... // add new value and sort list...
// XXX add option to append/prepend item to list...
;(replace && lst.indexOf(replace) >= 0) ? ;(replace && lst.indexOf(replace) >= 0) ?
lst[lst.indexOf(replace)] = txt lst[lst.indexOf(replace)] = txt
: options.place_new_item == 'start' ?
lst.unshift(txt)
: lst.push(txt) : lst.push(txt)
// unique... // unique...
@ -813,8 +814,7 @@ function(list, options){
// unique filter... // unique filter...
} else if(options.unique instanceof Function){ } else if(options.unique instanceof Function){
lst = lst.unique(options.unique) lst = lst.unique(options.unique) }
}
// itemadded handler... // itemadded handler...
options.itemadded options.itemadded
@ -827,8 +827,7 @@ function(list, options){
lst = lst lst = lst
.sort(options.sort instanceof Function ? .sort(options.sort instanceof Function ?
options.sort options.sort
: undefined) : undefined) }
}
lst = write(dialog.__list[id], lst) lst = write(dialog.__list[id], lst)
@ -1101,16 +1100,14 @@ function(list, options){
.toArray() .toArray()
var l = dialog.__list[id] var l = dialog.__list[id]
l.splice.apply(l, [0, l.length].concat(order)) l.splice.apply(l, [0, l.length].concat(order))
dialog.updateItemNumbers() dialog.updateItemNumbers() },
}, }) }
})
}
// mark items for removal -- if a list is given by user... // mark items for removal -- if a list is given by user...
to_remove.forEach(function(e){ to_remove
.forEach(function(e){
dialog.filter('"'+ e +'"') dialog.filter('"'+ e +'"')
.addClass('strike-out') .addClass('strike-out') })
})
options.itemopen options.itemopen
&& res.on('open', function(evt){ && res.on('open', function(evt){
@ -1122,8 +1119,7 @@ function(list, options){
if(options.editable_items !== false){ if(options.editable_items !== false){
var trigger_edit = function(){ var trigger_edit = function(){
dialog.select('!') dialog.select('!')
.trigger('itemedit') .trigger('itemedit') }
}
$(res) $(res)
.on('itemedit', function(){ editItem($(this)) }) .on('itemedit', function(){ editItem($(this)) })
;(options.item_edit_keys || ['F2']) ;(options.item_edit_keys || ['F2'])
@ -1133,8 +1129,7 @@ function(list, options){
options.item_edit_events != false options.item_edit_events != false
&& options.item_edit_events != '' && options.item_edit_events != ''
&& $(res).on(options.item_edit_events || 'menu', && $(res).on(options.item_edit_events || 'menu',
function(){ $(this).trigger('itemedit') }) function(){ $(this).trigger('itemedit') }) }
}
// new item... // new item...
if(options.new_item !== false){ if(options.new_item !== false){
@ -1150,15 +1145,12 @@ function(list, options){
.on('edit-commit', function(evt, txt){ .on('edit-commit', function(evt, txt){
if(txt.trim() != ''){ if(txt.trim() != ''){
txt = saveItem(txt) txt = saveItem(txt)
dialog.update() dialog.update()
.done(function(){ .done(function(){
//dialog.select('"'+txt+'"') //dialog.select('"'+txt+'"')
txt txt
&& dialog.select('"'+txt.replace(/\$/g, '')+'"') }) && dialog
} .select('"'+txt.replace(/\$/g, '')+'"') }) } })) }
}))
}
// dialog handlers... // dialog handlers...
// NOTE: we bind these only once per dialog... // NOTE: we bind these only once per dialog...
@ -1169,15 +1161,12 @@ function(list, options){
.on('update', function(){ .on('update', function(){
to_remove.forEach(function(e){ to_remove.forEach(function(e){
dialog.filter('"'+ e +'"') dialog.filter('"'+ e +'"')
.addClass('strike-out') .addClass('strike-out') }) })
})
})
// clear the to_remove items + save list... // clear the to_remove items + save list...
.on('close', function(){ .on('close', function(){
// prevent editing non-arrays... // prevent editing non-arrays...
if(!editable){ if(!editable){
return return }
}
lst = dialog.__list[id] lst = dialog.__list[id]
@ -1188,20 +1177,18 @@ function(list, options){
.forEach(function(e){ .forEach(function(e){
var i = lst.indexOf(e) var i = lst.indexOf(e)
i >= 0 i >= 0
&& lst.splice(i, 1) && lst.splice(i, 1) })
})
// sort... // sort...
if(options.sort){ if(options.sort){
lst.sort(options.sort !== true ? options.sort : undefined) lst.sort(
} options.sort !== true ?
options.sort
: undefined) }
write(list, lst) write(list, lst) }) }
})
}
return $(res) return $(res) }
}