-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from ve1ld/ops/AdminControls
Dynamic Admin Controls
- Loading branch information
Showing
11 changed files
with
124 additions
and
20 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 |
---|---|---|
@@ -1,6 +1,5 @@ | ||
defmodule Vyasa.Medium.Event do | ||
use Ecto.Schema | ||
|
||
import Ecto.Changeset | ||
|
||
alias Vyasa.Written.{Verse, Source} | ||
|
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 |
---|---|---|
|
@@ -144,6 +144,7 @@ defmodule Vyasa.Written do | |
|> Repo.preload([:verses, :translations]) | ||
|
||
chapter.verses | ||
|
||
end | ||
|
||
@doc """ | ||
|
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,79 @@ | ||
defmodule VyasaWeb.Admin.Written.Verse do | ||
use LiveAdmin.Resource, schema: Vyasa.Written.Verse | ||
end | ||
|
||
defmodule VyasaWeb.Admin.Medium.Event do | ||
use LiveAdmin.Resource, schema: Vyasa.Medium.Event, | ||
immutable_fields: [:source_id], | ||
actions: [:silence, :next, :prev], | ||
render_with: :render_field | ||
|
||
|
||
|
||
def render_field(record, field, session) do | ||
VyasaWeb.Admin.Renderer.render_field(record, field, session) | ||
end | ||
|
||
|
||
def silence(%{voice: _v} = e, _sess) do | ||
e = %{e | voice: nil} | ||
{:ok, e} | ||
end | ||
|
||
def next(%{voice: _v} = e, _sess) do | ||
{:ok, Vyasa.Medium.get_event_by_order!(e, 1)} | ||
end | ||
|
||
def prev(%{voice: _v} = e, _sess) do | ||
{:ok, Vyasa.Medium.get_event_by_order!(e, -1)} | ||
end | ||
end | ||
|
||
|
||
defmodule VyasaWeb.Admin.Renderer do | ||
use Phoenix.Component | ||
|
||
def render_field(%{origin: o, voice: %Vyasa.Medium.Voice{} = v} = assigns, :phase, _session) do | ||
assigns = %{assigns | origin: floor(o/1000), voice: Vyasa.Medium.Store.hydrate(v)} | ||
~H""" | ||
<%= @phase %> | ||
<audio id={"#{@origin}-audioplayback"} controls preload="metadata"> | ||
<source src={@voice.file_path <> "#t=#{@origin}"} type="audio/mp3"> | ||
</audio> | ||
""" | ||
end | ||
|
||
def render_field(%{verse: %Vyasa.Written.Verse{} = v} = assigns, :verse_id, _session) do | ||
assigns = %{assigns | verse: v |> Vyasa.Repo.preload(:translations)} | ||
~H""" | ||
<div class="flex items-center justify-center"> | ||
<%= @verse.body %> | ||
</div> | ||
<div class="whitespace-pre-line"> | ||
<%= List.first(@verse.translations).target.body_translit %> | ||
</div> | ||
""" | ||
end | ||
|
||
|
||
def render_field(record, field, _session) do | ||
IO.inspect(field) | ||
record | ||
|> Map.fetch!(field) | ||
|> case do | ||
bool when is_boolean(bool) -> | ||
if bool, do: "Yes", else: "No" | ||
date = %Date{} -> | ||
Calendar.strftime(date, "%a, %B %d %Y") | ||
bin when is_binary(bin) -> bin | ||
_ -> | ||
record | ||
|> Map.fetch!(field) | ||
|> case do | ||
val when is_binary(val) -> val | ||
val -> inspect(val, pretty: true) | ||
end | ||
end | ||
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
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