Commit d7159460 authored by Romain Courteaud's avatar Romain Courteaud

WIP version to access an slapos master.

parent 3c2c8724
......@@ -4,7 +4,7 @@
"portal_type_fields": "computer_fieldlist",
"initial_query": {"include_docs": true, "limit":[0,8]},
"form": true,
"view": "FOO",
"view": "web_view",
"property_dict": {
"initial_query_url_identifier": "_id",
"dynamic_children": [1],
......
......@@ -4,7 +4,7 @@
"portal_type_fields": "computer_fieldlist",
"initial_query": {"include_docs": true, "limit":[0,1]},
"form": true,
"view": "FOO",
"view": "web_view",
"property_dict": {
"initial_query_url_identifier": "_id",
"dynamic_children": [0],
......
......@@ -4,7 +4,7 @@
"portal_type_fields": "computer_fieldlist",
"initial_query": {"include_docs": true, "limit":[]},
"form": true,
"view": "FOO",
"view": "web_view",
"property_dict": {
"no_items": {
"message":"No servers associated with this network.",
......
{
"portal_type_source": "Network",
"portal_type_source": "Computer Network",
"portal_type_title": "network",
"portal_type_fields": "network_fieldlist",
"initial_query": {"include_docs": true, "limit":[0,8]},
......
{
"portal_type_source": "Network",
"portal_type_source": "Computer Network",
"portal_type_title": "network",
"portal_type_fields": "network_fieldlist",
"initial_query": {"include_docs": true, "limit":[0,1]},
"form": true,
"view": "FOO",
"view": "web_view",
"property_dict": {
"initial_query_url_identifier": "_id",
"dynamic_children": [0],
......
{
"portal_type_source": "Service",
"portal_type_source": "Hosting Subscription",
"portal_type_title": "service",
"portal_type_fields": "service_fieldlist",
"form": true,
"view": "FOO",
"view": "web_view",
"property_dict": {
"initial_query_url_identifier": "_id",
"dynamic_children": [0],
......
{
"portal_type_source": "Service",
"portal_type_source": "Hosting Subscription",
"portal_type_title": "service",
"portal_type_fields": "service_fieldlist",
"initial_query": {"include_docs": true, "limit":[0,16]},
......
{
"portal_type_source": "Service",
"portal_type_source": "Hosting Subscription",
"portal_type_title": "service",
"portal_type_fields": "service_fieldlist",
"form": true,
"view": "FOO",
"view": "web_view",
"property_dict": {
"initial_query_url_identifier": "_id",
"dynamic_children": [1],
......
......@@ -21,6 +21,8 @@
<script type="text/javascript" src="js/libs/jio/jio.js"></script>
<script type="text/javascript" src="js/libs/jio/complex_queries.js"></script>
<script type="text/javascript" src="js/libs/jio/localstorage.js"></script>
<script type="text/javascript" src="js/libs/uritemplate/uritemplate-min.js"></script>
<script type="text/javascript" src="js/libs/jio/hateoasstorage.js"></script>
<!-- plugins -->
<script type="text/javascript" src="js/plugins/validval/jquery.validVal.js"></script>
......
......@@ -1580,9 +1580,9 @@
if (answer && (answer.data || answer.request_new)) {
if (answer.request_new || answer.data.total_rows === 0) {
data = {};
if (answer.request_new) {
data._id = util.uuid();
}
// if (answer.request_new) {
// data._id = util.uuid();
// }
} else if (answer.data.total_rows > 1) {
util.error("Fieldlist: More than 1 record");
} else {
......@@ -5322,7 +5322,7 @@
if (!util.findKey(
(query_object || {}), "query_list", "key", field_list[i])
) {
wrap += field_list[i] + ': "%' + value + '%" OR ';
wrap += field_list[i] + ': "' + value + '" OR ';
}
}
obj.query += ' AND (' + wrap.slice(0, -4) + ')';
......@@ -6164,8 +6164,6 @@
})
.then(app.checkAuth)
.then(app.fetchFields)
.then(app.testDataSample)
.then(app.fetchDataSample)
.then(app.store)
.then(app.fetchDataTotal)
.then(app.fetchDataQuery)
......@@ -6281,7 +6279,7 @@
convert = "values";
}
return storage[parcel.storage][method || "allDocs"](parcel.query)
return storage[parcel.storage][method || "allDocs"](parcel.query, hacked_view)
.then(function (response) {
// TODO: best way?
if (convert !== undefined && response.status === 200) {
......@@ -7090,4 +7088,4 @@
.fail(util.error);
});
}(window, document, jQuery));
\ No newline at end of file
}(window, document, jQuery));
/*
* Copyright 2013, Nexedi SA
* Released under the LGPL license.
* http://www.gnu.org/licenses/lgpl.html
*/
// JIO Hateoas Storage Description :
// {
// type: "hateoas"
// url: {string}
// }
/*jslint nomen: true, unparam: true */
/*global jIO, complex_queries, console, UriTemplate, FormData, RSVP */
(function (jIO, complex_queries) {
"use strict";
function HateoasStorage(spec) {
if (typeof spec.url !== 'string' && !spec.url) {
throw new TypeError("Hateoas 'url' must be a string " +
"which contains more than one character.");
}
this._url = spec.url;
}
HateoasStorage.prototype._getSiteDocument = function () {
return jIO.util.ajax({
"type": "GET",
"url": this._url
}).then(function (response) {
return JSON.parse(response.target.responseText);
});
};
HateoasStorage.prototype._get = function (param, options) {
return this._getSiteDocument()
.then(function (site_hal) {
return jIO.util.ajax({
"type": "GET",
"url": UriTemplate.parse(site_hal._links.traverse.href)
.expand({
// XXX FIXME Compatibility with slapos site
relative_url: decodeURIComponent(param._id),
view: options._view
})
});
})
.then(function (response) {
var result = JSON.parse(response.target.responseText);
result._id = param._id;
return result;
});
};
HateoasStorage.prototype.get = function (command, param, options) {
this._get(param, options)
.then(function (response) {
command.success({"data": response});
})
.fail(function (error) {
console.error(error);
// XXX How to propagate the error
command.error(
"not_found",
"missing",
"Cannot find document"
);
});
};
HateoasStorage.prototype.post = function (command, metadata, options) {
return this._getSiteDocument()
.then(function (site_hal) {
var post_action = site_hal._actions.add,
data = new FormData(),
key;
for (key in metadata) {
if (metadata.hasOwnProperty(key)) {
// XXX Not a form dialog in this case but distant script
data.append(key, metadata[key]);
}
}
return jIO.util.ajax({
"type": post_action.method,
"url": post_action.href,
"data": data
});
}).then(function (doc) {
// XXX Really depend on server response...
var new_document_url = doc.target.getResponseHeader("Location");
return jIO.util.ajax({
"type": "GET",
"url": new_document_url
});
}).then(function (response) {
var doc_hal = JSON.parse(response.target.responseText);
if (doc_hal !== null) {
command.success({"id": encodeURIComponent(doc_hal._relative_url)});
} else {
command.error(
"not_found",
"missing",
"Cannot find document"
);
}
}, function (error) {
console.error(error);
command.error(
500,
"Too bad...",
"Unable to post doc"
);
});
};
HateoasStorage.prototype.put = function (command, metadata, options) {
return this._get(metadata, options)
.then(function (result) {
var put_action = result._embedded._view._actions.put,
renderer_form = result._embedded._view,
data = new FormData(),
key;
data.append("form_id", renderer_form.id);
for (key in metadata) {
if (metadata.hasOwnProperty(key)) {
if (key !== "_id") {
// Hardcoded my_ ERP5 behaviour
if (renderer_form.hasOwnProperty("my_" + key)) {
data.append(renderer_form["my_" + key].key, metadata[key]);
} else {
throw new Error("Can not save property " + key);
}
}
}
}
return jIO.util.ajax({
"type": put_action.method,
"url": put_action.href,
"data": data
});
})
.then(function (result) {
command.success(result);
})
.fail(function (error) {
console.error(error);
command.error(
"error",
"did not work as expected",
"Unable to call allDocs"
);
});
};
HateoasStorage.prototype.allDocs = function (command, param, options) {
return this._getSiteDocument()
.then(function (site_hal) {
return jIO.util.ajax({
"type": "GET",
"url": UriTemplate.parse(site_hal._links.raw_search.href)
.expand({
query: options.query,
// XXX Force erp5 to return embedded document
select_list: options.select_list || ["title", "reference"],
limit: options.limit
})
});
})
.then(function (response) {
return JSON.parse(response.target.responseText);
})
.then(function (catalog_json) {
var data = catalog_json._embedded.contents,
count = data.length,
i,
item,
result = [],
promise_list = [result];
for (i = 0; i < count; i += 1) {
item = data[i];
// XXX FIXME Compatibility with slapos site
item._id = encodeURIComponent(item._relative_url);
result.push({
// XXX FIXME Compatibility with slapos site
id: encodeURIComponent(item._relative_url),
key: encodeURIComponent(item._relative_url),
doc: {},
value: item
});
// if (options.include_docs) {
// promise_list.push(RSVP.Queue().push(function () {
// return this._get({_id: item.name}, {_view: "View"});
// }).push
// }
}
return RSVP.all(promise_list);
})
.then(function (promise_list) {
var result = promise_list[0],
count = result.length;
command.success({"data": {"rows": result, "total_rows": count}});
})
.fail(function (error) {
console.error(error);
command.error(
"error",
"did not work as expected",
"Unable to call allDocs"
);
});
};
jIO.addStorage("hateoas", HateoasStorage);
}(jIO, complex_queries));
......@@ -3,9 +3,6 @@
if (typeof define === 'function' && define.amd) {
return define(dependencies, module);
}
if (typeof exports === 'object') {
return module(exports, require('rsvp'), require('sha256'));
}
window.jIO = {};
module(window.jIO, RSVP, {hex_sha256: hex_sha256});
}(['exports', 'rsvp', 'sha256'], function (exports, RSVP, sha256) {
......@@ -53,6 +50,7 @@ constants.http_status_text = {
"204": "No Content",
"205": "Reset Content",
"206": "Partial Content",
"304": "Not Modified",
"400": "Bad Request",
"401": "Unauthorized",
"402": "Payment Required",
......@@ -81,10 +79,12 @@ constants.http_status_text = {
"507": "Insufficient Storage",
"Ok": "Ok",
"OK": "Ok",
"Created": "Created",
"No Content": "No Content",
"Reset Content": "Reset Content",
"Partial Content": "Partial Content",
"Not Modified": "Not Modified",
"Bad Request": "Bad Request",
"Unauthorized": "Unauthorized",
"Payment Required": "Payment Required",
......@@ -117,6 +117,7 @@ constants.http_status_text = {
"no_content": "No Content",
"reset_content": "Reset Content",
"partial_content": "Partial Content",
"not_modified": "Not Modified",
"bad_request": "Bad Request",
"unauthorized": "Unauthorized",
"payment_required": "Payment Required",
......@@ -161,6 +162,7 @@ constants.http_status = {
"204": 204,
"205": 205,
"206": 206,
"304": 304,
"400": 400,
"401": 401,
"402": 402,
......@@ -189,10 +191,12 @@ constants.http_status = {
"507": 507,
"Ok": 200,
"OK": 200,
"Created": 201,
"No Content": 204,
"Reset Content": 205,
"Partial Content": 206,
"Not Modified": 304,
"Bad Request": 400,
"Unauthorized": 401,
"Payment Required": 402,
......@@ -225,6 +229,7 @@ constants.http_status = {
"no_content": 204,
"reset_content": 205,
"partial_content": 206,
"not_modified": 304,
"bad_request": 400,
"unauthorized": 401,
"payment_required": 402,
......@@ -269,6 +274,7 @@ constants.http_action = {
"204": "success",
"205": "success",
"206": "success",
"304": "success",
"400": "error",
"401": "error",
"402": "error",
......@@ -297,10 +303,12 @@ constants.http_action = {
"507": "error",
"Ok": "success",
"OK": "success",
"Created": "success",
"No Content": "success",
"Reset Content": "success",
"Partial Content": "success",
"Not Modified": "success",
"Bad Request": "error",
"Unauthorized": "error",
"Payment Required": "error",
......@@ -333,6 +341,7 @@ constants.http_action = {
"no_content": "success",
"reset_content": "success",
"partial_content": "success",
"not_modified": "success",
"bad_request": "error",
"unauthorized": "error",
"payment_required": "error",
......@@ -670,24 +679,6 @@ function dictFilter(dict, keys) {
}
exports.util.dictFilter = dictFilter;
/**
* A faster version of `array.indexOf(value)` -> `indexOf(value, array)`
*
* @param {Any} value The value to search for
* @param {Array} array The array to browse
* @return {Number} index of value, -1 otherwise
*/
function indexOf(value, array) {
var i;
for (i = 0; i < array.length; i += 1) {
if (array[i] === value) {
return i;
}
}
return -1;
}
exports.util.indexOf = indexOf;
/**
* Gets all elements of an array and classifies them in a dict of array.
* Dict keys are element types, and values are list of element of type 'key'.
......@@ -727,40 +718,6 @@ function generateUuid() {
}
exports.util.generateUuid = generateUuid;
/**
* Returns the number with the lowest value
*
* @param {Number} *values The values to compare
* @return {Number} The minimum
*/
function min() {
var i, val;
for (i = 1; i < arguments.length; i += 1) {
if (val === undefined || val > arguments[i]) {
val = arguments[i];
}
}
return val;
}
exports.util.min = min;
/**
* Returns the number with the greatest value
*
* @param {Number} *values The values to compare
* @return {Number} The maximum
*/
function max() {
var i, val;
for (i = 1; i < arguments.length; i += 1) {
if (val === undefined || val < arguments[i]) {
val = arguments[i];
}
}
return val;
}
exports.util.max = max;
/**
* JSON stringify a value. Dict keys are sorted in order to make a kind of
* deepEqual thanks to a simple strict equal string comparison.
......@@ -878,6 +835,7 @@ function ajax(param) {
return new RSVP.Promise(function (resolve, reject, notify) {
var k;
xhr.open(param.type || "GET", param.url, true);
xhr.responseType = param.dataType || "";
if (typeof param.headers === 'object' && param.headers !== null) {
for (k in param.headers) {
if (param.headers.hasOwnProperty(k)) {
......@@ -896,6 +854,7 @@ function ajax(param) {
if (typeof param.beforeSend === 'function') {
param.beforeSend(xhr);
}
xhr.withCredentials = true;
xhr.send(param.data);
}, function () {
xhr.abort();
......@@ -2160,71 +2119,106 @@ function restCommandRejecter(param, args) {
// reject(status, reason, message, {"custom": "value"});
// reject(status, reason, {..});
// reject(status, {..});
var a = args[0], b = args[1], c = args[2], d = args[3], weak, strong;
weak = {"result": "error"};
strong = {};
weak.status = constants.http_status.unknown;
weak.statusText = constants.http_status_text.unknown;
weak.message = 'Command failed';
weak.reason = 'fail';
weak.method = param.method;
var arg, current_priority, priority = [
// 0 - custom parameter values
{},
// 1 - default values
{
"status": constants.http_status.unknown,
"statusText": constants.http_status_text.unknown,
"message": "Command failed",
"reason": "unknown"
},
// 2 - status, reason, message properties
{},
// 3 - status, reason, message parameters
{},
// 4 - never change
{"result": "error", "method": param.method}
];
args = Array.prototype.slice.call(args);
arg = args.shift();
// priority 4 - never change
current_priority = priority[4];
if (param.kwargs._id) {
weak.id = param.kwargs._id;
current_priority.id = param.kwargs._id;
}
if (/Attachment$/.test(param.method)) {
weak.attachment = param.kwargs._attachment;
current_priority.attachment = param.kwargs._attachment;
}
if (typeof a !== 'object' || Array.isArray(a)) {
strong.status = constants.http_status[a];
strong.statusText = constants.http_status_text[a];
if (strong.status === undefined ||
strong.statusText === undefined) {
return restCommandRejecter(param, [
// can create infernal loop if 'internal_storage_error' is not defined
// in the constants
'internal_storage_error',
'invalid response',
'Unknown status "' + a + '"'
]);
// priority 3 - status, reason, message parameters
current_priority = priority[3];
// parsing first parameter if is not an object
if (typeof arg !== 'object' || arg === null || Array.isArray(arg)) {
// first parameter is mandatory
current_priority.status = arg;
arg = args.shift();
}
// parsing second parameter if is not an object
if (typeof arg !== 'object' || arg === null || Array.isArray(arg)) {
if (arg !== undefined) {
current_priority.reason = arg;
}
arg = args.shift();
}
// parsing third parameter if is not an object
if (typeof arg !== 'object' || arg === null || Array.isArray(arg)) {
if (arg !== undefined) {
current_priority.message = arg;
}
a = b;
b = c;
c = d;
arg = args.shift();
}
if (typeof a !== 'object' || Array.isArray(a)) {
strong.reason = a;
a = b;
b = c;
// parsing fourth parameter if is an object
if (typeof arg === 'object' && arg !== null && !Array.isArray(arg)) {
// priority 0 - custom values
dictUpdate(priority[0], arg);
// priority 2 - status, reason, message properties
current_priority = priority[2];
if (arg.hasOwnProperty('reason')) {
current_priority.reason = arg.reason;
}
if (arg.hasOwnProperty('message')) {
current_priority.message = arg.message;
}
if ((arg.statusText || arg.status >= 0)) {
current_priority.status = arg.statusText || arg.status;
}
if (arg instanceof Error) {
current_priority.reason = arg.message || "";
current_priority.error = arg.name;
}
}
if (typeof a !== 'object' || Array.isArray(a)) {
strong.message = a;
a = b;
// merge priority dicts
for (current_priority = priority.length - 1;
current_priority > 0;
current_priority -= 1) {
dictUpdate(priority[current_priority - 1], priority[current_priority]);
}
priority = priority[0];
if (typeof a === 'object' && !Array.isArray(a)) {
dictUpdate(weak, a);
if (a instanceof Error) {
weak.reason = a.message;
weak.error = a.name;
}
// check status
priority.statusText = constants.http_status_text[priority.status];
if (priority.statusText === undefined) {
return restCommandRejecter(param, [
// can create infernal loop if 'internal_storage_error' is not defined in
// the constants
'internal_storage_error',
'invalid response',
'Unknown status "' + priority.status + '"'
]);
}
priority.status = constants.http_status[priority.statusText];
dictUpdate(weak, strong);
strong = undefined;
if (weak.error === undefined) {
weak.error = weak.statusText.toLowerCase().replace(/ /g, '_').
// set default priority error if not already set
if (priority.error === undefined) {
priority.error = priority.statusText.toLowerCase().replace(/ /g, '_').
replace(/[^_a-z]/g, '');
}
if (typeof weak.message !== 'string') {
weak.message = "";
}
if (typeof weak.reason !== 'string') {
weak.reason = "unknown";
}
return param.solver.reject(deepClone(weak));
return param.solver.reject(deepClone(priority));
}
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true */
......@@ -2235,81 +2229,127 @@ function restCommandResolver(param, args) {
// resolve('ok', {"custom": "value"});
// resolve(200, {...});
// resolve({...});
var a = args[0], b = args[1], weak = {"result": "success"}, strong = {};
var arg, current_priority, priority = [
// 0 - custom parameter values
{},
// 1 - default values
{},
// 2 - status property
{},
// 3 - status parameter
{},
// 4 - never change
{"result": "success", "method": param.method}
];
args = Array.prototype.slice.call(args);
arg = args.shift();
// priority 3 - never change
current_priority = priority[3];
if (param.kwargs._id) {
current_priority.id = param.kwargs._id;
}
if (/Attachment$/.test(param.method)) {
current_priority.attachment = param.kwargs._attachment;
}
// priority 1 - default values
current_priority = priority[1];
if (param.method === 'post') {
weak.status = constants.http_status.created;
weak.statusText = constants.http_status_text.created;
current_priority.status = constants.http_status.created;
current_priority.statusText = constants.http_status_text.created;
} else if (methodType(param.method) === "writer" ||
param.method === "check") {
weak.status = constants.http_status.no_content;
weak.statusText = constants.http_status_text.no_content;
current_priority.status = constants.http_status.no_content;
current_priority.statusText = constants.http_status_text.no_content;
} else {
weak.status = constants.http_status.ok;
weak.statusText = constants.http_status_text.ok;
current_priority.status = constants.http_status.ok;
current_priority.statusText = constants.http_status_text.ok;
}
if (param.kwargs._id) {
weak.id = param.kwargs._id;
}
if (/Attachment$/.test(param.method)) {
weak.attachment = param.kwargs._attachment;
// priority 3 - status parameter
current_priority = priority[3];
// parsing first parameter if is not an object
if (typeof arg !== 'object' || arg === null || Array.isArray(arg)) {
if (arg !== undefined) {
current_priority.status = arg;
}
arg = args.shift();
}
weak.method = param.method;
if (typeof a === 'string' || (typeof a === 'number' && isFinite(a))) {
strong.status = constants.http_status[a];
strong.statusText = constants.http_status_text[a];
if (strong.status === undefined ||
strong.statusText === undefined) {
return restCommandRejecter(param, [
'internal_storage_error',
'invalid response',
'Unknown status "' + a + '"'
]);
// parsing second parameter if is an object
if (typeof arg === 'object' && arg !== null && !Array.isArray(arg)) {
// priority 0 - custom values
dictUpdate(current_priority, arg);
// priority 2 - status property
if (arg.hasOwnProperty("status") || arg.hasOwnProperty("statusText")) {
priority[2].status = arg.statusText || arg.status;
}
a = b;
}
if (typeof a === 'object' && !Array.isArray(a)) {
dictUpdate(weak, a);
// merge priority dicts
for (current_priority = priority.length - 1;
current_priority > 0;
current_priority -= 1) {
dictUpdate(priority[current_priority - 1], priority[current_priority]);
}
dictUpdate(weak, strong);
strong = undefined; // free memory
if (param.method === 'post' && (typeof weak.id !== 'string' || !weak.id)) {
priority = priority[0];
// check document id if post method
if (param.method === 'post' &&
(typeof priority.id !== 'string' || !priority.id)) {
return restCommandRejecter(param, [
'internal_storage_error',
'invalid response',
'New document id have to be specified'
]);
}
// check status
priority.statusText = constants.http_status_text[priority.status];
if (priority.statusText === undefined) {
return restCommandRejecter(param, [
'internal_storage_error',
'invalid response',
'Unknown status "' + priority.status + '"'
]);
}
priority.status = constants.http_status[priority.statusText];
// check data for get Attachment
if (param.method === 'getAttachment') {
if (typeof weak.data === 'string') {
weak.data = new Blob([weak.data], {
"type": weak.content_type || weak.mimetype || ""
if (typeof priority.data === 'string') {
priority.data = new Blob([priority.data], {
"type": priority.content_type || priority.mimetype || ""
});
delete weak.content_type;
delete weak.mimetype;
delete priority.content_type;
delete priority.mimetype;
}
if (!(weak.data instanceof Blob)) {
if (!(priority.data instanceof Blob)) {
return restCommandRejecter(param, [
'internal_storage_error',
'invalid response',
'getAttachment method needs a Blob as returned "data".'
]);
}
// check data for readers (except check method)
} else if (methodType(param.method) === 'reader' &&
param.method !== 'check' &&
(typeof weak.data !== 'object' ||
Object.getPrototypeOf(weak.data) !== Object.prototype)) {
(typeof priority.data !== 'object' ||
priority.data === null ||
Object.getPrototypeOf(priority.data) !== Object.prototype)) {
return restCommandRejecter(param, [
'internal_storage_error',
'invalid response',
param.method + ' method needs a dict as returned "data".'
]);
}
return param.solver.resolve(deepClone(weak));
return param.solver.resolve(deepClone(priority));
}
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true, unparam: true */
/*global arrayInsert, indexOf, deepClone, defaults, restCommandRejecter */
/*global arrayInsert, deepClone, defaults */
// creates
// - some defaults job rule actions
......@@ -2399,7 +2439,7 @@ function enableJobChecker(jio, shared, options) {
// wrong single property
return;
}
if (indexOf(job_rule.action, shared.job_rule_action_names) === -1) {
if (shared.job_rule_action_names.indexOf(job_rule.action) === -1) {
// wrong action
return;
}
......@@ -2565,7 +2605,7 @@ function enableJobChecker(jio, shared, options) {
}
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true, unparam: true */
/*global setTimeout, Job, createStorage, deepClone, min, restCommandResolver,
/*global setTimeout, Job, createStorage, deepClone, restCommandResolver,
restCommandRejecter */
function enableJobExecuter(jio, shared) { // , options) {
......@@ -2757,7 +2797,7 @@ function enableJobMaker(jio, shared, options) {
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true, unparam: true */
/*global arrayExtend, localStorage, Workspace, uniqueJSONStringify, JobQueue,
constants, indexOf, setTimeout, clearTimeout */
constants, setTimeout, clearTimeout */
function enableJobQueue(jio, shared, options) {
......@@ -2959,7 +2999,7 @@ function enableJobReference(jio, shared, options) {
}
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true, unparam: true */
/*global arrayExtend, setTimeout, methodType, min, constants */
/*global arrayExtend, setTimeout, methodType, constants */
function enableJobRetry(jio, shared, options) {
......@@ -3066,7 +3106,7 @@ function enableJobRetry(jio, shared, options) {
param.modified = new Date();
shared.emit('job:modified', param);
shared.emit('job:start', param);
}, min(10000, param.tried * 2000));
}, Math.min(10000, param.tried * 2000));
} else {
shared.emit('job:reject', param, args);
}
......
!function(e){"use strict";function t(e){var n;if(null===e||void 0===e)return!1;if(r.isArray(e))return e.length>0;if("string"==typeof e||"number"==typeof e||"boolean"==typeof e)return!0;for(n in e)if(e.hasOwnProperty(n)&&t(e[n]))return!0;return!1}var n=function(){function e(e){this.options=e}return e.prototype.toString=function(){return JSON&&JSON.stringify?JSON.stringify(this.options):this.options},e}(),r=function(){function e(e){return"[object Array]"===Object.prototype.toString.apply(e)}function t(e){return"[object String]"===Object.prototype.toString.apply(e)}function n(e){return"[object Number]"===Object.prototype.toString.apply(e)}function r(e){return"[object Boolean]"===Object.prototype.toString.apply(e)}function i(e,t){var n,r="",i=!0;for(n=0;n<e.length;n+=1)i?i=!1:r+=t,r+=e[n];return r}function o(e,t){for(var n=[],r=0;r<e.length;r+=1)n.push(t(e[r]));return n}function s(e,t){for(var n=[],r=0;r<e.length;r+=1)t(e[r])&&n.push(e[r]);return n}function a(e){if("object"!=typeof e||null===e)return e;Object.freeze(e);var t,n;for(n in e)e.hasOwnProperty(n)&&(t=e[n],"object"==typeof t&&u(t));return e}function u(e){return"function"==typeof Object.freeze?a(e):e}return{isArray:e,isString:t,isNumber:n,isBoolean:r,join:i,map:o,filter:s,deepFreeze:u}}(),i=function(){function e(e){return e>="a"&&"z">=e||e>="A"&&"Z">=e}function t(e){return e>="0"&&"9">=e}function n(e){return t(e)||e>="a"&&"f">=e||e>="A"&&"F">=e}return{isAlpha:e,isDigit:t,isHexDigit:n}}(),o=function(){function e(e){var t,n,r="",i=s.encode(e);for(n=0;n<i.length;n+=1)t=i.charCodeAt(n),r+="%"+(16>t?"0":"")+t.toString(16).toUpperCase();return r}function t(e,t){return"%"===e.charAt(t)&&i.isHexDigit(e.charAt(t+1))&&i.isHexDigit(e.charAt(t+2))}function n(e,t){return parseInt(e.substr(t,2),16)}function r(e){if(!t(e,0))return!1;var r=n(e,1),i=s.numBytes(r);if(0===i)return!1;for(var o=1;i>o;o+=1)if(!t(e,3*o)||!s.isValidFollowingCharCode(n(e,3*o+1)))return!1;return!0}function o(e,r){var i=e.charAt(r);if(!t(e,r))return i;var o=n(e,r+1),a=s.numBytes(o);if(0===a)return i;for(var u=1;a>u;u+=1)if(!t(e,r+3*u)||!s.isValidFollowingCharCode(n(e,r+3*u+1)))return i;return e.substr(r,3*a)}var s={encode:function(e){return unescape(encodeURIComponent(e))},numBytes:function(e){return 127>=e?1:e>=194&&223>=e?2:e>=224&&239>=e?3:e>=240&&244>=e?4:0},isValidFollowingCharCode:function(e){return e>=128&&191>=e}};return{encodeCharacter:e,isPctEncoded:r,pctCharAt:o}}(),s=function(){function e(e){return i.isAlpha(e)||i.isDigit(e)||"_"===e||o.isPctEncoded(e)}function t(e){return i.isAlpha(e)||i.isDigit(e)||"-"===e||"."===e||"_"===e||"~"===e}function n(e){return":"===e||"/"===e||"?"===e||"#"===e||"["===e||"]"===e||"@"===e||"!"===e||"$"===e||"&"===e||"("===e||")"===e||"*"===e||"+"===e||","===e||";"===e||"="===e||"'"===e}return{isVarchar:e,isUnreserved:t,isReserved:n}}(),a=function(){function e(e,t){var n,r="",i="";for(("number"==typeof e||"boolean"==typeof e)&&(e=e.toString()),n=0;n<e.length;n+=i.length)i=e.charAt(n),r+=s.isUnreserved(i)||t&&s.isReserved(i)?i:o.encodeCharacter(i);return r}function t(t){return e(t,!0)}function n(e,t){var n=o.pctCharAt(e,t);return n.length>1?n:s.isReserved(n)||s.isUnreserved(n)?n:o.encodeCharacter(n)}function r(e){var t,n="",r="";for(t=0;t<e.length;t+=r.length)r=o.pctCharAt(e,t),n+=r.length>1?r:s.isReserved(r)||s.isUnreserved(r)?r:o.encodeCharacter(r);return n}return{encode:e,encodePassReserved:t,encodeLiteral:r,encodeLiteralCharacter:n}}(),u=function(){function e(e){t[e]={symbol:e,separator:"?"===e?"&":""===e||"+"===e||"#"===e?",":e,named:";"===e||"&"===e||"?"===e,ifEmpty:"&"===e||"?"===e?"=":"",first:"+"===e?"":e,encode:"+"===e||"#"===e?a.encodePassReserved:a.encode,toString:function(){return this.symbol}}}var t={};return e(""),e("+"),e("#"),e("."),e("/"),e(";"),e("?"),e("&"),{valueOf:function(e){return t[e]?t[e]:"=,!@|".indexOf(e)>=0?null:t[""]}}}(),p=function(){function e(e){this.literal=a.encodeLiteral(e)}return e.prototype.expand=function(){return this.literal},e.prototype.toString=e.prototype.expand,e}(),f=function(){function e(e){function t(){var t=e.substring(h,p);if(0===t.length)throw new n({expressionText:e,message:"a varname must be specified",position:p});c={varname:t,exploded:!1,maxLength:null},h=null}function r(){if(d===p)throw new n({expressionText:e,message:"after a ':' you have to specify the length",position:p});c.maxLength=parseInt(e.substring(d,p),10),d=null}var a,p,f=[],c=null,h=null,d=null,g="";for(a=function(t){var r=u.valueOf(t);if(null===r)throw new n({expressionText:e,message:"illegal use of reserved operator",position:p,operator:t});return r}(e.charAt(0)),p=a.symbol.length,h=p;p<e.length;p+=g.length){if(g=o.pctCharAt(e,p),null!==h){if("."===g){if(h===p)throw new n({expressionText:e,message:"a varname MUST NOT start with a dot",position:p});continue}if(s.isVarchar(g))continue;t()}if(null!==d){if(p===d&&"0"===g)throw new n({expressionText:e,message:"A :prefix must not start with digit 0",position:p});if(i.isDigit(g)){if(p-d>=4)throw new n({expressionText:e,message:"A :prefix must have max 4 digits",position:p});continue}r()}if(":"!==g)if("*"!==g){if(","!==g)throw new n({expressionText:e,message:"illegal character",character:g,position:p});f.push(c),c=null,h=p+1}else{if(null===c)throw new n({expressionText:e,message:"exploded without varspec",position:p});if(c.exploded)throw new n({expressionText:e,message:"exploded twice",position:p});if(c.maxLength)throw new n({expressionText:e,message:"an explode (*) MUST NOT follow to a prefix",position:p});c.exploded=!0}else{if(null!==c.maxLength)throw new n({expressionText:e,message:"only one :maxLength is allowed per varspec",position:p});if(c.exploded)throw new n({expressionText:e,message:"an exploeded varspec MUST NOT be varspeced",position:p});d=p+1}}return null!==h&&t(),null!==d&&r(),f.push(c),new l(e,a,f)}function t(e){return e.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,"\\$&")}function r(r){var i,o,s,a=[],u=null,f="",l=!0,h=0;for(i=0;i<r.length;i+=1)if(o=r.charAt(i),null===h){if(null===u)throw new Error("reached unreachable code");if("{"===o)throw new n({templateText:r,message:"brace already opened",position:i});if("}"===o){if(u+1===i)throw new n({templateText:r,message:"empty braces",position:u});try{s=e(r.substring(u+1,i))}catch(d){if(d.prototype===n.prototype)throw new n({templateText:r,message:d.options.message,position:u+d.options.position,details:d.options});throw d}a.push(s),0===s.operator.symbol.length?f+="([^/]+)":l=!1,u=null,h=i+1}}else{if("}"===o)throw new n({templateText:r,message:"unopened brace closed",position:i});"{"===o&&(i>h&&(s=new p(r.substring(h,i)),a.push(s),f+=t(s.literal)),h=null,u=i)}if(null!==u)throw new n({templateText:r,message:"unclosed brace",position:u});return h<r.length&&(s=new p(r.substring(h)),a.push(s),f+=t(s.literal)),l===!1&&(f=void 0),new c(r,a,f)}return r}(),l=function(){function e(e){return JSON&&JSON.stringify?JSON.stringify(e):e}function n(e){if(!t(e))return!0;if(r.isString(e))return""===e;if(r.isNumber(e)||r.isBoolean(e))return!1;if(r.isArray(e))return 0===e.length;for(var n in e)if(e.hasOwnProperty(n))return!1;return!0}function i(e){var t,n=[];for(t in e)e.hasOwnProperty(t)&&n.push({name:t,value:e[t]});return n}function o(e,t,n){this.templateText=e,this.operator=t,this.varspecs=n}function s(e,t,n){var r="";if(n=n.toString(),t.named){if(r+=a.encodeLiteral(e.varname),""===n)return r+=t.ifEmpty;r+="="}return null!==e.maxLength&&(n=n.substr(0,e.maxLength)),r+=t.encode(n)}function u(e){return t(e.value)}function p(e,o,s){var p=[],f="";if(o.named){if(f+=a.encodeLiteral(e.varname),n(s))return f+=o.ifEmpty;f+="="}return r.isArray(s)?(p=s,p=r.filter(p,t),p=r.map(p,o.encode),f+=r.join(p,",")):(p=i(s),p=r.filter(p,u),p=r.map(p,function(e){return o.encode(e.name)+","+o.encode(e.value)}),f+=r.join(p,",")),f}function f(e,o,s){var p=r.isArray(s),f=[];return p?(f=s,f=r.filter(f,t),f=r.map(f,function(t){var r=a.encodeLiteral(e.varname);return r+=n(t)?o.ifEmpty:"="+o.encode(t)})):(f=i(s),f=r.filter(f,u),f=r.map(f,function(e){var t=a.encodeLiteral(e.name);return t+=n(e.value)?o.ifEmpty:"="+o.encode(e.value)})),r.join(f,o.separator)}function l(e,n){var o=[],s="";return r.isArray(n)?(o=n,o=r.filter(o,t),o=r.map(o,e.encode),s+=r.join(o,e.separator)):(o=i(n),o=r.filter(o,function(e){return t(e.value)}),o=r.map(o,function(t){return e.encode(t.name)+"="+e.encode(t.value)}),s+=r.join(o,e.separator)),s}return o.prototype.toString=function(){return this.templateText},o.prototype.expand=function(i){var o,a,u,c,h=[],d=!1,g=this.operator;for(o=0;o<this.varspecs.length;o+=1)if(a=this.varspecs[o],u=i[a.varname],null!==u&&void 0!==u)if(a.exploded&&(d=!0),c=r.isArray(u),"string"==typeof u||"number"==typeof u||"boolean"==typeof u)h.push(s(a,g,u));else{if(a.maxLength&&t(u))throw new Error("Prefix modifiers are not applicable to variables that have composite values. You tried to expand "+this+" with "+e(u));a.exploded?t(u)&&(g.named?h.push(f(a,g,u)):h.push(l(g,u))):(g.named||!n(u))&&h.push(p(a,g,u))}return 0===h.length?"":g.first+r.join(h,g.separator)},o}(),c=function(){function e(e,t,n){this.templateText=e,this.expressions=t,void 0!==n&&(this.regexp=new RegExp("^"+n+"$")),r.deepFreeze(this)}return e.prototype.toString=function(){return this.templateText},e.prototype.expand=function(e){var t,n="";for(t=0;t<this.expressions.length;t+=1)n+=this.expressions[t].expand(e);return n},e.prototype.extract=function(e){var t,n,r,i,o=1,s=!0,a={};if(void 0!==this.regexp&&this.regexp.test(e)){for(i=this.regexp.exec(e),t=0;t<this.expressions.length;t+=1)n=this.expressions[t],void 0===n.literal&&(void 0!==n.operator&&0===n.operator.symbol.length&&1===n.varspecs.length?(r=n.varspecs[0],r.exploded===!1&&null===r.maxLength?-1===i[o].indexOf(",")?(a[r.varname]=decodeURIComponent(i[o]),o+=1):s=!1:s=!1):s=!1);if(s)return a}return!1},e.parse=f,e.UriTemplateError=n,e}();e(c)}(function(e){"use strict";"undefined"!=typeof module?module.exports=e:"function"==typeof define?define([],function(){return e}):"undefined"!=typeof window?window.UriTemplate=e:global.UriTemplate=e});
\ No newline at end of file
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