From 7356ddfcf380a865c7a192334e5512e9610f502a Mon Sep 17 00:00:00 2001 From: Christophe Bliard Date: Wed, 5 Jun 2024 16:55:02 +0200 Subject: [PATCH 1/2] [55467] Warn about potential data loss when changing progress modes https://community.openproject.org/wp/55467 --- .../work_packages_settings/show.html.erb | 17 ++++- .../show.html.erb | 3 +- config/locales/js-en.yml | 13 ++++ .../work-packages-settings.controller.ts | 69 +++++++++++++++++++ .../controllers/op-application.controller.ts | 2 +- 5 files changed, 99 insertions(+), 5 deletions(-) create mode 100644 frontend/src/stimulus/controllers/dynamic/admin/work-packages-settings.controller.ts diff --git a/app/views/admin/settings/work_packages_settings/show.html.erb b/app/views/admin/settings/work_packages_settings/show.html.erb index 0151e41e51fa..dd76fbf955a4 100644 --- a/app/views/admin/settings/work_packages_settings/show.html.erb +++ b/app/views/admin/settings/work_packages_settings/show.html.erb @@ -32,16 +32,29 @@ See COPYRIGHT and LICENSE files for more details. <%= toolbar title: t(:label_work_package_tracking) %> <%= styled_form_tag({ action: :update }, method: :patch) do %> -
+
<%= setting_check_box :cross_project_work_package_relations %>
<%= setting_check_box :display_subprojects_work_packages %>
<%= setting_check_box :work_package_startdate_is_adddate %>
<%= setting_select :work_package_done_ratio, WorkPackage::DONE_RATIO_OPTIONS.collect { |i| [t("setting_work_package_done_ratio_#{i}"), i] }, - container_class: "-middle" %> + container_class: "-middle", + data: { admin__work_packages_settings_target: "progressCalculationModeSelect", + action: "change->admin--work-packages-settings#displayWarning" } %>
<%= t("setting_work_package_done_ratio_explanation_html") %>
+
<%= setting_select(:work_package_list_default_highlighting_mode, Query::Highlighting::QUERY_HIGHLIGHTING_MODES.map do |mode| 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.erb index 29bf4690feb8..26e2c8552c95 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 @@ -70,14 +70,13 @@ See COPYRIGHT and LICENSE files for more details.
<%= t('settings.working_days.section_work_week') %> -
+

<%= t("working_days.warning") %>

-

<%= t("working_days.info") %>

diff --git a/config/locales/js-en.yml b/config/locales/js-en.yml index a5cd566e1bd7..bc65a24cc3ac 100644 --- a/config/locales/js-en.yml +++ b/config/locales/js-en.yml @@ -303,6 +303,19 @@ en: Are you sure you want to continue? + + work_packages_settings: + warning_progress_calculation_mode_change_from_status_to_field_html: >- + Changing progress calculation mode from status-based to work-based will make + % Complete a non-editable field whose value is derived from Work + and Remaining work. Existing values for % Complete are preserved. + If values for Work and Remaining work were not present, they + will be required in order to change % Complete. + warning_progress_calculation_mode_change_from_field_to_status_html: >- + Changing progress calculation mode from work-based to status-based will result + in all existing % Complete values to be lost and replaced with values + associated with each status. Existing values for Remaining work may + also be recalculated to reflect this change. This action is not reversible. custom_actions: date: specific: "on" diff --git a/frontend/src/stimulus/controllers/dynamic/admin/work-packages-settings.controller.ts b/frontend/src/stimulus/controllers/dynamic/admin/work-packages-settings.controller.ts new file mode 100644 index 000000000000..f805ff85473a --- /dev/null +++ b/frontend/src/stimulus/controllers/dynamic/admin/work-packages-settings.controller.ts @@ -0,0 +1,69 @@ +/* + * -- 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 WorkPackagesSettingsController extends Controller { + static targets = [ + 'progressCalculationModeSelect', + 'warningText', + 'warningToast', + ]; + + declare readonly progressCalculationModeSelectTarget:HTMLSelectElement; + declare readonly warningTextTarget:HTMLElement; + declare readonly warningToastTarget:HTMLElement; + private initialMode:string; + + connect() { + this.initialMode = this.progressCalculationModeSelectTarget.value; + } + + displayWarning() { + const warningMessageHtml = this.getWarningMessageHtml(); + if (warningMessageHtml) { + this.warningTextTarget.innerHTML = warningMessageHtml; + this.warningToastTarget.hidden = false; + } else { + this.warningToastTarget.hidden = true; + } + } + + getWarningMessageHtml():string { + const newMode = this.progressCalculationModeSelectTarget.value; + return I18n.t( + `js.admin.work_packages_settings.warning_progress_calculation_mode_change_from_${this.initialMode}_to_${newMode}_html`, + { defaultValue: '' }, + ); + } +} diff --git a/frontend/src/stimulus/controllers/op-application.controller.ts b/frontend/src/stimulus/controllers/op-application.controller.ts index 375065e3e901..e1234cc820e9 100644 --- a/frontend/src/stimulus/controllers/op-application.controller.ts +++ b/frontend/src/stimulus/controllers/op-application.controller.ts @@ -26,7 +26,7 @@ export class OpApplicationController extends ApplicationController { /** * Derive dynamic path from controller name. * - * Stimlus conventions allow subdirectories to be used by double dashes. + * Stimulus conventions allow subdirectories to be used by double dashes. * We convert these to slashes for the dynamic import. * * https://stimulus.hotwired.dev/handbook/installing#controller-filenames-map-to-identifiers From 55321b0c681d9f0c3957db3607f53210f3e4d9de Mon Sep 17 00:00:00 2001 From: Christophe Bliard Date: Wed, 5 Jun 2024 18:12:50 +0200 Subject: [PATCH 2/2] Remove test text --- app/views/admin/settings/work_packages_settings/show.html.erb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/views/admin/settings/work_packages_settings/show.html.erb b/app/views/admin/settings/work_packages_settings/show.html.erb index dd76fbf955a4..9c8031bba8e6 100644 --- a/app/views/admin/settings/work_packages_settings/show.html.erb +++ b/app/views/admin/settings/work_packages_settings/show.html.erb @@ -50,9 +50,7 @@ See COPYRIGHT and LICENSE files for more details. hidden data-admin--work-packages-settings-target="warningToast">
-

- Changing progress calculation mode from work-based is dangerous! Take this! -

+