Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add retired services node #632

Merged
merged 4 commits into from
Mar 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions app/controllers/service_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ def show
redirect_to :action => 'show', :controller => record.class.base_model.to_s.underscore, :id => record.id
end

def show_list
redirect_to :action => 'explorer', :flash_msg => @flash_array.try(:fetch_path, 0, :message)
end

def explorer
@explorer = true
@lastaction = "explorer"
Expand Down Expand Up @@ -216,6 +220,14 @@ def get_node_info(treenodeid)
@gtl_type = "grid"
@items_per_page = ONE_MILLION
@view, @pages = get_view(Vm, :parent => @record, :parent_method => :all_vms, :all_pages => true) # Get the records (into a view) and the paginator
when "Hash"
if id == "asrv"
process_show_list(:where_clause => "retired is false and ancestry is null")
@right_cell_text = _("Active Services")
else
process_show_list(:where_clause => "retired is true and ancestry is null")
@right_cell_text = _("Retired Services")
end
else # Get list of child Catalog Items/Services of this node
if x_node == "root"
process_show_list(:where_clause => "ancestry is null")
Expand Down
8 changes: 8 additions & 0 deletions app/helpers/application_helper/button/service_retire.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class ApplicationHelper::Button::ServiceRetire < ApplicationHelper::Button::Basic
needs :@record

