-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP commit on some vote capture ideas.
- Loading branch information
Showing
6 changed files
with
143 additions
and
1 deletion.
There are no files selected for viewing
Empty file.
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,17 @@ | ||
defmodule Flick.Votes.Answer do | ||
@moduledoc """ | ||
TBD | ||
""" | ||
|
||
use Ecto.Schema | ||
|
||
import Ecto.Changeset | ||
|
||
embedded_schema do | ||
field :question_id, :binary_id | ||
field :ranked_answer_ids, {:array, :binary_id} | ||
end | ||
|
||
# TODO: When capturing a vote, do we want to validate that all the supplied answer_ids match actual answers for the question in the ballot? | ||
# Maybe we could store a vitual field for the question so we can check it's answers during changeset? reference | ||
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,31 @@ | ||
defmodule Flick.Votes.Vote do | ||
@moduledoc """ | ||
A vote is a collection of ranked answers for a `Flick.Ballots.Ballot` question. | ||
""" | ||
|
||
use Ecto.Schema | ||
|
||
import Ecto.Changeset | ||
|
||
alias Flick.Ballots.Ballot | ||
alias Flick.Votes.Answer | ||
|
||
@type id :: Ecto.UUID.t() | ||
|
||
@typedoc """ | ||
A type for a persisted `Flick.Votes.Vote` entity. | ||
""" | ||
@type t :: %__MODULE__{ | ||
id: Ecto.UUID.t(), | ||
ballot_id: Ballot.id() | ||
} | ||
|
||
@primary_key {:id, :binary_id, autogenerate: true} | ||
schema "votes" do | ||
field :ballot_id, :binary_id | ||
embeds_many :answers, Answer, on_replace: :delete | ||
timestamps(type: :utc_datetime_usec) | ||
end | ||
|
||
# TODO: Should the changelog of a vote require we have an answer for each question? | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
defmodule FlickWeb.Vote.VoteCaptureLive do | ||
@moduledoc """ | ||
A live view that presents a ranked voting form for a published | ||
`Flick.Ballots.Ballot` entity. | ||
""" | ||
|
||
use FlickWeb, :live_view | ||
|
||
alias Flick.Ballots | ||
|
||
@impl Phoenix.LiveView | ||
def mount(params, _session, socket) do | ||
%{"ballot_id" => ballot_id} = params | ||
|
||
ballot = Ballots.get_ballot!(ballot_id) | ||
|
||
socket | ||
|> verify_ballot_is_published(ballot) | ||
|> assign(:page_title, "Vote: #{ballot.title}") | ||
|> assign(:ballot, ballot) | ||
|> ok() | ||
end | ||
|
||
defp verify_ballot_is_published(socket, ballot) do | ||
if ballot.published_at do | ||
socket | ||
else | ||
# TODO: We can make this a better user experience in the future. | ||
throw("can not vote on an unpublished ballot") | ||
end | ||
end | ||
|
||
@impl Phoenix.LiveView | ||
def render(assigns) do | ||
~H""" | ||
<div> | ||
<div>The Question</div> | ||
<div class="grid grid-cols-5"> | ||
<div> | ||
<!-- empty --> | ||
</div> | ||
<div>1st Choice</div> | ||
<div>2nd Choice</div> | ||
<div>3rd Choice</div> | ||
<div>4th Choice</div> | ||
<div>Answer Option A</div> | ||
<div>input</div> | ||
<div>input</div> | ||
<div>input</div> | ||
<div>input</div> | ||
<div>Answer Option B</div> | ||
<div>input</div> | ||
<div>input</div> | ||
<div>input</div> | ||
<div>input</div> | ||
<div>Answer Option C</div> | ||
<div>input</div> | ||
<div>input</div> | ||
<div>input</div> | ||
<div>input</div> | ||
<div>Answer Option D</div> | ||
<div>input</div> | ||
<div>input</div> | ||
<div>input</div> | ||
<div>input</div> | ||
<div>Answer Option E</div> | ||
<div>input</div> | ||
<div>input</div> | ||
<div>input</div> | ||
<div>input</div> | ||
<div>Answer Option F</div> | ||
<div>input</div> | ||
<div>input</div> | ||
<div>input</div> | ||
<div>input</div> | ||
</div> | ||
</div> | ||
""" | ||
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