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
introduce today operator on `AnyStageOrGateFilter`
ulferts194bd5c940a6
diff --git a/app/models/queries/projects/filters/any_stage_or_gate_filter.rb b/app/models/queries/projects/filters/any_stage_or_gate_filter.rbindex dfda6f59f03..7a357d0c860 100644--- a/app/models/queries/projects/filters/any_stage_or_gate_filter.rb+++ b/app/models/queries/projects/filters/any_stage_or_gate_filter.rb@@ -27,16 +27,17 @@# ++class Queries::Projects::Filters::AnyStageOrGateFilter < Queries::Projects::Filters::Base+ include Queries::Operators::DateRangeClauses+def type:dateenddef available_operators- [::Queries::Operators::OnDate]- end-- def default_operator- ::Queries::Operators::OnDate+ [+ ::Queries::Operators::Today,+ ::Queries::Operators::OnDate+ ]enddef available?@@ -51,8 +52,13 @@ class Queries::Projects::Filters::AnyStageOrGateFilter < Queries::Projects::Filtdef wherecase operatorwhen "=d"- stage_where- .or(gate_where)+ stage_where(parsed_start)+ .or(gate_where(parsed_end))+ .arel+ .exists+ when "t"+ stage_where(today)+ .or(gate_where(today)).arel.existselse@@ -60,22 +66,35 @@ class Queries::Projects::Filters::AnyStageOrGateFilter < Queries::Projects::Filtendend- def stage_where- date = Date.parse(values.first)-+ def stage_where(start_date, end_date = start_date)Project::LifeCycleStep.where("project_id = #{Project.table_name}.id").where(type: Project::Stage.name)- .where("start_date <= ? AND end_date >= ?", date, date)+ .where(date_range_clause(Project::LifeCycleStep.table_name, "start_date", nil, start_date))+ .where(date_range_clause(Project::LifeCycleStep.table_name, "end_date", end_date, nil))end- def gate_where+ def gate_where(date)# On gates, only the start_date is set.- date = Date.parse(values.first)-Project::LifeCycleStep.where("project_id = #{Project.table_name}.id").where(type: Project::Gate.name)- .where(start_date: date)+ .where(date_range_clause(Project::LifeCycleStep.table_name, "start_date", date, date))+ end++ def parsed_start+ Date.parse(values.first)+ end++ def parsed_end+ Date.parse(values.last)+ end++ def today+ Time.zone.today+ end++ def connection+ ActiveRecord::Base.connectionendenddiff --git a/spec/features/projects/lists/filters_spec.rb b/spec/features/projects/lists/filters_spec.rbindex bae51821ac9..ca5b539890b 100644--- a/spec/features/projects/lists/filters_spec.rb+++ b/spec/features/projects/lists/filters_spec.rb@@ -619,7 +619,7 @@ RSpec.describe "Projects list filters", :js, with_settings: { login_required?: fdescribe "filtering for lifecycle" doshared_let(:stage) do- create(:project_stage, project:, start_date: Time.zone.today + 5.days, end_date: Time.zone.today + 10.days)+ create(:project_stage, project:, start_date: Time.zone.today - 5.days, end_date: Time.zone.today + 10.days)endshared_let(:gate) { create(:project_gate, project: public_project, date: Time.zone.today + 8.days) }@@ -645,6 +645,10 @@ RSpec.describe "Projects list filters", :js, with_settings: { login_required?: fprojects_page.set_filter("any_stage_or_gate", "Any stage or gate", "on", [Time.zone.today + 8.days])projects_page.expect_projects_in_order(project, public_project)++ projects_page.set_filter("any_stage_or_gate", "Any stage or gate", "today")++ projects_page.expect_projects_in_order(project)endenddiff --git a/spec/models/queries/projects/project_query_results_any_stage_or_gate_spec.rb b/spec/models/queries/projects/project_query_results_any_stage_or_gate_spec.rbindex 6b18c526208..05c6f8d66c9 100644--- a/spec/models/queries/projects/project_query_results_any_stage_or_gate_spec.rb+++ b/spec/models/queries/projects/project_query_results_any_stage_or_gate_spec.rb@@ -1,3 +1,5 @@+# frozen_string_literal: true+# -- copyright# OpenProject is an open source project management software.# Copyright (C) 2010-2024 the OpenProject GmbH@@ -63,7 +65,7 @@ RSpec.describe ProjectQuery, "results of 'Any stage or gate' filter" doendcontext "when filtering in the middle of the stage" do- let(:values) { [stage_start_date + ((stage_end_date - stage_start_date) / 2)] }+ let(:values) { [(stage_start_date + ((stage_end_date - stage_start_date) / 2)).to_s] }it "returns the project whose stage is covering an interval including the date" doexpect(instance.results).to contain_exactly(project_with_stage)@@ -71,7 +73,7 @@ RSpec.describe ProjectQuery, "results of 'Any stage or gate' filter" doendcontext "when filtering on the first day of the stage" do- let(:values) { [stage_start_date] }+ let(:values) { [stage_start_date.to_s] }it "returns the project whose stage begins on that date" doexpect(instance.results).to contain_exactly(project_with_stage)@@ -79,7 +81,7 @@ RSpec.describe ProjectQuery, "results of 'Any stage or gate' filter" doendcontext "when filtering on the last day of the stage" do- let(:values) { [stage_end_date] }+ let(:values) { [stage_end_date.to_s] }it "returns the project whose stage ends on that date" doexpect(instance.results).to contain_exactly(project_with_stage)@@ -87,7 +89,7 @@ RSpec.describe ProjectQuery, "results of 'Any stage or gate' filter" doendcontext "when filtering before the stage" do- let(:values) { [stage_start_date - 1.day] }+ let(:values) { [(stage_start_date - 1.day).to_s] }it "returns no project" doexpect(instance.results).to be_empty@@ -95,7 +97,7 @@ RSpec.describe ProjectQuery, "results of 'Any stage or gate' filter" doendcontext "when filtering after the stage" do- let(:values) { [stage_end_date + 1.day] }+ let(:values) { [(stage_end_date + 1.day).to_s] }it "returns no project" doexpect(instance.results).to be_empty@@ -103,7 +105,7 @@ RSpec.describe ProjectQuery, "results of 'Any stage or gate' filter" doendcontext "when filtering on the day of the gate" do- let(:values) { [gate_date] }+ let(:values) { [gate_date.to_s] }it "returns the project whose gate is on the date of the value" doexpect(instance.results).to contain_exactly(project_with_gate)@@ -111,7 +113,7 @@ RSpec.describe ProjectQuery, "results of 'Any stage or gate' filter" doendcontext "when filtering before the gate" do- let(:values) { [gate_date - 1.day] }+ let(:values) { [(gate_date - 1.day).to_s] }it "returns no project" doexpect(instance.results).to be_empty@@ -119,11 +121,82 @@ RSpec.describe ProjectQuery, "results of 'Any stage or gate' filter" doendcontext "when filtering after the gate" do- let(:values) { [gate_date + 1.day] }+ let(:values) { [(gate_date + 1.day).to_s] }it "returns no project" doexpect(instance.results).to be_emptyendendend++ # TODO: check active state+ # TODO: work with time zones?++ context "with a t (today) operator" do+ before do+ instance.where("any_stage_or_gate", "t", [])+ end++ context "when being in the middle of the stage" do+ it "returns the project whose stage is currently running" do+ expect(instance.results).to contain_exactly(project_with_stage)+ end+ end++ context "when being on the first day of the stage" do+ it "returns the project whose stage begins on that date" do+ Timecop.travel(stage_start_date.noon) do+ expect(instance.results).to contain_exactly(project_with_stage)+ end+ end+ end++ context "when being on the last day of the stage" do+ it "returns the project whose stage begins on that date" do+ Timecop.travel(stage_end_date.noon) do+ expect(instance.results).to contain_exactly(project_with_stage)+ end+ end+ end++ context "when being before the stage" do+ it "returns no project" do+ Timecop.travel(stage_start_date.noon - 1.day) do+ expect(instance.results).to be_empty+ end+ end+ end++ context "when being after the stage" do+ it "returns no project" do+ Timecop.travel(stage_end_date.noon + 1.day) do+ expect(instance.results).to be_empty+ end+ end+ end++ context "when being on the day of the gate" do+ it "returns the project whose gate is on the date of the value" do+ Timecop.travel(gate_date.noon) do+ expect(instance.results).to contain_exactly(project_with_gate)+ end+ end+ end++ context "when being before the day of the gate" do+ it "returns no project" do+ Timecop.travel(gate_date.noon - 1.day) do+ expect(instance.results).to be_empty+ end+ end+ end++ context "when being after the day of the gate" do+ it "returns no project" do+ Timecop.travel(gate_date.noon + 1.day) do+ expect(instance.results).to be_empty+ end+ end+ end+ endend