Skip to content

Commit eafe55e

Browse files
author
Emmanouil Konstantinidis
committed
Style response elements
1 parent 1a49ea5 commit eafe55e

File tree

5 files changed

+70
-22
lines changed

5 files changed

+70
-22
lines changed

rest_framework_docs/static/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"build-bootstrap-fonts": "cp -r node_modules/bootstrap/fonts rest_framework_docs/",
99
"build-less": "lessc --clean-css rest_framework_docs/less/style.less rest_framework_docs/css/style.css",
1010
"watch-less": "watch 'npm run build-less' rest_framework_docs/less/",
11+
"watch": "npm run watch-less",
1112
"build": "npm run build-font-awesome && npm run build-bootstrap-fonts && npm run build-less",
1213
"start": "npm run build && npm run watch-less",
1314
"test": "echo \"Error: no test specified\" && exit 1"

rest_framework_docs/static/rest_framework_docs/css/style.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rest_framework_docs/static/rest_framework_docs/js/index.js

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,39 @@
11
$( document ).ready(function() {
22

3+
var setResponse = function (response) {
4+
5+
// Status Code
6+
var statusCodeFirstChar = String(response.status).charAt(0);
7+
var statusCodeClass;
8+
9+
switch (parseInt(statusCodeFirstChar)) {
10+
case 1:
11+
statusCodeClass = 'label-info';
12+
break;
13+
case 2:
14+
statusCodeClass = 'label-success';
15+
break;
16+
case 3:
17+
statusCodeClass = 'label-warning';
18+
break;
19+
case 4:
20+
statusCodeClass = 'label-danger';
21+
break;
22+
case 5:
23+
statusCodeClass = 'label-primary';
24+
break;
25+
}
26+
27+
$('#responseStatusCode').text(response.status);
28+
$('#responseStatusCode').addClass(statusCodeClass);
29+
30+
$('#responseStatusText').text(response.statusText.toLowerCase());
31+
$('#responseData').text(JSON.stringify(response.responseJSON, undefined, 2));
32+
33+
// console.log(response);
34+
// console.log(response.responseJSON);
35+
};
36+
337
var makeRequest = function () {
438
var url = $('#requestForm #urlInput').val();
539
var method = 'POST';
@@ -13,21 +47,11 @@ $( document ).ready(function() {
1347
password: 'test'
1448
}
1549
}).always(function(response) {
16-
17-
$('#responseStatusCode').text(response.status);
18-
$('#responseStatusText').text(response.statusText);
19-
$('#responseData').text(JSON.stringify(response.responseJSON, undefined, 2));
20-
21-
console.log(response);
22-
console.log(response.responseJSON);
50+
setResponse(response);
2351
});
2452
};
2553

2654
var setupForm = function (data) {
27-
console.log('------');
28-
console.log(data.path);
29-
console.log('------');
30-
3155
$('#urlInput').val(data.path);
3256

3357
$('#requestForm').submit(function (e) {

rest_framework_docs/static/rest_framework_docs/less/style.less

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,34 @@ body {
162162
/* @end Footer */
163163

164164

165+
/* @group Modal API */
166+
167+
.modal {
168+
169+
h3 {
170+
margin-top: 0;
171+
}
172+
173+
.request {
174+
175+
}
176+
177+
.response {
178+
.status-text {
179+
text-transform: capitalize;
180+
}
181+
182+
pre {
183+
font-size: 12px;
184+
margin-top: 20px;
185+
}
186+
}
187+
}
188+
189+
190+
/* @end Modal API */
191+
192+
165193
/* @group Github Ribbon - SVG */
166194

167195
.github-corner:hover .octo-arm {

rest_framework_docs/templates/rest_framework_docs/home.html

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ <h2 class="text-center">No endpoints found for {{ query }}.</h2>
8787
{% endif %}
8888

8989
<!-- Modal -->
90-
<!-- Modal -->
91-
<div class="modal fade" id="liveAPIModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
90+
<div class="modal fade api-modal" id="liveAPIModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
9291
<div class="modal-dialog modal-lg" role="document">
9392
<div class="modal-content">
9493
<div class="modal-header">
@@ -98,7 +97,7 @@ <h4 class="modal-title">Live API Endpoints</h4>
9897
<div class="modal-body">
9998

10099
<div class="row">
101-
<div class="col-md-6">
100+
<div class="col-md-6 request">
102101

103102
<h3>Request</h3>
104103
<form id="requestForm">
@@ -123,13 +122,9 @@ <h5>Data</h5>
123122

124123

125124
</div>
126-
<div class="col-md-6">
127-
<h3>Response</h3>
128-
<ul class="list">
129-
<li>Status Code: <span id="responseStatusCode"></span></li>
130-
<li>Status Text: <span id="responseStatusText"></span></li>
131-
</ul>
132-
125+
<div class="col-md-6 response">
126+
<h3>Response <span id="responseStatusCode" class="label pull-right"></span></h3>
127+
<div><strong>Status Text</strong>: <span class="status-text" id="responseStatusText"></span></div>
133128
<pre id="responseData"></pre>
134129
</div>
135130
</div>

0 commit comments

Comments
 (0)