Skip to content

Commit f019113

Browse files
authored
Update dash.js
Update UI (if jQuery dump is available) to display a button that opens a new window with rendered dump.
1 parent 032b7bb commit f019113

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

dashboard/dash.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,12 @@ $(function(){
132132
submit.removeAttr('disabled');
133133
reset.show();
134134
headers = parseHeaders(headers);
135+
resource.data("jsondata", "");
135136

136137
if (headers['content-type'].indexOf('application/json') > -1 || headers['content-type'].indexOf('text/json') > -1 || headers['content-type'].indexOf('application/vnd.api+json') > -1){
137138
//indentation!
138139
if (body.length){
140+
resource.data("jsondata", JSON.parse(body));
139141
body = JSON.stringify(JSON.parse(body), null, 3);
140142
// only do syntax highlighting if hljs is defined
141143
if (typeof hljs === 'undefined') {
@@ -166,13 +168,30 @@ $(function(){
166168
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>');
167169
}
168170

169-
response.find('.responseTime').html('Request took ' + timeSpent + 'ms');
171+
// only display dump button if jQuery dump is available
172+
var renderBtn = "";
173+
if (typeof $.dump === "undefined") {
174+
/* nothing */
175+
} else if (resource.data("jsondata")){
176+
renderBtn = "<span class=\"dumpBtn label label-default\" style=\"cursor:pointer;\">CLICK TO DUMP</span> ";
177+
}
178+
179+
response.find('.responseTime').html(renderBtn + 'Request took ' + timeSpent + 'ms');
170180
response.find('.responseStatus').html(status);
171181
response.find('.responseBody').html(body);
172182
});
173183

174184
});
175185

186+
$("body").on("click", ".dumpBtn", function(e){
187+
var data = $(this).closest(".resource").data("jsondata") || 0;
188+
if (data){
189+
$.dump(data, false, true, true);
190+
} else {
191+
alert("Unable to dump API response");
192+
}
193+
});
194+
176195
$(".resetRequest").click(function(){
177196
var reset = $(this)
178197
,resource = reset.closest('.resource')

0 commit comments

Comments
 (0)