bugfixes and tweaks...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2017-09-24 04:26:37 +03:00
parent e508f9848a
commit 5c78c95297
2 changed files with 51 additions and 26 deletions

View File

@ -47,6 +47,7 @@ var widgets = require('features/ui-widgets')
// //
var MAIN_COLLECTION_TITLE = '$ALL' var MAIN_COLLECTION_TITLE = '$ALL'
var MAIN_COLLECTION_GID = '0'
// XXX undo... // XXX undo...
var CollectionActions = actions.Actions({ var CollectionActions = actions.Actions({
@ -96,7 +97,8 @@ var CollectionActions = actions.Actions({
set collection(value){ set collection(value){
this.loadCollection(value) }, this.loadCollection(value) },
get collectionGID(){ get collectionGID(){
return ((this.collections || {})[this.collection] || {}).gid }, return ((this.collections || {})[this.collection] || {}).gid
|| MAIN_COLLECTION_GID },
set collectionGID(value){ set collectionGID(value){
this.collection = value }, this.collection = value },
@ -476,8 +478,10 @@ var CollectionActions = actions.Actions({
var state = collections[collection] = collections[collection] || {} var state = collections[collection] = collections[collection] || {}
state.title = state.title || collection state.title = state.title || collection
state.gid = state.gid state.gid = state.gid
// maintain the GID of MAIN_COLLECTION_TITLE as '0'... // maintain the GID of MAIN_COLLECTION_TITLE as MAIN_COLLECTION_GID...
|| (collection == MAIN_COLLECTION_TITLE ? '0' : this.data.newGID()) || (collection == MAIN_COLLECTION_TITLE ?
MAIN_COLLECTION_GID
: this.data.newGID())
// NOTE: we do not need to care about tags here as they // NOTE: we do not need to care about tags here as they
// will get overwritten on load... // will get overwritten on load...
state.data = (mode == 'empty' ? state.data = (mode == 'empty' ?
@ -1046,7 +1050,7 @@ module.Collection = core.ImageGridFeatures.Feature({
: [] : []
var from_id = 'collection: ' var from_id = 'collection: '
+JSON.stringify(from == MAIN_COLLECTION_TITLE ? +JSON.stringify(from == MAIN_COLLECTION_TITLE ?
'0' MAIN_COLLECTION_GID
: this.collections[from].gid || from) : this.collections[from].gid || from)
// everything has changed, no need to bother with details... // everything has changed, no need to bother with details...
@ -1570,7 +1574,6 @@ module.AutoCollections = core.ImageGridFeatures.Feature({
//--------------------------------------------------------------------- //---------------------------------------------------------------------
// XXX show collections in image metadata... (???) // XXX show collections in image metadata... (???)
// XXX mark unsaved (*) collections...
var UICollectionActions = actions.Actions({ var UICollectionActions = actions.Actions({
config: { config: {
// Global default collections... // Global default collections...
@ -1595,8 +1598,7 @@ var UICollectionActions = actions.Actions({
&& title != MAIN_COLLECTION_TITLE }, && title != MAIN_COLLECTION_TITLE },
})], })],
// XXX need .changes format... // XXX edit collection title here???
// XXX BUG: adding a new collections kills sort...
browseCollections: ['Collections/$Collec$tions...', browseCollections: ['Collections/$Collec$tions...',
core.doc`Collection list... core.doc`Collection list...
@ -1639,12 +1641,21 @@ var UICollectionActions = actions.Actions({
dialog.close() dialog.close()
} }
var setItemState = function(title){ var setItemState = function(title){
var gid = ((that.collections || {})[title] || {}).gid || title
// handle main collection changes...
gid = title == MAIN_COLLECTION_TITLE ?
MAIN_COLLECTION_GID
: gid
var text = this.find('.text').last() var text = this.find('.text').last()
// saved state... // saved state...
// XXX need changes format... var unsaved = that.changes === true
var unsaved = this.changes === true || (that.changes || {})['collection: '+ JSON.stringify(gid)]
|| (this.changes || {})['collections: '+ JSON.stringify(title)] || (that.collectionGID == gid
&& (that.config['collection-transfer-changes'] || [])
.filter(function(a){
return !!(that.changes || {})[a] }).length > 0)
unsaved unsaved
&& text.attr('unsaved', true) && text.attr('unsaved', true)
@ -1659,8 +1670,12 @@ var UICollectionActions = actions.Actions({
&& text.attr('cropped', cs.length) && text.attr('cropped', cs.length)
} }
// XXX should we update collections if they changed outside??? // update collection list if changed externally...
// XXX // XXX do we need this???
collections.splice.apply(collections, [0, collections.length].concat(
collections
.concat(this.collection_order || [])
.unique()))
// main collection... // main collection...
!action !action
@ -1678,7 +1693,8 @@ var UICollectionActions = actions.Actions({
.addClass('sort-handle') .addClass('sort-handle')
.html('&#x2630;')) .html('&#x2630;'))
setItemState setItemState
.call($(this), title) //.call($(this), title)
.call($(this), $(this).find('.text').attr('text'))
}, },
open: openHandler, open: openHandler,
}}) }})
@ -1709,20 +1725,18 @@ var UICollectionActions = actions.Actions({
}, { }, {
cls: 'collection-list', cls: 'collection-list',
// focus current collection... // focus current collection...
selected: that.collection || MAIN_COLLECTION_TITLE, selected: JSON.stringify(
(that.collection || MAIN_COLLECTION_TITLE)
// XXX not sure it is good that we have to do this...
.replace(/\$/g, '')),
}) })
.close(function(){ .close(function(){
// XXX for some reason when an item is added collections
// reverts to the pre-sorted state and all
// consecutive sorts are ignored...
console.log('>>>', collections)
that.collection_order = collections that.collection_order = collections
to_remove to_remove
.forEach(function(title){ that.removeCollection(title) }) .forEach(function(title){ that.removeCollection(title) })
}) })
})], })],
// XXX mark unsaved (*) collections...
browseImageCollections: ['Collections|Image/Image $collections...', browseImageCollections: ['Collections|Image/Image $collections...',
widgets.makeUIDialog(function(gid){ widgets.makeUIDialog(function(gid){
var that = this var that = this

View File

@ -683,6 +683,7 @@ function(data, options){
// NOTE: this uses .List(..) internally, see it's doc for additional // NOTE: this uses .List(..) internally, see it's doc for additional
// info. // info.
// NOTE: the list must contain strings. // NOTE: the list must contain strings.
// NOTE: this accounts for '$' as a key binding marker in item text...
// //
// XXX should id be the first argument?? // XXX should id be the first argument??
// XXX TEST: potential problem: when reloading the list this will // XXX TEST: potential problem: when reloading the list this will
@ -952,6 +953,8 @@ function(list, options){
txt = options.normalize ? txt = options.normalize ?
options.normalize(txt) options.normalize(txt)
: txt : txt
// account for '$' as key binding marker...
var ntxt = txt.replace(/\$/g, '')
// invalid format... // invalid format...
if(options.check && !options.check(txt)){ if(options.check && !options.check(txt)){
@ -960,6 +963,8 @@ function(list, options){
} }
lst = dialog.__list[id] lst = dialog.__list[id]
var normalized = lst.map(function(e){
return e.replace(/\$/g, '') })
// list length limit // list length limit
if(options.length_limit if(options.length_limit
@ -977,25 +982,32 @@ function(list, options){
} }
// check if item pre-existed... // check if item pre-existed...
var preexisted = lst.indexOf(options.unique instanceof Function ? var preexisted = options.unique instanceof Function ?
options.unique(txt) //lst.indexOf(options.unique(txt)) >= 0
: txt) >= 0 (lst.indexOf(options.unique(txt)) >= 0
// account for '$' as key binding marker... (XXX ???)
|| normalized.indexOf(options.unique(txt).replace(/\$/g, '')))
: (lst.indexOf(txt) >= 0
|| normalized.indexOf(ntxt) >= 0)
// add new value and sort list... // add new value and sort list...
lst.push(txt) lst.push(txt)
// unique... // unique...
if(options.unique == null || options.unique === true){ if(options.unique == null || options.unique === true){
lst = lst.unique() // account for '$' as key binding marker...
lst = lst.unique(function(e){ return e.replace(/\$/g, '') })
// unique normalized... // unique normalized...
} else if(options.unique instanceof Function){ } else if(options.unique instanceof Function){
lst = lst.unique(options.unique) lst = lst.unique(options.unique)
} }
// itemadded handler...
options.itemadded options.itemadded
&& !(options.unique && preexisted) && !(options.unique && preexisted)
&& options.itemadded.call(dialog, txt) && options
.itemadded.call(dialog, txt)
// sort... // sort...
if(options.sort){ if(options.sort){
@ -1005,8 +1017,7 @@ function(list, options){
: undefined) : undefined)
} }
// XXX should this be done here??? lst = write(dialog.__list[id], lst)
//lst = dialog.__list[id] = write(list, lst)
// update list and select new value... // update list and select new value...
dialog.update() dialog.update()