cleanup and refactoring...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2017-10-01 15:44:18 +03:00
parent 50b0c4e153
commit dd0b7f0842
3 changed files with 45 additions and 13 deletions

View File

@ -1106,25 +1106,36 @@ module.Collection = core.ImageGridFeatures.Feature({
// XXX might be a good idea to replace 'full' with changes to // XXX might be a good idea to replace 'full' with changes to
// override .changes... // override .changes...
// XXX need to account for collection local .changes... // XXX need to account for collection local .changes...
// XXX might be a good idea to build local changes in 'prepareIndexForWrite.pre'...
// ...or build and include .changes in .json(..)
['prepareIndexForWrite', ['prepareIndexForWrite',
function(res, _, full){ function(res){
var that = this var that = this
var changed = full == true var changed = res.changes === true
|| res.changes === true
|| res.changes.collections || res.changes.collections
var collections = this.collections var collections = this.collections
if(changed && res.raw.collections){ // collections partially changed...
var partial = Object.keys(this.collections)
.filter(function(t){
return res.changes['collection: '
+ JSON.stringify(collections[t].gid)] })
if((partial.length > 0 || changed)
&& res.raw.collections){
// select the actual changed collection list... // select the actual changed collection list...
changed = changed === true ? changed = changed === true ?
Object.keys(res.raw.collections) Object.keys(res.raw.collections)
: changed : changed
changed = (changed || []).concat(partial)
// collection index... // collection index...
// //
// NOTE: we are placing this in the index root to // NOTE: we are placing this in the index root to
// simplify lazy-loading of the collection // simplify lazy-loading of the collection
// index... // index...
// XXX save this only if index has changed...
// ...need 'collection-index' in changes...
// XXX need lazy-load handler in fs-loader for this... // XXX need lazy-load handler in fs-loader for this...
// XXX don't like the name... // XXX don't like the name...
var index = res.index['collection-index'] = {} var index = res.index['collection-index'] = {}
@ -1134,12 +1145,24 @@ module.Collection = core.ImageGridFeatures.Feature({
changed changed
// skip the raw field... // skip the raw field...
.filter(function(k){ return changed.indexOf(k) >= 0 }) .filter(function(k){
return res.raw.collections[k]
&& changed.indexOf(k) >= 0 })
.forEach(function(k){ .forEach(function(k){
var gid = res.raw.collections[k].gid || k var gid = res.raw.collections[k].gid || k
var path = 'collections/'+ gid var path = 'collections/'+ gid
var raw = res.raw.collections[k] var raw = res.raw.collections[k]
// local collection changes...
// XXX local changes are not processed correctly
// when the target collection is loaded...
// XXX revise the local changes format...
var local_changes = partial.indexOf(k) < 0 || {}
if(local_changes !== true){
(res.changes['collection: '+ JSON.stringify(gid)] || [])
.forEach(function(c){ local_changes[c] = true })
}
// collections/<gid>/metadata // collections/<gid>/metadata
var metadata = res.index[path +'/metadata'] = {} var metadata = res.index[path +'/metadata'] = {}
Object.keys(raw) Object.keys(raw)
@ -1149,8 +1172,11 @@ module.Collection = core.ImageGridFeatures.Feature({
// XXX use collection changes!!! // XXX use collection changes!!!
// ...this will need .prepareIndexForWrite(..) // ...this will need .prepareIndexForWrite(..)
// refactoring to replace 'full' with 'changed'... // refactoring to replace 'full' with 'changed'...
var prepared = that.prepareIndexForWrite(raw, true).index //var prepared = that.prepareIndexForWrite(raw, true).index
var prepared = that.prepareIndexForWrite(raw, local_changes).index
// move the collection data to collection path...
// XXX do we need to cleanup metadata???
Object.keys(prepared) Object.keys(prepared)
.forEach(function(key){ .forEach(function(key){
res.index[path +'/'+ key] = prepared[key] res.index[path +'/'+ key] = prepared[key]
@ -1418,7 +1444,7 @@ module.CollectionTags = core.ImageGridFeatures.Feature({
// XXX would be nice to be able to reuse the base functionality // XXX would be nice to be able to reuse the base functionality
// here... // here...
['prepareIndexForWrite', ['prepareIndexForWrite',
function(res, _, full){ function(res){
var raw = res.raw.collections || {} var raw = res.raw.collections || {}
// NOTE: we are cheating here, we do not need to check // NOTE: we are cheating here, we do not need to check

View File

@ -88,9 +88,9 @@ var IndexFormatActions = actions.Actions({
.prepareIndexForWrite(json) .prepareIndexForWrite(json)
-> data -> data
Prepare a full state (current/specific)... Prepare a state overwriting changes...
.prepareIndexForWrite(null, true) .prepareIndexForWrite(null, changes)
.prepareIndexForWrite(json, true) .prepareIndexForWrite(json, changes)
-> data -> data
NOTE: this will disregard .changes NOTE: this will disregard .changes
@ -149,9 +149,9 @@ var IndexFormatActions = actions.Actions({
<timestamp> - as returned by Date.timeStamp() (see: jli) <timestamp> - as returned by Date.timeStamp() (see: jli)
`, `,
function(json, full){ function(json, changes){
json = json || this.json('base') json = json || this.json('base')
var changes = full ? null changes = changes !== undefined ? changes
: this.hasOwnProperty('changes') ? this.changes : this.hasOwnProperty('changes') ? this.changes
: null : null
changes = changes === null ? true : changes changes = changes === null ? true : changes
@ -1060,7 +1060,7 @@ module.Comments = core.ImageGridFeatures.Feature({
// need to do anything special to restore, i.e. no need for // need to do anything special to restore, i.e. no need for
// doing anything on .prepareJSONForLoad(..) // doing anything on .prepareJSONForLoad(..)
['prepareIndexForWrite', ['prepareIndexForWrite',
function(res, _, full){ function(res){
var changed = res.changes === true var changed = res.changes === true
|| res.changes.comments || res.changes.comments

View File

@ -50,6 +50,12 @@ core.ImageGridFeatures.Feature('viewer-testing', [
'viewer-commandline', 'viewer-commandline',
'viewer-minimal', 'viewer-minimal',
// NOTE: this is not strictly needed unless we need to save stuff,
// added here mostly for testing purposes...
// ...this is best included by direct feature dependency.
'index-format',
'collections', 'collections',
// XXX remove when done testing... // XXX remove when done testing...