List of Works
+ <%['movie', 'book', 'album'].each do |category| %> +<%=category.capitalize%>s
+Votes | +Title | +Created By | +Published | +Upvote | +
---|---|---|---|---|
<%=work.votes.count%> | +<%=work.title%> | +<%=work.creator%> | +<%=work.publication_year%> | +Upvote | +
diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000..94a5613080 Binary files /dev/null and b/.DS_Store differ diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..18b43c9cd2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,27 @@ +# See https://help.github.com/articles/ignoring-files for more about ignoring files. +# +# If you find yourself ignoring temporary files generated by your text editor +# or operating system, you probably want to add a global ignore instead: +# git config --global core.excludesfile '~/.gitignore_global' + +# Ignore bundler config. +/.bundle + +# Ignore all logfiles and tempfiles. +/log/* +/tmp/* +!/log/.keep +!/tmp/.keep + +# Ignore uploaded files in development +/storage/* +!/storage/.keep + +/node_modules +/yarn-error.log + +/public/assets +.byebug_history + +# Ignore master key for decrypting credentials and more. +/config/master.key diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000000..e54d447e8f --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +ruby-2.4.1 \ No newline at end of file diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000000..8406aeb8bb --- /dev/null +++ b/Gemfile @@ -0,0 +1,81 @@ +source 'https://rubygems.org' +git_source(:github) { |repo| "https://github.com/#{repo}.git" } + +ruby '2.4.1' + +# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' +gem 'rails', '~> 5.2.1' +# Use postgresql as the database for Active Record +gem 'pg', '>= 0.18', '< 2.0' +# Use Puma as the app server +gem 'puma', '~> 3.11' +# Use SCSS for stylesheets +gem 'sass-rails', '~> 5.0' +# Use Uglifier as compressor for JavaScript assets +gem 'uglifier', '>= 1.3.0' +# See https://github.com/rails/execjs#readme for more supported runtimes +# gem 'mini_racer', platforms: :ruby + +# Use CoffeeScript for .coffee assets and views +# gem 'coffee-rails', '~> 4.2' +# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks +gem 'turbolinks', '~> 5' +# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder +gem 'jbuilder', '~> 2.5' +# Use Redis adapter to run Action Cable in production +# gem 'redis', '~> 4.0' +# Use ActiveModel has_secure_password +# gem 'bcrypt', '~> 3.1.7' + +# Use ActiveStorage variant +# gem 'mini_magick', '~> 4.8' + +# Use Capistrano for deployment +# gem 'capistrano-rails', group: :development + +# Reduces boot times through caching; required in config/boot.rb +gem 'bootsnap', '>= 1.1.0', require: false + +group :development, :test do + # Call 'byebug' anywhere in the code to stop execution and get a debugger console + gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] +end + +group :development do + # Access an interactive console on exception pages or by calling 'console' anywhere in the code. + gem 'web-console', '>= 3.3.0' + gem 'listen', '>= 3.0.5', '< 3.2' + # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring + gem 'spring' + gem 'spring-watcher-listen', '~> 2.0.0' +end + +group :test do + # Adds support for Capybara system testing and selenium driver + gem 'capybara', '>= 2.15' + gem 'selenium-webdriver' + # Easy installation and use of chromedriver to run system tests with Chrome + gem 'chromedriver-helper' +end + +# Windows does not include zoneinfo files, so bundle the tzinfo-data gem +gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] + +gem 'jquery-rails' +gem 'jquery-turbolinks' +gem 'bootstrap', '~> 4.1.3' +group :development, :test do + gem 'pry-rails' +end + +group :development do + gem 'better_errors' + gem 'binding_of_caller' + gem 'guard' + gem 'guard-minitest' +end + +group :test do + gem 'minitest-rails' + gem 'minitest-reporters' +end diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000000..e8933351d9 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,277 @@ +GEM + remote: https://rubygems.org/ + specs: + actioncable (5.2.1) + actionpack (= 5.2.1) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + actionmailer (5.2.1) + actionpack (= 5.2.1) + actionview (= 5.2.1) + activejob (= 5.2.1) + mail (~> 2.5, >= 2.5.4) + rails-dom-testing (~> 2.0) + actionpack (5.2.1) + actionview (= 5.2.1) + activesupport (= 5.2.1) + rack (~> 2.0) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + actionview (5.2.1) + activesupport (= 5.2.1) + builder (~> 3.1) + erubi (~> 1.4) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.3) + activejob (5.2.1) + activesupport (= 5.2.1) + globalid (>= 0.3.6) + activemodel (5.2.1) + activesupport (= 5.2.1) + activerecord (5.2.1) + activemodel (= 5.2.1) + activesupport (= 5.2.1) + arel (>= 9.0) + activestorage (5.2.1) + actionpack (= 5.2.1) + activerecord (= 5.2.1) + marcel (~> 0.3.1) + activesupport (5.2.1) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 0.7, < 2) + minitest (~> 5.1) + tzinfo (~> 1.1) + addressable (2.5.2) + public_suffix (>= 2.0.2, < 4.0) + ansi (1.5.0) + archive-zip (0.11.0) + io-like (~> 0.3.0) + arel (9.0.0) + autoprefixer-rails (9.1.4) + execjs + better_errors (2.5.0) + coderay (>= 1.0.0) + erubi (>= 1.0.0) + rack (>= 0.9.0) + bindex (0.5.0) + binding_of_caller (0.8.0) + debug_inspector (>= 0.0.1) + bootsnap (1.3.2) + msgpack (~> 1.0) + bootstrap (4.1.3) + autoprefixer-rails (>= 6.0.3) + popper_js (>= 1.12.9, < 2) + sass (>= 3.5.2) + builder (3.2.3) + byebug (10.0.2) + capybara (3.9.0) + addressable + mini_mime (>= 0.1.3) + nokogiri (~> 1.8) + rack (>= 1.6.0) + rack-test (>= 0.6.3) + xpath (~> 3.1) + childprocess (0.9.0) + ffi (~> 1.0, >= 1.0.11) + chromedriver-helper (2.1.0) + archive-zip (~> 0.10) + nokogiri (~> 1.8) + coderay (1.1.2) + concurrent-ruby (1.0.5) + crass (1.0.4) + debug_inspector (0.0.3) + erubi (1.7.1) + execjs (2.7.0) + ffi (1.9.25) + formatador (0.2.5) + globalid (0.4.1) + activesupport (>= 4.2.0) + guard (2.14.2) + formatador (>= 0.2.4) + listen (>= 2.7, < 4.0) + lumberjack (>= 1.0.12, < 2.0) + nenv (~> 0.1) + notiffany (~> 0.0) + pry (>= 0.9.12) + shellany (~> 0.0) + thor (>= 0.18.1) + guard-compat (1.2.1) + guard-minitest (2.4.6) + guard-compat (~> 1.2) + minitest (>= 3.0) + i18n (1.1.0) + concurrent-ruby (~> 1.0) + io-like (0.3.0) + jbuilder (2.7.0) + activesupport (>= 4.2.0) + multi_json (>= 1.2) + jquery-rails (4.3.3) + rails-dom-testing (>= 1, < 3) + railties (>= 4.2.0) + thor (>= 0.14, < 2.0) + jquery-turbolinks (2.1.0) + railties (>= 3.1.0) + turbolinks + listen (3.1.5) + rb-fsevent (~> 0.9, >= 0.9.4) + rb-inotify (~> 0.9, >= 0.9.7) + ruby_dep (~> 1.2) + loofah (2.2.2) + crass (~> 1.0.2) + nokogiri (>= 1.5.9) + lumberjack (1.0.13) + mail (2.7.0) + mini_mime (>= 0.1.1) + marcel (0.3.3) + mimemagic (~> 0.3.2) + method_source (0.9.0) + mimemagic (0.3.2) + mini_mime (1.0.1) + mini_portile2 (2.3.0) + minitest (5.11.3) + minitest-rails (3.0.0) + minitest (~> 5.8) + railties (~> 5.0) + minitest-reporters (1.3.5) + ansi + builder + minitest (>= 5.0) + ruby-progressbar + msgpack (1.2.4) + multi_json (1.13.1) + nenv (0.3.0) + nio4r (2.3.1) + nokogiri (1.8.5) + mini_portile2 (~> 2.3.0) + notiffany (0.1.1) + nenv (~> 0.1) + shellany (~> 0.0) + pg (1.1.3) + popper_js (1.14.3) + pry (0.11.3) + coderay (~> 1.1.0) + method_source (~> 0.9.0) + pry-rails (0.3.6) + pry (>= 0.10.4) + public_suffix (3.0.3) + puma (3.12.0) + rack (2.0.5) + rack-test (1.1.0) + rack (>= 1.0, < 3) + rails (5.2.1) + actioncable (= 5.2.1) + actionmailer (= 5.2.1) + actionpack (= 5.2.1) + actionview (= 5.2.1) + activejob (= 5.2.1) + activemodel (= 5.2.1) + activerecord (= 5.2.1) + activestorage (= 5.2.1) + activesupport (= 5.2.1) + bundler (>= 1.3.0) + railties (= 5.2.1) + sprockets-rails (>= 2.0.0) + rails-dom-testing (2.0.3) + activesupport (>= 4.2.0) + nokogiri (>= 1.6) + rails-html-sanitizer (1.0.4) + loofah (~> 2.2, >= 2.2.2) + railties (5.2.1) + actionpack (= 5.2.1) + activesupport (= 5.2.1) + method_source + rake (>= 0.8.7) + thor (>= 0.19.0, < 2.0) + rake (12.3.1) + rb-fsevent (0.10.3) + rb-inotify (0.9.10) + ffi (>= 0.5.0, < 2) + ruby-progressbar (1.10.0) + ruby_dep (1.5.0) + rubyzip (1.2.2) + sass (3.6.0) + sass-listen (~> 4.0.0) + sass-listen (4.0.0) + rb-fsevent (~> 0.9, >= 0.9.4) + rb-inotify (~> 0.9, >= 0.9.7) + sass-rails (5.0.7) + railties (>= 4.0.0, < 6) + sass (~> 3.1) + sprockets (>= 2.8, < 4.0) + sprockets-rails (>= 2.0, < 4.0) + tilt (>= 1.1, < 3) + selenium-webdriver (3.14.1) + childprocess (~> 0.5) + rubyzip (~> 1.2, >= 1.2.2) + shellany (0.0.1) + spring (2.0.2) + activesupport (>= 4.2) + spring-watcher-listen (2.0.1) + listen (>= 2.7, < 4.0) + spring (>= 1.2, < 3.0) + sprockets (3.7.2) + concurrent-ruby (~> 1.0) + rack (> 1, < 3) + sprockets-rails (3.2.1) + actionpack (>= 4.0) + activesupport (>= 4.0) + sprockets (>= 3.0.0) + thor (0.20.0) + thread_safe (0.3.6) + tilt (2.0.8) + turbolinks (5.2.0) + turbolinks-source (~> 5.2) + turbolinks-source (5.2.0) + tzinfo (1.2.5) + thread_safe (~> 0.1) + uglifier (4.1.19) + execjs (>= 0.3.0, < 3) + web-console (3.7.0) + actionview (>= 5.0) + activemodel (>= 5.0) + bindex (>= 0.4.0) + railties (>= 5.0) + websocket-driver (0.7.0) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.3) + xpath (3.1.0) + nokogiri (~> 1.8) + +PLATFORMS + ruby + +DEPENDENCIES + better_errors + binding_of_caller + bootsnap (>= 1.1.0) + bootstrap (~> 4.1.3) + byebug + capybara (>= 2.15) + chromedriver-helper + guard + guard-minitest + jbuilder (~> 2.5) + jquery-rails + jquery-turbolinks + listen (>= 3.0.5, < 3.2) + minitest-rails + minitest-reporters + pg (>= 0.18, < 2.0) + pry-rails + puma (~> 3.11) + rails (~> 5.2.1) + sass-rails (~> 5.0) + selenium-webdriver + spring + spring-watcher-listen (~> 2.0.0) + turbolinks (~> 5) + tzinfo-data + uglifier (>= 1.3.0) + web-console (>= 3.3.0) + +RUBY VERSION + ruby 2.4.1p111 + +BUNDLED WITH + 1.16.5 diff --git a/Guardfile b/Guardfile new file mode 100644 index 0000000000..e34f706f4a --- /dev/null +++ b/Guardfile @@ -0,0 +1,9 @@ +guard :minitest, autorun: false, spring: true do + watch(%r{^app/(.+).rb$}) { |m| "test/#{m[1]}_test.rb" } + watch(%r{^app/controllers/application_controller.rb$}) { 'test/controllers' } + watch(%r{^app/controllers/(.+)_controller.rb$}) { |m| "test/integration/#{m[1]}_test.rb" } + watch(%r{^app/views/(.+)_mailer/.+}) { |m| "test/mailers/#{m[1]}_mailer_test.rb" } + watch(%r{^lib/(.+).rb$}) { |m| "test/lib/#{m[1]}_test.rb" } + watch(%r{^test/.+_test.rb$}) + watch(%r{^test/test_helper.rb$}) { 'test' } +end diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000000..e85f913914 --- /dev/null +++ b/Rakefile @@ -0,0 +1,6 @@ +# Add your own tasks in files placed in lib/tasks ending in .rake, +# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. + +require_relative 'config/application' + +Rails.application.load_tasks diff --git a/app/.DS_Store b/app/.DS_Store new file mode 100644 index 0000000000..40049958de Binary files /dev/null and b/app/.DS_Store differ diff --git a/app/assets/config/manifest.js b/app/assets/config/manifest.js new file mode 100644 index 0000000000..b16e53d6d5 --- /dev/null +++ b/app/assets/config/manifest.js @@ -0,0 +1,3 @@ +//= link_tree ../images +//= link_directory ../javascripts .js +//= link_directory ../stylesheets .css diff --git a/app/assets/images/.keep b/app/assets/images/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js new file mode 100644 index 0000000000..4f73c21a7d --- /dev/null +++ b/app/assets/javascripts/application.js @@ -0,0 +1,20 @@ +// This is a manifest file that'll be compiled into application.js, which will include all the files +// listed below. +// +// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's +// vendor/assets/javascripts directory can be referenced here using a relative path. +// +// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the +// compiled file. JavaScript code in this file should be added after the last require_* statement. +// +// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details +// about supported directives. + //= require jquery3 + //= require popper + //= require bootstrap-sprockets + +// +//= require rails-ujs +//= require activestorage +//= require turbolinks +//= require_tree . diff --git a/app/assets/javascripts/cable.js b/app/assets/javascripts/cable.js new file mode 100644 index 0000000000..739aa5f022 --- /dev/null +++ b/app/assets/javascripts/cable.js @@ -0,0 +1,13 @@ +// Action Cable provides the framework to deal with WebSockets in Rails. +// You can generate new channels where WebSocket features live using the `rails generate channel` command. +// +//= require action_cable +//= require_self +//= require_tree ./channels + +(function() { + this.App || (this.App = {}); + + App.cable = ActionCable.createConsumer(); + +}).call(this); diff --git a/app/assets/javascripts/channels/.keep b/app/assets/javascripts/channels/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/assets/javascripts/sessions.js b/app/assets/javascripts/sessions.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/sessions.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/javascripts/users.js b/app/assets/javascripts/users.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/users.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/javascripts/votes.js b/app/assets/javascripts/votes.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/votes.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/javascripts/works.js b/app/assets/javascripts/works.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/works.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss new file mode 100644 index 0000000000..820bf2d5a3 --- /dev/null +++ b/app/assets/stylesheets/application.scss @@ -0,0 +1,281 @@ +body { + margin: 0; + font-family: -apple-system, "Segoe UI", "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"; + font-size: 1rem; + font-weight: 400; + line-height: 1.5; + color: #212529; + text-align: left; + background-color: #fff; +} + +a { + text-decoration: none; + background-color: transparent; +} +.app-header__nav { + display: flex; + flex-direction: row; + justify-content: space-between; +} + +.header__user-nav-container .nav-item { + margin-left: 2rem; +} + +.app-header__user-nav-container .nav-item { + margin-left: 2rem; +} + +.app-header__nav_item { + margin-top: 1rem; +} + +.top-ten__container { + display: grid; + grid-template-columns: 1fr 1fr 1fr; + grid-column-gap: 2em; +} + +.spotlight { + padding: 0 2rem 2rem 2rem; +} + + +main { + padding: 2rem; +} + +.app-header__header { + max-width: 100%; + background-color: #B2DFDB; + margin-bottom: 0.5rem; + padding: 2rem 1rem 0.5rem 1rem; +} + +.app-header__header h1 a { + color: #FF5722; + padding-right: 25px; + margin-right: 15px; + border-right: white 2px solid; +} + +.app-header__header h1 { + text-align: center; + margin: 25px auto 40px auto; +} + +.app-header__header h1 small { + color: white; +} + +.app-header__nav { + display: flex; + flex-direction: row; + justify-content: space-between; +} + +.app-header__site-nav-container .app-header__nav_item { + margin-right: 2rem; +} + +.app-header__nav_item .nav-link { + color: #00796B; +} + +.nav-link +{ + display: block; + padding: 0.5rem 1rem; +} +.spotlight__header--prefix { + color: #424242; +} + +.spotlight__header { + color: #26A69A; +} + +.spotlight__description { + margin-bottom: 0; +} + +.root__hr { + margin: 0px auto 3rem auto; + color: #EEEEEE; +} + +.top-ten__header { + color: #26A69A; + border-bottom: 2px solid; + border-bottom-color: #B2DFDB; +} + +.top-ten__list { + list-style-type: none; + margin-left: 0; + padding-left: 0; +} + +.list-group-item { + border: none; +} + +.list-group-item { + position: relative; + display: block; + padding: 0.75rem 1.25rem; + margin-bottom: -1px; + background-color: #fff; + // border: 1px solid rgba(0,0,0,0.125); +} + +.list-group-item:first-child { + border-top-left-radius: 0.25rem; + border-top-right-radius: 0.25rem; +} + +h1, h2, h3, h4, h5 { + font-weight: bold; +} + +a, h2, h3 { + color: #26A69A; +} + +.top-ten__creator { + color: slategrey; +} + +section { + display: block; +} + +.form-group { + margin-bottom: 1rem; +} + +label { + display: inline-block; + margin-bottom: 0.5rem; +} + +*,* ::before, *::after { + box-sizing: border-box; +} + +.form-control { + display: block; + width: 100%; + height: calc(2.25rem + 2px); + padding: 0.375rem 0.75rem; + font-size: 1rem; + line-height: 1.5; + color: #495057; + background-color: #fff; + background-clip: padding-box; + border: 1px solid #ced4da; + border-radius: 0.25rem; + transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out; +} + +button, input { + overflow: visible; +} + +.btn { + display: inline-block; + font-weight: 400; + text-align: center; + white-space: nowrap; + vertical-align: middle; + -webkit-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none; + border: 1px solid transparent; + padding: 0.375rem 0.75rem; + font-size: 1rem; + line-height: 1.5; + border-radius: 0.25rem; + transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out; +} + +.btn-primary { + background-color: #26A69A; + color: white; + border-color: #26A69A; +} +.btn-secondary { + color:#fff; + background-color: #6c757d; + border-color: #6c757d; +} + +.alert__container { + margin: 2rem 0 1rem 0; +} + +h4, .h4 { + font-size: 1.5rem; +} + +.works-votes__container { + margin-top: 2rem; +} + +.nav { + display: flex; + flex-wrap: wrap; + padding-left: 0; + margin-bottom: 0; + list-style: none; +} +ul { + margin-top:0; + margin-block-start: 1em; + margin-block-end: 1em; + margin-inline-start: 0px; + margin-inline-end: 0px; + padding-inline-start: 40px; +} + +.table { + width: 100%; + margin-bottom: 1rem; + background-color: transparent; +} + +table { + display: table; + border-spacing: 2px; + border-color: grey; + border-collapse: collapse; +} + +tbody { + display: table-row-group; + vertical-align: middle; + border-color: inherit; +} + +.table td { + padding: 0.75rem; + vertical-align: middle; + border-top: 1px solid #dee2e6; +} + +thead { + display: table-header-group; + vertical-align: middle; + border-color: inherit; +} +.btn-danger { + color: #fff; + background-color: #dc3545; + border-color: #dc3545; +} + +.works-votes__header { + color: black; +} diff --git a/app/assets/stylesheets/sessions.scss b/app/assets/stylesheets/sessions.scss new file mode 100644 index 0000000000..ccb1ed25b2 --- /dev/null +++ b/app/assets/stylesheets/sessions.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Sessions controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/users.scss b/app/assets/stylesheets/users.scss new file mode 100644 index 0000000000..31a2eacb84 --- /dev/null +++ b/app/assets/stylesheets/users.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Users controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/votes.scss b/app/assets/stylesheets/votes.scss new file mode 100644 index 0000000000..9a6720f80e --- /dev/null +++ b/app/assets/stylesheets/votes.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Votes controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/works.scss b/app/assets/stylesheets/works.scss new file mode 100644 index 0000000000..5618452f3e --- /dev/null +++ b/app/assets/stylesheets/works.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Works controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/channels/application_cable/channel.rb b/app/channels/application_cable/channel.rb new file mode 100644 index 0000000000..d672697283 --- /dev/null +++ b/app/channels/application_cable/channel.rb @@ -0,0 +1,4 @@ +module ApplicationCable + class Channel < ActionCable::Channel::Base + end +end diff --git a/app/channels/application_cable/connection.rb b/app/channels/application_cable/connection.rb new file mode 100644 index 0000000000..0ff5442f47 --- /dev/null +++ b/app/channels/application_cable/connection.rb @@ -0,0 +1,4 @@ +module ApplicationCable + class Connection < ActionCable::Connection::Base + end +end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb new file mode 100644 index 0000000000..473269f711 --- /dev/null +++ b/app/controllers/application_controller.rb @@ -0,0 +1,11 @@ +class ApplicationController < ActionController::Base + # before_action :set_cache_headers + before_action :find_user + + private + + def find_user + @current_user = User.find_by(id: session[:user_id]) + end + +end diff --git a/app/controllers/concerns/.keep b/app/controllers/concerns/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb new file mode 100644 index 0000000000..e36c18f800 --- /dev/null +++ b/app/controllers/sessions_controller.rb @@ -0,0 +1,31 @@ +class SessionsController < ApplicationController + def login + user = User.find_by(username: params[:user][:username]) + + if user.nil? + user = User.new(username: params[:user][:username]) + if user.save + session[:user_id] = user.id + flash[:success] = "Successfully created account and logged in as #{user.username}!" + redirect_to root_path + else + flash[:warning] = "User was not successfully added" + redirect_to login_path + end + else + session[:user_id] = user.id + flash[:success] = "Successfully logged in as existing user #{user.username}!" + redirect_to root_path + end + end + + def new + @user = User.new + end + + def destroy + session[:user_id] = nil + flash[:success] = 'Successfully logged out' + redirect_back fallback_location: root_path + end +end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb new file mode 100644 index 0000000000..30a9f0cb64 --- /dev/null +++ b/app/controllers/users_controller.rb @@ -0,0 +1,32 @@ +class UsersController < ApplicationController + def show + @user = User.find_by(id: params[:id].to_i) + end + + def index + @users = User.all + end + + def create + @user = User.new(user_params) + if @user.save + redirect_to user_path + else + render :new + end + end + + def update + @user.update(user_params) + if @user.save + redirect_to user_path + else + render :new + end + end + + private + def user_params + return params.require(:user).permit(:username) + end +end diff --git a/app/controllers/votes_controller.rb b/app/controllers/votes_controller.rb new file mode 100644 index 0000000000..0b5add49ec --- /dev/null +++ b/app/controllers/votes_controller.rb @@ -0,0 +1,31 @@ +class VotesController < ApplicationController + def new + @vote = Vote.new + end + + def index + @votes = Vote.all + end + + def create + @work = Work.find_by(id: params[:id]) + vote = Vote.new(user_id: @current_user.id, work_id: @work.id) + if @current_user.nil? + flash[:warning] = "You must be logged in to vote" + redirect_to root_path + else + upvote = Vote.new(user_id: @current_user.id, work_id: @work.id) + vote.save + flash[:message] = "Vote added to #{@work.title}" + end + end + + def destroy + unless @vote.nil? + @vote.destroy + flash[:success] = "Vote deleted" + redirect_to root_path + end + end + +end diff --git a/app/controllers/works_controller.rb b/app/controllers/works_controller.rb new file mode 100644 index 0000000000..13ad60ded9 --- /dev/null +++ b/app/controllers/works_controller.rb @@ -0,0 +1,80 @@ +class WorksController < ApplicationController + before_action :find_work, only:[:show, :edit, :update, :destroy, :upvote] + + def main + @works = Work.all + end + + def show; end + + def index + @works = Work.all + end + + def new + @work = Work.new + end + + def create + @work = Work.new(work_params) + if @work.save + flash[:success] = "Successfully created #{@work.category} #{@work.title}!" + redirect_to work_path(@work.id) + else + flash.now[:error] = 'Work not added' + @work.errors.messages.each do |field, messages| + flash.now[field] = messages + end + render :new + end + end + + def edit; end + + def update + if @work && @work.update(work_params) + redirect_to work_path(@work.id) + elsif @work + render :edit + end +end + + + def destroy + unless @work.nil? + @work.destroy + flash[:success] = "#{@work.title} deleted" + redirect_to root_path + end + end + + def upvote + if @current_user.nil? + flash[:warning] = "You must be logged in to vote" + redirect_to root_path + else + @upvote = Vote.new(user_id: @current_user.id, work_id: @work.id) + if @upvote.save + flash[:message] = "Vote added to #{@work.title}" + redirect_to works_path + else + flash[:warning] = "A problem occurred: #{@current_user.username.capitalize} has already voted for this work" + redirect_to work_path + end + end + end + +private + + def find_work + @work = Work.find_by(id:params[:id].to_i) + if @work.nil? + flash.now[:warning] = 'Cannot find work' + render :notfound + end + end + + def work_params + return params.require(:work).permit(:title, :publication_year, :creator, :description, :category) + end +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb new file mode 100644 index 0000000000..de6be7945c --- /dev/null +++ b/app/helpers/application_helper.rb @@ -0,0 +1,2 @@ +module ApplicationHelper +end diff --git a/app/helpers/sessions_helper.rb b/app/helpers/sessions_helper.rb new file mode 100644 index 0000000000..309f8b2eb3 --- /dev/null +++ b/app/helpers/sessions_helper.rb @@ -0,0 +1,2 @@ +module SessionsHelper +end diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb new file mode 100644 index 0000000000..2310a240d7 --- /dev/null +++ b/app/helpers/users_helper.rb @@ -0,0 +1,2 @@ +module UsersHelper +end diff --git a/app/helpers/votes_helper.rb b/app/helpers/votes_helper.rb new file mode 100644 index 0000000000..5a82eed07d --- /dev/null +++ b/app/helpers/votes_helper.rb @@ -0,0 +1,2 @@ +module VotesHelper +end diff --git a/app/helpers/works_helper.rb b/app/helpers/works_helper.rb new file mode 100644 index 0000000000..ccb78c2b73 --- /dev/null +++ b/app/helpers/works_helper.rb @@ -0,0 +1,2 @@ +module WorksHelper +end diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb new file mode 100644 index 0000000000..a009ace51c --- /dev/null +++ b/app/jobs/application_job.rb @@ -0,0 +1,2 @@ +class ApplicationJob < ActiveJob::Base +end diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb new file mode 100644 index 0000000000..286b2239d1 --- /dev/null +++ b/app/mailers/application_mailer.rb @@ -0,0 +1,4 @@ +class ApplicationMailer < ActionMailer::Base + default from: 'from@example.com' + layout 'mailer' +end diff --git a/app/models/application_record.rb b/app/models/application_record.rb new file mode 100644 index 0000000000..10a4cba84d --- /dev/null +++ b/app/models/application_record.rb @@ -0,0 +1,3 @@ +class ApplicationRecord < ActiveRecord::Base + self.abstract_class = true +end diff --git a/app/models/concerns/.keep b/app/models/concerns/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 0000000000..6679ec46c1 --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,5 @@ +class User < ApplicationRecord + has_many :works + has_many :votes + has_many :works, through: :votes +end diff --git a/app/models/vote.rb b/app/models/vote.rb new file mode 100644 index 0000000000..ff7308ea58 --- /dev/null +++ b/app/models/vote.rb @@ -0,0 +1,7 @@ +class Vote < ApplicationRecord + belongs_to :user + belongs_to :work + + validates :user_id, presence: true, uniqueness: { scope: :work, message: "You can only add one vote per work"} + # validates :work_id, presence: true +end diff --git a/app/models/work.rb b/app/models/work.rb new file mode 100644 index 0000000000..50f913fa0a --- /dev/null +++ b/app/models/work.rb @@ -0,0 +1,28 @@ +class Work < ApplicationRecord + has_many :votes, dependent: :destroy + # has_many :users, through :votes + + validates :title, presence: true, uniqueness: {scope: :category} + validates :publication_year, numericality: true, length: {is: 4} + validates :creator, presence: true + + def self.sort_by_category(category) + selected_works = [] + @works = Work.all + @works.each do |work| + if category == work.category + selected_works << work + end + end + return selected_works + end + + def self.sort_by_votes(category) + @works = self.sort_by_category(category) + return top_10 = @works.sort_by{|work| work.votes.count}.reverse! + end + + + + +end diff --git a/app/views/application/_form.html.erb b/app/views/application/_form.html.erb new file mode 100644 index 0000000000..d1298c5784 --- /dev/null +++ b/app/views/application/_form.html.erb @@ -0,0 +1,21 @@ + +<%= form_with model: @work, method: method, local: true do |f|%> +
Username | +Votes | +Joined | +
---|---|---|
<%=link_to user.username, user_path(user.id) %> | +<%=user.votes.count %> | +<%=user.created_at%> | +
Joined site <%=@user.created_at%>
+Media Title | +Created By | +Published | +Category | +Voted on | +
---|---|---|---|---|
<%=link_to work.title, work_path(work.id) %> | +<%=work.creator%> | +<%=work.publication_year%> | +<%=work.category%> | +<%=vote.created_at%> | +
Votes | +Title | +Created By | +Published | +Upvote | +
---|---|---|---|---|
<%=work.votes.count%> | +<%=work.title%> | +<%=work.creator%> | +<%=work.publication_year%> | +Upvote | +
<%=spotlight.votes.count%> votes - <%=spotlight.description%>
+<%=work.votes.count%> votes
+Created by: <%= @work.creator %>
+Published: <%= @work.publication_year%>
+<%= @work.description%>
+User | +Date | +
---|---|
+ <%=user.username%> + | +<%=vote.created_at%> | +
You may have mistyped the address or the page may have moved.
+If you are the application owner check the logs for more information.
+Maybe you tried to change something you didn't have access to.
+If you are the application owner check the logs for more information.
+If you are the application owner check the logs for more information.
+