Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Feb 9, 2021. It is now read-only.

Commit 5cf0ea4

Browse files
committed
Import all styles and changes from Design chapter
1 parent 356f84e commit 5cf0ea4

File tree

6 files changed

+153
-18
lines changed

6 files changed

+153
-18
lines changed

‎assets/css/app.css‎

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,70 @@
11
/* This file is for your main application css. */
22

33
@import "./phoenix.css";
4+
5+
/* Header */
6+
7+
header {
8+
border-bottom: none;
9+
margin-bottom: 0;
10+
}
11+
12+
.logo {
13+
font-weight: bold;
14+
}
15+
16+
.nav-text {
17+
display: inline-flex;
18+
margin-right: 5px;
19+
}
20+
21+
/* Featured */
22+
23+
.featured {
24+
height: 360px;
25+
background-color: black;
26+
color: white;
27+
}
28+
29+
.featured-img {
30+
margin-top: 50px;
31+
margin-right: 50px;
32+
float: left;
33+
}
34+
35+
.featured-thumbnail {
36+
height: 260px;
37+
}
38+
39+
.featured-data {
40+
margin-top: 50px;
41+
overflow: hidden;
42+
}
43+
44+
/* Games */
45+
46+
.games-index {
47+
margin-top: 2rem;
48+
}
49+
50+
.game-item {
51+
display: flex;
52+
}
53+
54+
.game-info {
55+
margin-left: 2em;
56+
}
57+
58+
/* Players */
59+
60+
.player-item {
61+
display: flex;
62+
}
63+
64+
.player-score {
65+
margin-bottom: 0;
66+
}
67+
68+
.player-name {
69+
margin-left: 1em;
70+
}

