Skip to content

Commit

Permalink
Convert my settings tabs to react
Browse files Browse the repository at this point in the history
  • Loading branch information
GilbertCherrie committed Nov 29, 2023
1 parent f493067 commit 05edebb
Show file tree
Hide file tree
Showing 36 changed files with 1,298 additions and 1,319 deletions.
97 changes: 0 additions & 97 deletions .haml-lint.yml

This file was deleted.

1 change: 1 addition & 0 deletions .haml-lint.yml
891 changes: 0 additions & 891 deletions .yarn/releases/yarn-4.0.0-rc.51.cjs

This file was deleted.

893 changes: 893 additions & 0 deletions .yarn/releases/yarn-4.0.2.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ enableGlobalCache: true

nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-4.0.0-rc.51.cjs
yarnPath: .yarn/releases/yarn-4.0.2.cjs
1 change: 0 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ def pp_options
:display => {
:startpage => "/dashboard/show",
:reporttheme => "MIQ",
:theme => "red", # Luminescent Blue
:taskbartext => true, # Show button text on taskbar
:vmcompare => "Compressed", # Start VM compare and drift in compressed mode
:hostcompare => "Compressed", # Start Host compare in compressed mode
Expand Down
141 changes: 18 additions & 123 deletions app/controllers/configuration_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def index
active_tab = 4 if active_tab.nil?
end
@tabform = params[:load_edit_err] ? @tabform : "ui_#{active_tab}"
set_tab_vars(active_tab)
edit
render :action => "show"
end
Expand Down Expand Up @@ -70,7 +71,8 @@ def edit

# New tab was pressed
def change_tab
assert_privileges('my_settings_admin')
assert_privileges('my_settings_view')
set_tab_vars(params['uib-tab'])
@tabform = "ui_" + params['uib-tab'] if params['uib-tab'] != "5"
edit
render :action => "show"
Expand All @@ -96,40 +98,10 @@ def filters_field_changed
end
end

# AJAX driven routine for gtl view selection
def view_selected
assert_privileges('my_settings_default_views')
# ui1 form
return unless load_edit("config_edit__ui1", "configuration")

@edit[:new][:views][VIEW_RESOURCES[params[:resource]]] = params[:view] # Capture the new view setting
session[:changed] = (@edit[:new] != @edit[:current])
@changed = session[:changed]
render :update do |page|
page << javascript_prologue
page << javascript_for_miq_button_visibility(@changed)
page.replace('tab_div', :partial => "ui_1")
end
end

# AJAX driven routine for theme selection
def theme_changed
assert_privileges('my_settings_visuals')
# ui1 theme changed
@edit = session[:edit]
@edit[:new][:display][:theme] = params[:theme] # Capture the new setting
session[:changed] = (@edit[:new] != @edit[:current])
@changed = session[:changed]
render :update do |page|
page << javascript_prologue
page.replace('tab_div', :partial => 'ui_1')
end
end

def update
assert_privileges('my_settings_admin')
assert_privileges('my_settings_default_filters')
set_tab_vars(@tabform.split('_').last)
if params["save"]
get_form_vars if @tabform != "ui_3"
case @tabform
when "ui_3" # User Filters tab
@edit = session[:edit]
Expand Down Expand Up @@ -213,7 +185,7 @@ def get_hr_str(hr)
end

def timeprofile_new
assert_privileges("timeprofile_new")
assert_privileges("my_settings_time_profiles")
@all_timezones = ActiveSupport::TimeZone.all.collect { |tz| ["(GMT#{tz.formatted_offset}) #{tz.name}", tz.name] }.freeze
@timeprofile = TimeProfile.new
@timeprofile_action = "timeprofile_new"
Expand All @@ -225,7 +197,7 @@ def timeprofile_new
end

def timeprofile_edit
assert_privileges("tp_edit")
assert_privileges("my_settings_time_profiles")
@all_timezones = ActiveSupport::TimeZone.all.collect { |tz| ["(GMT#{tz.formatted_offset}) #{tz.name}", tz.name] }.freeze
@timeprofile = TimeProfile.find(params[:id])
@timeprofile_action = "timeprofile_edit"
Expand All @@ -249,7 +221,7 @@ def timeprofile_edit

# Delete all selected or single displayed VM(s)
def timeprofile_delete
assert_privileges("tp_delete")
assert_privileges("my_settings_time_profiles")
timeprofiles = []
unless params[:id] # showing a list, scan all selected timeprofiles
timeprofiles = find_checked_items
Expand All @@ -274,11 +246,11 @@ def timeprofile_delete
end
process_timeprofiles(timeprofiles, "destroy") unless timeprofiles.empty?
end
set_form_vars
show_timeprofiles
end

def timeprofile_copy
assert_privileges("tp_copy")
assert_privileges("my_settings_time_profiles")
session[:set_copy] = "copy"
@all_timezones = ActiveSupport::TimeZone.all.collect { |tz| ["(GMT#{tz.formatted_offset}) #{tz.name}", tz.name] }.freeze
@in_a_form = true
Expand All @@ -295,26 +267,6 @@ def show
show_timeprofiles if params[:typ] == "timeprofiles"
end

def time_profile_form_fields
assert_privileges("tp_edit")
@timeprofile = TimeProfile.new if params[:id] == 'new'
@timeprofile = TimeProfile.find(params[:id]) if params[:id] != 'new'

render :json => {
:description => @timeprofile.description,
:admin_user => report_admin_user?,
:restricted_time_profile => @timeprofile.profile_type == "global" && !report_admin_user?,
:profile_type => @timeprofile.profile_type || "user",
:profile_tz => @timeprofile.tz.nil? ? "" : @timeprofile.tz,
:rollup_daily => !@timeprofile.rollup_daily_metrics.nil?,
:all_days => Array(@timeprofile.days).size == 7,
:days => Array(@timeprofile.days).uniq.sort,
:all_hours => Array(@timeprofile.hours).size == 24,
:hours => Array(@timeprofile.hours).uniq.sort,
:miq_reports_count => @timeprofile.miq_reports.count
}
end

def self.session_key_prefix
"configuration"
end
Expand Down Expand Up @@ -379,41 +331,20 @@ def build_tabs
end

@active_tab = @tabform.split("_").last

@labels = [_("Visual"), _("Default Filters"), _("Time Profiles")]
@tabs = []
@tabs.push(["1", _("Visual")]) if role_allows?(:feature => "my_settings_visuals")
@tabs.push(["3", _("Default Filters")]) if role_allows?(:feature => "my_settings_default_filters")
@tabs.push(["4", _("Time Profiles")]) if role_allows?(:feature => "my_settings_time_profiles")
end

def merge_in_user_settings(settings)
if (user_settings = current_user.try(:settings))
settings.each do |key, value|
value.merge!(user_settings[key]) unless user_settings[key].nil?
end
end
settings
end

# * start with DEFAULT_SETTINGS
# * merge in current session changes
# * merge in any settings from the DB if they exist
def init_settings
merge_in_user_settings(copy_hash(DEFAULT_SETTINGS))
end

def set_form_vars
case @tabform
when 'ui_1'
@edit = {
:current => init_settings,
:current => {},
:key => 'config_edit__ui1',
}

current_tz = @edit.fetch_path(:current, :display, :timezone)
if current_tz.blank?
@edit.store_path(:current, :display, :timezone, ::Settings.server.timezone)
end
when 'ui_3'
filters = MiqSearch.where(:search_type => "default")
current = filters.map do |filter|
Expand All @@ -431,54 +362,12 @@ def set_form_vars
:current => {},
:key => 'config_edit__ui4',
}
@edit[:timeprofile_id] = @timeprofile.try(:id)
if %w[timeprofile_new timeprofile_copy timeprofile_edit timeprofile_update].include?(params[:action])
@edit[:current] = {
:description => @timeprofile.description,
:profile_type => @timeprofile.profile_type || "user",
:profile_key => @timeprofile.profile_key,
:profile => {
:days => Array(@timeprofile.days).uniq.sort,
:hours => Array(@timeprofile.hours).uniq.sort,
:tz => @timeprofile.tz,
},
:rollup_daily => @timeprofile.rollup_daily_metrics,
}
@edit[:all_days] = @edit.fetch_path(:current, :profile, :days).length == 7
@edit[:all_hours] = @edit.fetch_path(:current, :profile, :hours).length == 24
end
show_timeprofiles
end
@edit[:new] = copy_hash(@edit[:current])
session[:edit] = @edit
end