def disabled?
@error_message = _('Service is already retired') if @record.retired
@error_message.present?
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class ApplicationHelper::Toolbar::RetiredServicesCenter < ApplicationHelper::Toolbar::Basic
include ApplicationHelper::Toolbar::Service::VmdbMixin
include ApplicationHelper::Toolbar::Service::PolicyMixin
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module ApplicationHelper::Toolbar::Service::LifecycleMixin
def self.included(included_class)
included_class.button_group('service_lifecycle', [
included_class.select(
:service_lifecycle_choice,
'fa fa-recycle fa-lg',
t = N_('Lifecycle'),
t,
:enabled => false,
:items => [
included_class.button(
:service_retire,
'fa fa-clock-o fa-lg',
N_('Set Retirement Dates for the selected items'),
N_('Set Retirement Dates'),
:enabled => false,
:url_parms => "main_div",
:onwhen => "1+"),
included_class.button(
:service_retire_now,
'fa fa-clock-o fa-lg',
N_('Retire the selected items'),
N_('Retire selected items'),
:url_parms => "main_div",
:confirm => N_("Retire the selected items?"),
:enabled => false,
:onwhen => "1+"),
]),
])
end
end
24 changes: 24 additions & 0 deletions app/helpers/application_helper/toolbar/service/policy_mixin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module ApplicationHelper::Toolbar::Service::PolicyMixin
def self.included(included_class)
included_class.button_group('service_policy', [
included_class.select(
:service_policy_choice,
'fa fa-shield fa-lg',
t = N_('Policy'),
t,
:enabled => false,
:onwhen => "1+",
:items => [
included_class.button(
:service_tag,
'pficon pficon-edit fa-lg',
N_('Edit tags for the selected Items'),
N_('Edit Tags'),
:url_parms => "main_div",
:enabled => false,
:onwhen => "1+"),
]
),
])
end
end
42 changes: 42 additions & 0 deletions app/helpers/application_helper/toolbar/service/vmdb_mixin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
module ApplicationHelper::Toolbar::Service::VmdbMixin
def self.included(included_class)
included_class.button_group('service_vmdb', [
included_class.select(
:service_vmdb_choice,
'fa fa-cog fa-lg',
t = N_('Configuration'),
t,
:enabled => false,
:onwhen => "1+",
:items => [
included_class.button(
:service_edit,
'pficon pficon-edit fa-lg',
N_('Select a single service to edit'),
N_('Edit Selected Service'),
:url_parms => "main_div",
:enabled => false,
:onwhen => "1"),
included_class.button(
:service_delete,
'pficon pficon-delete fa-lg',
N_('Remove selected Services'),
N_('Remove Services'),
:url_parms => "main_div",
:enabled => false,
:confirm => N_("Warning: The selected Services and ALL of their components will be permanently removed!"),
:onwhen => "1+"),
included_class.separator,
included_class.button(
:service_ownership,
'pficon pficon-user fa-lg',
N_('Set Ownership for the selected Services'),
N_('Set Ownership'),
:url_parms => "main_div",
:enabled => false,
:onwhen => "1+"),
]
),
])
end
end
10 changes: 7 additions & 3 deletions app/helpers/application_helper/toolbar/service_center.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,19 @@ class ApplicationHelper::Toolbar::ServiceCenter < ApplicationHelper::Toolbar::Ba
button(
:service_retire,
'fa fa-clock-o fa-lg',
N_('Set Retirement Dates for this Service'),
N_('Set Retirement Date')),
t = N_('Set Retirement Date for this Service'),
t,
:confirm => N_("Set Retirement this Service?"),
:klass => ApplicationHelper::Button::ServiceRetire
),
button(
:service_retire_now,
'fa fa-clock-o fa-lg',
t = N_('Retire this Service'),
t,
:confirm => N_("Retire this Service?"),
:klass => ApplicationHelper::Button::ServiceRetireNow),
:klass => ApplicationHelper::Button::ServiceRetireNow
),
]
),
])
Expand Down
90 changes: 3 additions & 87 deletions app/helpers/application_helper/toolbar/services_center.rb
Original file line number Diff line number Diff line change
@@ -1,89 +1,5 @@
class ApplicationHelper::Toolbar::ServicesCenter < ApplicationHelper::Toolbar::Basic
button_group('service_vmdb', [
select(
:service_vmdb_choice,
'fa fa-cog fa-lg',
t = N_('Configuration'),
t,
:enabled => false,
:onwhen => "1+",
:items => [
button(
:service_edit,
'pficon pficon-edit fa-lg',
N_('Select a single service to edit'),
N_('Edit Selected Service'),
:url_parms => "main_div",
:enabled => false,
:onwhen => "1"),
button(
:service_delete,
'pficon pficon-delete fa-lg',
N_('Remove selected Services'),
N_('Remove Services'),
:url_parms => "main_div",
:confirm => N_("Warning: The selected Services and ALL of their components will be permanently removed!"),
:enabled => false,
:onwhen => "1+"),
separator,
button(
:service_ownership,
'pficon pficon-user fa-lg',
N_('Set Ownership for the selected Services'),
N_('Set Ownership'),
:url_parms => "main_div",
:enabled => false,
:onwhen => "1+"),
]
),
])
button_group('service_policy', [
select(
:service_policy_choice,
'fa fa-shield fa-lg',
t = N_('Policy'),
t,
:enabled => false,
:onwhen => "1+",
:items => [
button(
:service_tag,
'pficon pficon-edit fa-lg',
N_('Edit tags for the selected Items'),
N_('Edit Tags'),
:url_parms => "main_div",
:enabled => false,
:onwhen => "1+"),
]
),
])
button_group('service_lifecycle', [
select(
:service_lifecycle_choice,
'fa fa-recycle fa-lg',
t = N_('Lifecycle'),
t,
:enabled => false,
:onwhen => "1+",
:items => [
button(
:service_retire,
'fa fa-clock-o fa-lg',
N_('Set Retirement Dates for the selected items'),
N_('Set Retirement Dates'),
:url_parms => "main_div",
:enabled => false,
:onwhen => "1+"),
button(
:service_retire_now,
'fa fa-clock-o fa-lg',
N_('Retire the selected items'),
N_('Retire selected items'),
:url_parms => "main_div",
:confirm => N_("Retire the selected items?"),
:enabled => false,
:onwhen => "1+"),
]
),
])
include ApplicationHelper::Toolbar::Service::VmdbMixin
include ApplicationHelper::Toolbar::Service::PolicyMixin
include ApplicationHelper::Toolbar::Service::LifecycleMixin
end
2 changes: 2 additions & 0 deletions app/helpers/application_helper/toolbar_chooser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ def center_toolbar_filename_services
elsif x_active_tree == :svcs_tree
if TreeBuilder.get_model_for_prefix(@nodetype) == "Service"
return "service_center_tb"
elsif x_node == 'xx-rsrv'
return "retired_services_center_tb"
else
return "services_center_tb"
end
Expand Down
30 changes: 21 additions & 9 deletions app/presenters/tree_builder_services.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class TreeBuilderServices < TreeBuilder
def tree_init_options(_tree_name)
{
:leaf => "Service",
:full_ids => true
:add_root => false
}
end

