-
-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0a35c26
commit 4129bcf
Showing
6 changed files
with
145 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
defmodule PlexusWeb.Admin.RatingLive.Index do | ||
use PlexusWeb, :live_view | ||
|
||
alias Plexus.Apps | ||
alias Plexus.Ratings | ||
|
||
@impl Phoenix.LiveView | ||
def mount(%{"package" => package, "google_lib" => google_lib}, _session, socket) do | ||
if connected?(socket), do: Apps.subscribe(package) | ||
|
||
page = | ||
Ratings.list_ratings(package, | ||
google_lib: google_lib, | ||
page_size: 9999, | ||
order_by: [desc: :app_build_number, desc: :updated_at] | ||
) | ||
|
||
{:ok, | ||
socket | ||
|> assign(:google_lib, google_lib) | ||
|> assign(:app, Apps.get_app!(package, scores: true)) | ||
|> stream(:ratings, page.entries)} | ||
end | ||
|
||
@impl Phoenix.LiveView | ||
def handle_params(params, _url, socket) do | ||
{:noreply, apply_action(socket, socket.assigns.live_action, params)} | ||
end | ||
|
||
defp apply_action(socket, :index, _params) do | ||
socket | ||
|> assign(:page_title, "#{socket.assigns.app.name} Ratings") | ||
end | ||
|
||
@impl Phoenix.LiveView | ||
def handle_info({:app_updated, app}, socket) do | ||
{:noreply, | ||
socket | ||
|> put_flash(:info, "'#{app.name}' Updated") | ||
|> assign(:app, Apps.get_app!(app.package, scores: true))} | ||
end | ||
|
||
def handle_info({:app_deleted, _app}, socket) do | ||
{:noreply, push_navigate(socket, to: ~p"/admin/apps")} | ||
end | ||
|
||
def handle_info({:rating_deleted, rating}, socket) do | ||
{:noreply, | ||
socket | ||
|> put_flash(:info, "Rating Deleted") | ||
|> assign(:app, Apps.get_app!(socket.assigns.app.package, scores: true)) | ||
|> stream_delete(:ratings, rating)} | ||
end | ||
|
||
def handle_info({:app_rating_updated, rating}, socket) do | ||
if rating.google_lib == String.to_existing_atom(socket.assigns.google_lib) do | ||
{:noreply, | ||
socket | ||
|> put_flash(:info, "Rating Added") | ||
|> assign(:app, Apps.get_app!(rating.app_package, scores: true)) | ||
|> stream_insert(:ratings, rating)} | ||
else | ||
{:noreply, socket} | ||
end | ||
end | ||
|
||
@impl Phoenix.LiveView | ||
def handle_event("delete", %{"id" => id}, socket) do | ||
{:ok, rating} = | ||
id | ||
|> Ratings.get_rating!() | ||
|> Ratings.delete_rating() | ||
|
||
{:noreply, stream_delete(socket, :ratings, rating)} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<.header> | ||
<%= @app.name %> <%= if @google_lib == "none", do: "Native", else: "MicroG" %> Ratings | ||
<:subtitle> | ||
<.badge score={Enum.find(@app.scores, &(to_string(&1.google_lib) == @google_lib))} /> | ||
</:subtitle> | ||
</.header> | ||
|
||
<.table id="ratings" rows={@streams.ratings}> | ||
<:col :let={{_id, rating}} label="Score"> | ||
<p class="text-sm text-gray-700"><%= rating.score %></p> | ||
</:col> | ||
<:col :let={{_id, rating}} label="App Version"> | ||
<p class="text-sm text-gray-700"> | ||
<%= rating.app_version %> (<%= rating.app_build_number %>) | ||
</p> | ||
</:col> | ||
<:col :let={{_id, rating}} label="ROM"> | ||
<p class="text-sm text-gray-700"><%= rating.rom_name %> (<%= rating.rom_build %>)</p> | ||
</:col> | ||
<:col :let={{_id, rating}} label="Android Version"> | ||
<p class="text-sm text-gray-700"><%= rating.android_version %></p> | ||
</:col> | ||
<:col :let={{_id, rating}} label="Installation Source"> | ||
<p class="text-sm text-gray-700"><%= rating.installation_source %></p> | ||
</:col> | ||
<:col :let={{_id, rating}} label="Notes"> | ||
<p class="text-sm text-gray-700 whitespace-pre-line"><%= rating.notes %></p> | ||
</:col> | ||
<:action :let={{id, rating}}> | ||
<.link | ||
phx-click={JS.push("delete", value: %{id: rating.id}) |> hide("##{id}")} | ||
data-confirm="Are you sure?" | ||
> | ||
Delete | ||
</.link> | ||
</:action> | ||
</.table> | ||
|
||
<.back navigate={~p"/admin/apps/#{@app}"}>Back to app</.back> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters