1
0
Fork 0

API Admin client-side cleanups

Dieser Commit ist enthalten in:
Angus McLeod 2019-06-03 09:40:54 +10:00
Ursprung cc98a14d15
Commit 22d1c6fd06
3 geänderte Dateien mit 40 neuen und 25 gelöschten Zeilen

Datei anzeigen

@ -10,15 +10,20 @@ export default Ember.Controller.extend({
notAuthorized: Ember.computed.not('api.authorized'), notAuthorized: Ember.computed.not('api.authorized'),
authorizationTypes: ['oauth', 'basic'], authorizationTypes: ['oauth', 'basic'],
isOauth: Ember.computed.equal('api.authType', 'oauth'), isOauth: Ember.computed.equal('api.authType', 'oauth'),
isBasicAuth: Ember.computed.equal('api.authType', 'basic'),
endpointMethods: ['GET', 'PUT', 'POST', 'PATCH', 'DELETE'], endpointMethods: ['GET', 'PUT', 'POST', 'PATCH', 'DELETE'],
saveDisabled: Ember.computed.empty('api.name'),
showRemove: Ember.computed.not('isNew'), showRemove: Ember.computed.not('isNew'),
@computed('saveDisabled', 'authType', 'authUrl') @computed('saveDisabled', 'api.authType', 'api.authUrl')
authDisabled(saveDisabled, authType, authUrl) { authDisabled(saveDisabled, authType, authUrl) {
return saveDisabled || !authType || !authUrl; return saveDisabled || !authType || !authUrl;
}, },
@computed('api.name', 'api.authType')
saveDisabled(name, authType) {
return !name || !authType;
},
@observes('api.title') @observes('api.title')
titleWatcher() { titleWatcher() {
const title = this.get('api.title'); const title = this.get('api.title');
@ -48,18 +53,19 @@ export default Ember.Controller.extend({
authorize() { authorize() {
const api = this.get('api'); const api = this.get('api');
const { authType, authUrl, authParams } = api; const { authType, authUrl, authParams } = api;
if (authType !== 'oauth') return;
let query = '?'; let query = '?';
if (authType === 'oauth') { query += `client_id=${api.clientId}`;
query += `client_id=${api.clientId}&redirect_uri=${encodeURIComponent(api.redirectUri)}&response_type=code`; query += `&redirect_uri=${encodeURIComponent(api.redirectUri)}`;
query += `&response_type=code`;
if (authParams) { if (authParams) {
authParams.forEach(p => { authParams.forEach(p => {
query += `&${p.key}=${encodeURIComponent(p.value)}`; query += `&${p.key}=${encodeURIComponent(p.value)}`;
}); });
}
} else {
// basic auth - no need to authorize separately
} }
window.location.href = authUrl + query; window.location.href = authUrl + query;
@ -68,15 +74,18 @@ export default Ember.Controller.extend({
save() { save() {
const api = this.get('api'); const api = this.get('api');
const name = api.name; const name = api.name;
const authType = api.authType;
let refreshList = false; let refreshList = false;
if (!name ) return; if (!name || !authType) return;
let data = { let data = {
title: api.title auth_type: authType
}; };
if (this.get('isNew') || (api.title !== this.get('originalTitle'))) { if (api.title) data['title'] = api.title;
if (api.get('isNew') || (api.title !== this.get('originalTitle'))) {
refreshList = true; refreshList = true;
} }
@ -84,10 +93,8 @@ export default Ember.Controller.extend({
data['new'] = true; data['new'] = true;
}; };
if (api.authType) data['auth_type'] = api.authType; if (authType === 'oauth') {
if (api.authUrl) data['auth_url'] = api.authUrl; data['auth_url'] = api.authUrl;
if (data.auth_type === 'oauth') {
data['client_id'] = api.clientId; data['client_id'] = api.clientId;
data['client_secret'] = api.clientSecret; data['client_secret'] = api.clientSecret;
@ -98,13 +105,13 @@ export default Ember.Controller.extend({
} }
data['token_url'] = api.tokenUrl; data['token_url'] = api.tokenUrl;
} else { } else if (authType === 'basic') {
data['username'] = api.username; data['username'] = api.username;
data['password'] = api.password; data['password'] = api.password;
} }
const endpoints = api.endpoints; const endpoints = api.endpoints;
if (endpoints.length) { if (endpoints.length) {
data['endpoints'] = JSON.stringify(endpoints); data['endpoints'] = JSON.stringify(endpoints);
} }

Datei anzeigen

@ -34,7 +34,12 @@
</div> </div>
<div class="actions"> <div class="actions">
{{d-button label="admin.wizard.api.auth.btn" action="authorize" disabled=authDisabled class="btn-primary"}} {{#if isOauth}}
{{d-button label="admin.wizard.api.auth.btn"
action="authorize"
disabled=authDisabled
class="btn-primary"}}
{{/if}}
</div> </div>
</div> </div>
@ -107,7 +112,9 @@
{{d-button label='admin.wizard.api.auth.params.new' icon='plus' action='addParam'}} {{d-button label='admin.wizard.api.auth.params.new' icon='plus' action='addParam'}}
</div> </div>
</div> </div>
{{else}} {{/if}}
{{#if isBasicAuth}}
<div class="control-group"> <div class="control-group">
<label>{{i18n 'admin.wizard.api.auth.username'}}</label> <label>{{i18n 'admin.wizard.api.auth.username'}}</label>
<div class="controls"> <div class="controls">

Datei anzeigen

@ -334,9 +334,6 @@
margin-bottom: 20px; margin-bottom: 20px;
.settings { .settings {
border-right: 1px solid #333;
margin-right: 20px;
padding-right: 20px;
width: 50%; width: 50%;
max-width: 50%; max-width: 50%;
} }
@ -352,6 +349,9 @@
} }
.status { .status {
border-left: 1px solid $primary;
margin-left: 20px;
padding-left: 20px;
width: 50%; width: 50%;
max-width: 50%; max-width: 50%;
@ -384,6 +384,7 @@
.endpoint { .endpoint {
display: flex; display: flex;
margin-top: 20px;
.combo-box { .combo-box {
width: 200px; width: 200px;