[auth] moved parse method into collection
This commit is contained in:
@@ -7,8 +7,7 @@ SwaggerUi.Views.AuthsCollectionView = Backbone.View.extend({
|
||||
this.options.data = this.options.data || {};
|
||||
this.router = this.options.router;
|
||||
|
||||
this.collection = new SwaggerUi.Collections.AuthsCollection();
|
||||
this.collection.add(this.parseData(opts.data));
|
||||
this.collection = new SwaggerUi.Collections.AuthsCollection(opts.data);
|
||||
|
||||
this.$innerEl = $('<div>');
|
||||
},
|
||||
@@ -24,44 +23,22 @@ SwaggerUi.Views.AuthsCollectionView = Backbone.View.extend({
|
||||
},
|
||||
|
||||
renderOneAuth: function (authModel) {
|
||||
var authEl;
|
||||
var authEl, authView;
|
||||
var type = authModel.get('type');
|
||||
|
||||
//todo refactor move view name into var and call new with it.
|
||||
if (type === 'apiKey') {
|
||||
authEl = new SwaggerUi.Views.ApiKeyAuthView({model: authModel, router: this.router}).render().el;
|
||||
authView = 'ApiKeyAuthView';
|
||||
} else if (type === 'basic' && this.$innerEl.find('.basic_auth_container').length === 0) {
|
||||
authEl = new SwaggerUi.Views.BasicAuthView({model: authModel, router: this.router}).render().el;
|
||||
authView = 'BasicAuthView';
|
||||
} else if (type === 'oauth2') {
|
||||
authEl = new SwaggerUi.Views.Oauth2View({model: authModel, router: this.router}).render().el;
|
||||
authView = 'Oauth2View';
|
||||
}
|
||||
|
||||
if (authView) {
|
||||
authEl = new SwaggerUi.Views[authView]({model: authModel, router: this.router}).render().el;
|
||||
}
|
||||
|
||||
this.$innerEl.append(authEl);
|
||||
},
|
||||
|
||||
//todo move into collection
|
||||
parseData: function (data) {
|
||||
var authz = Object.assign({}, window.swaggerUi.api.clientAuthorizations.authz);
|
||||
|
||||
return _.map(data, function (auth, name) {
|
||||
var isBasic = authz.basic && auth.type === 'basic';
|
||||
|
||||
_.extend(auth, {
|
||||
title: name
|
||||
});
|
||||
|
||||
if (authz[name] || isBasic) {
|
||||
_.extend(auth, {
|
||||
isLogout: true,
|
||||
value: isBasic ? undefined : authz[name].value,
|
||||
username: isBasic ? authz.basic.username : undefined,
|
||||
password: isBasic ? authz.basic.password : undefined,
|
||||
valid: true
|
||||
});
|
||||
}
|
||||
|
||||
return auth;
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user