Ver código fonte

Pass router to all views

bubble
Mohsen Azimi 9 anos atrás
pai
commit
9ed1ad88ec
6 arquivos alterados com 32 adições e 12 exclusões
  1. +15
    -5
      dist/swagger-ui.js
  2. +2
    -2
      dist/swagger-ui.min.js
  3. +3
    -2
      src/main/javascript/SwaggerUi.js
  4. +6
    -2
      src/main/javascript/view/MainView.js
  5. +4
    -1
      src/main/javascript/view/OperationView.js
  6. +2
    -0
      src/main/javascript/view/ResourceView.js

+ 15
- 5
dist/swagger-ui.js Ver arquivo

@@ -39,7 +39,7 @@ window.SwaggerUi = Backbone.Router.extend({
}
// Create an empty div which contains the dom_id
if (! $('#' + this.dom_id)){
if (! $('#' + this.dom_id).length){
$('body').append('<div id="' + this.dom_id + '"></div>') ;
}
@@ -118,7 +118,8 @@ window.SwaggerUi = Backbone.Router.extend({
this.mainView = new SwaggerUi.Views.MainView({
model: this.api,
el: $('#' + this.dom_id),
swaggerOptions: this.options
swaggerOptions: this.options,
router: this
}).render();
this.showMessage();
switch (this.options.docExpansion) {
@@ -1181,6 +1182,9 @@ SwaggerUi.Views.MainView = Backbone.View.extend({
initialize: function(opts){
opts = opts || {};
this.router = opts.router;
// set up the UI for input
this.model.auths = [];
var key, value;
@@ -1221,12 +1225,12 @@ SwaggerUi.Views.MainView = Backbone.View.extend({
var button;
if (auth.type === 'apiKey' && $('#apikey_button').length === 0) {
button = new SwaggerUi.Views.ApiKeyButton({model: auth}).render().el;
button = new SwaggerUi.Views.ApiKeyButton({model: auth, router: this.router}).render().el;
$('.auth_main_container').append(button);
}
if (auth.type === 'basicAuth' && $('#basic_auth_button').length === 0) {
button = new SwaggerUi.Views.BasicAuthButton({model: auth}).render().el;
button = new SwaggerUi.Views.BasicAuthButton({model: auth, router: this.router}).render().el;
$('.auth_main_container').append(button);
}
}
@@ -1264,6 +1268,7 @@ SwaggerUi.Views.MainView = Backbone.View.extend({
resource.id = resource.id.replace(/\s/g, '_');
var resourceView = new SwaggerUi.Views.ResourceView({
model: resource,
router: this.router,
tagName: 'li',
id: 'resource_' + resource.id,
className: 'resource',
@@ -1293,6 +1298,7 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({
initialize: function(opts) {
opts = opts || {};
this.router = opts.router;
this.auths = opts.auths;
this.parentId = this.model.parentId;
this.nickname = this.model.nickname;
@@ -1444,6 +1450,7 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({
if (signatureModel) {
responseSignatureView = new SwaggerUi.Views.SignatureView({
model: signatureModel,
router: this.router,
tagName: 'div'
});
$('.model-signature', $(this.el)).append(responseSignatureView.render().el);
@@ -1479,7 +1486,8 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({
param.type = type;
}
responseContentTypeView = new SwaggerUi.Views.ResponseContentTypeView({
model: contentTypeModel
model: contentTypeModel,
router: this.router
});
$('.response-content-type', $(this.el)).append(responseContentTypeView.render().el);
ref4 = this.model.parameters;
@@ -2021,6 +2029,7 @@ SwaggerUi.Views.ParameterView = Backbone.View.extend({
SwaggerUi.Views.ResourceView = Backbone.View.extend({
initialize: function(opts) {
opts = opts || {};
this.router = opts.router;
this.auths = opts.auths;
if ('' === this.model.description) {
this.model.description = null;
@@ -2068,6 +2077,7 @@ SwaggerUi.Views.ResourceView = Backbone.View.extend({
// Render an operation and add it to operations li
var operationView = new SwaggerUi.Views.OperationView({
model: operation,
router: this.router,
tagName: 'li',
className: 'endpoint',
swaggerOptions: this.options.swaggerOptions,


+ 2
- 2
dist/swagger-ui.min.js
Diferenças do arquivo suprimidas por serem muito extensas
Ver arquivo


+ 3
- 2
src/main/javascript/SwaggerUi.js Ver arquivo

@@ -33,7 +33,7 @@ window.SwaggerUi = Backbone.Router.extend({
}

// Create an empty div which contains the dom_id
if (! $('#' + this.dom_id)){
if (! $('#' + this.dom_id).length){
$('body').append('<div id="' + this.dom_id + '"></div>') ;
}

@@ -112,7 +112,8 @@ window.SwaggerUi = Backbone.Router.extend({
this.mainView = new SwaggerUi.Views.MainView({
model: this.api,
el: $('#' + this.dom_id),
swaggerOptions: this.options
swaggerOptions: this.options,
router: this
}).render();
this.showMessage();
switch (this.options.docExpansion) {


+ 6
- 2
src/main/javascript/view/MainView.js Ver arquivo

@@ -10,6 +10,9 @@ SwaggerUi.Views.MainView = Backbone.View.extend({

initialize: function(opts){
opts = opts || {};

this.router = opts.router;

// set up the UI for input
this.model.auths = [];
var key, value;
@@ -50,12 +53,12 @@ SwaggerUi.Views.MainView = Backbone.View.extend({
var button;

if (auth.type === 'apiKey' && $('#apikey_button').length === 0) {
button = new SwaggerUi.Views.ApiKeyButton({model: auth}).render().el;
button = new SwaggerUi.Views.ApiKeyButton({model: auth, router: this.router}).render().el;
$('.auth_main_container').append(button);
}

if (auth.type === 'basicAuth' && $('#basic_auth_button').length === 0) {
button = new SwaggerUi.Views.BasicAuthButton({model: auth}).render().el;
button = new SwaggerUi.Views.BasicAuthButton({model: auth, router: this.router}).render().el;
$('.auth_main_container').append(button);
}
}
@@ -93,6 +96,7 @@ SwaggerUi.Views.MainView = Backbone.View.extend({
resource.id = resource.id.replace(/\s/g, '_');
var resourceView = new SwaggerUi.Views.ResourceView({
model: resource,
router: this.router,
tagName: 'li',
id: 'resource_' + resource.id,
className: 'resource',


+ 4
- 1
src/main/javascript/view/OperationView.js Ver arquivo

@@ -14,6 +14,7 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({

initialize: function(opts) {
opts = opts || {};
this.router = opts.router;
this.auths = opts.auths;
this.parentId = this.model.parentId;
this.nickname = this.model.nickname;
@@ -165,6 +166,7 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({
if (signatureModel) {
responseSignatureView = new SwaggerUi.Views.SignatureView({
model: signatureModel,
router: this.router,
tagName: 'div'
});
$('.model-signature', $(this.el)).append(responseSignatureView.render().el);
@@ -200,7 +202,8 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({
param.type = type;
}
responseContentTypeView = new SwaggerUi.Views.ResponseContentTypeView({
model: contentTypeModel
model: contentTypeModel,
router: this.router
});
$('.response-content-type', $(this.el)).append(responseContentTypeView.render().el);
ref4 = this.model.parameters;


+ 2
- 0
src/main/javascript/view/ResourceView.js Ver arquivo

@@ -3,6 +3,7 @@
SwaggerUi.Views.ResourceView = Backbone.View.extend({
initialize: function(opts) {
opts = opts || {};
this.router = opts.router;
this.auths = opts.auths;
if ('' === this.model.description) {
this.model.description = null;
@@ -50,6 +51,7 @@ SwaggerUi.Views.ResourceView = Backbone.View.extend({
// Render an operation and add it to operations li
var operationView = new SwaggerUi.Views.OperationView({
model: operation,
router: this.router,
tagName: 'li',
className: 'endpoint',
swaggerOptions: this.options.swaggerOptions,


Carregando…
Cancelar
Salvar