OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Sync days_per_week and days_per_month on client side
Aaron Contrerasb600e762446b
diff --git a/app/contracts/settings/working_days_and_hours_params_contract.rb b/app/contracts/settings/working_days_and_hours_params_contract.rbindex 70adb482c7d..7ce38caaeaa 100644--- a/app/contracts/settings/working_days_and_hours_params_contract.rb+++ b/app/contracts/settings/working_days_and_hours_params_contract.rb@@ -32,7 +32,7 @@ module Settingsvalidate :working_days_are_presentvalidate :hours_per_day_are_present- validate :hours_per_week_are_present+ validate :days_per_week_are_presentvalidate :days_per_month_are_presentvalidate :unique_job@@ -50,9 +50,9 @@ module Settingsendend- def hours_per_week_are_present- if hours_per_week.blank?- errors.add :base, :hours_per_week_are_missing+ def days_per_week_are_present+ if days_per_week.blank?+ errors.add :base, :days_per_week_are_missingendend@@ -76,8 +76,8 @@ module Settingsparams[:hours_per_day]end- def hours_per_week- params[:hours_per_week]+ def days_per_week+ params[:days_per_week]enddef days_per_monthdiff --git a/app/controllers/admin/settings/working_days_and_hours_settings_controller.rb b/app/controllers/admin/settings/working_days_and_hours_settings_controller.rbindex f6b40d0f822..712395a1b14 100644--- a/app/controllers/admin/settings/working_days_and_hours_settings_controller.rb+++ b/app/controllers/admin/settings/working_days_and_hours_settings_controller.rb@@ -47,7 +47,7 @@ module Admin::Settingssettings[:working_days] = working_days_params(settings)settings[:non_working_days] = non_working_days_paramssettings[:hours_per_day] = params[:settings][:hours_per_day]- settings[:hours_per_week] = params[:settings][:hours_per_week]+ settings[:days_per_week] = params[:settings][:days_per_week]settings[:days_per_month] = params[:settings][:days_per_month]settingsenddiff --git a/app/services/settings/working_days_and_hours_update_service.rb b/app/services/settings/working_days_and_hours_update_service.rbindex 50f80557a3a..d3fe86a527b 100644--- a/app/services/settings/working_days_and_hours_update_service.rb+++ b/app/services/settings/working_days_and_hours_update_service.rb@@ -36,7 +36,6 @@ class Settings::WorkingDaysAndHoursUpdateService < Settings::UpdateServiceenddef validate_params(params)- binding.prycontract = Settings::WorkingDaysAndHoursParamsContract.new(model, user, params:)ServiceResult.new success: contract.valid?,errors: contract.errors,diff --git a/app/views/admin/settings/working_days_and_hours_settings/show.html.erb b/app/views/admin/settings/working_days_and_hours_settings/show.html.erbindex 8c77b003cf4..e0813489c5e 100644--- a/app/views/admin/settings/working_days_and_hours_settings/show.html.erb+++ b/app/views/admin/settings/working_days_and_hours_settings/show.html.erb@@ -35,7 +35,9 @@ See COPYRIGHT and LICENSE files for more details.class: 'op-working-days-admin-settings') do %>- <section class="form--section">+ <section class="form--section"+ data-application-target="dynamic"+ data-controller="admin--working-days-and-hours"><fieldset class="form--fieldset"><div class="form--field"><%= setting_text_field :hours_per_day,@@ -44,14 +46,18 @@ See COPYRIGHT and LICENSE files for more details.</div><div class="form--field">- <%= setting_text_field :hours_per_week,- type: :number %>- <div class="form--field-instructions"><%= t("setting_hours_per_week_explanation") %></div>+ <%= setting_text_field :days_per_week,+ type: :number,+ data: { admin__working_days_and_hours_target: 'daysPerWeekInput',+ action: 'blur->admin--working-days-and-hours#recalculateDaysPerMonth' } %>+ <div class="form--field-instructions"><%= t("setting_days_per_week_explanation") %></div></div><div class="form--field"><%= setting_text_field :days_per_month,- type: :number %>+ type: :number,+ data: { admin__working_days_and_hours_target: 'daysPerMonthInput',+ action: 'blur->admin--working-days-and-hours#recalculateDaysPerWeek' } %><div class="form--field-instructions"><%= t("setting_days_per_month_explanation") %></div></div>@@ -65,7 +71,7 @@ See COPYRIGHT and LICENSE files for more details.</p></div></div>-+<section class="form--section"><fieldset class="form--fieldset"><legend class="form--fieldset-legend"><%= t('settings.working_days.section_work_week') %></legend>diff --git a/config/constants/settings/definition.rb b/config/constants/settings/definition.rbindex e3f384d84ca..caf0b540561 100644--- a/config/constants/settings/definition.rb+++ b/config/constants/settings/definition.rb@@ -533,10 +533,10 @@ module Settingsdefault: 8,format: :integer},- hours_per_week: {+ days_per_week: {description: "This will define what is considered a “week” when displaying duration in a more natural way " \- "(for example, if a week is 40 hours, 1260 hours would be 7.5 weeks).",- default: 40,+ "(for example, if a week is 5 days, 15 days 3 weeks).",+ default: 5,format: :integer},# Health check configurationdiff --git a/config/locales/en.yml b/config/locales/en.ymlindex ece40dc3420..f2e5360153f 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -1018,7 +1018,7 @@ Project attributes and sections are defined in the <a href=%{admin_settings_url}working_days_are_missing: "At least one day of the week must be defined as a working day."previous_working_day_changes_unprocessed: "The previous changes to the working days configuration have not been applied yet."hours_per_day_are_missing: "The number of hours per day must be defined."- hours_per_week_are_missing: "The number of hours per week must be defined."+ days_per_week_are_missing: "The number of days per week must be defined."days_per_month_are_missing: "The number of days per month must be defined."time_entry:attributes:@@ -3078,7 +3078,8 @@ Project attributes and sections are defined in the <a href=%{admin_settings_url}setting_first_week_of_year: "First week in year contains"setting_date_format: "Date"setting_days_per_month: "Days per month"- setting_days_per_month_explanation: "This will define what is considered a “week” when displaying duration in a more natural way (for example, if a month is 20 days, 60 days would be 3 months."+ setting_days_per_month_explanation: >+ This will define what is considered a "week" when displaying duration in a more natural way (for example, if a month is 20 days, 60 days would be 3 months.setting_default_language: "Default language"setting_default_projects_modules: "Default enabled modules for new projects"setting_default_projects_public: "New projects are public by default"@@ -3096,10 +3097,10 @@ Project attributes and sections are defined in the <a href=%{admin_settings_url}setting_host_name: "Host name"setting_hours_per_day: "Hours per day"setting_hours_per_day_explanation: >- This will define what is considered a “day” when displaying duration in a more natural way (for example, if a day is 8 hours, 32 hours would be 4 days).- setting_hours_per_week: "Hours per week"- setting_hours_per_week_explanation: >- This will define what is considered a “week” when displaying duration in a more natural way (for example, if a week is 40 hours, 1260 hours would be 7.5 weeks).+ This will define what is considered a "day" when displaying duration in a more natural way (for example, if a day is 8 hours, 32 hours would be 4 days).+ setting_days_per_week: "Days per week"+ setting_days_per_week_explanation: >+ This will define what is considered a "week" when displaying duration in a more natural way (for example, if a week is 5 days, 15 days 3 weeks).setting_invitation_expiration_days: "Activation email expires after"setting_work_package_done_ratio: "Progress calculation"setting_work_package_done_ratio_field: "Work-based"diff --git a/frontend/src/stimulus/controllers/dynamic/admin/working-days-and-hours.controller.ts b/frontend/src/stimulus/controllers/dynamic/admin/working-days-and-hours.controller.tsnew file mode 100644index 00000000000..69298a5fe7a--- /dev/null+++ b/frontend/src/stimulus/controllers/dynamic/admin/working-days-and-hours.controller.ts@@ -0,0 +1,58 @@+/*+ * -- copyright+ * OpenProject is an open source project management software.+ * Copyright (C) 2023 the OpenProject GmbH+ *+ * This program is free software; you can redistribute it and/or+ * modify it under the terms of the GNU General Public License version 3.+ *+ * OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+ * Copyright (C) 2006-2013 Jean-Philippe Lang+ * Copyright (C) 2010-2013 the ChiliProject Team+ *+ * This program is free software; you can redistribute it and/or+ * modify it under the terms of the GNU General Public License+ * as published by the Free Software Foundation; either version 2+ * of the License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU General Public License for more details.+ *+ * You should have received a copy of the GNU General Public License+ * along with this program; if not, write to the Free Software+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+ *+ * See COPYRIGHT and LICENSE files for more details.+ * +++ */++import { Controller } from '@hotwired/stimulus';++/*+ * Helps keep daysPerWeek and daysPerMonth in-line with each other+ */+export default class WorkingDaysAndHoursController extends Controller {+ static targets = [+ 'daysPerWeekInput',+ 'daysPerMonthInput',+ ];++ declare readonly daysPerWeekInputTarget:HTMLInputElement;+ declare readonly daysPerMonthInputTarget:HTMLInputElement;++ connect() {}++ recalculateDaysPerWeek() {+ const daysPerMonth = parseFloat(this.daysPerMonthInputTarget.value);+ const daysPerWeek = daysPerMonth / 4;+ this.daysPerWeekInputTarget.value = daysPerWeek.toString();+ }++ recalculateDaysPerMonth() {+ const daysPerWeek = parseFloat(this.daysPerWeekInputTarget.value);+ const daysPerMonth = daysPerWeek * 4;+ this.daysPerMonthInputTarget.value = daysPerMonth.toString();+ }+}diff --git a/lib/api/v3/configuration/configuration_representer.rb b/lib/api/v3/configuration/configuration_representer.rbindex f4a9d703745..b10f31f8c55 100644--- a/lib/api/v3/configuration/configuration_representer.rb+++ b/lib/api/v3/configuration/configuration_representer.rb@@ -79,7 +79,7 @@ module APIproperty :hours_per_day,render_nil: true- property :hours_per_week,+ property :days_per_week,render_nil: trueproperty :days_per_month,diff --git a/spec/controllers/admin/settings/working_days_and_hours_settings_controller_spec.rb b/spec/controllers/admin/settings/working_days_and_hours_settings_controller_spec.rbindex baca0292526..38e753137e9 100644--- a/spec/controllers/admin/settings/working_days_and_hours_settings_controller_spec.rb+++ b/spec/controllers/admin/settings/working_days_and_hours_settings_controller_spec.rb@@ -39,10 +39,10 @@ RSpec.describe Admin::Settings::WorkingDaysAndHoursSettingsController dolet(:working_days) { [*"1".."7"] }let(:non_working_days_attributes) { {} }let(:hours_per_day) { 4 }- let(:hours_per_week) { 16 }- let(:days_per_month) { 25 }+ let(:days_per_week) { 5 }+ let(:days_per_month) { 20 }let(:params) do- { settings: { working_days:, non_working_days_attributes:, hours_per_day:, hours_per_week:, days_per_month: } }+ { settings: { working_days:, non_working_days_attributes:, hours_per_day:, days_per_week:, days_per_month: } }endsubject { patch "update", params: }