‎assets/elm/src/Main.elm‎

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,45 @@ subscriptions model =
168168
view : Model -> Html Msg
169169
view model =
170170
div []
171-
[ gamesIndex model
171+
[ featured model
172+
, gamesIndex model
172173
, playersIndex model
173174
]
174175

175176

176177

178+
-- FEATURED
179+
180+
181+
featured : Model -> Html msg
182+
featured model =
183+
case featuredGame model.gamesList of
184+
Just game ->
185+
div [ class "row featured" ]
186+
[ div [ class "container" ]
187+
[ div [ class "featured-img" ]
188+
[ img [ class "featured-thumbnail", src game.thumbnail ] [] ]
189+
, div [ class "featured-data" ]
190+
[ h2 [] [ text "Featured" ]
191+
, h3 [] [ text game.title ]
192+
, p [] [ text game.description ]
193+
, button [ class "button" ] [ text "Play Now!" ]
194+
]
195+
]
196+
]
197+
198+
Nothing ->
199+
div [] []
200+
201+
202+
featuredGame : List Game -> Maybe Game
203+
featuredGame games =
204+
games
205+
|> List.filter .featured
206+
|> List.head
207+
208+
209+
177210
-- GAMES
178211

179212

@@ -183,7 +216,7 @@ gamesIndex model =
183216
div [] []
184217

185218
else
186-
div [ class "games-index" ]
219+
div [ class "games-index container" ]
187220
[ h2 [] [ text "Games" ]
188221
, gamesList model.gamesList
189222
]
@@ -196,9 +229,16 @@ gamesList games =
196229

197230
gamesListItem : Game -> Html msg
198231
gamesListItem game =
199-
li [ class "game-item" ]
200-
[ strong [] [ text game.title ]
201-
, p [] [ text game.description ]
232+
a [ href "#" ]
233+
[ li [ class "game-item" ]
234+
[ div [ class "game-image" ]
235+
[ img [ src game.thumbnail ] []
236+
]
237+
, div [ class "game-info" ]
238+
[ h3 [] [ text game.title ]
239+
, p [] [ text game.description ]
240+
]
241+
]
202242
]
203243

204244

@@ -212,7 +252,7 @@ playersIndex model =
212252
div [] []
213253

214254
else
215-
div [ class "players-index" ]
255+
div [ class "players-index container" ]
216256
[ h2 [] [ text "Players" ]
217257
, model.playersList
218258
|> playersSortedByScore
@@ -234,12 +274,17 @@ playersList players =
234274

235275
playersListItem : Player -> Html msg
236276
playersListItem player =
277+
let
278+
playerLink name =
279+
a [ href ("players/" ++ String.fromInt player.id) ]
280+
[ strong [ class "player-name" ] [ text name ] ]
281+
in
237282
li [ class "player-item" ]
238-
[ case player.displayName of
283+
[ p [ class "player-score" ] [ text (String.fromInt player.score) ]
284+
, case player.displayName of
239285
Just displayName ->
240-
strong [][ text displayName]
286+
playerLink displayName
241287

242288
Nothing ->
243-
strong [] [ text player.username ]
244-
, p [] [ text (String.fromInt player.score) ]
289+
playerLink player.username
245290
]

‎lib/platform_web/controllers/player_controller.ex‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ defmodule PlatformWeb.PlayerController do
44
alias Platform.Accounts
55
alias Platform.Accounts.Player
66

7+
plug(:authorize when action in [:edit])
8+
79
def index(conn, _params) do
810
players = Accounts.list_players()
911
render(conn, "index.html", players: players)
@@ -60,4 +62,25 @@ defmodule PlatformWeb.PlayerController do
6062
|> put_flash(:info, "Player deleted successfully.")
6163
|> redirect(to: Routes.player_path(conn, :index))
6264
end
65+
66+
defp authorize(conn, _opts) do
67+
if Mix.env == :test do
68+
conn
69+
else
70+
current_player_id = conn.assigns.current_user().id
71+
72+
requested_player_id =
73+
conn.path_params["id"]
74+
|> String.to_integer()
75+
76+
if current_player_id == requested_player_id do
77+
conn
78+
else
79+
conn
80+
|> put_flash(:error, "Your account is not authorized to access that page.")
81+
|> redirect(to: Routes.page_path(conn, :index))
82+
|> halt()
83+
end
84+
end
85+
end
6386
end

‎lib/platform_web/templates/layout/app.html.eex‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,21 @@
1313
<nav role="navigation">
1414
<ul>
1515
<%= if @current_user do %>
16-
<p>Signed in as <strong><%= @current_user.username %></strong></p>
16+
<p class="nav-text">
17+
Signed in as&nbsp;
18+
<strong><%= link @current_user.username, to: Routes.player_path(@conn, :edit, @current_user) %></strong>
19+
</p>
1720
<%= link "Sign Out", to: Routes.player_session_path(@conn, :delete, @current_user), method: "delete", class: "button" %>
1821
<% else %>
1922
<%= link "Sign Up", to: Routes.player_path(@conn, :new), class: "button" %>
2023
<%= link "Sign In", to: Routes.player_session_path(@conn, :new), class: "button" %>
2124
<% end %>
2225
</ul>
2326
</nav>
24-
<a href="http://phoenixframework.org/" class="phx-logo">
25-
<img src="<%= Routes.static_path(@conn, "/images/phoenix.png") %>" alt="Phoenix Framework Logo"/>
26-
</a>
27+
<h1><%= link "Platform", to: Routes.page_path(@conn, :index), class: "logo" %></h1>
2728
</section>
2829
</header>
29-
<main role="main"class="container">
30+
<main role="main">
3031
<p class="alert alert-info" role="alert"><%= get_flash(@conn, :info) %></p>
3132
<p class="alert alert-danger" role="alert"><%= get_flash(@conn, :error) %></p>
3233
<%= render @view_module, @view_template, assigns %>

‎lib/platform_web/templates/player/edit.html.eex‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121

2222
<div>
2323
<%= submit "Save" %>
24+
<%= link "Delete Account", to: Routes.player_path(@conn, :delete, @player), method: :delete, data: [confirm: "Are you sure?"], class: "button" %>
25+
<%= link "Back", to: Routes.player_path(@conn, :index), class: "button" %>
2426
</div>
2527
<% end %>
2628

27-
<span><%= link "Back", to: Routes.player_path(@conn, :index) %></span>

‎lib/platform_web/templates/player/index.html.eex‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717

1818
<td>
1919
<%= link "Show", to: Routes.player_path(@conn, :show, player) %>
20-
<%= link "Edit", to: Routes.player_path(@conn, :edit, player) %>
21-
<%= link "Delete", to: Routes.player_path(@conn, :delete, player), method: :delete, data: [confirm: "Are you sure?"] %>
2220
</td>
2321
</tr>
2422
<% end %>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /