From 6b579f701dc8199e8987aa86cacdc85540d1e4df Mon Sep 17 00:00:00 2001 From: yaacov Date: Wed, 3 May 2017 11:39:58 +0300 Subject: [PATCH] Remove the tree presentor (thanks himdel) --- app/presenters/tree_builder.rb | 4 -- app/presenters/tree_builder_containers.rb | 46 ------------------- .../tree_builder_containers_filter.rb | 39 ---------------- .../tree_builder_containers_spec.rb | 41 ----------------- 4 files changed, 130 deletions(-) delete mode 100644 app/presenters/tree_builder_containers.rb delete mode 100644 app/presenters/tree_builder_containers_filter.rb delete mode 100644 spec/presenters/tree_builder_containers_spec.rb diff --git a/app/presenters/tree_builder.rb b/app/presenters/tree_builder.rb index 67cb102e730..6935522b096 100644 --- a/app/presenters/tree_builder.rb +++ b/app/presenters/tree_builder.rb @@ -410,10 +410,6 @@ def resolve_object_lambdas(count_only, objects) :schedules => "TreeBuilderReportSchedules", :widgets => "TreeBuilderReportWidgets", - # containers explorer tree - :containers => "TreeBuilderContainers", - :containers_filter => "TreeBuilderContainersFilter", - # automate explorer tree :ae => "TreeBuilderAeClass", diff --git a/app/presenters/tree_builder_containers.rb b/app/presenters/tree_builder_containers.rb deleted file mode 100644 index fabed3c0671..00000000000 --- a/app/presenters/tree_builder_containers.rb +++ /dev/null @@ -1,46 +0,0 @@ -class TreeBuilderContainers < TreeBuilder - private - - def tree_init_options(_) - { - :leaf => "Container", - :open_all => true, - :full_ids => true - } - end - - def set_locals_for_render - locals = super - locals.merge!(:autoload => true) - end - - # level 0 - root - def root_options - { - :title => t = _("All Containers (by Pods)"), - :tooltip => t - } - end - - # level 1 - pods - def x_get_tree_roots(count_only, _options) - objects = ContainerGroup.where(:deleted_on => nil).order(:name) - list = objects.compact.map do |c| - { - :id => c.id, - :text => c.name, - :tip => c.ems_ref, - :icon => "pficon pficon-folder-close", - :cfmeNoClick => true - } - end - count_only_or_objects(count_only, list) - end - - # level 2 - containers - def x_get_tree_custom_kids(object, count_only, _options) - container_group = ContainerGroup.find(object[:id]) - objects = Rbac.filtered(container_group.containers.where(:deleted_on => nil)) if container_group - count_only_or_objects(count_only, objects, 'name') - end -end diff --git a/app/presenters/tree_builder_containers_filter.rb b/app/presenters/tree_builder_containers_filter.rb deleted file mode 100644 index f5a1682d3eb..00000000000 --- a/app/presenters/tree_builder_containers_filter.rb +++ /dev/null @@ -1,39 +0,0 @@ -class TreeBuilderContainersFilter < TreeBuilder - private - - def tree_init_options(_) - { - :leaf => "Container", - :full_ids => true - } - end - - def set_locals_for_render - locals = super - locals.merge!(:autoload => true, :allow_reselect => true) - end - - def root_options - { - :title => t = _("All Containers"), - :tooltip => t - } - end - - # Get root nodes count/array for explorer tree - def x_get_tree_roots(_count_only, _options) - [ - {:id => "global", - :text => _("Global Filters"), - :icon => "pficon pficon-folder-close", - :tip => _("Global Shared Filters"), - :cfmeNoClick => true} - ] - end - - def x_get_tree_custom_kids(object, count_only, options) - return count_only ? 0 : [] if object[:id] != "global" - objects = MiqSearch.where(:db => options[:leaf]).visible_to_all - count_only_or_objects(count_only, objects, 'description') - end -end diff --git a/spec/presenters/tree_builder_containers_spec.rb b/spec/presenters/tree_builder_containers_spec.rb deleted file mode 100644 index b7a446eebbb..00000000000 --- a/spec/presenters/tree_builder_containers_spec.rb +++ /dev/null @@ -1,41 +0,0 @@ -describe TreeBuilderContainers do - let(:tag) { FactoryGirl.create(:tag, :name => "/managed/department/accounting") } - let(:role) { FactoryGirl.create(:miq_user_role, :name => "EvmRole-operator") } - let(:group) { FactoryGirl.create(:miq_group, :miq_user_role => role, :description => "Group 1") } - let(:user) { FactoryGirl.create(:user, :userid => 'User 1', :miq_groups => [group]) } - - before do - MiqRegion.seed - EvmSpecHelper.local_miq_server - - @container_group = FactoryGirl.create(:container_group, :name => "Pod", :id => 42) - @tagged_container = FactoryGirl.create(:container, - :name => "Tagged Container", - :tags => [tag], - :container_group => @container_group) - @untagged_container = FactoryGirl.create(:container, - :name => "Untagged Container", - :container_group => @container_group) - login_as user - end - - describe ".new" do - def get_tree_results(tree) - tree.x_get_child_nodes("xx-42").map { |c| c[:title] } - end - - it "returns all containers" do - tree = TreeBuilderContainers.new("containers_tree", "containers", {}, true) - results = get_tree_results(tree) - expect(results).to match_array(["Untagged Container", "Tagged Container"]) - end - - it "returns tagged containers, logged user with tag filter" do - user.current_group.entitlement = Entitlement.create! - user.current_group.entitlement.set_managed_filters([tag.name]) - @tree = TreeBuilderContainers.new("containers_tree", "containers", {}, true) - results = get_tree_results(@tree) - expect(results).to match_array(["Tagged Container"]) - end - end -end