diff --git a/assets/javascripts/discourse/components/wizard-custom-action.js.es6 b/assets/javascripts/discourse/components/wizard-custom-action.js.es6 index 28a361c3..95ac4dd7 100644 --- a/assets/javascripts/discourse/components/wizard-custom-action.js.es6 +++ b/assets/javascripts/discourse/components/wizard-custom-action.js.es6 @@ -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; diff --git a/assets/javascripts/discourse/controllers/admin-wizards-api-show.js.es6 b/assets/javascripts/discourse/controllers/admin-wizards-api-show.js.es6 index d083b157..f449e19a 100644 --- a/assets/javascripts/discourse/controllers/admin-wizards-api-show.js.es6 +++ b/assets/javascripts/discourse/controllers/admin-wizards-api-show.js.es6 @@ -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 => { diff --git a/assets/javascripts/discourse/models/custom-wizard-api.js.es6 b/assets/javascripts/discourse/models/custom-wizard-api.js.es6 index 5359534e..14fb5469 100644 --- a/assets/javascripts/discourse/models/custom-wizard-api.js.es6 +++ b/assets/javascripts/discourse/models/custom-wizard-api.js.es6 @@ -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; diff --git a/assets/javascripts/discourse/routes/admin-wizards-api-show.js.es6 b/assets/javascripts/discourse/routes/admin-wizards-api-show.js.es6 index 6d710c41..b77074d5 100644 --- a/assets/javascripts/discourse/routes/admin-wizards-api-show.js.es6 +++ b/assets/javascripts/discourse/routes/admin-wizards-api-show.js.es6 @@ -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); diff --git a/assets/javascripts/discourse/routes/admin-wizards-api.js.es6 b/assets/javascripts/discourse/routes/admin-wizards-api.js.es6 index 62ecd8fe..65c17865 100644 --- a/assets/javascripts/discourse/routes/admin-wizards-api.js.es6 +++ b/assets/javascripts/discourse/routes/admin-wizards-api.js.es6 @@ -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'); + } } + }); \ No newline at end of file diff --git a/assets/javascripts/discourse/routes/admin-wizards-wizard-show.js.es6 b/assets/javascripts/discourse/routes/admin-wizards-wizard-show.js.es6 index 1700bf6c..5530ec33 100644 --- a/assets/javascripts/discourse/routes/admin-wizards-wizard-show.js.es6 +++ b/assets/javascripts/discourse/routes/admin-wizards-wizard-show.js.es6 @@ -26,7 +26,7 @@ export default DiscourseRoute.extend({ name: I18n.t(`admin.wizard.field.type.${type}`) }; }) - + let props = { wizardList: parentModel.wizard_list, fieldTypes, diff --git a/assets/javascripts/discourse/templates/admin-wizards-api-show.hbs b/assets/javascripts/discourse/templates/admin-wizards-api-show.hbs index c484ab77..465e11aa 100644 --- a/assets/javascripts/discourse/templates/admin-wizards-api-show.hbs +++ b/assets/javascripts/discourse/templates/admin-wizards-api-show.hbs @@ -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 @@
-
- - - - - - - {{#each api.log as |logentry|}} - - - - - - - - {{/each}} -
DatetimeUserStatusURLError
{{logentry.time}} - - {{logentry.status}}{{logentry.url}}{{logentry.error}}
-
+
+ + + + + + + {{#each api.log as |logentry|}} + + + + + + + + {{/each}} +
DatetimeUserStatusURLError
{{logentry.time}} + + {{logentry.status}}{{logentry.url}}{{logentry.error}}
+
diff --git a/assets/javascripts/discourse/templates/admin-wizards-api.hbs b/assets/javascripts/discourse/templates/admin-wizards-api.hbs index 0425da3e..5f0c02ff 100644 --- a/assets/javascripts/discourse/templates/admin-wizards-api.hbs +++ b/assets/javascripts/discourse/templates/admin-wizards-api.hbs @@ -1,3 +1,18 @@ +
+ {{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"}} +
+
{{outlet}} -
\ No newline at end of file + diff --git a/assets/javascripts/discourse/templates/admin-wizards-wizard-show.hbs b/assets/javascripts/discourse/templates/admin-wizards-wizard-show.hbs index 81075e49..65cbc16e 100644 --- a/assets/javascripts/discourse/templates/admin-wizards-wizard-show.hbs +++ b/assets/javascripts/discourse/templates/admin-wizards-wizard-show.hbs @@ -180,6 +180,7 @@ action=action currentActionId=currentAction.id wizard=wizard + apis=apis removeAction="removeAction" wizardFields=wizardFields}} {{/each}} diff --git a/assets/stylesheets/common/wizard-api.scss b/assets/stylesheets/common/wizard-api.scss index 397fe7e4..2bd437ca 100644 --- a/assets/stylesheets/common/wizard-api.scss +++ b/assets/stylesheets/common/wizard-api.scss @@ -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; } } diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 08131f04..49e7bb55 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -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' diff --git a/config/routes.rb b/config/routes.rb index 39702b49..908e9656 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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' diff --git a/controllers/custom_wizard/admin/api.rb b/controllers/custom_wizard/admin/api.rb index 1e811061..b62eb261 100644 --- a/controllers/custom_wizard/admin/api.rb +++ b/controllers/custom_wizard/admin/api.rb @@ -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)