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

Issue202: Add contributor to the DMP downloaded files #206

Merged
merged 5 commits into from
May 24, 2022
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

### Added

- Added contributors to plan's cover page (if there is any) [#202](https://github.com/portagenetwork/roadmap/issues/202)
- Added plan title to csv exported file

## [3.0.4+portage-3.0.12] - 2022-05-12

### Added
Expand Down
20 changes: 14 additions & 6 deletions app/controllers/plan_exports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ def show

@hash = @plan.as_pdf(current_user, @show_coversheet)
@formatting = export_params[:formatting] || @plan.settings(:export).formatting
if params.key?(:phase_id) && params[:phase_id].length > 0

if params.key?(:phase_id) && params[:phase_id].length.positive?
# order phases by phase number asc
@hash[:phases] = @hash[:phases].sort_by{|phase| phase[:number]}
if (params[:phase_id] == "All")
@hash[:phases] = @hash[:phases].sort_by { |phase| phase[:number] }
if params[:phase_id] == "All"
@hash[:all_phases] = true
else
@selected_phase = @plan.phases.find(params[:phase_id])
Expand All @@ -46,6 +46,14 @@ def show
@selected_phase = @plan.phases.order("phases.updated_at DESC")
.detect { |p| p.visibility_allowed?(@plan) }
end

# Added contributors to coverage of plans.
# Users will see both roles and contributor names if the role is filled
@hash[:data_curation] = Contributor.where(plan_id: @plan.id).data_curation
@hash[:investigation] = Contributor.where(plan_id: @plan.id).investigation
@hash[:pa] = Contributor.where(plan_id: @plan.id).project_administration
@hash[:other] = Contributor.where(plan_id: @plan.id).other

respond_to do |format|
format.html { show_html }
format.csv { show_csv }
Expand Down Expand Up @@ -93,8 +101,8 @@ def show_pdf
date: l(@plan.updated_at.to_date, format: :readable)
},
font_size: 8,
spacing: (Integer(@formatting[:margin][:bottom]) / 2) - 4,
right: _("[page] of [topage]"),
spacing: (Integer(@formatting[:margin][:bottom]) / 2) - 4,
right: _("[page] of [topage]"),
encoding: "UTF-8"
}
end
Expand Down
24 changes: 23 additions & 1 deletion app/models/concerns/exportable_plan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ def prepare_coversheet
end
hash[:attribution] = attribution

# Added contributors to coverage of plans.
# Users will see both roles and contributor names if the role is filled
hash[:data_curation] = Contributor.where(plan_id: id).data_curation
hash[:investigation] = Contributor.where(plan_id: id).investigation
hash[:pa] = Contributor.where(plan_id: id).project_administration
hash[:other] = Contributor.where(plan_id: id).other

# Org name of plan owner's org
hash[:affiliation] = owner.present? ? owner.org.name : ""

Expand All @@ -127,12 +134,27 @@ def prepare_coversheet

# rubocop:disable Metrics/MethodLength, Metrics/AbcSize
def prepare_coversheet_for_csv(csv, _headings, hash)
csv << [_("Title: "), _("%{title}") % { title: title }]
csv << [if hash[:attribution].many?
_("Creators: ")
else
_("Creator:")
end, _("%{authors}") % { authors: hash[:attribution].join(", ") }]
csv << ["Affiliation: ", _("%{affiliation}") % { affiliation: hash[:affiliation] }]
if hash[:investigation].present?
csv << [_("Principal Investigator: "),
_("%{investigation}") % { investigation: hash[:investigation].map(&:name).join(", ") }]
end
if hash[:data_curation].present?
csv << [_("Date Manager: "),
_("%{data_curation}") % { data_curation: hash[:data_curation].map(&:name).join(", ") }]
end
if hash[:pa].present?
csv << [_("Project Administrator: "), _("%{pa}") % { pa: hash[:pa].map(&:name).join(", ") }]
end
if hash[:other].present?
csv << [_("Contributor: "), _("%{other}") % { other: hash[:other].map(&:name).join(", ") }]
end
csv << [_("Affiliation: "), _("%{affiliation}") % { affiliation: hash[:affiliation] }]
csv << if hash[:funder].present?
[_("Template: "), _("%{funder}") % { funder: hash[:funder] }]
else
Expand Down
16 changes: 16 additions & 0 deletions app/views/shared/export/_plan_coversheet.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@
<%# Allow raw html (==) for plan_attribution as it has <b> tags %>
<p><%== plan_attribution(@hash[:attribution]) %></p><br>

<%# Added contributors to coverage of plans.
# Users will see both roles and contributor names if the role is filled %>
<%# Roles are ranked by PI -> DM -> PA -> Other (if any) %>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good explanation of the behaviour of the view!

<% if @hash[:investigation].present? %>
<p><b><%= _("Principal Investigator: ") %></b><%= @hash[:investigation].map(&:name).join(', ') %></p><br>
<% end %>
<% if @hash[:data_curation].present? %>
<p><b><%= _("Data Manager: ") %></b><%= @hash[:data_curation].map(&:name).join(', ') %></p><br>
<% end %>
<% if @hash[:pa].present? %>
<p><b><%= _("Project Administrator: ") %></b><%= @hash[:pa].map(&:name).join(', ') %></p><br>
<% end %>
<% if @hash[:other].present? %>
<p><b><%= _("Contributor: ") %></b><%= @hash[:other].map(&:name).join(', ') %></p><br>
<% end %>

<p><b><%= _("Affiliation: ") %></b><%= @hash[:affiliation] %></p><br>

<% if @hash[:funder].present? %>
Expand Down
16 changes: 16 additions & 0 deletions app/views/shared/export/_plan_txt.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
<%= "#{@plan.title}" %>
<%= "----------------------------------------------------------\n" %>
<% if @show_coversheet %>

<%= @hash[:attribution].many? ? _("Creators: ") : _('Creator:') %> <%= @hash[:attribution].join(', ') %>
<%# Added contributors to coverage of plans.
# Users will see both roles and contributor names if the role is filled %>
<%# Roles are ranked by PI -> DM -> PA -> Other (if any) %>
<% if @hash[:investigation].present? %>
<%= _("Principal Investigator: ") + @hash[:investigation].map(&:name).join(', ') %>
<% end %>
<% if @hash[:data_curation].present? %>
<%= _("Data Manager: ") + @hash[:data_curation].map(&:name).join(', ') %>
<% end %>
<% if @hash[:pa].present? %>
<%= _("Project Administrator: ") + @hash[:pa].map(&:name).join(', ') %>
<% end %>
<% if @hash[:other].present? %>
<%= _("Contributor: ") + @hash[:other].map(&:name).join(', ') %>
<% end %>
<%= _("Affiliation: ") + @hash[:affiliation] %>
<% if @hash[:funder].present? %>
<%= _("Template: ") + @hash[:funder] %>
Expand Down