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

hide sorting buttons for other users #337

Merged
merged 5 commits into from
Sep 11, 2024
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
18 changes: 14 additions & 4 deletions lib/mindwendel_web/live/brainstorming_live/show.ex
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,24 @@ defmodule MindwendelWeb.BrainstormingLive.Show do

@impl true
def handle_event("sort_by_likes", %{"id" => id}, socket) do
Ideas.update_ideas_for_brainstorming_by_likes(id)
Brainstormings.broadcast({:ok, Brainstormings.get_brainstorming!(id)}, :brainstorming_updated)
brainstorming = Brainstormings.get_brainstorming!(id)

if has_move_permission(brainstorming, socket.assigns.current_user) do
Ideas.update_ideas_for_brainstorming_by_likes(id)
Brainstormings.broadcast({:ok, brainstorming}, :brainstorming_updated)
end

{:noreply, socket}
end

def handle_event("sort_by_label", %{"id" => id}, socket) do
Ideas.update_ideas_for_brainstorming_by_labels(id)
Brainstormings.broadcast({:ok, Brainstormings.get_brainstorming!(id)}, :brainstorming_updated)
brainstorming = Brainstormings.get_brainstorming!(id)

if has_move_permission(brainstorming, socket.assigns.current_user) do
Ideas.update_ideas_for_brainstorming_by_labels(id)
Brainstormings.broadcast({:ok, brainstorming}, :brainstorming_updated)
end

{:noreply, socket}
end

Expand Down
12 changes: 7 additions & 5 deletions lib/mindwendel_web/live/brainstorming_live/show.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@
class: "btn btn-primary m-1 d-none d-md-block",
title: gettext("New idea page (Hotkey: i)")
) %>
<%= link to: "#", class: "btn btn-primary m-1", phx_click: "sort_by_likes", phx_value_id: @brainstorming.id, title: gettext("Sort by likes") do %>
<i class="bi-sort-numeric-up-alt"></i> <%= gettext("Likes") %>
<% end %>
<%= link to: "#", class: "btn btn-primary m-1", phx_click: "sort_by_label", phx_value_id: @brainstorming.id, title: gettext("Sort by label") do %>
<i class="bi-sort-alpha-up-alt"></i> <%= gettext("Label") %>
<%= if has_move_permission(@brainstorming, @current_user) do %>
<%= link to: "#", class: "btn btn-primary m-1", phx_click: "sort_by_likes", phx_value_id: @brainstorming.id, title: gettext("Sort by likes") do %>
<i class="bi-sort-numeric-up-alt"></i> <%= gettext("Likes") %>
<% end %>
<%= link to: "#", class: "btn btn-primary m-1", phx_click: "sort_by_label", phx_value_id: @brainstorming.id, title: gettext("Sort by label") do %>
<i class="bi-sort-alpha-up-alt"></i> <%= gettext("Label") %>
<% end %>
<% end %>

<%= live_patch to: Routes.brainstorming_show_path(@socket, :share, @brainstorming), class: "btn btn-secondary m-1", title: gettext("Share") do %>
Expand Down
20 changes: 10 additions & 10 deletions priv/gettext/de/LC_MESSAGES/default.po
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ msgstr "Neue Idee"
msgid "New brainstorming"
msgstr "Neues Brainstorming"

#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:71
#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:73
#, elixir-autogen, elixir-format
msgid "New idea"
msgstr "Neue Idee"
Expand All @@ -122,7 +122,7 @@ msgstr "Neue Idee (Hotkey: i)"
msgid "No ideas brainstormed"
msgstr "Bisher keine Ideen vorhanden"

#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:121
#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:123
#, elixir-autogen, elixir-format
msgid "Open new idea page (Hotkey: i)"
msgstr "Öffne neue Ideen Dialog (Hotkey: i)"
Expand All @@ -147,12 +147,12 @@ msgstr "Speichere diesen Link, um das Brainstorming zukünftig zu bearbeiten ode
msgid "Saving..."
msgstr "Speichere..."

#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:33
#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:34
#, elixir-autogen, elixir-format
msgid "Sort by label"
msgstr "Sortiere nach Label"

#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:30
#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:31
#, elixir-autogen, elixir-format
msgid "Sort by likes"
msgstr "Sortiere nach Likes"
Expand Down Expand Up @@ -320,12 +320,12 @@ msgstr "Trete meinem Brainstorming bei."
msgid "Mindwendel Brainstorming"
msgstr "Mindwendel Brainstorming"

#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:37
#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:39
#, elixir-autogen, elixir-format
msgid "Share"
msgstr "Teilen"

#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:95
#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:97
#, elixir-autogen, elixir-format
msgid "Share brainstorming"
msgstr "Teile Dein Brainstorming"
Expand Down Expand Up @@ -355,7 +355,7 @@ msgstr "Idee bearbeiten"
msgid "Idea created updated"
msgstr ""

#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:83
#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:85
#, elixir-autogen, elixir-format
msgid "Update idea"
msgstr "Idee bearbeiten"
Expand All @@ -376,12 +376,12 @@ msgstr "Bist du sicher, dass das Brainstorming geleert werden soll?"
msgid "Empty brainstorming"
msgstr "Leere das Brainstorming"

#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:34
#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:35
#, elixir-autogen, elixir-format
msgid "Label"
msgstr "Label"

#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:31
#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:32
#, elixir-autogen, elixir-format
msgid "Likes"
msgstr "Likes"
Expand All @@ -406,7 +406,7 @@ msgstr "Nutzern das Verschieben von Ideen erlauben"
msgid "Back"
msgstr "Zurück"

#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:118
#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:120
#, elixir-autogen, elixir-format
msgid "+"
msgstr "+"
20 changes: 10 additions & 10 deletions priv/gettext/default.pot
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ msgstr ""
msgid "New brainstorming"
msgstr ""

#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:71
#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:73
#, elixir-autogen, elixir-format
msgid "New idea"
msgstr ""
Expand All @@ -121,7 +121,7 @@ msgstr ""
msgid "No ideas brainstormed"
msgstr ""

#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:121
#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:123
#, elixir-autogen, elixir-format
msgid "Open new idea page (Hotkey: i)"
msgstr ""
Expand All @@ -146,12 +146,12 @@ msgstr ""
msgid "Saving..."
msgstr ""

#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:33
#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:34
#, elixir-autogen, elixir-format
msgid "Sort by label"
msgstr ""

#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:30
#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:31
#, elixir-autogen, elixir-format
msgid "Sort by likes"
msgstr ""
Expand Down Expand Up @@ -319,12 +319,12 @@ msgstr ""
msgid "Mindwendel Brainstorming"
msgstr ""

#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:37
#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:39
#, elixir-autogen, elixir-format
msgid "Share"
msgstr ""

#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:95
#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:97
#, elixir-autogen, elixir-format
msgid "Share brainstorming"
msgstr ""
Expand Down Expand Up @@ -354,7 +354,7 @@ msgstr ""
msgid "Idea created updated"
msgstr ""

#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:83
#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:85
#, elixir-autogen, elixir-format
msgid "Update idea"
msgstr ""
Expand All @@ -375,12 +375,12 @@ msgstr ""
msgid "Empty brainstorming"
msgstr ""

#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:34
#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:35
#, elixir-autogen, elixir-format
msgid "Label"
msgstr ""

#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:31
#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:32
#, elixir-autogen, elixir-format
msgid "Likes"
msgstr ""
Expand All @@ -405,7 +405,7 @@ msgstr ""
msgid "Back"
msgstr ""

#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:118
#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:120
#, elixir-autogen, elixir-format
msgid "+"
msgstr ""
20 changes: 10 additions & 10 deletions priv/gettext/en/LC_MESSAGES/default.po
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ msgstr ""
msgid "New brainstorming"
msgstr ""

#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:71
#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:73
#, elixir-autogen, elixir-format
msgid "New idea"
msgstr ""
Expand All @@ -122,7 +122,7 @@ msgstr ""
msgid "No ideas brainstormed"
msgstr ""

#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:121
#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:123
#, elixir-autogen, elixir-format
msgid "Open new idea page (Hotkey: i)"
msgstr ""
Expand All @@ -147,12 +147,12 @@ msgstr ""
msgid "Saving..."
msgstr ""

#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:33
#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:34
#, elixir-autogen, elixir-format
msgid "Sort by label"
msgstr ""

#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:30
#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:31
#, elixir-autogen, elixir-format
msgid "Sort by likes"
msgstr ""
Expand Down Expand Up @@ -320,12 +320,12 @@ msgstr "Join my brainstorming"
msgid "Mindwendel Brainstorming"
msgstr "Mindwendel Brainstorming"

#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:37
#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:39
#, elixir-autogen, elixir-format
msgid "Share"
msgstr "Share"

#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:95
#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:97
#, elixir-autogen, elixir-format
msgid "Share brainstorming"
msgstr "Share brainstorming"
Expand Down Expand Up @@ -355,7 +355,7 @@ msgstr ""
msgid "Idea created updated"
msgstr ""

#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:83
#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:85
#, elixir-autogen, elixir-format
msgid "Update idea"
msgstr ""
Expand All @@ -376,12 +376,12 @@ msgstr "Are you sure that you want to delete this brainstorming?"
msgid "Empty brainstorming"
msgstr ""

#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:34
#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:35
#, elixir-autogen, elixir-format
msgid "Label"
msgstr ""

#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:31
#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:32
#, elixir-autogen, elixir-format
msgid "Likes"
msgstr ""
Expand All @@ -406,7 +406,7 @@ msgstr "Allow users to change the order of ideas"
msgid "Back"
msgstr ""

#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:118
#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:120
#, elixir-autogen, elixir-format
msgid "+"
msgstr ""
6 changes: 4 additions & 2 deletions test/mindwendel/ideas_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,15 @@ defmodule Mindwendel.IdeasTest do
second_idea =
Factory.insert!(:idea,
brainstorming: brainstorming,
label: Enum.at(brainstorming.labels, 0)
label: Enum.at(brainstorming.labels, 0),
inserted_at: ~N[2022-01-01 15:06:30]
)

third_idea =
Factory.insert!(:idea,
brainstorming: brainstorming,
label: Enum.at(brainstorming.labels, 1)
label: Enum.at(brainstorming.labels, 1),
inserted_at: ~N[2021-01-01 15:06:30]
)

Ideas.update_ideas_for_brainstorming_by_labels(brainstorming.id)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
defmodule MindwendelWeb.BrainstormingLive.ShowSortByLabelTest do
use MindwendelWeb.ConnCase
import Phoenix.LiveViewTest
alias Mindwendel.Brainstormings

alias Mindwendel.Factory

setup do
%{brainstorming: Factory.insert!(:brainstorming)}
moderating_user = Factory.insert!(:user)
brainstorming = Factory.insert!(:brainstorming)
Brainstormings.add_moderating_user(brainstorming, moderating_user)
%{brainstorming: brainstorming, moderating_user: moderating_user}
end

test "contains button \"Sort by labels\"", %{
conn: conn,
brainstorming: brainstorming
brainstorming: brainstorming,
moderating_user: moderating_user
} do
{:ok, show_live_view, _html} =
live(conn, Routes.brainstorming_show_path(conn, :show, brainstorming))
conn
|> init_test_session(%{current_user_id: moderating_user.id})
|> live(Routes.brainstorming_show_path(conn, :show, brainstorming))

assert show_live_view
|> has_element?(html_selector_button_sort_by_labels(brainstorming))
end

# The order of the labels is the defined by the column position_order
test "sort ideas by labels", %{conn: conn, brainstorming: brainstorming} do
test "sort ideas by labels", %{
conn: conn,
brainstorming: brainstorming,
moderating_user: moderating_user
} do
idea_with_first_label =
Factory.insert!(:idea, %{
brainstorming: brainstorming,
Expand All @@ -36,7 +47,9 @@ defmodule MindwendelWeb.BrainstormingLive.ShowSortByLabelTest do
idea_without_label = Factory.insert!(:idea, %{brainstorming: brainstorming})

{:ok, show_live_view, _html} =
live(conn, Routes.brainstorming_show_path(conn, :show, brainstorming))
conn
|> init_test_session(%{current_user_id: moderating_user.id})
|> live(Routes.brainstorming_show_path(conn, :show, brainstorming))

rendered =
show_live_view
Expand Down
Loading