added tag sync + some experimental stuff...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2014-12-08 13:04:09 +03:00
parent beb960ac3a
commit 1fe3301123
3 changed files with 102 additions and 10 deletions

View File

@ -2324,7 +2324,7 @@ var DataWithTagsPrototype = {
// -> data // -> data
// //
// Reset image tags from data... // Reset image tags from data...
// .tagsToImages(images, 'rest') // .tagsToImages(images, 'reset')
// -> data // -> data
// //
// XXX should this be here??? // XXX should this be here???

View File

@ -205,6 +205,8 @@ $(function(){
viewer: $('.viewer') 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... // XXX for some reason this is not visible when loading...
a.setEmptyMsg('Loading...') a.setEmptyMsg('Loading...')
@ -234,18 +236,27 @@ $(function(){
// experimental and optional features... // experimental and optional features...
//'auto-single-image', //'auto-single-image',
])
// XXX this is not for production...
'experiments',
])
// this publishes all the actions... // this publishes all the actions...
//module.GLOBAL_KEYBOARD.__proto__ = a //module.GLOBAL_KEYBOARD.__proto__ = a
// load some testing data... // load some testing data...
// NOTE: we can load this in parts... // NOTE: we can load this in parts...
a.load({ a
//viewer: $('.viewer'), .load({
data: data.Data(testing.mock_data), //viewer: $('.viewer'),
images: testing.makeTestImages(), 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( a.setEmptyMsg(

View File

@ -215,8 +215,7 @@ actions.Actions({
// basic life-cycle actions... // basic life-cycle actions...
// //
// XXX sync tags between data and images... // XXX do we need to call .syncTags(..) here???
// ...but which takes priority???
load: [ load: [
function(d){ function(d){
this.images = images.Images(d.images) this.images = images.Images(d.images)
@ -225,7 +224,7 @@ actions.Actions({
clear: [ clear: [
function(){ function(){
delete this.data delete this.data
delete this.Images delete this.images
}], }],
// XXX should this be here??? // XXX should this be here???
@ -543,6 +542,49 @@ actions.Actions({
// XXX mark updated... // XXX mark updated...
}) })
}], }],
// Sync tags...
//
// Sync both ways...
// .syncTags()
// .syncTags('both')
//
// Sync from .data
// .syncTags('data')
//
// Sync from .images
// .syncTags('images')
//
// Sync from <images> object
// .syncTags(<images>)
//
// 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... // 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 : */ * vim:set ts=4 sw=4 : */
return module }) return module })