Add file preview to list view

This commit is contained in:
aignatov-bio 2020-10-26 17:16:31 +01:00
parent d99e279ecc
commit 131d487e69
5 changed files with 23 additions and 6 deletions

View file

@ -11,7 +11,7 @@ var FilePreviewModal = (function() {
e.preventDefault();
e.stopPropagation();
params.gallery = $(`.file-preview-link[data-gallery-view-id=${galleryViewId}]`)
.toArray().sort((a, b) => $(a).closest('.step-asset').css('order') - $(b).closest('.step-asset').css('order'))
.toArray().sort((a, b) => $(a).closest('.asset').css('order') - $(b).closest('.asset').css('order'))
.map(i => i.dataset.id);
$.get($(this).data('preview-url'), params, function(result) {
$('#filePreviewModal .modal-content').html(result.html);

View file

@ -381,8 +381,8 @@ var ImageEditorModal = (function() {
contentType: false,
processData: false,
success: function(res) {
$(`.step-asset[data-asset-id=${data.id}]`).replaceWith(res.html);
$(`.step-asset[data-asset-id=${data.id}]`).closest('.attachments').trigger('reorder');
$(`.asset[data-asset-id=${data.id}]`).replaceWith(res.html);
$(`.asset[data-asset-id=${data.id}]`).closest('.attachments').trigger('reorder');
closeEditor();
}
});

View file

@ -34,7 +34,14 @@ class AssetsController < ApplicationController
def toggle_view_mode
@asset.view_mode = toggle_view_mode_params[:view_mode]
if @asset.save(touch: false)
html = render_to_string(partial: 'assets/asset.html.erb', locals: { asset: @asset })
if @assoc.class == Step
gallery_view_id = @assoc.id
end
html = render_to_string(partial: 'assets/asset.html.erb', locals: {
asset: @asset,
gallery_view_id: gallery_view_id
})
respond_to do |format|
format.json do
render json: { html: html }, status: :ok

View file

@ -9,7 +9,12 @@
<%= link_to rails_blob_path(asset.file, disposition: 'attachment'),
class: "file-preview-link file-name",
id: "modal_link#{asset.id}",
data: { no_turbolink: true, id: true, 'preview-url': asset_file_preview_path(asset)} do %>
data: {
no_turbolink: true,
id: asset.id,
gallery_view_id: gallery_view_id,
preview_url: asset_file_preview_path(asset)
} do %>
<%= asset.file_name %>
<% end %>
<div class="file-metadata">

View file

@ -10,7 +10,12 @@
<%= link_to rails_blob_path(asset.file, disposition: 'attachment'),
class: "file-preview-link file-name",
id: "modal_link#{asset.id}",
data: { no_turbolink: true, id: true, 'preview-url': asset_file_preview_path(asset)} do %>
data: {
no_turbolink: true,
id: asset.id,
gallery_view_id: gallery_view_id,
preview_url: asset_file_preview_path(asset)
} do %>
<%= asset.file_name %>
<% end %>
<div class="file-metadata">