Skip to content

Commit

Permalink
Merge pull request #10 from netooran/master
Browse files Browse the repository at this point in the history
Option to filter errors by error type
  • Loading branch information
JD authored Mar 5, 2020
2 parents a0d943c + ba76a1f commit de57fde
Show file tree
Hide file tree
Showing 3 changed files with 188 additions and 132 deletions.
7 changes: 6 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,15 @@ <h1 class="summary-header" style="text-align: center; margin-bottom: 15px">Error
<div class="limiter1">

<div class="dropdown">
<p> Display for file: </p>
<p> Display for: </p>
<label for="files">File Name: </label>
<select id="files">
<option value="all" selected="selected">All</option>
</select>
<label for="error-types">Error type: </label>
<select id="error-types">
<option value="all" selected="selected">All</option>
</select>
</div>
<div class="container-table100">
<div class="wrap-table100">
Expand Down
89 changes: 62 additions & 27 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,46 +41,81 @@ jQuery(document).ready(function($) {

})

$("#files").change(function() {
function applyFileNameFilter(errors, fileName) {
if (fileName === "all") return errors;
return errors.filter(error => error.filename === fileName);
}

function applyErrorTypeFilter(errors, errorType) {
if (errorType === "all") return errors;
return errors.map(error => {
const errorClone = JSON.parse(JSON.stringify(error));
errorClone.failure_list = error.failure_list.filter(
failure => failure.type === errorType
);
return errorClone;
});
}

function applyFilters(errors, selectedfilename, selectedErrorType) {
return applyErrorTypeFilter(
applyFileNameFilter(errors, selectedfilename),
selectedErrorType
);
}

function onFilterChange() {
var selectedfilename = $('#files').val()
var selectedErrorType = $('#error-types').val()

$.getJSON( "../data/report.json", function(jsondata) {
$('#errors').pagination('hide')
$('.limiter1 tbody').empty()
table_det = "<table class='lightbox-err'><tr><th style='font-weight: bold'>Serial Number</th><th style='font-weight: bold'>Git Commmit SHA</th></tr>";
for (var row_num=0; row_num<jsondata.results.length; row_num++){
var commit_table = "";
var filename = jsondata.results[row_num].filename;
if (selectedfilename == 'all') {
$('#errors').pagination('show')
window.location.reload(true)
return
}
if (filename == selectedfilename || selectedfilename == 'all') {
for(var failure_num=0; failure_num<jsondata.results[row_num].failure_list.length; failure_num++){
var errorType = jsondata.results[row_num].failure_list[failure_num].type;
var errorMessage = jsondata.results[row_num].failure_list[failure_num].message;
var commitIDs = jsondata.results[row_num].failure_list[failure_num].commits;
}

var filteredErrors = applyFilters(jsondata.results, selectedfilename, selectedErrorType);

if (selectedfilename == "all" && selectedErrorType == 'all') {
$("#errors").pagination("show");
window.location.reload(true);
return;
}

for (var row_num=0; row_num < filteredErrors.length; row_num++){
const error = filteredErrors[row_num];
var filename = error.filename;

for(var failure_num=0; failure_num < error.failure_list.length; failure_num++){
var errorType = error.failure_list[failure_num].type;
var errorMessage = error.failure_list[failure_num].message;
var commitIDs = error.failure_list[failure_num].commits;

$(".limiter1 tbody").append(`
<tr class="row100">
<td class="column100 column1" data-column="column1">${filename}</td>
<td class="column100 column2" data-column="column2">${errorType}</td>
<td class="column100 column3" data-column="column3"><div>${errorMessage}</div></td>
<td class="column100 column4" data-column="column4">
<a href="#" data-featherlight="#commit-details-${row_num}">${commitIDs.length}</a>
</td>
</tr>`);

$('.limiter1 tbody').append('<tr class="row100"><td class="column100 column1" data-column="column1">' + filename +
'</td><td class="column100 column2" data-column="column2">' + errorType +
'</td><td class="column100 column3" data-column="column3"><div>' + errorMessage +
'</div></td><td class="column100 column4" data-column="column4"><a href="#" data-featherlight="#commit-details-' + row_num + '">' + commitIDs.length +
'</a></td></tr>');
var commit_table = "";
for(var commitID_row_index=0; commitID_row_index<commitIDs.length; commitID_row_index++){
commit_table = commit_table.concat('<tr><td>' + (commitID_row_index+1) + '</td><td>' + commitIDs[commitID_row_index] + '</td></tr>');
for(var commitID_row_index=0; commitID_row_index < commitIDs.length; commitID_row_index++){
commit_table = commit_table.concat(`<tr><td>${ commitID_row_index + 1 }</td><td>${ commitIDs[commitID_row_index] }</td></tr>`);
}

$('#lightbox-det').append('<div id="commit-details-' + row_num +'"> '+ table_det + commit_table + '</table></div>');
}
}
}
}
})
})
}

$("#files").change(onFilterChange);
$("#error-types").change(onFilterChange);

var owl = $("#owl-testimonials");

owl.owlCarousel({
owl.owlCarousel({

pagination : true,
paginationNumbers: false,
Expand Down
224 changes: 120 additions & 104 deletions js/parser.js
Original file line number Diff line number Diff line change
@@ -1,104 +1,120 @@
$(document).ready(function() {

// Number of total records
// Page size
// page number

$.getJSON('../data/report.json', function(jd) {
total_filecontent = jd.summary.types.filecontent || 0;
total_filesize = jd.summary.types.filesize || 0;
total_filename = jd.summary.types.filename || 0;

$('.pricing-table .price .green')
.append('<p><span></span>' + total_filecontent + '</p>');
$('.pricing-table .price .red')
.append('<p><span></span>' + total_filesize + '</p>');
$('.pricing-table .price .yellow')
.append('<p><span></span>' + total_filename + '</p>');

var filename;
var totalErrors;
var totalWarnings;
var commitIDs;

var detailedFailures = jd.results;

var totalRecords=detailedFailures.length;
var pageSize = 5;
var pageNumber = 1;

$('#detailed-report').pagination({

dataSource: detailedFailures,
pageSize: 8,
className: 'paginationjs-theme-red',
callback: function(data, pagination) {
$('.limiter tbody').empty();
table_det = "<table class='lightbox-err'><tr><th style='font-weight: bold'>Serial Number</th><th style='font-weight: bold'>Git Commmit SHA</th></tr>";
for (var row_num=0; row_num<data.length; row_num++){
filename = data[row_num].filename;
totalErrors = data[row_num].failure_list.length;
totalWarnings = data[row_num].warning_list == null ? "No Warnings" : data[row_num].warning_list.length;

$('.limiter tbody').append('<tr class="row100" id="' + filename + '"><td class="column100 column1" data-column="column1">' + filename +
'</td><td class="column100 column2" data-column="column2"><a href="#summary">' + totalErrors +
'</a></td><td class="column100 column3" data-column="column3">' + totalWarnings +
'</td></tr>');
}
}
})

$('.limiter tbody').on('click', 'tr', function(){

$("#files").val(this.id)
$("#files").trigger("change")
var targetOffset = $(errors).offset().top - 50
$('html,body').animate({ scrollTop: targetOffset }, 100);
})

$('#errors').pagination({
dataSource: detailedFailures,
pageSize: 8,
className: 'paginationjs-theme-red',
callback: function(data, pagination) {
$('.limiter1 tbody').empty();
$('#lightbox-det').empty();

table_det = "<table class='lightbox-err'><tr><th style='font-weight: bold'>Serial Number</th><th style='font-weight: bold'>Git Commmit SHA</th></tr>";
for (var row_num=0; row_num<data.length; row_num++){
var commit_table = "";
filename = data[row_num].filename;

for(var failure_num=0; failure_num<data[row_num].failure_list.length; failure_num++){
errorType = data[row_num].failure_list[failure_num].type;
errorMessage = data[row_num].failure_list[failure_num].message;
commitIDs = data[row_num].failure_list[failure_num].commits;
}

$('.limiter1 tbody').append('<tr class="row100"><td class="column100 column1" data-column="column1">' + filename +
'</td><td class="column100 column2" data-column="column2">' + errorType +
'</td><td class="column100 column3" data-column="column3"><div>' + errorMessage +
'</div></td><td class="column100 column4" data-column="column4"><a href="#" data-featherlight="#commit-details-' + row_num + '">' + commitIDs.length +
'</a></td></tr>');
var commit_table = "";
for(var commitID_row_index=0; commitID_row_index<commitIDs.length; commitID_row_index++){
commit_table = commit_table.concat('<tr><td>' + (commitID_row_index+1) + '</td><td>' + commitIDs[commitID_row_index] + '</td></tr>');
}

$('#lightbox-det').append('<div id="commit-details-' + row_num +'"> '+ table_det + commit_table + '</table></div>');
}
}
})

// Populate drop down
var dropdownFiles = document.getElementById("files");
for (var row_num=0; row_num<detailedFailures.length; row_num++){
var option = document.createElement("option");
filename = detailedFailures[row_num].filename;
option.text = filename;
option.setAttribute("id", filename);
console.log(option);
dropdownFiles.add(option);
}
});
});
$(document).ready(function() {
// Number of total records
// Page size
// page number

function populateDropdown(el, data) {
var dropdown = document.getElementById(el);
for (var row_num = 0; row_num < data.length; row_num++) {
var option = document.createElement("option");
row_value = data[row_num];
option.text = row_value;
option.setAttribute("id", row_value);
console.log(option);
dropdown.add(option);
}
}

$.getJSON("../data/report.json", function(jd) {
total_filecontent = jd.summary.types.filecontent || 0;
total_filesize = jd.summary.types.filesize || 0;
total_filename = jd.summary.types.filename || 0;

$(".pricing-table .price .green").append("<p><span></span>" + total_filecontent + "</p>");
$(".pricing-table .price .red").append("<p><span></span>" + total_filesize + "</p>");
$(".pricing-table .price .yellow").append("<p><span></span>" + total_filename + "</p>");

var filename;
var totalErrors;
var totalWarnings;
var commitIDs;

var detailedFailures = jd.results;

var totalRecords = detailedFailures.length;
var pageSize = 5;
var pageNumber = 1;

$("#detailed-report").pagination({
dataSource: detailedFailures,
pageSize: 8,
className: "paginationjs-theme-red",
callback: function(data, pagination) {
$(".limiter tbody").empty();
table_det =
"<table class='lightbox-err'><tr><th style='font-weight: bold'>Serial Number</th><th style='font-weight: bold'>Git Commmit SHA</th></tr>";
for (var row_num = 0; row_num < data.length; row_num++) {
filename = data[row_num].filename;
totalErrors = data[row_num].failure_list.length;
totalWarnings = data[row_num].warning_list == null ? "No Warnings" : data[row_num].warning_list.length;

$(".limiter tbody").append(
'<tr class="row100" id="' + filename +
'"><td class="column100 column1" data-column="column1">' + filename +
'</td><td class="column100 column2" data-column="column2"><a href="#summary">' + totalErrors +
'</a></td><td class="column100 column3" data-column="column3">' + totalWarnings +
"</td></tr>"
);
}
}
});

$(".limiter tbody").on("click", "tr", function() {
$("#files").val(this.id);
$("#files").trigger("change");
var targetOffset = $(errors).offset().top - 50;
$("html,body").animate({ scrollTop: targetOffset }, 100);
});

$("#errors").pagination({
dataSource: detailedFailures,
pageSize: 8,
className: "paginationjs-theme-red",
callback: function(data, pagination) {
$(".limiter1 tbody").empty();
$("#lightbox-det").empty();

table_det = "<table class='lightbox-err'><tr><th style='font-weight: bold'>Serial Number</th><th style='font-weight: bold'>Git Commmit SHA</th></tr>";
for (var row_num = 0; row_num < data.length; row_num++) {
var commit_table = "";
filename = data[row_num].filename;

for (var failure_num = 0; failure_num < data[row_num].failure_list.length; failure_num++) {
errorType = data[row_num].failure_list[failure_num].type;
errorMessage = data[row_num].failure_list[failure_num].message;
commitIDs = data[row_num].failure_list[failure_num].commits;
}

$(".limiter1 tbody").append(
'<tr class="row100"><td class="column100 column1" data-column="column1">' + filename +
'</td><td class="column100 column2" data-column="column2">' + errorType +
'</td><td class="column100 column3" data-column="column3"><div>' + errorMessage +
'</div></td><td class="column100 column4" data-column="column4"><a href="#" data-featherlight="#commit-details-' + row_num + '">' + commitIDs.length +
"</a></td></tr>"
);
var commit_table = "";
for (var commitID_row_index = 0; commitID_row_index < commitIDs.length; commitID_row_index++) {
commit_table = commit_table.concat("<tr><td>" + (commitID_row_index + 1) + "</td><td>" + commitIDs[commitID_row_index] + "</td></tr>");
}

$("#lightbox-det").append('<div id="commit-details-' + row_num + '"> ' + table_det + commit_table + "</table></div>");
}
}
});

// Populate error filters
const fileNames = detailedFailures.map(failure => failure.filename);
const errorTypes = [
...new Set(
detailedFailures
.map(detailedFailure =>
detailedFailure.failure_list.map(failure => failure.type)
)
.flat()
)
];

populateDropdown("files", fileNames);
populateDropdown("error-types", errorTypes);
});
});

0 comments on commit de57fde

Please sign in to comment.