mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-29 11:45:18 +08:00
Fix attachment appearence after update (#1745)
This commit is contained in:
parent
837e5d1fea
commit
da5b24ef57
2 changed files with 27 additions and 7 deletions
|
@ -168,15 +168,29 @@ class AssetsController < ApplicationController
|
|||
# Post process file here
|
||||
@asset.post_process_file(@asset.team)
|
||||
|
||||
render_html = if @asset.step
|
||||
asset_position = @asset.step.asset_position(@asset)
|
||||
render_to_string(
|
||||
partial: 'steps/attachments/item.html.erb',
|
||||
locals: {
|
||||
asset: @asset,
|
||||
i: asset_position[:pos],
|
||||
assets_count: asset_position[:count],
|
||||
step: @asset.step
|
||||
},
|
||||
formats: :html
|
||||
)
|
||||
else
|
||||
render_to_string(
|
||||
partial: 'shared/asset_link',
|
||||
locals: { asset: @asset, display_image_tag: true },
|
||||
formats: :html
|
||||
)
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.json do
|
||||
render json: {
|
||||
html: render_to_string(
|
||||
partial: 'shared/asset_link',
|
||||
locals: { asset: @asset, display_image_tag: true },
|
||||
formats: :html
|
||||
)
|
||||
}
|
||||
render json: { html: render_html }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -124,6 +124,12 @@ class Step < ApplicationRecord
|
|||
st
|
||||
end
|
||||
|
||||
def asset_position(asset)
|
||||
assets.order(:file_updated_at).each_with_index do |step_asset, i|
|
||||
return { count: assets.count, pos: i } if asset.id == step_asset.id
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def cascade_after_destroy
|
||||
|
|
Loading…
Reference in a new issue