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
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<%=
render(
Primer::OpenProject::DangerDialog.new(
id: DIALOG_ID,
title: t("working_days.dialog.title"),
Comment thread
bsatarnejad marked this conversation as resolved.
confirm_button_text: t("working_days.dialog.confirm_button"),
form_arguments:,
size: :medium_portrait
)
) do |dialog|
dialog.with_confirmation_message do |message|
message.with_heading(tag: :h2) { t("working_days.dialog.heading") }
message.with_description_content(t("working_days.dialog.description"))
end

dialog.with_additional_details do
concat hidden_settings_fields
concat(
tag.div do
if removed_non_working_days.any?
concat tag.p(t("working_days.dialog.removed_title"))
concat(
render(
Primer::BaseComponent.new(
tag: :ul,
mb: 3
)
) do
safe_join(removed_non_working_days.map { |non_working_day| tag.li(non_working_day) })
end
)
end

concat tag.p(t("working_days.dialog.warning"))
end
)
end
end
%>
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# frozen_string_literal: true

#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 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.
#++

module Admin
module Settings
module WorkingDays
class ConfirmDialogComponent < ApplicationComponent
include OpTurbo::Streamable

DIALOG_ID = "working-days-change-dialog"

attr_reader :form_values, :removed_non_working_days

def initialize(form_values: {}, removed_non_working_days: [])
super
@form_values = form_values
@removed_non_working_days = removed_non_working_days
end

private

def form_arguments
{
action: helpers.admin_settings_working_days_and_hours_path,
method: :patch,
data: { turbo: false }
}
end

def hidden_settings_fields
hidden_field_tags_for("settings", form_values)
end

def hidden_field_tags_for(name, value)
case value
when Hash
safe_join(
value.flat_map do |key, nested_value|
hidden_field_tags_for("#{name}[#{key}]", nested_value)
end
)
when Array
safe_join(value.map { |array_value| hidden_field_tag("#{name}[]", array_value) })
else
hidden_field_tag(name, value)
end
end
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,25 @@

module Admin::Settings
class WorkingDaysAndHoursSettingsController < ::Admin::SettingsController
include OpTurbo::ComponentStream

menu_item :working_days_and_hours

def confirm_changes
return update unless working_days_changed? || non_working_days_changed?

removed_days = non_working_days_params
.select { |nwd| nwd["_destroy"].present? }
.filter_map { |nwd| removed_non_working_day_date(nwd) }

component = Admin::Settings::WorkingDays::ConfirmDialogComponent.new(
form_values: params.expect(settings: {}).to_h,
removed_non_working_days: removed_days
)

respond_with_dialog(component)
end

def failure_callback(call)
@modified_non_working_days = modified_non_working_days_for(call.result)
flash[:error] = call.message || I18n.t(:notice_internal_server_error)
Expand All @@ -53,15 +70,31 @@ def update_service

private

def working_days_changed?
working_days_params(params.expect(settings: {})) != Setting.working_days.map(&:to_i)
end

def non_working_days_changed?
non_working_days_params.any?
end

def working_days_params(settings)
settings[:working_days] ? settings[:working_days].compact_blank.map(&:to_i).uniq : []
end

def non_working_days_params
non_working_days = params[:settings].to_unsafe_hash[:non_working_days_attributes] || {}
non_working_days = params.expect(settings: {})[:non_working_days_attributes] || {}
non_working_days.to_h.values
end

def removed_non_working_day_date(non_working_day_params)
date = NonWorkingDay.find_by(id: non_working_day_params["id"])&.date || non_working_day_params["date"]

I18n.l(date.to_date, format: :long)
rescue Date::Error, NoMethodError
nil
end

def modified_non_working_days_for(result)
return if result.nil?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ See COPYRIGHT and LICENSE files for more details.
%>

<%= styled_form_tag(
admin_settings_working_days_and_hours_path,
method: :patch,
class: "op-working-days-admin-settings"
confirm_changes_admin_settings_working_days_and_hours_path,
class: "op-working-days-admin-settings",
data: { turbo_stream: true }
) do %>

<section class="form--section">
Expand Down
11 changes: 11 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6161,6 +6161,17 @@ en:
warning: >
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.
dialog:
title: "Change working days"
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.
removed_title: "You will remove the following days from the non-working days list:"
warning: >
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.
heading: "Change the working days?"
confirm_button: "Save and reschedule"
journal_note:
changed: _**Working days** changed (%{changes})._
days:
Expand Down
9 changes: 0 additions & 9 deletions config/locales/js-en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,6 @@ en:
new_date: "(new)"
add_non_working_day: "Non-working day"
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."
change_button: "Save and reschedule"
change_title: "Change working days"
removed_title: "You will remove the following days from the non-working days list:"
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."
warning: >
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.


Are you sure you want to continue?

work_packages_settings:
warning_progress_calculation_mode_change_from_status_to_field_html: >-
Expand Down
4 changes: 3 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,9 @@
get :new_link
end
end
resource :working_days_and_hours, controller: "/admin/settings/working_days_and_hours_settings", only: %i[show update]
resource :working_days_and_hours, controller: "/admin/settings/working_days_and_hours_settings", only: %i[show update] do
post :confirm_changes
end
resource :users, controller: "/admin/settings/users_settings", only: %i[show update]
resource :date_format, controller: "/admin/settings/date_format_settings", only: %i[show update]
resource :icalendar, controller: "/admin/settings/icalendar_settings", only: %i[show update]
Expand Down
Loading
Loading