1
0
Fork 0
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,
:key,
:banner,
:banner_upload_id,
:raw_description,
:required_data_message,
:force_final,
@ -99,6 +100,7 @@ class CustomWizard::AdminWizardController < CustomWizard::AdminController
:index,
:label,
:image,
:image_upload_id,
:description,
:required,
:key,

Datei anzeigen

@ -144,11 +144,17 @@ export default Component.extend(UndoChanges, {
actions: {
imageUploadDone(upload) {
this.set("field.image", upload.url);
this.setProperties({
"field.image": upload.url,
"field.image_upload_id": upload.id
});
},
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: {
bannerUploadDone(upload) {
this.set("step.banner", upload.url);
this.setProperties({
"step.banner": upload.url,
"step.banner_upload_id": upload.id
});
},
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,
key: null,
banner: null,
banner_upload_id: null,
raw_description: null,
required_data: null,
required_data_message: null,
@ -68,6 +69,7 @@ const field = {
index: null,
label: null,
image: null,
image_upload_id: null,
description: null,
required: null,
key: null,

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -32,6 +32,7 @@ class CustomWizard::Template
end
self.class.clear_cache_keys
remove_unused_wizard_upload_references
@data[:id]
end
@ -62,6 +63,7 @@ class CustomWizard::Template
end
clear_cache_keys
remove_wizard_upload_references
true
end
@ -176,4 +178,33 @@ class CustomWizard::Template
object.delete(:index)
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

Datei anzeigen

@ -226,5 +226,21 @@ after_initialize do
::DiscourseTagging.singleton_class.prepend CustomWizardDiscourseTagging
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)
end