diff --git a/app/models/cost_query/custom_field_mixin.rb b/app/models/cost_query/custom_field_mixin.rb index db14ca6686..30864ba85d 100644 --- a/app/models/cost_query/custom_field_mixin.rb +++ b/app/models/cost_query/custom_field_mixin.rb @@ -20,6 +20,10 @@ module CostQuery::CustomFieldMixin @all ||= generate_subclasses end + def reset! + @all = nil + end + def generate_subclasses IssueCustomField.all.map do |field| class_name = class_name_for field.name diff --git a/init.rb b/init.rb index 2e01539bef..d528a18ed5 100644 --- a/init.rb +++ b/init.rb @@ -3,6 +3,11 @@ require 'redmine' # Hooks require 'view_projects_show_sidebar_bottom_hook' +Dispatcher.to_prepare do + # Model Patches + require_dependency 'reporting_issue_custom_field_patch' +end + Redmine::Plugin.register :redmine_reporting do name 'Reporting Plugin' author 'Konstantin Haase, Philipp Tessenow @ finnlabs' diff --git a/lib/reporting_issue_custom_field_patch.rb b/lib/reporting_issue_custom_field_patch.rb new file mode 100644 index 0000000000..2a09b6c603 --- /dev/null +++ b/lib/reporting_issue_custom_field_patch.rb @@ -0,0 +1,26 @@ +module ReportingIssueCustomFieldPatch + def self.included(base) # :nodoc: + base.send(:include, InstanceMethods) + + # Same as typing in the class + base.class_eval do + unloadable + after_save :generate_custom_field_filters + after_save :generate_custom_field_group_bys + end + end + + module InstanceMethods + def generate_custom_field_filters + CostQuery::Filter.reset! + CostQuery::Filter::CustomFieldEntries.reset! + end + + def generate_custom_field_group_bys + CostQuery::GroupBy.reset! + CostQuery::GroupBy::CustomFieldEntries.reset! + end + end +end + +IssueCustomField.send(:include, ReportingIssueCustomFieldPatch)