Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

add mime type for download, so PDF can be handled differently

as-opd910d665393f
diff --git a/app/workers/backup_job.rb b/app/workers/backup_job.rb
index 560bdfad3f8..78f2a12ce95 100644
--- a/app/workers/backup_job.rb
+++ b/app/workers/backup_job.rb
@@ -143,7 +143,7 @@ class BackupJob < ApplicationJob
upsert_status(
status: :success,
message: I18n.t("export.succeeded"),
- payload: download_payload(download_url)
+ payload: download_payload(download_url, "application/zip")
)
end
diff --git a/modules/job_status/app/components/job_status/dialog/body_component.html.erb b/modules/job_status/app/components/job_status/dialog/body_component.html.erb
index 39bd72742b2..fce59e6ddc8 100644
--- a/modules/job_status/app/components/job_status/dialog/body_component.html.erb
+++ b/modules/job_status/app/components/job_status/dialog/body_component.html.erb
@@ -9,6 +9,7 @@
<% else %>
<%= content_tag :div, "", data: { "job-status-polling-target": "finished" } %>
<% end %>
+ <code><%= job.inspect %></code>
<%= render Primer::Beta::Blankslate.new do |component|
component.with_visual_icon(icon: icon[:icon], classes: icon[:classes], size: :medium) unless icon.nil?
component.with_heading(tag: :h2).with_content(title)
@@ -38,7 +39,10 @@
link: (render(Primer::Beta::Link.new(
href: download_url,
target: "_blank",
- download: "download",
+ type: mime_type,
+ # omit download attribute for PDF,
+ # so they open in a tab - if supported and activated in the browser
+ download: mime_type_pdf? ? nil : "download",
data: {
"job-status-polling-target": "download"
}
@@ -47,7 +51,7 @@
} }
end
if job_html.present?
- flex.with_row { job_html.html_safe }
+ flex.with_row(text_align: :left) { job_html.html_safe }
end
end
end
diff --git a/modules/job_status/app/components/job_status/dialog/body_component.rb b/modules/job_status/app/components/job_status/dialog/body_component.rb
index ed03c6a2eda..3618dc499f7 100644
--- a/modules/job_status/app/components/job_status/dialog/body_component.rb
+++ b/modules/job_status/app/components/job_status/dialog/body_component.rb
@@ -85,6 +85,14 @@ module JobStatus
error_statuses.include?(job.status) || job_errors?
end
+ def mime_type
+ job&.payload&.dig("mime_type")
+ end
+
+ def mime_type_pdf?
+ mime_type == "application/pdf"
+ end
+
def icon
return { icon: :alert, classes: "color-fg-danger" } if job.nil?
return { icon: :"x-circle", classes: "color-fg-danger" } if has_error?
@@ -97,13 +105,15 @@ module JobStatus
return I18n.t("job_status_dialog.errors") if has_error?
- job.message || job.payload&.dig("title") || I18n.t("job_status_dialog.title")
+ job.payload&.dig("title") || job.message || I18n.t("job_status_dialog.title")
end
def message
- return "" if job.nil? || !pending?
+ return I18n.t("job_status_dialog.generic_messages.#{job.status}") if pending?
+
+ return job.message if has_error?
- I18n.t("job_status_dialog.generic_messages.#{job.status}")
+ ""
end
end
end
diff --git a/modules/job_status/app/workers/job_status/application_job_with_status.rb b/modules/job_status/app/workers/job_status/application_job_with_status.rb
index d91a5e80d26..11f87ee5cd9 100644
--- a/modules/job_status/app/workers/job_status/application_job_with_status.rb
+++ b/modules/job_status/app/workers/job_status/application_job_with_status.rb
@@ -113,8 +113,8 @@ module JobStatus
##
# Crafts a payload for a download result
- def download_payload(path)
- { download: path }
+ def download_payload(path, mime_type)
+ { download: path, mime_type: }
end
end
end