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

[61535] Can switch to automatic scheduling with indirect predecessors

Christophe Bliard14a0adb7ef33
diff --git a/app/components/work_packages/date_picker/banner_component.rb b/app/components/work_packages/date_picker/banner_component.rb
index 84093d7139b..5b93786924d 100644
--- a/app/components/work_packages/date_picker/banner_component.rb
+++ b/app/components/work_packages/date_picker/banner_component.rb
@@ -126,7 +126,7 @@ module WorkPackages
end
def predecessor_relations
- @predecessor_relations ||= @work_package.follows_relations
+ @predecessor_relations ||= Relation.used_for_scheduling_of(@work_package)
end
def predecessor_work_packages
diff --git a/app/components/work_packages/date_picker/dialog_content_component.html.erb b/app/components/work_packages/date_picker/dialog_content_component.html.erb
index acfa4936e4e..cca99194363 100644
--- a/app/components/work_packages/date_picker/dialog_content_component.html.erb
+++ b/app/components/work_packages/date_picker/dialog_content_component.html.erb
@@ -1,26 +1,36 @@
<%=
content_tag("turbo-frame", id: "wp-datepicker-dialog--content") do
- component_wrapper(data: { "application-target": "dynamic",
- controller: "work-packages--date-picker--preview",
- test_selector: "op-datepicker-modal" },
- class: "wp-datepicker-dialog--content") do
+ component_wrapper(
+ data: { "application-target": "dynamic",
+ controller: "work-packages--date-picker--preview",
+ test_selector: "op-datepicker-modal" },
+ class: "wp-datepicker-dialog--content"
+ ) do
component_collection do |collection|
if show_banner?
collection.with_component(WorkPackages::DatePicker::BannerComponent.new(work_package:, manually_scheduled: schedule_manually))
end
collection.with_component(Primer::Alpha::Dialog::Body.new(classes: "wp-datepicker-dialog--body")) do
- render(Primer::Alpha::UnderlinePanels.new(label: I18n.t("work_packages.datepicker_modal.tabs.aria_label"),
- classes: "wp-datepicker-dialog--UnderlineNav")) do |component|
+ render(
+ Primer::Alpha::UnderlinePanels.new(
+ label: I18n.t("work_packages.datepicker_modal.tabs.aria_label"),
+ classes: "wp-datepicker-dialog--UnderlineNav"
+ )
+ ) do |component|
component.with_tab(selected: true, id: "wp-datepicker-dialog--content-tab--dates") do |tab|
tab.with_text { I18n.t("work_packages.datepicker_modal.tabs.dates") }
tab.with_panel do
- render(WorkPackages::DatePicker::FormContentComponent.new(form_id: DIALOG_FORM_ID,
- show_date_form: content_editable?,
- work_package:,
- schedule_manually:,
- focused_field:,
- touched_field_map:))
+ render(
+ WorkPackages::DatePicker::FormContentComponent.new(
+ form_id: DIALOG_FORM_ID,
+ show_date_form: can_set_dates?,
+ work_package:,
+ schedule_manually:,
+ focused_field:,
+ touched_field_map:
+ )
+ )
end
end
@@ -34,20 +44,28 @@
render(border_box_container(padding: :condensed)) do |box|
relation_group.visible_relations.each do |relation|
box.with_row(scheme: :default) do
- render(WorkPackageRelationsTab::RelationComponent.new(work_package:,
- relation: (relation unless relation_group.children_type?),
- visibility: :visible,
- child: (relation if relation_group.children_type?),
- editable: false))
+ render(
+ WorkPackageRelationsTab::RelationComponent.new(
+ work_package:,
+ relation: (relation unless relation_group.children_type?),
+ visibility: :visible,
+ child: (relation if relation_group.children_type?),
+ editable: false
+ )
+ )
end
end
relation_group.ghost_relations.each do |relation|
box.with_row(scheme: :default) do
- render(WorkPackageRelationsTab::RelationComponent.new(work_package:,
- relation: (relation unless relation_group.children_type?),
- visibility: :ghost,
- child: (relation if relation_group.children_type?),
- editable: false))
+ render(
+ WorkPackageRelationsTab::RelationComponent.new(
+ work_package:,
+ relation: (relation unless relation_group.children_type?),
+ visibility: :ghost,
+ child: (relation if relation_group.children_type?),
+ editable: false
+ )
+ )
end
end
end
@@ -66,16 +84,24 @@
collection.with_component(Primer::Alpha::Dialog::Footer.new) do
component_collection do |footer|
- footer.with_component(Primer::ButtonComponent.new(data: { action: "work-packages--date-picker--preview#cancel" },
- test_selector: "op-datepicker-modal--action")) do
+ footer.with_component(
+ Primer::ButtonComponent.new(
+ data: { action: "work-packages--date-picker--preview#cancel" },
+ test_selector: "op-datepicker-modal--action"
+ )
+ ) do
I18n.t("button_cancel")
end
- footer.with_component(Primer::ButtonComponent.new(scheme: :primary,
- type: :submit,
- form: DIALOG_FORM_ID,
- test_selector: "op-datepicker-modal--action",
- disabled: !content_editable?)) do
+ footer.with_component(
+ Primer::ButtonComponent.new(
+ scheme: :primary,
+ type: :submit,
+ form: DIALOG_FORM_ID,
+ test_selector: "op-datepicker-modal--action",
+ disabled: !can_set_dates?
+ )
+ ) do
I18n.t("button_save")
end
end
diff --git a/app/components/work_packages/date_picker/dialog_content_component.rb b/app/components/work_packages/date_picker/dialog_content_component.rb
index ad28a21cea0..761465f31ea 100644
--- a/app/components/work_packages/date_picker/dialog_content_component.rb
+++ b/app/components/work_packages/date_picker/dialog_content_component.rb
@@ -39,7 +39,7 @@ module WorkPackages
# Used for the three tabs for predecessors, successors and children in the date picker modal.
Tab = Data.define(:key, :relation_group)
- attr_accessor :work_package, :schedule_manually, :focused_field, :touched_field_map
+ attr_reader :work_package, :schedule_manually, :focused_field, :touched_field_map
def initialize(work_package:, schedule_manually: true, focused_field: :start_date, touched_field_map: {})
super
@@ -52,12 +52,20 @@ module WorkPackages
private
- def precedes_relations
- @precedes_relations ||= work_package.precedes_relations
+ def schedule_manually?
+ @schedule_manually
+ end
+
+ def has_children_or_predecessors?
+ children.any? || follows_relations_used_for_scheduling.any?
+ end
+
+ def follows_relations_used_for_scheduling
+ @follows_relations_used_for_scheduling ||= Relation.used_for_scheduling_of(work_package)
end
- def follows_relations
- @follows_relations ||= work_package.follows_relations
+ def precedes_relations
+ @precedes_relations ||= work_package.precedes_relations
end
def children
@@ -73,19 +81,18 @@ module WorkPackages
]
end
- def content_editable?
- @schedule_manually || follows_relations.any? || children.any?
+ # Returns true if dates can be set and saved: if the work package is
+ # scheduled manually or if it is scheduled automatically with children or
+ # predecessors.
+ def can_set_dates?
+ schedule_manually? || has_children_or_predecessors?
end
def show_banner?
- follows_relations.any? ||
+ follows_relations_used_for_scheduling.any? ||
children.any? ||
(@schedule_manually && (precedes_relations.any? || work_package.parent_id.present?))
end
-
- def has_relations?
- precedes_relations.any? || follows_relations.any? || children.any?
- end
end
end
end
diff --git a/app/components/work_packages/date_picker/form_content_component.rb b/app/components/work_packages/date_picker/form_content_component.rb
index e7d1a19ada2..eb24e462622 100644
--- a/app/components/work_packages/date_picker/form_content_component.rb
+++ b/app/components/work_packages/date_picker/form_content_component.rb
@@ -56,12 +56,9 @@ module WorkPackages
def submit_path
if work_package.new_record?
- url_for(controller: "work_packages/date_picker",
- action: "create")
+ datepicker_dialog_content_path
else
- url_for(controller: "work_packages/date_picker",
- action: "update",
- work_package_id: work_package.id)
+ work_package_datepicker_dialog_content_path(work_package)
end
end
diff --git a/app/models/relation.rb b/app/models/relation.rb
index af637a0d8de..b205b160baa 100644
--- a/app/models/relation.rb
+++ b/app/models/relation.rb
@@ -95,7 +95,7 @@ class Relation < ApplicationRecord
include ::Scopes::Scoped
- scopes :follows_non_manual_ancestors,
+ scopes :used_for_scheduling_of,
:types,
:visible
diff --git a/app/models/relations/scopes/follows_non_manual_ancestors.rb b/app/models/relations/scopes/used_for_scheduling_of.rb
similarity index 55%
rename from app/models/relations/scopes/follows_non_manual_ancestors.rb
rename to app/models/relations/scopes/used_for_scheduling_of.rb
index 785517713e9..0a626c4549d 100644
--- a/app/models/relations/scopes/follows_non_manual_ancestors.rb
+++ b/app/models/relations/scopes/used_for_scheduling_of.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) the OpenProject GmbH
@@ -27,28 +29,31 @@
#++
module Relations::Scopes
- module FollowsNonManualAncestors
+ module UsedForSchedulingOf
extend ActiveSupport::Concern
class_methods do
- # Returns all follows relationships of work package ancestors or work package unless
- # the ancestor or a work package between the ancestor and self is manually scheduled.
- def follows_non_manual_ancestors(work_package)
- ancestor_relations_non_manual = WorkPackageHierarchy
- .where(descendant_id: work_package.id)
- .where.not(ancestor_id: from_manual_ancestors(work_package).select(:ancestor_id))
+ # Returns all successor/predecessor relationships in which the work
+ # package or its automatically scheduled ancestors are a successor of. The
+ # automatically scheduled ancestors are the ancestors that are linked to
+ # the work package only through automatically scheduled parents. As soon
+ # as a parent is manually scheduled, its predecessors and ancestors are
+ # not involved in scheduling anymore.
+ def used_for_scheduling_of(work_package)
+ automatically_scheduled_ancestors =
+ WorkPackageHierarchy.where(descendant_id: work_package.id)
+ .where.not(ancestor_id: manually_scheduled_ancestors(work_package).select(:ancestor_id))
- where(from_id: ancestor_relations_non_manual.select(:ancestor_id))
- .follows
+ follows.where(from_id: automatically_scheduled_ancestors.select(:ancestor_id))
end
private
- def from_manual_ancestors(work_package)
- manually_schedule_ancestors = work_package.ancestors.where(schedule_manually: true)
+ def manually_scheduled_ancestors(work_package)
+ manually_scheduled_ancestors = work_package.ancestors.where(schedule_manually: true)
WorkPackageHierarchy
- .where(descendant_id: manually_schedule_ancestors.select(:id))
+ .where(descendant_id: manually_scheduled_ancestors.select(:id))
end
end
end
diff --git a/app/models/work_package/scheduling_rules.rb b/app/models/work_package/scheduling_rules.rb
index 311ae978481..9254e040329 100644
--- a/app/models/work_package/scheduling_rules.rb
+++ b/app/models/work_package/scheduling_rules.rb
@@ -56,7 +56,7 @@ module WorkPackage::SchedulingRules
# eager load `to` and `from` to avoid n+1 on successor_soonest_start
@soonest_start ||=
Relation
- .follows_non_manual_ancestors(self)
+ .used_for_scheduling_of(self)
.includes(:to, :from)
.filter_map(&:successor_soonest_start)
.max
diff --git a/spec/components/work_packages/date_picker/dialog_content_component_spec.rb b/spec/components/work_packages/date_picker/dialog_content_component_spec.rb
new file mode 100644
index 00000000000..b1ea33a2e24
--- /dev/null
+++ b/spec/components/work_packages/date_picker/dialog_content_component_spec.rb
@@ -0,0 +1,164 @@
+# 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 "rails_helper"
+
+RSpec.describe WorkPackages::DatePicker::DialogContentComponent, type: :component do
+ include OpenProject::StaticRouting::UrlHelpers
+
+ create_shared_association_defaults_for_work_package_factory
+
+ subject(:dialog_content) do
+ with_controller_class(WorkPackages::DatePickerController) do
+ with_request_url("/work_packages/:work_package_id/datepicker_dialog_content") do
+ render_inline(described_class.new(work_package:, schedule_manually:))
+ end
+ end
+ end
+
+ context "when manually scheduled" do
+ let(:schedule_manually) { true }
+ let(:work_package) { build_stubbed(:work_package) }
+
+ it "shows the date form" do
+ expect(dialog_content).to have_field(I18n.t("attributes.start_date"))
+ expect(dialog_content).to have_field(I18n.t("attributes.due_date"))
+ end
+
+ it "has an enabled save button" do
+ expect(dialog_content).to have_button(I18n.t("button_save"), disabled: false)
+ end
+ end
+
+ context "when automatically scheduled" do
+ let(:schedule_manually) { false }
+
+ context "without any predecessors nor children" do
+ let(:work_package) { build_stubbed(:work_package) }
+
+ it "does not show the date form" do
+ expect(dialog_content).to have_no_field(I18n.t("attributes.start_date"), disabled: :all)
+ expect(dialog_content).to have_no_field(I18n.t("attributes.due_date"), disabled: :all)
+ end
+
+ it "displays a blank slate explaining it can't be automatically scheduled because there are no predecessors" do
+ expect(dialog_content).to have_text(I18n.t("work_packages.datepicker_modal.blankslate.title"))
+ expect(dialog_content).to have_text(I18n.t("work_packages.datepicker_modal.blankslate.description"))
+ end
+
+ it "has a disabled save button" do
+ expect(dialog_content).to have_button(I18n.t("button_save"), disabled: true)
+ end
+ end
+
+ context "with a child" do
+ let(:work_package) { build_stubbed(:work_package, children: [build_stubbed(:work_package)]) }
+
+ it "shows the date form with disabled fields" do
+ expect(dialog_content).to have_field(I18n.t("attributes.start_date"), disabled: true)
+ expect(dialog_content).to have_field(I18n.t("attributes.due_date"), disabled: true)
+ end
+
+ it "shows the banner 'The dates are determined by child work packages'" do
+ expect(dialog_content).to have_text(I18n.t("work_packages.datepicker_modal.banner.title.automatic_with_children"))
+ end
+
+ it "has an enabled save button" do
+ expect(dialog_content).to have_button(I18n.t("button_save"), disabled: false)
+ end
+ end
+
+ context "with a direct predecessor" do
+ shared_let_work_packages(<<~TABLE)
+ subject | MTWTFSS | scheduling mode | predecessors
+ predecessor | | manual |
+ work_package | | automatic | predecessor
+ TABLE
+
+ it "shows the date form with disabled fields" do
+ expect(dialog_content).to have_field(I18n.t("attributes.start_date"), disabled: true)
+ expect(dialog_content).to have_field(I18n.t("attributes.due_date"), disabled: true)
+ end
+
+ it "shows the banner 'The start date is set by a predecessor'" do
+ expect(dialog_content).to have_text(I18n.t("work_packages.datepicker_modal.banner.title.automatic_with_predecessor"))
+ end
+
+ it "has an enabled save button" do
+ expect(dialog_content).to have_button(I18n.t("button_save"), disabled: false)
+ end
+ end
+
+ context "with an indirect predecessor involved in scheduling (like an automatically scheduled parent having a predecessor)" do
+ shared_let_work_packages(<<~TABLE)
+ hierarchy | MTWTFSS | scheduling mode | predecessors
+ parent_predecessor | | manual |
+ parent | | automatic | parent_predecessor
+ work_package | | automatic |
+ TABLE
+
+ it "shows the date form with disabled fields" do
+ expect(dialog_content).to have_field(I18n.t("attributes.start_date"), disabled: true)
+ expect(dialog_content).to have_field(I18n.t("attributes.due_date"), disabled: true)
+ end
+
+ it "shows the banner 'The start date is set by a predecessor'" do
+ expect(dialog_content).to have_text(I18n.t("work_packages.datepicker_modal.banner.title.automatic_with_predecessor"))
+ end
+
+ it "has an enabled save button" do
+ expect(dialog_content).to have_button(I18n.t("button_save"), disabled: false)
+ end
+ end
+
+ context "with an indirect predecessor not involved in scheduling (like a manually scheduled parent having a predecessor)" do
+ shared_let_work_packages(<<~TABLE)
+ hierarchy | MTWTFSS | scheduling mode | predecessors
+ parent_predecessor | | manual |
+ parent | | manual | parent_predecessor
+ work_package | | automatic |
+ TABLE
+
+ it "does not show the date form" do
+ expect(dialog_content).to have_no_field(I18n.t("attributes.start_date"), disabled: :all)
+ expect(dialog_content).to have_no_field(I18n.t("attributes.due_date"), disabled: :all)
+ end
+
+ it "displays a blank slate explaining it can't be automatically scheduled because there are no predecessors" do
+ expect(dialog_content).to have_text(I18n.t("work_packages.datepicker_modal.blankslate.title"))
+ expect(dialog_content).to have_text(I18n.t("work_packages.datepicker_modal.blankslate.description"))
+ end
+
+ it "has a disabled save button" do
+ expect(dialog_content).to have_button(I18n.t("button_save"), disabled: true)
+ end
+ end
+ end
+end