From 1fe330112322ff361290cc0307f2dc6d28d173ca Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Mon, 8 Dec 2014 13:04:09 +0300 Subject: [PATCH] added tag sync + some experimental stuff... Signed-off-by: Alex A. Naanou --- ui (gen4)/data.js | 2 +- ui (gen4)/ui.js | 23 ++++++++---- ui (gen4)/viewer.js | 87 +++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 102 insertions(+), 10 deletions(-) diff --git a/ui (gen4)/data.js b/ui (gen4)/data.js index bc4c49be..25703aff 100755 --- a/ui (gen4)/data.js +++ b/ui (gen4)/data.js @@ -2324,7 +2324,7 @@ var DataWithTagsPrototype = { // -> data // // Reset image tags from data... - // .tagsToImages(images, 'rest') + // .tagsToImages(images, 'reset') // -> data // // XXX should this be here??? diff --git a/ui (gen4)/ui.js b/ui (gen4)/ui.js index 9b4eae34..18027cfd 100755 --- a/ui (gen4)/ui.js +++ b/ui (gen4)/ui.js @@ -205,6 +205,8 @@ $(function(){ viewer: $('.viewer') }) + // used switch experimental actions on (set to true) or off (unset or false)... + //a.experimental = true // XXX for some reason this is not visible when loading... a.setEmptyMsg('Loading...') @@ -234,18 +236,27 @@ $(function(){ // experimental and optional features... //'auto-single-image', - ]) + // XXX this is not for production... + 'experiments', + ]) + // this publishes all the actions... //module.GLOBAL_KEYBOARD.__proto__ = a // load some testing data... // NOTE: we can load this in parts... - a.load({ - //viewer: $('.viewer'), - data: data.Data(testing.mock_data), - images: testing.makeTestImages(), - }) + a + .load({ + //viewer: $('.viewer'), + data: data.Data(testing.mock_data), + images: testing.makeTestImages(), + }) + // this is needed when loading legacy sources that do not have tags + // synced... + // do not do for actual data... + //.syncTags() + a.setEmptyMsg( diff --git a/ui (gen4)/viewer.js b/ui (gen4)/viewer.js index b1e0782c..bc509a06 100755 --- a/ui (gen4)/viewer.js +++ b/ui (gen4)/viewer.js @@ -215,8 +215,7 @@ actions.Actions({ // basic life-cycle actions... // - // XXX sync tags between data and images... - // ...but which takes priority??? + // XXX do we need to call .syncTags(..) here??? load: [ function(d){ this.images = images.Images(d.images) @@ -225,7 +224,7 @@ actions.Actions({ clear: [ function(){ delete this.data - delete this.Images + delete this.images }], // XXX should this be here??? @@ -543,6 +542,49 @@ actions.Actions({ // XXX mark updated... }) }], + // Sync tags... + // + // Sync both ways... + // .syncTags() + // .syncTags('both') + // + // Sync from .data + // .syncTags('data') + // + // Sync from .images + // .syncTags('images') + // + // Sync from object + // .syncTags() + // + // NOTE: mode is data.tagsToImages(..) / data.tagsFromImages(..) + // compatible... + // NOTE: setting source to 'both' and mode to 'reset' is the same as + // 'images' and 'reset' as all .data tags will be lost on first + // pass... + syncTags: ['Synchoronize tags between data and images', + function(source, mode){ + // can't do anything if either .data or .images are not + // defined... + if(this.data == null || this.images == null){ + return + } + + source = source || 'both' + mode = mode || 'merge' + images = this.images + if(typeof(source) != typeof('str')){ + images = source + source = 'images' + } + + if(source == 'data' || source == 'both'){ + this.data.tagsToImages(images, mode) + } + if(source == 'images' || source == 'both'){ + this.data.tagsFromImages(images, mode) + } + }], // crop... @@ -2316,6 +2358,45 @@ module.FileSystemLoader = features.Feature(ImageGridFeatures, { +//--------------------------------------------------------------------- + +var ExperimentActions = actions.Actions({ + /* trying an argument mutation method... (FAILED: arguments is mutable) + argumentMutation: [ + function(a, b){ + console.log('ACTIONS ARGS:', a, b) + }], + */ +}) + +var ExperimentFeature = +module.ExperimentFeature = features.Feature(ImageGridFeatures, { + title: '', + doc: '', + + tag: 'experiments', + + isApplicable: function(actions){ + return actions.experimental + }, + + actions: ExperimentActions, + + handlers: [ + /* trying an argument mutation method... (FAILED: arguments is mutable) + ['argumentMutation.pre', + function(a, b){ + console.log('EVENT ARGS:', a, b) + arguments[0] += 1 + arguments[1] += 1 + }], + */ + ], +}) + + + + /********************************************************************** * vim:set ts=4 sw=4 : */ return module })