Filter on jobs in time reports

Completes #2107
This commit is contained in:
Trevor Vallender 2023-11-27 14:20:28 +00:00
parent 0a265fbbce
commit 62d924dadc
4 changed files with 32 additions and 6 deletions

View File

@ -1,2 +1,3 @@
en:
field_jobs: Jobs
field_job: Job

View File

@ -15,5 +15,6 @@ Redmine::Plugin.register :jobs do
Rails.logger.info "Patch Jobs"
TimeEntryQuery.send(:include, TimeEntryQueryPatch)
TimeEntry.send(:include, TimeEntryPatch)
Project.send(:include, ProjectPatch)
end
end

11
lib/project_patch.rb Normal file
View File

@ -0,0 +1,11 @@
# frozen_string_literal: true
require_dependency 'project'
module ProjectPatch
extend ActiveSupport::Concern
included do
has_many :jobs
end
end

View File

@ -9,18 +9,18 @@ module TimeEntryQueryPatch
included do
include InstanceMethods
# alias_method :initialize_available_filters_without_jobs, :initialize_available_filters
# alias_method :initialize_available_filters, :initialize_available_filters_with_jobs
alias_method :initialize_available_filters_without_jobs, :initialize_available_filters
alias_method :initialize_available_filters, :initialize_available_filters_with_jobs
alias_method :available_columns_without_jobs, :available_columns
alias_method :available_columns, :available_columns_with_jobs
end
module InstanceMethods
# def initialize_available_filters_with_jobs
# initialize_available_filters_without_jobs
# initialize_issue_jobs_filter
# end
def initialize_available_filters_with_jobs
initialize_available_filters_without_jobs
initialize_issue_jobs_filter
end
def available_columns_with_jobs
if @available_columns.nil?
@ -32,8 +32,21 @@ module TimeEntryQueryPatch
@available_columns
end
def initialize_issue_jobs_filter(position: nil)
add_available_filter("job_id", order: position,
type: :list_optional,
values: jobs_list
)
end
def sql_for_issue_jobs_field(_field, operator, values)
build_sql_for_jobs_field klass: Issue, operator: operator, values: values
end
def jobs_list
Job.where(project: [project, project&.parent]).map do |job|
[job.name, job.id.to_s]
end
end
end
end