Co-authored-by: widlam <mikolaj.widla@gmail.com> Co-authored-by: Adam Bem <adam.bem@zoho.eu> Reviewed-on: #184 Reviewed-by: Adam Bem <bema@noreply.example.com> Co-authored-by: Mikolaj Widla <widlam@noreply.example.com> Co-committed-by: Mikolaj Widla <widlam@noreply.example.com>
		
			
				
	
	
		
			82 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			82 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
var historyJson = {};
 | 
						|
const maxIterations = 200;
 | 
						|
 | 
						|
function filterHistory(){
 | 
						|
    var dateFrom = new Date($('#historyFrom').val() + 'T' + $('#historyTimeFrom').val());
 | 
						|
    
 | 
						|
    var dateTo = new Date($('#historyTo').val() + 'T' + $('#historyTimeTo').val());
 | 
						|
        
 | 
						|
    loadHistory(dateFrom, dateTo);
 | 
						|
}
 | 
						|
 | 
						|
const startSearch = function(){
 | 
						|
    filterHistory();
 | 
						|
}
 | 
						|
$('#btn-searchHistory').click(startSearch);
 | 
						|
 | 
						|
function loadHistory(dateFrom, dateTo){
 | 
						|
    
 | 
						|
    var eventRequest = {
 | 
						|
        clientUUID : json[jsonIndex].clientUUID,
 | 
						|
        localDateTimeFrom : dateFrom,
 | 
						|
        localDateTimeTo : dateTo,
 | 
						|
        mockedResponseId : json[jsonIndex].mockedResponseId
 | 
						|
    };
 | 
						|
    $.ajax({
 | 
						|
        url: host + '/api/event',
 | 
						|
        type: 'POST',
 | 
						|
        data: JSON.stringify(eventRequest, null, 2),
 | 
						|
        contentType: "application/json"
 | 
						|
    }).done(function(data){
 | 
						|
        historyJson = data;
 | 
						|
        displayHistory();
 | 
						|
    });
 | 
						|
}
 | 
						|
 | 
						|
function getLast24hHistoryData(){
 | 
						|
    $.getJSON(host + '/api/event/' + clientUUID + '/' + lastId, function(data){
 | 
						|
        historyJson = data;
 | 
						|
        displayHistory();
 | 
						|
    });
 | 
						|
}
 | 
						|
 | 
						|
function historyToHtml(){
 | 
						|
    var innerHTML = '';
 | 
						|
    var iterations = historyJson.length <= maxIterations ? historyJson.length : maxIterations;
 | 
						|
    for(let i=0; i<iterations; i++){
 | 
						|
        let style = i%2==0 ? ' class="even"' : '';
 | 
						|
        innerHTML += '<tr' + style + '>' +
 | 
						|
            '<td>' + parseTimeStamp(historyJson[i].dateTimeStamp) + '</td>' +
 | 
						|
            '<td>' + historyJson[i].httpMethod + '</td>' +
 | 
						|
            '<td>' + parseRequestBody(historyJson[i].requestBody, i) + '</td>' +
 | 
						|
            '<td> <button id="'+i+'" class="showHeaderButton" onClick="showHeadersHistory(this);"> Show headers </button> </td>' + 
 | 
						|
        '</tr>';
 | 
						|
    }
 | 
						|
    return innerHTML;
 | 
						|
}
 | 
						|
 | 
						|
function parseRequestBody(requestBody,i){
 | 
						|
    return requestBody.length == 0 ?
 | 
						|
     "No request body" :
 | 
						|
     '<button id="'+i+'" class="showRequestBodyButton" onClick="showRequestBody(this);"> Show request body </button>'
 | 
						|
}
 | 
						|
 | 
						|
function parseTimeStamp(timeStamp){
 | 
						|
    return timeStamp.substring(0,19).replace('T',' ');
 | 
						|
}
 | 
						|
 | 
						|
function parseHeaders(pos){
 | 
						|
    parsedJson = new Map();
 | 
						|
    headers = historyJson[pos].headers
 | 
						|
    Object.keys( headers ).forEach(
 | 
						|
        (jsonKey) => {
 | 
						|
            parsedJson.set( jsonKey , headers[jsonKey] );
 | 
						|
        }
 | 
						|
    )
 | 
						|
    return parsedJson;
 | 
						|
}
 | 
						|
 | 
						|
function displayHistory(){
 | 
						|
    $('#historyTable tbody').html(historyToHtml());
 | 
						|
}
 |