Commit f1a032a0 authored by Tristan Cavelier's avatar Tristan Cavelier

postToDocumentTree from revisionstorage.js updated

parent 770d537c
...@@ -208,15 +208,15 @@ jIO.addStorageType('revision', function (spec, my) { ...@@ -208,15 +208,15 @@ jIO.addStorageType('revision', function (spec, my) {
* @method postToDocumentTree * @method postToDocumentTree
* @param {object} doctree The document tree object * @param {object} doctree The document tree object
* @param {object} doc The document object * @param {object} doc The document object
* @param {boolean} set_node_to_deleted true/false * @param {boolean} set_node_to_deleted Set the revision to deleted
* @return {array} The added document revs_info * @return {array} The added document revs_info
*/ */
priv.postToDocumentTree = function (doctree, doc, set_node_to_deleted) { priv.postToDocumentTree = function (doctree, doc, set_node_to_deleted) {
var i, revs_info, next_rev, next_rev_str, next_rev_status, var i, revs_info, next_rev, next_rev_str, selectNode, selected_node,
selectNode, selected_node, flag;
revs_info = [], flag = set_node_to_deleted === true ? "deleted" : "available";
revs_info = [];
selected_node = doctree; selected_node = doctree;
selectNode = function (node) { selectNode = function (node) {
var i; var i;
if (typeof node.rev !== "undefined") { if (typeof node.rev !== "undefined") {
...@@ -255,28 +255,26 @@ jIO.addStorageType('revision', function (spec, my) { ...@@ -255,28 +255,26 @@ jIO.addStorageType('revision', function (spec, my) {
doc._rev || 0, doc, priv.revsInfoToHistory(revs_info), doc._rev || 0, doc, priv.revsInfoToHistory(revs_info),
set_node_to_deleted); set_node_to_deleted);
next_rev_str = next_rev.join("-"); next_rev_str = next_rev.join("-");
next_rev_status = set_node_to_deleted === true ? "deleted" : "available";
// don't add if the next rev already exists // don't add if the next rev already exists
for (i = 0; i < selected_node.children.length; i += 1) { for (i = 0; i < selected_node.children.length; i += 1) {
if (selected_node.children[i].rev === next_rev_str) { if (selected_node.children[i].rev === next_rev_str) {
revs_info.unshift({ revs_info.unshift({
"rev": next_rev_str, "rev": next_rev_str,
"status": next_rev_status "status": flag
}); });
if (selected_node.children[i].status !== next_rev_status) { if (selected_node.children[i].status !== flag) {
selected_node.children[i].status = next_rev_status; selected_node.children[i].status = flag;
} }
return revs_info; return revs_info;
} }
} }
revs_info.unshift({ revs_info.unshift({
"rev": next_rev.join('-'), "rev": next_rev.join('-'),
"status": "available" "status": flag
}); });
selected_node.children.unshift({ selected_node.children.unshift({
"rev": next_rev.join('-'), "rev": next_rev.join('-'),
"status": "available", "status": flag,
"children": [] "children": []
}); });
return revs_info; return revs_info;
......
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