Verified Commit ac8bf9e7 authored by Kaspar Vollenweider's avatar Kaspar Vollenweider
Browse files

add two extra columns to assignments index

parent 9b8aeabd
......@@ -11,7 +11,7 @@ class AssignmentsController < ApplicationController
@assignments = @q.result
respond_to do |format|
format.xlsx do
render xlsx: 'index', filename: 'Begleitungen'
render xlsx: 'index', filename: "Begleitungen_#{Time.zone.now.strftime('%Y-%m-%dT%H%M%S')}"
end
format.html do
@assignments = @assignments.paginate(page: params[:page],
......
......@@ -14,7 +14,9 @@ class ClientsController < ApplicationController
@q.sorts = ['acceptance asc'] if @q.sorts.empty?
@clients = @q.result
respond_to do |format|
format.xlsx
format.xlsx do
render xlsx: 'index', filename: "KlientInnen_#{Time.zone.now.strftime('%Y-%m-%dT%H%M%S')}"
end
format.html do
@clients = @clients.paginate(page: params[:page], per_page: params[:print] && @clients.size)
end
......
......@@ -11,7 +11,9 @@ class GroupOffersController < ApplicationController
@group_offers = @q.result
respond_to do |format|
format.html { @group_offers = @group_offers.paginate(page: params[:page]) }
format.xlsx
format.xlsx do
render xlsx: 'index', filename: "Gruppenangebote_#{Time.zone.now.strftime('%Y-%m-%dT%H%M%S')}"
end
end
end
......
......@@ -9,7 +9,7 @@ class VolunteersController < ApplicationController
@q.sorts = ['acceptance asc'] if @q.sorts.empty?
@volunteers = @q.result
respond_to do |format|
format.xlsx { render xlsx: 'index', filename: 'Freiwilligen_Liste' }
format.xlsx { render xlsx: 'index', filename: "Freiwilligen_Liste_#{Time.zone.now.strftime('%Y-%m-%dT%H%M%S')}" }
format.html { @volunteers = @volunteers.paginate(page: params[:page]) }
end
end
......
module XlsHelper
AXLSX_COL_ALPHA_INDEX = ('A'..'Z').to_a +
('A'..'Z').to_a.map { |letter| "A#{letter}" } +
('A'..'Z').to_a.map { |letter| "B#{letter}" }
# rubocop:disable Metrics/MethodLength
def axlsx_locals(work_book, params)
{
wb: work_book,
std_style: work_book.styles.add_style(
alignment: { wrap_text: true, horizontal: :left, vertical: :top },
width: :auto_fit
),
date_style: work_book.styles.add_style(
alignment: { horizontal: :left, vertical: :top },
format_code: 'dd.mm.yyyy',
width: :auto_fit
),
time_style: work_book.styles.add_style(
alignment: { horizontal: :left, vertical: :top },
format_code: 'hh:mm',
width: :auto_fit
),
date_time_style: work_book.styles.add_style(
alignment: { horizontal: :left, vertical: :top },
format_code: 'dd.mm.yyyy hh:mm',
width: :auto_fit
),
header_style: work_book.styles.add_style(
bg_color: 'FFDFDEDF',
b: true,
alignment: { horizontal: :center, vertical: :center },
border: { color: '00', edges: [:bottom], style: :thin },
width: :auto_fit
),
wrapped_style: work_book.styles.add_style(
alignment: { wrap_text: true, horizontal: :left, vertical: :top }
),
zeit: Time.zone.now,
col_alpha_indexes: AXLSX_COL_ALPHA_INDEX
}.merge(params)
end
# rubocop:enable Metrics/MethodLength
def axlsx_autofilter(sheet, columns, rows_collection, first_col: 'A', first_row: 1)
last_cell = "#{AXLSX_COL_ALPHA_INDEX[columns.size - 1]}#{rows_collection.size + 1}"
sheet.auto_filter = "#{first_col}#{first_row}:#{last_cell}"
sheet.sheet_view.pane do |pane|
pane.top_left_cell = "#{first_col}#{first_row + 1}"
pane.state = :frozen_split
pane.y_split = 1
pane.x_split = 0
pane.active_pane = :bottom_right
end
end
end
......@@ -97,10 +97,6 @@ class Client < ApplicationRecord
date_between(:resigned_at, start_date, end_date)
}
def terminatable?
assignments.active_or_not_yet_active.none?
end
def self.acceptences_restricted
acceptances.except('resigned')
end
......@@ -113,16 +109,9 @@ class Client < ApplicationRecord
cost_units.keys.map(&:to_sym)
end
def gender
SALUTATION_GENDER_MAP[salutation.to_sym]
end
def gender_t
I18n.t("activerecord.attributes.client.genders.#{gender}")
end
def to_s
contact.full_name
# allow ransack to use defined scopes
def self.ransackable_scopes(auth_object = nil)
['active', 'inactive']
end
def self.first_languages
......@@ -131,13 +120,32 @@ class Client < ApplicationRecord
end
end
def other_authorities=(value)
super(value&.squish&.presence)
end
def competent_authority=(value)
super(value&.squish&.presence)
end
def gender
SALUTATION_GENDER_MAP[salutation.to_sym]
end
def gender_t
I18n.t("activerecord.attributes.client.genders.#{gender}")
end
def german_missing?
language_skills.german.blank?
end
# allow ransack to use defined scopes
def self.ransackable_scopes(auth_object = nil)
['active', 'inactive']
def terminatable?
assignments.active_or_not_yet_active.none?
end
def to_s
contact.full_name
end
def active?
......
......@@ -16,6 +16,8 @@ tr
td= link_to_if policy(User).show?,
assignment.involved_authority&.full_name || assignment.creator.full_name,
profile_url_path(assignment.involved_authority || assignment.creator)
= td_truncate_content_modal(assignment.client&.competent_authority, t_attr(:competent_authority, Client), shorten_size: 60)
= td_truncate_content_modal(assignment.client&.other_authorities, t_attr(:other_authorities, Client), shorten_size: 60)
- if policy(Assignment).show_comments?
= td_truncate_content_modal(assignment.comments, 'Rückmeldung')
- if controller_name == 'volunteers' && !assignment.volunteer.external? && policy(Feedback).index?
......
......@@ -10,7 +10,9 @@
th= sort_link @q, :client_contact_last_name, 'Klient/in'
th= sort_link @q, :period_start, t_attr(:period_start, Assignment)
th= sort_link @q, :period_end, t_attr(:period_end, Assignment)
th= 'Fallführende Stelle'
th= sort_link @q, :client_involved_authority_profile_contact_full_name, t_attr(:involved_authority)
th= sort_link @q, :client_competent_authority, t_attr(:competent_authority, Client)
th= sort_link @q, :client_other_authorities, t_attr(:other_authorities, Client)
- if policy(Assignment).show_comments?
th Rückmeldung
th.hidden-print colspan='4'
......
wb.use_shared_strings = true
header_style = wb.styles.add_style(
bg_color: 'FFDFDEDF',
b: true,
alignment: { horizontal: :center, vertical: :center },
border: { color: '00', edges: [:bottom], style: :thin },
width: :auto_fit
)
std_style = wb.styles.add_style alignment: { horizontal: :left, vertical: :top }, width: :auto_fit
wrapped_style = wb.styles.add_style alignment: { wrap_text: true, horizontal: :left, vertical: :top }
date_style = wb.styles.add_style format_code: 'dd.mm.yyyy', width: :auto_fit
wb.add_worksheet(name: t('clients_xlsx')) do |sheet|
# Header row frozen (sticky)
sheet.sheet_view.pane do |pane|
pane.top_left_cell = 'A2'
pane.state = :frozen_split
pane.y_split = 1
pane.x_split = 0
pane.active_pane = :bottom_right
end
sheet.add_row(
[
'Status', # 00
'Freiwillige/r', # 01
'Freiwillige/r Mailadresse', # 02
'Klient/in', # 03
t_attr(:period_start), # 04
t_attr(:period_end), # 05
t_attr(:created_at), # 06
t_attr(:updated_at) # 07
],
style: header_style, height: 25
)
columns = [
'Status', # 'Status'
'Freiwillige/r', # 'Freiwillige/r'
'Freiwillige/r Mailadresse', # 'Freiwillige/r Mailadresse'
'Klient/in', # 'Klient/in'
t_attr(:period_start), # period_start
t_attr(:period_end), # period_end
t_attr(:involved_authority, Client), # client_involved_authority
t_attr(:competent_authority, Client), # client_competent_authority
t_attr(:other_authorities, Client), # client_other_authorities
t_attr(:created_at), # created_at
t_attr(:updated_at) # updated_at
]
sheet.add_row(columns, style: header_style, height: 25)
assignments.each do |assignment|
sheet.add_row(
[
assignment.active? ? 'Aktiv' : 'Inaktiv', # 00
assignment.volunteer.contact.full_name, # 01
assignment.volunteer.contact.primary_email, # 02
assignment.client.contact.full_name, # 03
assignment.period_start, # 04
assignment.period_end, # 05
assignment.created_at.to_date, # 06
assignment.updated_at.to_date # 07
assignment.active? ? 'Aktiv' : 'Inaktiv', # 'Status'
assignment.volunteer.contact.full_name, # 'Freiwillige/r'
assignment.volunteer.contact.primary_email, # 'Freiwillige/r Mailadresse'
assignment.client.contact.full_name, # 'Klient/in'
assignment.period_start, # period_start
assignment.period_end, # period_end
assignment.client&.involved_authority&.full_name, # client_involved_authority
assignment.client&.competent_authority, # client_competent_authority
assignment.client&.other_authorities, # client_other_authorities
assignment.created_at.to_date, # created_at
assignment.updated_at.to_date # updated_at
],
types: [
:string, # 00
:string, # 01
:string, # 02
:string, # 03
:date, # 04
:date, # 05
:date, # 06
:date # 07
:string, # 'Status'
:string, # 'Freiwillige/r'
:string, # 'Freiwillige/r Mailadresse'
:string, # 'Klient/in'
:date, # period_start
:date, # period_end
nil, # client_involved_authority
nil, # client_competent_authority
nil, # client_other_authorities
:date, # created_at
:date # updated_at
],
style: [
std_style, # 00
std_style, # 01
std_style, # 02
std_style, # 03
date_style, # 04
date_style, # 05
date_style, # 06
date_style # 07
std_style, # 'Status'
std_style, # 'Freiwillige/r'
std_style, # 'Freiwillige/r Mailadresse'
std_style, # 'Klient/in'
date_style, # period_start
date_style, # period_end
std_style, # client_involved_authority
std_style, # client_competent_authority
std_style, # client_other_authorities
date_style, # created_at
date_style # updated_at
]
)
end
sheet.auto_filter = 'A1:H1'
sheet.auto_filter = "A1:#{col_alpha_indexes[columns.size - 1]}#{assignments.count + 1}"
# Header row frozen (sticky)
sheet.sheet_view.pane do |pane|
pane.top_left_cell = 'A2'
pane.state = :frozen_split
pane.y_split = 1
pane.x_split = 0
pane.active_pane = :bottom_right
end
end
wb = xlsx_package.workbook
render partial: 'assignments_table', locals: { wb: wb, assignments: @assignments }
render partial: 'assignments_table', locals: axlsx_locals(wb, assignments: @assignments)
......@@ -32,8 +32,8 @@ tr id=dom_id(client)
td
- if client.involved_authority.present?
= link_to client.involved_authority.full_name, profile_url_path(client.involved_authority)
td= client.competent_authority
td= client.other_authorities
= td_truncate_content_modal(client.competent_authority, t_attr(:competent_authority, Client), shorten_size: 60)
= td_truncate_content_modal(client.other_authorities, t_attr(:other_authorities, Client), shorten_size: 60)
td.no-wrap= l(client.created_at.to_date)
- if policy(Client).show_comments?
= td_truncate_content_modal(client.comments, 'Bemerkungen')
= td_truncate_content_modal(client.comments, 'Bemerkungen', shorten_size: 60)
wb.use_shared_strings = true
header_style = wb.styles.add_style(
bg_color: 'FFDFDEDF',
b: true,
alignment: { horizontal: :center, vertical: :center },
border: { color: '00', edges: [:bottom], style: :thin },
width: :auto_fit
)
std_style = wb.styles.add_style alignment: { horizontal: :left, vertical: :top }, width: :auto_fit
wrapped_style = wb.styles.add_style alignment: { wrap_text: true, horizontal: :left, vertical: :top }
date_style = wb.styles.add_style format_code: 'dd.mm.yyyy', width: :auto_fit
wb.add_worksheet(name: t('clients_xlsx')) do |sheet|
# Header row frozen (sticky)
sheet.sheet_view.pane do |pane|
pane.top_left_cell = 'A2'
pane.state = :frozen_split
pane.y_split = 1
pane.x_split = 0
pane.active_pane = :bottom_right
end
sheet.add_row(
[
'id', # 00
t_attr(:salutation), # 01
t_attr(:last_name, Contact), # 02
t_attr(:first_name, Contact), # 03
t_attr(:street, Contact), # 04
t_attr(:extended, Contact), # 05
t_attr(:postal_code, Contact), # 06
t_attr(:city, Contact), # 07
t_attr(:primary_phone, Contact), # 08
t_attr(:secondary_phone, Contact), # 09
t_attr(:primary_email, Contact), # 10
t_attr(:birth_year), # 11
t_attr(:nationality), # 12
t_attr(:education), # 13
t_attr(:entry_date), # 14
t_attr(:acceptance), # 15
t_attr(:involved_authority), # 16
t_attr(:language_skills), # 17
t_attr(:goals), # 18
t_attr(:created_at), # 19
t_attr(:updated_at) # 20
],
style: header_style, height: 25
)
columns = [
'id', # id
t_attr(:salutation), # salutation
t_attr(:last_name, Contact), # last_name
t_attr(:first_name, Contact), # first_name
t_attr(:street, Contact), # street
t_attr(:extended, Contact), # extended
t_attr(:postal_code, Contact), # postal_code
t_attr(:city, Contact), # city
t_attr(:primary_phone, Contact), # primary_phone
t_attr(:secondary_phone, Contact), # secondary_phone
t_attr(:primary_email, Contact), # primary_email
t_attr(:birth_year), # birth_year
t_attr(:nationality), # nationality
t_attr(:education), # education
t_attr(:entry_date), # entry_date
t_attr(:acceptance), # acceptance
t_attr(:involved_authority), # involved_authority
t_attr(:competent_authority), # competent_authority
t_attr(:other_authorities), # other_authorities
t_attr(:language_skills), # language_skills
t_attr(:goals), # goals
t_attr(:created_at), # created_at
t_attr(:updated_at) # updated_at
]
sheet.add_row(columns, style: header_style, height: 25)
clients.each do |client|
salutation = t("salutation.#{client.salutation}") if client.salutation?
contact = client.contact
sheet.add_row(
[
client.id, # 00
salutation, # 01
contact.last_name, # 02
contact.first_name, # 03
contact.street, # 04
contact.extended, # 05
contact.postal_code, # 06
contact.city, # 07
contact.primary_phone, # 08
contact.secondary_phone, # 09
contact.primary_email, # 10
client.birth_year, # 11
nationality_name(client.nationality), # 12
client.education, # 13
client.entry_date, # 14
t("acceptance.#{client.acceptance}"), # 15
client.involved_authority, # 16
client.language_skills.native_and_human_readable.join("\r"), # 17
client.goals, # 18
client.created_at.to_date, # 19
client.updated_at.to_date # 20
client.id, # id
salutation, # salutation
contact.last_name, # last_name
contact.first_name, # first_name
contact.street, # street
contact.extended, # extended
contact.postal_code, # postal_code
contact.city, # city
contact.primary_phone, # primary_phone
contact.secondary_phone, # secondary_phone
contact.primary_email, # primary_email
client.birth_year, # birth_year
nationality_name(client.nationality), # nationality
client.education, # education
client.entry_date, # entry_date
t("acceptance.#{client.acceptance}"), # acceptance
client.involved_authority&.full_name, # involved_authority
client.competent_authority, # competent_authority
client.other_authorities, # other_authorities
client.language_skills.native_and_human_readable.join("\r"), # language_skills
client.goals, # goals
client.created_at.to_date, # created_at
client.updated_at.to_date # updated_at
],
types: [
:string, # 00
:string, # 01
:string, # 02
:string, # 03
:string, # 04
:string, # 05
:string, # 06
:string, # 07
:string, # 08
:string, # 09
:string, # 10
:date, # 11
:string, # 12
:string, # 13
:string, # 14
:string, # 15
:string, # 16
:string, # 17
:string, # 18
:date, # 19
:date # 20
:string, # id
:string, # salutation
:string, # last_name
:string, # first_name
:string, # street
:string, # extended
:string, # postal_code
:string, # city
:string, # primary_phone
:string, # secondary_phone
:string, # primary_email
:date, # birth_year
:string, # nationality
:string, # education
:string, # entry_date
:string, # acceptance
:string, # involved_authority
:string, # competent_authority
:string, # other_authorities
:string, # language_skills
:string, # goals
:date, # created_at
:date # updated_at
],
style: [
std_style, # 00
std_style, # 01
std_style, # 02
std_style, # 03
wrapped_style, # 04
wrapped_style, # 05
std_style, # 06
std_style, # 07
std_style, # 08
std_style, # 09
std_style, # 10
std_style, # 11
std_style, # 12
std_style, # 13
std_style, # 14
std_style, # 15
std_style, # 16
std_style, # 17
std_style, # 18
date_style, # 19
date_style # 20
std_style, # id
std_style, # salutation
std_style, # last_name
std_style, # first_name
wrapped_style, # street
wrapped_style, # extended
std_style, # postal_code
std_style, # city
std_style, # primary_phone
std_style, # secondary_phone
std_style, # primary_email
std_style, # birth_year
std_style, # nationality
std_style, # education
std_style, # entry_date
std_style, # acceptance
std_style, # involved_authority
std_style, # competent_authority
std_style, # other_authorities
std_style, # language_skills
wrapped_style, # goals
date_style, # created_at
date_style # updated_at
]
)
end
sheet.auto_filter = 'A1:U1'
axlsx_autofilter(sheet, columns, clients)
end
wb = xlsx_package.workbook
render partial: 'client_table', locals: { wb: wb, clients: @clients }
render partial: 'client_table', locals: axlsx_locals(wb, clients: @clients)
wb = xlsx_package.workbook
# wb.use_shared_strings = true
## Format and style definitions
#
default_locals = {
wb: wb,
standard_format: wb.styles.add_style(
alignment: { wrap_text: true, horizontal: :left, vertical: :top },
width: :auto_fit
),
date_format: wb.styles.add_style(
alignment: { horizontal: :left, vertical: :top },
format_code: 'dd.mm.yyyy',
width: :auto_fit
),
time_format: wb.styles.add_style(
alignment: { horizontal: :left, vertical: :top },
format_code: 'hh:mm',
width: :auto_fit
),
date_time_format: wb.styles.add_style(
alignment: { horizontal: :left, vertical: :top },
format_code: 'dd.mm.yyyy hh:mm',
width: :auto_fit
),
header_style: wb.styles.add_style(
bg_color: 'FFDFDEDF',
b: true,
alignment: { horizontal: :center, vertical: :center },
border: { color: '00', edges: [:bottom], style: :thin },
width: :auto_fit
),
wrapped_style: wb.styles.add_style(
alignment: { wrap_text: true, horizontal: :left, vertical: :top }
),
zeit: Time.zone.now,
col_alpha_indexes: ('A'..'Z').to_a + ('A'..'Z').to_a.map { |letter| "A#{letter}" }
}
locals = axlsx_locals(wb, volunteers: @volunteers,
clients: @clients,