def get_form_vars
@edit = session[:edit]
case @tabform
when "ui_1" # Visual Settings tab
@edit[:new][:perpage][:grid] = params[:perpage_grid].to_i if params[:perpage_grid]
@edit[:new][:perpage][:tile] = params[:perpage_tile].to_i if params[:perpage_tile]
@edit[:new][:perpage][:list] = params[:perpage_list].to_i if params[:perpage_list]
@edit[:new][:perpage][:reports] = params[:perpage_reports].to_i if params[:perpage_reports]
@edit[:new][:display][:theme] = params[:display_theme] unless params[:display_theme].nil?
@edit[:new][:display][:bg_color] = params[:bg_color] unless params[:bg_color].nil?
@edit[:new][:display][:reporttheme] = params[:display_reporttheme] unless params[:display_reporttheme].nil?
@edit[:new][:display][:dashboards] = params[:display_dashboards] unless params[:display_dashboards].nil?
@edit[:new][:display][:timezone] = params[:display_timezone] unless params[:display_timezone].nil?
@edit[:new][:display][:startpage] = params[:start_page] unless params[:start_page].nil?
@edit[:new][:display][:locale] = params[:display_locale] if params[:display_locale]
@edit[:new][:display][:compare] = params[:display][:compare] if !params[:display].nil? && !params[:display][:compare].nil?
@edit[:new][:display][:drift] = params[:display][:drift] if !params[:display].nil? && !params[:display][:drift].nil?
when "ui_3" # Visual Settings tab
@edit[:new][:display][:compare] = params[:display][:compare] if !params[:display].nil? && !params[:display][:compare].nil?
@edit[:new][:display][:drift] = params[:display][:drift] if !params[:display].nil? && !params[:display][:drift].nil?
when "ui_4" # Visual Settings tab
@edit[:new][:display][:compare] = params[:display][:compare] if !params[:display].nil? && !params[:display][:compare].nil?
@edit[:new][:display][:drift] = params[:display][:drift] if !params[:display].nil? && !params[:display][:drift].nil?
end
end

