Merge pull request #11110 from tchak/some-cleanup
Some cleanup around champ updates
This commit is contained in:
commit
f6b750dd7a
3 changed files with 21 additions and 11 deletions
|
@ -58,7 +58,7 @@ class Attachment::EditComponent < ApplicationComponent
|
||||||
|
|
||||||
def destroy_attachment_path
|
def destroy_attachment_path
|
||||||
if champ.present?
|
if champ.present?
|
||||||
attachment_path(dossier_id: champ&.dossier_id, stable_id: champ&.stable_id, row_id: champ&.row_id)
|
attachment_path
|
||||||
else
|
else
|
||||||
attachment_path(auto_attach_url: @auto_attach_url, view_as: @view_as, direct_upload: @direct_upload)
|
attachment_path(auto_attach_url: @auto_attach_url, view_as: @view_as, direct_upload: @direct_upload)
|
||||||
end
|
end
|
||||||
|
|
|
@ -58,9 +58,9 @@ class EditableChamp::EditableChampComponent < ApplicationComponent
|
||||||
|
|
||||||
def turbo_poll_url_value
|
def turbo_poll_url_value
|
||||||
if @champ.private?
|
if @champ.private?
|
||||||
annotation_instructeur_dossier_path(@champ.dossier.procedure, @champ.dossier, @champ.stable_id, row_id: @champ.row_id, with_public_id: true)
|
annotation_instructeur_dossier_path(@champ.dossier.procedure, @champ.dossier, @champ.stable_id, row_id: @champ.row_id)
|
||||||
else
|
else
|
||||||
champ_dossier_path(@champ.dossier, @champ.stable_id, row_id: @champ.row_id, with_public_id: true)
|
champ_dossier_path(@champ.dossier, @champ.stable_id, row_id: @champ.row_id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -20,15 +20,16 @@ class AttachmentsController < ApplicationController
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@attachment = @blob.attachments.find(params[:id])
|
@attachment = @blob.attachments.find(params[:id])
|
||||||
@attachment.purge_later
|
|
||||||
flash.notice = 'La pièce jointe a bien été supprimée.'
|
|
||||||
|
|
||||||
if params[:dossier_id]
|
if champ?
|
||||||
@champ = find_champ
|
@attachment = champ.piece_justificative_file.find { _1.blob.id == @blob.id }
|
||||||
else
|
else
|
||||||
@attachment_options = attachment_options
|
@attachment_options = attachment_options
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@attachment.purge_later
|
||||||
|
flash.notice = 'La pièce jointe a bien été supprimée.'
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.turbo_stream
|
format.turbo_stream
|
||||||
format.html { redirect_back(fallback_location: root_url) }
|
format.html { redirect_back(fallback_location: root_url) }
|
||||||
|
@ -37,14 +38,23 @@ class AttachmentsController < ApplicationController
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def find_champ
|
def record
|
||||||
dossier = policy_scope(Dossier).includes(:champs).find(params[:dossier_id])
|
@attachment.record
|
||||||
dossier.champs.find_by(stable_id: params[:stable_id], row_id: params[:row_id] || Champ::NULL_ROW_ID)
|
end
|
||||||
|
|
||||||
|
def champ?
|
||||||
|
record.is_a?(Champ)
|
||||||
|
end
|
||||||
|
|
||||||
|
def champ
|
||||||
|
@champ ||= if champ?
|
||||||
|
record.dossier.champ_for_update(record.type_de_champ, row_id: record.row_id, updated_by: current_user.email)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def attachment_options
|
def attachment_options
|
||||||
{
|
{
|
||||||
attached_file: @attachment.record.public_send(@attachment.name),
|
attached_file: record.public_send(@attachment.name),
|
||||||
view_as: params[:view_as]&.to_sym,
|
view_as: params[:view_as]&.to_sym,
|
||||||
direct_upload: params[:direct_upload] == "true",
|
direct_upload: params[:direct_upload] == "true",
|
||||||
auto_attach_url: params[:direct_upload] == "true" ? params[:auto_attach_url] : nil
|
auto_attach_url: params[:direct_upload] == "true" ? params[:auto_attach_url] : nil
|
||||||
|
|
Loading…
Add table
Reference in a new issue