Expand All @@ -16,20 +16,32 @@ def set_locals_for_render
end

def root_options
{
:title => t = _("All Services"),
:tooltip => t
}
{ }
end

# Get root nodes count/array for explorer tree
def x_get_tree_roots(count_only, _options)
all_services = Rbac.filtered(Service.where(:display => true))
objects = []
objects.push(:id => "asrv",
:text => _("Active Services"),
:icon => "pficon pficon-folder-close",
:load_children => true,
:tip => _("Active Services"))
objects.push(:id => "rsrv",
:text => _("Retired Services"),
:icon => "pficon pficon-folder-close",
:load_children => true,
:tip => _("Retired Services"))
count_only_or_objects(count_only, objects)
end

def x_get_tree_custom_kids(object, count_only, _options)
services = Rbac.filtered(Service.where(:retired => object[:id] != 'asrv', :ancestry => [nil, ""]))
if count_only
all_services.size
services.size
else
MiqPreloader.preload(all_services.to_a, :picture)
Service.arrange_nodes(all_services.sort_by { |n| [n.ancestry.to_s, n.name.downcase] })
MiqPreloader.preload(services.to_a, :picture)
Service.arrange_nodes(services.sort_by { |n| [n.ancestry.to_s, n.name.downcase] })
end
end
end
34 changes: 16 additions & 18 deletions spec/presenters/tree_builder_services_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@
it "generates tree" do
create_deep_tree

expect(root_nodes).to eq(
@service => {
@service_c1 => {
@service_c11 => {},
@service_c12 => {
@service_c121 => {}
}
},
@service_c2 => {}
}
expect(root_nodes.size).to eq(2)
active_nodes = kid_nodes(root_nodes[0])
retired_nodes = kid_nodes(root_nodes[1])
expect(active_nodes).to eq(
@service => {},
@service_c1 => {},
@service_c2 => {}
)
expect(retired_nodes).to eq(@service_c3 => {})
end

private
Expand All @@ -24,17 +22,17 @@ def root_nodes
end

def kid_nodes(node)
builder.send(:x_get_tree_service_kids, node, false)
builder.send(:x_get_tree_custom_kids, node, false, {})
end

def create_deep_tree
@service = FactoryGirl.create(:service, :display => true)
@service_c1 = FactoryGirl.create(:service, :service => @service, :display => true)
@service_c11 = FactoryGirl.create(:service, :service => @service_c1, :display => true)
@service_c12 = FactoryGirl.create(:service, :service => @service_c1, :display => true)
@service_c121 = FactoryGirl.create(:service, :service => @service_c12, :display => true)
@service_c2 = FactoryGirl.create(:service, :service => @service, :display => true)
@service = FactoryGirl.create(:service, :display => true, :retired => false)
@service_c1 = FactoryGirl.create(:service, :display => true, :retired => false)
@service_c11 = FactoryGirl.create(:service, :service => @service_c1, :display => true, :retired => false)
@service_c12 = FactoryGirl.create(:service, :service => @service_c1, :display => true, :retired => false)
@service_c121 = FactoryGirl.create(:service, :service => @service_c12, :display => true, :retired => false)
@service_c2 = FactoryGirl.create(:service, :display => true, :retired => false)
# hidden
@service_c3 = FactoryGirl.create(:service, :service => @service, :display => false)
@service_c3 = FactoryGirl.create(:service, :retired => true)
end
end