Commit 1136a97c authored by Tristan Cavelier's avatar Tristan Cavelier

localstorage.js put method now modifies revisions history

parent cc8c320f
...@@ -38,11 +38,11 @@ var newLocalStorage = function ( spec, my ) { ...@@ -38,11 +38,11 @@ var newLocalStorage = function ( spec, my ) {
* @methode generateNextRev * @methode generateNextRev
* @param {string} previous_revision The previous revision * @param {string} previous_revision The previous revision
* @param {string} string String to help generate hash code * @param {string} string String to help generate hash code
* @return {string} The next revision * @return {array} 0:The next revision number and 1:the hash code
*/ */
priv.generateNextRev = function (previous_revision, string) { priv.generateNextRev = function (previous_revision, string) {
return (parseInt(previous_revision.split('-')[0],10)+1) + '-' + return [parseInt(previous_revision.split('-')[0],10)+1,
priv.hashCode(previous_revision + string); priv.hashCode(previous_revision + string)];
}; };
/** /**
...@@ -312,7 +312,7 @@ var newLocalStorage = function ( spec, my ) { ...@@ -312,7 +312,7 @@ var newLocalStorage = function ( spec, my ) {
var now = Date.now(); var now = Date.now();
// wait a little in order to simulate asynchronous saving // wait a little in order to simulate asynchronous saving
setTimeout (function () { setTimeout (function () {
var docid, doc, docpath, attmtid, attmt, attmtpath, prev_rev; var docid, doc, docpath, attmtid, attmt, attmtpath, prev_rev, rev;
docid = command.getDocId(); docid = command.getDocId();
prev_rev = command.getDocInfo('_rev'); prev_rev = command.getDocInfo('_rev');
docpath ='jio/local/'+priv.secured_username+'/'+ docpath ='jio/local/'+priv.secured_username+'/'+
...@@ -360,11 +360,20 @@ var newLocalStorage = function ( spec, my ) { ...@@ -360,11 +360,20 @@ var newLocalStorage = function ( spec, my ) {
// update document metadata // update document metadata
priv.documentObjectUpdate(doc,command.cloneDoc()); priv.documentObjectUpdate(doc,command.cloneDoc());
} }
doc._rev = priv.generateNextRev(prev_rev, ''+doc+' '+now+''); // rev = [number, hash]
rev = priv.generateNextRev(prev_rev, ''+doc+' '+now+'');
doc._rev = rev.join('-');
doc._revisions.ids.unshift(rev[1]);
doc._revisions.start = rev[0];
doc._revs_info[0].status = 'deleted';
doc._revs_info.unshift({
"rev": rev.join('-'),
"status": "available"
});
localstorage.setItem(docpath, doc); localstorage.setItem(docpath, doc);
that.success ( that.success (
priv.manageOptions( priv.manageOptions(
{ok:true,id:docid,rev:doc._rev}, {"ok":true,"id":docid,"rev":doc._rev},
command, command,
doc doc
) )
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment