Skip to content

Commit

Permalink
### 0.0.4
Browse files Browse the repository at this point in the history
* Filter on `a_parent_tracker` (any)
* Filter on `a_parent_status` (any)
* Add plugin settings to enable filters
  • Loading branch information
Jan Catrysse committed Aug 8, 2023
1 parent fd00b7d commit afc7bb6
Show file tree
Hide file tree
Showing 13 changed files with 198 additions and 16 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# CHANGELOG
### 0.0.4
* Filter on `a_parent_tracker` (any)
* Filter on `a_parent_status` (any)
* Add plugin settings to enable filters

### 0.0.3
* Filter on `root`
* Filter on `root_tracker`
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Link to Redmine plugin page: https://www.redmine.org/plugins/redmine_parent_chil
* Filter on `root_status`
* Filter on `parent_tracker`
* Filter on `parent_status`
* Filter on `parent_tracker` (any parent)
* Filter on `parent_status` (any parent)
* Filter on `child_tracker`
* Filter on `child_status`
* Operator `not equal to` on `start_date` and `end_date`
Expand Down
45 changes: 45 additions & 0 deletions app/views/settings/_parent_child_filters_settings.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<p>
<%= label_tag 'enable_root_id_filter', t('labels.enable_root_id_filter') %>
<%= check_box_tag 'settings[enable_root_id_filter]', 1,
@settings['enable_root_id_filter'] %>
</p>
<p>
<%= label_tag 'enable_root_tracker_id_filter', t('labels.enable_root_tracker_id_filter') %>
<%= check_box_tag 'settings[enable_root_tracker_id_filter]', 1,
@settings['enable_root_tracker_id_filter'] %>
</p>
<p>
<%= label_tag 'enable_root_status_id_filter', t('labels.enable_root_status_id_filter') %>
<%= check_box_tag 'settings[enable_root_status_id_filter]', 1,
@settings['enable_root_status_id_filter'] %>
</p>
<p>
<%= label_tag 'enable_parent_tracker_id_filter', t('labels.enable_parent_tracker_id_filter') %>
<%= check_box_tag 'settings[enable_parent_tracker_id_filter]', 1,
@settings['enable_parent_tracker_id_filter'] %>
</p>
<p>
<%= label_tag 'enable_parent_status_id_filter', t('labels.enable_parent_status_id_filter') %>
<%= check_box_tag 'settings[enable_parent_status_id_filter]', 1,
@settings['enable_parent_status_id_filter'] %>
</p>
<p>
<%= label_tag 'enable_a_parent_tracker_id_filter', t('labels.enable_a_parent_tracker_id_filter') %>
<%= check_box_tag 'settings[enable_a_parent_tracker_id_filter]', 1,
@settings['enable_a_parent_tracker_id_filter'] %>
</p>
<p>
<%= label_tag 'enable_a_parent_status_id_filter', t('labels.enable_a_parent_status_id_filter') %>
<%= check_box_tag 'settings[enable_a_parent_status_id_filter]', 1,
@settings['enable_a_parent_status_id_filter'] %>
</p>
<p>
<%= label_tag 'enable_child_tracker_id_filter', t('labels.enable_child_tracker_id_filter') %>
<%= check_box_tag 'settings[enable_child_tracker_id_filter]', 1,
@settings['enable_child_tracker_id_filter'] %>
</p>
<p>
<%= label_tag 'enable_child_status_id_filter', t('labels.enable_child_status_id_filter') %>
<%= check_box_tag 'settings[enable_child_status_id_filter]', 1,
@settings['enable_child_status_id_filter'] %>
</p>
12 changes: 11 additions & 1 deletion config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,19 @@ de:
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_a_parent_status_id: Status der Eltern (jeder)
label_filter_a_parent_tracker_id: Verfolgung der Eltern (jeder)
label_filter_root: Hauptticket
label_filter_root_status_id: Status des Haupttickets
label_filter_root_tracker_id: Verfolgung des Haupttickets
label_enable_root_id_filter: Haupttickets Filter aktivieren
label_enable_root_tracker_id_filter: Haupttickets Trackerfilter aktivieren
label_enable_root_status_id_filter: Haupttickets Statusfilter aktivieren
label_enable_parent_tracker_id_filter: Eltern Trackerfilter aktivieren
label_enable_parent_status_id_filter: Eltern Statusfilter aktivieren
label_enable_a_parent_tracker_id_filter: Eltern Trackerfilter aktivieren (alle)
label_enable_a_parent_status_id_filter: Eltern Statusfilter aktivieren (alle)
label_enable_child_tracker_id_filter: Kindes Trackerfilter aktivieren
label_enable_child_status_id_filter: Kindes Statusfilter aktivieren
12 changes: 11 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,19 @@ en:
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_a_parent_status_id: Parent (any) status
label_filter_a_parent_tracker_id: Parent (any) tracker
label_filter_root: Root
label_filter_root_status_id: Root status
label_filter_root_tracker_id: Root tracker
label_enable_root_id_filter: Enable Root Filter
label_enable_root_tracker_id_filter: Enable Root Tracker Filter
label_enable_root_status_id_filter: Enable Root Status Filter
label_enable_parent_tracker_id_filter: Enable Parent Tracker Filter
label_enable_parent_status_id_filter: Enable Parent Status Filter
label_enable_a_parent_tracker_id_filter: Enable Parent (any) Tracker Filter
label_enable_a_parent_status_id_filter: Enable Parent (any) Status Filter
label_enable_child_tracker_id_filter: Enable Child Tracker Filter
label_enable_child_status_id_filter: Enable Child Status Filter
12 changes: 11 additions & 1 deletion config/locales/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,19 @@ es:
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_a_parent_status_id: Estado del padre (todo)
label_filter_a_parent_tracker_id: Seguimiento del padre (todo)
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
label_enable_root_id_filter: Habilitar filtro raíz
label_enable_root_tracker_id_filter: Habilitar el filtro del rastreador raíz
label_enable_root_status_id_filter: Habilitar el filtro de estado raíz
label_enable_parent_tracker_id_filter : Habilitar filtro de rastreador parental
label_enable_parent_status_id_filter: habilitar el filtro de estado parental
label_enable_a_parent_tracker_id_filter: Habilitar filtro de rastreador parental (todos)
label_enable_a_parent_status_id_filter: habilitar el filtro de estado parental (todos)
label_enable_child_tracker_id_filter : Habilitar filtro de rastreador de niños
label_enable_child_status_id_filter: Habilitar filtro de estado de niños
12 changes: 11 additions & 1 deletion config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,19 @@ fr:
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_a_parent_status_id: Statut des parents (tout)
label_filter_a_parent_tracker_id: Tracker des parents (tout)
label_filter_root: Ticket racine
label_filter_root_status_id: Statut du ticket racine
label_filter_root_tracker_id: Tracker du ticket racine
label_enable_root_id_filter: Activer le filtre racine
label_enable_root_tracker_id_filter: Activer le filtre de tracker du ticket racine
label_enable_root_status_id_filter: Activer le filtre de statut du ticket racine
label_enable_parent_tracker_id_filter: Activer le filtre de tracker du parent
label_enable_parent_status_id_filter: Activer le filtre de statut du parent
label_enable_a_parent_tracker_id_filter: Activer le filtre de tracker parent (tout)
label_enable_a_parent_status_id_filter: Activer le filtre de statut parent (tout)
label_enable_child_tracker_id_filter: Activer le filtre de suivi de l'enfant
label_enable_child_status_id_filter: Activer le filtre de statut de l'enfant
12 changes: 11 additions & 1 deletion config/locales/nl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,19 @@ nl:
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_a_parent_status_id: Parent (alle) status
label_filter_a_parent_tracker_id: Parent (alle) tracker
label_filter_root: Root
label_filter_root_status_id: Root status
label_filter_root_tracker_id: Root tracker
label_enable_root_id_filter: Enable Root Filter
label_enable_root_tracker_id_filter: Root Tracker Filter inschakelen
label_enable_root_status_id_filter: Root Status Filter inschakelen
label_enable_parent_tracker_id_filter: Parent Tracker Filter inschakelen
label_enable_parent_status_id_filter: Parent Status Filter inschakelen
label_enable_a_parent_tracker_id_filter: Parent (any) Tracker Filter inschakelen
label_enable_a_parent_status_id_filter: Parent (any) Status Filter inschakelen
label_enable_child_tracker_id_filter: Child Tracker Filter inschakelen
label_enable_child_status_id_filter: Child Status Filter inschakelen
12 changes: 11 additions & 1 deletion config/locales/ro.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,19 @@ ro:
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_a_parent_status_id: Starea părintelui (toţi)
label_filter_a_parent_tracker_id: Urmărirea părintelui (toţi)
label_filter_root: Tichet principal
label_filter_root_status_id: Starea tichetului principal
label_filter_root_tracker_id: Urmărirea tichetului principal
label_enable_root_id_filter: Activați filtrul rădăcină
label_enable_root_tracker_id_filter: Activați filtrul Root Tracker
label_enable_root_status_id_filter: Activați filtrul de stare rădăcină
label_enable_parent_tracker_id_filter: Activați filtrul de urmărire parentală
label_enable_parent_status_id_filter: Activați filtrul de stare parentală
label_enable_a_parent_tracker_id_filter: Activați filtrul de urmărire părinte (orice).
label_enable_a_parent_status_id_filter: Activați filtrul de stare Parent (orice).
label_enable_child_tracker_id_filter: Activați filtrul de urmărire a copiilor
label_enable_child_status_id_filter: Activați filtrul pentru starea copilului
12 changes: 11 additions & 1 deletion config/locales/zh.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,19 @@ zh:
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_a_parent_status_id: 父(任何)状态
label_filter_a_parent_tracker_id: 父(任何)跟踪器
label_filter_root: 根票据
label_filter_root_status_id: 根票据状态
label_filter_root_tracker_id: 根票据追踪
label_enable_root_id_filter: 启用根过滤器
label_enable_root_tracker_id_filter: 启用根跟踪器过滤器
label_enable_root_status_id_filter: 启用根状态过滤器
label_enable_parent_tracker_id_filter: 启用父跟踪器过滤器
label_enable_parent_status_id_filter: 启用育儿状态过滤器
label_enable_a_parent_tracker_id_filter: 启用父跟踪器过滤器(全部)
label_enable_a_parent_status_id_filter: 启用父状态过滤器(全部)
label_enable_child_tracker_id_filter: 启用子跟踪器过滤器
label_enable_child_status_id_filter: 启用子状态过滤器
14 changes: 13 additions & 1 deletion init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,23 @@
name 'Parent Child Filters Plugin'
author 'Jan Catrysse'
description 'Search issues by parent and child tracker and status'
version '0.0.3'
version '0.0.4'
url 'https://github.com/jcatrysse/redmine_parent_child_filters'
author_url 'https://github.com/jcatrysse'

requires_redmine version_or_higher: '4.0'

settings default: {
'enable_root_id_filter' => true,
'enable_root_tracker_id_filter' => true,
'enable_root_status_id_filter' => true,
'enable_parent_tracker_id_filter' => true,
'enable_parent_status_id_filter' => true,
'enable_a_parent_tracker_id_filter' => true,
'enable_a_parent_status_id_filter' => true,
'enable_child_tracker_id_filter' => true,
'enable_child_status_id_filter' => true,
}, partial: 'settings/parent_child_filters_settings'
end

require File.dirname(__FILE__) + '/lib/redmine_parent_child_filters/patches/issue_query_patch'
Expand Down
62 changes: 55 additions & 7 deletions lib/redmine_parent_child_filters/patches/issue_query_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,51 @@ module IssueQueryPatch
module InstanceMethods
def initialize_available_filters_with_pcf
initialize_available_filters_without_pcf

add_available_filter(
"root_id",
:type => :tree, :label => :label_filter_root)
:type => :tree, :label => :label_filter_root
) if Setting.plugin_redmine_parent_child_filters['enable_root_id_filter']

add_available_filter(
"root_tracker_id",
type: :list, values: trackers.collect { |s| [s.name, s.id.to_s] }, label: :label_filter_root_tracker_id
)
) if Setting.plugin_redmine_parent_child_filters['enable_root_tracker_id_filter']

add_available_filter(
"root_status_id",
type: :list_status, values: lambda { issue_statuses_values }, label: :label_filter_root_status_id
)
) if Setting.plugin_redmine_parent_child_filters['enable_root_status_id_filter']

add_available_filter(
"parent_tracker_id",
type: :list, values: trackers.collect { |s| [s.name, s.id.to_s] }, label: :label_filter_parent_tracker_id
)
) if Setting.plugin_redmine_parent_child_filters['enable_parent_tracker_id_filter']

add_available_filter(
"parent_status_id",
type: :list_status, values: lambda { issue_statuses_values }, label: :label_filter_parent_status_id
)
) if Setting.plugin_redmine_parent_child_filters['enable_parent_status_id_filter']

add_available_filter(
"a_parent_tracker_id",
type: :list, values: trackers.collect { |s| [s.name, s.id.to_s] }, label: :label_filter_a_parent_tracker_id
) if Setting.plugin_redmine_parent_child_filters['enable_a_parent_tracker_id_filter']

add_available_filter(
"a_parent_status_id",
type: :list_status, values: lambda { issue_statuses_values }, label: :label_filter_a_parent_status_id
) if Setting.plugin_redmine_parent_child_filters['enable_a_parent_status_id_filter']

add_available_filter(
"child_tracker_id",
type: :list, values: trackers.collect { |s| [s.name, s.id.to_s] }, label: :label_filter_child_tracker_id
)
) if Setting.plugin_redmine_parent_child_filters['enable_child_tracker_id_filter']

