Skip to content

Commit

Permalink
Merge pull request #15760 from opf/feature/55467-warn-admins-about-po…
Browse files Browse the repository at this point in the history
…tential-data-loss-when-changing-progress-calculation-modes

[55467] Warn about potential data loss when changing progress modes
  • Loading branch information
dombesz authored Jun 5, 2024
2 parents e102faf + 55321b0 commit d4d23e7
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 5 deletions.
15 changes: 13 additions & 2 deletions app/views/admin/settings/work_packages_settings/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,27 @@ See COPYRIGHT and LICENSE files for more details.
<%= toolbar title: t(:label_work_package_tracking) %>

<%= styled_form_tag({ action: :update }, method: :patch) do %>
<section class="form--section">
<section class="form--section"
data-application-target="dynamic"
data-controller="admin--work-packages-settings">
<div class="form--field"><%= setting_check_box :cross_project_work_package_relations %></div>
<div class="form--field"><%= setting_check_box :display_subprojects_work_packages %></div>
<div class="form--field"><%= setting_check_box :work_package_startdate_is_adddate %></div>
<div class="form--field">
<%= 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" } %>
<div class="form--field-instructions"><%= t("setting_work_package_done_ratio_explanation_html") %></div>
</div>
<div class="op-toast -warning -with-bottom-spacing"
hidden
data-admin--work-packages-settings-target="warningToast">
<div class="op-toast--content">
<p data-admin--work-packages-settings-target="warningText"></p>
</div>
</div>
<div class="form--field settings--highlighting-mode">
<%= setting_select(:work_package_list_default_highlighting_mode,
Query::Highlighting::QUERY_HIGHLIGHTING_MODES.map do |mode|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,13 @@ See COPYRIGHT and LICENSE files for more details.
<section class="form--section">
<fieldset class="form--fieldset">
<legend class="form--fieldset-legend"><%= t('settings.working_days.section_work_week') %></legend>
<div class="op-toast -warning">
<div class="op-toast -warning -with-bottom-spacing">
<div class="op-toast--content">
<p>
<%= t("working_days.warning") %>
</p>
</div>
</div>
<p>
<p>
<%= t("working_days.info") %>
</p>
Expand Down
13 changes: 13 additions & 0 deletions config/locales/js-en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
<i>% Complete</i> a non-editable field whose value is derived from <i>Work</i>
and <i>Remaining work</i>. Existing values for <i>% Complete</i> are preserved.
If values for <i>Work</i> and <i>Remaining work</i> were not present, they
will be required in order to change <i>% Complete</i>.
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 <i>% Complete</i> values to be lost and replaced with values
associated with each status. Existing values for <i>Remaining work</i> may
also be recalculated to reflect this change. This action is not reversible.
custom_actions:
date:
specific: "on"
Expand Down
Original file line number Diff line number Diff line change
@@ -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: '' },
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d4d23e7

Please sign in to comment.