Skip to content
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
298 changes: 150 additions & 148 deletions .rubocop_todo.yml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Code:
Bruno Santschi, Puzzle ITC
Damian Senn, Puzzle ITC
Daniel Illi, Puzzle ITC
Linus Degen, Puzzle ITC
Mathis Hofer, Puzzle ITC
Pascal Simon, Puzzle ITC
Pascal Zumkehr, Puzzle ITC
Expand Down
39 changes: 23 additions & 16 deletions app/domain/evaluations/evaluation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,29 @@ def worktime_name
absences? ? Absencetime.label : Ordertime.label
end

# Infos which should be displayed as labels above evaluation table,
# if possible with link to entity (helper functions)
# Can be overloaded if different models/links should be displayed instead of
# category and division
# Available properties: item, prefix (optional), link_text (optional)
def header_info_labels
[
{ item: category },
{ item: division }
]
end

# Additional info labels with links which will be placed above evaluation table
# Available properties:
# - label (string): Is used as the link text
# - resource (object): Resource which link should refer to
# - child_resource (symbol): Optional child resource for nested URLs
# - include_period_labels (bool): URL params regarding period will be added to link
# See ManagedOrdersEval for an example.
def header_info_labels_custom
[]
end

# The header name of the division column to be displayed.
# Returns the class name of the division objects.
def division_header
Expand Down Expand Up @@ -201,16 +224,6 @@ def set_division_id(division_id = nil)
@division = container.find(division_id.to_i)
end

# Label for the represented category.
def category_label
detail_label(category)
end

# Label for the represented division, if any.
def division_label
detail_label(division)
end

def edit_link?(user)
for?(user) || !absences?
end
Expand Down Expand Up @@ -307,12 +320,6 @@ def worktime_type
absences? ? 'Absencetime' : 'Ordertime'
end

def detail_label(item)
return '' if item.nil? || item.is_a?(Class)

"#{item.class.model_name.human}: #{item.label}"
end

def class_category?
category.is_a? Class
end
Expand Down
19 changes: 17 additions & 2 deletions app/domain/evaluations/managed_orders_eval.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,23 @@ class ManagedOrdersEval < Evaluations::WorkItemsEval
self.billable_hours = true
self.planned_hours = true

def category_label
"Kunde: #{division.order.client.name}"
# Override default labels for category and division with client and order
def header_info_labels
[
{ item: division.order.client },
{ item: division.order }
]
end

def header_info_labels_custom
[
{
label: 'Leistungsübersicht im Auftrag',
resource: division.order,
child_resource: :order_services,
include_period_labels: true
}
]
end

def divisions(_period = nil, _times = nil)
Expand Down
13 changes: 5 additions & 8 deletions app/domain/evaluations/sub_work_items_eval.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,11 @@ def account_id
division ? division.id : category.id
end

# Label for the represented category.
def category_label
"Kunde: #{category.top_item.client.label}"
end

# Label for the represented division, if any.
def division_label
"Position: #{(division || category).label_ancestry}"
def header_info_labels
[
{ item: category.top_item.client },
{ item: category, link_text: (division || category).label_ancestry }
]
end

def division_column
Expand Down
7 changes: 5 additions & 2 deletions app/domain/evaluations/work_item_employees_eval.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ def account_id

####### overwritten methods for working with work item hierarchies

def category_label
"Position: #{category.top? ? category.label : category.label_verbose}"
def header_info_labels
[
{ item: category, link_text: category.top? ? category.label : category.label_verbose },
{ item: division }
]
end

def worktime_query(receiver, period = nil, division = nil)
Expand Down
29 changes: 29 additions & 0 deletions app/helpers/evaluator_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,35 @@ def detail_th_align(field)
end
end

# Builds a label and link to the given item
# prefix (text before link) and link_text can optionally be overwritten
def build_detail_label(item, prefix = nil, link_text = nil)
return '' if item.nil? || item.is_a?(Class)

prefix ||= item.class.model_name.human
link = assoc_link(item, link_text)

safe_join([prefix, ': ', link])
end

# Builds a custom link, can be used for nested URLs
# Period data can optionally be propagated into URL
def build_detail_label_custom(label, period = nil)
link_props = [
label[:resource],
label[:child_resource]
]

if label[:include_period_labels] && period
link_props << {
end_date: period.end_date.to_s,
start_date: period.start_date.to_s
}
end

link_to(label[:label], link_props)
end

def detail_td(worktime, field)
case field
when :work_date then content_tag(:td, f(worktime.work_date), class: 'right nowrap', style: 'width: 160px;')
Expand Down
9 changes: 5 additions & 4 deletions app/helpers/format_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,15 @@ def format_has_many(obj, assoc)
end

# Renders a link to the given association entry.
def assoc_link(val)
def assoc_link(val, link_text = nil)
display_text = link_text.presence || val.to_s
path_method = "#{val.class.model_name.singular_route_key}_path"
if show_path_exists?(path_method, val) && can?(:show, val)
link_to(val.to_s, val)
link_to(display_text, val)
elsif show_path_exists?("edit_#{path_method}", val) && can?(:edit, val)
link_to(val.to_s, edit_polymorphic_path(val))
link_to(display_text, edit_polymorphic_path(val))
else
val.to_s
display_text
end
end

Expand Down
9 changes: 6 additions & 3 deletions app/views/evaluator/details.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@

- @title = "#{@evaluation.worktime_name} Details #{@period.to_s}"

%h3= @evaluation.category_label
%h3= @evaluation.division_label
- @evaluation.header_info_labels.each do |label|
%p= build_detail_label(label[:item], prefix=label[:prefix], link_text=label[:link_text])

- @evaluation.header_info_labels_custom.each do |custom_label|
%p= build_detail_label_custom(custom_label, @period)

- if @absence
%h3
%p
Absenztyp:
= @absence

Expand Down
44 changes: 44 additions & 0 deletions test/helpers/evaluator_helper_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# frozen_string_literal: true

# Copyright (c) 2006-2025, Puzzle ITC AG. This file is part of
# PuzzleTime and licensed under the Affero General Public License version 3
# or later. See the COPYING file at the top-level directory or at
# https://github.com/puzzle/puzzletime.

require 'test_helper'

class EvaluatorHelperTest < ActionView::TestCase
include UtilityHelper
include CrudTestHelper
include FormatHelper

setup :reset_db, :setup_db, :create_test_data
teardown :reset_db

test 'build custom detail label without period parameters' do
employee = Employee.find_by(id: 1)
label = {
label: 'Meine Spesen',
resource: employee,
child_resource: :expenses,
include_period_labels: false
}
expected_link = '<a href="/employees/1/expenses">Meine Spesen</a>'

assert_equal(expected_link, build_detail_label_custom(label))
end

test 'build custom detail label with period parameters' do
employee = Employee.find_by(id: 1)
period = Period.new(Date.new(2025, 12, 1), Date.new(2025, 12, 31))
label = {
label: 'Meine Spesen',
resource: employee,
child_resource: :expenses,
include_period_labels: true
}
expected_link = '<a href="/employees/1/expenses?end_date=2025-12-31&amp;start_date=2025-12-01">Meine Spesen</a>'

assert_equal(expected_link, build_detail_label_custom(label, period))
end
end