add_available_filter(
"child_status_id",
type: :list_status, values: lambda { issue_statuses_values }, label: :label_filter_child_status_id
)
) if Setting.plugin_redmine_parent_child_filters['enable_child_status_id_filter']
end

def sql_for_root_id_field(field, operator, value)
Expand Down Expand Up @@ -103,6 +121,36 @@ def sql_for_parent_status_id_field(field, operator, value)
end
end

def sql_for_a_parent_tracker_id_field(field, operator, value)
subquery = "EXISTS (SELECT 1 FROM #{Issue.table_name} AS ancestor WHERE child.lft > ancestor.lft AND child.rgt < ancestor.rgt AND child.root_id = ancestor.root_id AND ancestor.tracker_id IN (#{value.join(',')}))"

case operator
when '='
"(#{Issue.table_name}.id IN (SELECT child.id FROM #{Issue.table_name} AS child WHERE #{subquery}))"
when '!'
"(#{Issue.table_name}.id NOT IN (SELECT child.id FROM #{Issue.table_name} AS child WHERE #{subquery}))"
end
end

def sql_for_a_parent_status_id_field(field, operator, value)
subquery = "EXISTS (SELECT 1 FROM #{Issue.table_name} AS ancestor WHERE child.lft > ancestor.lft AND child.rgt < ancestor.rgt AND child.root_id = ancestor.root_id AND ancestor.status_id IN (#{value.join(',')}))"

case operator
when '='
"(#{Issue.table_name}.id IN (SELECT child.id FROM #{Issue.table_name} AS child WHERE #{subquery}))"
when '!'
"(#{Issue.table_name}.id NOT IN (SELECT child.id FROM #{Issue.table_name} AS child WHERE #{subquery}))"
when 'o' # open issues
open_subquery = "EXISTS (SELECT 1 FROM #{Issue.table_name} AS ancestor WHERE child.lft > ancestor.lft AND child.rgt < ancestor.rgt AND child.root_id = ancestor.root_id AND ancestor.status_id IN (SELECT id FROM #{IssueStatus.table_name} WHERE is_closed = #{ActiveRecord::Base.connection.quoted_false}))"
"(#{Issue.table_name}.id IN (SELECT child.id FROM #{Issue.table_name} AS child WHERE #{open_subquery}))"
when 'c' # closed issues
closed_subquery = "EXISTS (SELECT 1 FROM #{Issue.table_name} AS ancestor WHERE child.lft > ancestor.lft AND child.rgt < ancestor.rgt AND child.root_id = ancestor.root_id AND ancestor.status_id IN (SELECT id FROM #{IssueStatus.table_name} WHERE is_closed = #{ActiveRecord::Base.connection.quoted_true}))"
"(#{Issue.table_name}.id IN (SELECT child.id FROM #{Issue.table_name} AS child WHERE #{closed_subquery}))"
when '*' # all issues
nil # return nil to include all issues regardless of status
end
end

def sql_for_child_tracker_id_field(field, operator, value)
tracker_filter = ''
case operator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Patches
module QueriesHelperPatch
module InstanceMethods
def filters_options_for_select(query)
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_filters = %w[root_id root_tracker_id root_status_id parent_id parent_tracker_id parent_status_id a_parent_tracker_id a_parent_status_id child_id child_tracker_id child_status_id]
new_group = :label_filter_group_parent_child
ungrouped = []
grouped = {}
Expand Down

0 comments on commit afc7bb6

Please sign in to comment.