fix user_abbrv

This commit is contained in:
byte[] 2019-12-08 13:18:10 -05:00
parent 284c91e2c6
commit ddc3ee61a1
3 changed files with 9 additions and 6 deletions

View file

@ -31,7 +31,7 @@ table.table
td class=report_row_class(report)
=> pretty_state(report)
= user_abbrv report.admin
= user_abbrv @conn, report.admin
td
= link "Show", to: Routes.admin_report_path(@conn, :show, report)
/- if report.open

View file

@ -2,7 +2,7 @@ defmodule PhilomenaWeb.Admin.ReportView do
use PhilomenaWeb, :view
import PhilomenaWeb.ReportView, only: [link_to_reported_thing: 2, report_row_class: 1, pretty_state: 1]
import PhilomenaWeb.ProfileView, only: [user_abbrv: 1, current?: 2]
import PhilomenaWeb.ProfileView, only: [user_abbrv: 2, current?: 2]
def truncate(<<string::binary-size(50), _rest::binary>>), do: string <> "..."
def truncate(string), do: string

View file

@ -50,10 +50,13 @@ defmodule PhilomenaWeb.ProfileView do
Enum.map_join(tags, " || ", & &1.name)
end
def user_abbrv(%{name: name}) do
String.upcase(initials_abbrv(name) || uppercase_abbrv(name) || first_letters_abbrv(name))
def user_abbrv(conn, %{name: name} = user) do
abbrv = String.upcase(initials_abbrv(name) || uppercase_abbrv(name) || first_letters_abbrv(name))
abbrv = "(" <> abbrv <> ")"
link(abbrv, to: Routes.profile_path(conn, :show, user))
end
def user_abbrv(_user), do: content_tag(:span, "(n/a)")
def user_abbrv(_conn, _user), do: content_tag(:span, "(n/a)")
defp initials_abbrv(name) do
case String.split(name, " ", parts: 4) do
@ -72,7 +75,7 @@ defmodule PhilomenaWeb.ProfileView do
end
defp uppercase_abbrv(name) do
case Regex.scan(~r/[A-Z]/, name, capture: :all_but_first) do
case Regex.scan(~r/([A-Z])/, name, capture: :all_but_first) do
[] ->
nil