Skip to content

Commit 6224216

Browse files
anna-devKagemaru
authored andcommitted
Make member absences remaining vacation column sortable (64536)
1 parent bf76977 commit 6224216

22 files changed

+271
-112
lines changed

.rubocop_todo.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2025-12-09 20:43:27 UTC using RuboCop version 1.75.3.
3+
# on 2025-12-10 09:06:25 UTC using RuboCop version 1.75.3.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
@@ -61,7 +61,7 @@ Lint/UnreachableLoop:
6161
Exclude:
6262
- 'app/models/working_condition.rb'
6363

64-
# Offense count: 111
64+
# Offense count: 114
6565
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
6666
Metrics/AbcSize:
6767
Max: 282
@@ -82,15 +82,15 @@ Metrics/ClassLength:
8282
Metrics/CyclomaticComplexity:
8383
Max: 13
8484

85-
# Offense count: 131
85+
# Offense count: 132
8686
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
8787
Metrics/MethodLength:
8888
Max: 312
8989

9090
# Offense count: 5
9191
# Configuration parameters: CountComments, CountAsOne.
9292
Metrics/ModuleLength:
93-
Max: 162
93+
Max: 163
9494

9595
# Offense count: 2
9696
# Configuration parameters: CountKeywordArgs.
@@ -228,7 +228,7 @@ Rails/HasManyOrHasOneDependent:
228228
- 'app/models/service.rb'
229229
- 'app/models/work_item.rb'
230230

231-
# Offense count: 62
231+
# Offense count: 63
232232
# Configuration parameters: Include.
233233
# Include: app/helpers/**/*.rb
234234
Rails/HelperInstanceVariable:
@@ -385,7 +385,7 @@ Style/ConditionalAssignment:
385385
Exclude:
386386
- 'app/controllers/concerns/worktimes_report.rb'
387387

388-
# Offense count: 326
388+
# Offense count: 327
389389
# Configuration parameters: AllowedConstants.
390390
Style/Documentation:
391391
Enabled: false
@@ -428,7 +428,7 @@ Style/OpenStructUse:
428428
Style/OptionalBooleanParameter:
429429
Enabled: false
430430

431-
# Offense count: 71
431+
# Offense count: 74
432432
# This cop supports safe autocorrection (--autocorrect).
433433
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, SplitStrings.
434434
# URISchemes: http, https

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ PuzzleTime is created by the following people:
33
Code:
44
Andreas Maierhofer, Puzzle ITC
55
Andreas Zuber, Puzzle ITC
6+
Anna Mund, Puzzle ITC
67
Bruno Santschi, Puzzle ITC
78
Damian Senn, Puzzle ITC
89
Daniel Illi, Puzzle ITC

app/controllers/application_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def set_period
5959
p = session[:period]
6060
return unless p.is_a? Array
6161

62-
@period = Period.new(*p)
62+
@period = Period.new(*p) if p.is_a?(Array)
6363
end
6464

6565
def sanitized_back_url

app/controllers/evaluator_controller.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def set_management_evaluation
140140
params[:category_id], Regexp.last_match[1]
141141
)
142142
when 'departmentorders' then Evaluations::DepartmentOrdersEval.new(params[:category_id])
143-
when 'absences' then Evaluations::AbsencesEval.new(params[:department_id], **worktime_search_conditions)
143+
when 'absences' then Evaluations::AbsencesEval.new(params[:department_id], sort_conditions, **worktime_search_conditions)
144144
when 'employeeabsences' then Evaluations::EmployeeAbsencesEval.new(
145145
params[:category_id], **worktime_search_conditions
146146
)
@@ -230,6 +230,12 @@ def worktime_search_conditions
230230
{ absence_id: params[:absence_id] }
231231
end
232232

233+
def sort_conditions
234+
return {} if params[:sort].blank?
235+
236+
params.to_enum.to_h.slice('sort_dir', 'sort')
237+
end
238+
233239
def authorize_action
234240
params[:evaluation] ||= params[:action].to_s
235241
evaluation

app/domain/evaluations/absences_eval.rb

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,61 @@
77

88
module Evaluations
99
class AbsencesEval < Evaluations::Evaluation
10+
include EvaluatorHelper
11+
include FormatHelper
12+
1013
self.sub_evaluation = 'employeeabsences'
1114
self.division_column = :employee_id
1215
self.label = 'Members Absenzen'
1316
self.absences = true
1417
self.detail_columns = detail_columns.reject { |i| i == :billable }
1518
self.detail_labels = detail_labels.merge(account: 'Absenz')
1619

17-
attr_reader :department_id
20+
attr_reader :department_id, :sort_conditions
1821

