Commit 9e47449b authored by Tristan Cavelier's avatar Tristan Cavelier

Improve DAVStorage and ConflictManagerStorage

Dav can now get content with getDocumentList.
Conflict manager errors are managed better and more explicit.
parent ca3d19d4
...@@ -168,8 +168,23 @@ ...@@ -168,8 +168,23 @@
type:'editor', type:'editor',
path:'component/slickgrid_document_lister.html', path:'component/slickgrid_document_lister.html',
gadget_id:'page-content', gadget_id:'page-content',
interval_id:null,
onload: function () {
if (this.interval_id === null) {
this.interval_id = setInterval (function() {
that.getList(this.update);
}, 5000);
}
},
update: function () { update: function () {
OfficeJS.open({app:'document_lister',force:true}); OfficeJS.open({app:'document_lister',force:true});
},
onunload: function () {
if (this.interval_id !== null) {
clearInterval (this.interval_id);
this.interval_id = null;
}
return true;
} }
}, },
workinprogress: { workinprogress: {
......
/*! JIO Storage - v0.1.0 - 2012-07-24 /*! JIO Storage - v0.1.0 - 2012-07-25
* Copyright (c) 2012 Nexedi; Licensed */ * Copyright (c) 2012 Nexedi; Licensed */
(function(LocalOrCookieStorage, $, Base64, sjcl, hex_sha256, Jio) { (function(LocalOrCookieStorage, $, Base64, sjcl, hex_sha256, Jio) {
...@@ -385,6 +385,35 @@ var newDAVStorage = function ( spec, my ) { ...@@ -385,6 +385,35 @@ var newDAVStorage = function ( spec, my ) {
headers: {'Authorization': 'Basic '+Base64.encode( headers: {'Authorization': 'Basic '+Base64.encode(
priv.username + ':' + priv.password ), Depth: '1'}, priv.username + ':' + priv.password ), Depth: '1'},
success: function (xmlData) { success: function (xmlData) {
var wait_for_me = 0;
var getContent = function (file) {
wait_for_me ++;
$.ajax ( {
url: priv.url + '/dav/' +
priv.username + '/' +
priv.applicationname + '/' +
file.name,
type: "GET",
async: true,
dataType: 'text', // TODO : is it necessary ?
headers: {'Authorization':'Basic '+
Base64.encode(priv.username +':'+
priv.password)},
success: function (content) {
file.content = content;
// WARNING : files can be disordered because
// of asynchronous action
document_array.push (file);
wait_for_me --;
},
error: function (type) {
type.message = 'Cannot get a document '+
'content from DAVStorage.';
that.fail(type);
wait_for_me --;
}
});
};
$(xmlData).find( $(xmlData).find(
'D\\:response, response' 'D\\:response, response'
).each( function(i,data){ ).each( function(i,data){
...@@ -409,10 +438,24 @@ var newDAVStorage = function ( spec, my ) { ...@@ -409,10 +438,24 @@ var newDAVStorage = function ( spec, my ) {
).each(function () { ).each(function () {
file.creation_date = $(this).text(); file.creation_date = $(this).text();
}); });
if (!command.getOption ('metadata_only')) {
getContent(file);
} else {
document_array.push (file); document_array.push (file);
} }
}
}); });
// wait until all getContent are ended, only if needed
var tmpfun = function () {
setTimeout(function() {
if (wait_for_me) {
tmpfun();
} else {
that.done(document_array); that.done(document_array);
}
},200);
};
tmpfun();
}, },
error: function (type) { error: function (type) {
type.message = type.message =
...@@ -1384,10 +1427,16 @@ var newConflictManagerStorage = function ( spec, my ) { ...@@ -1384,10 +1427,16 @@ var newConflictManagerStorage = function ( spec, my ) {
path: command.getPath(), path: command.getPath(),
method: 'saveDocument', method: 'saveDocument',
owner: priv.username, owner: priv.username,
conflict_owner: { conflict_owner1: {
name: command_file_metadata.winner.owner, name: command_file_metadata.winner.owner,
revision: command_file_metadata.winner.revision, revision: command_file_metadata.winner.revision,
hash: command_file_metadata.winner.hash} hash: command_file_metadata.winner.hash
},
conflict_owner2: {
name: priv.username,
revision: 1, // TODO : change it !
hash: local_file_hash
}
}, },
// gen hash // gen hash
conflict_hash = hex_sha256 (JSON.stringify ( conflict_hash = hex_sha256 (JSON.stringify (
...@@ -1624,6 +1673,11 @@ var newConflictManagerStorage = function ( spec, my ) { ...@@ -1624,6 +1673,11 @@ var newConflictManagerStorage = function ( spec, my ) {
cloned_option.onDone = function (result) { cloned_option.onDone = function (result) {
var i; var i;
for (i = 0; i < result.length; i+= 1) { for (i = 0; i < result.length; i+= 1) {
if (typeof result[i].content !== 'string') {
return am.call(o,'fail',[{
status:0, statusText:'Invalid content',
message:'Invalid file content, aborting job.'}]);
}
var splitname = result[i].name.split('.') || []; var splitname = result[i].name.split('.') || [];
var content_object; var content_object;
var doc = {}; var doc = {};
...@@ -1636,11 +1690,15 @@ var newConflictManagerStorage = function ( spec, my ) { ...@@ -1636,11 +1690,15 @@ var newConflictManagerStorage = function ( spec, my ) {
result_list.push(content_object); result_list.push(content_object);
splitname.length --; splitname.length --;
doc.name = splitname.join('.'); doc.name = splitname.join('.');
try {
doc.creation_date = content_object.owner[ doc.creation_date = content_object.owner[
content_object.winner.owner].creation_date; content_object.winner.owner].creation_date;
doc.last_modified = content_object.owner[ doc.last_modified = content_object.owner[
content_object.winner.owner].last_modified; content_object.winner.owner].last_modified;
command_file_metadata_list.push(doc); command_file_metadata_list.push(doc);
} catch (e) {
continue;
}
} }
} }
if (command.getOption('metadata_only')) { if (command.getOption('metadata_only')) {
...@@ -1825,9 +1883,7 @@ var newConflictManagerStorage = function ( spec, my ) { ...@@ -1825,9 +1883,7 @@ var newConflictManagerStorage = function ( spec, my ) {
// browse known conflict list // browse known conflict list
var i,j, done = false, known_conflict_list = var i,j, done = false, known_conflict_list =
command.getOption('known_conflict_list') || []; command.getOption('known_conflict_list') || [];
console.log ('1 ' + JSON.stringify (known_conflict_list));
for (i = 0; i < known_conflict_list.length; i+= 1) { for (i = 0; i < known_conflict_list.length; i+= 1) {
console.log ('2');
// if known conflict // if known conflict
if (known_conflict_list[i].hash === if (known_conflict_list[i].hash ===
conflict_hash) { conflict_hash) {
...@@ -1840,7 +1896,6 @@ var newConflictManagerStorage = function ( spec, my ) { ...@@ -1840,7 +1896,6 @@ var newConflictManagerStorage = function ( spec, my ) {
} }
for (j = 0; j < command_file_metadata.conflict_list.length; for (j = 0; j < command_file_metadata.conflict_list.length;
j+= 1) { j+= 1) {
console.log ('3');
if (known_conflict_list[i].hash === if (known_conflict_list[i].hash ===
command_file_metadata.conflict_list[j].hash) { command_file_metadata.conflict_list[j].hash) {
// if known other conflict // if known other conflict
......
This diff is collapsed.
...@@ -482,6 +482,11 @@ var newConflictManagerStorage = function ( spec, my ) { ...@@ -482,6 +482,11 @@ var newConflictManagerStorage = function ( spec, my ) {
cloned_option.onDone = function (result) { cloned_option.onDone = function (result) {
var i; var i;
for (i = 0; i < result.length; i+= 1) { for (i = 0; i < result.length; i+= 1) {
if (typeof result[i].content !== 'string') {
return am.call(o,'fail',[{
status:0, statusText:'Invalid content',
message:'Invalid file content, aborting job.'}]);
}
var splitname = result[i].name.split('.') || []; var splitname = result[i].name.split('.') || [];
var content_object; var content_object;
var doc = {}; var doc = {};
...@@ -494,11 +499,15 @@ var newConflictManagerStorage = function ( spec, my ) { ...@@ -494,11 +499,15 @@ var newConflictManagerStorage = function ( spec, my ) {
result_list.push(content_object); result_list.push(content_object);
splitname.length --; splitname.length --;
doc.name = splitname.join('.'); doc.name = splitname.join('.');
try {
doc.creation_date = content_object.owner[ doc.creation_date = content_object.owner[
content_object.winner.owner].creation_date; content_object.winner.owner].creation_date;
doc.last_modified = content_object.owner[ doc.last_modified = content_object.owner[
content_object.winner.owner].last_modified; content_object.winner.owner].last_modified;
command_file_metadata_list.push(doc); command_file_metadata_list.push(doc);
} catch (e) {
continue;
}
} }
} }
if (command.getOption('metadata_only')) { if (command.getOption('metadata_only')) {
......
...@@ -152,6 +152,35 @@ var newDAVStorage = function ( spec, my ) { ...@@ -152,6 +152,35 @@ var newDAVStorage = function ( spec, my ) {
headers: {'Authorization': 'Basic '+Base64.encode( headers: {'Authorization': 'Basic '+Base64.encode(
priv.username + ':' + priv.password ), Depth: '1'}, priv.username + ':' + priv.password ), Depth: '1'},
success: function (xmlData) { success: function (xmlData) {
var wait_for_me = 0;
var getContent = function (file) {
wait_for_me ++;
$.ajax ( {
url: priv.url + '/dav/' +
priv.username + '/' +
priv.applicationname + '/' +
file.name,
type: "GET",
async: true,
dataType: 'text', // TODO : is it necessary ?
headers: {'Authorization':'Basic '+
Base64.encode(priv.username +':'+
priv.password)},
success: function (content) {
file.content = content;
// WARNING : files can be disordered because
// of asynchronous action
document_array.push (file);
wait_for_me --;
},
error: function (type) {
type.message = 'Cannot get a document '+
'content from DAVStorage.';
that.fail(type);
wait_for_me --;
}
});
};
$(xmlData).find( $(xmlData).find(
'D\\:response, response' 'D\\:response, response'
).each( function(i,data){ ).each( function(i,data){
...@@ -176,10 +205,24 @@ var newDAVStorage = function ( spec, my ) { ...@@ -176,10 +205,24 @@ var newDAVStorage = function ( spec, my ) {
).each(function () { ).each(function () {
file.creation_date = $(this).text(); file.creation_date = $(this).text();
}); });
if (!command.getOption ('metadata_only')) {
getContent(file);
} else {
document_array.push (file); document_array.push (file);
} }
}
}); });
// wait until all getContent are ended, only if needed
var tmpfun = function () {
setTimeout(function() {
if (wait_for_me) {
tmpfun();
} else {
that.done(document_array); that.done(document_array);
}
},200);
};
tmpfun();
}, },
error: function (type) { error: function (type) {
type.message = type.message =
......
...@@ -703,6 +703,7 @@ test ('Get Document List', function () { ...@@ -703,6 +703,7 @@ test ('Get Document List', function () {
url:'https://ca-davstorage:8080', url:'https://ca-davstorage:8080',
applicationname:'jiotests'}); applicationname:'jiotests'});
o.mytest('fail to get list',undefined,404); o.mytest('fail to get list',undefined,404);
// FIXME : setTimeout does not pass !??
o.mytest('getting list',[{name:'file',creation_date:1335962911000, o.mytest('getting list',[{name:'file',creation_date:1335962911000,
last_modified:1335962907000}, last_modified:1335962907000},
{name:'memo',creation_date:1335894073000, {name:'memo',creation_date:1335894073000,
......
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