-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[50953] Progress reporting for work package hierarchies: Change calculation and name of Work and Remaining work #14216
Merged
cbliard
merged 8 commits into
dev
from
epic/40867-progress-reporting-for-work-package-hierarchies
Jan 10, 2024
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1ef2568
[50963] Update derived work and remaining work in a migration
cbliard d044c90
Introduce let_work_packages helpers
cbliard 0acbd07
Capitalize some column names in wp table configuration dropdown
cbliard a4d1f3e
Use accessible selector for checking column header presence
cbliard 43283bc
Add remaining work column to work package index sums test
cbliard 2bb40dc
[50962] Add feature test for query sums with filters
cbliard d230fcd
Replace build_work_package_hierarchy with let_work_packages
cbliard d4f6361
Display estimated time correctly in wiki macro
cbliard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#-- copyright | ||
# OpenProject is an open source project management software. | ||
# Copyright (C) 2012-2024 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. | ||
#++ | ||
|
||
Dir[Rails.root.join('spec/support/table_helpers/*.rb')].each { |f| require f } | ||
|
||
RSpec.configure do |config| | ||
config.extend TableHelpers::LetWorkPackages | ||
config.include TableHelpers::ExampleMethods | ||
|
||
RSpec::Matchers.define :match_table do |expected| | ||
match do |actual_work_packages| | ||
expected_data = TableHelpers::TableData.for(expected) | ||
actual_data = TableHelpers::TableData.from_work_packages(actual_work_packages, expected_data.columns) | ||
|
||
representer = TableHelpers::TableRepresenter.new(tables_data: [expected_data, actual_data], | ||
columns: expected_data.columns) | ||
@expected = representer.render(expected_data) | ||
@actual = representer.render(actual_data) | ||
|
||
values_match? @expected, @actual | ||
end | ||
|
||
diffable | ||
attr_reader :expected, :actual | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
# frozen_string_literal: true | ||
|
||
#-- copyright | ||
# OpenProject is an open source project management software. | ||
# Copyright (C) 2012-2024 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_relative 'identifier' | ||
|
||
module TableHelpers | ||
module Column | ||
extend Identifier | ||
|
||
def self.for(header) | ||
case header | ||
when /\A\s*estimated hours/i | ||
raise ArgumentError, 'Please use "work" instead of "estimated hours"' | ||
when /derived estimated hours/i | ||
raise ArgumentError, 'Please use "derived work" instead of "derived estimated hours"' | ||
when /derived remaining hours/i | ||
raise ArgumentError, 'Please use "derived remaining work" instead of "derived remaining hours"' | ||
when /\A\s*remaining hours/i | ||
raise ArgumentError, 'Please use "remaining work" instead of "remaining hours"' | ||
when /\A\s*work/i | ||
Duration.new(header:, attribute: :estimated_hours) | ||
when /derived work/i | ||
Duration.new(header:, attribute: :derived_estimated_hours) | ||
when /\A\s*remaining work/i | ||
Duration.new(header:, attribute: :remaining_hours) | ||
when /derived remaining work/i | ||
Duration.new(header:, attribute: :derived_remaining_hours) | ||
when /subject/ | ||
Subject.new(header:) | ||
when /hierarchy/ | ||
Hierarchy.new(header:) | ||
else | ||
assert_work_package_attribute_exists(header) | ||
Generic.new(header:) | ||
end | ||
end | ||
|
||
def self.assert_work_package_attribute_exists(attribute) | ||
attribute = to_identifier(attribute).to_s | ||
return if WorkPackage.attribute_names.include?(attribute) | ||
|
||
raise ArgumentError, "WorkPackage does not have an attribute named #{attribute.inspect}" | ||
end | ||
|
||
class Generic | ||
include Identifier | ||
|
||
attr_reader :attribute, :title, :raw_header | ||
|
||
def initialize(header:, attribute: nil) | ||
@raw_header = header | ||
@title = header.strip | ||
@attribute = attribute || to_identifier(title) | ||
end | ||
|
||
def format(value) | ||
value.to_s | ||
end | ||
|
||
def cell_format(value, size) | ||
format(value).send(text_align, size) | ||
end | ||
|
||
def parse(raw_value) | ||
raw_value.strip | ||
end | ||
|
||
def text_align | ||
:ljust | ||
end | ||
|
||
def read_and_update_work_packages_data(work_packages_data) | ||
work_packages_data.each do |work_package_data| | ||
work_package_data => { attributes:, row: } | ||
raw_value = row[raw_header] | ||
work_package_data.merge!(metadata_for_value(raw_value)) | ||
attributes.merge!(attributes_for_raw_value(raw_value, work_package_data, work_packages_data)) | ||
end | ||
end | ||
|
||
def attributes_for_raw_value(raw_value, _data, _work_packages_data) | ||
{ attribute => parse(raw_value) } | ||
end | ||
|
||
def metadata_for_value(_raw_value) | ||
{} | ||
end | ||
end | ||
|
||
module Identifiable | ||
include Identifier | ||
|
||
def metadata_for_value(raw_value, *) | ||
super.merge(identifier: to_identifier(raw_value)) | ||
end | ||
end | ||
|
||
class Duration < Generic | ||
def text_align | ||
:rjust | ||
end | ||
|
||
def format(value) | ||
if value.nil? | ||
'' | ||
elsif value == value.truncate | ||
"%sh" % value.to_i | ||
else | ||
"%sh" % value | ||
end | ||
end | ||
|
||
def parse(raw_value) | ||
raw_value.blank? ? nil : raw_value.to_f | ||
end | ||
end | ||
|
||
class Subject < Generic | ||
include Identifiable | ||
end | ||
|
||
class Hierarchy < Generic | ||
include Identifiable | ||
|
||
def attributes_for_raw_value(raw_value, data, work_packages_data) | ||
{ | ||
parent: find_parent(data, work_packages_data), | ||
subject: parse(raw_value) | ||
} | ||
end | ||
|
||
def metadata_for_value(raw_value) | ||
super.merge(hierarchy_indent: raw_value[/\A */].size) | ||
end | ||
|
||
private | ||
|
||
def find_parent(data, work_packages_data) | ||
return if data[:hierarchy_indent] == 0 | ||
|
||
work_packages_data | ||
.slice(0, data[:index]) | ||
.reverse | ||
.find { _1[:hierarchy_indent] < data[:hierarchy_indent] } | ||
.then { _1&.fetch(:identifier) } | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to look up what this does. Very cool that it works somewhat like a Hash destructuring.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pattern matching. I'm still not sure if I like it or not, so I try using it from times to times to get a better feeling about it.