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

Textual Summaries - textual_*_icon - support for fonticons, decorators #603

Merged
merged 3 commits into from
Mar 7, 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
27 changes: 16 additions & 11 deletions app/helpers/textual_summary_helper.rb
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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