Skip to content

Commit

Permalink
Merge pull request #603 from himdel/textual-icon
Browse files Browse the repository at this point in the history
Textual Summaries - textual_*_icon - support for fonticons, decorators
  • Loading branch information
martinpovolny committed Mar 7, 2017
2 parents 891dabf + fd8628a commit 5ba6e0a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
27 changes: 16 additions & 11 deletions app/helpers/textual_summary_helper.rb
Expand Up @@ -77,14 +77,13 @@ def textual_object_link(object, as: nil, controller: nil, feature: nil, label: n
feature ||= "#{controller}_show"

label ||= ui_lookup(:model => klass.name)
image = textual_object_icon(object, klass)
value = if block_given?
yield object
else
object.name
end

h = {:label => label, :image => image, :value => value}
h = {:label => label, :value => value}.merge(textual_object_icon(object, klass))

if role_allows?(:feature => feature)
if restful_routed?(object)
Expand Down Expand Up @@ -114,10 +113,9 @@ def textual_collection_link(collection, as: nil, controller_collection: nil, exp
feature ||= "#{controller_collection}_show_list"

label ||= ui_lookup(:models => klass.name)
image = textual_collection_icon(collection, klass)
count = collection.count

h = {:label => label, :image => image, :value => count.to_s}
h = {:label => label, :value => count.to_s}.merge(textual_collection_icon(collection, klass))

if count > 0 && role_allows?(:feature => feature)
if link
Expand Down Expand Up @@ -146,9 +144,11 @@ def textual_collection_link(collection, as: nil, controller_collection: nil, exp
end

def textual_object_icon(object, klass)
case object
when ExtManagementSystem
"svg/vendor-#{object.image_name}.svg"
icon = object.decorate.try(:fonticon)
image = object.decorate.try(:listicon_image)

if icon || image
{:icon => icon, :image => image}
else
textual_class_icon(klass)
end
Expand All @@ -159,12 +159,17 @@ def textual_collection_icon(_collection, klass)
end

def textual_class_icon(klass)
if klass <= AdvancedSetting
"100/advancedsetting.png"
icon = klass.decorate.try(:fonticon)
image = klass.decorate.try(:listicon_image)

if icon || image
{:icon => icon, :image => image}
elsif klass <= AdvancedSetting
{:image => "100/advancedsetting.png"}
elsif klass <= MiqTemplate
"100/vm.png"
{:image => "100/vm.png"}
else
"100/#{klass.name.underscore}.png"
{:image => "100/#{klass.name.underscore}.png"}
end
end

Expand Down
12 changes: 6 additions & 6 deletions spec/helpers/container_summary_helper_spec.rb
@@ -1,7 +1,7 @@
describe ContainerSummaryHelper do
let(:container_project) { FactoryGirl.create(:container_project) }
let(:rel_hash_with_link) { [:label, :image, :value, :link, :title] }
let(:rel_hash_without_link) { [:label, :image, :value] }
let(:rel_hash_with_link) { [:label, :value, :link, :title] }
let(:rel_hash_without_link) { [:label, :value] }

before do
self.class.send(:include, ApplicationHelper)
Expand All @@ -14,13 +14,13 @@

it 'show link when role allows' do
stub_user(:features => :all)
expect(subject.keys).to eq(rel_hash_with_link)
expect(subject.keys).to include(*rel_hash_with_link)
expect(subject[:value]).to eq(container_project.name)
end

it 'hide link when role does not allow' do
stub_user(:features => :none)
expect(subject.keys).to eq(rel_hash_without_link)
expect(subject.keys).to include(*rel_hash_without_link)
expect(subject[:value]).to eq(container_project.name)
end
end
Expand All @@ -31,13 +31,13 @@

it 'show link when role allows' do
stub_user(:features => :all)
expect(subject.keys).to eq(rel_hash_with_link)
expect(subject.keys).to include(*rel_hash_with_link)
expect(subject[:value]).to eq("2")
end

it 'hide link when role does not allow' do
stub_user(:features => :none)
expect(subject.keys).to eq(rel_hash_without_link)
expect(subject.keys).to include(*rel_hash_without_link)
expect(subject[:value]).to eq("2")
end
end
Expand Down

0 comments on commit 5ba6e0a

Please sign in to comment.