0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-22 09:20:29 +01:00

Move api to v0.2

Dieser Commit ist enthalten in:
Angus McLeod 2020-04-22 23:03:18 +10:00
Ursprung 8327b7fad0
Commit e06f543720
13 geänderte Dateien mit 100 neuen und 61 gelöschten Zeilen

Datei anzeigen

@ -60,7 +60,7 @@ export default Component.extend(UndoChanges, {
return content;
},
@discourseComputed('wizard.apis')
@discourseComputed('apis')
availableApis(apis) {
return apis.map(a => {
return {
@ -70,7 +70,7 @@ export default Component.extend(UndoChanges, {
});
},
@discourseComputed('wizard.apis', 'action.api')
@discourseComputed('apis', 'action.api')
availableEndpoints(apis, api) {
if (!api) return [];
return apis.find(a => a.name === api).endpoints;

Datei anzeigen

@ -166,20 +166,13 @@ export default Controller.extend({
this.set('updating', true);
ajax(`/admin/wizards/apis/${name.underscore()}`, {
ajax(`/admin/wizards/api/${name.underscore()}`, {
type: 'PUT',
data
}).catch(popupAjaxError)
.then(result => {
if (result.success) {
if (refreshList) {
this.transitionToRoute('adminWizardsApi', result.api.name.dasherize()).then(() => {
this.send('refreshModel');
});
} else {
this.set('api', CustomWizardApi.create(result.api));
this.set('responseIcon', 'check');
}
this.send('afterSave', result.api.name);
} else {
this.set('responseIcon', 'times');
}
@ -192,14 +185,12 @@ export default Controller.extend({
this.set('updating', true);
ajax(`/admin/wizards/apis/${name.underscore()}`, {
ajax(`/admin/wizards/api/${name.underscore()}`, {
type: 'DELETE'
}).catch(popupAjaxError)
.then(result => {
if (result.success) {
this.transitionToRoute('adminWizardsApis').then(() => {
this.send('refreshModel');
});
this.send('afterDestroy');
}
}).finally(() => this.set('updating', false));
},
@ -208,7 +199,7 @@ export default Controller.extend({
const name = this.get('api.name');
if (!name) return;
ajax(`/admin/wizards/apis/logs/${name.underscore()}`, {
ajax(`/admin/wizards/api/${name.underscore()}/logs`, {
type: 'DELETE'
}).catch(popupAjaxError)
.then(result => {

Datei anzeigen

@ -45,7 +45,7 @@ CustomWizardApi.reopenClass({
},
find(name) {
return ajax(`/admin/wizards/apis/${name}`, {
return ajax(`/admin/wizards/api/${name}`, {
type: 'GET'
}).then(result => {
return CustomWizardApi.create(result);
@ -53,7 +53,7 @@ CustomWizardApi.reopenClass({
},
list() {
return ajax("/admin/wizards/apis", {
return ajax("/admin/wizards/api", {
type: 'GET'
}).then(result => {
return result;

Datei anzeigen

@ -2,14 +2,8 @@ import CustomWizardApi from '../models/custom-wizard-api';
import DiscourseRoute from "discourse/routes/discourse";
export default DiscourseRoute.extend({
queryParams: {
refresh_list: {
refreshModel: true
}
},
model(params) {
if (params.name === 'new') {
if (params.name === 'create') {
return CustomWizardApi.create({ isNew: true });
} else {
return CustomWizardApi.find(params.name);

Datei anzeigen

@ -1,7 +1,45 @@
import DiscourseRoute from "discourse/routes/discourse";
import CustomWizardApi from '../models/custom-wizard-api';
export default DiscourseRoute.extend({
beforeModel() {
this.transitionTo('adminWizardsApiShow');
model() {
return CustomWizardApi.list();
},
setupController(controller, model) {
const showParams = this.paramsFor('adminWizardsApiShow');
const apiName = showParams.name == 'create' ? null : showParams.name;
const apiList = (model || []).map(api => {
return {
id: api.name,
name: api.title
}
});
controller.setProperties({
apiName,
apiList
})
},
actions: {
changeApi(apiName) {
this.controllerFor('adminWizardsApi').set('apiName', apiName);
this.transitionTo('adminWizardsApiShow', apiName);
},
afterDestroy() {
this.transitionTo('adminWizardsApi').then(() => this.refresh());
},
afterSave(apiName) {
this.refresh().then(() => this.send('changeApi', apiName));
},
createApi() {
this.controllerFor('adminWizardsApi').set('apiName', 'create');
this.transitionTo('adminWizardsApiShow', 'create');
}
}
});

Datei anzeigen

@ -92,7 +92,7 @@
{{combo-box
value=api.authType
content=authorizationTypes
onChange=(action (mut authorizationTypes))
onChange=(action (mut api.authType))
options=(hash
none='admin.wizard.api.auth.type_none'
)}}
@ -261,8 +261,8 @@
none="admin.wizard.api.endpoint.content_type"
)}}
{{multi-select
value=endpoint.success_codes
content=successCodes
values=endpoint.success_codes
onChange=(action (mut endpoint.success_codes))
options=(hash
none="admin.wizard.api.endpoint.success_codes"
@ -285,26 +285,26 @@
</div>
<div class="wizard-api-log">
<div class="log-list">
<table class="wizard-api-log-table">
<th>Datetime</th>
<th>User</th>
<th>Status</th>
<th>URL</th>
<th>Error</th>
{{#each api.log as |logentry|}}
<tr>
<td>{{logentry.time}}</td>
<td class="user-image">
<div class="user-image-inner">
<a href="{{unbound logentry.userpath}}" data-user-card="{{unbound logentry.username}}">{{avatar logentry imageSize="large"}}</a>
</div>
</td>
<td>{{logentry.status}}</td>
<td>{{logentry.url}}</td>
<td>{{logentry.error}}</td>
</tr>
{{/each}}
</table>
</div>
<div class="log-list">
<table class="wizard-api-log-table">
<th>Datetime</th>
<th>User</th>
<th>Status</th>
<th>URL</th>
<th>Error</th>
{{#each api.log as |logentry|}}
<tr>
<td>{{logentry.time}}</td>
<td class="user-image">
<div class="user-image-inner">
<a href="{{unbound logentry.userpath}}" data-user-card="{{unbound logentry.username}}">{{avatar logentry imageSize="large"}}</a>
</div>
</td>
<td>{{logentry.status}}</td>
<td>{{logentry.url}}</td>
<td>{{logentry.error}}</td>
</tr>
{{/each}}
</table>
</div>
</div>

Datei anzeigen

@ -1,3 +1,18 @@
<div class="admin-wizard-controls">
{{combo-box
value=apiName
content=apiList
onChange=(route-action 'changeApi')
options=(hash
none='admin.wizard.api.select'
)}}
{{d-button
action="createApi"
label="admin.wizard.api.create"
icon="plus"}}
</div>
<div class="admin-wizard-container">
{{outlet}}
</div>

Datei anzeigen

@ -180,6 +180,7 @@
action=action
currentActionId=currentAction.id
wizard=wizard
apis=apis
removeAction="removeAction"
wizardFields=wizardFields}}
{{/each}}

Datei anzeigen

@ -29,6 +29,8 @@
}
.wizard-api-header {
margin-top: 20px;
&.page {
margin-bottom: 20px;
}
@ -39,6 +41,7 @@
.wizard-header {
overflow: hidden;
font-size: 1.3em;
}
}

Datei anzeigen

@ -236,7 +236,9 @@ en:
api:
label: "API"
nav_label: 'APIs'
new: 'New Api'
select: "Select API"
create: "Create API"
new: 'New API'
name: "Name (can't be changed)"
name_placeholder: 'Underscored'
title: 'Title'

Datei anzeigen

@ -24,11 +24,10 @@ Discourse::Application.routes.append do
get 'admin/wizards/submissions/:wizard_id/download' => 'admin_submissions#download'
get 'admin/wizards/api' => 'admin_api#list'
get 'admin/wizards/api/new' => 'admin_api#index'
get 'admin/wizards/api/:name' => 'admin_api#find'
put 'admin/wizards/api/:name' => 'admin_api#save'
delete 'admin/wizards/api/:name' => 'admin_api#remove'
delete 'admin/wizards/api/log/:name' => 'admin_api#clearlogs'
delete 'admin/wizards/api/:name/logs' => 'admin_api#clearlogs'
get 'admin/wizards/api/:name/redirect' => 'admin_api#redirect'
get 'admin/wizards/api/:name/authorize' => 'admin_api#authorize'

Datei anzeigen

@ -1,12 +1,8 @@
class CustomWizard::AdminApiController < CustomWizard::AdminController
skip_before_action :check_xhr, only: [:redirect]
def index
end
def list
serializer = ActiveModel::ArraySerializer.new(
CustomWizard::Api.list,
serializer = ActiveModel::ArraySerializer.new(CustomWizard::Api.list,
each_serializer: CustomWizard::BasicApiSerializer
)
render json: MultiJson.dump(serializer)