Skip to content

Commit

Permalink
Merge pull request #822 from omittones/improve-frontend-code
Browse files Browse the repository at this point in the history
Fix frontend bugs.
  • Loading branch information
cyberw authored Oct 19, 2019
2 parents 2a0d18a + e47c052 commit c44fa04
Showing 1 changed file with 27 additions and 29 deletions.
56 changes: 27 additions & 29 deletions locust/static/locust.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ $(".close_link").click(function(event) {
$(this).parent().parent().hide();
});

var alternate = false;

$("ul.tabs").tabs("div.panes > div").on("onClick", function(event) {
if (event.target == $(".chart-tab-link")[0]) {
// trigger resizing of charts
Expand Down Expand Up @@ -97,24 +95,37 @@ var sortBy = function(field, reverse, primer){
}

// Sorting by column
var alternate = false; //used by jqote2.min.js
var sortAttribute = "name";
var slaveSortAttribute = "id";
var desc = false;
var report;
$(".stats_label").click(function(event) {
event.preventDefault();
sortAttribute = $(this).attr("data-sortkey");
desc = !desc;

function renderTable(report) {
var totalRow = report.stats.pop();
var sortedStats = (report.stats).sort(sortBy(sortAttribute, desc));
sortedStats.push(totalRow);
$('#stats tbody').empty();
$('#errors tbody').empty();
alternate = false;
totalRow = report.stats.pop();
sortedStats = (report.stats).sort(sortBy(sortAttribute, desc));
sortedStats.push(totalRow);

window.alternate = false;
$('#stats tbody').jqoteapp(stats_tpl, sortedStats);
alternate = false;

window.alternate = false;
$('#errors tbody').jqoteapp(errors_tpl, (report.errors).sort(sortBy(sortAttribute, desc)));

$("#total_rps").html(Math.round(report.total_rps*100)/100);
$("#fail_ratio").html(Math.round(report.fail_ratio*100));
$("#status_text").html(report.state);
$("#userCount").html(report.user_count);
}


$(".stats_label").click(function(event) {
event.preventDefault();
sortAttribute = $(this).attr("data-sortkey");
desc = !desc;
renderTable(window.report);
});

// init charts
Expand All @@ -124,31 +135,18 @@ var usersChart = new LocustLineChart($(".charts-container"), "Number of Users",

function updateStats() {
$.get('./stats/requests', function (report) {
$("#total_rps").html(Math.round(report.total_rps*100)/100);
//$("#fail_ratio").html(Math.round(report.fail_ratio*10000)/100);
$("#fail_ratio").html(Math.round(report.fail_ratio*100));
$("#status_text").html(report.state);
$("#userCount").html(report.user_count);
window.report = report;

renderTable(report);

if (report.slaves) {
slaves = (report.slaves).sort(sortBy(slaveSortAttribute, desc));
$("#slaves tbody").empty();
window.alternate = false;
$("#slaves tbody").jqoteapp(slaves_tpl, slaves);
$("#slaveCount").html(slaves.length);
}

$('#stats tbody').empty();
$('#errors tbody').empty();

alternate = false;

totalRow = report.stats.pop();
sortedStats = (report.stats).sort(sortBy(sortAttribute, desc));
sortedStats.push(totalRow);
$('#stats tbody').jqoteapp(stats_tpl, sortedStats);
alternate = false;
$('#errors tbody').jqoteapp(errors_tpl, (report.errors).sort(sortBy(sortAttribute, desc)));

if (report.state !== "stopped"){
// get total stats row
var total = report.stats[report.stats.length-1];
Expand All @@ -170,4 +168,4 @@ function updateExceptions() {
setTimeout(updateExceptions, 5000);
});
}
updateExceptions();
updateExceptions();

0 comments on commit c44fa04

Please sign in to comment.