Skip to content

Commit f8daaee

Browse files
Merge pull request #4 from elixirschool/card-display
card display
2 parents da3d5a0 + b874af9 commit f8daaee

File tree

5 files changed

+47
-3
lines changed

5 files changed

+47
-3
lines changed

lib/pointing_party/card.ex

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

8+
89
schema "cards" do
910
field :description, :string
1011
field :title, :string
12+
field :points, :integer
1113

1214
timestamps()
1315
end
1416

17+
def points_range, do: [0, 1, 3, 5]
18+
1519
@doc false
1620
def changeset(card, attrs) do
1721
card
18-
|> cast(attrs, [:title, :description])
22+
|> cast(attrs, [:title, :description, :points])
1923
|> validate_required([:title, :description])
24+
|> validate_inclusion(:points, Card.points_range())
2025
end
2126

2227
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
Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,29 @@
1-
<%= @card.title %>
1+
2+
<div class="card text-left">
3+
<div class="card-header">
4+
<h2><%= @card.title %></h2>
5+
</div>
6+
<div class="card-body">
7+
<p class="card-text"><%= @card.description %></p>
8+
<div class="form-group text-left">
9+
<div class="form-row align-items-center">
10+
<div class="col-2">
11+
<label for="storyPoints">Story Points</label>
12+
<select class="form-control" id="storyPoints">
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) %>
20+
</select>
21+
</div>
22+
</div>
23+
</div>
24+
<a href="#" class="btn btn-primary">Calculate Points</a>
25+
</div>
26+
<div class="card-footer text-muted">
27+
created at: <%= @card.inserted_at %>
28+
</div>
29+
</div>

lib/pointing_party_web/templates/layout/app.html.eex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
66
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
77
<title>PointingParty</title>
8+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
89
<link rel="stylesheet" href="<%= Routes.static_path(@conn, "/css/app.css") %>"/>
910
</head>
1011
<body>
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)