Skip to content

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

[43549] Fix duration field for remainingTime

Oliver Güntheradcd28e9290e
diff --git a/frontend/src/app/shared/components/fields/display/display-field.initializer.ts b/frontend/src/app/shared/components/fields/display/display-field.initializer.ts
index 86fc42442d8..05ef0b16e34 100644
--- a/frontend/src/app/shared/components/fields/display/display-field.initializer.ts
+++ b/frontend/src/app/shared/components/fields/display/display-field.initializer.ts
@@ -50,7 +50,8 @@ import { PlainFormattableDisplayField } from 'core-app/shared/components/fields/
import { LinkedWorkPackageDisplayField } from 'core-app/shared/components/fields/display/field-types/linked-work-package-display-field.module';
import { CombinedDateDisplayField } from 'core-app/shared/components/fields/display/field-types/combined-date-display.field';
import { EstimatedTimeDisplayField } from 'core-app/shared/components/fields/display/field-types/estimated-time-display-field.module';
-import { DurationDisplayField } from 'core-app/shared/components/fields/display/field-types/duration-display-field.module';
+import { DaysDurationDisplayField } from 'core-app/shared/components/fields/display/field-types/days-duration-display-field.module';
+import { HoursDurationDisplayField } from 'core-app/shared/components/fields/display/field-types/hours-duration-display-field.module';
export function initializeCoreDisplayFields(displayFieldService:DisplayFieldService) {
return () => {
@@ -73,7 +74,7 @@ export function initializeCoreDisplayFields(displayFieldService:DisplayFieldServ
.addFieldType(ResourcesDisplayField, 'resources', ['[]CustomOption'])
.addFieldType(MultipleUserFieldModule, 'users', ['[]User'])
.addFieldType(FormattableDisplayField, 'formattable', ['Formattable'])
- .addFieldType(DurationDisplayField, 'duration', ['duration'])
+ .addFieldType(DaysDurationDisplayField, 'duration', ['duration'])
.addFieldType(EstimatedTimeDisplayField, 'estimatedTime', ['estimatedTime'])
.addFieldType(DateDisplayField, 'date', ['Date'])
.addFieldType(DateTimeDisplayField, 'datetime', ['DateTime'])
@@ -87,6 +88,7 @@ export function initializeCoreDisplayFields(displayFieldService:DisplayFieldServ
.addSpecificFieldType('WorkPackage', WorkPackageIdDisplayField, 'id', ['id'])
.addSpecificFieldType('WorkPackage', WorkPackageSpentTimeDisplayField, 'spentTime', ['spentTime'])
.addSpecificFieldType('WorkPackage', CombinedDateDisplayField, 'combinedDate', ['combinedDate'])
+ .addSpecificFieldType('WorkPackage', HoursDurationDisplayField, 'remainingTime', ['remainingTime'])
.addSpecificFieldType('TimeEntry', PlainFormattableDisplayField, 'comment', ['comment'])
.addSpecificFieldType('Project', ProjectStatusDisplayField, 'status', ['status'])
.addSpecificFieldType('TimeEntry', WorkPackageDisplayField, 'work_package', ['workPackage']);
diff --git a/frontend/src/app/shared/components/fields/display/field-types/duration-display-field.module.ts b/frontend/src/app/shared/components/fields/display/field-types/days-duration-display-field.module.ts
similarity index 96%
rename from frontend/src/app/shared/components/fields/display/field-types/duration-display-field.module.ts
rename to frontend/src/app/shared/components/fields/display/field-types/days-duration-display-field.module.ts
index b4aff6fb87d..2705e7542ae 100644
--- a/frontend/src/app/shared/components/fields/display/field-types/duration-display-field.module.ts
+++ b/frontend/src/app/shared/components/fields/display/field-types/days-duration-display-field.module.ts
@@ -30,7 +30,7 @@ import { DisplayField } from 'core-app/shared/components/fields/display/display-
import { InjectField } from 'core-app/shared/helpers/angular/inject-field.decorator';
import { TimezoneService } from 'core-app/core/datetime/timezone.service';
-export class DurationDisplayField extends DisplayField {
+export class DaysDurationDisplayField extends DisplayField {
@InjectField() timezoneService:TimezoneService;
public get valueString() {
diff --git a/frontend/src/app/shared/components/fields/display/field-types/hours-duration-display-field.module.ts b/frontend/src/app/shared/components/fields/display/field-types/hours-duration-display-field.module.ts
new file mode 100644
index 00000000000..b341e39eb47
--- /dev/null
+++ b/frontend/src/app/shared/components/fields/display/field-types/hours-duration-display-field.module.ts
@@ -0,0 +1,39 @@
+// -- copyright
+// OpenProject is an open source project management software.
+// Copyright (C) 2012-2022 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 { DisplayField } from 'core-app/shared/components/fields/display/display-field.module';
+import { InjectField } from 'core-app/shared/helpers/angular/inject-field.decorator';
+import { TimezoneService } from 'core-app/core/datetime/timezone.service';
+
+export class HoursDurationDisplayField extends DisplayField {
+ @InjectField() timezoneService:TimezoneService;
+
+ public get valueString() {
+ return this.timezoneService.formattedDuration(this.value, 'hour');
+ }
+}
diff --git a/frontend/src/app/shared/components/fields/edit/edit-field.initializer.ts b/frontend/src/app/shared/components/fields/edit/edit-field.initializer.ts
index b746fb1088d..8461e4ebd6b 100644
--- a/frontend/src/app/shared/components/fields/edit/edit-field.initializer.ts
+++ b/frontend/src/app/shared/components/fields/edit/edit-field.initializer.ts
@@ -84,7 +84,7 @@ export function initializeCoreEditFields(editFieldService:EditFieldService, sele
.addSpecificFieldType('Project', ProjectStatusEditFieldComponent, 'status', ['status'])
.addSpecificFieldType('TimeEntry', PlainFormattableEditFieldComponent, 'comment', ['comment'])
.addSpecificFieldType('TimeEntry', TimeEntryWorkPackageEditFieldComponent, 'workPackage', ['WorkPackage'])
- .addSpecificFieldType('TimeEntry', HoursDurationEditFieldComponent, 'hours', ['hours']);
+ .addSpecificFieldType('WorkPackage', HoursDurationEditFieldComponent, 'remainingTime', ['remainingTime']);
selectAutocompleterRegisterService.register(VersionAutocompleterComponent, 'Version');
selectAutocompleterRegisterService.register(WorkPackageAutocompleterComponent, 'WorkPackage');
diff --git a/modules/backlogs/spec/features/work_packages/remaining_time_spec.rb b/modules/backlogs/spec/features/work_packages/remaining_time_spec.rb
new file mode 100644
index 00000000000..f5f05da2fa1
--- /dev/null
+++ b/modules/backlogs/spec/features/work_packages/remaining_time_spec.rb
@@ -0,0 +1,74 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2022 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.
+#++
+
+require 'spec_helper'
+
+describe 'Work packages remaining time', type: :feature, js: true do
+ before do
+ allow(User).to receive(:current).and_return current_user
+ allow(Setting).to receive(:plugin_openproject_backlogs).and_return('points_burn_direction' => 'down',
+ 'wiki_template' => '',
+ 'card_spec' => 'Sattleford VM-5040',
+ 'story_types' => [story_type.id.to_s],
+ 'task_type' => task_type.id.to_s)
+ end
+
+ let(:current_user) { create(:admin) }
+ let(:project) do
+ create(:project,
+ enabled_module_names: %w(work_package_tracking backlogs))
+ end
+ let(:status) { create :default_status }
+ let(:story_type) { create(:type_feature) }
+ let(:task_type) { create(:type_feature) }
+
+ let(:work_package) do
+ create :story,
+ type: task_type,
+ author: current_user,
+ project:,
+ status:
+ end
+
+ it 'is can set and edit the remaining time in hours (Regression #43549)' do
+ wp_page = Pages::FullWorkPackage.new(work_package)
+
+ wp_page.visit!
+ wp_page.expect_subject
+
+ wp_page.expect_attributes remainingTime: '-'
+
+ wp_page.update_attributes remainingTime: '125' # rubocop:disable Rails/ActiveRecordAliases
+
+ wp_page.expect_attributes remainingTime: '125'
+
+ work_package.reload
+
+ expect(work_package.remaining_hours).to eq 125.0
+ end
+end