Commit 282d28d5 authored by Sven Franck's avatar Sven Franck

jslint pass jobRules.js

parent 2534a5e1
var jobRules = (function(spec) { /*jslint indent: 2, maxlen: 80, sloppy: true */
var that = {}; var jobRules = (function () {
// Attributes // var that = {}, priv = {};
var priv = {};
priv.compare = {}; priv.compare = {};
priv.action = {}; priv.action = {};
Object.defineProperty(that,"eliminate",{ Object.defineProperty(that, "eliminate", {
configurable:false,enumerable:false,writable:false,value: configurable: false,
function() { return 'eliminate'; } enumerable: false,
writable: false,
value: function () {
return 'eliminate';
}
}); });
Object.defineProperty(that,"update",{ Object.defineProperty(that, "update", {
configurable:false,enumerable:false,writable:false,value: configurable: false,
function() { return 'update'; } enumerable: false,
writable: false,
value: function () {
return 'update';
}
}); });
Object.defineProperty(that,"dontAccept",{ Object.defineProperty(that, "dontAccept", {
configurable:false,enumerable:false,writable:false,value: configurable: false,
function() { return 'dont accept'; } enumerable: false,
writable: false,
value: function () {
return 'dont accept';
}
}); });
Object.defineProperty(that,"wait",{ Object.defineProperty(that, "wait", {
configurable:false,enumerable:false,writable:false,value: configurable: false,
function() { return 'wait'; } enumerable: false,
writable: false,
value: function () {
return 'wait';
}
}); });
Object.defineProperty(that,"none",{ Object.defineProperty(that, "none", {
configurable:false,enumerable:false,writable:false,value: configurable: false,
function() { return 'none'; } enumerable: false,
writable: false,
value: function () {
return 'none';
}
}); });
that.default_action = that.none; that.default_action = that.none;
that.default_compare = function(job1,job2) { that.default_compare = function (job1, job2) {
return (job1.getCommand().getDocId() === return (job1.getCommand().getDocId() === job2.getCommand().getDocId() &&
job2.getCommand().getDocId() &&
job1.getCommand().getDocInfo('_rev') === job1.getCommand().getDocInfo('_rev') ===
job2.getCommand().getDocInfo('_rev') && job2.getCommand().getDocInfo('_rev') &&
job1.getCommand().getOption('rev') === job1.getCommand().getOption('rev') ===
...@@ -45,19 +64,17 @@ var jobRules = (function(spec) { ...@@ -45,19 +64,17 @@ var jobRules = (function(spec) {
* @param {object} job2 The job to compare with. * @param {object} job2 The job to compare with.
* @return {string} An action string. * @return {string} An action string.
*/ */
priv.getAction = function(job1,job2) { priv.getAction = function (job1, job2) {
var j1label, j2label, j1status; var j1label, j2label, j1status;
j1label = job1.getCommand().getLabel(); j1label = job1.getCommand().getLabel();
j2label = job2.getCommand().getLabel(); j2label = job2.getCommand().getLabel();
j1status = (job1.getStatus().getLabel()==='on going'? j1status = (job1.getStatus().getLabel() === 'on going' ?
'on going':'not on going'); 'on going' : 'not on going');
if (priv.action[j1label] && if (priv.action[j1label] && priv.action[j1label][j1status] &&
priv.action[j1label][j1status] &&
priv.action[j1label][j1status][j2label]) { priv.action[j1label][j1status][j2label]) {
return priv.action[j1label][j1status][j2label](job1,job2); return priv.action[j1label][j1status][j2label](job1, job2);
} else {
return that.default_action(job1,job2);
} }
return that.default_action(job1, job2);
}; };
/** /**
...@@ -67,15 +84,13 @@ var jobRules = (function(spec) { ...@@ -67,15 +84,13 @@ var jobRules = (function(spec) {
* @param {object} job2 The job to compare with. * @param {object} job2 The job to compare with.
* @return {boolean} true if comparable, else false. * @return {boolean} true if comparable, else false.
*/ */
priv.canCompare = function(job1,job2) { priv.canCompare = function (job1, job2) {
var job1label = job1.getCommand().getLabel(), var job1label = job1.getCommand().getLabel(),
job2label = job2.getCommand().getLabel(); job2label = job2.getCommand().getLabel();
if (priv.compare[job1label] && if (priv.compare[job1label] && priv.compare[job2label]) {
priv.compare[job2label]) { return priv.compare[job1label][job2label](job1, job2);
return priv.compare[job1label][job2label](job1,job2);
} else {
return that.default_compare(job1,job2);
} }
return that.default_compare(job1, job2);
}; };
/** /**
...@@ -85,13 +100,21 @@ var jobRules = (function(spec) { ...@@ -85,13 +100,21 @@ var jobRules = (function(spec) {
* @param {object} job2 The new job. * @param {object} job2 The new job.
* @return {string} The action string. * @return {string} The action string.
*/ */
Object.defineProperty(that,"validateJobAccordingToJob",{ Object.defineProperty(that, "validateJobAccordingToJob", {
configurable:false,enumerable:false,writable:false,value: configurable: false,
function(job1,job2) { enumerable: false,
if (priv.canCompare(job1,job2)) { writable: false,
return {action:priv.getAction(job1,job2),job:job1}; value: function (job1, job2) {
if (priv.canCompare(job1, job2)) {
return {
action: priv.getAction(job1, job2),
job: job1
};
} }
return {action:that.default_action(job1,job2),job:job1}; return {
action: that.default_action(job1, job2),
job: job1
};
} }
}); });
...@@ -103,13 +126,14 @@ var jobRules = (function(spec) { ...@@ -103,13 +126,14 @@ var jobRules = (function(spec) {
* @param {string} method2 The action label from the new job. * @param {string} method2 The action label from the new job.
* @param {function} rule The rule that return an action string. * @param {function} rule The rule that return an action string.
*/ */
Object.defineProperty(that,"addActionRule",{ Object.defineProperty(that, "addActionRule", {
configurable:false,enumerable:false,writable:false,value: configurable: false,
function(method1,ongoing,method2,rule) { enumerable: false,
var ongoing_s = (ongoing?'on going':'not on going'); writable: false,
value: function (method1, ongoing, method2, rule) {
var ongoing_s = (ongoing ? 'on going' : 'not on going');
priv.action[method1] = priv.action[method1] || {}; priv.action[method1] = priv.action[method1] || {};
priv.action[method1][ongoing_s] = priv.action[method1][ongoing_s] = priv.action[method1][ongoing_s] || {};
priv.action[method1][ongoing_s] || {};
priv.action[method1][ongoing_s][method2] = rule; priv.action[method1][ongoing_s][method2] = rule;
} }
}); });
...@@ -122,9 +146,11 @@ var jobRules = (function(spec) { ...@@ -122,9 +146,11 @@ var jobRules = (function(spec) {
* @param {function} rule The rule that return a boolean * @param {function} rule The rule that return a boolean
* - true if job1 and job2 can be compared, else false. * - true if job1 and job2 can be compared, else false.
*/ */
Object.defineProperty(that,"addCompareRule",{ Object.defineProperty(that, "addCompareRule", {
configurable:false,enumerable:false,writable:false,value: configurable: false,
function(method1,method2,rule) { enumerable: false,
writable: false,
value: function (method1, method2, rule) {
priv.compare[method1] = priv.compare[method1] || {}; priv.compare[method1] = priv.compare[method1] || {};
priv.compare[method1][method2] = rule; priv.compare[method1][method2] = rule;
} }
...@@ -182,62 +208,62 @@ var jobRules = (function(spec) { ...@@ -182,62 +208,62 @@ var jobRules = (function(spec) {
For more information, see documentation For more information, see documentation
*/ */
that.addActionRule('post' ,true ,'post' ,that.dontAccept); that.addActionRule('post', true, 'post', that.dontAccept);
that.addActionRule('post' ,true ,'put' ,that.wait); that.addActionRule('post', true, 'put', that.wait);
that.addActionRule('post' ,true ,'get' ,that.wait); that.addActionRule('post', true, 'get', that.wait);
that.addActionRule('post' ,true ,'remove' ,that.wait); that.addActionRule('post', true, 'remove', that.wait);
that.addActionRule('post' ,true ,'putAttachment',that.wait); that.addActionRule('post', true, 'putAttachment', that.wait);
that.addActionRule('post' ,false,'post' ,that.update); that.addActionRule('post', false, 'post', that.update);
that.addActionRule('post' ,false,'put' ,that.wait); that.addActionRule('post', false, 'put', that.wait);
that.addActionRule('post' ,false,'get' ,that.wait); that.addActionRule('post', false, 'get', that.wait);
that.addActionRule('post' ,false,'remove' ,that.eliminate); that.addActionRule('post', false, 'remove', that.eliminate);
that.addActionRule('post' ,false,'putAttachment',that.wait); that.addActionRule('post', false, 'putAttachment', that.wait);
that.addActionRule('put' ,true ,'post' ,that.dontAccept); that.addActionRule('put', true, 'post', that.dontAccept);
that.addActionRule('put' ,true ,'put' ,that.wait); that.addActionRule('put', true, 'put', that.wait);
that.addActionRule('put' ,true ,'get' ,that.wait); that.addActionRule('put', true, 'get', that.wait);
that.addActionRule('put' ,true ,'remove' ,that.wait); that.addActionRule('put', true, 'remove', that.wait);
that.addActionRule('put' ,true ,'putAttachment',that.wait); that.addActionRule('put', true, 'putAttachment', that.wait);
that.addActionRule('put' ,false,'post' ,that.dontAccept); that.addActionRule('put', false, 'post', that.dontAccept);
that.addActionRule('put' ,false,'put' ,that.update); that.addActionRule('put', false, 'put', that.update);
that.addActionRule('put' ,false,'get' ,that.wait); that.addActionRule('put', false, 'get', that.wait);
that.addActionRule('put' ,false,'remove' ,that.eliminate); that.addActionRule('put', false, 'remove', that.eliminate);
that.addActionRule('put' ,false,'putAttachment',that.wait); that.addActionRule('put', false, 'putAttachment', that.wait);
that.addActionRule('get' ,true ,'post' ,that.wait); that.addActionRule('get', true, 'post', that.wait);
that.addActionRule('get' ,true ,'put' ,that.wait); that.addActionRule('get', true, 'put', that.wait);
that.addActionRule('get' ,true ,'get' ,that.dontAccept); that.addActionRule('get', true, 'get', that.dontAccept);
that.addActionRule('get' ,true ,'remove' ,that.wait); that.addActionRule('get', true, 'remove', that.wait);
that.addActionRule('get' ,true ,'putAttachment',that.wait); that.addActionRule('get', true, 'putAttachment', that.wait);
that.addActionRule('get' ,false,'post' ,that.wait); that.addActionRule('get', false, 'post', that.wait);
that.addActionRule('get' ,false,'put' ,that.wait); that.addActionRule('get', false, 'put', that.wait);
that.addActionRule('get' ,false,'get' ,that.update); that.addActionRule('get', false, 'get', that.update);
that.addActionRule('get' ,false,'remove' ,that.wait); that.addActionRule('get', false, 'remove', that.wait);
that.addActionRule('get' ,false,'putAttachment',that.wait); that.addActionRule('get', false, 'putAttachment', that.wait);
that.addActionRule('remove' ,true ,'post' ,that.wait); that.addActionRule('remove', true, 'post', that.wait);
that.addActionRule('remove' ,true ,'get' ,that.dontAccept); that.addActionRule('remove', true, 'get', that.dontAccept);
that.addActionRule('remove' ,true ,'remove' ,that.dontAccept); that.addActionRule('remove', true, 'remove', that.dontAccept);
that.addActionRule('remove' ,true ,'putAttachment',that.dontAccept); that.addActionRule('remove', true, 'putAttachment', that.dontAccept);
that.addActionRule('remove' ,false,'post' ,that.eliminate); that.addActionRule('remove', false, 'post', that.eliminate);
that.addActionRule('remove' ,false,'put' ,that.dontAccept); that.addActionRule('remove', false, 'put', that.dontAccept);
that.addActionRule('remove' ,false,'get' ,that.dontAccept); that.addActionRule('remove', false, 'get', that.dontAccept);
that.addActionRule('remove' ,false,'remove' ,that.update); that.addActionRule('remove', false, 'remove', that.update);
that.addActionRule('remove' ,false,'putAttachment',that.dontAccept); that.addActionRule('remove', false, 'putAttachment', that.dontAccept);
that.addActionRule('allDocs' ,true ,'allDocs' ,that.dontAccept); that.addActionRule('allDocs', true, 'allDocs', that.dontAccept);
that.addActionRule('allDocs' ,false,'allDocs' ,that.update); that.addActionRule('allDocs', false, 'allDocs', that.update);
that.addActionRule('putAttachment',true ,'post' ,that.dontAccept); that.addActionRule('putAttachment', true, 'post', that.dontAccept);
that.addActionRule('putAttachment',true ,'put' ,that.wait); that.addActionRule('putAttachment', true, 'put', that.wait);
that.addActionRule('putAttachment',true ,'get' ,that.wait); that.addActionRule('putAttachment', true, 'get', that.wait);
that.addActionRule('putAttachment',true ,'remove' ,that.wait); that.addActionRule('putAttachment', true, 'remove', that.wait);
that.addActionRule('putAttachment',true ,'putAttachment',that.wait); that.addActionRule('putAttachment', true, 'putAttachment', that.wait);
that.addActionRule('putAttachment',false,'post' ,that.dontAccept); that.addActionRule('putAttachment', false, 'post', that.dontAccept);
that.addActionRule('putAttachment',false,'put' ,that.wait); that.addActionRule('putAttachment', false, 'put', that.wait);
that.addActionRule('putAttachment',false,'get' ,that.wait); that.addActionRule('putAttachment', false, 'get', that.wait);
that.addActionRule('putAttachment',false,'remove' ,that.eliminate); that.addActionRule('putAttachment', false, 'remove', that.eliminate);
that.addActionRule('putAttachment',false,'putAttachment',that.update); that.addActionRule('putAttachment', false, 'putAttachment', that.update);
// end adding rules // end adding rules
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
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