///////////////////////////////////////////////////////////////////////////////
/// master.js
/// arangodb js api
///////////////////////////////////////////////////////////////////////////////
var welcomeMSG = ""
+ " _ \n"
+ " __ _ _ __ __ _ _ __ __ _ ___ ___| |__ \n"
+ " / _` | '__/ _` | '_ \\ / _` |/ _ \\/ __| '_ \\ \n"
+ " | (_| | | | (_| | | | | (_| | (_) \\__ \\ | | | \n"
+ " \\__,_|_| \\__,_|_| |_|\\__, |\\___/|___/_| |_| \n"
+ " |___/ \n"
+ " \n"
+ "Welcome to arangosh Copyright (c) 2012 triAGENS GmbH.";
var existingCharts;
var statDivCount;
// documents global vars
var collectionCount;
var totalCollectionCount;
var collectionCurrentPage;
var globalCollectionName;
var globalCollectionID;
var globalCollectionRev;
var checkCollectionName;
var printedHelp = false;
var open = false;
var rowCounter = 0;
var shArray = [];
$(document).ready(function() {
showCursor();
//hide incomplete functions
$("#uploadFile").attr("disabled", "disabled");
$("#uploadFileImport").attr("disabled", "disabled");
$("#uploadFileSearch").attr("disabled", "disabled");
///////////////////////////////////////////////////////////////////////////////
/// global variables
///////////////////////////////////////////////////////////////////////////////
var tableView = true;
var sid = ($.cookie("sid"));
var currentUser;
//logtable vars
var currentPage = 1;
var currentAmount;
var currentTableID = "#logTableID";
var currentLoglevel = 5;
//live click for all log tables
var tables = ["#logTableID", "#critLogTableID", "#warnLogTableID", "#infoLogTableID", "#debugLogTableID"];
$.each(tables, function(v, i ) {
$(i + '_prev').live('click', function () {
if ( i == "#logTableID" ) {
createNextPagination("all");
}
else {
createNextPagination();
}
});
$(i + '_next').live('click', function () {
if ( i == "#logTableID" ) {
createPrevPagination("all");
}
else {
createPrevPagination();
}
});
$(i + '_last').live('click', function () {
createLogTable(currentLoglevel);
});
$(i+ '_first').live('click', function () {
createLastLogPagination(i);
});
});
$("#documents_prev").live('click', function () {
createPrevDocPagination();
});
$("#documents_next").live('click', function () {
createNextDocPagination();
});
$("#documents_first").live('click', function () {
createFirstPagination("#documentsTable");
});
$("#documents_last").live('click', function () {
createLastPagination("#documentsTable");
});
///////////////////////////////////////////////////////////////////////////////
//statistics live click buttons close
///////////////////////////////////////////////////////////////////////////////
$(".statsClose").live('click', function () {
var divID = $(this).parent().parent();
var chart = $(this).parent().parent().attr('id');
var chartID = JSON.parse(chart.replace(/\D/g, '' ));
var todelete;
$.each(existingCharts, function(x, i ) {
var tempid = i.id;
if (tempid == chartID) {
todelete = x;
}
});
existingCharts.splice(todelete, 1);
$("#chartBox"+chartID).remove();
stateSaving();
if (temptop > 150 && templeft > 20) {
templeft = templeft - 10;
temptop = temptop - 10;
}
});
///////////////////////////////////////////////////////////////////////////////
// show statistic settings
///////////////////////////////////////////////////////////////////////////////
$(".statsSettings").live('click', function () {
var chartID = $(this).parent().next("div");
var settingsID = $(this).parent().next("div").next("div");
$(chartID).hide();
$(settingsID).fadeIn();
});
///////////////////////////////////////////////////////////////////////////////
// show statistics charts
///////////////////////////////////////////////////////////////////////////////
$(".statsCharts").live('click', function () {
var chartID = $(this).parent().next("div");
var settingsID = $(this).parent().next("div").next("div");
stateSaving();
updateChartBoxes();
$(settingsID).hide();
$(chartID).fadeIn();
});
///////////////////////////////////////////////////////////////////////////////
/// html customizations
///////////////////////////////////////////////////////////////////////////////
$('#logView ul').append('
');
///////////////////////////////////////////////////////////////////////////////
/// initialize jquery tabs
///////////////////////////////////////////////////////////////////////////////
$("#tabs").tabs({
select: function(event, ui) {
if (ui.index == 0) {
currentLoglevel = 5;
createLogTable(5);
}
else {
currentLoglevel = ui.index;
createLogTable(ui.index);
}
}
});
///////////////////////////////////////////////////////////////////////////////
/// disable grey'd out buttons
///////////////////////////////////////////////////////////////////////////////
$(".nofunction").attr("disabled", "true");
///////////////////////////////////////////////////////////////////////////////
/// checks for a login user cookie, creates new sessions if null
///////////////////////////////////////////////////////////////////////////////
// if ($.cookie("sid") == null) {
// $('#logoutButton').hide();
// $('#movetologinButton').show();
// $.ajax({
// type: "POST",
// url: "/_admin/user-manager/session/",
// contentType: "application/json",
// processData: false,
// success: function(data) {
// $.cookie("sid", data.sid);
// },
// error: function(data) {
// }
// });
// }
///////////////////////////////////////////////////////////////////////////////
/// if user exists, then:
///////////////////////////////////////////////////////////////////////////////
if ($.cookie("rights") != null || $.cookie("user") != null) {
$('#loginWindow').hide();
$('#movetologinButton').hide();
$('#logoutButton').show();
$('#activeUser').text($.cookie("user") + '!');
currentUser = $.cookie("user");
}
else {
$('#logoutButton').hide();
}
///////////////////////////////////////////////////////////////////////////////
/// draws collection table
///////////////////////////////////////////////////////////////////////////////
var collectionTable = $('#collectionsTableID').dataTable({
"aaSorting": [[ 2, "desc" ]],
"bPaginate": false,
"bFilter": false,
"bLengthChange": false,
"bDeferRender": true,
"bAutoWidth": false,
"iDisplayLength": -1,
"bJQueryUI": true,
"aoColumns": [{"sWidth":"150px", "bSortable":false}, {"sWidth": "200px"}, {"sWidth": "200px"}, null, {"sWidth": "200px"}, {"sWidth": "200px"} ],
"aoColumnDefs": [{ "sClass": "alignRight", "aTargets": [ 4, 5 ] }],
"oLanguage": {"sEmptyTable": "No collections"}
});
///////////////////////////////////////////////////////////////////////////////
/// draws the document edit table
///////////////////////////////////////////////////////////////////////////////
var documentEditTable = $('#documentEditTableID').dataTable({
"aaSorting": [[ 1, "desc" ]],
"bAutoWidth": false,
"bFilter": false,
"bPaginate":false,
"bSortable": false,
"bLengthChange": false,
"bDeferRender": true,
"iDisplayLength": -1,
"bJQueryUI": true,
"aoColumns": [{"sClass":"read_only", "bSortable": false, "sWidth": "30px"},
{"sClass":"writeable", "bSortable": false, "sWidth":"400px" },
{"sClass":"writeable", "bSortable": false},
{"bVisible": false } ],
"oLanguage": {"sEmptyTable": "No documents"}
});
///////////////////////////////////////////////////////////////////////////////
/// draws new doc view table
///////////////////////////////////////////////////////////////////////////////
var newDocumentTable = $('#NewDocumentTableID').dataTable({
"bFilter": false,
"bPaginate":false,
"bSortable": false,
"bLengthChange": false,
"bDeferRender": true,
"bAutoWidth": true,
"iDisplayLength": -1,
"bJQueryUI": true,
"aoColumns": [{ "sClass":"center", "sClass":"read_only","bSortable": false, "sWidth": "30px"},
{"sClass":"writeable", "bSortable": false, "sWidth":"250px" },
{"sClass":"writeable", "bSortable": false },
{"bVisible": false } ]
});
///////////////////////////////////////////////////////////////////////////////
/// draws documents table
///////////////////////////////////////////////////////////////////////////////
var documentsTable = $('#documentsTableID').dataTable({
"bFilter": false,
"bPaginate":false,
"bSortable": false,
"bLengthChange": false,
"bDeferRender": true,
"bAutoWidth": false,
"iDisplayLength": -1,
"bJQueryUI": true,
"aoColumns": [{ "sClass":"read_only", "bSortable": false, "sWidth":"80px"},
{ "sClass":"read_only","bSortable": false, "sWidth": "200px"},
{ "sClass":"read_only","bSortable": false, "sWidth": "100px"},
{ "bSortable": false, "sClass": "cuttedContent"}],
"oLanguage": { "sEmptyTable": "No documents"}
});
///////////////////////////////////////////////////////////////////////////////
/// draws crit log table
///////////////////////////////////////////////////////////////////////////////
var critLogTable = $('#critLogTableID').dataTable({
"bFilter": false,
"bPaginate":false,
"bLengthChange": false,
"bDeferRender": true,
"bAutoWidth": true,
"iDisplayLength": -1,
"bJQueryUI": true,
"aoColumns": [{ "sClass":"center", "sWidth": "100px", "bSortable":false}, {"bSortable":false}],
"oLanguage": {"sEmptyTable": "No critical logfiles available"}
});
///////////////////////////////////////////////////////////////////////////////
/// draws warn log table
///////////////////////////////////////////////////////////////////////////////
var warnLogTable = $('#warnLogTableID').dataTable({
"bFilter": false,
"bPaginate":false,
"bLengthChange": false,
"bDeferRender": true,
"bAutoWidth": true,
"iDisplayLength": -1,
"bJQueryUI": true,
"aoColumns": [{ "sClass":"center", "sWidth": "100px", "bSortable":false}, {"bSortable":false}],
"oLanguage": {"sEmptyTable": "No warning logfiles available"}
});
///////////////////////////////////////////////////////////////////////////////
/// draws info log table
///////////////////////////////////////////////////////////////////////////////
var infoLogTable = $('#infoLogTableID').dataTable({
"bFilter": false,
"bPaginate":false,
"bLengthChange": false,
"bDeferRender": true,
"bAutoWidth": true,
"iDisplayLength": -1,
"bJQueryUI": true,
"aoColumns": [{ "sClass":"center", "sWidth": "100px", "bSortable":false}, {"bSortable":false}],
"oLanguage": {"sEmptyTable": "No info logfiles available"}
});
///////////////////////////////////////////////////////////////////////////////
/// draws debug log table
///////////////////////////////////////////////////////////////////////////////
var debugLogTable = $('#debugLogTableID').dataTable({
"bFilter": false,
"bPaginate":false,
"bLengthChange": false,
"bDeferRender": true,
"bAutoWidth": true,
"iDisplayLength": -1,
"bJQueryUI": true,
"aoColumns": [{ "sClass":"center", "sWidth": "100px", "bSortable":false}, {"bSortable":false}],
"oLanguage": {"sEmptyTable": "No debug logfiles available"}
});
///////////////////////////////////////////////////////////////////////////////
/// draws "all" log table
///////////////////////////////////////////////////////////////////////////////
var logTable = $('#logTableID').dataTable({
"bFilter": false,
"bPaginate":false,
"bLengthChange": false,
"bDeferRender": true,
"bAutoWidth": true,
"iDisplayLength": -1,
"bJQueryUI": true,
"aoColumns": [{ "sClass":"center", "sWidth": "100px", "bSortable":false}, {"bSortable":false}],
"oLanguage": {"sEmptyTable": "No logfiles available"}
});
///////////////////////////////////////////////////////////////////////////////
/// creates layout using jquery ui
///////////////////////////////////////////////////////////////////////////////
$('body').layout({
closable: false,
resizable: false,
applyDefaultStyles: false,
north__spacing_open:0,
north__spacing_closed: 0,
center__spacing_open:0,
center__spacing_open:0,
south__spacing_closed: 0,
south__spacing_closed: 0
});
///////////////////////////////////////////////////////////////////////////////
/// location check
///////////////////////////////////////////////////////////////////////////////
$.address.change(function(event) {
///////////////////////////////////////////////////////////////////////////////
/// Home
///////////////////////////////////////////////////////////////////////////////
if (location.hash == '' || location.hash =='#') {
drawCollectionsTable();
$('#subCenterView').hide();
$('#centerView').show();
$('#collectionsView').show();
createnav("Collections");
highlightNav("#nav1");
}
///////////////////////////////////////////////////////////////////////////////
/// new document table view (collection)
///////////////////////////////////////////////////////////////////////////////
else if (location.hash.substr(0, 12) == "#collection?" ) {
$("#addNewDocButton").removeAttr("disabled");
tableView = true;
$('#toggleNewDocButtonText').text('Edit Source');
var collectionID = location.hash.substr(12, location.hash.length);
var collID = collectionID.split("=");
$.ajax({
type: "GET",
url: "/_api/collection/" + collID[0],
contentType: "application/json",
processData: false,
success: function(data) {
collectionName = data.name;
$('#nav2').text(collectionName);
$('#nav2').attr('href', '#showCollection?' +collID[0]);
$('#nav1').attr('class', 'arrowbg');
},
error: function(data) {
}
});
$('#nav1').text('Collections');
$('#nav1').attr('href', '#');
$('#nav2').attr('class', 'arrowbg');
$('#nav3').text('new document');
highlightNav("#nav3");
newDocumentTable.fnClearTable();
documentTableMakeEditable('#NewDocumentTableID');
hideAllSubDivs();
$('#collectionsView').hide();
$('#newDocumentView').show();
$('#NewDocumentTableView').show();
$('#NewDocumentSourceView').hide();
}
///////////////////////////////////////////////////////////////////////////////
/// showe edit documents view
///////////////////////////////////////////////////////////////////////////////
else if (location.hash.substr(0, 14) == "#editDocument?") {
tableView = true;
$("#addEditedDocRowButton").removeAttr("disabled");
$('#toggleEditedDocButton').val('Edit Source');
$('#toggleEditedDocButtonText').text('Edit Source');
$('#documentEditSourceView').hide();
$('#documentEditTableView').show();
var collectiondocID = location.hash.substr(14, location.hash.length);
collectionID = collectiondocID.split("/");
$.ajax({
type: "GET",
url: "/_api/collection/" + collectionID,
contentType: "application/json",
processData: false,
success: function(data) {
collectionName = data.name;
$('#nav2').text(collectionName);
$('#nav2').attr('href', '#showCollection?' +collectionID[0]);
},
error: function(data) {
}
});
$('#nav1').text('Collections');
$('#nav1').attr('href', '#');
$('#nav1').attr('class', 'arrowbg');
$('#nav2').attr('class', 'arrowbg');
$('#nav3').text('Edit document:' + collectionID[1]);
$.ajax({
type: "GET",
url: "/_api/document/" + collectiondocID,
contentType: "application/json",
processData: false,
success: function(data) {
$('#documentEditSourceBox').val(JSON.stringify(data));
documentEditTable.fnClearTable();
hideAllSubDivs();
$('#collectionsView').hide();
$('#documentEditView').show();
$('#documentEditSourceView').hide();
$.each(data, function(key, val) {
if (key == '_id') {
documentEditTable.fnAddData(["", key, val, JSON.stringify(val)]);
}
else if (key == '_rev') {
documentEditTable.fnAddData(["", key, val, JSON.stringify(val)]);
}
else if (key != '_rev' && key != '_id') {
documentEditTable.fnAddData(['',key, value2html(val), JSON.stringify(val)]);
}
});
documentTableMakeEditable('#documentEditTableID');
showCursor();
},
error: function(data) {
}
});
}
///////////////////////////////////////////////////////////////////////////////
/// show colletions documents view
///////////////////////////////////////////////////////////////////////////////
else if (location.hash.substr(0, 16) == "#showCollection?") {
$('#nav1').removeClass('highlighted');
var collectionID = location.hash.substr(16, location.hash.length);
globalAjaxCursorChange();
$.ajax({
type: "GET",
url: "/_api/collection/" + collectionID + "/count",
contentType: "application/json",
processData: false,
async: false,
success: function(data) {
globalCollectionName = data.name;
test = data.name;
collectionCount = data.count;
$('#nav2').text(globalCollectionName);
},
error: function(data) {
}
});
$('#nav1').text('Collections');
$('#nav1').attr('href', '#');
$('#nav2').attr('href', null);
$('#nav3').text('');
highlightNav("#nav2");
$("#nav3").removeClass("arrowbg");
$("#nav2").removeClass("arrowbg");
$("#nav1").addClass("arrowbg");
$.ajax({
type: 'PUT',
url: '/_api/simple/all/',
data: '{"collection":"' + globalCollectionName + '","skip":0,"limit":10}',
contentType: "application/json",
success: function(data) {
$.each(data.result, function(k, v) {
documentsTable.fnAddData(['', v._id, v._rev, '' + cutByResolution(JSON.stringify(v)) + "
"]);
});
$(".prettify").snippet("javascript", {style: "nedit", menu: false, startText: false, transparent: true, showNum: false});
showCursor();
},
error: function(data) {
}
});
documentsTable.fnClearTable();
hideAllSubDivs();
$('#collectionsView').hide();
$('#documentsView').show();
totalCollectionCount = Math.ceil(collectionCount / 10);
collectionCurrentPage = 1;
$('#documents_status').text("Showing page 1 of " + totalCollectionCount);
}
///////////////////////////////////////////////////////////////////////////////
/// shows edit collection view
///////////////////////////////////////////////////////////////////////////////
else if (location.hash.substr(0, 16) == "#editCollection?") {
var collectionID = location.hash.substr(16, location.hash.length);
var collectionName;
var tmpStatus;
$.ajax({
type: "GET",
url: "/_api/collection/" + collectionID,
contentType: "application/json",
processData: false,
success: function(data) {
collectionName = data.name;
$('#nav2').text('Edit: ' + collectionName);
$('#editCollectionName').val(data.name);
$('#editCollectionID').text(data.id);
switch (data.status) {
case 1: tmpStatus = "new born collection"; break;
case 2: tmpStatus = "unloaded"; break;
case 3: tmpStatus = "loaded"; break;
case 4: tmpStatus = "in the process of being unloaded"; break;
case 5: tmpStatus = "deleted"; break;
}
$('#editCollectionStatus').text(tmpStatus);
checkCollectionName = collectionName;
},
error: function(data) {
}
});
$('#nav1').text('Collections');
$('#nav1').attr('href', '#');
$('#nav1').attr('class', 'arrowbg');
hideAllSubDivs();
$('#collectionsView').hide();
$('#editCollectionView').show();
$('#editCollectionName').focus();
}
///////////////////////////////////////////////////////////////////////////////
/// shows log view
///////////////////////////////////////////////////////////////////////////////
else if (location.hash == "#logs") {
createLogTable(5);
hideAllSubDivs();
$('#collectionsView').hide();
$('#logView').show();
createnav ("Logs");
showCursor();
}
///////////////////////////////////////////////////////////////////////////////
/// shows status view
///////////////////////////////////////////////////////////////////////////////
else if (location.hash == "#status") {
$('#graphBox').empty();
stateReading();
hideAllSubDivs();
$('#collectionsView').hide();
$('#statusView').show();
createnav ("Statistics");
makeDraggableAndResizable();
//TODO
createChartBoxes();
updateGraphs();
}
///////////////////////////////////////////////////////////////////////////////
/// shows config view
///////////////////////////////////////////////////////////////////////////////
else if (location.hash == "#config") {
hideAllSubDivs();
$('#configContent').empty();
$('#collectionsView').hide();
$('#configView').show();
createnav ("Configuration");
var switcher = "primary";
var insertType;
$.ajax({
type: "GET", url: "/_admin/config/description",contentType: "application/json", processData: false, async: false,
success: function(data) {
$.each(data, function(key, val) {
if (key == "error" || key == "code") {
}
else {
$('#configContent').append('' + val.name + '
');
$.each(val, function(k, v) {
if (v.name != undefined) {
switch(v.type) {
case 'integer':
if (v.readonly == true) {
insertType = '123456'; break;
}
else {
insertType = '123456'; break;
}
case 'string':
if (v.readonly == true) {
insertType = 'string'; break;
}
else {
insertType = 'string'; break;
}
case 'pull-down':
insertType = '';
break;
case 'boolean':
insertType = '