Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stream publication files until we resolve that differently #270

Merged
merged 3 commits into from
Feb 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/admin/news_article.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
f.input :tpi_sector_ids, label: 'Sectors', as: :select,
collection: TPISector.order(:name), input_html: {multiple: true}
f.input :keywords_string, label: 'Keywords', hint: t('hint.tag'), as: :tags, collection: Keyword.pluck(:name)
f.input :image, as: :file
f.input :image, as: :file, input_html: {accept: 'image/*'}
end

f.actions
Expand Down
9 changes: 7 additions & 2 deletions app/admin/publication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,13 @@
f.input :tpi_sector_ids, label: 'Sectors', as: :select,
collection: TPISector.order(:name), input_html: {multiple: true}
f.input :keywords_string, label: 'Keywords', hint: t('hint.tag'), as: :tags, collection: Keyword.pluck(:name)
f.input :file, as: :file
f.input :image, as: :file
f.input :file,
as: :file,
hint: preview_file_tag(f.object.file),
input_html: {
accept: 'application/pdf, application/vnd.ms-powerpoint, .ppt, .pptx, application/msword, .docx'
}
f.input :image, as: :file, hint: preview_file_tag(f.object.image), input_html: {accept: 'image/*'}
end

f.actions
Expand Down
35 changes: 27 additions & 8 deletions app/controllers/tpi/publications_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
module TPI
class PublicationsController < TPIController
include ActionController::Live

before_action :fetch_tags, only: [:index]
before_action :fetch_sectors, only: [:index]
before_action :fetch_publication, only: [:show]

def index
@publications_and_articles = Queries::TPI::NewsPublicationsQuery
Expand All @@ -17,25 +20,41 @@ def partial
end

def show
@publication = params[:type].eql?('NewsArticle') ? NewsArticle.find(params[:id]) : Publication.find(params[:id])
respond_to do |format|
format.html
format.pdf { redirect_to rails_blob_url(@publication.file, disposition: 'preview') }
format.html do
admin_panel_path = polymorphic_path([:admin, @publication])
fixed_navbar("#{@publication.class.name.underscore.humanize} #{@publication.title}", admin_panel_path)

redirect_to '' unless @publication
end
format.pdf { stream_publication_file }
end
end

admin_panel_path = polymorphic_path([:admin, @publication])
private

fixed_navbar("#{@publication.class.name.underscore.humanize} #{@publication.title}", admin_panel_path)
def stream_publication_file
send_file_headers!(
type: @publication.file.content_type,
disposition: 'inline',
filename: @publication.file.filename.to_s
)

redirect_to '' unless @publication
@publication.file.download do |chunk|
response.stream.write(chunk)
end
ensure
response.stream.close
end

private

def filter_params
params.permit(:tags, :sectors)
end

def fetch_publication
@publication = params[:type].eql?('NewsArticle') ? NewsArticle.find(params[:id]) : Publication.find(params[:id])
end

def fetch_tags
@tags = Keyword
.joins(:taggings)
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/pages/_image_fields.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<%= content_tag :div, class: 'nested-fields inline-fields', data: { controller: 'image', new_record: is_new_record } do %>
<% if is_new_record || !form.object.logo.present? %>
<%= form.input :logo, as: :file %>
<%= form.input :logo, as: :file, input_html: {accept: 'image/*'} %>
<% else %>
<%= image_tag form.object.logo, style: 'height: 100px; width: 100px;' %>
<% end %>
Expand Down