Skip to content

Commit

Permalink
Merge pull request #3034 from skateman/topology-tag-naming
Browse files Browse the repository at this point in the history
Name the tags on the topology screens based on its classifications
  • Loading branch information
Dan Clarizio authored Dec 14, 2017
2 parents f4dc798 + 44bd5a4 commit d7681c0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
8 changes: 7 additions & 1 deletion app/assets/javascripts/services/topology_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,20 @@ ManageIQ.angular.app.service('topologyService', function() {
__('Status: ') + d.item.status,
];

if (d.item.kind === 'Tag') {
status = [
d.item.name,
__('Type: ') + d.item.display_kind,
];
}

if (d.item.kind === 'Host' || d.item.kind === 'Vm') {
status.push(__('Provider: ') + d.item.provider);
}

return status;
};


this.showHideNames = function($scope) {
return function() {
$scope.checkboxModel.value = $('input#box_display_names')[0].checked;
Expand Down
11 changes: 10 additions & 1 deletion app/services/topology_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,18 @@ def entity_id(entity)
entity_type(entity) + entity.compressed_id.to_s
end

def entity_name(entity)
if entity.kind_of?(Tag)
cls = entity.classification
[cls.parent, cls].map(&:description).join(': ')
else
entity.name
end
end

def build_base_entity_data(entity)
{
:name => entity.name,
:name => entity_name(entity),
:kind => entity_type(entity),
:model => entity.class.to_s,
:miq_id => entity.id,
Expand Down
22 changes: 22 additions & 0 deletions spec/services/topology_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,26 @@
end
end
end

describe '#entity_name' do
let(:name) { subject.send(:entity_name, entity) }

context 'entity is not a tag' do
let(:entity) { FactoryGirl.create(:vm_vmware) }

it 'returns with the name of the entity' do
expect(name).to eq(entity.name)
end
end

context 'entity is a tag' do
let(:parent_cls) { FactoryGirl.create(:classification, :description => 'foo') }
let(:cls) { FactoryGirl.create(:classification, :parent => parent_cls, :description => 'bar') }
let(:entity) { FactoryGirl.create(:tag, :classification => cls) }

it 'returns with the parent and the child classification description' do
expect(name).to eq('foo: bar')
end
end
end
end

0 comments on commit d7681c0

Please sign in to comment.