Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow plugins to bring their own miq_reports #19391

Merged
merged 1 commit into from
Oct 22, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions app/models/miq_report/seeding.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module MiqReport::Seeding
extend ActiveSupport::Concern

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

module ClassMethods
def seed
Expand Down Expand Up @@ -66,7 +66,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 +84,32 @@ def seed_record(path, report)
end
end

def template_type(path)
File.dirname(path).include?("reports") ? "report" : "compare"
end

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

def seed_core_files
[REPORT_DIR, COMPARE_DIR].flat_map { |dir| Dir.glob(dir.join("**", "*.yaml")).sort }
end

def seed_plugin_files
Vmdb::Plugins.flat_map do |plugin|
%w[reports compare].flat_map { |dir| Dir.glob(plugin.root.join("content", dir, "**", "*.yaml")).sort }
end
end

def seed_filename(path)
path.remove("#{REPORT_DIR}/").remove("#{COMPARE_DIR}/")
if File.dirname(path).include?("reports")
path.split("reports/").last
elsif File.dirname(path).include?("compare")
path.split("compare/").last
else
path
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realized that seed_filename is sometimes passed not the full path but just the filename from the db record here and here, so it is possible to not have either "reports" or "compare" in the path.

Since those records have the filename set by seed_filename(path) I don't think we could index_by(&:filename) which simplifies this method but want to check to see if I'm missing something.

end
end
end
end