Skip to content

Commit

Permalink
Show tags in users list
Browse files Browse the repository at this point in the history
  • Loading branch information
carlogilmar committed Oct 15, 2020
1 parent 3e810a1 commit c9caa96
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/star/operators/user_operator.ex
Expand Up @@ -30,7 +30,7 @@ defmodule Star.UserOperator do

def get_all_by_role(role) do
query = from(user in User, where: user.role == ^role, order_by: [desc: user.inserted_at])
query |> Repo.all()
query |> Repo.all() |> Repo.preload([:definition])
end

def get_by_email(email) do
Expand Down
8 changes: 8 additions & 0 deletions lib/star_web/live/users_live.ex
@@ -1,5 +1,6 @@
defmodule StarWeb.UsersLive do
use Phoenix.LiveView
alias Star.DefinitionOperator
alias Star.UserOperator
alias Star.SignupManager
alias StarWeb.UsersView
Expand Down Expand Up @@ -42,6 +43,13 @@ defmodule StarWeb.UsersLive do
{:noreply, socket}
end

def handle_event("delete_tag", %{"tag_id" => id}, socket) do
tag_id = String.to_integer(id)
{:ok, _user_deleted} = DefinitionOperator.delete(tag_id)
socket = update_users(socket)
{:noreply, socket}
end

def handle_event("save", %{"user" => %{"email" => email}}, socket) do
_ = SignupManager.invite_user(email)
socket = update_users(socket)
Expand Down
15 changes: 14 additions & 1 deletion lib/star_web/templates/users/index.html.leex
Expand Up @@ -48,7 +48,20 @@
<%= for user <- @users do %>
<tr>
<td><%= user.id %></td>
<td><%= user.email %></td>
<td>
<a data-toggle="collapse" href="#collapseExample<%= user.id %>" role="button" aria-expanded="false" aria-controls="collapseExample">
<%= user.email %>
</a>
<div class="collapse" id="collapseExample<%= user.id %>">
<span class="badge badge-secondary"> <%= user.city %>, <%= user.country %></span>
<p class="signika"> <%= user.description %> </p>
<%= for tag <- user.definition do %>
<a class="oswald redvp" href="#" phx-click="delete_tag" phx-value-tag_id="<%= tag.id %>">
<small><%= tag.description %> 🚫&nbsp;&nbsp;</small>
</a>
<% end %>
</div>
</td>
<td><%= user.name %></td>
<td><span class="badge badge-info"><%= user.role %></span></td>
<td>
Expand Down

0 comments on commit c9caa96

Please sign in to comment.