Skip to content

Commit

Permalink
Catalog de explorization initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffibm committed Aug 3, 2023
1 parent f2775e1 commit 84dada7
Show file tree
Hide file tree
Showing 21 changed files with 326 additions and 120 deletions.
3 changes: 3 additions & 0 deletions app/assets/stylesheets/service_template_catalog.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the ServiceTemplateCatalog controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: https://sass-lang.com/
2 changes: 1 addition & 1 deletion app/controllers/application_controller/explorer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def tree_select(node_info = false)
self.x_node = params[:id]

assert_accordion_and_tree_privileges(x_active_tree)

if node_info
get_node_info(x_node)
replace_right_cell(:nodetype => x_node)
Expand Down
190 changes: 111 additions & 79 deletions app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class CatalogController < ApplicationController
require 'byebug'
include AutomateTreeHelper
include Mixins::ServiceDialogCreationMixin
include Mixins::BreadcrumbsMixin
Expand All @@ -24,6 +25,22 @@ def index
redirect_to(:action => 'explorer')
end

def service_catalogs
assert_privileges("service_catalogs_show_list")
end

def catalog_items
assert_privileges("catalog_itemss_show_list")
end

def orchestration_templates
assert_privileges("orchestration_templates_show_list")
end

def catalogs
assert_privileges("catalogs_show_list")
end

CATALOG_X_BUTTON_ALLOWED_ACTIONS = {
'ab_button_new' => :ab_button_new,
'ab_button_edit' => :ab_button_edit,
Expand Down Expand Up @@ -84,6 +101,14 @@ def x_button
catalogitem_new
].freeze

def catalog_item
stc = ServiceTemplateCatalog.find(params[:id].to_i)
@record = stc.service_templates.where("id = ?", params[:item].to_i)&.first
identify_catalog(@record.id)
@title = @record.name
@lastaction = "show"
end

def assert_privileges_for_servicetemplate_edit
if params[:pressed].present? && EDIT_CATALOG_FEATURES.include?(params[:pressed])
assert_privileges(params[:pressed])
Expand Down Expand Up @@ -323,7 +348,7 @@ def atomic_form_field_changed
# VM or Template show selected, redirect to proper controller
def show
assert_privileges("catalog_items_view")

byebug
@sb[:action] = nil
@explorer = true if request.xml_http_request? # Ajax request means in explorer
record = ServiceTemplate.find(params[:id])
Expand All @@ -338,43 +363,43 @@ def show
end
end

def explorer
@explorer = true
@lastaction = "explorer"
@report_deleted = params[:report_deleted] == 'true' if params[:report_deleted]
@sb[:action] = nil

# if AJAX request, replace right cell, and return
if request.xml_http_request?
replace_right_cell
return
end

build_accordions_and_trees

if params[:id] && !params[:button] # If a tree node id came in, show in one of the trees
@nodetype, id = parse_nodetype_and_id(params[:id])
self.x_active_tree = 'sandt_tree'
self.x_active_accord = 'sandt'
st = ServiceTemplate.find(params[:id].split("-").last)
prefix = st.service_template_catalog_id ? "stc-#{st.service_template_catalog_id}_st-" : "-Unassigned_st-"
self.x_node = "#{prefix}#{id}"
get_node_info(x_node)
else
@in_a_form = false
end

if params[:commit] == "Upload" && session.fetch_path(:edit, :new, :sysprep_enabled, 1) == "Sysprep Answer File"
upload_sysprep_file
set_form_locals_for_sysprep
end
template_locals = {:locals => {:controller => "catalog"}}
template_locals[:locals].merge!(fetch_playbook_details) if need_ansible_locals?
template_locals[:locals].merge!(fetch_ct_details) if need_container_template_locals?
template_locals[:locals].merge!(fetch_ovf_template_details) if need_ovf_template_locals?

render :layout => "application", :action => "explorer", :locals => template_locals
end
# def explorer
# @explorer = true
# @lastaction = "explorer"
# @report_deleted = params[:report_deleted] == 'true' if params[:report_deleted]
# @sb[:action] = nil

# # if AJAX request, replace right cell, and return
# if request.xml_http_request?
# replace_right_cell
# return
# end

# build_accordions_and_trees

# if params[:id] && !params[:button] # If a tree node id came in, show in one of the trees
# @nodetype, id = parse_nodetype_and_id(params[:id])
# self.x_active_tree = 'sandt_tree'
# self.x_active_accord = 'sandt'
# st = ServiceTemplate.find(params[:id].split("-").last)
# prefix = st.service_template_catalog_id ? "stc-#{st.service_template_catalog_id}_st-" : "-Unassigned_st-"
# self.x_node = "#{prefix}#{id}"
# get_node_info(x_node)
# else
# @in_a_form = false
# end

