Skip to content

Commit

Permalink
Allow plugins to bring their own miq_reports
Browse files Browse the repository at this point in the history
Check vmdb::plugins for product/reports and product/compare when seeding
MiqReports
  • Loading branch information
agrare committed Oct 11, 2019
1 parent cd215c7 commit e0f4511
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions app/models/miq_report/seeding.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
module MiqReport::Seeding
extend ActiveSupport::Concern

REPORT_DIR = Rails.root.join("product/reports")
COMPARE_DIR = Rails.root.join("product/compare")
RELATIVE_REPORT_DIR = "product/reports".freeze
RELATIVE_COMPARE_DIR = "product/compare".freeze
REPORT_DIR = Rails.root.join(RELATIVE_REPORT_DIR).freeze
COMPARE_DIR = Rails.root.join(RELATIVE_COMPARE_DIR).freeze

module ClassMethods
def seed
Expand Down Expand Up @@ -66,7 +68,7 @@ def seed_record(path, report)
attrs[:priority] = File.basename(path).split("_").first.to_i
attrs[:rpt_group] = File.basename(File.dirname(path)).split("_").last
attrs[:rpt_type] = "Default"
attrs[:template_type] = path.start_with?(REPORT_DIR.to_s) ? "report" : "compare"
attrs[:template_type] = template_type(path)

begin
report.update!(attrs)
Expand All @@ -84,12 +86,34 @@ def seed_record(path, report)
end
end

def template_type(path)
path.include?(RELATIVE_REPORT_DIR.to_s) ? "report" : "compare"
end

def seed_files
seed_core_files + seed_plugin_files
end

def seed_core_files
Dir.glob(REPORT_DIR.join("**/*.yaml")).sort + Dir.glob(COMPARE_DIR.join("**/*.yaml")).sort
end

def seed_plugin_files
Vmdb::Plugins.flat_map do |plugin|
Dir.glob(plugin.root.join("#{RELATIVE_REPORT_DIR}/**/*.yaml")).sort + Dir.glob(plugin.root.join("#{RELATIVE_COMPARE_DIR}/**/*.yaml")).sort
end
end

def seed_filename(path)
path.remove("#{REPORT_DIR}/").remove("#{COMPARE_DIR}/")
send("seed_#{template_type(path)}", path)
end

def seed_report_filename(path)
path.split("#{RELATIVE_REPORT_DIR}/").last
end

def seed_compare_filename(path)
path.split("#{RELATIVE_COMPARE_DIR}/").last
end
end
end

0 comments on commit e0f4511

Please sign in to comment.