Skip to content

Commit efae47b

Browse files
add points to card
1 parent 02e56f9 commit efae47b

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

lib/pointing_party/card.ex

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,22 @@ defmodule PointingParty.Card do
55
alias PointingParty.Repo
66
alias PointingParty.Card
77

8+
def points_range, do: [0, 1, 3, 5]
9+
810
schema "cards" do
911
field :description, :string
1012
field :title, :string
13+
field :points, :integer
1114

1215
timestamps()
1316
end
1417

1518
@doc false
1619
def changeset(card, attrs) do
1720
card
18-
|> cast(attrs, [:title, :description])
21+
|> cast(attrs, [:title, :description, :points])
1922
|> validate_required([:title, :description])
23+
|> validate_inclusion(:points, Card.points_range)
2024
end
2125

2226
def get!(id) do

lib/pointing_party_web/controllers/card_controller.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ defmodule PointingPartyWeb.CardController do
55
def index(conn, _params) do
66
# temporary, just to get something on the page for now
77
card = Card.first()
8-
render(conn, "index.html", card: card)
8+
points = Card.points_range()
9+
render(conn, "index.html", card: card, points: points)
910
end
1011
end

lib/pointing_party_web/templates/card/index.html.eex

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@
1010
<div class="col-2">
1111
<label for="storyPoints">Story Points</label>
1212
<select class="form-control" id="storyPoints">
13-
<option>0</option>
14-
<option>1</option>
15-
<option>3</option>
16-
<option>5</option>
13+
<%= Enum.map(@points, fn point -> %>
14+
<%= if @card.points == point do %>
15+
<option selected="selected'"><%= point %></option>
16+
<% else %>
17+
<option><%= point %></option>
18+
<% end %>
19+
<% end) %>
1720
</select>
1821
</div>
1922
</div>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
defmodule PointingParty.Repo.Migrations.AddPointsToCards do
2+
use Ecto.Migration
3+
4+
def change do
5+
alter table("cards") do
6+
add :points, :integer, default: 0
7+
end
8+
end
9+
end

0 commit comments

Comments
 (0)