0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-26 02:50:28 +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; return content;
}, },
@discourseComputed('wizard.apis') @discourseComputed('apis')
availableApis(apis) { availableApis(apis) {
return apis.map(a => { return apis.map(a => {
return { return {
@ -70,7 +70,7 @@ export default Component.extend(UndoChanges, {
}); });
}, },
@discourseComputed('wizard.apis', 'action.api') @discourseComputed('apis', 'action.api')
availableEndpoints(apis, api) { availableEndpoints(apis, api) {
if (!api) return []; if (!api) return [];
return apis.find(a => a.name === api).endpoints; return apis.find(a => a.name === api).endpoints;

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -1,7 +1,45 @@
import DiscourseRoute from "discourse/routes/discourse"; import DiscourseRoute from "discourse/routes/discourse";
import CustomWizardApi from '../models/custom-wizard-api';
export default DiscourseRoute.extend({ export default DiscourseRoute.extend({
beforeModel() { model() {
this.transitionTo('adminWizardsApiShow'); 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 {{combo-box
value=api.authType value=api.authType
content=authorizationTypes content=authorizationTypes
onChange=(action (mut authorizationTypes)) onChange=(action (mut api.authType))
options=(hash options=(hash
none='admin.wizard.api.auth.type_none' none='admin.wizard.api.auth.type_none'
)}} )}}
@ -261,8 +261,8 @@
none="admin.wizard.api.endpoint.content_type" none="admin.wizard.api.endpoint.content_type"
)}} )}}
{{multi-select {{multi-select
value=endpoint.success_codes
content=successCodes content=successCodes
values=endpoint.success_codes
onChange=(action (mut endpoint.success_codes)) onChange=(action (mut endpoint.success_codes))
options=(hash options=(hash
none="admin.wizard.api.endpoint.success_codes" none="admin.wizard.api.endpoint.success_codes"
@ -285,26 +285,26 @@
</div> </div>
<div class="wizard-api-log"> <div class="wizard-api-log">
<div class="log-list"> <div class="log-list">
<table class="wizard-api-log-table"> <table class="wizard-api-log-table">
<th>Datetime</th> <th>Datetime</th>
<th>User</th> <th>User</th>
<th>Status</th> <th>Status</th>
<th>URL</th> <th>URL</th>
<th>Error</th> <th>Error</th>
{{#each api.log as |logentry|}} {{#each api.log as |logentry|}}
<tr> <tr>
<td>{{logentry.time}}</td> <td>{{logentry.time}}</td>
<td class="user-image"> <td class="user-image">
<div class="user-image-inner"> <div class="user-image-inner">
<a href="{{unbound logentry.userpath}}" data-user-card="{{unbound logentry.username}}">{{avatar logentry imageSize="large"}}</a> <a href="{{unbound logentry.userpath}}" data-user-card="{{unbound logentry.username}}">{{avatar logentry imageSize="large"}}</a>
</div> </div>
</td> </td>
<td>{{logentry.status}}</td> <td>{{logentry.status}}</td>
<td>{{logentry.url}}</td> <td>{{logentry.url}}</td>
<td>{{logentry.error}}</td> <td>{{logentry.error}}</td>
</tr> </tr>
{{/each}} {{/each}}
</table> </table>
</div> </div>
</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"> <div class="admin-wizard-container">
{{outlet}} {{outlet}}
</div> </div>

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -236,7 +236,9 @@ en:
api: api:
label: "API" label: "API"
nav_label: 'APIs' nav_label: 'APIs'
new: 'New Api' select: "Select API"
create: "Create API"
new: 'New API'
name: "Name (can't be changed)" name: "Name (can't be changed)"
name_placeholder: 'Underscored' name_placeholder: 'Underscored'
title: 'Title' 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/submissions/:wizard_id/download' => 'admin_submissions#download'
get 'admin/wizards/api' => 'admin_api#list' get 'admin/wizards/api' => 'admin_api#list'
get 'admin/wizards/api/new' => 'admin_api#index'
get 'admin/wizards/api/:name' => 'admin_api#find' get 'admin/wizards/api/:name' => 'admin_api#find'
put 'admin/wizards/api/:name' => 'admin_api#save' put 'admin/wizards/api/:name' => 'admin_api#save'
delete 'admin/wizards/api/:name' => 'admin_api#remove' 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/redirect' => 'admin_api#redirect'
get 'admin/wizards/api/:name/authorize' => 'admin_api#authorize' get 'admin/wizards/api/:name/authorize' => 'admin_api#authorize'

Datei anzeigen

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