mirror of https://gitee.com/bigwinds/arangodb
Fixed jslint warnings, removed sloppy:true
This commit is contained in:
parent
61ab284433
commit
20578ae5f5
|
@ -1,252 +1,255 @@
|
||||||
/*jslint indent: 2, nomen: true, maxlen: 100, sloppy: true, vars: true, white: true, plusplus: true */
|
/*jslint indent: 2, nomen: true, maxlen: 100, vars: true, white: true, plusplus: true */
|
||||||
/*global window, $ */
|
/*global window, $ */
|
||||||
|
|
||||||
window.arangoHelper = {
|
(function() {
|
||||||
lastNotificationMessage: null,
|
"use strict";
|
||||||
|
window.arangoHelper = {
|
||||||
|
lastNotificationMessage: null,
|
||||||
|
|
||||||
CollectionTypes: {},
|
CollectionTypes: {},
|
||||||
systemAttributes: function () {
|
systemAttributes: function () {
|
||||||
return {
|
return {
|
||||||
'_id' : true,
|
'_id' : true,
|
||||||
'_rev' : true,
|
'_rev' : true,
|
||||||
'_key' : true,
|
'_key' : true,
|
||||||
'_bidirectional' : true,
|
'_bidirectional' : true,
|
||||||
'_vertices' : true,
|
'_vertices' : true,
|
||||||
'_from' : true,
|
'_from' : true,
|
||||||
'_to' : true,
|
'_to' : true,
|
||||||
'$id' : true
|
'$id' : true
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
fixTooltips: function (selector, placement) {
|
fixTooltips: function (selector, placement) {
|
||||||
$(selector).tooltip({
|
$(selector).tooltip({
|
||||||
placement: placement,
|
placement: placement,
|
||||||
hide: false,
|
hide: false,
|
||||||
show: false
|
show: false
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
currentDatabase: function () {
|
|
||||||
var returnVal = false;
|
|
||||||
$.ajax({
|
|
||||||
type: "GET",
|
|
||||||
cache: false,
|
|
||||||
url: "/_api/database/current",
|
|
||||||
contentType: "application/json",
|
|
||||||
processData: false,
|
|
||||||
async: false,
|
|
||||||
success: function(data) {
|
|
||||||
returnVal = data.result.name;
|
|
||||||
},
|
|
||||||
error: function(data) {
|
|
||||||
returnVal = false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return returnVal;
|
|
||||||
},
|
|
||||||
|
|
||||||
databaseAllowed: function () {
|
|
||||||
var currentDB = this.currentDatabase();
|
|
||||||
returnVal = false;
|
|
||||||
$.ajax({
|
|
||||||
type: "GET",
|
|
||||||
cache: false,
|
|
||||||
url: "/_db/"+encodeURIComponent(currentDB)+"/_api/database/",
|
|
||||||
contentType: "application/json",
|
|
||||||
processData: false,
|
|
||||||
async: false,
|
|
||||||
success: function(data) {
|
|
||||||
returnVal = true;
|
|
||||||
},
|
|
||||||
error: function(data) {
|
|
||||||
returnVal = false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return returnVal;
|
|
||||||
},
|
|
||||||
|
|
||||||
removeNotifications: function () {
|
|
||||||
$.gritter.removeAll();
|
|
||||||
this.lastNotificationMessage = null;
|
|
||||||
},
|
|
||||||
arangoNotification: function (message) {
|
|
||||||
var returnVal = false;
|
|
||||||
$.gritter.add({
|
|
||||||
title: "Notice:",
|
|
||||||
text: message,
|
|
||||||
time: 3000,
|
|
||||||
before_open: function(){
|
|
||||||
returnVal = true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this.lastNotificationMessage = null;
|
|
||||||
|
|
||||||
return returnVal;
|
|
||||||
},
|
|
||||||
arangoError: function (message) {
|
|
||||||
var returnVal = false;
|
|
||||||
$.gritter.add({
|
|
||||||
title: "Error:",
|
|
||||||
text: message,
|
|
||||||
sticky: true,
|
|
||||||
before_open: function(){
|
|
||||||
if (this.lastNotificationMessage === message) {
|
|
||||||
// prevent display the same message over & over
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if($('.gritter-item-wrapper').length == 3) {
|
|
||||||
// not more than 3 messages at once
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
this.lastNotificationMessage = message;
|
|
||||||
returnVal = true;
|
|
||||||
},
|
|
||||||
before_close: function(){
|
|
||||||
// reset last text when closing a specific message
|
|
||||||
this.lastNotificationMessage = null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return returnVal;
|
|
||||||
},
|
|
||||||
getRandomToken: function () {
|
|
||||||
return Math.round(new Date().getTime());
|
|
||||||
},
|
|
||||||
|
|
||||||
isSystemAttribute: function (val) {
|
|
||||||
var a = this.systemAttributes();
|
|
||||||
return a[val];
|
|
||||||
},
|
|
||||||
|
|
||||||
isSystemCollection: function (val) {
|
|
||||||
//return val && val.name && val.name.substr(0, 1) === '_';
|
|
||||||
return val.substr(0, 1) === '_';
|
|
||||||
},
|
|
||||||
|
|
||||||
collectionApiType: function (identifier) {
|
|
||||||
if (this.CollectionTypes[identifier] === undefined) {
|
|
||||||
this.CollectionTypes[identifier] = window.arangoDocumentStore
|
|
||||||
.getCollectionInfo(identifier).type;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.CollectionTypes[identifier] === 3) {
|
|
||||||
return "edge";
|
|
||||||
}
|
|
||||||
return "document";
|
|
||||||
},
|
|
||||||
|
|
||||||
collectionType: function (val) {
|
|
||||||
if (! val || val.name === '') {
|
|
||||||
return "-";
|
|
||||||
}
|
|
||||||
var type;
|
|
||||||
if (val.type === 2) {
|
|
||||||
type = "document";
|
|
||||||
}
|
|
||||||
else if (val.type === 3) {
|
|
||||||
type = "edge";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
type = "unknown";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (val.name.substr(0, 1) === '_') {
|
|
||||||
type += " (system)";
|
|
||||||
}
|
|
||||||
|
|
||||||
return type;
|
|
||||||
},
|
|
||||||
|
|
||||||
FormatJSON: function (oData, sIndent) {
|
|
||||||
var self = this;
|
|
||||||
var sHTML, iCount;
|
|
||||||
if (sIndent === undefined) {
|
|
||||||
sIndent = "";
|
|
||||||
}
|
|
||||||
var sIndentStyle = " ";
|
|
||||||
var sDataType = self.RealTypeOf(oData);
|
|
||||||
|
|
||||||
if (sDataType === "array") {
|
|
||||||
if (oData.length === 0) {
|
|
||||||
return "[]";
|
|
||||||
}
|
|
||||||
sHTML = "[";
|
|
||||||
} else {
|
|
||||||
iCount = 0;
|
|
||||||
$.each(oData, function() {
|
|
||||||
iCount++;
|
|
||||||
return;
|
|
||||||
});
|
});
|
||||||
if (iCount === 0) { // object is empty
|
},
|
||||||
return "{}";
|
|
||||||
}
|
|
||||||
sHTML = "{";
|
|
||||||
}
|
|
||||||
|
|
||||||
iCount = 0;
|
currentDatabase: function () {
|
||||||
$.each(oData, function(sKey, vValue) {
|
var returnVal = false;
|
||||||
if (iCount > 0) {
|
$.ajax({
|
||||||
sHTML += ",";
|
type: "GET",
|
||||||
|
cache: false,
|
||||||
|
url: "/_api/database/current",
|
||||||
|
contentType: "application/json",
|
||||||
|
processData: false,
|
||||||
|
async: false,
|
||||||
|
success: function(data) {
|
||||||
|
returnVal = data.result.name;
|
||||||
|
},
|
||||||
|
error: function(data) {
|
||||||
|
returnVal = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return returnVal;
|
||||||
|
},
|
||||||
|
|
||||||
|
databaseAllowed: function () {
|
||||||
|
var currentDB = this.currentDatabase(),
|
||||||
|
returnVal = false;
|
||||||
|
$.ajax({
|
||||||
|
type: "GET",
|
||||||
|
cache: false,
|
||||||
|
url: "/_db/"+encodeURIComponent(currentDB)+"/_api/database/",
|
||||||
|
contentType: "application/json",
|
||||||
|
processData: false,
|
||||||
|
async: false,
|
||||||
|
success: function(data) {
|
||||||
|
returnVal = true;
|
||||||
|
},
|
||||||
|
error: function(data) {
|
||||||
|
returnVal = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return returnVal;
|
||||||
|
},
|
||||||
|
|
||||||
|
removeNotifications: function () {
|
||||||
|
$.gritter.removeAll();
|
||||||
|
this.lastNotificationMessage = null;
|
||||||
|
},
|
||||||
|
arangoNotification: function (message) {
|
||||||
|
var returnVal = false;
|
||||||
|
$.gritter.add({
|
||||||
|
title: "Notice:",
|
||||||
|
text: message,
|
||||||
|
time: 3000,
|
||||||
|
before_open: function(){
|
||||||
|
returnVal = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.lastNotificationMessage = null;
|
||||||
|
|
||||||
|
return returnVal;
|
||||||
|
},
|
||||||
|
arangoError: function (message) {
|
||||||
|
var returnVal = false;
|
||||||
|
$.gritter.add({
|
||||||
|
title: "Error:",
|
||||||
|
text: message,
|
||||||
|
sticky: true,
|
||||||
|
before_open: function(){
|
||||||
|
if (this.lastNotificationMessage === message) {
|
||||||
|
// prevent display the same message over & over
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if($('.gritter-item-wrapper').length === 3) {
|
||||||
|
// not more than 3 messages at once
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
this.lastNotificationMessage = message;
|
||||||
|
returnVal = true;
|
||||||
|
},
|
||||||
|
before_close: function(){
|
||||||
|
// reset last text when closing a specific message
|
||||||
|
this.lastNotificationMessage = null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return returnVal;
|
||||||
|
},
|
||||||
|
getRandomToken: function () {
|
||||||
|
return Math.round(new Date().getTime());
|
||||||
|
},
|
||||||
|
|
||||||
|
isSystemAttribute: function (val) {
|
||||||
|
var a = this.systemAttributes();
|
||||||
|
return a[val];
|
||||||
|
},
|
||||||
|
|
||||||
|
isSystemCollection: function (val) {
|
||||||
|
//return val && val.name && val.name.substr(0, 1) === '_';
|
||||||
|
return val.substr(0, 1) === '_';
|
||||||
|
},
|
||||||
|
|
||||||
|
collectionApiType: function (identifier) {
|
||||||
|
if (this.CollectionTypes[identifier] === undefined) {
|
||||||
|
this.CollectionTypes[identifier] = window.arangoDocumentStore
|
||||||
|
.getCollectionInfo(identifier).type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.CollectionTypes[identifier] === 3) {
|
||||||
|
return "edge";
|
||||||
|
}
|
||||||
|
return "document";
|
||||||
|
},
|
||||||
|
|
||||||
|
collectionType: function (val) {
|
||||||
|
if (! val || val.name === '') {
|
||||||
|
return "-";
|
||||||
|
}
|
||||||
|
var type;
|
||||||
|
if (val.type === 2) {
|
||||||
|
type = "document";
|
||||||
|
}
|
||||||
|
else if (val.type === 3) {
|
||||||
|
type = "edge";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
type = "unknown";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (val.name.substr(0, 1) === '_') {
|
||||||
|
type += " (system)";
|
||||||
|
}
|
||||||
|
|
||||||
|
return type;
|
||||||
|
},
|
||||||
|
|
||||||
|
FormatJSON: function (oData, sIndent) {
|
||||||
|
var self = this;
|
||||||
|
var sHTML, iCount;
|
||||||
|
if (sIndent === undefined) {
|
||||||
|
sIndent = "";
|
||||||
|
}
|
||||||
|
var sIndentStyle = " ";
|
||||||
|
var sDataType = self.RealTypeOf(oData);
|
||||||
|
|
||||||
if (sDataType === "array") {
|
if (sDataType === "array") {
|
||||||
sHTML += ("\n" + sIndent + sIndentStyle);
|
if (oData.length === 0) {
|
||||||
|
return "[]";
|
||||||
|
}
|
||||||
|
sHTML = "[";
|
||||||
} else {
|
} else {
|
||||||
sHTML += ("\n" + sIndent + sIndentStyle + JSON.stringify(sKey) + ": ");
|
iCount = 0;
|
||||||
|
$.each(oData, function() {
|
||||||
|
iCount++;
|
||||||
|
return;
|
||||||
|
});
|
||||||
|
if (iCount === 0) { // object is empty
|
||||||
|
return "{}";
|
||||||
|
}
|
||||||
|
sHTML = "{";
|
||||||
}
|
}
|
||||||
|
|
||||||
// display relevant data type
|
iCount = 0;
|
||||||
switch (self.RealTypeOf(vValue)) {
|
$.each(oData, function(sKey, vValue) {
|
||||||
case "array":
|
if (iCount > 0) {
|
||||||
case "object":
|
sHTML += ",";
|
||||||
sHTML += self.FormatJSON(vValue, (sIndent + sIndentStyle));
|
}
|
||||||
break;
|
if (sDataType === "array") {
|
||||||
case "boolean":
|
sHTML += ("\n" + sIndent + sIndentStyle);
|
||||||
case "number":
|
} else {
|
||||||
sHTML += vValue.toString();
|
sHTML += ("\n" + sIndent + sIndentStyle + JSON.stringify(sKey) + ": ");
|
||||||
break;
|
}
|
||||||
case "null":
|
|
||||||
sHTML += "null";
|
|
||||||
break;
|
|
||||||
case "string":
|
|
||||||
sHTML += "\"" + vValue.replace(/\\/g, "\\\\").replace(/"/g, "\\\"") + "\"";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
sHTML += ("TYPEOF: " + typeof vValue);
|
|
||||||
}
|
|
||||||
// loop
|
|
||||||
iCount++;
|
|
||||||
});
|
|
||||||
|
|
||||||
// close object
|
// display relevant data type
|
||||||
if (sDataType === "array") {
|
switch (self.RealTypeOf(vValue)) {
|
||||||
sHTML += ("\n" + sIndent + "]");
|
case "array":
|
||||||
} else {
|
case "object":
|
||||||
sHTML += ("\n" + sIndent + "}");
|
sHTML += self.FormatJSON(vValue, (sIndent + sIndentStyle));
|
||||||
|
break;
|
||||||
|
case "boolean":
|
||||||
|
case "number":
|
||||||
|
sHTML += vValue.toString();
|
||||||
|
break;
|
||||||
|
case "null":
|
||||||
|
sHTML += "null";
|
||||||
|
break;
|
||||||
|
case "string":
|
||||||
|
sHTML += "\"" + vValue.replace(/\\/g, "\\\\").replace(/"/g, "\\\"") + "\"";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
sHTML += ("TYPEOF: " + typeof vValue);
|
||||||
|
}
|
||||||
|
// loop
|
||||||
|
iCount++;
|
||||||
|
});
|
||||||
|
|
||||||
|
// close object
|
||||||
|
if (sDataType === "array") {
|
||||||
|
sHTML += ("\n" + sIndent + "]");
|
||||||
|
} else {
|
||||||
|
sHTML += ("\n" + sIndent + "}");
|
||||||
|
}
|
||||||
|
|
||||||
|
// return
|
||||||
|
return sHTML;
|
||||||
|
},
|
||||||
|
|
||||||
|
RealTypeOf: function (v) {
|
||||||
|
if (typeof v === "object") {
|
||||||
|
if (v === null) {
|
||||||
|
return "null";
|
||||||
|
}
|
||||||
|
var array = [];
|
||||||
|
if (v.constructor === array.constructor) {
|
||||||
|
return "array";
|
||||||
|
}
|
||||||
|
var date = new Date();
|
||||||
|
if (v.constructor === date.constructor) {
|
||||||
|
return "date";
|
||||||
|
}
|
||||||
|
var regexp = new RegExp();
|
||||||
|
if (v.constructor === regexp.constructor) {
|
||||||
|
return "regex";
|
||||||
|
}
|
||||||
|
return "object";
|
||||||
|
}
|
||||||
|
return typeof v;
|
||||||
}
|
}
|
||||||
|
|
||||||
// return
|
};
|
||||||
return sHTML;
|
}());
|
||||||
},
|
|
||||||
|
|
||||||
RealTypeOf: function (v) {
|
|
||||||
if (typeof v === "object") {
|
|
||||||
if (v === null) {
|
|
||||||
return "null";
|
|
||||||
}
|
|
||||||
var array = [];
|
|
||||||
if (v.constructor === array.constructor) {
|
|
||||||
return "array";
|
|
||||||
}
|
|
||||||
var date = new Date();
|
|
||||||
if (v.constructor === date.constructor) {
|
|
||||||
return "date";
|
|
||||||
}
|
|
||||||
var regexp = new RegExp();
|
|
||||||
if (v.constructor === regexp.constructor) {
|
|
||||||
return "regex";
|
|
||||||
}
|
|
||||||
return "object";
|
|
||||||
}
|
|
||||||
return typeof v;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue