Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-22 09:20:29 +01:00
various
Dieser Commit ist enthalten in:
Ursprung
d8fd5cb258
Commit
dae08e53d4
13 geänderte Dateien mit 148 neuen und 69 gelöschten Zeilen
|
@ -1,3 +1,3 @@
|
|||
{{#if currentUser.admin}}
|
||||
{{nav-item route='adminWizards' label='admin.wizard.nav'}}
|
||||
{{nav-item route='adminWizards' label='admin.wizard.nav_label'}}
|
||||
{{/if}}
|
||||
|
|
|
@ -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")
|
||||
});
|
|
@ -198,8 +198,6 @@ CustomWizard.reopenClass({
|
|||
submissions(wizardId) {
|
||||
return ajax(`/admin/wizards/submissions/${wizardId}`, {
|
||||
type: "GET"
|
||||
}).then(result => {
|
||||
return result.submissions;
|
||||
});
|
||||
},
|
||||
|
||||
|
|
|
@ -2,13 +2,31 @@ import CustomWizard from '../models/custom-wizard';
|
|||
import DiscourseRoute from "discourse/routes/discourse";
|
||||
|
||||
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) {
|
||||
const wizardId = params.wizard_id;
|
||||
if (wizardId && wizardId !== 'new') {
|
||||
return CustomWizard.submissions(params.wizard_id);
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
},
|
||||
|
||||
setupController(controller, model) {
|
||||
if (model.submissions) {
|
||||
let fields = [];
|
||||
model.forEach((s) => {
|
||||
model.submissions.forEach((s) => {
|
||||
Object.keys(s).forEach((k) => {
|
||||
if (fields.indexOf(k) < 0) {
|
||||
fields.push(k);
|
||||
|
@ -17,7 +35,7 @@ export default DiscourseRoute.extend({
|
|||
});
|
||||
|
||||
let submissions = [];
|
||||
model.forEach((s) => {
|
||||
model.submissions.forEach((s) => {
|
||||
let submission = {};
|
||||
fields.forEach((f) => {
|
||||
submission[f] = s[f];
|
||||
|
@ -25,6 +43,13 @@ export default DiscourseRoute.extend({
|
|||
submissions.push(submission);
|
||||
});
|
||||
|
||||
controller.setProperties({ submissions, fields });
|
||||
console.log(model.id)
|
||||
|
||||
controller.setProperties({
|
||||
wizard: model.wizard,
|
||||
submissions,
|
||||
fields
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -2,6 +2,6 @@ import DiscourseRoute from "discourse/routes/discourse";
|
|||
|
||||
export default DiscourseRoute.extend({
|
||||
redirect() {
|
||||
this.transitionTo('adminWizard', 'first');
|
||||
this.transitionTo('adminWizardSubmissions', 'first');
|
||||
}
|
||||
});
|
|
@ -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">
|
||||
<table>
|
||||
<tr>
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
name="background"
|
||||
value=model.background
|
||||
placeholderKey="admin.wizard.background_placeholder"
|
||||
class="medium"}}
|
||||
class="small"}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="content">
|
||||
<div class="content submissions">
|
||||
{{outlet}}
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
{{#admin-nav}}
|
||||
{{nav-item route='adminWizardsCustom' label='admin.wizard.custom_label'}}
|
||||
{{nav-item route='adminWizardsSubmissions' label='admin.wizard.submissions_label'}}
|
||||
{{nav-item route='adminWizardsCustom' label='admin.wizard.nav_label'}}
|
||||
{{nav-item route='adminWizardsSubmissions' label='admin.wizard.submissions.nav_label'}}
|
||||
{{#if siteSettings.wizard_api_features}}
|
||||
{{nav-item route='adminWizardsApis' label='admin.wizard.api.nav_label'}}
|
||||
{{/if}}
|
||||
{{nav-item route='adminWizardsTransfer' label='admin.wizard.transfer.nav_label'}}
|
||||
{{/admin-nav}}
|
||||
|
||||
<div class="admin-container">
|
||||
<div class="admin-container admin-wizard-container">
|
||||
{{outlet}}
|
||||
</div>
|
||||
|
|
|
@ -2,14 +2,26 @@
|
|||
@import 'wizard-transfer';
|
||||
@import 'wizard-api';
|
||||
|
||||
body.admin-wizard {
|
||||
.admin-container > .row {
|
||||
.admin-wizard-container {
|
||||
.row {
|
||||
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 {
|
||||
|
@ -97,11 +109,21 @@ body.admin-wizard {
|
|||
min-height: 31px;
|
||||
margin-bottom: 30px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
|
||||
input {
|
||||
margin-bottom: 0;
|
||||
width: 350px;
|
||||
}
|
||||
|
||||
label {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.download-link {
|
||||
font-size: 1rem;
|
||||
line-height: 20px;
|
||||
}
|
||||
}
|
||||
|
||||
&.medium {
|
||||
|
@ -138,8 +160,6 @@ body.admin-wizard {
|
|||
}
|
||||
|
||||
.admin-wizard.settings {
|
||||
margin-top: 10px;
|
||||
margin-left: 30px;
|
||||
|
||||
[class~='setting'] {
|
||||
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 {
|
||||
width: 100%;
|
||||
min-height: 150px;
|
||||
|
|
|
@ -7,12 +7,10 @@ en:
|
|||
admin:
|
||||
wizard:
|
||||
label: "Wizard"
|
||||
nav: "Wizards"
|
||||
nav_label: "Wizards"
|
||||
new: "New"
|
||||
custom_label: "Custom"
|
||||
submissions_label: "Submissions"
|
||||
name: "Name"
|
||||
name_placeholder: "name"
|
||||
name_placeholder: "wizard name"
|
||||
background: "Background"
|
||||
background_placeholder: "#hex"
|
||||
save_submissions: "Save"
|
||||
|
@ -198,6 +196,11 @@ en:
|
|||
body: "Body"
|
||||
body_placeholder: "JSON"
|
||||
|
||||
submissions:
|
||||
nav_label: "Submissions"
|
||||
title: "{{name}} Submissions"
|
||||
download: "Download"
|
||||
|
||||
api:
|
||||
label: "API"
|
||||
nav_label: 'APIs'
|
||||
|
|
|
@ -17,10 +17,12 @@ Discourse::Application.routes.append do
|
|||
get 'admin/wizards/custom/new' => 'admin#index'
|
||||
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'
|
||||
put 'admin/wizards/custom/save' => 'admin#save'
|
||||
delete 'admin/wizards/custom/remove' => 'admin#remove'
|
||||
get 'admin/wizards/submissions' => 'admin#index'
|
||||
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/new' => 'api#index'
|
||||
get 'admin/wizards/apis/:name' => 'api#find'
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class CustomWizard::AdminController < ::ApplicationController
|
||||
before_action :ensure_logged_in
|
||||
class CustomWizard::AdminController < ::Admin::AdminController
|
||||
skip_before_action :check_xhr, only: [:download_submissions]
|
||||
before_action :ensure_admin
|
||||
|
||||
def index
|
||||
|
@ -55,38 +55,42 @@ class CustomWizard::AdminController < ::ApplicationController
|
|||
|
||||
def find_wizard
|
||||
params.require(:wizard_id)
|
||||
|
||||
wizard = PluginStore.get('custom_wizard', params[:wizard_id].underscore)
|
||||
|
||||
render json: success_json.merge(wizard: wizard)
|
||||
end
|
||||
|
||||
def custom_wizards
|
||||
rows = PluginStoreRow.where(plugin_name: 'custom_wizard').order(:id)
|
||||
|
||||
wizards = [*rows].map { |r| CustomWizard::Template.new(r.value) }
|
||||
|
||||
render json: success_json.merge(wizards: wizards)
|
||||
end
|
||||
|
||||
def submissions
|
||||
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 user = User.find_by(id: r.key)
|
||||
username = user.username
|
||||
if wizard.present?
|
||||
render json: success_json.merge(
|
||||
submissions: build_submissions(wizard_id),
|
||||
wizard: wizard.slice(:id, :name)
|
||||
)
|
||||
else
|
||||
username = I18n.t('admin.wizard.submissions.no_user', id: r.key)
|
||||
head :ok
|
||||
end
|
||||
end
|
||||
|
||||
submissions.map { |s| { username: username }.merge!(s.except("redirect_to")) }
|
||||
end.flatten
|
||||
def download_submissions
|
||||
params.require(:wizard_id)
|
||||
wizard_id = params[:wizard_id].underscore
|
||||
|
||||
render json: success_json.merge(submissions: all_submissions)
|
||||
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
|
||||
|
||||
private
|
||||
|
@ -244,4 +248,24 @@ class CustomWizard::AdminController < ::ApplicationController
|
|||
|
||||
result
|
||||
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
|
||||
|
|
Laden …
In neuem Issue referenzieren