/** * General Interface Actions */ $(document).ready( function() { var message = false; if($('#editor').length > 0) { var editor = ace.edit("editor"); editor.getSession().setMode("ace/mode/json"); editor.setTheme("ace/theme/twilight"); // This formats the JSON all pretty like var val = editor.session.getValue() var o = JSON.parse(val) // may throw if json is malformed val = JSON.stringify(o, null, 4) // 4 is the indent size editor.session.setValue(val) } if($('#message').html() != '') { $('#message').fadeIn(); message = setTimeout(function() { $("#message").fadeOut(400) }, 5000); } $('#run-test').click(function() { $('form').submit() }); $('form').submit(function(e) { // Stop form from submitting normally e.preventDefault(); // Get some values from elements on the page: var $form = $( this ), json = editor.getValue(); url = $form.attr( "action" ); // Send the data using post var posting = $.post( url, { json: json } ); clearTimeout(message); $("#message").fadeIn(); $("#message").empty().append(' Processing ...'); $('.btn').attr('disabled', true); // Put the results in a div posting.done(function( data ) { $("#message").fadeIn(); $("#message").empty().append(data); $('.btn').attr('disabled', false); message = setTimeout(function() { $("#message").fadeOut(400) }, 5000); }); }); $('#controller-start').click(function(e) { e.preventDefault(); ajaxCall('/webapp-controllerstart'); }); $('#controller-stop').click(function(e) { e.preventDefault(); ajaxCall('/webapp-controllerstop'); }); $('#controller-restart').click(function(e) { e.preventDefault(); ajaxCall('/webapp-controllerrestart'); }); $('#controller-clear').click(function(e) { e.preventDefault(); ajaxCall('/webapp-controllerclear'); }); $('#injector-start').click(function(e) { e.preventDefault(); ajaxCall('/webapp-injectorstart'); }); $('#injector-stop').click(function(e) { e.preventDefault(); ajaxCall('/webapp-injectorstop'); }); $('#injector-restart').click(function(e) { e.preventDefault(); ajaxCall('/webapp-injectorrestart'); }); $('#injector-clear').click(function(e) { e.preventDefault(); ajaxCall('/webapp-injectorclear'); }); $('#browsermob-start').click(function(e) { e.preventDefault(); ajaxCall('/webapp-browsermobstart'); }); $('#browsermob-stop').click(function(e) { e.preventDefault(); ajaxCall('/webapp-browsermobstop'); }); $('#reporting-start').click(function(e) { e.preventDefault(); ajaxCall('/webapp-reportingstart'); }); $('#reporting-stop').click(function(e) { e.preventDefault(); ajaxCall('/webapp-reportingstop'); }); $('#reporting-restart').click(function(e) { e.preventDefault(); ajaxCall('/webapp-reportingrestart'); }); $('#reporting-clear').click(function(e) { e.preventDefault(); ajaxCall('/webapp-reportingclear'); }); $('#memcache-start').click(function(e) { e.preventDefault(); $('#memcache-start').fadeTo(0, 0.3); ajaxCall('/webapp-memcachestart'); }); $('#memcache-stop').click(function(e) { e.preventDefault(); $('#memcache-stop').fadeTo(0, 0.3); ajaxCall('/webapp-memcachestop'); }); function ajaxCall(url) { clearTimeout(message); $("#message").fadeIn(); $("#message").empty().append(' Processing ...'); $('.btn').attr('disabled', true); if(url.match('controller')) { $('#controller-start, #controller-stop, #controller-restart, #controller-clear').fadeTo(0, 0.3); } if(url.match('injector')) { $('#injector-start, #injector-stop, #injector-restart, #injector-clear').fadeTo(0, 0.3); } if(url.match('reporting')) { $('#reporting-start, #reporting-stop, #reporting-restart, #reporting-clear').fadeTo(0, 0.3); } $.ajax({ url: url, async: true }) .done(function( msg ) { $("#message").fadeIn(); $("#message").empty().append(msg); $('.btn').attr('disabled', false); message = setTimeout(function() { $("#message").fadeOut(400) }, 5000); }); } $('#expand-editor').click(function(e) { e.preventDefault(); if($('#expand-editor').text() == 'Expand Editor') { $('#editor').height(770); $('#expand-editor').text('Shrink Editor'); ace.edit("editor").resize(); } else { $('#editor').height(50); $('#expand-editor').text('Expand Editor') ace.edit("editor").resize(); } }); $('.capture-image').click(function(e) { e.preventDefault(); if($(this).attr('expanded') == 'true') { $(this).css('width', '50%'); $(this).attr('expanded', 'false'); } else { $(this).css('width', '100%'); $(this).attr('expanded', 'true'); } }); //Definition of the function (non-global, because of the previous line) function reload(){ $( "#controller" ).load( "/webapp-controllerlog" ); $( "#injector" ).load( "/webapp-injectorlog" ); $( "#reporting" ).load( "/webapp-reportinglog" ); } //set an interval setInterval(reload, 4000); //Call the function reload(); google.charts.load('44', {'packages':['gauge']}); google.charts.setOnLoadCallback(drawChart); function drawChart() { var data = google.visualization.arrayToDataTable([ ['Label', 'Value'], ['Controller', 0], ['Injector', 0], ['Reports', 0] ]); var options = { width: 400, height: 120, greenFrom: 0, greenTo: 50, yellowFrom:50, yellowTo: 150, redFrom: 150, redTo: 200, minorTicks: 10, max : 200 }; var chart = new google.visualization.Gauge(document.getElementById('chart_div')); chart.draw(data, options); function updateGaugeChart() { $.ajax({ url: "/webapp-gauge", dataType: "json", async: true }).done(function( jsonData ) { var data = google.visualization.arrayToDataTable(jsonData); chart.draw(data, options); setTimeout(updateGaugeChart, 1000) }); } updateGaugeChart(); // Update status function updateGeneralStatus() { $.ajax({ url: "/webapp-stats", dataType: "json", async: true }).done(function( jsonData ) { $('#statusMemcache').addClass('glyphicon-remove-sign').removeClass('glyphicon-ok-sign glyphicon-question-sign'); $('#statusController').addClass('glyphicon-remove-sign').removeClass('glyphicon-ok-sign glyphicon-question-sign'); $('#statusInjector').addClass('glyphicon-remove-sign').removeClass('glyphicon-ok-sign glyphicon-question-sign'); $('#statusReporting').addClass('glyphicon-remove-sign').removeClass('glyphicon-ok-sign glyphicon-question-sign'); $('#statusBrowserMob').addClass('glyphicon-remove-sign').removeClass('glyphicon-ok-sign glyphicon-question-sign'); $('#statusMemcachedInstalled').addClass('glyphicon-remove-sign').removeClass('glyphicon-ok-sign glyphicon-question-sign'); $('#statusBrowserMobInstalled').addClass('glyphicon-remove-sign').removeClass('glyphicon-ok-sign glyphicon-question-sign'); if(jsonData.statusMemcachedInstalled == true) { $('#statusMemcachedInstalled').addClass('glyphicon-ok-sign').removeClass('glyphicon-remove-sign glyphicon-question-sign'); } if(jsonData.statusBrowserMobInstalled != false) { $('#statusBrowserMobInstalled').addClass('glyphicon-ok-sign').removeClass('glyphicon-remove-sign glyphicon-question-sign'); } if(jsonData.statusQueueCount) { $('#statusQueueCountContent').empty().append(jsonData.statusQueueCount); } else { $('#statusQueueCountContent').empty().append('Not Loaded'); } if(jsonData.statusMemcache == true) { $('#statusMemcache').addClass('glyphicon-ok-sign').removeClass('glyphicon-remove-sign glyphicon-question-sign'); $('#memcache-start').hide(); $('#memcache-stop').fadeTo(0, 1); } else { $('#memcache-start').fadeTo(0, 1); $('#memcache-stop').hide(); } if(jsonData.statusController == true) { $('#statusController').addClass('glyphicon-ok-sign').removeClass('glyphicon-remove-sign glyphicon-question-sign'); $('#controller-start').fadeTo(0, 0.3); $('#controller-stop').fadeTo(0, 1); $('#controller-restart').fadeTo(0, 1); $('#controller-clear').fadeTo(0, 1); } else { $('#controller-start').fadeTo(0, 1); $('#controller-stop').fadeTo(0, 0.3); $('#controller-restart').fadeTo(0, 0.3); $('#controller-clear').fadeTo(0, 1); } if(jsonData.statusInjector == true) { $('#statusInjector').addClass('glyphicon-ok-sign').removeClass('glyphicon-remove-sign glyphicon-question-sign'); $('#injector-start').fadeTo(0, 0.3); $('#injector-stop').fadeTo(0, 1); $('#injector-restart').fadeTo(0, 1); $('#injector-clear').fadeTo(0, 1); } else { $('#injector-start').fadeTo(0, 1); $('#injector-stop').fadeTo(0, 0.3); $('#injector-restart').fadeTo(0, 0.3); $('#injector-clear').fadeTo(0, 1); } if(jsonData.statusReporting == true) { $('#statusReporting').addClass('glyphicon-ok-sign').removeClass('glyphicon-remove-sign glyphicon-question-sign'); $('#reporting-start').fadeTo(0, 0.3); $('#reporting-stop').fadeTo(0, 1); $('#reporting-restart').fadeTo(0, 1); $('#reporting-clear').fadeTo(0, 1); } else { $('#reporting-start').fadeTo(0, 1); $('#reporting-stop').fadeTo(0, 0.3); $('#reporting-restart').fadeTo(0, 0.3); $('#reporting-clear').fadeTo(0, 1); } if(jsonData.statusBrowserMob == true) { $('#statusBrowserMob').addClass('glyphicon-ok-sign').removeClass('glyphicon-remove-sign glyphicon-question-sign'); $('#browsermob-start').hide(); $('#browsermob-stop').fadeTo(0, 1); } else { $('#browsermob-start').fadeTo(0, 1); $('#browsermob-stop').hide(); } setTimeout(updateGeneralStatus, 5000) }); } updateGeneralStatus(); } (function(){ // Create jQuery body object var $body = $('.modal-body'), // Use a tags with 'class="modalTrigger"' as the triggers $modalTriggers = $('a.modalTrigger'); // Trigger event handler openModal = function(evt) { var $trigger = $(this), // Trigger jQuery object modalPath = $trigger.attr('href'), // Modal path is href of trigger $newModal, // Declare modal variable removeModal = function(evt) { // Remove modal handler //$newModal.off('hidden.bs.modal'); // Turn off 'hide' event //$newModal.remove(); // Remove modal from DOM }, showModal = function(data) { // Ajax complete event handler $body.empty(); $body.append(data); // Add to DOM $newModal = $('.modal').last(); // Modal jQuery object $newModal.modal('show'); // Showtime! $newModal.on('hidden.bs.modal',removeModal); // Remove modal from DOM on hide }; $.get(modalPath,showModal); // Ajax request evt.preventDefault(); // Prevent default a tag behavior }; $modalTriggers.on('click',openModal); // Add event handlers }()); }); function copyToClipboard(elem) { // create hidden text element, if it doesn't already exist var targetId = "_hiddenCopyText_"; var isInput = elem.tagName === "INPUT" || elem.tagName === "TEXTAREA"; var origSelectionStart, origSelectionEnd; if (isInput) { // can just use the original source element for the selection and copy target = elem; origSelectionStart = elem.selectionStart; origSelectionEnd = elem.selectionEnd; } else { // must use a temporary form element for the selection and copy target = document.getElementById(targetId); if (!target) { var target = document.createElement("textarea"); target.style.position = "absolute"; target.style.left = "-9999px"; target.style.top = "0"; target.id = targetId; document.body.appendChild(target); } target.textContent = elem.textContent; } // select the content var currentFocus = document.activeElement; target.focus(); target.setSelectionRange(0, target.value.length); // copy the selection var succeed; try { succeed = document.execCommand("copy"); } catch(e) { succeed = false; } // restore original focus if (currentFocus && typeof currentFocus.focus === "function") { currentFocus.focus(); } if (isInput) { // restore prior selection elem.setSelectionRange(origSelectionStart, origSelectionEnd); } else { // clear temporary content target.textContent = ""; } return succeed; }