From af10366c2288f10fa9e36517a4dffd614e15caf5 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Mon, 18 Sep 2017 18:32:34 +0300 Subject: [PATCH] some refactorng + work on saving collections... Signed-off-by: Alex A. Naanou --- ui (gen4)/css/experimenting.css | 12 ++++ ui (gen4)/features/base.js | 6 +- ui (gen4)/features/collections.js | 58 ++++++++++++++++--- ui (gen4)/features/core.js | 2 +- ui (gen4)/features/ui-partial-ribbons-vdom.js | 2 +- ui (gen4)/features/ui-ribbons.js | 4 +- ui (gen4)/imagegrid/data.js | 14 ++--- 7 files changed, 77 insertions(+), 21 deletions(-) diff --git a/ui (gen4)/css/experimenting.css b/ui (gen4)/css/experimenting.css index 06734848..e4cff426 100755 --- a/ui (gen4)/css/experimenting.css +++ b/ui (gen4)/css/experimenting.css @@ -265,6 +265,18 @@ body { opacity: 0.5; font-style: italic; } +.browse-widget.collection-list .list .item .text[unsaved]:after { + content: "*"; + margin-left: 0px; + opacity: 0.5; + font-style: italic; +} +.browse-widget.collection-list .list .item .text[unsaved][cropped]:after { + content: "* (cropped)"; + margin-left: 0px; + opacity: 0.5; + font-style: italic; +} /* External Editor List */ diff --git a/ui (gen4)/features/base.js b/ui (gen4)/features/base.js index c9b9697f..c7c3ff40 100755 --- a/ui (gen4)/features/base.js +++ b/ui (gen4)/features/base.js @@ -320,20 +320,20 @@ actions.Actions({ null : this.images.getImagePath(gid, this.location.path) }], - replaceGid: ['- System/Replace image gid', + replaceGID: ['- System/Replace image gid', {journal: true}, function(from, to){ from = this.data.getImage(from) // data... - var res = this.data.replaceGid(from, to) + var res = this.data.replaceGID(from, to) if(res == null){ return } // images... - this.images && this.images.replaceGid(from, to) + this.images && this.images.replaceGID(from, to) }], diff --git a/ui (gen4)/features/collections.js b/ui (gen4)/features/collections.js index fdf3b53b..19212a2e 100755 --- a/ui (gen4)/features/collections.js +++ b/ui (gen4)/features/collections.js @@ -75,10 +75,24 @@ var CollectionActions = actions.Actions({ // } collections: null, + get collectionGIDs(){ + var res = {} + var c = this.collections || {} + Object.keys(c) + .forEach(function(title){ + res[c[title].gid || title] = title + }) + return res + }, + get collection(){ return this.location.collection }, set collection(value){ this.loadCollection(value) }, + get collectionGID(){ + return ((this.collections || {})[this.collection] || {}).gid }, + set collectionGID(value){ + this.collection = value }, // XXX should this check consistency??? get collection_order(){ @@ -243,6 +257,8 @@ var CollectionActions = actions.Actions({ collection = collection == '!' ? this.collection : collection + // if collection is a gid, get the title... + collection = this.collectionGIDs[collection] || collection if(collection == null || this.collections == null || !(collection in this.collections)){ @@ -427,7 +443,7 @@ var CollectionActions = actions.Actions({ // save the data... var state = collections[collection] = collections[collection] || {} state.title = state.title || collection - state.gid = state.gid || this.data.newGid() + state.gid = state.gid || this.data.newGID() // NOTE: we do not need to care about tags here as they // will get overwritten on load... state.data = (mode == 'empty' ? @@ -476,7 +492,7 @@ var CollectionActions = actions.Actions({ if(!this.collections || collection == MAIN_COLLECTION_TITLE){ return } - delete this.collections[collection] + delete this.collections[this.collectionGIDs[collection] || collection] }], @@ -526,6 +542,7 @@ var CollectionActions = actions.Actions({ function(gids, collection){ var that = this collection = collection || this.collection + collection = this.collectionGIDs[collection] || collection if(collection == null || collection == MAIN_COLLECTION_TITLE){ return } @@ -580,6 +597,7 @@ var CollectionActions = actions.Actions({ `, function(align, collection, data){ collection = arguments.length == 1 ? align : collection + collection = this.collectionGIDs[collection] || collection if(collection == null || collection == MAIN_COLLECTION_TITLE){ return } @@ -625,6 +643,7 @@ var CollectionActions = actions.Actions({ {browseMode: function(){ return !this.collection && 'disabled' }}, function(gids, collection){ collection = collection || this.collection + collection = this.collectionGIDs[collection] || collection if(collection == null || collection == MAIN_COLLECTION_TITLE || !this.collections @@ -910,11 +929,25 @@ module.Collection = core.ImageGridFeatures.Feature({ // XXX do we need this??? ['json.pre', function(){ this.saveCollection() }], + + // changes... + // + // format: + // XXX we need: + // - mark collection list changes + // collection-list: true + // - mark whole collection change + // 'collection: ': true + // - mark changes local to collection + // 'collection: ': [, ..] + // // XXX maintain changes... // - collection-level: mark collections as changed... // - in-collection: // - save/restore parent changes when loading/exiting collections // - move collection chnages to collections + // XXX on sriwthicng collections, need to transfer changes + maintain + // global changes... [[ 'collect', 'joinCollect', @@ -1421,6 +1454,7 @@ module.AutoCollections = core.ImageGridFeatures.Feature({ //--------------------------------------------------------------------- // XXX show collections in image metadata... (???) +// XXX mark unsaved (*) collections... var UICollectionActions = actions.Actions({ config: { // Global default collections... @@ -1445,6 +1479,7 @@ var UICollectionActions = actions.Actions({ && title != MAIN_COLLECTION_TITLE }, })], + // XXX need .changes format... browseCollections: ['Collections/$Collec$tions...', core.doc`Collection list... @@ -1479,7 +1514,16 @@ var UICollectionActions = actions.Actions({ that.focusImage(gid) dialog.close() } - var setCroppedState = function(title){ + var setItemState = function(title){ + var text = this.find('.text').last() + + // saved state... + // XXX need changes format... + var unsaved = this.changes === true + || (this.changes || {})['collections: '+ JSON.stringify(title)] + unsaved + && text.attr('unsaved', true) + // indicate collection crop... var cs = title == (that.collection || MAIN_COLLECTION_TITLE) ? @@ -1488,8 +1532,7 @@ var UICollectionActions = actions.Actions({ that.collections[title].crop_stack : null cs - && this.find('.text').last() - .attr('cropped', cs.length) + && text.attr('cropped', cs.length) } //var collections = Object.keys(that.collections || {}) @@ -1514,7 +1557,7 @@ var UICollectionActions = actions.Actions({ .css('color', 'transparent') .addClass('sort-handle') .html('☰')) - setCroppedState + setItemState .call($(this), title) }, open: openHandler, @@ -1534,7 +1577,7 @@ var UICollectionActions = actions.Actions({ check: function(title){ return title.length > 0 }, - each: setCroppedState, + each: setItemState, itemadded: function(title){ action ? @@ -1554,6 +1597,7 @@ var UICollectionActions = actions.Actions({ }) }) })], + // XXX mark unsaved (*) collections... browseImageCollections: ['Collections|Image/Image $collections...', widgets.makeUIDialog(function(gid){ var that = this diff --git a/ui (gen4)/features/core.js b/ui (gen4)/features/core.js index f2fcfdd7..1f844928 100755 --- a/ui (gen4)/features/core.js +++ b/ui (gen4)/features/core.js @@ -1176,7 +1176,7 @@ var TaskActions = actions.Actions({ getJob: ['- Jobs/', function(name){ - name = name || this.data.newGid() + name = name || this.data.newGID() // get/init task dict... var t = this.__jobs = this.__jobs || {} diff --git a/ui (gen4)/features/ui-partial-ribbons-vdom.js b/ui (gen4)/features/ui-partial-ribbons-vdom.js index 99dbcc13..957b467b 100755 --- a/ui (gen4)/features/ui-partial-ribbons-vdom.js +++ b/ui (gen4)/features/ui-partial-ribbons-vdom.js @@ -62,7 +62,7 @@ var Ribbons = { noTransitions: null, noTransitionsDeep: null, elemGID: null, - replaceGid: null, + replaceGID: null, makeShadow: null, diff --git a/ui (gen4)/features/ui-ribbons.js b/ui (gen4)/features/ui-ribbons.js index 394ef048..3b2a92ad 100755 --- a/ui (gen4)/features/ui-ribbons.js +++ b/ui (gen4)/features/ui-ribbons.js @@ -210,10 +210,10 @@ actions.Actions({ }], - replaceGid: [ + replaceGID: [ function(from, to){ return function(res){ - res && this.ribbons.replaceGid(from, to) + res && this.ribbons.replaceGID(from, to) } }], diff --git a/ui (gen4)/imagegrid/data.js b/ui (gen4)/imagegrid/data.js index 809bf836..8be41cab 100755 --- a/ui (gen4)/imagegrid/data.js +++ b/ui (gen4)/imagegrid/data.js @@ -116,7 +116,7 @@ var DataClassPrototype = { fromArray: function(list){ var res = new Data() // XXX make a real ribbon gid... - var gid = res.newGid() + var gid = res.newGID() res.order = list res.ribbon_order.push(gid) res.ribbons[gid] = list.slice() @@ -447,7 +447,7 @@ var DataPrototype = { // If no arguments are given then a unique gid will be generated. // // XXX revise... - newGid: function(str, nohash){ + newGID: function(str, nohash){ // prevent same gids from ever being created... // NOTE: this is here in case we are generating new gids fast // enough that Date.now() produces identical results for 2+ @@ -658,7 +658,7 @@ var DataPrototype = { // Replace image gid... // // NOTE: if to exists then it will get overwritten. - replaceGid: function(from, to){ + replaceGID: function(from, to){ if(from in this.ribbons){ // ribbons... var ribbon = this.ribbons[from] @@ -1414,7 +1414,7 @@ var DataPrototype = { // If mode is 'below' this will create a new ribbon below the target, // otherwise the new ribbon will be created above. newRibbon: function(target, mode){ - var gid = this.newGid() + var gid = this.newGID() var i = this.getRibbonOrder(target) i = mode == 'below' ? i+1 : i @@ -1960,7 +1960,7 @@ var DataPrototype = { gids = gids instanceof Array ? gids : [gids] // XXX not safe -- fast enough and one can generate two identical // gids... - group = group == null ? this.newGid('G' + Date.now()) : group + group = group == null ? this.newGID('G' + Date.now()) : group if(this.groups == null){ this.groups = {} @@ -2314,7 +2314,7 @@ var DataPrototype = { if(d < 0){ // see if g is unique... if(g in base.ribbons || base.order.indexOf(g) >= 0){ - g = base.newGid() + g = base.newGID() } base.ribbon_order.splice(t, 0, g) base.ribbons[g] = r @@ -2330,7 +2330,7 @@ var DataPrototype = { } else { // see if g is unique... if(g in base.ribbons || base.order.indexOf(g) >= 0){ - g = base.newGid() + g = base.newGID() } base.ribbon_order.push(g) base.ribbons[g] = r