0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-22 09:20:29 +01:00
Dieser Commit ist enthalten in:
Angus McLeod 2020-04-12 09:27:16 +10:00
Ursprung d8fd5cb258
Commit dae08e53d4
13 geänderte Dateien mit 148 neuen und 69 gelöschten Zeilen

Datei anzeigen

@ -1,3 +1,3 @@
{{#if currentUser.admin}} {{#if currentUser.admin}}
{{nav-item route='adminWizards' label='admin.wizard.nav'}} {{nav-item route='adminWizards' label='admin.wizard.nav_label'}}
{{/if}} {{/if}}

Datei anzeigen

@ -0,0 +1,6 @@
import Controller from "@ember/controller";
import { fmt } from "discourse/lib/computed";
export default Controller.extend({
downloadUrl: fmt("wizard.id", "/admin/wizards/submissions/%@/download")
});

Datei anzeigen

@ -198,8 +198,6 @@ CustomWizard.reopenClass({
submissions(wizardId) { submissions(wizardId) {
return ajax(`/admin/wizards/submissions/${wizardId}`, { return ajax(`/admin/wizards/submissions/${wizardId}`, {
type: "GET" type: "GET"
}).then(result => {
return result.submissions;
}); });
}, },

Datei anzeigen

@ -2,29 +2,54 @@ import CustomWizard from '../models/custom-wizard';
import DiscourseRoute from "discourse/routes/discourse"; import DiscourseRoute from "discourse/routes/discourse";
export default DiscourseRoute.extend({ export default DiscourseRoute.extend({
beforeModel() {
const param = this.paramsFor('adminWizardSubmissions').wizard_id;
const wizards = this.modelFor('admin-wizards-submissions');
if (wizards.length && (param === 'first')) {
const wizard = wizards.get(`${param}Object`);
if (wizard) {
this.transitionTo('adminWizardSubmissions', wizard.id.dasherize());
}
}
},
model(params) { model(params) {
return CustomWizard.submissions(params.wizard_id); const wizardId = params.wizard_id;
if (wizardId && wizardId !== 'new') {
return CustomWizard.submissions(params.wizard_id);
} else {
return {};
}
}, },
setupController(controller, model) { setupController(controller, model) {
let fields = []; if (model.submissions) {
model.forEach((s) => { let fields = [];
Object.keys(s).forEach((k) => { model.submissions.forEach((s) => {
if (fields.indexOf(k) < 0) { Object.keys(s).forEach((k) => {
fields.push(k); if (fields.indexOf(k) < 0) {
} fields.push(k);
}
});
}); });
});
let submissions = []; let submissions = [];
model.forEach((s) => { model.submissions.forEach((s) => {
let submission = {}; let submission = {};
fields.forEach((f) => { fields.forEach((f) => {
submission[f] = s[f]; submission[f] = s[f];
});
submissions.push(submission);
}); });
submissions.push(submission);
}); console.log(model.id)
controller.setProperties({ submissions, fields }); controller.setProperties({
wizard: model.wizard,
submissions,
fields
});
}
} }
}); });

Datei anzeigen

@ -2,6 +2,6 @@ import DiscourseRoute from "discourse/routes/discourse";
export default DiscourseRoute.extend({ export default DiscourseRoute.extend({
redirect() { redirect() {
this.transitionTo('adminWizard', 'first'); this.transitionTo('adminWizardSubmissions', 'first');
} }
}); });

Datei anzeigen

@ -1,3 +1,14 @@
<div class="wizard-header large">
<label>{{i18n 'admin.wizard.submissions.title' name=wizard.name}}</label>
<a class="btn btn-default download-link" href="{{downloadUrl}}" target="_blank">
{{d-icon 'download'}}
<span class="d-button-label">
{{i18n "admin.wizard.submissions.download"}}
</span>
</a>
</div>
<div class="wizard-submissions"> <div class="wizard-submissions">
<table> <table>
<tr> <tr>

Datei anzeigen

@ -27,7 +27,7 @@
name="background" name="background"
value=model.background value=model.background
placeholderKey="admin.wizard.background_placeholder" placeholderKey="admin.wizard.background_placeholder"
class="medium"}} class="small"}}
</div> </div>
</div> </div>

Datei anzeigen

