Commit ade981ac authored by Tristan Cavelier's avatar Tristan Cavelier

Updating and Improving conflict solver

parent 5cc60ab5
<div id="basic_conflict_solver_div" style="text-align:center;"> <div id="basic_conflict_solver_div" style="text-align:center;" class="well">
<div class="row-fluid"> <div class="row-fluid">
<div class="span12"> <div class="span12">
A conflict occured while saving this document: A conflict occured while saving this document:
</div> </div>
</div> </div>
<div class="row-fluid"> <div id="revisions">
<div class="span6">
<div>
<strong>local revision</strong>
</div>
<div>
<textarea id="local_revision" style="width:100%;">loading...</textarea>
</div>
<div>
<button onclick="window.basic_conflict_solver.keepLocalRevision();">
keep this revision
</button>
</div>
</div>
<div class="span6">
<div>
<strong>conflicting revision</strong>
</div>
<div>
<textarea id="conflicting_revision" style="width:100%;">loading...</textarea>
</div>
<div>
<button onclick="window.basic_conflict_solver.keepOtherRevision();">
keep this revision
</button>
</div>
</div>
</div> </div>
<div class="row-fluid"> <div class="row-fluid">
<div class="span12"> <div class="span12">
...@@ -43,21 +17,34 @@ ...@@ -43,21 +17,34 @@
window.basic_conflict_solver = { window.basic_conflict_solver = {
conflict_object:{}, conflict_object:{},
keepLocalRevision: function () { addRevision: function (revision,content) {
// TODO : keep local document.querySelector ('#basic_conflict_solver_div #revisions').
OfficeJS.solveConflict( innerHTML += '<div class="row-fluid"><div class="span12">'+
this.conflict_object, '<div><textarea id="'+revision+'">'+content+'</textarea></div>'+
document.querySelector('#basic_conflict_solver_div '+ '<div><button onclick="console.log('+"'"+revision+"'"+');'+
'#local_revision').textContent); 'basic_conflict_solver.keepRevision('+"'"+revision+"'"+');'+
delete window.basic_conflict_solver; '">Save this one</button></div><hr/>'+
// window.basic_conflict_solver.keepRevision('+
// '<div><button onclick="alert('+"'"+'cobra'+"'"+');'+
// "'"+revision+"'"+'); alert("after"); return false;">Save this one</button></div><hr/>'+
'</div></div>';
},
addRemovedRevision: function (revision) {
document.querySelector ('#basic_conflict_solver_div #revisions').
innerHTML += '<div class="row-fluid"><div class="span12">'+
'<div>Removed</div>'+
'<div><button onclick="window.basic_conflict_solver.keepRevision('+
"'"+revision+"'"+'); return false;">Save this one</button></div><hr/>'+
'</div></div>';
}, },
keepOtherRevision: function () { keepRevision: function (revision) {
// TODO : keep other
OfficeJS.solveConflict( OfficeJS.solveConflict(
this.conflict_object, this.conflict_object,
document.querySelector('#basic_conflict_solver_div '+ $('#'+revision).text()
'#local_revision').textContent); );
delete window.basic_conflict_solver; },
abort: function () {
// TODO :
} }
}; };
......
...@@ -42,7 +42,8 @@ ...@@ -42,7 +42,8 @@
<script type="text/javascript"> <script type="text/javascript">
<!-- <!--
(function () { window.OfficeJS_slickgrid = {};
window.OfficeJS_slickgrid.reload = function () {
var grid, onSortFunction, onClickFunction, check_box_selector, var grid, onSortFunction, onClickFunction, check_box_selector,
onRemoveSeveral, showIconFormatter, onRemoveSeveral, showIconFormatter,
document_list = OfficeJS.cloneCurrentDocumentList(), document_list = OfficeJS.cloneCurrentDocumentList(),
...@@ -156,7 +157,8 @@ ...@@ -156,7 +157,8 @@
grid.onClick.subscribe(onClickFunction); grid.onClick.subscribe(onClickFunction);
grid.onSort.subscribe(onSortFunction); grid.onSort.subscribe(onSortFunction);
}); });
}()); };
window.OfficeJS_slickgrid.reload();
//--> //-->
</script> </script>
</body> </body>
......
...@@ -178,12 +178,14 @@ ...@@ -178,12 +178,14 @@
}, },
update: function () { update: function () {
OfficeJS.open({app:'document_lister',force:true}); OfficeJS.open({app:'document_lister',force:true});
//window.OfficeJS_slickgrid.reload();
}, },
onunload: function () { onunload: function () {
if (this.interval_id !== null) { if (this.interval_id !== null) {
clearInterval (this.interval_id); clearInterval (this.interval_id);
this.interval_id = null; this.interval_id = null;
} }
delete window.OfficeJS_slickgrid;
return true; return true;
} }
}, },
...@@ -203,6 +205,7 @@ ...@@ -203,6 +205,7 @@
}, },
onunload: function () { onunload: function () {
window.work_in_progress.stop(); window.work_in_progress.stop();
delete window.work_in_progress;
return true; return true;
} }
}, },
...@@ -211,28 +214,46 @@ ...@@ -211,28 +214,46 @@
path:'component/basic_conflict_solver.html', path:'component/basic_conflict_solver.html',
gadget_id:'page-conflict', gadget_id:'page-conflict',
onload: function (param) { onload: function (param) {
var rev_list = [], i;
for (var rev in param.conflict_object.revision_object) {
rev_list.push(rev);
}
// FIXME : load jobs are in conflict ! redesign jio !
var load = function (rev,i) {
if (rev) {
i++;
setTimeout(function() {
priv.jio.loadDocument( priv.jio.loadDocument(
param.name, param.conflict_object.path,{
{max_retry:3, revision: rev,
onResponse:function (result) { max_retry:3,
if (!result.status.isDone()) { success: function (result) {
console.error (result.error.message); window.basic_conflict_solver.
conflict_object =
param.conflict_object;
window.basic_conflict_solver.
addRevision(
rev,result.content);
load(rev_list[i],i);
},
error: function (error) {
window.basic_conflict_solver.
conflict_object =
param.conflict_object;
if (error.status === 404) {
window.basic_conflict_solver.
addRemovedRevision(rev);
} else { } else {
document.querySelector ( console.error (error.message);
'#basic_conflict_solver_div ' +
'#conflicting_revision ').textContent =
result.value.content;
} }
}}); load(rev_list[i],i);
// TODO : add owner, revision, ... }
setTimeout(function() { });
window.basic_conflict_solver.conflict_object = });
param.conflict_object; }
document.querySelector ( };
'#basic_conflict_solver_div ' + '#local_revision '). load (rev_list[0],0);
textContent = // NOTE : improve, don't load already loaded revision
param.local_content;
},500);
} }
} }
}; };
...@@ -257,7 +278,8 @@ ...@@ -257,7 +278,8 @@
currentEditor:null, currentEditor:null,
currentSolver:null, currentSolver:null,
currentApp:null, currentApp:null,
currentActivity:null currentActivity:null,
currentRevision:null
}; };
priv.loading_object = { priv.loading_object = {
spinstate: 0, spinstate: 0,
...@@ -448,9 +470,8 @@ ...@@ -448,9 +470,8 @@
/** /**
* @method setJio * @method setJio
* @param {object} storage The storage informations * @param {object} storage The storage informations
* @param {object} applicant The applicant informations
*/ */
that.setJio = function (storage,applicant) { that.setJio = function (storage) {
var leftnavbar; var leftnavbar;
if (priv.isJioSet()) { if (priv.isJioSet()) {
alert ('Jio already set.'); alert ('Jio already set.');
...@@ -479,21 +500,25 @@ ...@@ -479,21 +500,25 @@
} }
priv.loading_object.getlist(); priv.loading_object.getlist();
priv.jio.getDocumentList( priv.jio.getDocumentList(
'.', '.',{
{sort:{last_modified:'descending', sort:{last_modified:'descending',
name:'ascending'}, name:'ascending'},
limit:{begin:0,end:50}, limit:{begin:0,end:50},
// search:{name:'a'}, // search:{name:'a'},
max_retry:3, max_retry:3,
onResponse:function (result) { success: function (result) {
if (result.status.isDone()) { priv.data_object.documentList = result;
priv.data_object.documentList = result.value;
priv.showDocumentListInsideLeftNavBar(); priv.showDocumentListInsideLeftNavBar();
} else { priv.loading_object.end_getlist();
// TODO : announce conflicts
if (typeof callback === 'function') {
callback();
}
},
error: function (error) {
priv.lastfailure.path = '.'; priv.lastfailure.path = '.';
priv.lastfailure.method = 'getDocumentList'; priv.lastfailure.method = 'getDocumentList';
console.error (result.error.message); console.error (error.message);
}
priv.loading_object.end_getlist(); priv.loading_object.end_getlist();
if (typeof callback === 'function') { if (typeof callback === 'function') {
callback(); callback();
...@@ -522,23 +547,27 @@ ...@@ -522,23 +547,27 @@
priv.loading_object.save(); priv.loading_object.save();
priv.jio.saveDocument( priv.jio.saveDocument(
basename+'.'+current_editor.ext, basename+'.'+current_editor.ext,
current_content, current_content,{
{onResponse:function (result) { previous_revision: priv.data_object.currentRevision || '0',
if (!result.status.isDone()) { success: function (result) {
priv.lastfailure.path = basename; if (result) {
priv.lastfailure.method = 'saveDocument'; priv.data_object.currentRevision = result;
console.error (result.error.message);
} }
priv.loading_object.end_save(); priv.loading_object.end_save();
that.getList(); that.getList();
}, },
onConflict:function (conflict_object) { error: function (error) {
priv.onConflict ({name:basename, priv.lastfailure.path = basename;
content:current_content}, priv.lastfailure.method = 'saveDocument';
current_editor.ext, console.error (error.message);
conflict_object); priv.loading_object.end_save();
that.getList();
if (error.conflict_object) {
priv.onConflict (error.conflict_object);
// TODO : same for remove method // TODO : same for remove method
}}); }
}
});
}; };
/** /**
...@@ -554,19 +583,25 @@ ...@@ -554,19 +583,25 @@
} }
priv.loading_object.load(); priv.loading_object.load();
priv.jio.loadDocument( priv.jio.loadDocument(
basename+'.'+current_editor.ext, basename+'.'+current_editor.ext,{
{max_retry:3, max_retry:3,
onResponse:function (result) { success: function (result) {
if (!result.status.isDone()) { if (result.revision) {
console.error (result.error.message); priv.data_object.currentRevision = result.revision;
if (result.conflict_object) {
priv.onConflict(result.conflict_object);
}
}
current_editor.setContent(result.content);
priv.loading_object.end_load();
},
error: function (error) {
priv.lastfailure.path = basename; priv.lastfailure.path = basename;
priv.lastfailure.method = 'loadDocument'; priv.lastfailure.method = 'loadDocument';
} else { console.error (error.message);
current_editor.setContent(
result.value.content);
}
priv.loading_object.end_load(); priv.loading_object.end_load();
}}); }
});
}; };
/** /**
...@@ -574,23 +609,31 @@ ...@@ -574,23 +609,31 @@
* @method remove * @method remove
* @param {string} name The document name. * @param {string} name The document name.
*/ */
that.remove = function (name) { that.remove = function (name,revision) {
if (!priv.isJioSet()) { if (!priv.isJioSet()) {
console.error ('No Jio set yet.'); console.error ('No Jio set yet.');
return; return;
} }
priv.loading_object.remove(); priv.loading_object.remove();
priv.jio.removeDocument( priv.jio.removeDocument(
name, name,{
{onResponse:function (result) { revision: revision,
if (!result.status.isDone()) { success: function (result) {
console.error (result.error.message); priv.loading_object.end_remove();
that.getList();
},
error: function (error) {
priv.lastfailure.path = name; priv.lastfailure.path = name;
priv.lastfailure.method = 'removeDocument'; priv.lastfailure.method = 'removeDocument';
} console.error (error.message);
priv.loading_object.end_remove(); priv.loading_object.end_remove();
that.getList(); that.getList();
}}); if (error.conflict_object) {
priv.onConflict (error.conflict_object);
// TODO : same for remove method
}
}
});
}; };
/** /**
...@@ -632,49 +675,45 @@ ...@@ -632,49 +675,45 @@
* @param {object} doc The document object * @param {object} doc The document object
* @param {object} conflict_object The conflict object * @param {object} conflict_object The conflict object
*/ */
priv.onConflict = function (document, ext, conflict_object) { priv.onConflict = function (conflict_object) {
ext = ext || '';
// TODO : load other revision
// get the good conflict solver and load it // get the good conflict solver and load it
if (ext && priv.conflict_solver_object[ext]) { // if (ext && priv.conflict_solver_object[ext]) {
that.open({app:priv.conflict_solver_object[ext], // that.open({app:priv.conflict_solver_object[ext],
name:conflict_object.path, // // local_content:document.content,
local_content:document.content, // conflict_object:conflict_object});
conflict_object:conflict_object}); // } else {
} else {
that.open({app:'basic_conflict_solver', that.open({app:'basic_conflict_solver',
name:conflict_object.path, // local_content:document.content,
local_content:document.content,
conflict_object:conflict_object}); conflict_object:conflict_object});
} // }
}; };
that.solveConflict = function (conflict_object, data) { that.solveConflict = function (conflict_object, data) {
var current_solver = priv.data_object.currentSolver; // TODO : that.close basic_solver
priv.data_object.currentEditor.setContent(data);
priv.loading_object.save(); priv.loading_object.save();
priv.jio.saveDocument( conflict_object.solveConflict(
conflict_object.path, data,{
data, success: function (result) {
{onResponse:function (result) { if (result) {
if (!result.status.isDone()) { priv.data_object.currentRevision = result;
priv.lastfailure.path = basename(path);
priv.lastfailure.method = 'saveDocument';
console.error (result.error.message);
} }
priv.loading_object.end_save(); priv.loading_object.end_save();
that.getList(); that.getList();
document.querySelector ('#basic_conflict_solver_div').
style.display = 'none';
priv.data_object.currentSolver = null;
},
onConflict:function (conflict_object) {
priv.onConflict ({name:basename,
content:current_content},
current_editor.ext,
conflict_object);
}, },
known_conflict_list:[conflict_object]}); error: function (error) {
priv.lastfailure.path = basename;
priv.lastfailure.method = 'saveDocument';
console.error (error.message);
priv.loading_object.end_save();
that.getList();
if (error.conflict_object) {
priv.onConflict (error.conflict_object);
// TODO : same for remove method
}
}
});
}; };
/** /**
......
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