From c9400b83a07e203981da811aeead7933e97838f3 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Tue, 29 Dec 2015 01:02:57 +0300 Subject: [PATCH] refactored loading (now one entry point only: .load(..)) + added location.hash fro current image and .location.current support... Signed-off-by: Alex A. Naanou --- ui (gen4)/features/base.js | 10 +++-- ui (gen4)/features/history.js | 10 ++++- ui (gen4)/features/location.js | 18 +++++++-- ui (gen4)/features/meta.js | 1 - ui (gen4)/features/ui.js | 68 ++++++++++------------------------ ui (gen4)/images.js | 12 ++++-- 6 files changed, 57 insertions(+), 62 deletions(-) diff --git a/ui (gen4)/features/base.js b/ui (gen4)/features/base.js index cb65f07e..01df6602 100755 --- a/ui (gen4)/features/base.js +++ b/ui (gen4)/features/base.js @@ -191,6 +191,8 @@ actions.Actions({ // XXX do we need to call .syncTags(..) here??? load: ['- File|Interface/', function(d){ + this.clear() + this.images = images.Images(d.images) this.data = data.Data(d.data) }], @@ -221,10 +223,12 @@ actions.Actions({ // ...note if we use this it breaks, need to rethink... loadURLs: ['File/Load a URL list', function(lst, base){ - this.clear() + var imgs = images.Images.fromArray(lst, base) - this.images = images.Images.fromArray(lst, base) - this.data = data.Data.fromArray(this.images.keys()) + this.load({ + images: imgs, + data: data.Data.fromArray(imgs.keys()), + }) }], // XXX experimental... diff --git a/ui (gen4)/features/history.js b/ui (gen4)/features/history.js index 3b81f4be..2101675d 100755 --- a/ui (gen4)/features/history.js +++ b/ui (gen4)/features/history.js @@ -196,6 +196,7 @@ var URLHistoryLocalStorageActions = actions.Actions({ config: { 'url-history-local-storage-key': 'url-history', 'url-history-loaded-local-storage-key': 'url-history-loaded', + 'url-history-load-current': true, }, __url_history: null, @@ -268,6 +269,13 @@ var URLHistoryLocalStorageActions = actions.Actions({ if(loaded && localStorage[loaded]){ var l = JSON.parse(localStorage[loaded]) + + if(l.current != null && this.config['url-history-load-current']){ + this.one('load', function(){ + this.current = l.current + }) + } + this.openURLFromHistory(l.path, l.method) } else { @@ -299,7 +307,7 @@ module.URLHistoryLocalStorage = core.ImageGridFeatures.Feature({ function(){ this.saveURLHistory() }], // save base_path... - ['load loadURLs', + ['load', function(){ this.location && this.location.path && this.saveLocation() }], // save... diff --git a/ui (gen4)/features/location.js b/ui (gen4)/features/location.js index 88a7efdb..36e698d9 100755 --- a/ui (gen4)/features/location.js +++ b/ui (gen4)/features/location.js @@ -34,8 +34,6 @@ var LocationActions = actions.Actions({ // { // path: , // method: , - // // XXX current or hash??? - // // XXX not yet supported... // current: , // } // @@ -56,6 +54,11 @@ var LocationActions = actions.Actions({ if(b){ this.__location.path = b } + + if(this.__location.current == null){ + this.__location.current = this.current + } + return this.__location }, set location(value){ @@ -86,10 +89,17 @@ var LocationActions = actions.Actions({ current: cur, } - this[value.method || 'loadIndex'](path) + var res = this[value.method || 'loadIndex'](path) // XXX load current... - // XXX + if(res.then != null){ + res.then(function(){ + this.current = cur + }) + + } else { + this.current = cur + } }, }) diff --git a/ui (gen4)/features/meta.js b/ui (gen4)/features/meta.js index 377770fe..0c9d87ee 100755 --- a/ui (gen4)/features/meta.js +++ b/ui (gen4)/features/meta.js @@ -52,7 +52,6 @@ core.ImageGridFeatures.Feature('viewer-testing', [ // local storage + url... 'config-local-storage', - // XXX make this browser-only... 'ui-url-hash', 'url-history-local-storage', 'ui-single-image-view-local-storage', diff --git a/ui (gen4)/features/ui.js b/ui (gen4)/features/ui.js index 7d61851d..03b33803 100755 --- a/ui (gen4)/features/ui.js +++ b/ui (gen4)/features/ui.js @@ -193,18 +193,16 @@ actions.Actions({ ? this.ribbons.viewer : viewer - // XXX do we need to recycle the ribbons??? - if(this.ribbons != null){ + if(this.ribbons == null){ + this.ribbons = ribbons.Ribbons(viewer, this.images) + // XXX is this correct??? + this.ribbons.__image_updaters = [this.updateImage.bind(this)] + + } else { this.ribbons.clear() + this.ribbons.images = this.images } - // NOTE: this is done unconditionally to avoid manually - // setting images and other stuff in the future... - this.ribbons = ribbons.Ribbons(viewer, this.images) - - // XXX is this correct??? - this.ribbons.__image_updaters = [this.updateImage.bind(this)] - this.reload() } }], @@ -250,7 +248,7 @@ actions.Actions({ this.ribbons.updateImage(gids) }], clear: [ - function(){ this.ribbons.clear() }], + function(){ this.ribbon && this.ribbons.clear() }], clone: [function(full){ return function(res){ if(this.ribbons){ @@ -263,32 +261,6 @@ actions.Actions({ }], - // XXX should this be an entry point??? - // ...IMO this should be more like .fromArray(..) and use .load(..) - // internally... - loadURLs: [ - function(){ - return function(){ - // recycle the viewer if one is not given specifically... - var viewer = this.ribbons != null - ? this.ribbons.viewer - : viewer - - if(this.ribbons == null){ - this.ribbons = ribbons.Ribbons(viewer, this.images) - // XXX is this correct??? - this.ribbons.__image_updaters = [this.updateImage.bind(this)] - - } else { - this.ribbons.clear() - this.ribbons.images = this.images - } - - this.reload() - } - }], - - replaceGid: [ function(from, to){ return function(res){ @@ -775,7 +747,7 @@ module.Viewer = core.ImageGridFeatures.Feature({ var journalActions = { clear: null, load: null, - loadURLs: null, + //loadURLs: null, setBaseRibbon: null, @@ -1794,7 +1766,8 @@ module.SingleImageViewLocalStorage = core.ImageGridFeatures.Feature({ handlers:[ // set scale... - ['load loadURLs', + //['load loadURLs', + ['load', function(){ // prevent this from doing anything while no viewer... if(!this.ribbons || !this.ribbons.viewer || this.ribbons.viewer.length == 0){ @@ -2810,10 +2783,8 @@ module.DirectControlGSAP = core.ImageGridFeatures.Feature({ //--------------------------------------------------------------------- -// XXX make this browser specific... -// XXX BUG: loading of current gid from url for some reason is broken, -// race?... +// XXX make this browser specific... (???) var URLHash = module.URLHash = core.ImageGridFeatures.Feature({ title: '', @@ -2822,25 +2793,24 @@ module.URLHash = core.ImageGridFeatures.Feature({ tag: 'ui-url-hash', depends: ['ui'], + //isApplicable: function(){}, + handlers: [ ['focusImage', function(res, a){ - console.log('focus:', a) if(this.current && this.current != ''){ location.hash = this.current } }], - // XXX this does not work for some reason... - // ...likely because of the slow async load and sync set... - ['start', + ['load.pre', function(){ var h = location.hash h = h.replace(/^#/, '') - // for some odd reason this does not work... - if(h != ''){ - console.log('!!!!', h) - this.current = h + return function(){ + if(h != '' && this.data.getImageOrder(h) >= 0){ + this.current = h + } } }], ], diff --git a/ui (gen4)/images.js b/ui (gen4)/images.js index 57ce9ae2..dca0518d 100755 --- a/ui (gen4)/images.js +++ b/ui (gen4)/images.js @@ -291,14 +291,18 @@ module.ImagesClassPrototype = { //var base_pattern = base ? RegExp('^' + base) : null var base_pattern = base ? RegExp('^' + quoteRegExp(base)) : null data.forEach(function(path){ - var gid = hash('I'+i) + // XXX need to normalize path... + var p = (base_pattern ? path.replace(base_pattern, './') : path) + .replace(/([\/\\])\1+/g, '/') + // XXXX + var gid = hash('I'+i+':'+p) + // XXX populate the image doc better... images[gid] = { id: gid, - // XXX need to normalize path... - path: (base_pattern ? path.replace(base_pattern, './') : path) - .replace(/([\/\\])\1+/g, '/'), + path: p, } + // remove only of base path is given and in path... if(base && base_pattern.test(path)){ images[gid].base_path = base