Adding JSON sample UI to response
This commit is contained in:
@@ -445,6 +445,7 @@
|
|||||||
}
|
}
|
||||||
if (this.responseClass != null) {
|
if (this.responseClass != null) {
|
||||||
this.responseClassSignature = this.getSignature(this.responseClass, this.resource.models);
|
this.responseClassSignature = this.getSignature(this.responseClass, this.resource.models);
|
||||||
|
this.responseSampleJSON = this.getSampleJSON(this.responseClass, this.resource.models);
|
||||||
}
|
}
|
||||||
this.errorResponses = this.errorResponses || [];
|
this.errorResponses = this.errorResponses || [];
|
||||||
_ref1 = this.parameters;
|
_ref1 = this.parameters;
|
||||||
|
|||||||
@@ -14,6 +14,18 @@ class OperationView extends Backbone.View
|
|||||||
|
|
||||||
$(@el).html(Handlebars.templates.operation(@model))
|
$(@el).html(Handlebars.templates.operation(@model))
|
||||||
|
|
||||||
|
if @model.responseClassSignature and @model.responseClassSignature != 'string'
|
||||||
|
signatureModel =
|
||||||
|
sampleJSON: @model.responseSampleJSON
|
||||||
|
isParam: false
|
||||||
|
signature: @model.responseClassSignature
|
||||||
|
|
||||||
|
responseSignatureView = new SignatureView({model: signatureModel, tagName: 'div'})
|
||||||
|
$('.model-signature', $(@el)).append responseSignatureView.render().el
|
||||||
|
else
|
||||||
|
$('.model-signature', $(@el)).html(@model.responseClass)
|
||||||
|
|
||||||
|
|
||||||
# Render each parameter
|
# Render each parameter
|
||||||
@addParameter param for param in @model.parameters
|
@addParameter param for param in @model.parameters
|
||||||
|
|
||||||
|
|||||||
@@ -8,8 +8,13 @@ class ParameterView extends Backbone.View
|
|||||||
template = @template()
|
template = @template()
|
||||||
$(@el).html(template(@model))
|
$(@el).html(template(@model))
|
||||||
|
|
||||||
|
signatureModel =
|
||||||
|
sampleJSON: @model.sampleJSON
|
||||||
|
isParam: true
|
||||||
|
signature: @model.signature
|
||||||
|
|
||||||
if @model.sampleJSON
|
if @model.sampleJSON
|
||||||
signatureView = new SignatureView({model: @model, tagName: 'div'})
|
signatureView = new SignatureView({model: signatureModel, tagName: 'div'})
|
||||||
$('.model-signature', $(@el)).append signatureView.render().el
|
$('.model-signature', $(@el)).append signatureView.render().el
|
||||||
else
|
else
|
||||||
$('.model-signature', $(@el)).html(@model.signature)
|
$('.model-signature', $(@el)).html(@model.signature)
|
||||||
|
|||||||
@@ -13,6 +13,11 @@ class SignatureView extends Backbone.View
|
|||||||
|
|
||||||
@switchToDescription()
|
@switchToDescription()
|
||||||
|
|
||||||
|
@isParam = @model.isParam
|
||||||
|
|
||||||
|
if @isParam
|
||||||
|
$('.notice', $(@el)).text('Click to set as parameter value')
|
||||||
|
|
||||||
@
|
@
|
||||||
|
|
||||||
template: ->
|
template: ->
|
||||||
@@ -36,8 +41,11 @@ class SignatureView extends Backbone.View
|
|||||||
|
|
||||||
# handler for snippet to text area
|
# handler for snippet to text area
|
||||||
snippetToTextArea: (e) ->
|
snippetToTextArea: (e) ->
|
||||||
e?.preventDefault()
|
if @isParam
|
||||||
textArea = $('textarea', $(@el.parentNode.parentNode.parentNode))
|
e?.preventDefault()
|
||||||
if $.trim(textArea.val()) == ''
|
textArea = $('textarea', $(@el.parentNode.parentNode.parentNode))
|
||||||
|
if $.trim(textArea.val()) == ''
|
||||||
textArea.val(@model.sampleJSON)
|
textArea.val(@model.sampleJSON)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -22,12 +22,8 @@
|
|||||||
<p>{{{notes}}}</p>
|
<p>{{{notes}}}</p>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{#if responseClass}}
|
{{#if responseClass}}
|
||||||
<h4>Response Class</h4>
|
<h4>Response Model</h4>
|
||||||
{{#if responseClassSignature}}
|
<span class="model-signature"></span>
|
||||||
<p><span class="model-signature">{{{responseClassSignature}}}</span></p>
|
|
||||||
{{else}}
|
|
||||||
<p>{{{responseClass}}}</p>
|
|
||||||
{{/if}}
|
|
||||||
{{/if}}
|
{{/if}}
|
||||||
<form accept-charset='UTF-8' class='sandbox'>
|
<form accept-charset='UTF-8' class='sandbox'>
|
||||||
<div style='margin:0;padding:0;display:inline'></div>
|
<div style='margin:0;padding:0;display:inline'></div>
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
<div class="snippet">
|
<div class="snippet">
|
||||||
<pre><code>{{sampleJSON}}</code></pre>
|
<pre><code>{{sampleJSON}}</code></pre>
|
||||||
<small>Click to set as parameter value</small>
|
<small class="notice"></small>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user