merged from oauth2 branch

This commit is contained in:
Tony Tam
2014-03-19 21:50:31 -07:00
parent 1f6aa46e52
commit da63a33845
17 changed files with 1051 additions and 43 deletions

View File

@@ -6,14 +6,55 @@ class OperationView extends Backbone.View
'click .submit' : 'submitOperation'
'click .response_hider' : 'hideResponse'
'click .toggleOperation' : 'toggleOperationContent'
'mouseenter .api-ic' : 'mouseEnter'
'mouseout .api-ic' : 'mouseExit'
}
initialize: ->
mouseEnter: (e) ->
elem = $(e.currentTarget.parentNode).find('#api_information_panel')
x = event.pageX
y = event.pageY
scX = $(window).scrollLeft()
scY = $(window).scrollTop()
scMaxX = scX + $(window).width()
scMaxY = scY + $(window).height()
wd = elem.width()
hgh = elem.height()
if (x + wd > scMaxX)
x = scMaxX - wd
if (x < scX)
x = scX
if (y + hgh > scMaxY)
y = scMaxY - hgh
if (y < scY)
y = scY
pos = {}
pos.top = y
pos.left = x
elem.css(pos)
$(e.currentTarget.parentNode).find('#api_information_panel').show()
mouseExit: (e) ->
$(e.currentTarget.parentNode).find('#api_information_panel').hide()
render: ->
isMethodSubmissionSupported = true #jQuery.inArray(@model.method, @model.supportedSubmitMethods) >= 0
@model.isReadOnly = true unless isMethodSubmissionSupported
@model.oauth = null
if @model.authorizations
for k, v of @model.authorizations
if k == "oauth2"
if @model.oauth == null
@model.oauth = {}
if @model.oauth.scopes is undefined
@model.oauth.scopes = []
for o in v
@model.oauth.scopes.push o
$(@el).html(Handlebars.templates.operation(@model))
if @model.responseClassSignature and @model.responseClassSignature != 'string'
@@ -282,11 +323,11 @@ class OperationView extends Backbone.View
# puts the response data in UI
showStatus: (response) ->
if response.content is undefined
content = response.data
url = response.url
content = response.data
url = response.url
else
content = response.content.data
url = response.request.url
content = response.content.data
url = response.request.url
headers = response.headers
# if server is nice, and sends content-type back, we can use it

View File

@@ -710,6 +710,9 @@ table {
.swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading ul.options li a {
text-decoration: none;
}
.swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading ul.options li.access {
color: black;
}
.swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.content {
border-top: none;
padding: 10px;
@@ -1031,6 +1034,132 @@ table {
.swagger-ui-wrap form.form_box p strong {
color: black;
}
.title {
font-style: bold;
}
.secondary_form {
display: none;
}
.main_image {
display: block;
margin-left: auto;
margin-right: auto;
}
.oauth_body {
margin-left: 100px;
margin-right: 100px;
}
.oauth_submit {
text-align: center;
}
.api-popup-dialog {
z-index: 10000;
position: absolute;
width: 500px;
background: #FFF;
padding: 20px;
border: 1px solid #ccc;
border-radius: 5px;
display: none;
font-size: 13px;
color: #777;
}
.api-popup-dialog .api-popup-title {
font-size: 24px;
padding: 10px 0;
}
.api-popup-dialog .api-popup-title {
font-size: 24px;
padding: 10px 0;
}
.api-popup-dialog p.error-msg {
padding-left: 5px;
padding-bottom: 5px;
}
.api-popup-dialog button.api-popup-authbtn {
height: 30px;
}
.api-popup-dialog button.api-popup-cancel {
height: 30px;
}
.api-popup-scopes {
padding: 10px 20px;
}
.api-popup-scopes li {
padding: 5px 0;
line-height: 20px;
}
.api-popup-scopes .api-scope-desc {
padding-left: 20px;
font-style: italic;
}
.api-popup-scopes li input {
position: relative;
top: 2px;
}
.api-popup-actions {
padding-top: 10px;
}
.access {
float: right;
}
.auth {
float: right;
}
#api_information_panel {
position: absolute;
background: #FFF;
border: 1px solid #ccc;
border-radius: 5px;
display: none;
font-size: 13px;
max-width: 300px;
line-height: 30px;
color: black;
padding: 5px;
}
#api_information_panel p .api-msg-enabled {
color: green;
}
#api_information_panel p .api-msg-disabled {
color: red;
}
.api-ic {
height: 18px;
vertical-align: middle;
display: inline-block;
background: url(../images/explorer_icons.png) no-repeat;
}
.ic-info {
background-position: 0 0;
width: 18px;
margin-top: -7px;
margin-left: 4px;
}
.ic-warning {
background-position: -60px 0;
width: 18px;
margin-top: -7px;
margin-left: 4px;
}
.ic-error {
background-position: -30px 0;
width: 18px;
margin-top: -7px;
margin-left: 4px;
}
.ic-off {
background-position: -90px 0;
width: 58px;
margin-top: -4px;
cursor: pointer;
}
.ic-on {
background-position: -160px 0;
width: 58px;
margin-top: -4px;
cursor: pointer;
}
#header {
background-color: #89bf04;
padding: 14px;

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

View File

