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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Add duration display field with days display
Oliver Günther8ff6aee75118
diff --git a/config/locales/js-en.yml b/config/locales/js-en.ymlindex fa094452bdb..58ed199c38b 100644--- a/config/locales/js-en.yml+++ b/config/locales/js-en.yml@@ -1179,6 +1179,10 @@ en:one: "1 h"other: "%{count} h"zero: "0 h"+ day:+ one: "1 day"+ other: "%{count} days"+ zero: "0 days"zen_mode:button_activate: 'Activate zen mode'button_deactivate: 'Deactivate zen mode'diff --git a/frontend/.eslintrc.js b/frontend/.eslintrc.jsindex 2bc6b9dc2ed..1a210dc2ebc 100644--- a/frontend/.eslintrc.js+++ b/frontend/.eslintrc.js@@ -80,6 +80,9 @@ module.exports = {// It'd be good if we could error this for switch cases but allow it for for loops"no-continue": "off",+ // no param reassignment is a pain when trying to set props on elements+ "no-param-reassign": "off",+// No void at all collides with `@typescript-eslint/no-floating-promises` which wants us to handle each promise.// Until we do that, `void` is a good way to explicitly mark unhandled promises."no-void": ["error", { allowAsStatement: true }],diff --git a/frontend/src/app/core/datetime/timezone.service.ts b/frontend/src/app/core/datetime/timezone.service.tsindex 607067ee07c..7e87bd0a0fa 100644--- a/frontend/src/app/core/datetime/timezone.service.ts+++ b/frontend/src/app/core/datetime/timezone.service.ts@@ -145,8 +145,20 @@ export class TimezoneService {return Number(moment.duration(durationString).asHours().toFixed(2));}- public formattedDuration(durationString:string):string {- return this.I18n.t('js.units.hour', { count: this.toHours(durationString) });+ public toDays(durationString:string):number {+ return Number(moment.duration(durationString).asDays().toFixed(2));+ }++ public formattedDuration(durationString:string, unit:'hour'|'days' = 'hour'):string {+ switch (unit) {+ case 'hour':+ return this.I18n.t('js.units.hour', { count: this.toHours(durationString) });+ case 'days':+ return this.I18n.t('js.units.day', { count: this.toDays(durationString) });+ default:+ // Case fallthrough for eslint+ return '';+ }}public formattedISODate(date:any):string {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.tsindex 5098ce53914..86fc42442d8 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,6 +50,7 @@ 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';export function initializeCoreDisplayFields(displayFieldService:DisplayFieldService) {return () => {@@ -72,6 +73,7 @@ export function initializeCoreDisplayFields(displayFieldService:DisplayFieldServ.addFieldType(ResourcesDisplayField, 'resources', ['[]CustomOption']).addFieldType(MultipleUserFieldModule, 'users', ['[]User']).addFieldType(FormattableDisplayField, 'formattable', ['Formattable'])+ .addFieldType(DurationDisplayField, 'duration', ['duration']).addFieldType(EstimatedTimeDisplayField, 'estimatedTime', ['estimatedTime']).addFieldType(DateDisplayField, 'date', ['Date']).addFieldType(DateTimeDisplayField, 'datetime', ['DateTime'])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/duration-display-field.module.tsnew file mode 100644index 00000000000..b4aff6fb87d--- /dev/null+++ b/frontend/src/app/shared/components/fields/display/field-types/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 DurationDisplayField extends DisplayField {+ @InjectField() timezoneService:TimezoneService;++ public get valueString() {+ return this.timezoneService.formattedDuration(this.value, 'days');+ }+}diff --git a/spec/features/work_packages/table/duration_field_spec.rb b/spec/features/work_packages/table/duration_field_spec.rbnew file mode 100644index 00000000000..5b04f74ead8--- /dev/null+++ b/spec/features/work_packages/table/duration_field_spec.rb@@ -0,0 +1,38 @@+require 'spec_helper'++describe 'Duration field in the work package table',+ with_flag: { work_packages_duration_field_active: true },+ js: true do+ shared_let(:current_user) { create :admin }+ shared_let(:work_package) do+ create :work_package,+ subject: 'moved',+ author: current_user,+ start_date: Time.zone.today.beginning_of_week.next_occurring(:monday),+ due_date: Time.zone.today.beginning_of_week.next_occurring(:thursday)+ end++ let!(:wp_table) { Pages::WorkPackagesTable.new(work_package.project) }+ let!(:query) do+ query = build(:query, user: current_user, project: work_package.project)+ query.column_names = %w(subject start_date due_date duration)+ query.filters.clear+ query.show_hierarchies = false++ query.save!+ query+ end++ let(:duration) { wp_table.edit_field work_package, :duration }++ before do+ login_as(current_user)++ wp_table.visit_query query+ wp_table.expect_work_package_listed work_package+ end++ it 'shows the duration as days' do+ duration.expect_state_text '3 days'+ end+end