diff --git a/docs/migration_wow.livemd b/docs/migration_wow.livemd index 38b18d61..af8e2b9c 100644 --- a/docs/migration_wow.livemd +++ b/docs/migration_wow.livemd @@ -54,7 +54,6 @@ Vyasa.Release.migrate() ```elixir Path.expand(mypath, "#{File.cwd!()}/data/Elixir.Vyasa.Written.Source") -|> Vyasa.Corpus.Migrator.Restore.read() |> Vyasa.Corpus.Migrator.Restore.run() ``` @@ -93,10 +92,12 @@ end) ```elixir # can test if events are seeded correctly here: voice_id = "b1db78be-0bdf-443c-afdf-3221bac38758" -loaded_voice = Vyasa.Repo.get(Vyasa.Medium.Voice, voice_id) -|> Vyasa.Medium.get_voices!() -|> List.first() -|> Vyasa.Medium.Store.hydrate() + +loaded_voice = + Vyasa.Repo.get(Vyasa.Medium.Voice, voice_id) + |> Vyasa.Medium.get_voices!() + |> List.first() + |> Vyasa.Medium.Store.hydrate() loaded_voice.events ``` diff --git a/lib/vyasa/corpus/migrator/restore.ex b/lib/vyasa/corpus/migrator/restore.ex index 9f0ed127..bf7d2fca 100644 --- a/lib/vyasa/corpus/migrator/restore.ex +++ b/lib/vyasa/corpus/migrator/restore.ex @@ -41,6 +41,7 @@ defmodule Vyasa.Corpus.Migrator.Restore do # events are dependent on both verse and voice source + |> read() |> Enum.map(fn x -> # &1["translations"] x["events"] diff --git a/lib/vyasa/draft.ex b/lib/vyasa/draft.ex index f525372e..1e90739e 100644 --- a/lib/vyasa/draft.ex +++ b/lib/vyasa/draft.ex @@ -6,7 +6,6 @@ defmodule Vyasa.Draft do import Ecto.Query, warn: false alias Vyasa.Adapters.Binding alias Vyasa.Sangh.Mark - alias Vyasa.Sangh alias Vyasa.Repo # Inits the binding for an empty selection @@ -45,10 +44,6 @@ defmodule Vyasa.Draft do %{bind | node_field_name => 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. diff --git a/lib/vyasa/sangh/comments.ex b/lib/vyasa/sangh/comments.ex index c12c6ee7..4a190b04 100644 --- a/lib/vyasa/sangh/comments.ex +++ b/lib/vyasa/sangh/comments.ex @@ -1,4 +1,13 @@ defmodule Vyasa.Sangh.Comment do + @moduledoc """ + Not your traditional comments, waypoints and containers for marks + so that they can be referred to and moved around + + Can create a trail of marks and tied to session + Can seperate marks into collapsible categories + + Sangh session Ids is SOT on shared and individual context + """ use Ecto.Schema import Ecto.Changeset alias EctoLtree.LabelTree, as: Ltree @@ -10,22 +19,22 @@ defmodule Vyasa.Sangh.Comment do field :active, :boolean, default: true field :path, Ltree field :signature, :string + field :traits, {:array, :string}, default: [] field :child_count, :integer, default: 0, virtual: true belongs_to :session, Session, references: :id, type: Ecto.UUID belongs_to :parent, Comment, references: :id, type: Ecto.UUID - #has_many :marks, Mark, references: :id, foreign_key: :comment_bind_id, on_replace: :delete_if_exists + has_many :marks, Mark, references: :id, foreign_key: :comment_id, on_replace: :delete_if_exists #has_many :bindings, Binding, references: :id, foreign_key: :comment_bind_id, on_replace: :delete_if_exists - timestamps() end @doc false def changeset(%Comment{} = comment, attrs) do comment - |> cast(attrs, [:id, :body, :path, :chapter_number, :p_type, :session_id, :parent_id, :text_id]) - |> cast_assoc(:bindings, with: &Mark.changeset/2) + |> cast(attrs, [:id, :body, :path, :session_id, :signature, :parent_id]) + |> cast_assoc(:marks, with: &Mark.changeset/2) |> validate_required([:id, :session_id]) end diff --git a/lib/vyasa/sangh/mark.ex b/lib/vyasa/sangh/mark.ex index e14d2673..c539de4e 100644 --- a/lib/vyasa/sangh/mark.ex +++ b/lib/vyasa/sangh/mark.ex @@ -27,7 +27,7 @@ defmodule Vyasa.Sangh.Mark do def changeset(event, attrs) do event - |> cast(attrs, [:body, :order, :status, :comment_id, :binding_id]) + |> cast(attrs, [:body, :order, :state, :comment_id, :binding_id]) end def update_mark(%Mark{} = draft_mark, opts \\ []) do diff --git a/lib/vyasa/sangh/session.ex b/lib/vyasa/sangh/session.ex index eee306f4..b77789d6 100644 --- a/lib/vyasa/sangh/session.ex +++ b/lib/vyasa/sangh/session.ex @@ -4,6 +4,7 @@ defmodule Vyasa.Sangh.Session do alias Vyasa.Sangh.{Comment} + @derive {Jason.Encoder, only: [:id]} @primary_key {:id, Ecto.UUID, autogenerate: true} schema "sessions" do @@ -16,6 +17,5 @@ defmodule Vyasa.Sangh.Session do def changeset(session, attrs) do session |> cast(attrs, [:id]) - |> validate_required([:id]) end end diff --git a/lib/vyasa/written/verse.ex b/lib/vyasa/written/verse.ex index 5659677d..95b56461 100644 --- a/lib/vyasa/written/verse.ex +++ b/lib/vyasa/written/verse.ex @@ -3,20 +3,18 @@ defmodule Vyasa.Written.Verse do import Ecto.Changeset alias Vyasa.Written.{Source, Chapter, Translation} - alias Vyasa.Sangh.{Comment} - alias Vyasa.Adapters.Binding @primary_key {:id, Ecto.UUID, autogenerate: true} schema "verses" do field :no, :integer field :body, :string field :binding, :map, virtual: true + field :comments, {:array, :map}, virtual: true, default: [] belongs_to :source, Source, type: Ecto.UUID belongs_to :chapter, Chapter, type: :integer, references: :no, foreign_key: :chapter_no has_many :translations, Translation - many_to_many :comments, Comment, join_through: Binding end @doc false diff --git a/lib/vyasa_web/components/source_content/reading_content.ex b/lib/vyasa_web/components/source_content/reading_content.ex index 6f500748..fcf582ac 100644 --- a/lib/vyasa_web/components/source_content/reading_content.ex +++ b/lib/vyasa_web/components/source_content/reading_content.ex @@ -13,7 +13,7 @@ defmodule VyasaWeb.Content.ReadingContent do alias Vyasa.Medium.{Voice} alias Vyasa.Written.{Source, Chapter} alias Phoenix.LiveView.Socket - alias Vyasa.Sangh.{Comment, Mark} + alias Vyasa.Sangh.{Mark} alias VyasaWeb.OgImageController @impl true @@ -43,7 +43,7 @@ defmodule VyasaWeb.Content.ReadingContent do @impl true # received updates from parent liveview when a handshake is init, does a pub for the voice to use def update( - %{id: "reading-content", sess_id: sess_id} = _props, + %{id: "reading-content"} = _props, %{ assigns: %{ session: %{id: sess_id}, @@ -127,27 +127,16 @@ defmodule VyasaWeb.Content.ReadingContent do socket - |> sync_session() - |> assign(:content_action, :show_verses) - |> maybe_stream_configure(:verses, dom_id: &"verse-#{&1.id}") - |> stream(:verses, verses) |> assign( :kv_verses, # creates a map of verse_id_to_verses - Enum.into( - verses, - %{}, - &{&1.id, - %{ - &1 - | comments: [ - %Comment{signature: "Pope", body: "Achilles’ wrath, to Greece the direful spring - Of woes unnumber’d, heavenly goddess, sing"} - ] - }} - ) - ) + Enum.into(verses, %{},&({&1.id, &1}) + )) |> assign(:marks, [%Mark{state: :draft, order: 0}]) + |> sync_session() + |> assign(:content_action, :show_verses) + |> maybe_stream_configure(:verses, dom_id: &"verse-#{&1.id}") + |> stream(:verses, verses) # DEPRECATED # RENAME? |> assign(:src, source) @@ -209,12 +198,10 @@ defmodule VyasaWeb.Content.ReadingContent do defp sync_session(%Socket{assigns: %{session: %{id: sess_id}}} = socket) when is_binary(sess_id) do Vyasa.PubSub.subscribe("written:session:" <> sess_id) Vyasa.PubSub.publish(:init, :written_handshake, "media:session:" <> sess_id) - IO.inspect(sess_id <> " sync la") socket end defp sync_session(socket) do - IO.inspect(socket, label: "not ready to init sync of session from within ReadingContent") socket end @@ -421,6 +408,7 @@ defmodule VyasaWeb.Content.ReadingContent do ~H"""