Skip to content

Commit

Permalink
Watch video - work in progress p160
Browse files Browse the repository at this point in the history
  • Loading branch information
dharnitski committed Sep 18, 2016
1 parent 36b5bf6 commit 92e8340
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 17 deletions.
18 changes: 18 additions & 0 deletions test/controllers/user_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,22 @@ defmodule Rumbl.UserControllerTest do
#assert String.contains?(conn.resp_body, user.name)
#assert String.contains?(conn.resp_body, other_user.name)
end

@tag login_as: "max"
test "shows chosen resource", %{user: owner, conn: conn} do
conn = get conn, user_path(conn, :show, owner)
assert html_response(conn, 200) =~ "Showing User"
end

test "renders form for new resources", %{conn: conn} do
conn = get conn, user_path(conn, :new)
assert html_response(conn, 200) =~ "New User"
end

test "creates resource and redirects when data is valid", %{conn: conn} do
conn = post conn, user_path(conn, :create), user: @valid_attrs
assert redirected_to(conn) == user_path(conn, :index)
#assert Repo.get_by(User, @valid_attrs)
end

end
14 changes: 14 additions & 0 deletions test/controllers/watch_controller_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
defmodule Rumbl.WatchControllerTest do
use Rumbl.ConnCase
alias Rumbl.Video

@valid_attrs %{url: "http://youtu.be", title: "vid", description: "a vid"}

test "shows chosen resource", %{conn: conn} do
user = insert_user(username: "username")
video = insert_video(user, @valid_attrs)
conn = get conn, watch_path(conn, :show, video)
assert html_response(conn, 200) =~ "Annotations"
end

end
9 changes: 9 additions & 0 deletions web/controllers/watch_controller.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
defmodule Rumbl.WatchController do
use Rumbl.Web, :controller
alias Rumbl.Video

def show(conn, %{"id" => id}) do
video = Repo.get!(Video, id)
render conn, "show.html", video: video
end
end
1 change: 1 addition & 0 deletions web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ defmodule Rumbl.Router do

resources "/users", UserController, only: [:index, :show, :new, :create]
resources "/sessions", SessionController, only: [:new, :create, :delete]
get "/watch/:id", WatchController, :show
get "/", PageController, :index
end

Expand Down
29 changes: 15 additions & 14 deletions web/templates/layout/app.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,21 @@
<body>
<div class="container">
<div class="header">
<ol class="breadcrumb text-right">
<%= if @current_user do %>
<li><%= @current_user.username %></li>
<li>
<%= link "Log out", to: session_path(@conn, :delete, @current_user),
method: "delete" %>
</li>
<% else %>
<li><%= link "Register", to: user_path(@conn, :new) %></li>
<li><%= link "Log in", to: session_path(@conn, :new) %></li>
<% end %>
</ol>
<span class="logo"></span>
</div>
<ol class="breadcrumb text-right">
<%= if @current_user do %>
<li><%= @current_user.username %></li>
<li><%= link "My Videos", to: video_path(@conn, :index) %></li>
<li>
<%= link "Log out", to: session_path(@conn, :delete, @current_user),
method: "delete" %>
</li>
<% else %>
<li><%= link "Register", to: user_path(@conn, :new) %></li>
<li><%= link "Log in", to: session_path(@conn, :new) %></li>
<% end %>
</ol>
<span class="logo"></span>
</div>

<p class="alert alert-info" role="alert"><%= get_flash(@conn, :info) %></p>
<p class="alert alert-danger" role="alert"><%= get_flash(@conn, :error) %></p>
Expand Down
10 changes: 7 additions & 3 deletions web/templates/video/index.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@
<td><%= video.description %></td>

<td class="text-right">
<%= link "Show", to: video_path(@conn, :show, video), class: "btn btn-default btn-xs" %>
<%= link "Edit", to: video_path(@conn, :edit, video), class: "btn btn-default btn-xs" %>
<%= link "Delete", to: video_path(@conn, :delete, video), method: :delete, data: [confirm: "Are you sure?"], class: "btn btn-danger btn-xs" %>
<%= link "Watch", to: watch_path(@conn, :show, video),
class: "btn btn-default btn-xs" %>
<%= link "Edit", to: video_path(@conn, :edit, video),
class: "btn btn-default btn-xs" %>
<%= link "Delete", to: video_path(@conn, :delete, video),
method: :delete, data: [confirm: "Are you sure?"],
class: "btn btn-danger btn-xs" %>
</td>
</tr>
<% end %>
Expand Down
22 changes: 22 additions & 0 deletions web/templates/watch/show.html.eex
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<h2><%= @video.title %></h2>
<div class="row">
<div class="col-sm-7">
<%= content_tag :div, id: "video", data: [id: @video.id, player_id: player_id(@video)] do %>
<% end %>
</div>
<div class="col-sm-5">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Annotations</h3>
</div>
<div id="msg-container" class="panel-body annotations">
</div>
<div class="panel-footer">
<textarea id="msg-input" rows="3" class="form-control"
placeholder="Comment..."></textarea>
<button id="msg-submit" class="btn btn-primary form-control"
type="submit">Post</button>
</div>
</div>
</div>
</div>
9 changes: 9 additions & 0 deletions web/views/watch_view.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
defmodule Rumbl.WatchView do
use Rumbl.Web, :view

def player_id(video) do
~r/^.*(?:youtu.be\/|v\/|e\/|u\/\w+\/|embed\/|v=)(?<id>[^#\&\?]*).*/
|> Regex.named_captures(video.url)
|> get_in(["id"])
end
end

0 comments on commit 92e8340

Please sign in to comment.