# if params[:commit] == "Upload" && session.fetch_path(:edit, :new, :sysprep_enabled, 1) == "Sysprep Answer File"
# upload_sysprep_file
# set_form_locals_for_sysprep
# end
# template_locals = {:locals => {:controller => "catalog"}}
# template_locals[:locals].merge!(fetch_playbook_details) if need_ansible_locals?
# template_locals[:locals].merge!(fetch_ct_details) if need_container_template_locals?
# template_locals[:locals].merge!(fetch_ovf_template_details) if need_ovf_template_locals?

# render :layout => "application", :action => "explorer", :locals => template_locals
# end

def set_form_locals_for_sysprep
@pages = false
Expand All @@ -391,34 +416,34 @@ def identify_catalog(id = nil)
add_flash(_("This item is invalid"), :warning) unless @flash_array || @record.try(:template_valid?)
end

# ST clicked on in the explorer right cell
def x_show
@sb[:action] = nil
@explorer = true
if x_active_tree == :stcat_tree
assert_privileges("catalog_items_view")

if params[:rec_id]
# link to Catalog Item clicked on catalog summary screen
self.x_active_tree = :sandt_tree
self.x_active_accord = 'sandt'
@record = ServiceTemplate.find(params[:rec_id])
else
@record = ServiceTemplateCatalog.find(params[:id])
end
elsif x_active_tree == :ot_tree
assert_privileges("orchestration_templates_view")

@record ||= OrchestrationTemplate.find(params[:id])
else
assert_privileges("st_catalog_view")

identify_catalog(params[:id])
@record ||= ServiceTemplateCatalog.find(params[:id])
end
params[:id] = x_build_node_id(@record) # Get the tree node id
tree_select
end
# # ST clicked on in the explorer right cell
# def x_show
# @sb[:action] = nil
# @explorer = true
# if x_active_tree == :stcat_tree
# assert_privileges("catalog_items_view")

# if params[:rec_id]
# # link to Catalog Item clicked on catalog summary screen
# self.x_active_tree = :sandt_tree
# self.x_active_accord = 'sandt'
# @record = ServiceTemplate.find(params[:rec_id])
# else
# @record = ServiceTemplateCatalog.find(params[:id])
# end
# elsif x_active_tree == :ot_tree
# assert_privileges("orchestration_templates_view")

# @record ||= OrchestrationTemplate.find(params[:id])
# else
# assert_privileges("st_catalog_view")

# identify_catalog(params[:id])
# @record ||= ServiceTemplateCatalog.find(params[:id])
# end
# params[:id] = x_build_node_id(@record) # Get the tree node id
# tree_select
# end

def st_edit
assert_privileges(params[:id] ? 'catalogitem_edit' : 'catalogitem_new')
Expand Down Expand Up @@ -947,7 +972,12 @@ def features
:name => :svccat,
:title => _("Service Catalogs")
},

