0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-25 02:30:28 +01:00
Dieser Commit ist enthalten in:
Angus McLeod 2022-08-02 12:39:56 +01:00
Ursprung 38307c565a
Commit 2cec01ba2c
10 geänderte Dateien mit 71 neuen und 6 gelöschten Zeilen

Datei anzeigen

@ -88,6 +88,7 @@ class CustomWizard::AdminWizardController < CustomWizard::AdminController
:title, :title,
:key, :key,
:banner, :banner,
:banner_upload_id,
:raw_description, :raw_description,
:required_data_message, :required_data_message,
:force_final, :force_final,
@ -99,6 +100,7 @@ class CustomWizard::AdminWizardController < CustomWizard::AdminController
:index, :index,
:label, :label,
:image, :image,
:image_upload_id,
:description, :description,
:required, :required,
:key, :key,

Datei anzeigen

@ -144,11 +144,17 @@ export default Component.extend(UndoChanges, {
actions: { actions: {
imageUploadDone(upload) { imageUploadDone(upload) {
this.set("field.image", upload.url); this.setProperties({
"field.image": upload.url,
"field.image_upload_id": upload.id
});
}, },
imageUploadDeleted() { imageUploadDeleted() {
this.set("field.image", null); this.setProperties({
"field.image": null,
"field.image_upload_id": null
});
}, },
}, },
}); });

Datei anzeigen

@ -24,11 +24,17 @@ export default Component.extend({
actions: { actions: {
bannerUploadDone(upload) { bannerUploadDone(upload) {
this.set("step.banner", upload.url); this.setProperties({
"step.banner": upload.url,
"step.banner_upload_id": upload.id
});
}, },
bannerUploadDeleted() { bannerUploadDeleted() {
this.set("step.banner", null); this.setProperties({
"step.banner": null,
"step.banner_upload_id": null
});
}, },
}, },
}); });

Datei anzeigen

@ -43,6 +43,7 @@ const step = {
title: null, title: null,
key: null, key: null,
banner: null, banner: null,
banner_upload_id: null,
raw_description: null, raw_description: null,
required_data: null, required_data: null,
required_data_message: null, required_data_message: null,
@ -68,6 +69,7 @@ const field = {
index: null, index: null,
label: null, label: null,
image: null, image: null,
image_upload_id: null,
description: null, description: null,
required: null, required: null,
key: null, key: null,

Datei anzeigen

@ -44,7 +44,7 @@
imageUrl=field.image imageUrl=field.image
onUploadDone=(action "imageUploadDone") onUploadDone=(action "imageUploadDone")
onUploadDeleted=(action "imageUploadDeleted") onUploadDeleted=(action "imageUploadDeleted")
type="wizard-step" type=(concat "wizard-" wizard.id)
class="no-repeat contain-image" class="no-repeat contain-image"
id=(concat "wizard-field-" field.id "-image-upload")}} id=(concat "wizard-field-" field.id "-image-upload")}}
</div> </div>

Datei anzeigen

@ -18,7 +18,7 @@
imageUrl=step.banner imageUrl=step.banner
onUploadDone=(action "bannerUploadDone") onUploadDone=(action "bannerUploadDone")
onUploadDeleted=(action "bannerUploadDeleted") onUploadDeleted=(action "bannerUploadDeleted")
type="wizard-banner" type=(concat "wizard-" wizard.id)
class="no-repeat contain-image" class="no-repeat contain-image"
id=(concat "wizard-step-" step.id "-banner-upload")}} id=(concat "wizard-step-" step.id "-banner-upload")}}
</div> </div>

Datei anzeigen

@ -11,6 +11,7 @@ class CustomWizard::Field
:label, :label,
:description, :description,
:image, :image,
:image_upload_id,
:key, :key,
:validations, :validations,
:min_length, :min_length,

Datei anzeigen

@ -16,6 +16,7 @@ class CustomWizard::Step
:next, :next,
:previous, :previous,
:banner, :banner,
:banner_upload_id,
:disabled, :disabled,
:description_vars, :description_vars,
:last_step, :last_step,

Datei anzeigen

@ -32,6 +32,7 @@ class CustomWizard::Template
end end
self.class.clear_cache_keys self.class.clear_cache_keys
remove_unused_wizard_upload_references
@data[:id] @data[:id]
end end
@ -62,6 +63,7 @@ class CustomWizard::Template
end end
clear_cache_keys clear_cache_keys
remove_wizard_upload_references
true true
end end
@ -176,4 +178,33 @@ class CustomWizard::Template
object.delete(:index) object.delete(:index)
end end
end end
def collect_upload_ids
upload_ids = []
@data[:steps].each do |step|
upload_ids << step[:banner_upload_id] if step[:banner_upload_id]
step[:fields].each do |field|
upload_ids << field[:image_upload_id] if field[:image_upload_id]
end
end
upload_ids
end
def wizard_upload_references
@wizard_upload_references ||= begin
record = PluginStoreRow.find_by(plugin_name: CustomWizard::PLUGIN_NAME, key: @data[:id])
UploadReference.where(target_type: "CustomWizard", target_id: custom_wizard_record.id)
end
end
def remove_unused_wizard_upload_references
wizard_upload_references.where.not(upload_id: collect_upload_ids).delete_all
end
def remove_wizard_upload_references
wizard_upload_references.delete_all
end
end end

Datei anzeigen

@ -226,5 +226,21 @@ after_initialize do
::DiscourseTagging.singleton_class.prepend CustomWizardDiscourseTagging ::DiscourseTagging.singleton_class.prepend CustomWizardDiscourseTagging
end end
on(:after_upload_creation) do |upload, opts|
from_wizard = opts[:type].include?("wizard-")
wizard_id = opts[:type].split("wizard-").last
wizard_record = PluginStoreRow.find_by(plugin_name: CustomWizard::PLUGIN_NAME, key: wizard_id)
if wizard_record
UploadReference.create(
upload_id: upload.id,
target_type: "CustomWizard",
target_id: wizard_record.id,
created_at: Time.zone.now,
updated_at: Time.zone.now
)
end
end
DiscourseEvent.trigger(:custom_wizard_ready) DiscourseEvent.trigger(:custom_wizard_ready)
end end