Skip to content

Commit

Permalink
Merge pull request #22087 from nasark/miq_widgets_pluggability
Browse files Browse the repository at this point in the history
Make MIQ widgets pluggable
  • Loading branch information
agrare authored Aug 31, 2022
2 parents 91d9369 + 2c8a973 commit e0864db
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
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) }
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

0 comments on commit e0864db

Please sign in to comment.