Merge pull request #74 from arjunballa/master
doneSuccess and doneFailure callback functions and display resources in list and expanded view
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -19,3 +19,4 @@ reports/*
|
|||||||
.sass-cache
|
.sass-cache
|
||||||
swagger-ui.sublime-workspace
|
swagger-ui.sublime-workspace
|
||||||
.idea
|
.idea
|
||||||
|
.project
|
||||||
|
|||||||
@@ -22,9 +22,9 @@ class SwaggerUi extends Backbone.Router
|
|||||||
@options = options
|
@options = options
|
||||||
|
|
||||||
# Set the callbacks
|
# Set the callbacks
|
||||||
@options.success = => @render()
|
@options.success = => @render(options)
|
||||||
@options.progress = (d) => @showMessage(d)
|
@options.progress = (d) => @showMessage(d)
|
||||||
@options.failure = (d) => @onLoadFailure(d)
|
@options.failure = (d) => @onLoadFailure(d, options.doneFailure)
|
||||||
|
|
||||||
# Create view to handle the header inputs
|
# Create view to handle the header inputs
|
||||||
@headerView = new HeaderView({el: $('#header')})
|
@headerView = new HeaderView({el: $('#header')})
|
||||||
@@ -47,10 +47,14 @@ class SwaggerUi extends Backbone.Router
|
|||||||
|
|
||||||
# This is bound to success handler for SwaggerApi
|
# This is bound to success handler for SwaggerApi
|
||||||
# so it gets called when SwaggerApi completes loading
|
# so it gets called when SwaggerApi completes loading
|
||||||
render: ->
|
render:(options) ->
|
||||||
@showMessage('Finished Loading Resource Information. Rendering Swagger UI...')
|
@showMessage('Finished Loading Resource Information. Rendering Swagger UI...')
|
||||||
@mainView = new MainView({model: @api, el: $('#' + @dom_id)}).render()
|
@mainView = new MainView({model: @api, el: $('#' + @dom_id)}).render()
|
||||||
@showMessage()
|
@showMessage()
|
||||||
|
switch options.docStyle
|
||||||
|
when "expand" then Docs.expandOperationsForResource('')
|
||||||
|
when "list" then Docs.collapseOperationsForResource('')
|
||||||
|
options.doneSuccess() if options.doneSuccess
|
||||||
setTimeout(
|
setTimeout(
|
||||||
=>
|
=>
|
||||||
Docs.shebang()
|
Docs.shebang()
|
||||||
@@ -64,10 +68,11 @@ class SwaggerUi extends Backbone.Router
|
|||||||
$('#message-bar').html data
|
$('#message-bar').html data
|
||||||
|
|
||||||
# shows message in red
|
# shows message in red
|
||||||
onLoadFailure: (data = '') ->
|
onLoadFailure: (data = '', doneFailure) ->
|
||||||
$('#message-bar').removeClass 'message-success'
|
$('#message-bar').removeClass 'message-success'
|
||||||
$('#message-bar').addClass 'message-fail'
|
$('#message-bar').addClass 'message-fail'
|
||||||
$('#message-bar').html data
|
val = $('#message-bar').html data
|
||||||
|
doneFailure() if doneFailure
|
||||||
|
val
|
||||||
|
|
||||||
window.SwaggerUi = SwaggerUi
|
window.SwaggerUi = SwaggerUi
|
||||||
|
|||||||
@@ -46,7 +46,14 @@
|
|||||||
apiKey:"special-key",
|
apiKey:"special-key",
|
||||||
dom_id:"swagger-ui-container",
|
dom_id:"swagger-ui-container",
|
||||||
supportHeaderParams: false,
|
supportHeaderParams: false,
|
||||||
supportedSubmitMethods: ['get', 'post', 'put']
|
supportedSubmitMethods: ['get', 'post', 'put'],
|
||||||
|
doneSuccess: function(){
|
||||||
|
console.log("DONE!!!")
|
||||||
|
},
|
||||||
|
// "" - default behavior
|
||||||
|
// list - list view of all resources
|
||||||
|
// expand - expanded view of all resources
|
||||||
|
docStyle: ""
|
||||||
});
|
});
|
||||||
|
|
||||||
window.swaggerUi.load();
|
window.swaggerUi.load();
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ var Docs = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
toggleEndpointListForResource: function(resource) {
|
toggleEndpointListForResource: function(resource) {
|
||||||
var elem = $('li#resource_' + Docs.escapeResourceName(resource) + ' ul.endpoints');
|
var elem = $('li[id^=resource_' + Docs.escapeResourceName(resource) + '] ul.endpoints');
|
||||||
if (elem.is(':visible')) {
|
if (elem.is(':visible')) {
|
||||||
Docs.collapseEndpointListForResource(resource);
|
Docs.collapseEndpointListForResource(resource);
|
||||||
} else {
|
} else {
|
||||||
@@ -117,24 +117,24 @@ var Docs = {
|
|||||||
|
|
||||||
// Expand resource
|
// Expand resource
|
||||||
expandEndpointListForResource: function(resource) {
|
expandEndpointListForResource: function(resource) {
|
||||||
$('#resource_' + resource).addClass('active');
|
$('[id^=resource_' + resource + ']').addClass('active');
|
||||||
|
|
||||||
var elem = $('li#resource_' + Docs.escapeResourceName(resource) + ' ul.endpoints');
|
var elem = $('li[id^=resource_' + Docs.escapeResourceName(resource) + '] ul.endpoints');
|
||||||
elem.slideDown();
|
elem.slideDown();
|
||||||
},
|
},
|
||||||
|
|
||||||
// Collapse resource and mark as explicitly closed
|
// Collapse resource and mark as explicitly closed
|
||||||
collapseEndpointListForResource: function(resource) {
|
collapseEndpointListForResource: function(resource) {
|
||||||
$('#resource_' + resource).removeClass('active');
|
$('[id^=resource_' + resource + ']').removeClass('active');
|
||||||
|
|
||||||
var elem = $('li#resource_' + Docs.escapeResourceName(resource) + ' ul.endpoints');
|
var elem = $('li[id^=resource_' + Docs.escapeResourceName(resource) + '] ul.endpoints');
|
||||||
elem.slideUp();
|
elem.slideUp();
|
||||||
},
|
},
|
||||||
|
|
||||||
expandOperationsForResource: function(resource) {
|
expandOperationsForResource: function(resource) {
|
||||||
// Make sure the resource container is open..
|
// Make sure the resource container is open..
|
||||||
Docs.expandEndpointListForResource(resource);
|
Docs.expandEndpointListForResource(resource);
|
||||||
$('li#resource_' + Docs.escapeResourceName(resource) + ' li.operation div.content').each(function() {
|
$('li[id^=resource_' + Docs.escapeResourceName(resource) + '] li.operation div.content').each(function() {
|
||||||
Docs.expandOperation($(this));
|
Docs.expandOperation($(this));
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -142,7 +142,7 @@ var Docs = {
|
|||||||
collapseOperationsForResource: function(resource) {
|
collapseOperationsForResource: function(resource) {
|
||||||
// Make sure the resource container is open..
|
// Make sure the resource container is open..
|
||||||
Docs.expandEndpointListForResource(resource);
|
Docs.expandEndpointListForResource(resource);
|
||||||
$('li#resource_' + Docs.escapeResourceName(resource) + ' li.operation div.content').each(function() {
|
$('li[id^=resource_' + Docs.escapeResourceName(resource) + '] li.operation div.content').each(function() {
|
||||||
Docs.collapseOperation($(this));
|
Docs.collapseOperation($(this));
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user