From f26af3395ddb895ec511d7dd78322c5bf713d0e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Hal=C3=A1sz?= Date: Thu, 24 Aug 2017 11:26:49 +0200 Subject: [PATCH] Make the explorer listnavs more compact and drop the explorer_tree --- app/assets/javascripts/miq_application.js | 7 ++++-- app/views/layouts/listnav/_explorer.html.haml | 25 ++++++++----------- app/views/shared/_explorer_tree.html.haml | 8 ------ .../listnav/_explorer_html.haml_spec.rb | 16 ++++++++++++ .../shared/_explorer_tree.html.haml_spec.rb | 15 ----------- 5 files changed, 31 insertions(+), 40 deletions(-) delete mode 100644 app/views/shared/_explorer_tree.html.haml create mode 100644 spec/views/layouts/listnav/_explorer_html.haml_spec.rb delete mode 100644 spec/views/shared/_explorer_tree.html.haml_spec.rb diff --git a/app/assets/javascripts/miq_application.js b/app/assets/javascripts/miq_application.js index 3291ba6044e..53014a964a4 100644 --- a/app/assets/javascripts/miq_application.js +++ b/app/assets/javascripts/miq_application.js @@ -1231,8 +1231,11 @@ function miqAccordSelect(e) { return false; } - var url = '/' + $('body').data('controller') + '/accordion_select?id=' + $(e.target).attr('id'); - miqJqueryRequest(url, {beforeSend: true, complete: true}); + // No need to load anything if only a single accordion is present + if ($('#accordion > .panel').length > 1) { + var url = '/' + $('body').data('controller') + '/accordion_select?id=' + $(e.target).attr('id'); + miqJqueryRequest(url, {beforeSend: true, complete: true}); + } return true; } diff --git a/app/views/layouts/listnav/_explorer.html.haml b/app/views/layouts/listnav/_explorer.html.haml index 437fdafe3cb..0793c8b89e0 100644 --- a/app/views/layouts/listnav/_explorer.html.haml +++ b/app/views/layouts/listnav/_explorer.html.haml @@ -1,17 +1,12 @@ -#accordion.panel-group - - if @accords.present? && @accords.length == 1 # there is no need for JavaScript if only one accordion is present - .panel.panel-default - .panel-heading - %h4.panel-title - %a{:href => '#'} - = @accords.first[:title] - .panel-collapse.collapse.in - .panel-body{:id => @accords.first[:container]} - = render :partial => 'shared/explorer_tree', :locals => {:name => @accords.first[:name]} - - elsif @accords.present? && @accords.length > 1 - - accord_names = @accords.map { |accord| accord[:name].to_sym } - - @accords.each_with_index do |a, i| - = miq_accordion_panel(a[:title], accord_names.include?(@sb[:active_accord]) ? a[:name].to_sym == @sb[:active_accord] : i == 0, a[:container]) do - = render :partial => 'shared/explorer_tree', :locals => {:name => a[:name]} +- if @accords + #accordion.panel-group + -# Set the first accordion as selected if there is no active_accord in the sandbox + - selected = @accords.find(-> { @accords.first }) { |accord| accord[:name].to_sym == @sb[:active_accord] } + - @accords.each do |accord| + = miq_accordion_panel(accord[:title], selected == accord, accord[:container]) do + -# Set the first tree to be rendered if there is a mismatch with the name/type + - tree = @trees.find(-> { @trees.first }) { |t| t.type == accord[:name].to_sym } + = render :partial => 'shared/tree', :locals => {:tree => tree, :name => tree.name.to_s} + :javascript $('#accordion').on('show.bs.collapse', miqAccordSelect); diff --git a/app/views/shared/_explorer_tree.html.haml b/app/views/shared/_explorer_tree.html.haml deleted file mode 100644 index a9cc9e64f0c..00000000000 --- a/app/views/shared/_explorer_tree.html.haml +++ /dev/null @@ -1,8 +0,0 @@ --# Common partial for all available explorer trees --# Locals: --# name - name of the accordion which renders the given tree --# Used instance variables: --# @trees - all the available trees generated with TreeBuilder - -- tree = @trees.length == 1 ? @trees.first : @trees.detect { |t| t.type == name.to_sym } -= render :partial => 'shared/tree', :locals => {:tree => tree, :name => tree.name.to_s} diff --git a/spec/views/layouts/listnav/_explorer_html.haml_spec.rb b/spec/views/layouts/listnav/_explorer_html.haml_spec.rb new file mode 100644 index 00000000000..f7a7e62f8dd --- /dev/null +++ b/spec/views/layouts/listnav/_explorer_html.haml_spec.rb @@ -0,0 +1,16 @@ +describe 'layouts/_explorer.html.haml' do + let(:tree_1) { TreeBuilderConfigurationManager.new('tree_1', 'tree_1', {}) } + let(:accord) { {:title => 'foo', :name => 'tree_1'} } + + before do + set_controller_for_view('provider_foreman') + assign(:sb, {}) + assign(:trees, [tree_1]) + assign(:accords, [accord]) + end + + it 'renders the explorer listnav' do + render :partial => 'layouts/listnav/explorer' + expect(view).to render_template(:partial => 'layouts/listnav/_explorer') + end +end diff --git a/spec/views/shared/_explorer_tree.html.haml_spec.rb b/spec/views/shared/_explorer_tree.html.haml_spec.rb deleted file mode 100644 index 5c8daf88bea..00000000000 --- a/spec/views/shared/_explorer_tree.html.haml_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -describe "shared/_explorer_tree.html.haml" do - let(:tree_1) { TreeBuilderConfigurationManager.new("tree_1", "tree_1", {}) } - - before do - set_controller_for_view("provider_foreman") - assign(:trees, [tree_1]) - end - - context "when showtype is 'details'" do - it "should render shared explorer_tree view" do - render :partial => "shared/explorer_tree", :locals => {:name => "tree_1"} - expect(view).to render_template(:partial => 'shared/_explorer_tree') - end - end -end