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
table_helpers: Add successor relations column type
Christophe Bliardea2844e939c0
diff --git a/spec/components/work_package_relations_tab/relations_mediator_spec.rb b/spec/components/work_package_relations_tab/relations_mediator_spec.rbindex bde386288a6..e583ae853d4 100644--- a/spec/components/work_package_relations_tab/relations_mediator_spec.rb+++ b/spec/components/work_package_relations_tab/relations_mediator_spec.rb@@ -88,12 +88,12 @@ RSpec.describe WorkPackageRelationsTab::RelationsMediator docontext "having a closest relation" doshared_let_work_packages(<<~TABLE)- hierarchy | MTWTFSS | scheduling mode | predecessors- predecessor1 | XXX | manual |- predecessor2 | XX | manual |- predecessor3 | XX | manual |- predecessor4 | | manual |- work_package | X | automatic | predecessor1 with lag 2, predecessor2 with lag 7, predecessor3 with lag 7, predecessor4 with lag 10+ hierarchy | MTWTFSS | scheduling mode | successors+ predecessor1 | XXX | manual | work_package with lag 2+ predecessor2 | XX | manual | work_package with lag 7+ predecessor3 | XX | manual | work_package with lag 7+ predecessor4 | | manual | work_package with lag 10+ work_package | X | automatic |TABLEdescribe "#closest_relation" dodiff --git a/spec/support/table_helpers/column.rb b/spec/support/table_helpers/column.rbindex 6ef79ca360a..80f51b6a377 100644--- a/spec/support/table_helpers/column.rb+++ b/spec/support/table_helpers/column.rb@@ -40,6 +40,7 @@ require_relative "column_type/related_to_relations"require_relative "column_type/schedule"require_relative "column_type/scheduling_mode"require_relative "column_type/status"+require_relative "column_type/successor_relations"require_relative "column_type/subject"module TableHelpers@@ -61,6 +62,7 @@ module TableHelpersschedule_manually: ColumnType::SchedulingMode,status: ColumnType::Status,subject: ColumnType::Subject,+ successor_relations: ColumnType::SuccessorRelations,__fallback__: ColumnType::Generic}.freeze@@ -100,6 +102,8 @@ module TableHelpers:schedule_manuallywhen /\s*predecessors\s*/:predecessor_relations+ when /\s*successors\s*/+ :successor_relationswhen /\s*relate[ds][ _]to\s*/:related_to_relationswhen /status/, /hierarchy/diff --git a/spec/support/table_helpers/column_type/successor_relations.rb b/spec/support/table_helpers/column_type/successor_relations.rbnew file mode 100644index 00000000000..2a8e9275f2b--- /dev/null+++ b/spec/support/table_helpers/column_type/successor_relations.rb@@ -0,0 +1,92 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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.+#++++module TableHelpers+ module ColumnType+ # Column to add successors to work packages like "wp1, wp2 with lag 2, wp3".+ #+ # Supported texts:+ # - :wp+ # - :wp with lag :int+ # - precedes :wp+ # - precedes :wp with lag :int+ # They can be combined by separated them with commas: "precedes wp1, wp2 with lag 2, wp3".+ #+ # Example:+ #+ # | subject | successors |+ # | predecessor2 | main, predecessor with lag 2 |+ # | predecessor | precedes main |+ # | main | |+ class SuccessorRelations < Generic+ def attributes_for_work_package(_attribute, _work_package)+ {}+ end++ def extract_data(_attribute, raw_header, work_package_data, _work_packages_data)+ successors = work_package_data.dig(:row, raw_header)+ successors = successors.split(",").map(&:strip).compact_blank+ parse_successors(successors)+ end++ def parse_successors(successors)+ relations = successors.to_h do |successor|+ relation = parse_successor(successor)+ [relation[:with], relation]+ end+ { relations: }.compact_blank+ end++ def parse_successor(successor)+ case successor+ when /^(?:precedes)?\s*(.+?)(?: with lag (\d+))?\s*$/+ {+ raw: successor,+ type: :precedes,+ with: $1,+ lag: $2.to_i+ }+ else+ spell_checker = DidYouMean::SpellChecker.new(+ dictionary: [+ ":wp",+ ":wp with lag :int",+ "precedes :wp",+ "precedes :wp with lag :int"+ ]+ )+ suggestions = spell_checker.correct(successor).map(&:inspect).join(" ")+ did_you_mean = " Did you mean #{suggestions} instead?" if suggestions.present?+ raise "unable to parse successor #{successor.inspect}.#{did_you_mean}"+ end+ end+ end+ end+enddiff --git a/spec/support_spec/table_helpers/column_type/successor_relations_spec.rb b/spec/support_spec/table_helpers/column_type/successor_relations_spec.rbnew file mode 100644index 00000000000..b4347daf25a--- /dev/null+++ b/spec/support_spec/table_helpers/column_type/successor_relations_spec.rb@@ -0,0 +1,115 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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"++module TableHelpers::ColumnType+ RSpec.describe SuccessorRelations do+ subject(:column_type) { described_class.new }++ def parsed_data(table)+ TableHelpers::TableParser.new.parse(table)+ end++ describe "empty" do+ it "stores nothing when empty" do+ work_package_data = parsed_data(<<~TABLE).first+ | successors |+ | |+ TABLE+ expect(work_package_data[:relations]).to be_nil+ expect(work_package_data[:attributes]).to be_empty++ work_package_data = parsed_data(<<~TABLE).first+ | successors |+ | |+ TABLE+ expect(work_package_data[:relations]).to be_nil+ expect(work_package_data[:attributes]).to be_empty+ end+ end++ describe "[precedes] <successor> [with lag <nb_days>]" do+ it "stores precedes relations in work_package_data" do+ work_package_data = parsed_data(<<~TABLE).pluck(:relations)+ | successors |+ | precedes main with lag 3 |+ | main with lag 3 |+ TABLE+ expect(work_package_data)+ .to eq([+ {+ "main" => { raw: "precedes main with lag 3", type: :precedes, with: "main", lag: 3 }+ },+ {+ "main" => { raw: "main with lag 3", type: :precedes, with: "main", lag: 3 }+ }+ ])+ end++ it "has a default lag of 0 days when not specified" do+ work_package_data = parsed_data(<<~TABLE).pluck(:relations)+ | successors |+ | precedes main |+ | main |+ TABLE+ expect(work_package_data)+ .to eq([+ {+ "main" => { raw: "precedes main", type: :precedes, with: "main", lag: 0 }+ },+ {+ "main" => { raw: "main", type: :precedes, with: "main", lag: 0 }+ }+ ])+ end++ it "can store multiple relations" do+ work_package_data = parsed_data(<<~TABLE).pluck(:relations)+ | successors |+ | precedes wp1, precedes wp2 |+ | precedes wp1, wp2, wp3 |+ TABLE+ expect(work_package_data)+ .to eq([+ {+ "wp1" => { raw: "precedes wp1", type: :precedes, with: "wp1", lag: 0 },+ "wp2" => { raw: "precedes wp2", type: :precedes, with: "wp2", lag: 0 }+ },+ {+ "wp1" => { raw: "precedes wp1", type: :precedes, with: "wp1", lag: 0 },+ "wp2" => { raw: "wp2", type: :precedes, with: "wp2", lag: 0 },+ "wp3" => { raw: "wp3", type: :precedes, with: "wp3", lag: 0 }+ }+ ])+ end+ end+ end+enddiff --git a/spec/support_spec/table_helpers/table_data_spec.rb b/spec/support_spec/table_helpers/table_data_spec.rbindex eefda8e5c6b..688967bfd38 100644--- a/spec/support_spec/table_helpers/table_data_spec.rb+++ b/spec/support_spec/table_helpers/table_data_spec.rb@@ -176,6 +176,32 @@ module TableHelpersexpect(follower.follows_relations.first.lag).to eq(2)end+ it "creates 'precedes' relations between work packages out of the table data" do+ table_representation = <<~TABLE+ subject | successors+ predecessor | precedes main with lag 2+ main | precedes successor+ successor |+ TABLE++ table_data = described_class.for(table_representation)+ table = table_data.create_work_packages+ expect(table.work_packages.count).to eq(3)+ predecessor = table.work_package(:predecessor)+ main = table.work_package(:main)+ successor = table.work_package(:successor)++ expect(main.follows_relations.count).to eq(1)+ expect(main.follows_relations.first.predecessor).to eq(predecessor)+ expect(main.follows_relations.first.successor).to eq(main)+ expect(main.follows_relations.first.lag).to eq(2)++ expect(main.precedes_relations.count).to eq(1)+ expect(main.precedes_relations.first.predecessor).to eq(main)+ expect(main.precedes_relations.first.successor).to eq(successor)+ expect(main.precedes_relations.first.lag).to eq(0)+ end+it "creates 'relates' relations between work packages out of the table data" dotable_representation = <<~TABLEsubject | related to