diff --git a/rest_framework/static/rest_framework/docs/css/base.css b/rest_framework/static/rest_framework/docs/css/base.css index 3afb273ce..d1f60b63b 100644 --- a/rest_framework/static/rest_framework/docs/css/base.css +++ b/rest_framework/static/rest_framework/docs/css/base.css @@ -3,6 +3,11 @@ padding-right: 30px; } +.btn:focus, +.btn:focus:active { + outline: none; +} + .sidebar { overflow: auto; font-family: verdana; @@ -308,7 +313,7 @@ body { color: #93c54b; } -.api-modal .modal-body .request-info { +.api-modal .modal-body .request-awaiting { background-color: #f8f5f0; text-align: center; padding: 5px 10px; @@ -329,3 +334,12 @@ body { padding: .2em .6em .3em; font-size: 14px; } + +.api-modal .modal-content .toggle-view { + text-align: right; + float: right; +} + +.api-modal .modal-content .response .well { + margin: 0; +} diff --git a/rest_framework/templates/rest_framework/docs/index.html b/rest_framework/templates/rest_framework/docs/index.html index eab6ef86f..41866adc4 100644 --- a/rest_framework/templates/rest_framework/docs/index.html +++ b/rest_framework/templates/rest_framework/docs/index.html @@ -122,15 +122,18 @@ }) function requestCallback(request) { - var requestText = request.options.method + ' ' + request.url; - - var parser = document.createElement('a'); + let parser = document.createElement('a'); parser.href = request.url; + const method = request.options.method + const path = parser.pathname + parser.hash + parser.search - form.find(".request-response").text(requestText) - form.find(".request-response").removeClass("hide") - form.find(".request-method").text(request.options.method) - form.find(".request-url").text(parser.pathname + parser.hash + parser.search) + // Filling the main response meta + form.closest(".modal-content").find(".toggle-view").removeClass("hide") + form.find(".request-method").text(method) + form.find(".request-url").text(path) + + // Filling the raw panel + form.find(".response-raw-request").text(method + ' ' + path + '\n\n') } function responseCallback(response) { @@ -144,27 +147,38 @@ form.find(".response-status-code").text(response.status) form.find(".meta").removeClass("hide") + + // Filling the raw panel + console.log(response); + form.find(".response-raw-response").text('HTTP/1.1 ' + response.status + ' ' + response.statusText) } const client = new coreapi.Client({csrf: csrf, requestCallback: requestCallback, responseCallback: responseCallback}) client.action(doc, key, params).then(function (data) { var response = JSON.stringify(data, null, 2); - form.find(".request-info").addClass("hide") + form.find(".request-awaiting").addClass("hide") form.find(".response-data").text(response) form.find(".response-data").removeClass("hide") - form.find(".response-error").addClass("hide") }).catch(function (error) { var response = JSON.stringify(error.content, null, 2); - form.find(".request-info").addClass("hide") - form.find(".response-error").text(error.message) + form.find(".request-awaiting").addClass("hide") form.find(".response-data").text(response) - form.find(".response-error").removeClass("hide") form.find(".response-data").removeClass("hide") - - /*form.find(".response-data").addClass("hide")*/ }) }); + + $('.toggle-view button').click(function() { + var selectedView = $(this).data("display-toggle"); + $(this).removeClass("btn-default").addClass('btn-info').siblings().removeClass('btn-info'); + if (selectedView === 'raw') { + $(this).closest(".modal-content").find(".response-raw").removeClass("hide"); + $(this).closest(".modal-content").find(".response-data").addClass("hide"); + } else { + $(this).closest(".modal-content").find(".response-data").removeClass("hide"); + $(this).closest(".modal-content").find(".response-raw").addClass("hide"); + } + }); diff --git a/rest_framework/templates/rest_framework/docs/interact.html b/rest_framework/templates/rest_framework/docs/interact.html index 373dca0f3..c56c5bbad 100644 --- a/rest_framework/templates/rest_framework/docs/interact.html +++ b/rest_framework/templates/rest_framework/docs/interact.html @@ -5,8 +5,15 @@