-
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.
- Loading branch information
ks0m1c_dharma
committed
Jul 27, 2024
1 parent
55da916
commit 55408f6
Showing
10 changed files
with
360 additions
and
87 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
defmodule Vyasa.Draft do | ||
@moduledoc """ | ||
The Drafting Context for all your marking and binding needs | ||
""" | ||
|
||
import Ecto.Query, warn: false | ||
alias Vyasa.Adapters.Binding | ||
alias Vyasa.Sangh.Mark | ||
alias Vyasa.Sangh | ||
alias Vyasa.Repo | ||
|
||
|
||
|
||
def bind_node(%{"selection" => ""} = node) do | ||
bind_node(node, %Binding{}) | ||
end | ||
|
||
def bind_node(%{"selection" => selection} = node) do | ||
bind_node(Map.delete(node, "selection"), %Binding{:window => %{:quote => selection}}) | ||
end | ||
|
||
def bind_node(%{"field" => field} = node, bind) do | ||
bind_node(Map.delete(node, "field"), %{bind | field_key: String.split(field, "::") |> Enum.map(&(String.to_existing_atom(&1)))}) | ||
end | ||
|
||
def bind_node(%{"node" => node, "node_id" => node_id}, %Binding{} = bind) do | ||
n = node | ||
|> String.to_existing_atom() | ||
|> struct() | ||
|> Binding.field_lookup() | ||
|
||
%{bind | n => node_id, :node_id => node_id} | ||
end | ||
|
||
def create_comment([%Mark{} | _]= marks) do | ||
Sangh.create_comment(%{marks: marks}) | ||
end | ||
@doc """ | ||
Returns the list of marks. | ||
## Examples | ||
iex> list_marks() | ||
[%Mark{}, ...] | ||
""" | ||
def list_marks do | ||
Repo.all(Mark) | ||
end | ||
|
||
@doc """ | ||
Gets a single mark. | ||
Raises `Ecto.NoResultsError` if the Mark does not exist. | ||
## Examples | ||
iex> get_mark!(123) | ||
%Mark{} | ||
iex> get_mark!(456) | ||
** (Ecto.NoResultsError) | ||
""" | ||
def get_mark!(id), do: Repo.get!(Mark, id) | ||
|
||
@doc """ | ||
Creates a mark. | ||
## Examples | ||
iex> create_mark(%{field: value}) | ||
{:ok, %Mark{}} | ||
iex> create_mark(%{field: bad_value}) | ||
{:error, %Ecto.Changeset{}} | ||
""" | ||
def create_mark(attrs \\ %{}) do | ||
%Mark{} | ||
|> Mark.changeset(attrs) | ||
|> Repo.insert() | ||
end | ||
|
||
@doc """ | ||
Updates a mark. | ||
## Examples | ||
iex> update_mark(mark, %{field: new_value}) | ||
{:ok, %Mark{}} | ||
iex> update_mark(mark, %{field: bad_value}) | ||
{:error, %Ecto.Changeset{}} | ||
""" | ||
def update_mark(%Mark{} = mark, attrs) do | ||
mark | ||
|> Mark.changeset(attrs) | ||
|> Repo.update() | ||
end | ||
|
||
@doc """ | ||
Deletes a mark. | ||
## Examples | ||
iex> delete_mark(mark) | ||
{:ok, %Mark{}} | ||
iex> delete_mark(mark) | ||
{:error, %Ecto.Changeset{}} | ||
""" | ||
def delete_mark(%Mark{} = mark) do | ||
Repo.delete(mark) | ||
end | ||
|
||
@doc """ | ||
Returns an `%Ecto.Changeset{}` for tracking mark changes. | ||
## Examples | ||
iex> change_mark(mark) | ||
%Ecto.Changeset{data: %Mark{}} | ||
""" | ||
def change_mark(%Mark{} = mark, attrs \\ %{}) do | ||
Mark.changeset(mark, attrs) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
defmodule Vyasa.Sangh.Mark do | ||
@moduledoc """ | ||
Interpretation & bounding of binding | ||
""" | ||
|
||
use Ecto.Schema | ||
import Ecto.Changeset | ||
|
||
alias Vyasa.Sangh.{Comment} | ||
alias Vyasa.Adapters.Binding | ||
|
||
@primary_key {:id, Ecto.UUID, autogenerate: true} | ||
schema "marks" do | ||
field :body, :string | ||
field :order, :integer | ||
field :state, Ecto.Enum, values: [:draft, :bookmark, :live] | ||
field :verse_id, :string, virtual: true | ||
|
||
belongs_to :comment, Comment, foreign_key: :comment_id, type: :binary_id | ||
belongs_to :binding, Binding, foreign_key: :binding_id, type: :binary_id | ||
|
||
timestamps() | ||
end | ||
|
||
def changeset(event, attrs) do | ||
event | ||
|> cast(attrs, [:body, :order, :status, :comment_id, :binding_id]) | ||
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,43 @@ | ||
defmodule VyasaWeb.DraftMatrix do | ||
use VyasaWeb, :live_component | ||
|
||
@impl true | ||
def update(assigns, socket) do | ||
assigns = Enum.reject(assigns, fn {_k, v} -> is_nil(v) or v == [] end) | ||
|
||
{:ok, | ||
socket | ||
|> assign(assigns) | ||
|> assign_new(:actions, fn -> [] end) | ||
|> assign_new(:marks, fn -> [] end) | ||
|> assign_new(:custom_style, fn -> [] end)} | ||
end | ||
|
||
@impl true | ||
def handle_event("adjust", adjusted, socket) do | ||
style = Enum.map(adjusted, fn {key, val} -> | ||
"#{key}: #{val}" | ||
end) | ||
|
||
{:noreply, assign(socket, custom_style: style)} | ||
end | ||
|
||
@doc """ | ||
Renders a marginote w action slots for interaction with marginote | ||
""" | ||
@impl true | ||
def render(assigns) do | ||
~H""" | ||
<header class={["absolute z-50 shadow-sm", @actions != [] && "marginote"]} id={@id} | ||
style={["max-width: calc(-24px + 100vw)", @custom_style] |> List.flatten() |> Enum.join(";")}> | ||
<.form for={%{}} phx-submit="create_mark"> | ||
<input | ||
name="body" | ||
class="block lg:w-[80%] md:w-96 rounded-lg border border-gray-200 bg-gray-50 p-2 pl-5 text-sm text-gray-800" | ||
placeholder="Write here..." | ||
/> | ||
</.form> | ||
</header> | ||
""" | ||
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
Oops, something went wrong.