Update the code format.
This commit is contained in:
@@ -74,7 +74,10 @@ defmodule DecentralisedBookIndexWeb.AuthorLive.FormComponent do
|
||||
end
|
||||
|
||||
def handle_event("save", %{"author" => author_params}, socket) do
|
||||
case AshPhoenix.Form.submit(socket.assigns.form, params: author_params, actor: socket.assigns.current_user) do
|
||||
case AshPhoenix.Form.submit(socket.assigns.form,
|
||||
params: author_params,
|
||||
actor: socket.assigns.current_user
|
||||
) do
|
||||
{:ok, author} ->
|
||||
notify_parent({:saved, author})
|
||||
|
||||
@@ -103,7 +106,9 @@ defmodule DecentralisedBookIndexWeb.AuthorLive.FormComponent do
|
||||
|
||||
defp notify_parent(msg), do: send(self(), {__MODULE__, msg})
|
||||
|
||||
defp assign_form(%{assigns: %{author: author, alternative_author_id: alternative_author_id}} = socket) do
|
||||
defp assign_form(
|
||||
%{assigns: %{author: author, alternative_author_id: alternative_author_id}} = socket
|
||||
) do
|
||||
alias_id =
|
||||
if alternative_author_id == nil do
|
||||
nil
|
||||
@@ -142,8 +147,8 @@ defmodule DecentralisedBookIndexWeb.AuthorLive.FormComponent do
|
||||
defp patch_url(action, author_id) do
|
||||
case action do
|
||||
:edit -> ~p"/authors/#{author_id}"
|
||||
:new -> ~p"/authors"
|
||||
_ -> ~p"/authors"
|
||||
:new -> ~p"/authors"
|
||||
_ -> ~p"/authors"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -60,12 +60,13 @@ defmodule DecentralisedBookIndexWeb.AuthorLive.Index do
|
||||
sort_by = Map.get(params, "sort_by", "name") |> validate_sort_by()
|
||||
page_params = AshPhoenix.LiveView.page_from_params(params, 10)
|
||||
|
||||
page = Metadata.search_author!(
|
||||
search_query,
|
||||
query: [sort_input: sort_by],
|
||||
page: page_params ++ [count: true],
|
||||
actor: socket.assigns.current_user
|
||||
)
|
||||
page =
|
||||
Metadata.search_author!(
|
||||
search_query,
|
||||
query: [sort_input: sort_by],
|
||||
page: page_params ++ [count: true],
|
||||
actor: socket.assigns.current_user
|
||||
)
|
||||
|
||||
socket =
|
||||
socket
|
||||
@@ -110,7 +111,7 @@ defmodule DecentralisedBookIndexWeb.AuthorLive.Index do
|
||||
[
|
||||
{"Sort by name", "name"},
|
||||
{"Sort by recently updated", "-updated_at"},
|
||||
{"Sort by recently added", "-inserted_at"},
|
||||
{"Sort by recently added", "-inserted_at"}
|
||||
]
|
||||
end
|
||||
|
||||
|
||||
@@ -71,15 +71,16 @@ defmodule DecentralisedBookIndexWeb.AuthorLive.Show do
|
||||
|
||||
@impl true
|
||||
def handle_params(%{"id" => id}, _, socket) do
|
||||
author = Ash.get!(DecentralisedBookIndex.Metadata.Author, id, actor: socket.assigns.current_user)
|
||||
author =
|
||||
Ash.get!(DecentralisedBookIndex.Metadata.Author, id, actor: socket.assigns.current_user)
|
||||
|
||||
alternative_names = DecentralisedBookIndex.Metadata.get_author_alternative_names!(author)
|
||||
|
||||
{:noreply,
|
||||
socket
|
||||
|> assign(:page_title, page_title(socket.assigns.live_action))
|
||||
|> assign(:author, author)
|
||||
|> assign(:alternative_names, alternative_names)
|
||||
}
|
||||
|> assign(:alternative_names, alternative_names)}
|
||||
end
|
||||
|
||||
defp page_title(:show), do: "Show Author"
|
||||
|
||||
@@ -373,7 +373,9 @@ defmodule DecentralisedBookIndexWeb.BookLive.FormComponent do
|
||||
defp set_book_edition_registry_id(form, alternative_edition_id) do
|
||||
if alternative_edition_id != nil do
|
||||
form
|
||||
|> AshPhoenix.Form.update_params(&Map.put(&1, "book_editions_registry_id", alternative_edition_id))
|
||||
|> AshPhoenix.Form.update_params(
|
||||
&Map.put(&1, "book_editions_registry_id", alternative_edition_id)
|
||||
)
|
||||
else
|
||||
form
|
||||
end
|
||||
@@ -382,8 +384,8 @@ defmodule DecentralisedBookIndexWeb.BookLive.FormComponent do
|
||||
defp patch_url(action, book_id) do
|
||||
case action do
|
||||
:edit -> ~p"/books/#{book_id}"
|
||||
:new -> ~p"/books"
|
||||
_ -> ~p"/books"
|
||||
:new -> ~p"/books"
|
||||
_ -> ~p"/books"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -71,13 +71,14 @@ defmodule DecentralisedBookIndexWeb.BookLive.Index do
|
||||
search_mode = Map.get(params, "search_mode", "title") |> validate_search_mode()
|
||||
page_params = AshPhoenix.LiveView.page_from_params(params, 10)
|
||||
|
||||
page = search(
|
||||
search_mode,
|
||||
search_query,
|
||||
page_params,
|
||||
sort_by: sort_by,
|
||||
actor: socket.assigns[:current_user]
|
||||
)
|
||||
page =
|
||||
search(
|
||||
search_mode,
|
||||
search_query,
|
||||
page_params,
|
||||
sort_by: sort_by,
|
||||
actor: socket.assigns[:current_user]
|
||||
)
|
||||
|
||||
socket =
|
||||
socket
|
||||
@@ -129,7 +130,7 @@ defmodule DecentralisedBookIndexWeb.BookLive.Index do
|
||||
[
|
||||
{"Sort by title", "title"},
|
||||
{"Sort by recently updated", "-updated_at"},
|
||||
{"Sort by recently added", "-inserted_at"},
|
||||
{"Sort by recently added", "-inserted_at"}
|
||||
]
|
||||
end
|
||||
|
||||
@@ -157,7 +158,7 @@ defmodule DecentralisedBookIndexWeb.BookLive.Index do
|
||||
{"Search by title", "title"},
|
||||
{"Search by isbn13", "isbn13"},
|
||||
{"Search by isbn", "isbn"},
|
||||
{"Search by asin", "asin"},
|
||||
{"Search by asin", "asin"}
|
||||
]
|
||||
end
|
||||
|
||||
@@ -182,7 +183,7 @@ defmodule DecentralisedBookIndexWeb.BookLive.Index do
|
||||
|
||||
def search(search_mode, search_query, page_params, opts \\ []) do
|
||||
sort_by = Keyword.get(opts, :sort_by, nil)
|
||||
actor = Keyword.get(opts, :actor, nil)
|
||||
actor = Keyword.get(opts, :actor, nil)
|
||||
|
||||
case search_mode do
|
||||
"title" ->
|
||||
@@ -212,5 +213,4 @@ defmodule DecentralisedBookIndexWeb.BookLive.Index do
|
||||
|
||||
{:noreply, push_patch(socket, to: ~p"/books?#{params}")}
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -99,15 +99,19 @@ defmodule DecentralisedBookIndexWeb.BookLive.Show do
|
||||
|
||||
@impl true
|
||||
def handle_params(%{"id" => id}, _, socket) do
|
||||
book = Ash.get!(Metadata.Book, id, actor: socket.assigns.current_user, load: [:bids, :author_roles, :publisher])
|
||||
book =
|
||||
Ash.get!(Metadata.Book, id,
|
||||
actor: socket.assigns.current_user,
|
||||
load: [:bids, :author_roles, :publisher]
|
||||
)
|
||||
|
||||
alternative_editions = Metadata.get_book_alternative_editions!(book)
|
||||
|
||||
{:noreply,
|
||||
socket
|
||||
|> assign(:page_title, page_title(socket.assigns.live_action))
|
||||
|> assign(:book, book)
|
||||
|> assign(:alternative_editions, alternative_editions)
|
||||
}
|
||||
|> assign(:alternative_editions, alternative_editions)}
|
||||
end
|
||||
|
||||
defp page_title(:show), do: "Show Book"
|
||||
@@ -118,6 +122,7 @@ defmodule DecentralisedBookIndexWeb.BookLive.Show do
|
||||
def authors(assigns) do
|
||||
author_roles = Metadata.get_author_roles_by_book_id!(assigns.book.id, load: [:author])
|
||||
author_count = length(author_roles)
|
||||
|
||||
authors_string =
|
||||
author_roles
|
||||
|> Enum.map(fn author_role ->
|
||||
|
||||
@@ -50,7 +50,10 @@ defmodule DecentralisedBookIndexWeb.DbiServerLive.Edit do
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_info({DecentralisedBookIndexWeb.DbiServerLive.FormComponent, {:saved, _dbi_server}}, socket) do
|
||||
def handle_info(
|
||||
{DecentralisedBookIndexWeb.DbiServerLive.FormComponent, {:saved, _dbi_server}},
|
||||
socket
|
||||
) do
|
||||
{:noreply, socket}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -99,8 +99,8 @@ defmodule DecentralisedBookIndexWeb.DbiServerLive.FormComponent do
|
||||
defp patch_url(action, server_id) do
|
||||
case action do
|
||||
:edit -> ~p"/servers/#{server_id}"
|
||||
:new -> ~p"/servers"
|
||||
_ -> ~p"/servers"
|
||||
:new -> ~p"/servers"
|
||||
_ -> ~p"/servers"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -100,12 +100,13 @@ defmodule DecentralisedBookIndexWeb.DbiServerLive.Index do
|
||||
sort_by = Map.get(params, "sort_by", "name") |> validate_sort_by()
|
||||
page_params = AshPhoenix.LiveView.page_from_params(params, 10)
|
||||
|
||||
page = Metadata.search_dbi_server!(
|
||||
search_query,
|
||||
query: [sort_input: sort_by],
|
||||
page: page_params ++ [count: true],
|
||||
actor: socket.assigns.current_user
|
||||
)
|
||||
page =
|
||||
Metadata.search_dbi_server!(
|
||||
search_query,
|
||||
query: [sort_input: sort_by],
|
||||
page: page_params ++ [count: true],
|
||||
actor: socket.assigns.current_user
|
||||
)
|
||||
|
||||
socket =
|
||||
socket
|
||||
@@ -163,7 +164,7 @@ defmodule DecentralisedBookIndexWeb.DbiServerLive.Index do
|
||||
[
|
||||
{"Sort by name", "name"},
|
||||
{"Sort by recently updated", "-updated_at"},
|
||||
{"Sort by recently added", "-inserted_at"},
|
||||
{"Sort by recently added", "-inserted_at"}
|
||||
]
|
||||
end
|
||||
|
||||
|
||||
@@ -50,7 +50,10 @@ defmodule DecentralisedBookIndexWeb.PublisherLive.Edit do
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_info({DecentralisedBookIndexWeb.PublisherLive.FormComponent, {:saved, _publisher}}, socket) do
|
||||
def handle_info(
|
||||
{DecentralisedBookIndexWeb.PublisherLive.FormComponent, {:saved, _publisher}},
|
||||
socket
|
||||
) do
|
||||
{:noreply, socket}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -100,8 +100,8 @@ defmodule DecentralisedBookIndexWeb.PublisherLive.FormComponent do
|
||||
defp patch_url(action, publisher_id) do
|
||||
case action do
|
||||
:edit -> ~p"/publishers/#{publisher_id}"
|
||||
:new -> ~p"/publishers"
|
||||
_ -> ~p"/publishers"
|
||||
:new -> ~p"/publishers"
|
||||
_ -> ~p"/publishers"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -71,12 +71,13 @@ defmodule DecentralisedBookIndexWeb.PublisherLive.Index do
|
||||
sort_by = Map.get(params, "sort_by", "name") |> validate_sort_by()
|
||||
page_params = AshPhoenix.LiveView.page_from_params(params, 10)
|
||||
|
||||
page = Metadata.search_publisher!(
|
||||
search_query,
|
||||
query: [sort_input: sort_by],
|
||||
page: page_params ++ [count: true],
|
||||
actor: socket.assigns.current_user
|
||||
)
|
||||
page =
|
||||
Metadata.search_publisher!(
|
||||
search_query,
|
||||
query: [sort_input: sort_by],
|
||||
page: page_params ++ [count: true],
|
||||
actor: socket.assigns.current_user
|
||||
)
|
||||
|
||||
socket =
|
||||
socket
|
||||
@@ -124,7 +125,7 @@ defmodule DecentralisedBookIndexWeb.PublisherLive.Index do
|
||||
[
|
||||
{"Sort by name", "name"},
|
||||
{"Sort by recently updated", "-updated_at"},
|
||||
{"Sort by recently added", "-inserted_at"},
|
||||
{"Sort by recently added", "-inserted_at"}
|
||||
]
|
||||
end
|
||||
|
||||
|
||||
@@ -56,7 +56,6 @@ defmodule DecentralisedBookIndexWeb.UserLive.Index do
|
||||
/>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
"""
|
||||
end
|
||||
|
||||
@@ -71,12 +70,13 @@ defmodule DecentralisedBookIndexWeb.UserLive.Index do
|
||||
sort_by = Map.get(params, "sort_by", "name") |> validate_sort_by()
|
||||
page_params = AshPhoenix.LiveView.page_from_params(params, 10)
|
||||
|
||||
page = User.search!(
|
||||
search_query,
|
||||
query: [sort_input: sort_by],
|
||||
page: page_params ++ [count: true],
|
||||
actor: socket.assigns.current_user
|
||||
)
|
||||
page =
|
||||
User.search!(
|
||||
search_query,
|
||||
query: [sort_input: sort_by],
|
||||
page: page_params ++ [count: true],
|
||||
actor: socket.assigns.current_user
|
||||
)
|
||||
|
||||
socket =
|
||||
socket
|
||||
@@ -101,7 +101,7 @@ defmodule DecentralisedBookIndexWeb.UserLive.Index do
|
||||
[
|
||||
{"Sort by email", "email"},
|
||||
{"Sort by role", "role"},
|
||||
{"Sort by role desc", "-role"},
|
||||
{"Sort by role desc", "-role"}
|
||||
]
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user