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

Add duration filter for work packages

Dombi Attila60c17404832e
diff --git a/app/models/queries/work_packages.rb b/app/models/queries/work_packages.rb
index 3e6bc3033df..f0c7322372e 100644
--- a/app/models/queries/work_packages.rb
+++ b/app/models/queries/work_packages.rb
@@ -75,7 +75,7 @@ module Queries::WorkPackages
filter Filter::RelatableFilter
filter Filter::MilestoneFilter
filter Filter::TypeaheadFilter
-
+ filter Filter::DurationFilter
exclude Filter::RelatableFilter
column Columns::PropertyColumn
diff --git a/app/models/queries/work_packages/filter/duration_filter.rb b/app/models/queries/work_packages/filter/duration_filter.rb
new file mode 100644
index 00000000000..11e96a5c12f
--- /dev/null
+++ b/app/models/queries/work_packages/filter/duration_filter.rb
@@ -0,0 +1,42 @@
+#-- 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.
+#++
+
+class Queries::WorkPackages::Filter::DurationFilter <
+ Queries::WorkPackages::Filter::WorkPackageFilter
+ def type
+ :integer
+ end
+
+ def where
+ if operator == Queries::Operators::None.to_sym.to_s
+ super + " OR #{WorkPackage.table_name}.duration=0"
+ else
+ super
+ end
+ end
+end
diff --git a/spec/models/queries/work_packages/filter/duration_filter_spec.rb b/spec/models/queries/work_packages/filter/duration_filter_spec.rb
new file mode 100644
index 00000000000..c996117d44d
--- /dev/null
+++ b/spec/models/queries/work_packages/filter/duration_filter_spec.rb
@@ -0,0 +1,66 @@
+#-- 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.
+#++
+
+require 'spec_helper'
+
+describe Queries::WorkPackages::Filter::DurationFilter, type: :model do
+ it_behaves_like 'basic query filter' do
+ let(:type) { :integer }
+ let(:class_key) { :duration }
+
+ describe '#available?' do
+ it 'is true' do
+ expect(instance).to be_available
+ end
+ end
+
+ describe '#allowed_values' do
+ it 'is nil' do
+ expect(instance.allowed_values).to be_nil
+ end
+ end
+
+ it_behaves_like 'non ar filter'
+
+ describe '#where' do
+ let!(:work_package_zero_duration) { create(:work_package, duration: 0) }
+ let!(:work_package_no_duration) { create(:work_package, duration: nil) }
+ let!(:work_package_with_duration) { create(:work_package, duration: 1) }
+
+ context 'with the operator being "none"' do
+ before do
+ instance.operator = Queries::Operators::None.to_sym.to_s
+ end
+
+ it 'finds zero and none values' do
+ expect(WorkPackage.where(instance.where)).to match_array [work_package_zero_duration, work_package_no_duration]
+ end
+ end
+ end
+ end
+end