Skip to content

Commit

Permalink
Merge pull request #2522 from skateman/ops-2nd-level-tabs
Browse files Browse the repository at this point in the history
Move tagging-related tabs into subtabs on the Settings/Region screen
  • Loading branch information
h-kataria authored Oct 27, 2017
2 parents 96652fe + a743672 commit ddf6608
Show file tree
Hide file tree
Showing 16 changed files with 94 additions and 73 deletions.
8 changes: 6 additions & 2 deletions app/assets/javascripts/miq_application.js
Original file line number Diff line number Diff line change
Expand Up @@ -903,15 +903,19 @@ function miqClickAndPop(el) {
return false;
}

function miq_tabs_init(id, url) {
function miq_tabs_init(id, url, parms) {
$(id + ' > ul.nav-tabs a[data-toggle="tab"]').on('show.bs.tab', function(e) {
if ($(e.target).parent().hasClass('disabled')) {
e.preventDefault();
return false;
} else if (typeof url != 'undefined') {
// Load remote tab if an URL is specified
var currTabTarget = $(e.target).attr('href').substring(1);
miqObserveRequest(url + '/?tab_id=' + currTabTarget, {beforeSend: true})
var urlParams = _.reduce(parms || [], function(sum, value, key) {
return sum + '&' + key + '=' + value;
}, '?tab_id=' + currTabTarget);

miqObserveRequest(url + urlParams, {beforeSend: true})
.catch(function(err) {
add_flash(__('Error requesting data from server'), 'error');
console.log(err);
Expand Down
30 changes: 22 additions & 8 deletions app/controllers/ops_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,13 @@ def explorer
@build = nil
@sb[:user] = nil
@ldap_group = nil
elsif %w(settings_import settings_import_tags).include?(@sb[:active_tab])
elsif @sb[:active_tab] == 'settings_tags' && %w(settings_import settings_import_tags).include?(@sb[:active_subtab])
session[:changed] = !flash_errors?
end
# setting active record object here again, since they are no longer there due to redirect
@ldap_group = @edit[:ldap_group] if params[:cls_id] && params[:cls_id].split('_')[0] == "lg"
@x_edit_buttons_locals = set_form_locals if @in_a_form
edit_changed? if @edit && !%w(settings_import settings_import_tags).include?(@sb[:active_tab])
edit_changed? if @edit && (@sb[:active_tab] == 'settings_tags' && !%w(settings_import settings_import_tags).include?(@sb[:active_subtab]))
render :layout => "application"
end

Expand Down Expand Up @@ -167,7 +167,15 @@ def change_tab(new_tab_id = nil)
redirect_to(:action => "ap_edit", :tab => "edit#{params[:tab]}", :id => (@scan.id || "new").to_s)
end
else
@sb[:active_tab] = params[:tab_id] || new_tab_id
# This is an ugly hack to have 2nd level tabs for our current tab changing workflow
# FIXME: this should be gone when we go with tabs fully implemented in angular
if params[:parent_tab_id]
@sb[:active_tab] = params[:parent_tab_id]
@sb[:active_subtab] = params[:tab_id]
else
@sb[:active_tab] = params[:tab_id] || new_tab_id
end

@sb[:user] = nil
@ldap_group = nil
@flash_array = nil if MiqServer.my_server(true).logon_status == :ready # don't reset if flash array
Expand All @@ -193,6 +201,11 @@ def change_tab(new_tab_id = nil)
end
end

def change_subtab
@sb[:active_tab] = params[:tab_id]
change_tab
end

def rbac_group_load_tab
tab_id = params[:tab_id]
_, group_id = TreeBuilder.extract_node_model_and_id(x_node)
Expand Down Expand Up @@ -338,6 +351,7 @@ def set_active_tab(nodetype)
case node[0]
when "root"
@sb[:active_tab] = "settings_details"
@sb[:active_subtab] = "settings_co_categories"
when "z"
@sb[:active_tab] = "settings_evm_servers"
when "xx", "sis", "msc", "l", "lr", "ld"
Expand Down Expand Up @@ -383,16 +397,16 @@ def set_form_locals
record_id = my_server.id
end
elsif x_active_tree == :settings_tree
if %w(settings_import settings_import_tags).include?(@sb[:active_tab])
if @sb[:active_tab] == 'settings_tags' && %w(settings_import settings_import_tags).include?(@sb[:active_subtab])
action_url = "apply_imports"
record_id = @sb[:active_tab].split("settings_").last
locals[:no_reset] = true
locals[:apply_button] = true
locals[:no_cancel] = true
locals[:apply_method] = :post
if @sb[:active_tab] == "settings_import"
if @sb[:active_tab] == "settings_tags" && @sb[:active_subtab] == "settings_import"
locals[:apply_text] = _("Apply the good VM custom variable value records")
elsif @sb[:active_tab] == "settings_import_tags"
elsif @sb[:active_tab] == "settings_tags" && @sb[:active_subtab] == "settings_import_tags"
locals[:apply_text] = _("Apply the good import records")
end
elsif @sb[:active_tab] == "settings_cu_collection"
Expand All @@ -417,10 +431,10 @@ def set_form_locals
action_url = "zone_edit"
record_id = @edit[:zone_id] ? @edit[:zone_id] : nil
end
elsif @sb[:active_tab] == "settings_co_categories" && @in_a_form
elsif @sb[:active_tab] == "settings_tags" && @sb[:active_subtab] == "settings_co_categories" && @in_a_form
action_url = "category_edit"
record_id = @category.try(:id)
elsif @sb[:active_tab] == "settings_label_tag_mapping" && @in_a_form
elsif @sb[:active_tab] == "settings_tags" && @sb[:active_subtab] == "settings_label_tag_mapping" && @in_a_form
action_url = "label_tag_mapping_edit"
record_id = @lt_map.try(:id)
elsif @sb[:active_tab] == 'settings_rhn_edit'
Expand Down
55 changes: 29 additions & 26 deletions app/controllers/ops_controller/settings/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1093,33 +1093,36 @@ def settings_get_info(nodetype = x_node)
when "settings_cu_collection" # C&U collection settings
cu_build_edit_screen
@in_a_form = true
when "settings_co_categories"
category_get_all
when "settings_co_tags"
# dont hide the disabled categories, so user can remove tags from the disabled ones
cats = Classification.categories.sort_by(&:description) # Get the categories, sort by name
@cats = {} # Classifications array for first chooser
cats.each do |c|
@cats[c.description] = c.name unless c.read_only? # Show the non-read_only categories
when "settings_tags"
case @sb[:active_subtab]
when "settings_co_categories"
category_get_all
when "settings_co_tags"
# dont hide the disabled categories, so user can remove tags from the disabled ones
cats = Classification.categories.sort_by(&:description) # Get the categories, sort by name
@cats = {} # Classifications array for first chooser
cats.each do |c|
@cats[c.description] = c.name unless c.read_only? # Show the non-read_only categories
end
@cat = cats.first
ce_build_screen # Build the Classification Edit screen
when "settings_import_tags"
@edit = {}
@edit[:new] = {}
@edit[:key] = "#{@sb[:active_tab]}_edit__#{@sb[:selected_server_id]}"
add_flash(_("Locate and upload a file to start the import process"), :info)
@in_a_form = true
when "settings_import" # Import tab
@edit = {}
@edit[:new] = {}
@edit[:key] = "#{@sb[:active_tab]}_edit__#{@sb[:selected_server_id]}"
@edit[:new][:upload_type] = nil
@sb[:good] = nil unless @sb[:show_button]
add_flash(_("Choose the type of custom variables to be imported"), :info)
@in_a_form = true
when "settings_label_tag_mapping"
label_tag_mapping_get_all
end
@cat = cats.first
ce_build_screen # Build the Classification Edit screen
when "settings_import_tags"
@edit = {}
@edit[:new] = {}
@edit[:key] = "#{@sb[:active_tab]}_edit__#{@sb[:selected_server_id]}"
add_flash(_("Locate and upload a file to start the import process"), :info)
@in_a_form = true
when "settings_import" # Import tab
@edit = {}
@edit[:new] = {}
@edit[:key] = "#{@sb[:active_tab]}_edit__#{@sb[:selected_server_id]}"
@edit[:new][:upload_type] = nil
@sb[:good] = nil unless @sb[:show_button]
add_flash(_("Choose the type of custom variables to be imported"), :info)
@in_a_form = true
when "settings_label_tag_mapping"
label_tag_mapping_get_all
when "settings_rhn"
@edit = session[:edit] || {}
@edit[:new] ||= {}
Expand Down
51 changes: 30 additions & 21 deletions app/views/ops/_all_tabs.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,14 @@
#settings_list
= render :partial => "settings_list_tab"
- else
= render(:partial => "layouts/flash_msg")
%ul.nav.nav-tabs
= miq_tab_header("settings_details", @sb[:active_tab]) do
= _("Details")
= miq_tab_header("settings_cu_collection", @sb[:active_tab]) do
= _("C & U Collection")
= miq_tab_header("settings_co_categories", @sb[:active_tab]) do
= escape_javascript(current_tenant.name)
= _("Categories")
= miq_tab_header("settings_co_tags", @sb[:active_tab]) do
= escape_javascript(current_tenant.name)
= miq_tab_header("settings_tags", @sb[:active_tab]) do
= _("Tags")
= miq_tab_header("settings_import_tags", @sb[:active_tab]) do
= _("Import Tags")
= miq_tab_header("settings_import", @sb[:active_tab]) do
= _("Import Variables")
= miq_tab_header("settings_label_tag_mapping", @sb[:active_tab]) do
= _("Map Tags")
= miq_tab_header("settings_rhn", @sb[:active_tab]) do
= _("Red Hat Updates")
= miq_tab_header("settings_replication", @sb[:active_tab]) do
Expand All @@ -72,16 +63,34 @@
= render :partial => "settings_details_tab"
= miq_tab_content("settings_cu_collection", @sb[:active_tab]) do
= render :partial => "settings_cu_collection_tab"
= miq_tab_content("settings_co_categories", @sb[:active_tab]) do
= render :partial => "settings_co_categories_tab"
= miq_tab_content("settings_co_tags", @sb[:active_tab]) do
= render :partial => "settings_co_tags_tab"
= miq_tab_content("settings_import_tags", @sb[:active_tab]) do
= render :partial => "settings_import_tags_tab"
= miq_tab_content("settings_import", @sb[:active_tab]) do
= render :partial => "settings_import_tab"
= miq_tab_content("settings_label_tag_mapping", @sb[:active_tab]) do
= render :partial => "settings_label_tag_mapping_tab"
= miq_tab_content("settings_tags", @sb[:active_tab]) do
#ops_tags_subtabs
%ul.nav.nav-tabs.nav-tabs-pf{:style => 'font-size: 12px'}
= miq_tab_header("settings_co_categories", @sb[:active_subtab]) do
= escape_javascript(current_tenant.name)
= _("Categories")
= miq_tab_header("settings_co_tags", @sb[:active_subtab]) do
= escape_javascript(current_tenant.name)
= _("Tags")
= miq_tab_header("settings_import_tags", @sb[:active_subtab]) do
= _("Import Tags")
= miq_tab_header("settings_import", @sb[:active_subtab]) do
= _("Import Variables")
= miq_tab_header("settings_label_tag_mapping", @sb[:active_subtab]) do
= _("Map Tags")
.tab-content
= miq_tab_content("settings_co_categories", @sb[:active_subtab]) do
= render :partial => "settings_co_categories_tab"
= miq_tab_content("settings_co_tags", @sb[:active_subtab]) do
= render :partial => "settings_co_tags_tab"
= miq_tab_content("settings_import_tags", @sb[:active_subtab]) do
= render :partial => "settings_import_tags_tab"
= miq_tab_content("settings_import", @sb[:active_subtab]) do
= render :partial => "settings_import_tab"
= miq_tab_content("settings_label_tag_mapping", @sb[:active_subtab]) do
= render :partial => "settings_label_tag_mapping_tab"
:javascript
miq_tabs_init("#ops_tags_subtabs", "/ops/change_tab", {parent_tab_id: 'settings_tags'});
= miq_tab_content("settings_rhn", @sb[:active_tab]) do
= render :partial => "settings_rhn_tab"
= miq_tab_content("settings_replication", @sb[:active_tab]) do
Expand Down
1 change: 0 additions & 1 deletion app/views/ops/_classification_entries.html.haml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#classification_entries_div
%h3= "#{@cat.description} Entries"
= render :partial => "layouts/flash_msg"
%table.table.table-striped.table-bordered.table-hover
%thead
%tr
Expand Down
3 changes: 1 addition & 2 deletions app/views/ops/_settings_co_categories_tab.html.haml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
- if @sb[:active_tab] == "settings_co_categories"
= render :partial => "layouts/flash_msg"
- if @sb[:active_tab] == "settings_tags" && @sb[:active_subtab] == "settings_co_categories"
%table.table.table-striped.table-bordered.table-hover
%thead
%tr
Expand Down
2 changes: 1 addition & 1 deletion app/views/ops/_settings_co_tags_tab.html.haml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- if @sb[:active_tab] == "settings_co_tags"
- if @sb[:active_tab] == "settings_tags" && @sb[:active_subtab] == "settings_co_tags"
#tab_div
- url = url_for_only_path(:action => 'ce_new_cat')
.form-horizontal
Expand Down
1 change: 0 additions & 1 deletion app/views/ops/_settings_cu_collection_tab.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
:id => "config_form",
:class => "form-horizontal",
:method => :post) do
= render :partial => "layouts/flash_msg"
.row
.col-md-12.col-lg-6
%fieldset
Expand Down
1 change: 0 additions & 1 deletion app/views/ops/_settings_details_tab.html.haml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
- if @sb[:active_tab] == "settings_details"
- if super_admin_user?
= render :partial => "layouts/flash_msg"
- region = MiqRegion.my_region
- if @edit
- url = url_for_only_path(:action => 'region_form_field_changed', :id => (region.id || "new"))
Expand Down
3 changes: 1 addition & 2 deletions app/views/ops/_settings_import_tab.html.haml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
- if @sb[:active_tab] == "settings_import"
- if @sb[:active_tab] == "settings_tags" && @sb[:active_subtab] == "settings_import"
- url = url_for_only_path(:action => 'upload_form_field_changed', :id => @sb[:active_tab].split('_').last)
%h3= _("Messages")
= render(:partial => "layouts/flash_msg")
%hr
%h3= _("Upload Custom Variable Values")
= form_tag({:action => "upload_csv",
Expand Down
3 changes: 1 addition & 2 deletions app/views/ops/_settings_import_tags_tab.html.haml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
- if @sb[:active_tab] == "settings_import_tags"
- if @sb[:active_tab] == "settings_tags" && @sb[:active_subtab] == "settings_import_tags"
#tab_div
%h3
= _("Messages")
= render(:partial => "layouts/flash_msg")
%hr
%h3
= _("Upload %{customer_name} Tag Assignments for VMs") % {:customer_name => session[:customer_name]}
Expand Down
3 changes: 1 addition & 2 deletions app/views/ops/_settings_label_tag_mapping_tab.html.haml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
- if @sb[:active_tab] == "settings_label_tag_mapping"
= render :partial => "layouts/flash_msg"
- if @sb[:active_tab] == "settings_tags" && @sb[:active_subtab] == "settings_label_tag_mapping"
%table.table.table-striped.table-bordered.table-hover
%thead
%tr
Expand Down
1 change: 0 additions & 1 deletion app/views/ops/_settings_replication_tab.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
%form.form-horizontal#form_div{"name" => "angularForm",
"ng-controller" => "pglogicalReplicationFormController",
"ng-show" => "afterGet"}
= render :partial => "layouts/flash_msg"
.form-group{"ng-class" => "{'has-error': angularForm.subscriptions.$invalid}"}
%label.col-md-2.control-label
= _('Type')
Expand Down
1 change: 0 additions & 1 deletion app/views/ops/_settings_rhn_tab.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
@updates[] -- update information for individual servers passed to the server_table partial
- if @sb[:active_tab] == "settings_rhn"
= render :partial => 'layouts/flash_msg'

%h3
Red Hat Software Updates
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/ops_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@
allow(controller).to receive(:assert_privileges).and_return(true)
seed_session_trees('ops', :settings_tree, 'root')
expect(controller).to receive(:render_to_string).with(any_args).exactly(3).times
post :change_tab, :params => {:tab_id => tab}
post :change_tab, :params => {:tab_id => tab, :parent_tab_id => 'settings_tags'}
end

it "Apply button remains disabled with flash errors" do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
describe 'ops/_settings_label_tag_mapping_tab.html.haml' do
before { assign(:sb, :active_tab => 'settings_label_tag_mapping') }
before { assign(:sb, :active_tab => 'settings_tags', :active_subtab => 'settings_label_tag_mapping') }

context 'table view' do
it 'renders the table with zero mappings' do
Expand Down

0 comments on commit ddf6608

Please sign in to comment.