From ec490e56e9a65f4744b4aacf965d8c08a8088dce Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sun, 20 Dec 2015 08:12:56 +0300 Subject: [PATCH] refactoring... Signed-off-by: Alex A. Naanou --- ui (gen4)/features/base.js | 130 +++++++++++++++++++++++++++++++++---- ui (gen4)/features/meta.js | 2 +- ui (gen4)/lib/features.js | 7 +- 3 files changed, 120 insertions(+), 19 deletions(-) diff --git a/ui (gen4)/features/base.js b/ui (gen4)/features/base.js index 59aac2dd..d105575d 100755 --- a/ui (gen4)/features/base.js +++ b/ui (gen4)/features/base.js @@ -80,7 +80,6 @@ function(attr, states, callback){ /*********************************************************************/ // XXX split this into read and write actions... -// XXX check if align by position is relevant here... var BaseActions = module.BaseActions = actions.Actions({ @@ -239,12 +238,7 @@ actions.Actions({ function(mode){ var res = {} for(var k in this){ - // dump the base crop state... - if(k == 'data' && this.crop_stack && this.crop_stack.length > 0){ - res[k] = this.crop_stack[0].dumpJSON() - - // dump current state... - } else if(this[k] != null && this[k].dumpJSON != null){ + if(this[k] != null && this[k].dumpJSON != null){ res[k] = this[k].dumpJSON() } } @@ -551,8 +545,25 @@ actions.Actions({ function(target){ this.images && this.images.flipImage(this.data.getImage(target), 'horizontal') }], +}) +var Base = +module.Base = core.ImageGridFeatures.Feature({ + title: 'ImageGrid base', + + tag: 'base', + + actions: BaseActions, +}) + + + +//--------------------------------------------------------------------- +// Tags... + +var TagsActions = +module.TagsActions = actions.Actions({ // tags... // // XXX mark updated... @@ -651,8 +662,68 @@ actions.Actions({ this.data.tagsFromImages(images, mode) } }], +}) +var Tags = +module.Tags = core.ImageGridFeatures.Feature({ + title: '', + + tag: 'tags', + depends: [ + 'base', + ], + + actions: TagsActions, +}) + + + +//--------------------------------------------------------------------- +// Crop... + +var CropActions = +module.CropActions = actions.Actions({ + + crop_stack: null, + + // load the crop stack if present... + load: [function(data){ + if(data.crop_stack){ + this.crop_stack = data.crop_stack.map(function(j){ + return data.Data(j) + }) + } + }], + + // store the root crop state instead of the current view... + // + // modes supported: + // - current - store the current state/view + // - base - store the base state/view + // - full - store the crop stack + // + // XXX might need to revise the mode approach... + // XXX add support to loading the states... + json: [function(mode){ + mode = mode || 'current' + + return function(res){ + if(mode == 'base' + && this.crop_stack + && this.crop_stack.length > 0){ + res.data = this.crop_stack[0].dumpJSON() + } + if(mode == 'full' + && this.crop_stack + && this.crop_stack.length > 0){ + res.crop_stack = this.crop_stack.map(function(c){ + return c.dumpJSON() + }) + } + } + }], + // crop... // crop: ['- Crop/Crop image list', @@ -762,8 +833,28 @@ actions.Actions({ var selector = mode == 'any' ? 'getTaggedByAny' : 'getTaggedByAll' this.crop(this.data[selector](tags), flatten) }], +}) +var Crop = +module.Crop = core.ImageGridFeatures.Feature({ + title: '', + + tag: 'crop', + depends: [ + 'base', + ], + + actions: CropActions, +}) + + + +//--------------------------------------------------------------------- +// Image Group... + +var ImageGroupActions = +module.ImageGroupActions = actions.Actions({ // grouping... // XXX need to tell .images about this... group: ['- Group|Edit/Group images', @@ -813,17 +904,32 @@ actions.Actions({ }) -var Base = -module.Base = core.ImageGridFeatures.Feature({ - title: 'ImageGrid base', +var ImageGroup = +module.ImageGroup = core.ImageGridFeatures.Feature({ + title: '', - tag: 'base', + tag: 'image-group', + depends: [ + 'base', + ], - actions: BaseActions, + actions: ImageGroupActions, }) +//--------------------------------------------------------------------- +// Meta base features... + +// full features base... +core.ImageGridFeatures.Feature('base-full', [ + 'base', + 'tags', + 'crop', + 'image-group', +]) + + /********************************************************************** * vim:set ts=4 sw=4 : */ diff --git a/ui (gen4)/features/meta.js b/ui (gen4)/features/meta.js index cb570ecd..01148c3c 100755 --- a/ui (gen4)/features/meta.js +++ b/ui (gen4)/features/meta.js @@ -27,7 +27,7 @@ var core = require('features/core') core.ImageGridFeatures.Feature('viewer-testing', [ 'lifecycle', - 'base', + 'base-full', 'ui', // features... diff --git a/ui (gen4)/lib/features.js b/ui (gen4)/lib/features.js index aa7f3ce4..7affeeaa 100755 --- a/ui (gen4)/lib/features.js +++ b/ui (gen4)/lib/features.js @@ -101,6 +101,7 @@ module.FeatureProto = { // merge config... // XXX should this use inheritance??? + // XXX do we need to clone .config? if(this.config != null || (this.actions != null && this.actions.config != null)){ @@ -110,12 +111,6 @@ module.FeatureProto = { actions.config = {} } Object.keys(config).forEach(function(n){ - /* - // keep existing keys... - if(actions.config[n] === undefined){ - actions.config[n] = config[n] - } - */ // NOTE: this will overwrite existing values... actions.config[n] = config[n] })