Commit b0c669ec authored by Tristan Cavelier's avatar Tristan Cavelier Committed by Sebastien Robin

JIO provides now a limit method for jio storages.

If the storage does not limit document list by itself,
JIO will limit it anyway.
The storage should use the method limitDone() to tell to JIO that
the document list is already limited (avoid double limiting).
If the storage can not support limiting, it can also use
limitDocumentArray() provided by JIO (and no need to use limitDone()).
parent 2ec1169b
...@@ -708,6 +708,7 @@ var JIO = ...@@ -708,6 +708,7 @@ var JIO =
priv.queue = options.queue; priv.queue = options.queue;
priv.res = {'status':'done','message':''}; priv.res = {'status':'done','message':''};
priv.sorted = false; priv.sorted = false;
priv.limited = false;
//// end Private attributes //// end Private attributes
//// Private Methods //// Private Methods
...@@ -759,8 +760,15 @@ var JIO = ...@@ -759,8 +760,15 @@ var JIO =
} }
} }
// check for sorting // check for sorting
if (typeof priv.job.sort !== 'undefined' && !priv.sorted) { if (!priv.sorted && typeof priv.job.sort !== 'undefined') {
that.sortDocumentArray(priv.res.return_value); that.sortDocumentArray({documentarray:priv.res.return_value});
}
// check for limiting
if (!priv.limited &&
typeof priv.job.limit !== 'undefined' &&
typeof priv.job.limit.begin !== 'undefined' &&
typeof priv.job.limit.end !== 'undefined') {
that.limitDocumentArray({documentarray:priv.res.return_value});
} }
}; };
priv.fail_removeDocument = function () { priv.fail_removeDocument = function () {
...@@ -925,8 +933,14 @@ var JIO = ...@@ -925,8 +933,14 @@ var JIO =
message:'This method must be redefined!'}); message:'This method must be redefined!'});
}; };
that.sortDocumentArray = function (documentarray) { /**
documentarray.sort(function (row1,row2) { * Sorts a document list using sort parameters set in the job.
* @method sortDocumentArray
* @param {object} o
* - o.documentarray {array} the array we want to sort.
*/
that.sortDocumentArray = function (o) {
o.documentarray.sort(function (row1,row2) {
var k, res; var k, res;
for (k in priv.job.sort) { for (k in priv.job.sort) {
var sign = (priv.job.sort[k] === 'descending' ? -1 : 1); var sign = (priv.job.sort[k] === 'descending' ? -1 : 1);
...@@ -937,10 +951,37 @@ var JIO = ...@@ -937,10 +951,37 @@ var JIO =
}); });
that.sortDone(); that.sortDone();
}; };
/**
* Tells to this storage that the sorting process is already done.
* @method sortDone
*/
that.sortDone = function () { that.sortDone = function () {
priv.sorted = true; priv.sorted = true;
}; };
/**
* Limits the document list. Get only the document between
* @method limitDocumentArray
* @param {object} o
* - o.documentarray {array} the array we wont to limit
* @return {array} The new document list
*/
that.limitDocumentArray = function (o) {
o.documentarray = o.documentarray.slice(priv.job.limit.begin,
priv.job.limit.end);
that.limitDone();
return o.documentarray;
};
/**
* Tells to this storage that the limiting process is already done.
* @method limitDone
*/
that.limitDone = function () {
priv.limited = true;
};
//// end Public Methods //// end Public Methods
return that; return that;
}; };
......
This diff is collapsed.
...@@ -705,6 +705,7 @@ var JIO = ...@@ -705,6 +705,7 @@ var JIO =
priv.queue = options.queue; priv.queue = options.queue;
priv.res = {'status':'done','message':''}; priv.res = {'status':'done','message':''};
priv.sorted = false; priv.sorted = false;
priv.limited = false;
//// end Private attributes //// end Private attributes
//// Private Methods //// Private Methods
...@@ -759,6 +760,13 @@ var JIO = ...@@ -759,6 +760,13 @@ var JIO =
if (!priv.sorted && typeof priv.job.sort !== 'undefined') { if (!priv.sorted && typeof priv.job.sort !== 'undefined') {
that.sortDocumentArray({documentarray:priv.res.return_value}); that.sortDocumentArray({documentarray:priv.res.return_value});
} }
// check for limiting
if (!priv.limited &&
typeof priv.job.limit !== 'undefined' &&
typeof priv.job.limit.begin !== 'undefined' &&
typeof priv.job.limit.end !== 'undefined') {
that.limitDocumentArray({documentarray:priv.res.return_value});
}
}; };
priv.fail_removeDocument = function () { priv.fail_removeDocument = function () {
priv.res.message = 'Unable to removed document.'; priv.res.message = 'Unable to removed document.';
...@@ -949,6 +957,28 @@ var JIO = ...@@ -949,6 +957,28 @@ var JIO =
priv.sorted = true; priv.sorted = true;
}; };
/**
* Limits the document list. Get only the document between
* @method limitDocumentArray
* @param {object} o
* - o.documentarray {array} the array we wont to limit
* @return {array} The new document list
*/
that.limitDocumentArray = function (o) {
o.documentarray = o.documentarray.slice(priv.job.limit.begin,
priv.job.limit.end);
that.limitDone();
return o.documentarray;
};
/**
* Tells to this storage that the limiting process is already done.
* @method limitDone
*/
that.limitDone = function () {
priv.limited = true;
};
//// end Public Methods //// end Public Methods
return that; return that;
}; };
......
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