@@ -16,14 +16,23 @@
<script src='lib/swagger.js' type='text/javascript'></script>
<script src='swagger-ui.js' type='text/javascript'></script>
<script src='lib/highlight.7.3.pack.js' type='text/javascript'></script>
<!--script src='lib/swagger-oauth.js' type='text/javascript'></script-->
<script type="text/javascript">
// var clientId = "your-client-id";
// var realm = "your-realm";
$(function () {
window.swaggerUi = new SwaggerUi({
url: "http://petstore.swagger.wordnik.com/api/api-docs",
dom_id: "swagger-ui-container",
supportedSubmitMethods: ['get', 'post', 'put', 'delete'],
onComplete: function(swaggerApi, swaggerUi){
log("Loaded SwaggerUI")
log("Loaded SwaggerUI");
/*if(typeof initOAuth == "function")
initOAuth();
*/
$('pre code').each(function(i, e) {hljs.highlightBlock(e)});
},
onFailure: function(data) {
@@ -65,14 +74,8 @@
</div>
</div>
<div id="message-bar" class="swagger-ui-wrap">
&nbsp;
</div>
<div id="swagger-ui-container" class="swagger-ui-wrap">
</div>
<div id="message-bar" class="swagger-ui-wrap">&nbsp;</div>
<div id="swagger-ui-container" class="swagger-ui-wrap"></div>
</body>
</html>

15
src/main/html/o2c.html Normal file
View File

@@ -0,0 +1,15 @@
<script>
var qp = null;
if(window.location.hash) {
qp = location.hash.substring(1);
}
else {
qp = location.search.substring(1);
}
qp = qp ? JSON.parse('{"' + qp.replace(/&/g, '","').replace(/=/g,'":"') + '"}',
function(key, value) {
return key===""?value:decodeURIComponent(value) }
):{}
window.opener.onOAuthComplete(qp);
window.close();
</script>

79
src/main/less/auth.less Normal file
View File

@@ -0,0 +1,79 @@
.title {
font-style: bold;
}
.secondary_form {
display: none;
}
.main_image {
display: block;
margin-left: auto;
margin-right: auto;
}
.oauth_body {
margin-left: 100px;
margin-right: 100px;
}
.oauth_submit {
text-align: center;
}
.api-popup-dialog {
z-index: 10000;
position: absolute;
width: 500px;
background: #FFF;
padding: 20px;
border: 1px solid #ccc;
border-radius: 5px;
display: none;
font-size: 13px;
color: #777;
.api-popup-title{
font-size: 24px;
padding: 10px 0;
}
.api-popup-title{
font-size: 24px;
padding: 10px 0;
}
p.error-msg {
padding-left: 5px;
padding-bottom: 5px;
}
button.api-popup-authbtn {
height: 30px;
}
button.api-popup-cancel {
height: 30px;
}
}
.api-popup-scopes {
padding: 10px 20px;
li {
padding: 5px 0;
line-height: 20px;
}
.api-scope-desc {
padding-left: 20px;
font-style: italic;
}
li input {
position: relative;
top: 2px;
}
}
.api-popup-actions {
padding-top: 10px;
}

View File

@@ -1,5 +1,73 @@
@import 'src/main/less/reset.less';
@import 'src/main/less/specs.less';
@import 'src/main/less/auth.less';
.access {
float: right;
}
.auth {
float: right;
}
#api_information_panel {
position: absolute;
background: #FFF;
border: 1px solid #ccc;
border-radius: 5px;
display: none;
font-size: 13px;
max-width: 300px;
line-height: 30px;
color: black;
padding: 5px;
p {
.api-msg-enabled {
color: green;
}
.api-msg-disabled {
color: red;
}
}
}
.api-ic {
height: 18px;
vertical-align: middle;
display: inline-block;
background: url(../images/explorer_icons.png) no-repeat;
}
.ic-info {
background-position: 0 0;
width: 18px;
margin-top: -7px;
margin-left: 4px;
}
.ic-warning {
background-position: -60px 0;
width: 18px;
margin-top: -7px;
margin-left: 4px;
}
.ic-error {
background-position: -30px 0;
width: 18px;
margin-top: -7px;
margin-left: 4px;
}
.ic-off {
background-position: -90px 0;
width: 58px;
margin-top: -4px;
cursor: pointer;
}
.ic-on {
background-position: -160px 0;
width: 58px;
margin-top: -4px;
cursor: pointer;
}
#header {
background-color: #89bf04;

View File

@@ -632,6 +632,11 @@
}
}
}
ul.options {
li.access {
color: black;
}
}
}
div.content {
border-top: none;

View File

@@ -21,6 +21,22 @@
<h4>Implementation Notes</h4>
<p>{{{notes}}}</p>
{{/if}}
{{#oauth}}
<div class="auth">
<span class="api-ic ic-error"></span>{{/oauth}}
{{#each oauth}}
<div id="api_information_panel" style="top: 526px; left: 776px; display: none;">
{{#each this}}
<div title='{{{this.description}}}'>{{this.scope}}</div>
{{/each}}
</div>
{{/each}}
{{#oauth}}</div>{{/oauth}}
{{#oauth}}
<div class='access'>
<span class="api-ic ic-off" title="click to authenticate"></span>
</div>
{{/oauth}}
{{#if type}}
<h4>Response Class</h4>
<p><span class="model-signature" /></p>