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
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ The encoding options are the same as on the page itself and might depend on your

### workday settings

Workday settings are fixed now (see [#27](https://github.com/xmera-circle/redmine_workload/issues/27)) but lead to restrictions for PostgreSQL user.
Workday settings were fixed in this version (see [#27](https://github.com/xmera-circle/redmine_workload/issues/27)) but led to restrictions for PostgreSQL user. Since 4.1.0 the working days come from Redmine's own configuration, see below.

:warning: **PostgreSQL requires Ruby 3.1 or newer.** Redmine 6.1 requires Ruby 3.2
or newer anyway, so this is no longer a separate constraint for the 4.x line.
Expand Down Expand Up @@ -109,7 +109,16 @@ Please refer to [redmine.org -> Plugins](https://www.redmine.org/projects/redmin
There are three places where this plugin might be configured:

1. In the plugin settings, available in the administration area under `plugins`.
You can configure working days, thresholds here and set global holidays.
You can configure thresholds here and set global holidays. The working days
are **not** configured here: they are read from Redmine's own
`Administration -> Settings -> Issue tracking -> Non-working days`, so that the
workload calculation and the rest of Redmine agree on which days are worked.

:warning: Changing the working days does not show up in the workload view right
away. `WlDateTools.working_days_in_time_span` caches its result per user and
time span for up to 12 hours. Restart Redmine or clear its cache
(`rake tmp:cache:clear`, or remove `tmp/cache`) to apply the change
immediately. The same applies to global holidays and vacations.

2. In the roles section of the administration area, the plugin adds new permissions as described below.
There is no need to configure this plugin on project level.
Expand Down
97 changes: 8 additions & 89 deletions app/views/settings/_workload_settings.erb
Original file line number Diff line number Diff line change
@@ -1,96 +1,15 @@
<%
# This file provides configuration options for the workload plugin.
%>
<fieldset class="box tabular">
<legend><%= l(:workload_settings_general_workdays) %></legend>

<p><%= l(:workload_settings_general_workdays_explanation) %></p>

<p>
<label><%= l(:workload_settings_general_workdays_monday) %></label>
<input type="hidden"
name="settings[general_workday_monday]"
value=""
>
<input type="checkbox"
name="settings[general_workday_monday]"
value="checked"
<%= "checked" if settings['general_workday_monday'] != '' %>
>
</p>
<p>
<label><%= l(:workload_settings_general_workdays_tuesday) %></label>
<input type="hidden"
name="settings[general_workday_tuesday]"
value=""
>
<input type="checkbox"
name="settings[general_workday_tuesday]"
value="checked"
<%= "checked" if settings['general_workday_tuesday'] != '' %>
>
</p>
<p>
<label><%= l(:workload_settings_general_workdays_wednesday) %></label>
<input type="hidden"
name="settings[general_workday_wednesday]"
value=""
>
<input type="checkbox"
name="settings[general_workday_wednesday]"
value="checked"
<%= "checked" if settings['general_workday_wednesday'] != '' %>
>
</p>
<p>
<label><%= l(:workload_settings_general_workdays_thursday) %></label>
<input type="hidden"
name="settings[general_workday_thursday]"
value=""
>
<input type="checkbox"
name="settings[general_workday_thursday]"
value="checked"
<%= "checked" if settings['general_workday_thursday'] != '' %>
>
</p>
<p>
<label><%= l(:workload_settings_general_workdays_friday) %></label>
<input type="hidden"
name="settings[general_workday_friday]"
value=""
>
<input type="checkbox"
name="settings[general_workday_friday]"
value="checked"
<%= "checked" if settings['general_workday_friday'] != '' %>
>
</p>
<p>
<label><%= l(:workload_settings_general_workdays_saturday) %></label>
<input type="hidden"
name="settings[general_workday_saturday]"
value=""
>
<input type="checkbox"
name="settings[general_workday_saturday]"
value="checked"
<%= "checked" if settings['general_workday_saturday'] != '' %>
>
</p>
<p>
<label><%= l(:workload_settings_general_workdays_sunday) %></label>
<input type="hidden"
name="settings[general_workday_sunday]"
value=""
>
<input type="checkbox"
name="settings[general_workday_sunday]"
value="checked"
<%= "checked" if settings['general_workday_sunday'] != '' %>
>
</p>
<fieldset class="box">
<legend><%= l(:workload_settings_general_workdays) %></legend>

<p><em class="info"><%= l(:workload_settings_general_workdays_from_core) %></em></p>
<p><%= link_to l(:setting_non_working_week_days), settings_path(tab: 'issues') %></p>

<p><em class="info icon icon-warning"><%= sprite_icon('warning', l(:workload_settings_general_workdays_cache_hint)) %></em></p>
</fieldset>

<fieldset class="box tabular">
<legend><%= l(:workload_settings_hours) %></legend>

Expand Down
2 changes: 2 additions & 0 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ de:
workload_overdue_issues_hours: "Stunden aus überfälligen Tickets:"
workload_settings_general_workdays: "Wöchentliche Arbeitstage"
workload_settings_general_workdays_explanation: "Diese Tage werden bei der Berechnung der Arbeitsbelastung als Arbeitstage angenommen:"
workload_settings_general_workdays_from_core: "Die Arbeitstage stammen aus Redmines eigener Konfiguration, damit beide übereinstimmen. Dort ändern:"
workload_settings_general_workdays_cache_hint: "Eine Änderung wirkt nicht sofort: die Berechnung wird je Anwender und Zeitraum bis zu 12 Stunden zwischengespeichert. Für eine sofortige Wirkung Redmine neu starten oder den Cache leeren."
workload_settings_general_workdays_monday: "Montag"
workload_settings_general_workdays_tuesday: "Dienstag"
workload_settings_general_workdays_wednesday: "Mittwoch"
Expand Down
2 changes: 2 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ en:
workload_overdue_issues_hours: "Hours from overdue issues:"
workload_settings_general_workdays: "Weekly working days"
workload_settings_general_workdays_explanation: "The following days will be considered as working days when computing the workload:"
workload_settings_general_workdays_from_core: "Working days are taken from Redmine's own configuration so that both agree. Change them there:"
workload_settings_general_workdays_cache_hint: "Changing them does not show up right away: the calculation is cached per user and time span for up to 12 hours. Restart Redmine or clear its cache to apply the change immediately."
workload_settings_general_workdays_monday: "Monday:"
workload_settings_general_workdays_tuesday: "Tuesday:"
workload_settings_general_workdays_wednesday: "Wednesday:"
Expand Down
2 changes: 2 additions & 0 deletions config/locales/it.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ it:

workload_settings_general_workdays: "Giorni lavorativi settimanali"
workload_settings_general_workdays_explanation: "I seguenti giorni settimanali saranno considerati come lavorativi:"
workload_settings_general_workdays_from_core: "I giorni lavorativi provengono dalla configurazione di Redmine, in modo che coincidano. Modificali qui:"
workload_settings_general_workdays_cache_hint: "Una modifica non ha effetto immediato: il calcolo viene memorizzato nella cache per utente e periodo fino a 12 ore. Per applicarla subito, riavvia Redmine o svuota la cache."
workload_settings_general_workdays_monday: "Lunedì:"
workload_settings_general_workdays_tuesday: "Martedì:"
workload_settings_general_workdays_wednesday: "Mercoledì:"
Expand Down
7 changes: 0 additions & 7 deletions init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@

settings partial: 'settings/workload_settings',
default: {
'general_workday_monday' => 'checked',
'general_workday_tuesday' => 'checked',
'general_workday_wednesday' => 'checked',
'general_workday_thursday' => 'checked',
'general_workday_friday' => 'checked',
'general_workday_saturday' => '',
'general_workday_sunday' => '',
'threshold_lowload_min' => 0.1,
'threshold_normalload_min' => 7,
'threshold_highload_min' => 8.5,
Expand Down
14 changes: 3 additions & 11 deletions lib/redmine_workload/wl_date_tools.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,10 @@ def self.months_in_time_span(time_span)

# Returns a list of all regular working weekdays.
# 1 is monday, 7 is sunday (same as in Date::cwday)
#
# Taken from Redmine's own 'Non-working days' setting so that both agree.
def self.working_days
result = Set.new

result.add(1) if settings['general_workday_monday'] != ''
result.add(2) if settings['general_workday_tuesday'] != ''
result.add(3) if settings['general_workday_wednesday'] != ''
result.add(4) if settings['general_workday_thursday'] != ''
result.add(5) if settings['general_workday_friday'] != ''
result.add(6) if settings['general_workday_saturday'] != ''
result.add(7) if settings['general_workday_sunday'] != ''

result
Set.new((1..7).to_a - Array(Setting.non_working_week_days).map(&:to_i))
end

def self.working_days_in_time_span(time_span, assignee, no_cache: false)
Expand Down
12 changes: 3 additions & 9 deletions test/unit/user_workload_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -788,16 +788,10 @@ def teardown

private

# Set Saturday, Sunday and Wednesday to be a holiday, all others to be a
# working day.
# Set Saturday, Sunday and Wednesday to be a non-working day, all others to
# be a working day.
def define_saturday_sunday_and_wednesday_as_holiday
settings['general_workday_monday'] = 'checked'
settings['general_workday_tuesday'] = 'checked'
settings['general_workday_wednesday'] = ''
settings['general_workday_thursday'] = 'checked'
settings['general_workday_friday'] = 'checked'
settings['general_workday_saturday'] = ''
settings['general_workday_sunday'] = ''
Setting.non_working_week_days = %w[3 6 7]
end

def assert_issue_times_hash_equals(expected, actual)
Expand Down
37 changes: 15 additions & 22 deletions test/unit/wl_date_tools_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ def setup

test 'working_days_in_time_span works if start and end day are equal and no holiday.' do
# Set friday to be a working day.
Setting['plugin_redmine_workload']['general_workday_friday'] = 'checked'
Setting.non_working_week_days = %w[6 7]

date = Date.new(2005, 12, 30) # A friday
assert_equal Set.new([date]), RedmineWorkload::WlDateTools.working_days_in_time_span(date..date, @user, no_cache: true)
end

test 'working_days_in_time_span works if start and end day are equal and a holiday.' do
# Set friday to be a holiday.
Setting['plugin_redmine_workload']['general_workday_friday'] = ''
# Set friday to be a non-working day.
Setting.non_working_week_days = %w[5 6 7]

date = Date.new(2005, 12, 30) # A friday
assert_equal Set.new, RedmineWorkload::WlDateTools.working_days_in_time_span(date..date, @user, no_cache: true)
Expand All @@ -33,24 +33,17 @@ def setup
end

test 'working_days_in_time_span works if both days follow each other and are holidays.' do
# Set wednesday and thursday to be a holiday.
Setting['plugin_redmine_workload']['general_workday_wednesday'] = ''
Setting['plugin_redmine_workload']['general_workday_thursday'] = ''
# Set wednesday and thursday to be non-working days.
Setting.non_working_week_days = %w[3 4]

start_date = Date.new(2005, 12, 28) # A wednesday
end_date = Date.new(2005, 12, 29) # A thursday
assert_equal Set.new, RedmineWorkload::WlDateTools.working_days_in_time_span(start_date..end_date, @user, no_cache: true)
end

test 'working_days_in_time_span works if only weekends and mondays are holidays and startday is thursday, endday is tuesday.' do
# Set saturday, sunday and monday to be a holiday, all others to be a working day.
Setting['plugin_redmine_workload']['general_workday_monday'] = ''
Setting['plugin_redmine_workload']['general_workday_tuesday'] = 'checked'
Setting['plugin_redmine_workload']['general_workday_wednesday'] = 'checked'
Setting['plugin_redmine_workload']['general_workday_thursday'] = 'checked'
Setting['plugin_redmine_workload']['general_workday_friday'] = 'checked'
Setting['plugin_redmine_workload']['general_workday_saturday'] = ''
Setting['plugin_redmine_workload']['general_workday_sunday'] = ''
# Set saturday, sunday and monday to be non-working days.
Setting.non_working_week_days = %w[1 6 7]

start_date = Date.new(2005, 12, 29) # A thursday
end_date = Date.new(2006, 1, 3) # A tuesday
Expand All @@ -65,18 +58,18 @@ def setup
end

test 'working_days returns the working days.' do
# Set saturday, sunday and monday to be a holiday, all others to be a working day.
Setting['plugin_redmine_workload']['general_workday_monday'] = ''
Setting['plugin_redmine_workload']['general_workday_tuesday'] = 'checked'
Setting['plugin_redmine_workload']['general_workday_wednesday'] = 'checked'
Setting['plugin_redmine_workload']['general_workday_thursday'] = 'checked'
Setting['plugin_redmine_workload']['general_workday_friday'] = 'checked'
Setting['plugin_redmine_workload']['general_workday_saturday'] = ''
Setting['plugin_redmine_workload']['general_workday_sunday'] = ''
# Set saturday, sunday and monday to be non-working days.
Setting.non_working_week_days = %w[1 6 7]

assert_equal Set.new([2, 3, 4, 5]), RedmineWorkload::WlDateTools.working_days
end

test 'working_days returns all days when Redmine has no non-working days.' do
Setting.non_working_week_days = []

assert_equal Set.new([1, 2, 3, 4, 5, 6, 7]), RedmineWorkload::WlDateTools.working_days
end

test 'getMonthsBetween returns [] if last day after first day' do
first_day = Date.new(2012, 3, 29)
last_day = Date.new(2012, 3, 28)
Expand Down
8 changes: 1 addition & 7 deletions test/unit/wl_national_holiday_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@ class WlNationalHolidayTest < ActiveSupport::TestCase

setup do
# reset default settings
Setting['plugin_redmine_workload']['general_workday_monday'] = 'checked'
Setting['plugin_redmine_workload']['general_workday_tuesday'] = 'checked'
Setting['plugin_redmine_workload']['general_workday_wednesday'] = 'checked'
Setting['plugin_redmine_workload']['general_workday_thursday'] = 'checked'
Setting['plugin_redmine_workload']['general_workday_friday'] = 'checked'
Setting['plugin_redmine_workload']['general_workday_saturday'] = ''
Setting['plugin_redmine_workload']['general_workday_sunday'] = ''
Setting.non_working_week_days = %w[6 7]
end

test 'single holiday' do
Expand Down
8 changes: 1 addition & 7 deletions test/unit/wl_user_vacation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@ class WlUserVacationTest < ActiveSupport::TestCase

setup do
# reset default settings
Setting['plugin_redmine_workload']['general_workday_monday'] = 'checked'
Setting['plugin_redmine_workload']['general_workday_tuesday'] = 'checked'
Setting['plugin_redmine_workload']['general_workday_wednesday'] = 'checked'
Setting['plugin_redmine_workload']['general_workday_thursday'] = 'checked'
Setting['plugin_redmine_workload']['general_workday_friday'] = 'checked'
Setting['plugin_redmine_workload']['general_workday_saturday'] = ''
Setting['plugin_redmine_workload']['general_workday_sunday'] = ''
Setting.non_working_week_days = %w[6 7]
end

test 'Vacation for user' do
Expand Down
Loading