def get_session_data
super
@tabform = session[:config_tabform] if session[:config_tabform]
Expand All @@ -495,6 +384,12 @@ def set_session_data
session[:zone_options] = @zone_options
end

def set_tab_vars(current_tab)
@path = '/configuration/change_tab/'
@current_tab = current_tab.to_s
@check_for_changes = true
end

def merge_settings(user_settings, global_settings)
prune_old_settings(user_settings ? user_settings.merge(global_settings) : global_settings)
end
Expand Down
14 changes: 9 additions & 5 deletions app/controllers/service_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def button
service_retire
when 'service_retire_now'
service_retire_now
when 'service_reconfigure'
javascript_redirect(:action => 'service_reconfigure', :id => params[:id])
when "custom_button"
@display == 'generic_objects' ? generic_object_custom_buttons : custom_buttons
else
Expand Down Expand Up @@ -74,16 +76,18 @@ def edit
checked[0] = params[:id] if checked.blank? && params[:id]
@service = find_record_with_rbac(Service, checked[0])
@in_a_form = true
drop_breadcrumb(:name => _("Edit Service\"%{name}\"") % {:name => @service.name}, :url => "/service/edit/#{@service.id}")
drop_breadcrumb(:name => _("Edit Service \"%{name}\"") % {:name => @service.name}, :url => "/service/edit/#{@service.id}")
end

def service_reconfigure
service = Service.find_by(:id => params[:id])
assert_privileges('service_reconfigure')

service = find_record_with_rbac(Service, params[:id])
service_template = service.service_template
resource_action = service_template.resource_actions.find_by(:action => 'Reconfigure') if service_template

@right_cell_text = _("Reconfigure Service \"%{name}\"") % {:name => service.name}
dialog_locals = {:resource_action_id => resource_action.id, :target_id => service.id}
@dialog_locals = {:resource_action_id => resource_action.id, :target_id => service.id}
@in_a_form = true
drop_breadcrumb(:name => _("Reconfigure Service \"%{name}\"") % {:name => service.name}, :url => "/service/service_reconfigure/#{service.id}")
end

def service_form_fields
Expand Down
3 changes: 0 additions & 3 deletions app/helpers/configuration_helper.rb

This file was deleted.

Loading

0 comments on commit 05edebb

Please sign in to comment.