diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index cedf6c52d..5154af08f 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,6 +1,6 @@ module ApplicationHelper def icon(id, label) - tag.i class: "bi bi-#{id}", role: "img", "aria-label": label, title: label + tag.i class: "bi bi-#{id}", role: "img", title: label end def card(style, title, options = {}, &content) diff --git a/app/helpers/models_helper.rb b/app/helpers/models_helper.rb index d55ff4d52..9486a2ebc 100644 --- a/app/helpers/models_helper.rb +++ b/app/helpers/models_helper.rb @@ -11,7 +11,7 @@ def group(files) def status_badges(model) badges = [] badges << content_tag(:span, icon("bi bi-stars", t("general.new")), class: "text-warning align-middle") if model.new? - badges << problem_icon(model.problems_including_files.visible(current_user.problem_settings)) + badges << problem_icon_tag(model.problems_including_files.visible(current_user.problem_settings)) content_tag :span, safe_join(badges, " "), class: "status-badges" end diff --git a/app/helpers/problems_helper.rb b/app/helpers/problems_helper.rb index 24c782b65..f8161f86f 100644 --- a/app/helpers/problems_helper.rb +++ b/app/helpers/problems_helper.rb @@ -4,13 +4,25 @@ def problem_severity(problem) end def max_problem_severity(problems = Problem.all) + return nil if problems.empty? severities = problems.select(:category).distinct.map { |p| problem_severity(p) } severities.max_by { |p| Problem::SEVERITIES.find_index(p) } end - def problem_icon(problems = Problem.all) - return "" if problems.empty? + def problem_icon(severity) + case severity + when :info + "info-circle-fill" + when :warning + "exclamation-triangle-fill" + when :danger + "x-octagon-fill" + end + end + + def problem_icon_tag(problems = Problem.all) severity = max_problem_severity(problems) - content_tag(:span, icon("exclamation-triangle-fill", Problem.model_name.human(count: 100)), class: "text-#{severity} align-middle") + ico = problem_icon(severity) + content_tag(:span, icon(ico, t("problems.severities.#{severity}")), class: "text-#{severity} align-middle") if ico # rubocop:todo I18n/RailsI18n/DecorateStringFormattingUsingInterpolation end end diff --git a/app/views/application/_navbar.html.erb b/app/views/application/_navbar.html.erb index 56f46fba3..8c6a4dd68 100644 --- a/app/views/application/_navbar.html.erb +++ b/app/views/application/_navbar.html.erb @@ -54,10 +54,12 @@ <%- if current_user %> <% if Problem.visible(current_user.problem_settings).count > 0 %> <% end %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index dc97b902d..5fbe485e7 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -25,7 +25,7 @@ <% end %> <% if alert %>

- <%= icon "exclamation-triangle-fill", t(".alert.danger") %> + <%= icon "x-octagon-fill", t(".alert.danger") %> <%= alert %>

<% end %> diff --git a/app/views/models/_file.html.erb b/app/views/models/_file.html.erb index 25ce3e82a..c91913fae 100644 --- a/app/views/models/_file.html.erb +++ b/app/views/models/_file.html.erb @@ -30,7 +30,7 @@ <% if file.presupported || file.presupported_version %> <%= icon "bar-chart-line-fill", ModelFile.human_attribute_name(:presupported) %> <% end %> - <%= problem_icon(file.problems) %> + <%= problem_icon_tag(file.problems) %> diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index f981c53de..cbf7d19d6 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -7,7 +7,6 @@ doc = Nokogiri::HTML(html) expect(doc.at("i")["class"]).to eq("bi bi-test") expect(doc.at("i")["role"]).to eq("img") - expect(doc.at("i")["aria-label"]).to eq("Test Label") expect(doc.at("i")["title"]).to eq("Test Label") end end