Adding 'snippet' tab to parameter datatype signature UI
This new section displays how a complex datatype should look like providing some sample code for the developer using Swagger.
This commit is contained in:
@@ -7,6 +7,13 @@ class ParameterView extends Backbone.View
|
||||
template = @template()
|
||||
$(@el).html(template(@model))
|
||||
|
||||
console.log @model
|
||||
if @model.sampleJSON
|
||||
signatureView = new SignatureView({model: @model, tagName: 'div'})
|
||||
$('.model-signature', $(@el)).append signatureView.render().el
|
||||
else
|
||||
$('.model-signature', $(@el)).html(@model.signature)
|
||||
|
||||
@
|
||||
|
||||
# Return an appropriate template based on if the parameter is a list, readonly, required
|
||||
|
||||
43
src/main/coffeescript/view/SignatureView.coffee
Normal file
43
src/main/coffeescript/view/SignatureView.coffee
Normal file
@@ -0,0 +1,43 @@
|
||||
class SignatureView extends Backbone.View
|
||||
events: {
|
||||
'click a.description-link' : 'switchToDescription'
|
||||
'click a.snippet-link' : 'switchToSnippet'
|
||||
'mousedown .snippet' : 'snippetToTextArea'
|
||||
}
|
||||
|
||||
initialize: ->
|
||||
|
||||
render: ->
|
||||
template = @template()
|
||||
$(@el).html(template(@model))
|
||||
|
||||
@switchToDescription()
|
||||
|
||||
@
|
||||
|
||||
template: ->
|
||||
Handlebars.templates.signature
|
||||
|
||||
# handler for show signature
|
||||
switchToDescription: (e) ->
|
||||
e?.preventDefault()
|
||||
$(".snippet", $(@el)).hide()
|
||||
$(".description", $(@el)).show()
|
||||
$('.description-link', $(@el)).addClass('selected')
|
||||
$('.snippet-link', $(@el)).removeClass('selected')
|
||||
|
||||
# handler for show sample
|
||||
switchToSnippet: (e) ->
|
||||
e?.preventDefault()
|
||||
$(".description", $(@el)).hide()
|
||||
$(".snippet", $(@el)).show()
|
||||
$('.snippet-link', $(@el)).addClass('selected')
|
||||
$('.description-link', $(@el)).removeClass('selected')
|
||||
|
||||
# handler for snippet to text area
|
||||
snippetToTextArea: (e) ->
|
||||
e?.preventDefault()
|
||||
textArea = $('textarea', $(@el.parentNode.parentNode.parentNode))
|
||||
if $.trim(textArea.val()) == ''
|
||||
textArea.val(@model.sampleJSON)
|
||||
|
||||
@@ -1515,3 +1515,64 @@ body ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operatio
|
||||
}
|
||||
.model-signature span:nth-child(odd) { color:#333; }
|
||||
.model-signature span:nth-child(even) { color:#C5862B; }
|
||||
|
||||
.model-signature .signature-nav a {
|
||||
text-decoration: none;
|
||||
color: #AAA;
|
||||
}
|
||||
|
||||
.model-signature pre {
|
||||
font-size: .85em;
|
||||
line-height: 1.2em;
|
||||
overflow: auto;
|
||||
max-height: 200px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.model-signature pre:hover {
|
||||
background-color: #ffffdd;
|
||||
}
|
||||
|
||||
.model-signature .snippet small {
|
||||
font-size: 0.75em;
|
||||
}
|
||||
|
||||
.model-signature .signature-container {
|
||||
clear: both;
|
||||
}
|
||||
|
||||
.model-signature .signature-nav a:hover {
|
||||
text-decoration: underline;
|
||||
color: black;
|
||||
}
|
||||
|
||||
.model-signature .signature-nav .selected {
|
||||
color: black;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.model-signature ul.signature-nav {
|
||||
float: none;
|
||||
clear: both;
|
||||
overflow: hidden;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
display: block;
|
||||
clear: none;
|
||||
float: right;
|
||||
margin-right: 5px;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.model-signature ul.signature-nav li {
|
||||
float: left;
|
||||
clear: none;
|
||||
margin: 0;
|
||||
padding: 2px 10px;
|
||||
border-right: 1px solid #dddddd;
|
||||
}
|
||||
|
||||
.model-signature ul.signature-nav li:last-child {
|
||||
padding-right: 0;
|
||||
border-right: none;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,6 @@
|
||||
</td>
|
||||
<td>{{{description}}}</td>
|
||||
<td>
|
||||
<span class="model-signature">{{{signature}}}</span>
|
||||
<span class="model-signature"></span>
|
||||
</td>
|
||||
|
||||
|
||||
@@ -18,4 +18,4 @@
|
||||
</select>
|
||||
</td>
|
||||
<td>{{{description}}}</td>
|
||||
<td><span class="model-signature">{{{signature}}}</span></td>
|
||||
<td><span class="model-signature"></span></td>
|
||||
|
||||
@@ -7,4 +7,4 @@
|
||||
{{/if}}
|
||||
</td>
|
||||
<td>{{{description}}}</td>
|
||||
<td><span class="model-signature">{{{signature}}}</span></td>
|
||||
<td><span class="model-signature"></span></td>
|
||||
|
||||
@@ -7,4 +7,4 @@
|
||||
{{/if}}
|
||||
</td>
|
||||
<td>{{{description}}}</td>
|
||||
<td><span class="model-signature">{{{signature}}}</span></td>
|
||||
<td><span class="model-signature"></span></td>
|
||||
|
||||
@@ -18,4 +18,4 @@
|
||||
<td>
|
||||
<strong>{{{description}}}</strong>
|
||||
</td>
|
||||
<td><span class="model-signature">{{{signature}}}</span></td>
|
||||
<td><span class="model-signature"></span></td>
|
||||
|
||||
18
src/main/template/signature.handlebars
Normal file
18
src/main/template/signature.handlebars
Normal file
@@ -0,0 +1,18 @@
|
||||
<div>
|
||||
<ul class="signature-nav">
|
||||
<li><a class="description-link" href="#">Description</a></li>
|
||||
<li><a class="snippet-link" href="#">Snippet</a></li>
|
||||
</ul>
|
||||
<div>
|
||||
|
||||
<div class="signature-container">
|
||||
<div class="description">
|
||||
{{{signature}}}
|
||||
</div>
|
||||
|
||||
<div class="snippet">
|
||||
<pre>{{{sampleJSON}}}</pre>
|
||||
<small>Click to set as parameter value</small>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user