Skip to content

Commit

Permalink
Update dash.js
Browse files Browse the repository at this point in the history
Update UI (if jQuery dump is available) to display a button that opens a new window with rendered dump.
  • Loading branch information
JamoCA authored Apr 3, 2024
1 parent 032b7bb commit f019113
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion dashboard/dash.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,12 @@ $(function(){
submit.removeAttr('disabled');
reset.show();
headers = parseHeaders(headers);
resource.data("jsondata", "");

if (headers['content-type'].indexOf('application/json') > -1 || headers['content-type'].indexOf('text/json') > -1 || headers['content-type'].indexOf('application/vnd.api+json') > -1){
//indentation!
if (body.length){
resource.data("jsondata", JSON.parse(body));
body = JSON.stringify(JSON.parse(body), null, 3);
// only do syntax highlighting if hljs is defined
if (typeof hljs === 'undefined') {
Expand Down Expand Up @@ -166,13 +168,30 @@ $(function(){
headerRow.append('<div class="row"><div class="col-md-5 headerName">' + sortable[h] + ':</div><div class="col-md-7 headerVal">' + headers[sortable[h]] + '</div></div>');
}

response.find('.responseTime').html('Request took ' + timeSpent + 'ms');
// only display dump button if jQuery dump is available
var renderBtn = "";
if (typeof $.dump === "undefined") {
/* nothing */
} else if (resource.data("jsondata")){
renderBtn = "<span class=\"dumpBtn label label-default\" style=\"cursor:pointer;\">CLICK TO DUMP</span> ";
}

response.find('.responseTime').html(renderBtn + 'Request took ' + timeSpent + 'ms');
response.find('.responseStatus').html(status);
response.find('.responseBody').html(body);
});

});

$("body").on("click", ".dumpBtn", function(e){
var data = $(this).closest(".resource").data("jsondata") || 0;
if (data){
$.dump(data, false, true, true);
} else {
alert("Unable to dump API response");
}
});

$(".resetRequest").click(function(){
var reset = $(this)
,resource = reset.closest('.resource')
Expand Down

0 comments on commit f019113

Please sign in to comment.