@ -9,7 +9,7 @@
</ul> </ul>
</div> </div>
<div class="content"> <div class="content submissions">
{{outlet}} {{outlet}}
</div> </div>
</div> </div>

Datei anzeigen

@ -1,12 +1,12 @@
{{#admin-nav}} {{#admin-nav}}
{{nav-item route='adminWizardsCustom' label='admin.wizard.custom_label'}} {{nav-item route='adminWizardsCustom' label='admin.wizard.nav_label'}}
{{nav-item route='adminWizardsSubmissions' label='admin.wizard.submissions_label'}} {{nav-item route='adminWizardsSubmissions' label='admin.wizard.submissions.nav_label'}}
{{#if siteSettings.wizard_api_features}} {{#if siteSettings.wizard_api_features}}
{{nav-item route='adminWizardsApis' label='admin.wizard.api.nav_label'}} {{nav-item route='adminWizardsApis' label='admin.wizard.api.nav_label'}}
{{/if}} {{/if}}
{{nav-item route='adminWizardsTransfer' label='admin.wizard.transfer.nav_label'}} {{nav-item route='adminWizardsTransfer' label='admin.wizard.transfer.nav_label'}}
{{/admin-nav}} {{/admin-nav}}
<div class="admin-container"> <div class="admin-container admin-wizard-container">
{{outlet}} {{outlet}}
</div> </div>

Datei anzeigen

@ -2,14 +2,26 @@
@import 'wizard-transfer'; @import 'wizard-transfer';
@import 'wizard-api'; @import 'wizard-api';
body.admin-wizard { .admin-wizard-container {
.admin-container > .row { .row {
display: flex; display: flex;
> .content {
flex: 1;
margin-top: 10px;
margin-left: 30px;
table {
margin-top: 0;
min-width: 100%;
width: auto;
}
}
} }
}
.boxed.white {
background-color: initial; .wizard-submissions {
} overflow: scroll;
} }
.wizard-list { .wizard-list {
@ -97,11 +109,21 @@ body.admin-wizard {
min-height: 31px; min-height: 31px;
margin-bottom: 30px; margin-bottom: 30px;
display: flex; display: flex;
justify-content: space-between;
input { input {
margin-bottom: 0; margin-bottom: 0;
width: 350px; width: 350px;
} }
label {
margin-bottom: 0;
}
.download-link {
font-size: 1rem;
line-height: 20px;
}
} }
&.medium { &.medium {
@ -138,8 +160,6 @@ body.admin-wizard {
} }
.admin-wizard.settings { .admin-wizard.settings {
margin-top: 10px;
margin-left: 30px;
[class~='setting'] { [class~='setting'] {
display: inline-flex; display: inline-flex;
@ -410,16 +430,6 @@ body.admin-wizard {
} }
} }
.admin-contents .wizard-submissions {
width: 100%;
margin-top: 10px;
margin-left: 30px;
table {
margin-top: 0;
}
}
.wizard-field-composer textarea { .wizard-field-composer textarea {
width: 100%; width: 100%;
min-height: 150px; min-height: 150px;

Datei anzeigen

@ -7,12 +7,10 @@ en:
admin: admin:
wizard: wizard:
label: "Wizard" label: "Wizard"
nav: "Wizards" nav_label: "Wizards"
new: "New" new: "New"
custom_label: "Custom"
submissions_label: "Submissions"
name: "Name" name: "Name"
name_placeholder: "name" name_placeholder: "wizard name"
background: "Background" background: "Background"
background_placeholder: "#hex" background_placeholder: "#hex"
save_submissions: "Save" save_submissions: "Save"
@ -197,6 +195,11 @@ en:
select_an_endpoint: "Select an endpoint" select_an_endpoint: "Select an endpoint"
body: "Body" body: "Body"
body_placeholder: "JSON" body_placeholder: "JSON"
submissions:
nav_label: "Submissions"
title: "{{name}} Submissions"
download: "Download"
api: api:
label: "API" label: "API"

Datei anzeigen

@ -17,10 +17,12 @@ Discourse::Application.routes.append do
get 'admin/wizards/custom/new' => 'admin#index' get 'admin/wizards/custom/new' => 'admin#index'
get 'admin/wizards/custom/all' => 'admin#custom_wizards' get 'admin/wizards/custom/all' => 'admin#custom_wizards'
get 'admin/wizards/custom/:wizard_id' => 'admin#find_wizard' get 'admin/wizards/custom/:wizard_id' => 'admin#find_wizard'
get 'admin/wizards/custom/:wizard_id' => 'admin#find_wizard'
put 'admin/wizards/custom/save' => 'admin#save' put 'admin/wizards/custom/save' => 'admin#save'
delete 'admin/wizards/custom/remove' => 'admin#remove' delete 'admin/wizards/custom/remove' => 'admin#remove'
get 'admin/wizards/submissions' => 'admin#index' get 'admin/wizards/submissions' => 'admin#index'
get 'admin/wizards/submissions/:wizard_id' => 'admin#submissions' get 'admin/wizards/submissions/:wizard_id' => 'admin#submissions'
get 'admin/wizards/submissions/:wizard_id/download' => 'admin#download_submissions'
get 'admin/wizards/apis' => 'api#list' get 'admin/wizards/apis' => 'api#list'
get 'admin/wizards/apis/new' => 'api#index' get 'admin/wizards/apis/new' => 'api#index'
get 'admin/wizards/apis/:name' => 'api#find' get 'admin/wizards/apis/:name' => 'api#find'

Datei anzeigen

@ -1,5 +1,5 @@
class CustomWizard::AdminController < ::ApplicationController class CustomWizard::AdminController < ::Admin::AdminController
before_action :ensure_logged_in skip_before_action :check_xhr, only: [:download_submissions]
before_action :ensure_admin before_action :ensure_admin
def index def index
@ -55,38 +55,42 @@ class CustomWizard::AdminController < ::ApplicationController
def find_wizard def find_wizard
params.require(:wizard_id) params.require(:wizard_id)
wizard = PluginStore.get('custom_wizard', params[:wizard_id].underscore) wizard = PluginStore.get('custom_wizard', params[:wizard_id].underscore)
render json: success_json.merge(wizard: wizard) render json: success_json.merge(wizard: wizard)
end end
def custom_wizards def custom_wizards
rows = PluginStoreRow.where(plugin_name: 'custom_wizard').order(:id) rows = PluginStoreRow.where(plugin_name: 'custom_wizard').order(:id)
wizards = [*rows].map { |r| CustomWizard::Template.new(r.value) } wizards = [*rows].map { |r| CustomWizard::Template.new(r.value) }
render json: success_json.merge(wizards: wizards) render json: success_json.merge(wizards: wizards)
end end
def submissions def submissions
params.require(:wizard_id) params.require(:wizard_id)
rows = PluginStoreRow.where(plugin_name: "#{params[:wizard_id]}_submissions").order('id DESC') wizard_id = params[:wizard_id].underscore
wizard = PluginStore.get('custom_wizard', wizard_id)
all_submissions = [*rows].map do |r|
submissions = ::JSON.parse(r.value) if wizard.present?
render json: success_json.merge(
if user = User.find_by(id: r.key) submissions: build_submissions(wizard_id),
username = user.username wizard: wizard.slice(:id, :name)
else )
username = I18n.t('admin.wizard.submissions.no_user', id: r.key) else
end head :ok
end
submissions.map { |s| { username: username }.merge!(s.except("redirect_to")) } end
end.flatten
def download_submissions
render json: success_json.merge(submissions: all_submissions) params.require(:wizard_id)
wizard_id = params[:wizard_id].underscore
wizard = PluginStore.get('custom_wizard', wizard_id)
submissions = build_submissions(wizard_id).to_json
send_data submissions,
filename: "#{Discourse.current_hostname}-wizard-submissions-#{wizard['name']}.json",
content_type: "application/json"
end end
private private
@ -244,4 +248,24 @@ class CustomWizard::AdminController < ::ApplicationController
result result
end end
def build_submissions(wizard_id)
rows = PluginStoreRow.where(plugin_name: "#{wizard_id}_submissions").order('id DESC')
submissions = [*rows].map do |row|
value = ::JSON.parse(row.value)
if user = User.find_by(id: row.key)
username = user.username
else
username = I18n.t('admin.wizard.submissions.no_user', id: row.key)
end
value.map do |submission|
{
username: username
}.merge!(submission.except("redirect_to"))
end
end.flatten
end
end end