Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mod2 #113

Open
wants to merge 37 commits into
base: master
Choose a base branch
from
Open

Mod2 #113

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
663c04f
video and categories
QsBBQ May 19, 2014
c1b9057
categoryid in video
QsBBQ May 19, 2014
7b4e04c
updated index
QsBBQ May 19, 2014
bb86fb5
updated index
QsBBQ May 19, 2014
e3a2416
fixed end
QsBBQ May 20, 2014
7156438
added categories to videos
QsBBQ May 20, 2014
6fc5dac
stuff spitting out
QsBBQ May 20, 2014
4f2067f
iterating
QsBBQ May 20, 2014
a3feeb5
working
QsBBQ May 21, 2014
2cf7d7c
working
QsBBQ May 21, 2014
0ecfe43
test
QsBBQ May 21, 2014
66a0dfc
tested video model for save
QsBBQ May 24, 2014
9d75022
tested validations
QsBBQ May 24, 2014
40ee716
upated with shoulda matchers
QsBBQ May 24, 2014
f611bf7
added search
QsBBQ May 25, 2014
e7bd746
added search
QsBBQ May 25, 2014
ca615b3
recent videos
QsBBQ May 25, 2014
fe6bcbc
last update
QsBBQ May 25, 2014
099d6ff
register not working
QsBBQ May 28, 2014
4f4cfca
broken
QsBBQ May 28, 2014
c1438ca
added require for strong params
QsBBQ May 28, 2014
567019f
still not working
QsBBQ May 28, 2014
d6bfb4f
fixed routes
QsBBQ May 28, 2014
92afa52
updated
QsBBQ May 28, 2014
4b3fc9b
working
QsBBQ May 28, 2014
cd2f61d
search
QsBBQ May 28, 2014
2f26e0b
search aligned
QsBBQ May 28, 2014
a6ca94b
search aligned
QsBBQ May 28, 2014
9b9369c
search with git
QsBBQ May 28, 2014
0179ee1
video controller test
QsBBQ Jun 2, 2014
ed99c37
getting fault
QsBBQ Jun 4, 2014
50c5881
getting fault
QsBBQ Jun 4, 2014
8cc44e8
all passed
QsBBQ Jun 4, 2014
d3445a8
couple more
QsBBQ Jun 10, 2014
fc9e66f
working
QsBBQ Jun 10, 2014
4a5c32c
working now
QsBBQ Jun 10, 2014
640484a
finish week2
QsBBQ Jun 10, 2014
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--color
14 changes: 14 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ gem 'haml-rails'
gem 'sass-rails'
gem 'uglifier'
gem 'jquery-rails'
gem 'bootstrap_form'
gem 'bcrypt-ruby'
gem 'fabrication'
gem 'faker'

group :development do
gem 'sqlite3'
Expand All @@ -16,6 +20,16 @@ group :development do
gem 'thin'
gem "better_errors"
gem "binding_of_caller"

end

group :test, :development do
gem 'rspec-rails'
end

group :test do
gem 'shoulda-matchers'

end