{
:role => "catalog_items",
:role_any => true,
:name => :sandt,
:title => _("Catalog Items1")
},
{
:role => "catalog_items_accord",
:role_any => true,
Expand Down Expand Up @@ -1106,16 +1136,16 @@ def atomic_req_submit
end
end

def service_template_list(scope, options = {})
@no_checkboxes = x_active_tree == :svccat_tree
if x_active_tree == :svccat_tree
@gtl_small_tiles = true
@row_button = true if role_allows?(:feature => 'svc_catalog_provision') # Show a button instead of the checkbox
options[:gtl_dbname] = :catalog
end
options[:named_scope] = scope
process_show_list(options)
end
# def service_template_list(scope, options = {})
# @no_checkboxes = x_active_tree == :svccat_tree
# if x_active_tree == :svccat_tree
# @gtl_small_tiles = true
# @row_button = true if role_allows?(:feature => 'svc_catalog_provision') # Show a button instead of the checkbox
# options[:gtl_dbname] = :catalog
# end
# options[:named_scope] = scope
# process_show_list(options)
# end

def ot_edit_set_form_vars(right_cell_text)
checked = find_checked_items
Expand Down Expand Up @@ -2034,7 +2064,6 @@ def fetch_ovf_template_details

ovf_template = ManageIQ::Providers::Vmware::InfraManager::OrchestrationTemplate.find_by(:id => provision[:ovf_template_id])
ovf_template_details[:provisioning][:ovf_template_name] = ovf_template.try(:name)

ovf_template_details
end

Expand Down Expand Up @@ -2265,6 +2294,8 @@ def replace_right_cell(options = {})
add_nodes = open_parent_nodes(@record) # Open the parent nodes of selected record, if not open
end

puts "x_active_tree============== #{x_active_tree}"

v_tb =
case x_active_tree
when :sandt_tree
Expand Down Expand Up @@ -2318,6 +2349,8 @@ def replace_right_cell(options = {})
template_locals.merge!(fetch_playbook_details) if need_ansible_locals?
template_locals.merge!(fetch_ct_details) if need_container_template_locals?
template_locals.merge!(fetch_ovf_template_details) if need_ovf_template_locals?
puts " template_locals123=#{template_locals.inspect}"

r[:partial => "catalog/#{x_active_tree}_show", :locals => template_locals]
end
elsif @sb[:buttons_node]
Expand Down Expand Up @@ -2386,7 +2419,6 @@ def replace_right_cell(options = {})
presenter.reset_one_trans

presenter.update(:breadcrumbs, r[:partial => 'layouts/breadcrumbs'])

render :json => presenter.for_render
end

Expand Down
98 changes: 98 additions & 0 deletions app/controllers/service_template_catalog_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
class ServiceTemplateCatalogController < ApplicationController
include Mixins::GenericSessionMixin
include Mixins::GenericShowMixin
include Mixins::GenericListMixin
include Mixins::BreadcrumbsMixin
include Mixins::GenericFormMixin


before_action :check_privileges
before_action :get_session_data
after_action :cleanup_action
after_action :set_session_data
after_action :title

EDIT_CATALOG_FEATURES = %w[
atomic_catalogitem_edit
catalogitem_edit
atomic_catalogitem_new
catalogitem_new
].freeze

def title
@page_title = _("Catalogs")
end

def self.model
@model ||= ServiceTemplateCatalog
end

def self.table_name
@table_name ||= "service_template_catalogs"
end

def show_list
assert_privileges("catalog_service_template_catalogs_show_list")
process_show_list(:dbname => :service_template_catalogs, :gtl_dbname => :service_template_catalogs)
@title = 'Service Catalogs'
end

def show
assert_privileges("catalog_service_template_catalogs_show")
@record = ServiceTemplateCatalog.find(params[:id])
@title = @record&.name
@record_service_templates = Rbac.filtered(@record.service_templates, :named_scope => :public_service_templates)
end

def new
end

# def service_catalog_item
# @record = ServiceTemplateCatalog.find(params[:id].to_i)
# @service_templates = @record.service_templates.where("id = ?", params[:item].to_i)&.first
# @title = @service_templates&.name
# end


def assert_privileges_for_servicetemplate_edit
if params[:pressed].present? && EDIT_CATALOG_FEATURES.include?(params[:pressed])
assert_privileges(params[:pressed])
elsif params[:button].blank?
assert_privileges('atomic_catalogitem_edit')
end
end

def find_record_with_rbac(service_template, record_id)
options = @find_with_aggregates ? {:named_scope => :with_aggregates} : {}
super(service_template, record_id, options)
end

def edit
assert_privileges_for_servicetemplate_edit

checked_id = find_checked_items.first || params[:id]


@sb[:cached_waypoint_ids] = MiqAeClass.waypoint_ids_for_state_machines
@record = checked_id.present? ? find_record_with_rbac(ServiceTemplateCatalog, checked_id) : ServiceTemplate.new
@sb[:st_form_active_tab] = "basic"
composite_type = @record.service_type == "composite"
new_atomic_item = params[:pressed] == "atomic_catalogitem_new" || (params[:button].present? && session[:edit][:new][:service_type] == "atomic")
if checked_id.present? && composite_type || checked_id.nil? && !new_atomic_item
st_edit
else
atomic_st_edit
end
end

def breadcrumbs_options
{
:breadcrumbs => [
{:title => _("Services")},
{:title => _("Catalogs")},
{:title => _("Service Catalogs"), :url => controller_url},
],
}
end
toolbar :servicetemplatecatalog, :servicetemplatecatalogs
end
4 changes: 4 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,10 @@ def view_to_url(view, parent = nil)
action = 'show'
return url_for_only_path(:action => action, :id => params[:id]) + "?display=generic_objects&generic_object_id="
end
if request[:controller] == 'service_catalogs' && view.db == 'GenericObject'
action = 'show'
return url_for_only_path(:controller => 'service_catalogs', :action => action, :id => params[:id]) + "?display=generic_objects&generic_object_id="
end
if @explorer
# showing a list view of another CI inside vmx
if %w[SecurityGroup
Expand Down
Loading

0 comments on commit 84dada7

Please sign in to comment.