Commit 4880ef9e authored by Tristan Cavelier's avatar Tristan Cavelier Committed by Sebastien Robin

improve replicate storage get list + change officejs storage + grunt ok

parent da79424c
......@@ -40,8 +40,9 @@
<div class="controls docs-input-sizes">
<input class="input-xlarge"
type="text" name="JSONstorage" id="input_json_storage"
value="{&quot;type&quot;:&quot;local&quot;,&quot;userName&quot;:&quot;tristan&quot;}"
value="{&quot;type&quot;:&quot;replicate&quot;,&quot;storageArray&quot;:[{&quot;type&quot;:&quot;local&quot;,&quot;userName&quot;:&quot;tristan&quot;},{&quot;type&quot;:&quot;dav&quot;,&quot;userName&quot;:&quot;tristan&quot;,&quot;password&quot;:&quot;mdp&quot;,&quot;location&quot;:&quot;http://localhost:80&quot;}]}"
placeholder="storage" />
<!-- value="{&quot;type&quot;:&quot;local&quot;,&quot;userName&quot;:&quot;tristan&quot;}" -->
</div>
<label class="control-label"
for="JSONapplicantID">
......
......@@ -10,7 +10,7 @@ require.config ({
JIO: '../src/jio',
Base64API: '../lib/base64/base64',
Base64: '../js/base64.requirejs_module',
JIOStorages: '../lib/jio/jio.storage.min',
JIOStorages: '../src/jio.storage',
OfficeJS: 'moduleloader'
}
......
/*! JIO - v0.1.0 - 2012-05-18
/*! JIO - v0.1.0 - 2012-05-21
* Copyright (c) 2012 Nexedi; Licensed */
......@@ -261,10 +261,7 @@ var JIO =
// options.jioID : the jio ID
var k, emptyfun = function (){},
jioIdArray = jioGlobalObj.localStorage.getItem (jioIdArrayName);
if (jioIdArray === null) {
jioIdArray = [];
}
jioIdArray = jioGlobalObj.localStorage.getItem (jioIdArrayName)||[];
if (options.publisher) {
priv.publisher = publisher;
}
......@@ -292,8 +289,8 @@ var JIO =
// Returns a new queueID
var k = null, id = 0,
jioIdArray = jioGlobalObj.localStorage.getItem (jioIdArrayName);
for (k in jioIdArray) {
jioIdArray = jioGlobalObj.localStorage.getItem (jioIdArrayName)||[];
for (k = 0; k < jioIdArray.length; k += 1) {
if (jioIdArray[k] >= jioGlobalObj.queueID) {
jioGlobalObj.queueID = jioIdArray[k] + 1;
}
......@@ -306,8 +303,8 @@ var JIO =
// recover job object from older inactive jio
var k = null, newJioIdArray = [], jioIdArrayChanged = false,
jioIdArray = jioGlobalObj.localStorage.getItem (jioIdArrayName);
for (k in jioIdArray) {
jioIdArray = jioGlobalObj.localStorage.getItem (jioIdArrayName)||[];
for (k = 0; k < jioIdArray.length; k += 1) {
if (jioGlobalObj.localStorage.getItem (
'jio/id/'+jioIdArray[k]) < Date.now () - 10000) {
// remove id from jioIdArray
......@@ -408,7 +405,7 @@ var JIO =
if (res.newone) {
// if it is a new job, we can eliminate deprecated jobs and
// set this job dependencies.
for (id in res.elimArray) {
for (id = 0; id < res.elimArray.length; id += 1) {
basestorage = new BaseStorage(
{'queue':that,'job':priv.jobObject[res.elimArray[id]]});
basestorage.eliminate();
......@@ -416,13 +413,13 @@ var JIO =
if (res.waitArray.length > 0) {
job.status = 'wait';
job.waitingFor = {'jobIdArray':res.waitArray};
for (id in res.waitArray) {
for (id = 0; id < res.waitArray.length; id += 1) {
if (priv.jobObject[res.waitArray[id]]) {
priv.jobObject[res.waitArray[id]].maxtries = 1;
}
}
}
for (id in res.removeArray) {
for (id = 0; id < res.removeArray.length; id += 1) {
that.removeJob(priv.jobObject[res.removeArray[id]]);
}
// set job id
......@@ -484,7 +481,7 @@ var JIO =
that.invokeAll = function () {
// Do all jobs in the queue.
var i = 'id', ok;
var i = 'id', j, ok;
//// do All jobs
for (i in priv.jobObject) {
ok = false;
......@@ -498,7 +495,9 @@ var JIO =
if (priv.jobObject[i].waitingFor.jobIdArray) {
// wait job
// browsing job id array
for (var j in priv.jobObject[i].waitingFor.jobIdArray) {
for (j = 0;
j < priv.jobObject[i].waitingFor.jobIdArray.length;
j += 1) {
if (priv.jobObject[priv.jobObject[i].
waitingFor.jobIdArray[j]]) {
// if a job is still exist, don't invoke
......@@ -746,7 +745,7 @@ var JIO =
var i;
priv.res.message = 'Document list received.';
priv.res.list = documentlist;
for (i in priv.res.list) {
for (i = 0; i < priv.res.list.length; i += 1) {
priv.res.list[i].lastModified =
new Date(priv.res.list[i].lastModified).getTime();
priv.res.list[i].creationDate =
......
This diff is collapsed.
/*! JIO Storage - v0.1.0 - 2012-05-18
/*! JIO Storage - v0.1.0 - 2012-05-21
* Copyright (c) 2012 Nexedi; Licensed */
......@@ -45,11 +45,11 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// wait a little in order to simulate asynchronous operation
setTimeout(function () {
var localStorageObject = null;
var localStorageObject = null, k, splitk;
localStorageObject = LocalOrCookieStorage.getAll();
for (var k in localStorageObject) {
var splitk = k.split('/');
for (k in localStorageObject) {
splitk = k.split('/');
if (splitk[0] === 'jio' &&
splitk[1] === 'local' &&
splitk[2] === that.getUserName()) {
......@@ -525,7 +525,7 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
}
};
for (i in priv.storageArray) {
for (i = 0; i < priv.storageArray.length; i += 1) {
newjob = that.cloneJob();
newjob.maxtries = priv.maxtries;
newjob.storage = priv.storageArray[i];
......@@ -560,7 +560,7 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
}
};
for (i in priv.storageArray) {
for (i = 0; i < priv.storageArray.length; i += 1) {
newjob = that.cloneJob();
newjob.maxtries = priv.maxtries;
newjob.storage = priv.storageArray[i];
......@@ -633,7 +633,7 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
}
};
for (i in priv.storageArray) {
for (i = 0; i < priv.storageArray.length; i += 1) {
newjob = that.cloneJob();
newjob.maxtries = priv.maxtries;
newjob.storage = priv.storageArray[i];
......@@ -655,23 +655,23 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// 'lastModified':date,'creationDate':date}
// TODO
var newjob = {}, res = {'status':'done'}, i = 'id',
var newjob = {}, res = {'status':'done'}, i = 'id', done = false,
callback = function (result) {
priv.returnsValuesArray.push(result);
if (result.status === 'fail') {
res.status = 'fail';
}
if (priv.returnsValuesArray.length === priv.length) {
// if this is the last callback
if (res.status === 'fail') {
that.fail('Unable retrieve all lists.',0);
if (!done) {
if (result.status !== 'fail') {
that.done (result.list);
done = true;
} else {
that.done(result.list);
if (priv.returnsValuesArray.length ===
priv.length) {
that.fail ('Unable to retrieve list.',0);
}
}
}
};
for (i in priv.storageArray) {
for (i = 0; i < priv.storageArray.length; i += 1) {
newjob = that.cloneJob();
newjob.maxtries = priv.maxtries;
newjob.storage = priv.storageArray[i];
......@@ -706,7 +706,7 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
}
};
for (i in priv.storageArray) {
for (i = 0; i < priv.storageArray.length; i += 1) {
newjob = that.cloneJob();
newjob.maxtries = priv.maxtries;
newjob.storage = priv.storageArray[i];
......
This diff is collapsed.
/*! Local Or Cookie Storage - v0.1.0 - 2012-05-18
/*! Local Or Cookie Storage - v0.1.0 - 2012-05-21
* Copyright (c) 2012 Nexedi; Licensed */
var LocalOrCookieStorage =
......@@ -43,10 +43,10 @@ var LocalOrCookieStorage =
};
CookieStorage.prototype = {
getItem: function (name) {
var cookies = document.cookie.split(';');
for (var i in cookies) {
var x = cookies[i].substr(0, cookies[i].indexOf('='));
var y = cookies[i].substr(cookies[i].indexOf('=')+1);
var cookies = document.cookie.split(';'), i;
for (i = 0; i < cookies.length; i += 1) {
var x = cookies[i].substr(0, cookies[i].indexOf('=')),
y = cookies[i].substr(cookies[i].indexOf('=')+1);
x = x.replace(/^\s+|\s+$/g,"");
if( x === name ) { return unescape(y); }
}
......@@ -63,11 +63,11 @@ var LocalOrCookieStorage =
return false;
},
getAll: function() {
var retObject = {};
var cookies = document.cookie.split(':');
for (var i in cookies) {
var x = cookies[i].substr(0, cookies[i].indexOf('='));
var y = cookies[i].substr(cookies[i].indexOf('=')+1);
var retObject = {}, i,
cookies = document.cookie.split(':');
for (i = 0; i < cookies.length; i += 1) {
var x = cookies[i].substr(0, cookies[i].indexOf('=')),
y = cookies[i].substr(cookies[i].indexOf('=')+1);
x = x.replace(/^\s+|\s+$/g,"");
retObject[x] = unescape(y);
}
......
/*! Local Or Cookie Storage - v0.1.0 - 2012-05-18
/*! Local Or Cookie Storage - v0.1.0 - 2012-05-21
* Copyright (c) 2012 Nexedi; Licensed */
var LocalOrCookieStorage=function(){var a=function(){var a=function(){};a.prototype={getItem:function(a){return JSON.parse(localStorage.getItem(a))},setItem:function(a,b){if(a)return localStorage.setItem(a,JSON.stringify(b))},getAll:function(){return localStorage},deleteItem:function(a){a&&delete localStorage[a]}};var b=function(){};b.prototype={getItem:function(a){var b=document.cookie.split(";");for(var c in b){var d=b[c].substr(0,b[c].indexOf("=")),e=b[c].substr(b[c].indexOf("=")+1);d=d.replace(/^\s+|\s+$/g,"");if(d===a)return unescape(e)}return null},setItem:function(a,b){return b!==undefined?(document.cookie=a+"="+JSON.stringify(b)+";domain="+window.location.hostname+";path="+window.location.pathname,!0):!1},getAll:function(){var a={},b=document.cookie.split(":");for(var c in b){var d=b[c].substr(0,b[c].indexOf("=")),e=b[c].substr(b[c].indexOf("=")+1);d=d.replace(/^\s+|\s+$/g,""),a[d]=unescape(e)}return a},deleteItem:function(a){document.cookie=a+"=null;domain="+window.location.hostname+";path="+window.location.pathname+";expires=Thu, 01-Jan-1970 00:00:01 GMT"}};try{return localStorage.getItem?new a:new b}catch(c){return new b}};return window.requirejs?(define("LocalOrCookieStorage",[],a),undefined):a()}();
\ No newline at end of file
var LocalOrCookieStorage=function(){var a=function(){var a=function(){};a.prototype={getItem:function(a){return JSON.parse(localStorage.getItem(a))},setItem:function(a,b){if(a)return localStorage.setItem(a,JSON.stringify(b))},getAll:function(){return localStorage},deleteItem:function(a){a&&delete localStorage[a]}};var b=function(){};b.prototype={getItem:function(a){var b=document.cookie.split(";"),c;for(c=0;c<b.length;c+=1){var d=b[c].substr(0,b[c].indexOf("=")),e=b[c].substr(b[c].indexOf("=")+1);d=d.replace(/^\s+|\s+$/g,"");if(d===a)return unescape(e)}return null},setItem:function(a,b){return b!==undefined?(document.cookie=a+"="+JSON.stringify(b)+";domain="+window.location.hostname+";path="+window.location.pathname,!0):!1},getAll:function(){var a={},b,c=document.cookie.split(":");for(b=0;b<c.length;b+=1){var d=c[b].substr(0,c[b].indexOf("=")),e=c[b].substr(c[b].indexOf("=")+1);d=d.replace(/^\s+|\s+$/g,""),a[d]=unescape(e)}return a},deleteItem:function(a){document.cookie=a+"=null;domain="+window.location.hostname+";path="+window.location.pathname+";expires=Thu, 01-Jan-1970 00:00:01 GMT"}};try{return localStorage.getItem?new a:new b}catch(c){return new b}};return window.requirejs?(define("LocalOrCookieStorage",[],a),undefined):a()}();
\ No newline at end of file
......@@ -652,18 +652,18 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// 'lastModified':date,'creationDate':date}
// TODO
var newjob = {}, res = {'status':'done'}, i = 'id',
var newjob = {}, res = {'status':'done'}, i = 'id', done = false,
callback = function (result) {
priv.returnsValuesArray.push(result);
if (result.status === 'fail') {
res.status = 'fail';
}
if (priv.returnsValuesArray.length === priv.length) {
// if this is the last callback
if (res.status === 'fail') {
that.fail('Unable retrieve all lists.',0);
if (!done) {
if (result.status !== 'fail') {
that.done (result.list);
done = true;
} else {
that.done(result.list);
if (priv.returnsValuesArray.length ===
priv.length) {
that.fail ('Unable to retrieve list.',0);
}
}
}
};
......
......@@ -61,7 +61,7 @@ var LocalOrCookieStorage =
},
getAll: function() {
var retObject = {}, i,
var cookies = document.cookie.split(':');
cookies = document.cookie.split(':');
for (i = 0; i < cookies.length; i += 1) {
var x = cookies[i].substr(0, cookies[i].indexOf('=')),
y = cookies[i].substr(cookies[i].indexOf('=')+1);
......
......@@ -5,12 +5,15 @@
$ = loader.jQuery;
//// clear jio localstorage
for (var k in LocalOrCookieStorage.getAll()) {
var splitk = k.split('/');
if ( splitk[0] === 'jio' ) {
LocalOrCookieStorage.deleteItem(k);
}
}
(function () {
var k, storageObject = LocalOrCookieStorage.getAll();
for (k in storageObject) {
var splitk = k.split('/');
if ( splitk[0] === 'jio' ) {
LocalOrCookieStorage.deleteItem(k);
}
}
}());
//// end clear jio localstorage
//// Tools
......
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