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

Make MIQ widgets pluggable #22087

Merged
merged 1 commit into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
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
10 changes: 1 addition & 9 deletions app/models/miq_widget.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class MiqWidget < ApplicationRecord
include YAMLImportExportMixin
acts_as_miq_set_member

WIDGET_DIR = File.expand_path(File.join(Rails.root, "product/dashboard/widgets"))
WIDGET_REPORT_SOURCE = "Generated for widget".freeze

before_destroy :destroy_schedule
Expand Down Expand Up @@ -458,7 +457,7 @@ def self.get_group(group)
end

def self.sync_from_dir
Dir.glob(File.join(WIDGET_DIR, "*.yaml")).sort.each { |f| sync_from_file(f) }
agrare marked this conversation as resolved.
Show resolved Hide resolved
Vmdb::Plugins.miq_widgets_content.sort.each { |f| sync_from_file(f) }
end

def self.sync_from_file(filename)
Expand Down Expand Up @@ -556,13 +555,6 @@ def self.seed
sync_from_dir
end

def self.seed_widget(pattern)
files = Dir.glob(File.join(WIDGET_DIR, "*#{pattern}*"))
files.collect do |f|
sync_from_file(f)
end
end

def save_with_shortcuts(shortcuts) # [[<shortcut.id>, <widget_shortcut.description>], ...]
transaction do
ws = [] # Create an array of widget shortcuts
Expand Down
4 changes: 4 additions & 0 deletions lib/vmdb/plugins.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ def automate_domains
end
end

def miq_widgets_content
@miq_widgets_content ||= Dir.glob(Rails.root.join("product/dashboard/widgets", "*")) + flat_map { |engine| content_directories(engine, "dashboard/widgets") }
end

def provider_plugins
@provider_plugins ||= select { |engine| engine.name.start_with?("ManageIQ::Providers::") }
end
Expand Down
4 changes: 3 additions & 1 deletion spec/lib/task_helpers/exports/widgets_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
Dir.mktmpdir('miq_exp_dir')
end

let(:widget_path) { Rails.root.join("product/dashboard/widgets/chart_vendor_and_guest_os.yaml") }

before do
EvmSpecHelper.local_miq_server

MiqReport.seed_report("Vendor and Guest OS")
MiqWidget.seed_widget("chart_vendor_and_guest_os")
MiqWidget.sync_from_file(widget_path)
MiqWidget.sync_from_hash(YAML.safe_load("
description: Test Widget
title: Test Widget
Expand Down
4 changes: 3 additions & 1 deletion spec/models/miq_widget/chart_content_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
RSpec.describe "Widget Chart Content" do
let(:widget) { MiqWidget.find_by(:description => "chart_vendor_and_guest_os") }
let(:widget_path) { Rails.root.join("product/dashboard/widgets/chart_vendor_and_guest_os.yaml") }

before do
EvmSpecHelper.local_miq_server

MiqReport.seed_report("Vendor and Guest OS")
MiqWidget.seed_widget("chart_vendor_and_guest_os")
MiqWidget.sync_from_file(widget_path)

@role = FactoryBot.create(:miq_user_role)
@group = FactoryBot.create(:miq_group, :miq_user_role => @role)
Expand Down
3 changes: 2 additions & 1 deletion spec/models/miq_widget_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -684,10 +684,11 @@ def add_dashboard_for_user(db_name, userid, group)

context "multiple groups" do
let(:widget) { MiqWidget.find_by(:description => "chart_vendor_and_guest_os") }
let(:widget_path) { Rails.root.join("product/dashboard/widgets/chart_vendor_and_guest_os.yaml") }

before do
MiqReport.seed_report("Vendor and Guest OS")
MiqWidget.seed_widget("chart_vendor_and_guest_os")
MiqWidget.sync_from_file(widget_path)

# tests are written for timezone_matters = true
widget.options[:timezone_matters] = true if widget.options
Expand Down