diff --git a/media-ranker/Gemfile b/media-ranker/Gemfile index 50dc03f45d..937343c0b3 100644 --- a/media-ranker/Gemfile +++ b/media-ranker/Gemfile @@ -7,6 +7,8 @@ gem 'rails', '4.2.5' gem 'sqlite3' # Use SCSS for stylesheets gem 'sass-rails', '~> 5.0' +# Use bootstrap for styling +gem 'bootstrap-sass', '~> 3.3.6' # Use Uglifier as compressor for JavaScript assets gem 'uglifier', '>= 1.3.0' # Use CoffeeScript for .coffee assets and views @@ -39,7 +41,6 @@ group :development, :test do gem 'simplecov' gem 'better_errors' gem 'binding_of_caller' - gem 'rails-erd' end group :development do diff --git a/media-ranker/Gemfile.lock b/media-ranker/Gemfile.lock index c19ec270af..20f5bbde5d 100644 --- a/media-ranker/Gemfile.lock +++ b/media-ranker/Gemfile.lock @@ -37,15 +37,20 @@ GEM thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) arel (6.0.3) + autoprefixer-rails (6.1.2) + execjs + json better_errors (2.1.1) coderay (>= 1.0.0) erubis (>= 2.6.6) rack (>= 0.9.0) binding_of_caller (0.7.2) debug_inspector (>= 0.0.1) + bootstrap-sass (3.3.6) + autoprefixer-rails (>= 5.2.1) + sass (>= 3.3.4) builder (3.2.2) byebug (8.2.1) - choice (0.2.0) coderay (1.1.0) coffee-rails (4.1.0) coffee-script (>= 2.2.0) @@ -100,11 +105,6 @@ GEM activesupport (>= 4.2.0.beta, < 5.0) nokogiri (~> 1.6.0) rails-deprecated_sanitizer (>= 1.0.1) - rails-erd (1.4.4) - activerecord (>= 3.2) - activesupport (>= 3.2) - choice (~> 0.2.0) - ruby-graphviz (~> 1.2) rails-html-sanitizer (1.0.2) loofah (~> 2.0) railties (4.2.5) @@ -131,7 +131,6 @@ GEM rspec-mocks (~> 3.4.0) rspec-support (~> 3.4.0) rspec-support (3.4.1) - ruby-graphviz (1.2.2) sass (3.4.19) sass-rails (5.0.4) railties (>= 4.0.0, < 5.0) @@ -177,12 +176,12 @@ PLATFORMS DEPENDENCIES better_errors binding_of_caller + bootstrap-sass (~> 3.3.6) byebug coffee-rails (~> 4.1.0) jbuilder (~> 2.0) jquery-rails rails (= 4.2.5) - rails-erd rspec-rails sass-rails (~> 5.0) sdoc (~> 0.4.0) diff --git a/media-ranker/app/assets/images/owl.jpg b/media-ranker/app/assets/images/owl.jpg new file mode 100644 index 0000000000..b3ded30950 Binary files /dev/null and b/media-ranker/app/assets/images/owl.jpg differ diff --git a/media-ranker/app/assets/javascripts/albums.coffee b/media-ranker/app/assets/javascripts/albums.coffee new file mode 100644 index 0000000000..24f83d18bb --- /dev/null +++ b/media-ranker/app/assets/javascripts/albums.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/media-ranker/app/assets/javascripts/application.js b/media-ranker/app/assets/javascripts/application.js index e07c5a830f..f91cae5d9b 100644 --- a/media-ranker/app/assets/javascripts/application.js +++ b/media-ranker/app/assets/javascripts/application.js @@ -11,6 +11,7 @@ // about supported directives. // //= require jquery +//= require bootstrap-sprockets //= require jquery_ujs //= require turbolinks //= require_tree . diff --git a/media-ranker/app/assets/javascripts/books.coffee b/media-ranker/app/assets/javascripts/books.coffee new file mode 100644 index 0000000000..24f83d18bb --- /dev/null +++ b/media-ranker/app/assets/javascripts/books.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/media-ranker/app/assets/javascripts/movies.coffee b/media-ranker/app/assets/javascripts/movies.coffee new file mode 100644 index 0000000000..24f83d18bb --- /dev/null +++ b/media-ranker/app/assets/javascripts/movies.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/media-ranker/app/assets/stylesheets/albums.scss b/media-ranker/app/assets/stylesheets/albums.scss new file mode 100644 index 0000000000..0eb33ca0f6 --- /dev/null +++ b/media-ranker/app/assets/stylesheets/albums.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the albums controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/media-ranker/app/assets/stylesheets/application.css b/media-ranker/app/assets/stylesheets/application.scss similarity index 81% rename from media-ranker/app/assets/stylesheets/application.css rename to media-ranker/app/assets/stylesheets/application.scss index f9cd5b3483..8722ed906e 100644 --- a/media-ranker/app/assets/stylesheets/application.css +++ b/media-ranker/app/assets/stylesheets/application.scss @@ -10,6 +10,12 @@ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new * file per style scope. * - *= require_tree . - *= require_self */ + +@import "bootstrap-sprockets"; +@import "bootstrap"; + +.page-header { + background: url(/assets/images/owl.jpg); + background-repeat: no-repeat; +} diff --git a/media-ranker/app/assets/stylesheets/books.scss b/media-ranker/app/assets/stylesheets/books.scss new file mode 100644 index 0000000000..9fab565c8d --- /dev/null +++ b/media-ranker/app/assets/stylesheets/books.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Books controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/media-ranker/app/assets/stylesheets/movies.scss b/media-ranker/app/assets/stylesheets/movies.scss new file mode 100644 index 0000000000..70aaa8a9a4 --- /dev/null +++ b/media-ranker/app/assets/stylesheets/movies.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the movies controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/media-ranker/app/controllers/albums_controller.rb b/media-ranker/app/controllers/albums_controller.rb new file mode 100644 index 0000000000..489ba60e0c --- /dev/null +++ b/media-ranker/app/controllers/albums_controller.rb @@ -0,0 +1,50 @@ +class AlbumsController < ApplicationController + + def index + @albums = Album.order(rank: :desc) + end + + def create + album = Album.create(album_params) + album.update_attribute(:rank, 1) + redirect_to albums_path + end + + def new + @album = Album.new + end + + def edit + @album = Album.find(params[:id]) + end + + def show + @album = Album.find(params[:id]) + end + + def update + album = Album.find(params[:id]) + album.update(album_params) + redirect_to albums_path + end + + def destroy + album = Album.find(params[:id]) + album.destroy + redirect_to albums_path + end + + def upvote + album = Album.find(params[:id]) + rank = album.rank + 1 + album.update_attribute(:rank, rank) + redirect_to(:back) + end + +private + + def album_params + params.require(:album).permit(:title, :artist, :description) + end + +end diff --git a/media-ranker/app/controllers/application_controller.rb b/media-ranker/app/controllers/application_controller.rb index d83690e1b9..66dd171d35 100644 --- a/media-ranker/app/controllers/application_controller.rb +++ b/media-ranker/app/controllers/application_controller.rb @@ -1,5 +1,10 @@ class ApplicationController < ActionController::Base - # Prevent CSRF attacks by raising an exception. - # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception + + def index + @books = Book.order(rank: :desc).limit(3) + @albums = Album.order(rank: :desc).limit(3) + @movies = Movie.order(rank: :desc).limit(3) + end + end diff --git a/media-ranker/app/controllers/books_controller.rb b/media-ranker/app/controllers/books_controller.rb new file mode 100644 index 0000000000..6ea38d40df --- /dev/null +++ b/media-ranker/app/controllers/books_controller.rb @@ -0,0 +1,50 @@ +class BooksController < ApplicationController + + def index + @books = Book.order(rank: :desc) + end + + def create + book = Book.create(book_params) + book.update_attribute(:rank, 1) + redirect_to books_path + end + + def new + @book = Book.new + end + + def edit + @book = Book.find(params[:id]) + end + + def show + @book = Book.find(params[:id]) + end + + def update + book = Book.find(params[:id]) + book.update(book_params) + redirect_to books_path + end + + def destroy + book = Book.find(params[:id]) + book.destroy + redirect_to books_path + end + + def upvote + book = Book.find(params[:id]) + rank = book.rank + 1 + book.update_attribute(:rank, rank) + redirect_to(:back) + end + +private + + def book_params + params.require(:book).permit(:title, :author, :description) + end + +end diff --git a/media-ranker/app/controllers/movies_controller.rb b/media-ranker/app/controllers/movies_controller.rb new file mode 100644 index 0000000000..1286c28175 --- /dev/null +++ b/media-ranker/app/controllers/movies_controller.rb @@ -0,0 +1,50 @@ +class MoviesController < ApplicationController + + def index + @movies = Movie.order(rank: :desc) + end + + def create + movie = Movie.create(movie_params) + movie.update_attribute(:rank, 1) + redirect_to movies_path + end + + def new + @movie = Movie.new + end + + def edit + @movie = Movie.find(params[:id]) + end + + def show + @movie = Movie.find(params[:id]) + end + + def update + movie = Movie.find(params[:id]) + movie.update(movie_params) + redirect_to movies_path + end + + def destroy + movie = Movie.find(params[:id]) + movie.destroy + redirect_to movies_path + end + + def upvote + movie = Movie.find(params[:id]) + rank = movie.rank + 1 + movie.update_attribute(:rank, rank) + redirect_to(:back) + end + + private + + def movie_params + params.require(:movie).permit(:title, :director, :description) + end + +end diff --git a/media-ranker/app/helpers/albums_helper.rb b/media-ranker/app/helpers/albums_helper.rb new file mode 100644 index 0000000000..d976b7cef8 --- /dev/null +++ b/media-ranker/app/helpers/albums_helper.rb @@ -0,0 +1,2 @@ +module AlbumsHelper +end diff --git a/media-ranker/app/helpers/books_helper.rb b/media-ranker/app/helpers/books_helper.rb new file mode 100644 index 0000000000..4b9311e0be --- /dev/null +++ b/media-ranker/app/helpers/books_helper.rb @@ -0,0 +1,2 @@ +module BooksHelper +end diff --git a/media-ranker/app/helpers/movies_helper.rb b/media-ranker/app/helpers/movies_helper.rb new file mode 100644 index 0000000000..493eee555f --- /dev/null +++ b/media-ranker/app/helpers/movies_helper.rb @@ -0,0 +1,2 @@ +module MoviesHelper +end diff --git a/media-ranker/app/models/album.rb b/media-ranker/app/models/album.rb new file mode 100644 index 0000000000..d79d8cd024 --- /dev/null +++ b/media-ranker/app/models/album.rb @@ -0,0 +1,5 @@ +class Album < ActiveRecord::Base + validates :title, presence: true; + validates :artist, presence: true; + validates :description, presence: true; +end diff --git a/media-ranker/app/models/book.rb b/media-ranker/app/models/book.rb new file mode 100644 index 0000000000..7cb9fd498c --- /dev/null +++ b/media-ranker/app/models/book.rb @@ -0,0 +1,5 @@ +class Book < ActiveRecord::Base + validates :title, presence: true; + validates :author, presence: true; + validates :description, presence: true; +end diff --git a/media-ranker/app/models/movie.rb b/media-ranker/app/models/movie.rb new file mode 100644 index 0000000000..ca0f21e666 --- /dev/null +++ b/media-ranker/app/models/movie.rb @@ -0,0 +1,5 @@ +class Movie < ActiveRecord::Base + validates :title, presence: true; + validates :director, presence: true; + validates :description, presence: true; +end diff --git a/media-ranker/app/views/albums/edit.html.erb b/media-ranker/app/views/albums/edit.html.erb new file mode 100644 index 0000000000..5519293f37 --- /dev/null +++ b/media-ranker/app/views/albums/edit.html.erb @@ -0,0 +1,14 @@ +
Ranking | +Name | +Upvote | + + + <% @albums.each do |album| %> +
---|---|---|
Ranked: <%= album.rank%> | +<%= link_to album.title, album_path(album.id) %> | +<%= button_to 'Upvote', upvote_album_path(album.id), class: 'btn btn-default' %> | +
+ <%= @album.description %> +
+ <%= button_to 'Upvote', upvote_album_path(@album.id), class: "btn btn-primary" %> + <%= button_to "Edit #{@album.title}", edit_album_path(@album.id) , :method => :get, class: "btn btn-default" %> + <%= button_to 'Delete', album_path, :method => :delete, class: "btn btn-danger" %> + <%= button_to 'View All albums', albums_path, :method => :get, class: "btn btn-default" %> + <%= button_to 'View All Media', root_path, :method => :get, class: "btn btn-default" %> +Ranking | +Name | +Upvote | + + + <% @books.each do |book| %> +
---|---|---|
Ranked: <%= book.rank%> | +<%= link_to book.title, book_path(book.id) %> | +<%= button_to 'Upvote', upvote_book_path(book.id), class: 'btn btn-default' %> | +
+ <%= @book.description %> +
+ <%= button_to 'Upvote', upvote_book_path(@book.id), class: "btn btn-primary" %> + <%= button_to "Edit #{@book.title}", edit_book_path(@book.id) , :method => :get, class: "btn btn-default" %> + <%= button_to 'Delete', book_path, :method => :delete, class: "btn btn-danger" %> + <%= button_to 'View All books', books_path, :method => :get, class: "btn btn-default" %> + <%= button_to 'View All Media', root_path, :method => :get, class: "btn btn-default" %> +