diff --git a/app/assets/javascripts/admin.js b/app/assets/javascripts/admin.js index f6a74253..9da7bd10 100644 --- a/app/assets/javascripts/admin.js +++ b/app/assets/javascripts/admin.js @@ -15,3 +15,4 @@ //= require activestorage //= require turbolinks //= require tasks +//= require copy_to_clipboard \ No newline at end of file diff --git a/app/assets/javascripts/copy_to_clipboard.js b/app/assets/javascripts/copy_to_clipboard.js new file mode 100644 index 00000000..c29523e6 --- /dev/null +++ b/app/assets/javascripts/copy_to_clipboard.js @@ -0,0 +1,32 @@ +function copyToClipboard(text){ + var textArea = document.createElement("textarea"); + + textArea.style.position = 'fixed'; + textArea.style.top = 0; + textArea.style.left = 0; + textArea.style.width = '2em'; + textArea.style.height = '2em'; + textArea.style.padding = 0; + textArea.style.border = 'none'; + textArea.style.outline = 'none'; + textArea.style.boxShadow = 'none'; + textArea.style.background = 'transparent'; + textArea.value = text; + + document.body.appendChild(textArea); + textArea.focus(); + textArea.select(); + + try { + var successful = document.execCommand('copy'); + if (successful) { + // no-op, would be nice to how some non-intrusive confirmation + } else { + alert('Copy to clipboard failed'); + } + } catch (err) { + alert('Copy to clipboard failed'); + } + + document.body.removeChild(textArea); +} diff --git a/app/views/admin/uploads/index.html.erb b/app/views/admin/uploads/index.html.erb index b441b2b1..ee15da49 100644 --- a/app/views/admin/uploads/index.html.erb +++ b/app/views/admin/uploads/index.html.erb @@ -15,7 +15,9 @@ Filename - Url + + + @@ -23,9 +25,21 @@ <% @files.each do |file| %> <%= file.key %> - <%= link_to 'Link to file', UploadsService.get_url(file) %> + + <% if file.content_type.include?('video') %> + <%= video_tag UploadsService.get_url(file), size: "320x200", :controls => true %> + <% elsif file.content_type.include?('image') %> + <%= link_to (image_tag UploadsService.get_url(file), size: "320x200"), UploadsService.get_url(file) %> + <% end %> + + <%= link_to 'Copy link', UploadsService.get_url(file), class: 'copy-to-clipboard', onclick: "copyToClipboard('#{UploadsService.get_url(file)}');return false;" %> + <%= link_to 'Download️', UploadsService.get_url(file), download: file.filename %> <%= link_to 'Delete', admin_upload_path(file.key), method: :delete, data: { confirm: 'Are you sure you want to delete file: ' + file.key + '?' } %> <% end %> + +