Skip to content
Snippets Groups Projects
Verified Commit 4ddd1ef4 authored by tribut's avatar tribut :man_dancing:
Browse files

Show filedrop in frontend and enable downloads

parent 7f71a05b
No related branches found
No related tags found
No related merge requests found
......@@ -86,11 +86,12 @@ class AssignmentsController < ApplicationController
@user.assignments.each do |assignment|
session = assignment.session
assignees = session.assignments.map { |a| a.user.name }
desc = [
desc [
"Assignees: #{assignees.join(', ')}",
"Speakers: #{session.speakers.map(&:name).join(', ')}",
session.description
]
desc.unshift("Filedrop has data for this session!<br>\n" + conference_session_url(session.conference, session)) if session.filedrop?
event = Icalendar::Event.new
event.dtstart = Icalendar::Values::DateTime.new(session.starts_at, tzid: session.starts_at.time_zone.tzinfo.name)
......
class FiledropFilesController < ApplicationController
before_action :authenticate_user!
before_action :set_filedrop_file, only: [:download]
def download
# Define the file path within the storage directory
file_path = @filedrop_file.local_path
# Send the file to the user
if File.exist?(file_path)
send_file file_path, filename: @filedrop_file.name, disposition: 'attachment'
else
render plain: 'File not found', status: :not_found
end
end
private
def set_filedrop_file
@filedrop_file = FiledropFile.find(params[:id])
end
end
class SessionsController < ApplicationController
before_action :authenticate_user!, except: [:index]
before_action :authorize_shiftcoordinator, except: [:index, :show]
def index
......@@ -21,7 +22,7 @@ class SessionsController < ApplicationController
def show
@conference = Conference.find_by(slug: params[:conference_slug])
@session = Session.includes(:stage).find_by(conference: @conference, ref_id: params[:ref_id])
@session = Session.includes(:stage, :filedrop_comments, :filedrop_files).find_by(conference: @conference, ref_id: params[:ref_id])
@users = User.all
end
......
......@@ -50,6 +50,10 @@ class Session < ApplicationRecord
assignments.length.positive?
end
def filedrop?
return filedrop_files.exists? || filedrop_comments.exists?
end
private
def notify_if_changed
......
<div>
<h1 class="font-bold text-4xl">FiledropFiles#download</h1>
<p>Find me in app/views/filedrop_files/download.html.erb</p>
</div>
......@@ -2,7 +2,7 @@
<%= turbo_frame_tag dom_id(session), method: "morph", class: "w-full", data: { controller: "session", language: session.language } do %>
<div class="session shadow hover:shadow-lg overflow-scroll text-sm w-full !h-full min-h-full hover:!min-h-max <%= session.translators_needed? ? "translators-needed" : "no-translators-needed" %> <%= session.backup_needed? ? "backup-needed" : "no-backup-needed" %> <%= session.assignees? ? "has-assignees" : "no-assignees" %> <%= (session.ends_at < Time.now ? "past" : "") %>">
<h4>
<small class="text-2xs uppercase font-light bg-black/10 rounded-sm p-1 mr-1 lang-<%= session.language %>"><%= session.language %></small><% unless session.recorded %><span aria-label="Session is not recorded" title="Session is not recorded"><svg class="inline-block -mt-0.5 w-5 h-5" fill="#000000" version="1.1" viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg"><path d="m255-1c-141 0-256 115-256 256s115 256 256 256 256-115 256-256-115-256-256-256zm0 17c63 0 121 25 163 65l-65 65-19-48c-0.85-2.6-4.3-5.1-7.7-5.1h-142c-3.4 0-6 1.7-7.7 5.1l-21 55h-49c-17 0-31 14-31 31v169c0 17 14 31 31 31h6.7l-34 34c-39-43-64-100-64-162 0-131 108-239 239-239zm60 239c0 33-26 60-60 60-14 0-26-4.4-36-12l84-83c7.3 9.9 12 22 12 36zm-119 0c0-33 26-60 60-60 14 0 26 4.5 36 12l-84 83c-7.4-9.9-12-22-12-36zm108-60c-13-11-30-17-48-17-43 0-77 34-77 77 0 18 6.2 35 17 48l-64 63h-25c-7.7 0-14-6-14-14v-169c0-7.7 6-14 14-14h55c3.4 0 6.8-2.6 7.7-5.1l21-55h130l19 50-36 36zm-97 120c13 11 30 17 48 17 43 0 77-34 77-77 0-18-6.1-35-16-48l38-38h49c7.7 0 14 6 14 14v169c0 7.7-6 14-14 14h-247l51-51zm48 179c-63 0-120-25-163-65l46-46h265c17 0 31-14 32-31v-169c0-17-14-31-31-31h-34l60-59c39 43 64 100 64 162-1e-3 131-108 239-239 239z"/><path d="m383 187c-9.4 0-17 7.7-17 17s7.7 17 17 17 17-7.7 17-17-7.7-17-17-17z"/></svg></span><% end %>
<small class="text-2xs uppercase font-light bg-black/10 rounded-sm p-1 mr-1 lang-<%= session.language %>"><%= session.language %></small><% unless session.recorded %><span aria-label="Session is not recorded" title="Session is not recorded"><svg class="inline-block -mt-0.5 w-5 h-5" fill="#000000" version="1.1" viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg"><path d="m255-1c-141 0-256 115-256 256s115 256 256 256 256-115 256-256-115-256-256-256zm0 17c63 0 121 25 163 65l-65 65-19-48c-0.85-2.6-4.3-5.1-7.7-5.1h-142c-3.4 0-6 1.7-7.7 5.1l-21 55h-49c-17 0-31 14-31 31v169c0 17 14 31 31 31h6.7l-34 34c-39-43-64-100-64-162 0-131 108-239 239-239zm60 239c0 33-26 60-60 60-14 0-26-4.4-36-12l84-83c7.3 9.9 12 22 12 36zm-119 0c0-33 26-60 60-60 14 0 26 4.5 36 12l-84 83c-7.4-9.9-12-22-12-36zm108-60c-13-11-30-17-48-17-43 0-77 34-77 77 0 18 6.2 35 17 48l-64 63h-25c-7.7 0-14-6-14-14v-169c0-7.7 6-14 14-14h55c3.4 0 6.8-2.6 7.7-5.1l21-55h130l19 50-36 36zm-97 120c13 11 30 17 48 17 43 0 77-34 77-77 0-18-6.1-35-16-48l38-38h49c7.7 0 14 6 14 14v169c0 7.7-6 14-14 14h-247l51-51zm48 179c-63 0-120-25-163-65l46-46h265c17 0 31-14 32-31v-169c0-17-14-31-31-31h-34l60-59c39 43 64 100 64 162-1e-3 131-108 239-239 239z"/><path d="m383 187c-9.4 0-17 7.7-17 17s7.7 17 17 17 17-7.7 17-17-7.7-17-17-17z"/></svg></span><% end %><% if session.filedrop? %><%= link_to conference_session_path(session.conference, session), data: { turbo: false } do %><span aria-label="Filedrop has data for this session" title="Filedrop has data for this session"><svg class="inline-block -mt-0.5 w-5 h-5" fill="#EA33F7" xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="m720-120 160-160-56-56-64 64v-167h-80v167l-64-64-56 56 160 160ZM560 0v-80h320V0H560ZM240-160q-33 0-56.5-23.5T160-240v-560q0-33 23.5-56.5T240-880h280l240 240v121h-80v-81H480v-200H240v560h240v80H240Zm0-80v-560 560Z"/></svg></span><% end %><% end %>
<%= link_to session.title, session.url, target: "_blank" %>
</h4>
<div class="relative">
......
......@@ -6,7 +6,39 @@
<h2><%= @session.stage.name %>&middot; <%= @session.session_format %> &middot; <%= @session.track %></h2>
<p><%= @session.description.html_safe %></p>
<h3>Assigned Users</h3>
<% if @session.filedrop_comments.any? %>
<h3 class="mt-4">Comments <span class="font-normal">from Speakers' Filedrop</span></h2>
<ul class="space-y-4 my-4">
<% @session.filedrop_comments.each do |comment| %>
<li class="bg-gray-100 shadow rounded-lg p-2">
<div class="text-gray-900 whitespace-pre-wrap"><%= comment.body %></div>
<div class="text-gray-500 text-sm mt-2">
<%= comment.orig_created&.in_time_zone(@session.conference.time_zone || 'UTC')&.strftime("%B %d, %Y %H:%M") %>
</div>
</li>
<% end %>
</ul>
<% end %>
<h3 class="mt-4">Files <span class="font-normal">from Speakers' Filedrop</span></h3>
<ul class="space-y-4 my-4">
<% @session.filedrop_files.each do |file| %>
<li class="bg-white shadow rounded-lg p-4">
<div class="flex justify-between items-center">
<div>
<div class="text-gray-900 text-lg font-semibold"><%= file.name %></div>
<div class="text-gray-500 text-sm">Size: <%= number_to_human_size(file.size) %></div>
<div class="text-gray-500 text-sm">Checksum: <%= file.checksum %></div>
</div>
<div>
<%= link_to 'Download', download_filedrop_file_path(file), class: "bg-blue-500 text-white px-3 py-2 rounded" %>
</div>
</div>
</li>
<% end %>
</ul>
<h3 class="mt-4">Assigned Users</h3>
<ul class="inline-flex flex-wrap gap-1 my-1">
<% @session.assignments.each do |assignment| %>
<li>
......
......@@ -32,6 +32,12 @@ Rails.application.routes.draw do
end
resources :sessions, param: :ref_id
resources :filedrop_files, only: [] do
member do
get 'download', to: 'filedrop_files#download'
end
end
# get 'conferences/:slug', to: 'conferences#show', as: :conference
# get 'conferences/:slug/:date', to: 'conferences#show', as: :conference_day
# get 'conferences/:slug/session/:ref_id', to: 'sessions#show', as: :conference_session
......
require "test_helper"
class FiledropFilesControllerTest < ActionDispatch::IntegrationTest
test "should get download" do
get filedrop_files_download_url
assert_response :success
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment