Skip to content

Commit 031c3ce

Browse files
authored
[73372] Wrong icon used when changing non working days (#23292)
* Create a new dialog component for non-working days * Change the non-working days component * Add feature spec * Fix reload after canceling the action * preserve submitted form data for confirmation, and simplify cancel handling * Change header text * Remove the typescript unnecessary codes and listening to a form submit and call update on confirm changes
1 parent bfa2588 commit 031c3ce

10 files changed

Lines changed: 253 additions & 122 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<%=
2+
render(
3+
Primer::OpenProject::DangerDialog.new(
4+
id: DIALOG_ID,
5+
title: t("working_days.dialog.title"),
6+
confirm_button_text: t("working_days.dialog.confirm_button"),
7+
form_arguments:,
8+
size: :medium_portrait
9+
)
10+
) do |dialog|
11+
dialog.with_confirmation_message do |message|
12+
message.with_heading(tag: :h2) { t("working_days.dialog.heading") }
13+
message.with_description_content(t("working_days.dialog.description"))
14+
end
15+
16+
dialog.with_additional_details do
17+
concat hidden_settings_fields
18+
concat(
19+
tag.div do
20+
if removed_non_working_days.any?
21+
concat tag.p(t("working_days.dialog.removed_title"))
22+
concat(
23+
render(
24+
Primer::BaseComponent.new(
25+
tag: :ul,
26+
mb: 3
27+
)
28+
) do
29+
safe_join(removed_non_working_days.map { |non_working_day| tag.li(non_working_day) })
30+
end
31+
)
32+
end
33+
34+
concat tag.p(t("working_days.dialog.warning"))
35+
end
36+
)
37+
end
38+
end
39+
%>
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# frozen_string_literal: true
2+
3+
#-- copyright
4+
# OpenProject is an open source project management software.
5+
# Copyright (C) the OpenProject GmbH
6+
#
7+
# This program is free software; you can redistribute it and/or
8+
# modify it under the terms of the GNU General Public License version 3.
9+
#
10+
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
11+
# Copyright (C) 2006-2013 Jean-Philippe Lang
12+
# Copyright (C) 2010-2013 the ChiliProject Team
13+
#
14+
# This program is free software; you can redistribute it and/or
15+
# modify it under the terms of the GNU General Public License
16+
# as published by the Free Software Foundation; either version 2
17+
# of the License, or (at your option) any later version.
18+
#
19+
# This program is distributed in the hope that it will be useful,
20+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22+
# GNU General Public License for more details.
23+
#
24+
# You should have received a copy of the GNU General Public License
25+
# along with this program; if not, write to the Free Software
26+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27+
#
28+
# See COPYRIGHT and LICENSE files for more details.
29+
#++
30+
31+
module Admin
32+
module Settings
33+
module WorkingDays
34+
class ConfirmDialogComponent < ApplicationComponent
35+
include OpTurbo::Streamable
36+
37+
DIALOG_ID = "working-days-change-dialog"
38+
39+
attr_reader :form_values, :removed_non_working_days
40+
41+
def initialize(form_values: {}, removed_non_working_days: [])
42+
super
43+
@form_values = form_values
44+
@removed_non_working_days = removed_non_working_days
45+
end
46+
47+
private
48+
49+
def form_arguments
50+
{
51+
action: helpers.admin_settings_working_days_and_hours_path,
52+
method: :patch,
53+
data: { turbo: false }
54+
}
55+
end
56+
57+
def hidden_settings_fields
58+
hidden_field_tags_for("settings", form_values)
59+
end
60+
61+
def hidden_field_tags_for(name, value)
62+
case value
63+
when Hash
64+
safe_join(
65+
value.flat_map do |key, nested_value|
66+
hidden_field_tags_for("#{name}[#{key}]", nested_value)
67+
end
68+
)
69+
when Array
70+
safe_join(value.map { |array_value| hidden_field_tag("#{name}[]", array_value) })
71+
else
72+
hidden_field_tag(name, value)
73+
end
74+
end
75+
end
76+
end
77+
end
78+
end

app/controllers/admin/settings/working_days_and_hours_settings_controller.rb

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,25 @@
3030

3131
module Admin::Settings
3232
class WorkingDaysAndHoursSettingsController < ::Admin::SettingsController
33+
include OpTurbo::ComponentStream
34+
3335
menu_item :working_days_and_hours
3436

37+
def confirm_changes
38+
return update unless working_days_changed? || non_working_days_changed?
39+
40+
removed_days = non_working_days_params
41+
.select { |nwd| nwd["_destroy"].present? }
42+
.filter_map { |nwd| removed_non_working_day_date(nwd) }
43+
44+
component = Admin::Settings::WorkingDays::ConfirmDialogComponent.new(
45+
form_values: params.expect(settings: {}).to_h,
46+
removed_non_working_days: removed_days
47+
)
48+
49+
respond_with_dialog(component)
50+
end
51+
3552
def failure_callback(call)
3653
@modified_non_working_days = modified_non_working_days_for(call.result)
3754
flash[:error] = call.message || I18n.t(:notice_internal_server_error)
@@ -53,15 +70,31 @@ def update_service
5370

5471
private
5572

73+
def working_days_changed?
74+
working_days_params(params.expect(settings: {})) != Setting.working_days.map(&:to_i)
75+
end
76+
77+
def non_working_days_changed?
78+
non_working_days_params.any?
79+
end
80+
5681
def working_days_params(settings)
5782
settings[:working_days] ? settings[:working_days].compact_blank.map(&:to_i).uniq : []
5883
end
5984

6085
def non_working_days_params
61-
non_working_days = params[:settings].to_unsafe_hash[:non_working_days_attributes] || {}
86+
non_working_days = params.expect(settings: {})[:non_working_days_attributes] || {}
6287
non_working_days.to_h.values
6388
end
6489

90+
def removed_non_working_day_date(non_working_day_params)
91+
date = NonWorkingDay.find_by(id: non_working_day_params["id"])&.date || non_working_day_params["date"]
92+
93+
I18n.l(date.to_date, format: :long)
94+
rescue Date::Error, NoMethodError
95+
nil
96+
end
97+
6598
def modified_non_working_days_for(result)
6699
return if result.nil?
67100

app/views/admin/settings/working_days_and_hours_settings/show.html.erb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ See COPYRIGHT and LICENSE files for more details.
4141
%>
4242

4343
<%= styled_form_tag(
44-
admin_settings_working_days_and_hours_path,
45-
method: :patch,
46-
class: "op-working-days-admin-settings"
44+
confirm_changes_admin_settings_working_days_and_hours_path,
45+
class: "op-working-days-admin-settings",
46+
data: { turbo_stream: true }
4747
) do %>
4848

4949
<section class="form--section">

config/locales/en.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6201,6 +6201,17 @@ en:
62016201
warning: >
62026202
Changing which days of the week are considered working days or non-working days
62036203
can affect the start and finish days of all work packages and life cycles in all projects in this instance.
6204+
dialog:
6205+
title: "Change working days"
6206+
description: >
6207+
Changing which days of the week are considered working days or non-working days
6208+
can affect the start and finish days of all work packages and life cycles in all projects in this instance.
6209+
removed_title: "You will remove the following days from the non-working days list:"
6210+
warning: >
6211+
The changes might take some time to take effect. You will be notified when all relevant work
6212+
packages and project life cycles have been updated.
6213+
heading: "Change the working days?"
6214+
confirm_button: "Save and reschedule"
62046215
journal_note:
62056216
changed: _**Working days** changed (%{changes})._
62066217
days:

config/locales/js-en.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -228,15 +228,6 @@ en:
228228
new_date: "(new)"
229229
add_non_working_day: "Non-working day"
230230
already_added_error: "A non-working day for this date exists already. There can only be one non-working day created for each unique date."
231-
change_button: "Save and reschedule"
232-
change_title: "Change working days"
233-
removed_title: "You will remove the following days from the non-working days list:"
234-
change_description: "Changing which days of the week are considered working days or non-working days can affect the start and finish days of all work packages and life cycles in all projects in this instance."
235-
warning: >
236-
The changes might take some time to take effect. You will be notified when all relevant work packages and project life cycles have been updated.
237-
238-
239-
Are you sure you want to continue?
240231

241232
work_packages_settings:
242233
warning_progress_calculation_mode_change_from_status_to_field_html: >-

config/routes.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,9 @@
750750
get :new_link
751751
end
752752
end
753-
resource :working_days_and_hours, controller: "/admin/settings/working_days_and_hours_settings", only: %i[show update]
753+
resource :working_days_and_hours, controller: "/admin/settings/working_days_and_hours_settings", only: %i[show update] do
754+
post :confirm_changes
755+
end
754756
resource :users, controller: "/admin/settings/users_settings", only: %i[show update]
755757
resource :date_format, controller: "/admin/settings/date_format_settings", only: %i[show update]
756758
resource :icalendar, controller: "/admin/settings/icalendar_settings", only: %i[show update]

0 commit comments

Comments
 (0)