Commit 90de18c4 authored by Otto Visser's avatar Otto Visser
Browse files

Merge branch 'development' into 'master'

Project Forum Release v2.8.12 - 04-10-2022

See merge request !881
parents 969eebab 928cab63
......@@ -14,7 +14,7 @@
</div>
<div class="col-md-6 btn-group">
<button type="button" class="btn btn-primary btn-block dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Email supervisors with role <span class="caret"></span>
Email Group supervisors with role <span class="caret"></span>
</button>
<ul class="dropdown-menu btn-block">
<li>
......
<div class="row">
<div class="col-md-12">
<% recipient_name = params[:type] == 'role' ? "#{@course_specific_role.name.pluralize}" : params[:type].capitalize %>
<% role_email = params[:type] == 'role' %>
<% recipient_name = role_email ? "#{@course_specific_role.name.pluralize}" : params[:type].capitalize %>
<h2>
<%= "Email All #{recipient_name}" %>
<%= "Email All #{params[:type] == 'role' ? ' Group ' : ''}#{recipient_name}" %>
</h2>
<div class="panel-body">
<div class="row">
<div class="col-md-12">
<%= bootstrap_form_tag url: send_email_admin_course_edition_path(@course, @course_edition, type: params[:type], role: params[:role]) do |f| %>
<% if role_email %>
<p class="txt-italic">
Note: This email will be sent to all users who have the <%= @course_specific_role.name %> role assigned
for at least one <span class="txt-bold">group</span>.
Users who have it assigned for a project without groups will <span class="txt-bold">not</span> receive
an email.
</p>
<% end %>
<%= f.text_field :subject, required: true %>
<%= f.text_area :message, rows: 10, placeholder: "Send a message to all #{recipient_name}. You will receive a copy of the email as well.", required: true %>
<%= f.submit 'Send Message', class: 'btn btn-primary right' %>
......
<%- headers = [
Project.human_attribute_name(:id),
Project.human_attribute_name(:name),
Project.human_attribute_name(:course_edition),
Project.human_attribute_name(:offerer),
Project.human_attribute_name(:status),
] -%>
<%-
# find the maximum number of times each role is seen in any project and put it in roles_count
roles_count = Hash.new(0)
@projects = @projects.includes(user_course_specific_roles: %i[course_specific_role user])
@projects.each do |project|
project_role_hash = Hash.new(0)
project.user_course_specific_roles.each { |ucsr| project_role_hash[ucsr.course_specific_role.name] += 1 }
project_role_hash.each { |k, v| roles_count[k] = v if v > roles_count[k] }
end
headers = [
Project.human_attribute_name(:id),
Project.human_attribute_name(:name),
Project.human_attribute_name(:course_edition),
Project.human_attribute_name(:offerer),
Project.human_attribute_name(:status),
]
# append role headers (Supervisor 1, Supervisor 1 Email, Supervisor 2, Supervisor 2 Email, TA, TA Email ...)
roles_count.each do |k, v|
(1..v).each do |i|
r = "#{k} #{i}"
r = k if v == 1
headers += [r, "#{r} #{User.human_attribute_name(:email)}"]
end
end
-%>
<%= CSV.generate_line headers -%>
<%- @projects.each do |project| -%>
<%= CSV.generate_line([
project.id,
project.name,
project.course_edition.display_name,
project.offerer.name,
project.human_enum(:status)
]).html_safe -%>
<%- row = [
project.id,
project.name,
project.course_edition.display_name,
project.offerer.name,
project.human_enum(:status)
]
# Add names and emails of people with roles in this project
roles_count.each do |k, v|
f = 0
project.user_course_specific_roles.each do |ucsr|
next if ucsr.course_specific_role.name != k
row += [ucsr.user.full_name, ucsr.user.email]
f += 1
end
# Add empty cells if the project doesn't have enough people with this role (e.g. skip "Supervisor 3" if the project has two)
row += Array.new((v - f) * 2, nil)
end
-%>
<%= CSV.generate_line(row).html_safe -%>
<%- end -%>
......@@ -2,21 +2,57 @@ wb = xlsx_package.workbook
wb.add_worksheet(name: 'projects') do |sheet|
styles = add_styles_to sheet
sheet.add_row [
# find the maximum number of times each role is seen in any project and put it in roles_count
roles_count = Hash.new(0)
@projects = @projects.includes(user_course_specific_roles: %i[course_specific_role user])
@projects.each do |project|
project_role_hash = Hash.new(0)
project.user_course_specific_roles.each { |ucsr| project_role_hash[ucsr.course_specific_role.name] += 1 }
project_role_hash.each { |k, v| roles_count[k] = v if v > roles_count[k] }
end
headers = [
Project.human_attribute_name(:id),
Project.human_attribute_name(:name),
Project.human_attribute_name(:course_edition),
Project.human_attribute_name(:company),
Project.human_attribute_name(:status)
], style: styles[:legend]
]
# append role headers (Supervisor 1, Supervisor 1 Email, Supervisor 2, Supervisor 2 Email, TA, TA Email ...)
roles_count.each do |k, v|
(1..v).each do |i|
r = "#{k} #{i}"
r = k if v == 1
headers += [r, "#{r} #{User.human_attribute_name(:email)}"]
end
end
sheet.add_row headers, style: styles[:legend]
@projects.each do |project|
sheet.add_row [
row = [
project.id,
project.name,
project.course_edition.display_name,
project.offerer.name,
project.human_enum(:status)
]
# Add names and emails of people with roles in this project
roles_count.each do |k, v|
f = 0
project.user_course_specific_roles.each do |ucsr|
next if ucsr.course_specific_role.name != k
row += [ucsr.user.full_name, ucsr.user.email]
f += 1
end
# Add empty cells if the project doesn't have enough people with this role (e.g. skip "Supervisor 3" if the project has two)
row += Array.new((v - f) * 2, nil)
end
sheet.add_row row
end
end
......@@ -3,8 +3,10 @@
<h3 class="panel-title">Project Client Contacts</h3>
</div>
<div class="list-group">
<% User.with_role(:client, @project).each do |client| %>
<%= link_to_if_rights client, :name, admin_user_url(client), class: 'list-group-item' %>
<% end %>
<% User.with_role(:client, @project).each do |client| %>
<div class="list-group-item">
<%= link_to_if_rights client, :name, admin_user_url(client) %> (<%= mail_to client.email %>)
</div>
<% end %>
</div>
</div>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment