Participation panel revamp and fixes
Apollo is a pain in the ass with pagination & filters, so this removes the tabs system and uses a <select> to filter instead Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -92,7 +92,8 @@ defmodule Mobilizon.GraphQL.Resolvers.Event do
|
||||
|> Enum.map(&String.to_existing_atom/1)
|
||||
end
|
||||
|
||||
{:ok, Events.list_participants_for_event(event_id, roles, page, limit)}
|
||||
participants = Events.list_participants_for_event(event_id, roles, page, limit)
|
||||
{:ok, participants}
|
||||
else
|
||||
{:is_owned, nil} ->
|
||||
{:error, "Moderator Actor ID is not owned by authenticated user"}
|
||||
@@ -115,17 +116,12 @@ defmodule Mobilizon.GraphQL.Resolvers.Event do
|
||||
_args,
|
||||
%{context: %{current_user: %User{id: user_id} = _user}} = _resolution
|
||||
) do
|
||||
if Events.is_user_moderator_for_event?(user_id, event_id) do
|
||||
stats =
|
||||
Map.put(
|
||||
stats,
|
||||
:going,
|
||||
stats.participant + stats.moderator + stats.administrator + stats.creator
|
||||
)
|
||||
going = stats.participant + stats.moderator + stats.administrator + stats.creator
|
||||
|
||||
{:ok, stats}
|
||||
if Events.is_user_moderator_for_event?(user_id, event_id) do
|
||||
{:ok, Map.put(stats, :going, going)}
|
||||
else
|
||||
{:ok, %EventParticipantStats{}}
|
||||
{:ok, %{going: going}}
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -752,7 +752,6 @@ defmodule Mobilizon.Events do
|
||||
end
|
||||
|
||||
@moderator_roles [:moderator, :administrator, :creator]
|
||||
@default_participant_roles [:participant] ++ @moderator_roles
|
||||
|
||||
@doc """
|
||||
Returns the list of participants for an event.
|
||||
@@ -762,13 +761,14 @@ defmodule Mobilizon.Events do
|
||||
Page.t()
|
||||
def list_participants_for_event(
|
||||
id,
|
||||
roles \\ @default_participant_roles,
|
||||
roles \\ [],
|
||||
page \\ nil,
|
||||
limit \\ nil
|
||||
) do
|
||||
id
|
||||
|> list_participants_for_event_query()
|
||||
|> filter_role(roles)
|
||||
|> order_by(asc: :role)
|
||||
|> Page.build_page(page, limit)
|
||||
end
|
||||
|
||||
|
||||
@@ -4,11 +4,11 @@ defmodule Mobilizon.Web.ErrorView do
|
||||
"""
|
||||
use Mobilizon.Web, :view
|
||||
alias Mobilizon.Service.Metadata.Instance
|
||||
alias Mobilizon.Web.PageView
|
||||
import Mobilizon.Web.Views.Utils
|
||||
|
||||
def render("404.html", _assigns) do
|
||||
def render("404.html", %{conn: conn}) do
|
||||
tags = Instance.build_tags()
|
||||
PageView.inject_tags(tags)
|
||||
inject_tags(tags, get_locale(conn))
|
||||
end
|
||||
|
||||
def render("404.json", _assigns) do
|
||||
|
||||
@@ -13,10 +13,10 @@ defmodule Mobilizon.Web.PageView do
|
||||
|
||||
alias Mobilizon.Service.Metadata
|
||||
alias Mobilizon.Service.Metadata.Instance
|
||||
alias Mobilizon.Service.Metadata.Utils, as: MetadataUtils
|
||||
|
||||
alias Mobilizon.Federation.ActivityPub.Utils
|
||||
alias Mobilizon.Federation.ActivityStream.Convertible
|
||||
import Mobilizon.Web.Views.Utils
|
||||
|
||||
def render("actor.activity-json", %{conn: %{assigns: %{object: %Actor{} = actor}}}) do
|
||||
actor
|
||||
@@ -59,38 +59,4 @@ defmodule Mobilizon.Web.PageView do
|
||||
tags = Instance.build_tags()
|
||||
inject_tags(tags, get_locale(conn))
|
||||
end
|
||||
|
||||
@spec inject_tags(List.t(), String.t()) :: {:safe, String.t()}
|
||||
def inject_tags(tags, locale \\ "en") do
|
||||
with {:ok, index_content} <- File.read(index_file_path()) do
|
||||
do_replacements(index_content, MetadataUtils.stringify_tags(tags), locale)
|
||||
end
|
||||
end
|
||||
|
||||
@spec index_file_path :: String.t()
|
||||
defp index_file_path do
|
||||
Path.join(Application.app_dir(:mobilizon, "priv/static"), "index.html")
|
||||
end
|
||||
|
||||
@spec replace_meta(String.t(), String.t()) :: String.t()
|
||||
# TODO: Find why it's different in dev/prod and during tests
|
||||
defp replace_meta(index_content, tags) do
|
||||
index_content
|
||||
|> String.replace("<meta name=\"server-injected-data\" />", tags)
|
||||
|> String.replace("<meta name=server-injected-data>", tags)
|
||||
end
|
||||
|
||||
@spec do_replacements(String.t(), String.t(), String.t()) :: {:safe, String.t()}
|
||||
defp do_replacements(index_content, tags, locale) do
|
||||
index_content
|
||||
|> replace_meta(tags)
|
||||
|> String.replace("<html lang=\"en\">", "<html lang=\"#{locale}\">")
|
||||
|> String.replace("<html lang=en>", "<html lang=\"#{locale}\">")
|
||||
|> (&{:safe, &1}).()
|
||||
end
|
||||
|
||||
@spec get_locale(Conn.t()) :: String.t()
|
||||
defp get_locale(%{private: %{cldr_locale: nil}}), do: "en"
|
||||
defp get_locale(%{private: %{cldr_locale: %{requested_locale_name: locale}}}), do: locale
|
||||
defp get_locale(_), do: "en"
|
||||
end
|
||||
|
||||
41
lib/web/views/utils.ex
Normal file
41
lib/web/views/utils.ex
Normal file
@@ -0,0 +1,41 @@
|
||||
defmodule Mobilizon.Web.Views.Utils do
|
||||
@moduledoc """
|
||||
Utils for views
|
||||
"""
|
||||
|
||||
alias Mobilizon.Service.Metadata.Utils, as: MetadataUtils
|
||||
|
||||
@spec inject_tags(List.t(), String.t()) :: {:safe, String.t()}
|
||||
def inject_tags(tags, locale \\ "en") do
|
||||
with {:ok, index_content} <- File.read(index_file_path()) do
|
||||
do_replacements(index_content, MetadataUtils.stringify_tags(tags), locale)
|
||||
end
|
||||
end
|
||||
|
||||
@spec index_file_path :: String.t()
|
||||
defp index_file_path do
|
||||
Path.join(Application.app_dir(:mobilizon, "priv/static"), "index.html")
|
||||
end
|
||||
|
||||
@spec replace_meta(String.t(), String.t()) :: String.t()
|
||||
# TODO: Find why it's different in dev/prod and during tests
|
||||
defp replace_meta(index_content, tags) do
|
||||
index_content
|
||||
|> String.replace("<meta name=\"server-injected-data\" />", tags)
|
||||
|> String.replace("<meta name=server-injected-data>", tags)
|
||||
end
|
||||
|
||||
@spec do_replacements(String.t(), String.t(), String.t()) :: {:safe, String.t()}
|
||||
defp do_replacements(index_content, tags, locale) do
|
||||
index_content
|
||||
|> replace_meta(tags)
|
||||
|> String.replace("<html lang=\"en\">", "<html lang=\"#{locale}\">")
|
||||
|> String.replace("<html lang=en>", "<html lang=\"#{locale}\">")
|
||||
|> (&{:safe, &1}).()
|
||||
end
|
||||
|
||||
@spec get_locale(Conn.t()) :: String.t()
|
||||
def get_locale(%{private: %{cldr_locale: nil}}), do: "en"
|
||||
def get_locale(%{private: %{cldr_locale: %{requested_locale_name: locale}}}), do: locale
|
||||
def get_locale(_), do: "en"
|
||||
end
|
||||
Reference in New Issue
Block a user