0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-25 18:50:27 +01:00

Isolated custom field removal

Dieser Commit ist enthalten in:
Angus McLeod 2020-11-09 21:44:32 +11:00
Ursprung 848a0dc0ca
Commit 155eabd377
8 geänderte Dateien mit 78 neuen und 17 gelöschten Zeilen

Datei anzeigen

@ -13,7 +13,8 @@ export default Component.extend({
tagName: 'tr', tagName: 'tr',
topicSerializers: ['topic_view', 'topic_list_item'], topicSerializers: ['topic_view', 'topic_list_item'],
postSerializers: ['post'], postSerializers: ['post'],
categorySerializers: ['basic_category', 'topic_view', 'topic_list_item'], groupSerializers: ['basic_group'],
categorySerializers: ['basic_category'],
klassContent: generateContent(['topic', 'post', 'group', 'category'], 'klass'), klassContent: generateContent(['topic', 'post', 'group', 'category'], 'klass'),
typeContent: generateContent(['string', 'boolean', 'integer', 'json'], 'type'), typeContent: generateContent(['string', 'boolean', 'integer', 'json'], 'type'),
showInputs: or('field.new', 'field.edit'), showInputs: or('field.new', 'field.edit'),
@ -37,9 +38,12 @@ export default Component.extend({
close() { close() {
if (this.field.edit) { if (this.field.edit) {
this.set('field.edit', false); this.set('field.edit', false);
} else {
this.removeField(this.field);
} }
},
destroy() {
this.set('removing', true);
this.removeField(this.field);
} }
} }
}); });

Datei anzeigen

@ -11,14 +11,10 @@ export default Controller.extend({
actions: { actions: {
addField() { addField() {
this.get('customFields').pushObject( this.get('customFields').pushObject(
CustomWizardCustomField.create() CustomWizardCustomField.create({ edit: true })
); );
}, },
removeField(field) {
this.get('customFields').removeObject(field);
},
saveFields() { saveFields() {
this.set('saving', true); this.set('saving', true);
CustomWizardCustomField.saveFields(this.customFields) CustomWizardCustomField.saveFields(this.customFields)
@ -29,9 +25,17 @@ export default Controller.extend({
this.set('saveIcon', 'times'); this.set('saveIcon', 'times');
} }
setTimeout(() => this.set('saveIcon', ''), 5000); setTimeout(() => this.set('saveIcon', ''), 5000);
this.get('customFields').setEach('edit', false);
}).finally(() => { }).finally(() => {
this.set('saving', false); this.set('saving', false);
}); });
},
removeField(field) {
CustomWizardCustomField.removeField(field)
.then(result => {
this.get('customFields').removeObject(field);
});
} }
} }
}); });

Datei anzeigen

@ -23,6 +23,12 @@ CustomWizardCustomField.reopenClass({
custom_fields: customFields custom_fields: customFields
}) })
}).catch(popupAjaxError); }).catch(popupAjaxError);
},
removeField(field) {
return ajax(`${basePath}/${field.name}`, {
type: 'DELETE'
}).catch(popupAjaxError);
} }
}); });

Datei anzeigen

@ -39,6 +39,14 @@
<td><label>{{field.name}}</label></td> <td><label>{{field.name}}</label></td>
<td> <td>
{{d-button action="edit" icon="pencil-alt"}} {{d-button action="edit" icon="pencil-alt"}}
{{d-button action="close" icon="times"}} {{#if field.edit}}
{{d-button action="close" icon="times"}}
{{else}}
{{#if destroying}}
{{loading-spinner size="small"}}
{{else}}
{{d-button action="destroy" icon="trash-alt"}}
{{/if}}
{{/if}}
</td> </td>
{{/if}} {{/if}}

Datei anzeigen

@ -589,6 +589,11 @@
td { td {
vertical-align: top; vertical-align: top;
label {
margin: 0;
line-height: 30px;
}
} }
td:not(:last-of-type) { td:not(:last-of-type) {

Datei anzeigen

@ -21,6 +21,7 @@ Discourse::Application.routes.append do
get 'admin/wizards/custom-fields' => 'admin_custom_fields#index' get 'admin/wizards/custom-fields' => 'admin_custom_fields#index'
put 'admin/wizards/custom-fields' => 'admin_custom_fields#update' put 'admin/wizards/custom-fields' => 'admin_custom_fields#update'
delete 'admin/wizards/custom-fields/:name' => 'admin_custom_fields#destroy'
get 'admin/wizards/submissions' => 'admin_submissions#index' get 'admin/wizards/submissions' => 'admin_submissions#index'
get 'admin/wizards/submissions/:wizard_id' => 'admin_submissions#show' get 'admin/wizards/submissions/:wizard_id' => 'admin_submissions#show'

Datei anzeigen

@ -12,12 +12,17 @@ class CustomWizard::AdminCustomFieldsController < CustomWizard::AdminController
if saved_field = CustomWizard::CustomField.find(field_param[:name]) if saved_field = CustomWizard::CustomField.find(field_param[:name])
CustomWizard::CustomField::ATTRS.each do |attr| CustomWizard::CustomField::ATTRS.each do |attr|
field_data[attr] = field_param[attr] || saved_field.send(attr) field_data[attr] = saved_field.send(attr)
end end
field_id = saved_field.id field_id = saved_field.id
end end
fields_to_save.push(CustomWizard::CustomField.new(field_id, field_data)) CustomWizard::CustomField::ATTRS.each do |attr|
field_data[attr] = field_param[attr]
end
field = CustomWizard::CustomField.new(field_id, field_data)
fields_to_save.push(field)
end end
PluginStoreRow.transaction do PluginStoreRow.transaction do
@ -34,6 +39,16 @@ class CustomWizard::AdminCustomFieldsController < CustomWizard::AdminController
render json: success_json render json: success_json
end end
def destroy
params.require(:name)
if CustomWizard::CustomField.destroy(params[:name])
render json: success_json
else
render json: failed_json
end
end
private private
def custom_field_params def custom_field_params

Datei anzeigen

@ -50,7 +50,7 @@ class ::CustomWizard::CustomField
end end
if self.class.save_to_store(id, key, data) if self.class.save_to_store(id, key, data)
self.class.reset self.class.invalidate_cache
true true
else else
false false
@ -65,8 +65,10 @@ class ::CustomWizard::CustomField
value = send(attr) value = send(attr)
i18n_key = "wizard.custom_field.error" i18n_key = "wizard.custom_field.error"
if REQUIRED.include?(attr) && value.blank? if value.blank?
I18n.t("#{i18n_key}.required_attribute", attr: attr) if REQUIRED.include?(attr)
add_error(I18n.t("#{i18n_key}.required_attribute", attr: attr))
end
next next
end end
@ -170,4 +172,20 @@ class ::CustomWizard::CustomField
record.save record.save
end end
end end
def self.destroy(name)
if exists?(name)
PluginStoreRow.where(plugin_name: NAMESPACE, key: name).destroy_all
invalidate_cache
true
else
false
end
end
def self.invalidate_cache
self.reset
Discourse.clear_readonly!
Discourse.request_refresh!
end
end end