19-
def initialize(department_id = nil, **worktime_search_conditions)
22+
def initialize(department_id = nil, sort_conditions = nil, **worktime_search_conditions)
2023
super(Employee, **worktime_search_conditions)
2124
@department_id = department_id
25+
@sort_conditions = sort_conditions
26+
end
27+
28+
def divisions(period = nil, times = nil)
29+
employees_with_absences(period, times).map do |e|
30+
unformatted_vacations = remaining_vacations(e, format: false)
31+
e.remaining_vacations = format_days(unformatted_vacations)
32+
e.sort_col = unformatted_vacations * descending
33+
e
34+
end.sort_by(&:sort_col)
2235
end
2336

24-
def divisions(period = nil)
37+
def employees_with_absences(period, times)
2538
scope = Employee.employed_ones(period || Period.current_year)
2639

27-
return scope if department_id.blank?
40+
scope = scope.where(department_id: department_id) if department_id.present?
41+
scope.filter do |e|
42+
times_or_plannings?(self, e, times, [period])
43+
end
44+
end
2845

29-
scope.where(department_id:)
46+
def division_header
47+
'Member'
3048
end
3149

3250
def employee_id
3351
division&.id
3452
end
3553

3654
def division_supplement(_user)
37-
[[:remaining_vacations, 'Übrige Ferien', 'right'],
38-
[:overtime_vacations_tooltip, '', 'left']]
55+
{
56+
remaining_vacations: { title: 'Übrige Ferien', align: 'right', sortable: true },
57+
overtime_vacations_tooltip: {}
58+
}
59+
end
60+
61+
private
62+
63+
def descending
64+
sort_conditions && sort_conditions['sort_dir'] == 'desc' ? -1 : 1
3965
end
4066
end
4167
end

app/domain/evaluations/clients_eval.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def initialize
1919
super(Client)
2020
end
2121

22-
def divisions(_period = nil)
22+
def divisions(_period = nil, _times = nil)
2323
WorkItem.joins(:client).list
2424
end
2525

app/domain/evaluations/department_orders_eval.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ def initialize(department_id)
1616
super(Department.find(department_id))
1717
end
1818

19-
def divisions(_period = nil)
19+
def divisions(_period = nil, _times = nil)
2020
WorkItem.joins(:order).includes(:order).where(orders: { department_id: category.id }).list
2121
end
2222

2323
def division_supplement(_user)
24-
[[:order_completed, 'Abschluss erledigt', 'left'],
25-
[:order_committed, 'Abschluss freigegeben', 'left']]
24+
{
25+
order_completed: { title: 'Abschluss erledigt' },
26+
order_committed: { title: 'Abschluss freigegeben' }
27+
}
2628
end
2729

2830
def include_no_period_zero_totals

app/domain/evaluations/employee_work_items_eval.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def for?(user)
2222
end
2323

2424
def division_supplement(_user)
25-
[]
25+
{}
2626
end
2727

2828
def employee_id

app/domain/evaluations/employees_eval.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def initialize(emp_search_conditions = {})
1818
super(Employee)
1919
end
2020

21-
def divisions(period = nil)
21+
def divisions(period = nil, _times = nil)
2222
employees = if period
2323
Employee.list
2424
else
@@ -51,11 +51,13 @@ def sum_total_times(period = nil)
5151
end
5252

5353
def division_supplement(_user)
54-
[[:overtime, 'Überstunden', 'right'],
55-
[:vacations, 'Ferien', 'right'],
56-
[:overtime_vacations_tooltip, '', 'left'],
57-
[:worktime_commits, 'Freigabe', 'left'],
58-
[:worktime_reviews, 'Kontrolle', 'left']]
54+
{
55+
overtime: { title: 'Überstunden', align: 'right' },
56+
vacations: { title: 'Ferien', align: 'right' },
57+
overtime_vacations_tooltip: {},
58+
worktime_commits: { title: 'Freigabe' },
59+
worktime_reviews: { title: 'Kontrolle' }
60+
}
5961
end
6062
end
6163
end

app/domain/evaluations/evaluation.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class Evaluation
6767

6868
# Returns a list of all division objects for the represented category.
6969
# May be parameterized by a period. This is ignored by default.
70-
def divisions(_period = nil)
70+
def divisions(_period = nil, _times = nil)
7171
category.send(division_method).list
7272
end
7373

@@ -154,7 +154,11 @@ def worktime_name
154154
# Returns the class name of the division objects.
155155
def division_header
156156
divs = divisions
157-
divs.respond_to?(:klass) ? divs.klass.model_name.human : ''
157+
if divs.respond_to?(:klass)
158+
divs.klass.model_name.human
159+
else
160+
respond_to?(:division_header) ? division_header : ''
161+
end
158162
end
159163

160164
# Returns a two-dimensional Array with helper methods of the evaluator
@@ -164,7 +168,7 @@ def division_header
164168
# No methods are called by default.
165169
# See EmployeeWorkItemsEval for an example.
166170
def division_supplement(_user)
167-
[]
171+
{}
168172
end
169173

170174
def sub_work_items_evaluation(division)

0 commit comments

Comments
 (0)