init
Dieser Commit ist enthalten in:
Ursprung
94c56ef550
Commit
d221d65d77
12 geänderte Dateien mit 209 neuen und 0 gelöschten Zeilen
|
@ -0,0 +1,28 @@
|
|||
import Controller from "@ember/controller";
|
||||
import EmberObject from '@ember/object';
|
||||
import { ajax } from 'discourse/lib/ajax';
|
||||
import { popupAjaxError } from 'discourse/lib/ajax-error';
|
||||
|
||||
export default Controller.extend({
|
||||
fieldKeys: ['klass', 'name', 'type'],
|
||||
classes: ['topic', 'user', 'group'],
|
||||
|
||||
actions: {
|
||||
addField() {
|
||||
this.get('customFields').pushObject(
|
||||
EmberObject.create({
|
||||
new: true
|
||||
})
|
||||
);
|
||||
},
|
||||
|
||||
saveFields() {
|
||||
ajax(`/admin/wizards/custom-fields`, {
|
||||
type: 'PUT',
|
||||
data: {
|
||||
custom_fields: this.customFields
|
||||
}
|
||||
}).catch(popupAjaxError)
|
||||
}
|
||||
}
|
||||
});
|
|
@ -7,6 +7,8 @@ export default {
|
|||
this.route('adminWizardsWizardShow', { path: '/:wizardId/', resetNamespace: true });
|
||||
});
|
||||
|
||||
this.route('adminWizardsCustomFields', { path: '/custom-fields', resetNamespace: true });
|
||||
|
||||
this.route('adminWizardsSubmissions', { path: '/submissions', resetNamespace: true }, function() {
|
||||
this.route('adminWizardsSubmissionsShow', { path: '/:wizardId/', resetNamespace: true });
|
||||
})
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
import DiscourseRoute from "discourse/routes/discourse";
|
||||
import { ajax } from 'discourse/lib/ajax';
|
||||
import { A } from "@ember/array";
|
||||
|
||||
export default DiscourseRoute.extend({
|
||||
model() {
|
||||
return ajax('/admin/wizards/custom-fields');
|
||||
},
|
||||
|
||||
setupController(controller, model) {
|
||||
controller.set('customFields', A(model || []));
|
||||
}
|
||||
});
|
|
@ -0,0 +1,33 @@
|
|||
<div class="admin-wizard-controls">
|
||||
<h3>{{i18n 'admin.wizard.custom_fields.nav_label'}}</h3>
|
||||
|
||||
{{d-button
|
||||
label="add"
|
||||
icon="plus"
|
||||
action="addField"}}
|
||||
</div>
|
||||
|
||||
<div class="admin-wizard-container">
|
||||
{{#if model}}
|
||||
<table>
|
||||
<tr>
|
||||
{{#each fieldKeys as |key|}}
|
||||
<th>{{i18n (concat "admin.wizard.custom_fields." key)}}</th>
|
||||
{{/each}}
|
||||
</tr>
|
||||
{{#each customFields as |field|}}
|
||||
<tr>
|
||||
{{#if field.new}}
|
||||
<td>{{combo-box value=field.klass content=classes onChange=(action (mut field.klass))}}</td>
|
||||
<td>{{input value=field.name}}</td>
|
||||
<td>{{combo-box value=field.type content=types onChange=(action (mut field.type))}}</td>
|
||||
{{else}}
|
||||
{{#each-in field as |k v|}}
|
||||
<td>{{v}}</td>
|
||||
{{/each-in}}
|
||||
{{/if}}
|
||||
</tr>
|
||||
{{/each}}
|
||||
</table>
|
||||
{{/if}}
|
||||
</div>
|
|
@ -1,5 +1,6 @@
|
|||
{{#admin-nav}}
|
||||
{{nav-item route='adminWizardsWizard' label='admin.wizard.nav_label'}}
|
||||
{{nav-item route='adminWizardsCustomFields' label='admin.wizard.custom_fields.nav_label'}}
|
||||
{{nav-item route='adminWizardsSubmissions' label='admin.wizard.submissions.nav_label'}}
|
||||
{{#if siteSettings.wizard_apis_enabled}}
|
||||
{{nav-item route='adminWizardsApi' label='admin.wizard.api.nav_label'}}
|
||||
|
|
|
@ -731,6 +731,7 @@
|
|||
options=(hash
|
||||
inputTypes='association'
|
||||
wizardFieldSelection='value'
|
||||
wizardActionSelection='value'
|
||||
userFieldSelection='value'
|
||||
keyPlaceholder='admin.wizard.action.custom_fields.key'
|
||||
context='action'
|
||||
|
|
|
@ -274,6 +274,12 @@ en:
|
|||
visibility_level: Visibility Level
|
||||
members_visibility_level: Members Visibility Level
|
||||
|
||||
custom_fields:
|
||||
nav_label: "Custom Fields"
|
||||
klass: "Class"
|
||||
name: "Name"
|
||||
type: "Type"
|
||||
|
||||
submissions:
|
||||
nav_label: "Submissions"
|
||||
title: "{{name}} Submissions"
|
||||
|
|
40
controllers/custom_wizard/admin/custom_fields.rb
Normale Datei
40
controllers/custom_wizard/admin/custom_fields.rb
Normale Datei
|
@ -0,0 +1,40 @@
|
|||
class CustomWizard::CustomFieldsController < CustomWizard::AdminController
|
||||
def index
|
||||
render_custom_field_list
|
||||
end
|
||||
|
||||
def update
|
||||
field_data = params[:custom_fields]
|
||||
|
||||
custom_fields = field_data.map { |data| CustomWizard::CustomFields.new(data) }
|
||||
|
||||
custom_fields.each do |field_data|
|
||||
custom_field.validate
|
||||
|
||||
unless custom_field.valid?
|
||||
raise Discourse::InvalidParameters, "Invalid field: '#{custom_field.name}'"
|
||||
end
|
||||
end
|
||||
|
||||
all_fields_saved = true
|
||||
|
||||
custom_fields.each do |field|
|
||||
unless field.save
|
||||
all_fields_saved = false
|
||||
end
|
||||
end
|
||||
|
||||
if all_fields_saved
|
||||
render_custom_field_list
|
||||
else
|
||||
render json: error_json
|
||||
end
|
||||
end
|
||||
|
||||
def render_custom_field_list
|
||||
render_serialized(
|
||||
CustomWizard::CustomFields.list,
|
||||
CustomWizard::CustomFieldsSerializer
|
||||
)
|
||||
end
|
||||
end
|
61
lib/custom_wizard/custom_fields.rb
Normale Datei
61
lib/custom_wizard/custom_fields.rb
Normale Datei
|
@ -0,0 +1,61 @@
|
|||
class ::CustomWizard::CustomFields
|
||||
include HasErrors
|
||||
include ActiveModel::Serialization
|
||||
|
||||
CLASSES ||= ["topic", "user", "group", "category"]
|
||||
ATTRS ||= ["name", "klass", "type"]
|
||||
KEY ||= "custom_wizard_custom_fields"
|
||||
|
||||
def initialize(data)
|
||||
data = data.with_indifferent_access
|
||||
|
||||
ATTRS.each do |attr|
|
||||
self.class.class_eval { attr_accessor attr }
|
||||
send("#{attr}=", data[attr]) if data[attr].present?
|
||||
end
|
||||
end
|
||||
|
||||
def save
|
||||
validate
|
||||
|
||||
if valid?
|
||||
data = {}
|
||||
name = nil
|
||||
|
||||
ATTRS.each do |attr|
|
||||
value = send(attr)
|
||||
|
||||
if attr == 'name'
|
||||
name = value
|
||||
else
|
||||
data[attr] = value
|
||||
end
|
||||
end
|
||||
|
||||
PluginStore.set(KEY, name, data)
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
def validate
|
||||
ATTRS.each do |attr|
|
||||
value = send(attr)
|
||||
add_error("Attribute required: #{attr}") if value.blank?
|
||||
add_error("Unsupported class: #{value}") if CLASSES.exclude?(value)
|
||||
end
|
||||
end
|
||||
|
||||
def valid?
|
||||
errors.blank?
|
||||
end
|
||||
|
||||
def self.list
|
||||
PluginStoreRow.where(plugin_name: KEY)
|
||||
.map do |record|
|
||||
data = JSON.parse(record.value)
|
||||
data[:name] = record.key
|
||||
self.new(data)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -320,6 +320,10 @@ class CustomWizard::Wizard
|
|||
Jobs.cancel_scheduled_job(:set_after_time_wizard, wizard_id: wizard[:id])
|
||||
Jobs.enqueue(:clear_after_time_wizard, wizard_id: wizard[:id])
|
||||
end
|
||||
|
||||
if serialize_fields.present?
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
wizard[:id]
|
||||
|
|
17
plugin.rb
17
plugin.rb
|
@ -42,6 +42,7 @@ after_initialize do
|
|||
../controllers/custom_wizard/admin/submissions.rb
|
||||
../controllers/custom_wizard/admin/api.rb
|
||||
../controllers/custom_wizard/admin/logs.rb
|
||||
../controllers/custom_wizard/admin/custom_fields.rb
|
||||
../controllers/custom_wizard/wizard.rb
|
||||
../controllers/custom_wizard/steps.rb
|
||||
../controllers/custom_wizard/transfer.rb
|
||||
|
@ -51,6 +52,7 @@ after_initialize do
|
|||
../lib/custom_wizard/action_result.rb
|
||||
../lib/custom_wizard/action.rb
|
||||
../lib/custom_wizard/builder.rb
|
||||
../lib/custom_wizard/custom_fields.rb
|
||||
../lib/custom_wizard/field.rb
|
||||
../lib/custom_wizard/mapper.rb
|
||||
../lib/custom_wizard/log.rb
|
||||
|
@ -68,6 +70,7 @@ after_initialize do
|
|||
../serializers/custom_wizard/api_serializer.rb
|
||||
../serializers/custom_wizard/basic_api_serializer.rb
|
||||
../serializers/custom_wizard/basic_wizard_serializer.rb
|
||||
../serializers/custom_wizard/custom_fields_serializer.rb
|
||||
../serializers/custom_wizard/wizard_field_serializer.rb
|
||||
../serializers/custom_wizard/wizard_step_serializer.rb
|
||||
../serializers/custom_wizard/wizard_serializer.rb
|
||||
|
@ -160,5 +163,19 @@ after_initialize do
|
|||
|
||||
CustomWizard::Wizard.register_styles
|
||||
|
||||
CustomWizard::CustomFields.list.each do |field|
|
||||
add_to_class(field.klass.to_sym, field.name.to_sym) do
|
||||
custom_fields[field.name]
|
||||
end
|
||||
|
||||
add_to_serializer(field.klass.to_sym, field.name.to_sym) do
|
||||
if field.klass === 'topic'
|
||||
object.topic.send(field.name)
|
||||
else
|
||||
object.send(field.name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
DiscourseEvent.trigger(:custom_wizard_ready)
|
||||
end
|
||||
|
|
3
serializers/custom_wizard/custom_fields_serializer.rb
Normale Datei
3
serializers/custom_wizard/custom_fields_serializer.rb
Normale Datei
|
@ -0,0 +1,3 @@
|
|||
class CustomWizard::CustomFieldsSerializer < ApplicationSerializer
|
||||
attributes :klass, :name, :type
|
||||
end
|
Laden …
In neuem Issue referenzieren