From fd00b7debae2e1e67d4825a0b66fc656fc6a9ed1 Mon Sep 17 00:00:00 2001 From: Jan Catrysse Date: Mon, 7 Aug 2023 15:26:41 +0200 Subject: [PATCH] * Filter on `root_tracker` * Filter on `root_status` --- CHANGELOG.md | 4 +- README.md | 4 +- config/locales/de.yml | 15 +++--- config/locales/en.yml | 15 +++--- config/locales/es.yml | 15 +++--- config/locales/fr.yml | 15 +++--- config/locales/nl.yml | 15 +++--- config/locales/ro.yml | 15 +++--- config/locales/zh.yml | 15 +++--- .../patches/issue_query_patch.rb | 49 ++++++++++++++++--- .../patches/queries_helper_patch.rb | 4 +- 11 files changed, 113 insertions(+), 53 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cab2227..facfeed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # CHANGELOG ### 0.0.3 -* Filter on `root_issue` +* Filter on `root` +* Filter on `root_tracker` +* Filter on `root_status` * Operator `not equal to` on `start_date` and `end_date` * Resolved issue: `SystemStackError (stack level too deep)` Converted `initialize_available_filters` to use `alias_method` diff --git a/README.md b/README.md index f5e11f0..f368ad1 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,9 @@ Link to Redmine plugin page: https://www.redmine.org/plugins/redmine_parent_chil * Version 0.0.1 >= Redmine 4 (including Redmine 5) ## Features -* Filter on `root_issue` +* Filter on `root` +* Filter on `root_tracker` +* Filter on `root_status` * Filter on `parent_tracker` * Filter on `parent_status` * Filter on `child_tracker` diff --git a/config/locales/de.yml b/config/locales/de.yml index d7935b5..f590064 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -1,7 +1,10 @@ de: - label_group_parent_child: Eltern und Kind - child_status_id: Status des Kindes - child_tracker_id: Tracker des Kindes - child_tracker_status_id: Tracker un Status des Kindes - parent_status_id: Status des Elternteils - parent_tracker_id: Tracker des Elternteils \ No newline at end of file + label_filter_group_parent_child: Eltern und Kind + label_filter_child_status_id: Status des Kindes + label_filter_child_tracker_id: Verfolgung des Kindes + label_filter_child_tracker_status_id: Verfolgung und Status des Kindes + label_filter_parent_status_id: Status der Eltern + label_filter_parent_tracker_id: Verfolgung der Eltern + label_filter_root: Hauptticket + label_filter_root_status_id: Status des Haupttickets + label_filter_root_tracker_id: Verfolgung des Haupttickets diff --git a/config/locales/en.yml b/config/locales/en.yml index 6072d8d..2dd008e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1,7 +1,10 @@ en: - label_group_parent_child: Parent and child - child_status_id: Child status - child_tracker_id: Child tracker - child_tracker_status_id: Child tracker and status - parent_status_id: Parent status - parent_tracker_id: Parent tracker + label_filter_group_parent_child: Parent and child + label_filter_child_status_id: Child status + label_filter_child_tracker_id: Child tracker + label_filter_child_tracker_status_id: Child tracker and status + label_filter_parent_status_id: Parent status + label_filter_parent_tracker_id: Parent tracker + label_filter_root: Root + label_filter_root_status_id: Root status + label_filter_root_tracker_id: Root tracker diff --git a/config/locales/es.yml b/config/locales/es.yml index 26c784c..f7a6bb7 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -1,7 +1,10 @@ es: - label_group_parent_child: Padre y hijo - child_status_id: Estado del hijo - child_tracker_id: Tracker del hijo - child_tracker_status_id: Tracker y estado del hijo - parent_status_id: Estado del padre - parent_tracker_id: Tracker del padre + label_filter_group_parent_child: Padre e hijo + label_filter_child_status_id: Estado del hijo + label_filter_child_tracker_id: Seguimiento del hijo + label_filter_child_tracker_status_id: Seguimiento y estado del hijo + label_filter_parent_status_id: Estado del padre + label_filter_parent_tracker_id: Seguimiento del padre + label_filter_root: Ticket raíz + label_filter_root_status_id: Estado del ticket raíz + label_filter_root_tracker_id: Seguimiento del ticket raíz diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 01b8192..eb6a824 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -1,7 +1,10 @@ fr: - label_group_parent_child: Parent et enfant - child_status_id: Statut de l'enfant - child_tracker_id: Tracker de l'enfant - child_tracker_status_id: Tracker et statut de l'enfant - parent_status_id: Statut du parent - parent_tracker_id: Tracker du parent + label_filter_group_parent_child: Parent et enfant + label_filter_child_status_id: Statut de l'enfant + label_filter_child_tracker_id: Suivi de l'enfant + label_filter_child_tracker_status_id: Tracker et statut de l'enfant + label_filter_parent_status_id: Statut du parent + label_filter_parent_tracker_id: Tracker du parent + label_filter_root: Ticket racine + label_filter_root_status_id: Statut du ticket racine + label_filter_root_tracker_id: Tracker du ticket racine diff --git a/config/locales/nl.yml b/config/locales/nl.yml index a4da113..4aae48b 100644 --- a/config/locales/nl.yml +++ b/config/locales/nl.yml @@ -1,7 +1,10 @@ nl: - label_group_parent_child: Parent en child - child_status_id: Child status - child_tracker_id: Child tracker - child_tracker_status_id: Child tracker and status - parent_status_id: Parent status - parent_tracker_id: Parent tracker + label_filter_group_parent_child: Parent en child + label_filter_child_status_id: Child status + label_filter_child_tracker_id: Child tracker + label_filter_child_tracker_status_id: Child tracker and status + label_filter_parent_status_id: Parent status + label_filter_parent_tracker_id: Parent tracker + label_filter_root: Root + label_filter_root_status_id: Root status + label_filter_root_tracker_id: Root tracker diff --git a/config/locales/ro.yml b/config/locales/ro.yml index 7bba9d3..1c498e4 100644 --- a/config/locales/ro.yml +++ b/config/locales/ro.yml @@ -1,7 +1,10 @@ ro: - label_group_parent_child: Părinte și copil - child_status_id: Stare copil - child_tracker_id: Tracker copil - child_tracker_status_id: Tracker și stare copil - parent_status_id: Stare părinte - parent_tracker_id: Tracker părinte + label_filter_group_parent_child: Părinte și copil + label_filter_child_status_id: Starea copilului + label_filter_child_tracker_id: Urmărirea copilului + label_filter_child_tracker_status_id: Urmărirea și starea copilului + label_filter_parent_status_id: Starea părintelui + label_filter_parent_tracker_id: Urmărirea părintelui + label_filter_root: Tichet principal + label_filter_root_status_id: Starea tichetului principal + label_filter_root_tracker_id: Urmărirea tichetului principal diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 466d76e..879eec3 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -1,7 +1,10 @@ zh: - label_group_parent_child: 父母和子女 - child_status_id: 子状态 - child_tracker_id: 子追踪器 - child_tracker_status_id: 子追踪器和状态 - parent_status_id: 父母状态 - parent_tracker_id: 父母追踪器 \ No newline at end of file + label_filter_group_parent_child: 父与子 + label_filter_child_status_id: 子状态 + label_filter_child_tracker_id: 子票据追踪 + label_filter_child_tracker_status_id: 子票据追踪及状态 + label_filter_parent_status_id: 父状态 + label_filter_parent_tracker_id: 父票据追踪 + label_filter_root: 根票据 + label_filter_root_status_id: 根票据状态 + label_filter_root_tracker_id: 根票据追踪 diff --git a/lib/redmine_parent_child_filters/patches/issue_query_patch.rb b/lib/redmine_parent_child_filters/patches/issue_query_patch.rb index a202249..c0359f2 100644 --- a/lib/redmine_parent_child_filters/patches/issue_query_patch.rb +++ b/lib/redmine_parent_child_filters/patches/issue_query_patch.rb @@ -6,27 +6,35 @@ module InstanceMethods def initialize_available_filters_with_pcf initialize_available_filters_without_pcf add_available_filter( - "rootissue_id", - :type => :tree, :label => :label_rootissue) + "root_id", + :type => :tree, :label => :label_filter_root) + add_available_filter( + "root_tracker_id", + type: :list, values: trackers.collect { |s| [s.name, s.id.to_s] }, label: :label_filter_root_tracker_id + ) + add_available_filter( + "root_status_id", + type: :list_status, values: lambda { issue_statuses_values }, label: :label_filter_root_status_id + ) add_available_filter( "parent_tracker_id", - type: :list, values: trackers.collect { |s| [s.name, s.id.to_s] }, label: :parent_tracker_id + type: :list, values: trackers.collect { |s| [s.name, s.id.to_s] }, label: :label_filter_parent_tracker_id ) add_available_filter( "parent_status_id", - type: :list_status, values: lambda { issue_statuses_values }, label: :parent_status_id + type: :list_status, values: lambda { issue_statuses_values }, label: :label_filter_parent_status_id ) add_available_filter( "child_tracker_id", - type: :list, values: trackers.collect { |s| [s.name, s.id.to_s] }, label: :child_tracker_id + type: :list, values: trackers.collect { |s| [s.name, s.id.to_s] }, label: :label_filter_child_tracker_id ) add_available_filter( "child_status_id", - type: :list_status, values: lambda { issue_statuses_values }, label: :child_status_id + type: :list_status, values: lambda { issue_statuses_values }, label: :label_filter_child_status_id ) end - def sql_for_rootissue_id_field(field, operator, value) + def sql_for_root_id_field(field, operator, value) case operator when "=" # accepts a comma separated list of ids @@ -45,6 +53,33 @@ def sql_for_rootissue_id_field(field, operator, value) end end + def sql_for_root_tracker_id_field(field, operator, value) + if operator == '=' + # Include issues which are their own root and match the tracker condition + # OR include issues where their root matches the tracker condition + "((#{Issue.table_name}.id = #{Issue.table_name}.root_id AND #{Issue.table_name}.tracker_id IN (#{value.join(',')})) OR (#{Issue.table_name}.root_id IN (SELECT id FROM #{Issue.table_name} WHERE tracker_id IN (#{value.join(',')}))))" + elsif operator == '!' + # Exclude issues which are their own root and match the tracker condition + # OR exclude issues where their root matches the tracker condition + "NOT ((#{Issue.table_name}.id = #{Issue.table_name}.root_id AND #{Issue.table_name}.tracker_id IN (#{value.join(',')})) OR (#{Issue.table_name}.root_id IN (SELECT id FROM #{Issue.table_name} WHERE tracker_id IN (#{value.join(',')}))))" + end + end + + def sql_for_root_status_id_field(field, operator, value) + case operator + when '=' + "((#{Issue.table_name}.id = #{Issue.table_name}.root_id AND #{Issue.table_name}.status_id IN (#{value.join(',')})) OR (#{Issue.table_name}.root_id IN (SELECT id FROM #{Issue.table_name} WHERE status_id IN (#{value.join(',')}))))" + when '!' + "NOT ((#{Issue.table_name}.id = #{Issue.table_name}.root_id AND #{Issue.table_name}.status_id IN (#{value.join(',')})) OR (#{Issue.table_name}.root_id IN (SELECT id FROM #{Issue.table_name} WHERE status_id IN (#{value.join(',')}))))" + when 'o' + "((#{Issue.table_name}.id = #{Issue.table_name}.root_id AND #{Issue.table_name}.status_id IN (SELECT id FROM #{IssueStatus.table_name} WHERE is_closed = #{ActiveRecord::Base.connection.quoted_false})) OR (#{Issue.table_name}.root_id IN (SELECT id FROM #{Issue.table_name} WHERE status_id IN (SELECT id FROM #{IssueStatus.table_name} WHERE is_closed = #{ActiveRecord::Base.connection.quoted_false}))))" + when 'c' + "((#{Issue.table_name}.id = #{Issue.table_name}.root_id AND #{Issue.table_name}.status_id IN (SELECT id FROM #{IssueStatus.table_name} WHERE is_closed = #{ActiveRecord::Base.connection.quoted_true})) OR (#{Issue.table_name}.root_id IN (SELECT id FROM #{Issue.table_name} WHERE status_id IN (SELECT id FROM #{IssueStatus.table_name} WHERE is_closed = #{ActiveRecord::Base.connection.quoted_true}))))" + when '*' + "(#{Issue.table_name}.id != #{Issue.table_name}.root_id)" + end + end + def sql_for_parent_tracker_id_field(field, operator, value) if operator == '=' "(#{Issue.table_name}.parent_id IN (SELECT id FROM #{Issue.table_name} WHERE tracker_id IN (#{value.join(',')})))" diff --git a/lib/redmine_parent_child_filters/patches/queries_helper_patch.rb b/lib/redmine_parent_child_filters/patches/queries_helper_patch.rb index 9682761..54f6d75 100644 --- a/lib/redmine_parent_child_filters/patches/queries_helper_patch.rb +++ b/lib/redmine_parent_child_filters/patches/queries_helper_patch.rb @@ -6,8 +6,8 @@ module Patches module QueriesHelperPatch module InstanceMethods def filters_options_for_select(query) - new_filters = %w[rootissue_id parent_tracker_id parent_status_id child_tracker_id child_status_id child_tracker_status_id] - new_group = :label_group_parent_child + new_filters = %w[root_id root_tracker_id root_status_id parent_tracker_id parent_status_id child_tracker_id child_status_id child_tracker_status_id] + new_group = :label_filter_group_parent_child ungrouped = [] grouped = {} query.available_filters.map do |field, field_options|