group :production do
Expand Down
28 changes: 28 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@ GEM
tzinfo (~> 0.3.37)
arel (4.0.1)
atomic (1.1.14)
bcrypt (3.1.7)
bcrypt-ruby (3.1.5)
bcrypt (>= 3.1.3)
better_errors (1.0.1)
coderay (>= 1.0.0)
erubis (>= 2.6.6)
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
bootstrap-sass (3.0.2.1)
sass (~> 3.2)
bootstrap_form (2.1.1)
builder (3.1.4)
coderay (1.1.0)
coffee-rails (4.0.1)
Expand All @@ -45,9 +49,13 @@ GEM
coffee-script-source (1.6.3)
daemons (1.1.9)
debug_inspector (0.0.2)
diff-lcs (1.2.5)
erubis (2.7.0)
eventmachine (1.0.0)
execjs (2.0.2)
fabrication (2.11.2)
faker (1.3.0)
i18n (~> 0.5)
haml (4.0.4)
tilt
haml-rails (0.4)
Expand Down Expand Up @@ -98,11 +106,25 @@ GEM
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (10.1.0)
rspec-core (2.14.8)
rspec-expectations (2.14.5)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.14.6)
rspec-rails (2.14.2)
actionpack (>= 3.0)
activemodel (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec-core (~> 2.14.0)
rspec-expectations (~> 2.14.0)
rspec-mocks (~> 2.14.0)
sass (3.2.12)
sass-rails (4.0.1)
railties (>= 4.0.0, < 5.0)
sass (>= 3.1.10)
sprockets-rails (~> 2.0.0)
shoulda-matchers (2.6.1)
activesupport (>= 3.0.0)
slop (3.4.7)
sprockets (2.10.0)
hike (~> 1.2)
Expand Down Expand Up @@ -134,18 +156,24 @@ PLATFORMS
ruby

DEPENDENCIES
bcrypt-ruby
better_errors
binding_of_caller
bootstrap-sass
bootstrap_form
coffee-rails
fabrication
faker
haml-rails
jquery-rails
pg
pry
pry-nav
rails
rails_12factor
rspec-rails
sass-rails
shoulda-matchers
sqlite3
thin
uglifier
10 changes: 10 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
class ApplicationController < ActionController::Base
protect_from_forgery

def require_user
redirect_to sign_in_path unless current_user
end

def current_user
User.find(session[:user_id]) if session[:user_id]
end

helper_method :current_user
end
10 changes: 10 additions & 0 deletions app/controllers/categories_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class CategoriesController < ApplicationController

def index
@categories = Category.all
end

def show
@category = Category.find(params[:id])
end
end
5 changes: 5 additions & 0 deletions app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class PagesController < ApplicationController
def front
redirect_to home_path if current_user
end
end
34 changes: 34 additions & 0 deletions app/controllers/queue_items_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
class QueueItemsController < ApplicationController
before_filter :require_user

def index
@queue_items = current_user.queue_items
end

def create
video = Video.find(params[:video_id])
queue_video(video)
redirect_to my_queue_path
end

def destroy
queue_item = QueueItem.find(params[:id])
queue_item.destroy if current_user.queue_items.include?(queue_item)
redirect_to my_queue_path
end

private

def queue_video(video)
QueueItem.create(video: video, user: current_user, position: new_queue_item_position) unless current_user_queued_vide?(video)
end

def new_queue_item_position
current_user.queue_items.count + 1
end

def current_user_queued_vide?(video)
current_user.queue_items.map(&:video).include?(video)
end

end
20 changes: 20 additions & 0 deletions app/controllers/reviews_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class ReviewsController < ApplicationController
before_filter :require_user

def create
@video = Video.find(params[:video_id])
review = @video.reviews.build(review_params.merge!(user: current_user))
if review.save
redirect_to @video
else
@reviews = @video.reviews.reload
render 'videos/show'
end
end

private

def review_params
params.require(:review).permit(:rating, :content)
end
end
23 changes: 23 additions & 0 deletions app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class SessionsController < ApplicationController
def new
redirect_to home_path if current_user
end

def create
user = User.where(email: params[:email]).first
if user && user.authenticate(params[:password])
session[:user_id] = user.id
flash[:success] = 'You are signed in, enjoy'
redirect_to home_path
else
flash[:danger] = "Invalid email or password."
redirect_to sign_in_path
end
end

def destroy
session[:user_id] = nil
flash[:danger] = "You are signed out."
redirect_to root_path
end
end
20 changes: 20 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class UsersController < ApplicationController
def new
@user = User.new
end

def create
@user = User.new(user_params)
if @user.save
redirect_to sign_in_path
else
render :new
end
end

private

def user_params
params.require(:user).permit(:full_name, :email, :password)
end
end
17 changes: 17 additions & 0 deletions app/controllers/videos_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class VideosController < ApplicationController
before_filter :require_user

def index
@videos = Video.all
@categories = Category.all
end

def show
@video = Video.find(params[:id])
@reviews = @video.reviews
end

def search
@results = Video.search_by_title(params[:search_term])
end
end
8 changes: 8 additions & 0 deletions app/models/category.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Category < ActiveRecord::Base
has_many :videos, order: "created_at DESC"
validates_presence_of :name

def recent_videos
videos.first(6)
end
end
16 changes: 16 additions & 0 deletions app/models/queue_item.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class QueueItem < ActiveRecord::Base
belongs_to :user
belongs_to :video

delegate :category, to: :video
delegate :title, to: :video, prefix: :video

def rating
review = Review.where(user_id: user_id, video_id: video.id).first
review.rating if review
end

def category_name
category.name
end
end
6 changes: 6 additions & 0 deletions app/models/review.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Review < ActiveRecord::Base
belongs_to :video
belongs_to :user

validates_presence_of :content, :rating
end
8 changes: 8 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class User < ActiveRecord::Base
validates_presence_of :email, :password, :full_name
validates_uniqueness_of :email

has_secure_password validations: false

has_many :queue_items
end
13 changes: 13 additions & 0 deletions app/models/video.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Video < ActiveRecord::Base
belongs_to :category
has_many :reviews, order: "created_at DESC"
#has_many :reviews, -> { order: ("created_at DESC") }
#validates :title, presence: true
#validates :description, presence: true
validates_presence_of :title, :description

def self.search_by_title(search_term)
return [] if search_term.blank?
where("title LIKE ?", "%#{search_term}%").order("created_at DESC")
end
end
14 changes: 14 additions & 0 deletions app/views/categories/show.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
%section.genre
%header.clearfix
%h1= @category.name
.genre_sorting
Sort by:
%select(name="")
%option(value="a-z") Title: A - Z
%option(value="z-a") Title: Z - A
%option(value="rating") Rating
%article.row
- @category.videos.each do |video|
.video.col-md-2
= link_to video_path(video) do
%img(src="#{video.small_cover_url}")
8 changes: 8 additions & 0 deletions app/views/pages/front.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
%section.site_title
%h1
Unlimited Movies for Only 9.99 a Month.
= link_to "Sign Up Now!", register_path
%p.sign_up
%p.sign_in
Have an account? Please
= link_to "Sign In", sign_in_path
38 changes: 38 additions & 0 deletions app/views/queue_items/index.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
%section.my_queue.container
.row
.col-sm-10.col-sm-offset-1
%article
%header
%h2 My Queue
%table.table
%thead
%tr
%th(width="10%") List Order
%th(width="30%") Video Title
%th(width="10%") Play
%th(width="20%") Rating
%th(width="15%") Genre
%th(width="15%") Remove
%tbody
- @queue_items.each do |queue_item|
%tr
%td= queue_item.position

%td
= link_to queue_item.video_title, queue_item.video
%td
= button_to "Play", nil, class: "btn btn-default"
%td
%select.form-group(name="")
%option(value="5") 5 Stars
%option(value="4") 4 Stars
%option(value="3") 3 Stars
%option(value="2") 2 Stars
%option(value="1") 1 Star
%td
= link_to queue_item.category_name, queue_item.category
%td
= link_to queue_item, method: :delete do
%i.glyphicon.glyphicon-remove

= button_to "Update Instant Queue", nil, class: "btn btn-default"
Loading