diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..11a546eaa --- /dev/null +++ b/.gitignore @@ -0,0 +1,30 @@ +# 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 +/coverage +.DS_Store + + +# Ignore master key for decrypting credentials and more. +/config/master.key diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 000000000..25c81fe39 --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +ruby-2.5.1 \ No newline at end of file diff --git a/Gemfile b/Gemfile new file mode 100644 index 000000000..d997ee960 --- /dev/null +++ b/Gemfile @@ -0,0 +1,83 @@ +source 'https://rubygems.org' +git_source(:github) { |repo| "https://github.com/#{repo}.git" } + +ruby '2.5.1' + +# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' +gem 'rails', '~> 5.2.3' +# 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-turbolinks' +gem 'jquery-rails' +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' + gem 'minitest-skip' +end + +gem 'will_paginate', '~> 3.0' \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 000000000..f63ce26f2 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,276 @@ +GEM + remote: https://rubygems.org/ + specs: + actioncable (5.2.3) + actionpack (= 5.2.3) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + actionmailer (5.2.3) + actionpack (= 5.2.3) + actionview (= 5.2.3) + activejob (= 5.2.3) + mail (~> 2.5, >= 2.5.4) + rails-dom-testing (~> 2.0) + actionpack (5.2.3) + actionview (= 5.2.3) + activesupport (= 5.2.3) + rack (~> 2.0) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + actionview (5.2.3) + activesupport (= 5.2.3) + builder (~> 3.1) + erubi (~> 1.4) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.3) + activejob (5.2.3) + activesupport (= 5.2.3) + globalid (>= 0.3.6) + activemodel (5.2.3) + activesupport (= 5.2.3) + activerecord (5.2.3) + activemodel (= 5.2.3) + activesupport (= 5.2.3) + arel (>= 9.0) + activestorage (5.2.3) + actionpack (= 5.2.3) + activerecord (= 5.2.3) + marcel (~> 0.3.1) + activesupport (5.2.3) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 0.7, < 2) + minitest (~> 5.1) + tzinfo (~> 1.1) + addressable (2.6.0) + public_suffix (>= 2.0.2, < 4.0) + ansi (1.5.0) + archive-zip (0.12.0) + io-like (~> 0.3.0) + arel (9.0.0) + better_errors (2.5.1) + coderay (>= 1.0.0) + erubi (>= 1.0.0) + rack (>= 0.9.0) + bindex (0.7.0) + binding_of_caller (0.8.0) + debug_inspector (>= 0.0.1) + bootsnap (1.4.3) + msgpack (~> 1.0) + builder (3.2.3) + byebug (11.0.1) + capybara (3.16.2) + addressable + mini_mime (>= 0.1.3) + nokogiri (~> 1.8) + rack (>= 1.6.0) + rack-test (>= 0.6.3) + regexp_parser (~> 1.2) + xpath (~> 3.2) + childprocess (0.9.0) + ffi (~> 1.0, >= 1.0.11) + chromedriver-helper (2.1.1) + archive-zip (~> 0.10) + nokogiri (~> 1.8) + coderay (1.1.2) + concurrent-ruby (1.1.5) + crass (1.0.4) + debug_inspector (0.0.3) + erubi (1.8.0) + execjs (2.7.0) + ffi (1.10.0) + formatador (0.2.5) + globalid (0.4.2) + activesupport (>= 4.2.0) + guard (2.15.0) + 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.6.0) + concurrent-ruby (~> 1.0) + io-like (0.3.0) + jbuilder (2.8.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.3) + crass (~> 1.0.2) + nokogiri (>= 1.5.9) + lumberjack (1.0.13) + mail (2.7.1) + mini_mime (>= 0.1.1) + marcel (0.3.3) + mimemagic (~> 0.3.2) + method_source (0.9.2) + mimemagic (0.3.3) + mini_mime (1.0.1) + mini_portile2 (2.4.0) + minitest (5.11.3) + minitest-rails (3.0.0) + minitest (~> 5.8) + railties (~> 5.0) + minitest-reporters (1.3.6) + ansi + builder + minitest (>= 5.0) + ruby-progressbar + minitest-skip (0.0.1) + minitest (~> 5.0) + msgpack (1.2.9) + multi_json (1.13.1) + nenv (0.3.0) + nio4r (2.3.1) + nokogiri (1.10.2) + mini_portile2 (~> 2.4.0) + notiffany (0.1.1) + nenv (~> 0.1) + shellany (~> 0.0) + pg (1.1.4) + pry (0.12.2) + coderay (~> 1.1.0) + method_source (~> 0.9.0) + pry-rails (0.3.9) + pry (>= 0.10.4) + public_suffix (3.0.3) + puma (3.12.1) + rack (2.0.7) + rack-test (1.1.0) + rack (>= 1.0, < 3) + rails (5.2.3) + actioncable (= 5.2.3) + actionmailer (= 5.2.3) + actionpack (= 5.2.3) + actionview (= 5.2.3) + activejob (= 5.2.3) + activemodel (= 5.2.3) + activerecord (= 5.2.3) + activestorage (= 5.2.3) + activesupport (= 5.2.3) + bundler (>= 1.3.0) + railties (= 5.2.3) + 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.3) + actionpack (= 5.2.3) + activesupport (= 5.2.3) + method_source + rake (>= 0.8.7) + thor (>= 0.19.0, < 2.0) + rake (12.3.2) + rb-fsevent (0.10.3) + rb-inotify (0.10.0) + ffi (~> 1.0) + regexp_parser (1.4.0) + ruby-progressbar (1.10.0) + ruby_dep (1.5.0) + rubyzip (1.2.2) + sass (3.7.4) + 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.141.0) + 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.3) + thread_safe (0.3.6) + tilt (2.0.9) + turbolinks (5.2.0) + turbolinks-source (~> 5.2) + turbolinks-source (5.2.0) + tzinfo (1.2.5) + thread_safe (~> 0.1) + uglifier (4.1.20) + 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) + will_paginate (3.1.7) + xpath (3.2.0) + nokogiri (~> 1.8) + +PLATFORMS + ruby + +DEPENDENCIES + better_errors + binding_of_caller + bootsnap (>= 1.1.0) + 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 + minitest-skip + pg (>= 0.18, < 2.0) + pry-rails + puma (~> 3.11) + rails (~> 5.2.3) + 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) + will_paginate (~> 3.0) + +RUBY VERSION + ruby 2.5.1p57 + +BUNDLED WITH + 1.17.3 diff --git a/Guardfile b/Guardfile new file mode 100644 index 000000000..e34f706f4 --- /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 000000000..e85f91391 --- /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/assets/config/manifest.js b/app/assets/config/manifest.js new file mode 100644 index 000000000..b16e53d6d --- /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 000000000..e69de29bb diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js new file mode 100644 index 000000000..82e6f0f6c --- /dev/null +++ b/app/assets/javascripts/application.js @@ -0,0 +1,16 @@ +// 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 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 000000000..739aa5f02 --- /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 000000000..e69de29bb diff --git a/app/assets/javascripts/drivers.js b/app/assets/javascripts/drivers.js new file mode 100644 index 000000000..dee720fac --- /dev/null +++ b/app/assets/javascripts/drivers.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/homepages.js b/app/assets/javascripts/homepages.js new file mode 100644 index 000000000..dee720fac --- /dev/null +++ b/app/assets/javascripts/homepages.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/passengers.js b/app/assets/javascripts/passengers.js new file mode 100644 index 000000000..dee720fac --- /dev/null +++ b/app/assets/javascripts/passengers.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/trips.js b/app/assets/javascripts/trips.js new file mode 100644 index 000000000..dee720fac --- /dev/null +++ b/app/assets/javascripts/trips.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.css b/app/assets/stylesheets/application.css new file mode 100644 index 000000000..4b4a13db7 --- /dev/null +++ b/app/assets/stylesheets/application.css @@ -0,0 +1,226 @@ + +@import url('https://fonts.googleapis.com/css?family=Cutive+Mono|Montserrat:900|Work+Sans:300'); + + body { + font-family: 'Work Sans', sans-serif; + font-weight: 300; + } + + h1, h2, h3, h4, h5, h6 { + font-family: 'Montserrat', sans-serif; + font-weight: 900; + } +.grid-container { + display: grid; + grid-template-columns: 1fr 1fr 1fr 1fr; + grid-template-rows: 80px 1fr 80px; + grid-template-areas: "page-left navbar navbar page-right" "page-left left-card right-card page-right" "page-left content content page-right" "footer footer footer footer"; + } + +.content { + grid-area: content; +} + +.navbar { + grid-area: navbar; + font-family: 'Montserrat', sans-serif; + display: block; + top: 2; + width: auto; + height: 60px; + background: #fff; + border: solid 5px rgb(145, 221, 183);; + } + +a { + color: #555; + } + + nav ul { + margin: 0px; + padding: 20 20px; + list-style: none; + overflow: hidden; + background-color: transparent; + z-index: 10;; + } + + nav li { + float: right; + } + + nav li a { + display: block; + padding: 20px 10px; + background-color: transparent; + text-decoration: none; + } + + nav li a:hover, + nav .menu-btn:hover { + color: red; + } + + nav .logo { + display: block; + float: left; + font-size: 2em; + padding: 10px 20px; + text-decoration: none; + } + + nav .menu { + clear: none; + max-height: none; + float: right; + } + + table.table { + font-size: 1.2rem; + font-family: "Cutive Mono", monospace; + background-color: #FFFFFF; + width: 100%; + height: 100%; + text-align: center; +} + +table.table td, table.table th { + border: 1px solid #FFFFFF; + padding: 5px 5px; +} +table.table tr:nth-child(even) { + background: #D0F5C7; +} + +table.table th { + background: #3AA467; + font-size: 1.2rem; + font-weight: 900; + color: #FFFFFF; + text-align: center; + border-left: 2px solid #FFFFFF; +} + +table.table th:first-child { + border-left: none; +} + +td { + border: none; + border-bottom: 1px solid #eee; + position: relative; + white-space: normal; + text-align: left; +} + +.table td:before { + position: absolute; + top: 8px; + left: 15px; + width: 45%; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + text-align: left; + font-weight: bold; +} + +.left-card { + grid-area: left-card; + width: 450px; + height: 250px; + background-color: #fff; + border-radius: 6px; + overflow: hidden; + position: relative; +} + +.left-card .additional { + position: absolute; + width: 150px; + height: 100%; + background: linear-gradient(#92bCa6, #A2CCB6); + transition: width 0.4s; + overflow: hidden; + z-index: 2; + border-radius: 5px; + } + + .left-card:hover .additional { + width: 100%; + border-radius: 5px; + } + + .left-card .additional .user { + width: 150px; + height: 100%; + position: relative; + float: left; + } + + .left-card .additional .user h2 { + writing-mode: tb-rl; + transform: rotate(-180deg); + margin-left: 2rem; + margin-top: 2rem; + text-align: center; + color: #fff; + } + + .left-card .additional .user:after { + content: ""; + display: block; + position: absolute; + top: 10%; + right: -2px; + height: 80%; + border-left: 2px solid rgba(0,0,0,0.025); + } + + .left-card .additional .user { + top: 2%; + text-transform: uppercase; + font-size: 0.75em; + font-weight: bold; + } + + .left-card .additional .coords { + margin: 0 1rem; + font-size: 1rem; + color: #325C46; + } + + .left-card .additional .coords span + span { + float: right; + color: #fff; + } + + .left-card .additional .more-info { + width: 300px; + float: left; + position: absolute; + left: 150px; + height: 100%; + } + + .left-card .additional .more-info h1 { + color: #325C46; + margin-bottom: 0; + } + + .left-card h1 { + text-align: center; + } + + .center { + position: absolute; + top: 50%; + left: 50%; + } + +.page-right { grid-area: page-right; } + +.page-left { grid-area: page-left; } + +.footer { grid-area: footer; } + diff --git a/app/assets/stylesheets/drivers.scss b/app/assets/stylesheets/drivers.scss new file mode 100644 index 000000000..8c1768a14 --- /dev/null +++ b/app/assets/stylesheets/drivers.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Drivers 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/homepages.scss b/app/assets/stylesheets/homepages.scss new file mode 100644 index 000000000..2305c36d1 --- /dev/null +++ b/app/assets/stylesheets/homepages.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Homepages 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/passengers.scss b/app/assets/stylesheets/passengers.scss new file mode 100644 index 000000000..0e27942f7 --- /dev/null +++ b/app/assets/stylesheets/passengers.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Passengers 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/trips.scss b/app/assets/stylesheets/trips.scss new file mode 100644 index 000000000..f1f72ad11 --- /dev/null +++ b/app/assets/stylesheets/trips.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Trips 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 000000000..d67269728 --- /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 000000000..0ff5442f4 --- /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 000000000..09705d12a --- /dev/null +++ b/app/controllers/application_controller.rb @@ -0,0 +1,2 @@ +class ApplicationController < ActionController::Base +end diff --git a/app/controllers/concerns/.keep b/app/controllers/concerns/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/app/controllers/drivers_controller.rb b/app/controllers/drivers_controller.rb new file mode 100644 index 000000000..9996c800a --- /dev/null +++ b/app/controllers/drivers_controller.rb @@ -0,0 +1,81 @@ +class DriversController < ApplicationController + def index + @drivers = Driver.all.paginate(:page => params[:page], :per_page => 10) + end + + def show + driver_id = params[:id].to_i + @driver = Driver.find_by(id: driver_id) + + if @driver.nil? + redirect_to drivers_path + end + end + + def new + @driver = Driver.new + end + + def create + @driver = Driver.new(driver_params) + + if @driver.save + redirect_to driver_path(@driver.id) + else + render :new, status: :bad_request + end + end + + def edit + driver_id = params[:id].to_i + @driver = Driver.find_by(id: driver_id) + + if @driver.nil? + redirect_to drivers_path + end + end + + def update + @driver = Driver.find_by(id: params[:id]) + + if @driver.update(driver_params) + redirect_to driver_path(@driver.id) + else + render :edit, status: :bad_request + end + + if @driver.nil? + redirect_to drivers_path + end + end + + def destroy + driver = Driver.find_by(id: params[:id]) + + if driver.nil? + head :not_found + else + driver.destroy + redirect_to drivers_path + end + end + + def availability + driver = Driver.find_by(id: params[:id]) + + if driver.nil? + head :not_found + else + driver.toggle(:available) + driver.save + end + + redirect_to driver_path(driver.id) + end + + private + + def driver_params + params.require(:driver).permit(:name, :vin, :available, :active) + end +end diff --git a/app/controllers/homepages_controller.rb b/app/controllers/homepages_controller.rb new file mode 100644 index 000000000..f200c8ac2 --- /dev/null +++ b/app/controllers/homepages_controller.rb @@ -0,0 +1,4 @@ +class HomepagesController < ApplicationController + def index + end +end diff --git a/app/controllers/passengers_controller.rb b/app/controllers/passengers_controller.rb new file mode 100644 index 000000000..71cd5c675 --- /dev/null +++ b/app/controllers/passengers_controller.rb @@ -0,0 +1,68 @@ +class PassengersController < ApplicationController + def index + @passengers = Passenger.all.order(:id) + end + + def show + passenger_id = params[:id].to_i + @passenger = Passenger.find_by(id: passenger_id) + @trip = Trip.new + + if @passenger.nil? + redirect_to passengers_path + end + end + + def new + @passenger = Passenger.new + end + + def create + @passenger = Passenger.new(passenger_params) + + if @passenger.save + redirect_to passenger_path(@passenger.id) + else + render :new, status: :bad_request + end + end + + def edit + passenger_id = params[:id].to_i + @passenger = Passenger.find_by(id: passenger_id) + + if @passenger.nil? + redirect_to passengers_path + end + end + + def update + passenger_id = params[:id].to_i + @passenger = Passenger.find_by(id: passenger_id) + + if @passenger.update(passenger_params) + redirect_to passenger_path(@passenger.id) + elsif @passenger.nil? || !@passenger.active + redirect_to passengers_path + else + render :edit, status: :bad_request + end + end + + def destroy + passenger = Passenger.find_by(id: params[:id]) + + if passenger.nil? + head :not_found + else + passenger.destroy + redirect_to passengers_path + end + end + + private + + def passenger_params + return params.require(:passenger).permit(:name, :phone_num, :active) + end +end diff --git a/app/controllers/trips_controller.rb b/app/controllers/trips_controller.rb new file mode 100644 index 000000000..abd7381f6 --- /dev/null +++ b/app/controllers/trips_controller.rb @@ -0,0 +1,79 @@ +require "date" + +class TripsController < ApplicationController + def index + if params[:passenger_id] + @trips = Trip.where(passenger: Passenger.find_by(id: [:passenger_id])) + elsif params[:driver_id] + @trips = Trip.where(driver: Driver.find_by(id: [:driver_id])) + else + @trips = Trip.all.order(:id) + end + end + + def show + @trip = Trip.find_by(id: params[:id]) + if @trip.nil? + head :not_found + end + end + + def new + @trip = Trip.new + end + + def create + @trip = Trip.new( + date: Date.today, + cost: 0, + passenger_id: params[:passenger_id], + driver_id: Driver.next_available.id, + ) + if @trip.save + @trip.driver.update_attribute(:available, false) + redirect_to trip_path(@trip.id) + else + redirect_to passenger_path(@trip.passenger_id), available: :bad_request + end + end + + def edit + trip_id = params[:id].to_i + @trip = Trip.find_by(id: trip_id) + + if @trip.nil? + head :not_found + end + end + + def update + @trip = Trip.find_by(id: params[:id]) + + if @trip.update(trip_params) + redirect_to trip_path(@trip.id) + else + render :edit + end + + if @trip.nil? + head :not_found + end + end + + def destroy + trip = Trip.find_by(id: params[:id]) + + if trip.nil? + head :not_found + else + trip.destroy + redirect_to homepages_path + end + end + + private + + def trip_params + params.require(:trip).permit(:rating, :cost, :driver_id, :passenger_id) + end +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb new file mode 100644 index 000000000..de6be7945 --- /dev/null +++ b/app/helpers/application_helper.rb @@ -0,0 +1,2 @@ +module ApplicationHelper +end diff --git a/app/helpers/drivers_helper.rb b/app/helpers/drivers_helper.rb new file mode 100644 index 000000000..e5fc532e4 --- /dev/null +++ b/app/helpers/drivers_helper.rb @@ -0,0 +1,2 @@ +module DriversHelper +end diff --git a/app/helpers/homepages_helper.rb b/app/helpers/homepages_helper.rb new file mode 100644 index 000000000..4bd8098f3 --- /dev/null +++ b/app/helpers/homepages_helper.rb @@ -0,0 +1,2 @@ +module HomepagesHelper +end diff --git a/app/helpers/passengers_helper.rb b/app/helpers/passengers_helper.rb new file mode 100644 index 000000000..1af9e68f1 --- /dev/null +++ b/app/helpers/passengers_helper.rb @@ -0,0 +1,2 @@ +module PassengersHelper +end diff --git a/app/helpers/trips_helper.rb b/app/helpers/trips_helper.rb new file mode 100644 index 000000000..04f333d46 --- /dev/null +++ b/app/helpers/trips_helper.rb @@ -0,0 +1,2 @@ +module TripsHelper +end diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb new file mode 100644 index 000000000..a009ace51 --- /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 000000000..286b2239d --- /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 000000000..10a4cba84 --- /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 000000000..e69de29bb diff --git a/app/models/driver.rb b/app/models/driver.rb new file mode 100644 index 000000000..d44b385c9 --- /dev/null +++ b/app/models/driver.rb @@ -0,0 +1,21 @@ +class Driver < ApplicationRecord + has_many :trips + validates :name, presence: true + validates :vin, presence: true, uniqueness: true + + FEE = 165 + PERCENTAGE = 0.80 + + def total_earnings + return self.trips.sum { |trip| trip.cost - FEE } * PERCENTAGE + end + + def average_rating + not_nil = self.trips.find_all{ |trip| !trip.rating.nil? } + return 1.0 * not_nil.sum{ |trip| trip.rating } / not_nil.length + end + + def self.next_available + return Driver.where(:available == true && :active == true).order(:updated_at).first + end +end diff --git a/app/models/passenger.rb b/app/models/passenger.rb new file mode 100644 index 000000000..d50725311 --- /dev/null +++ b/app/models/passenger.rb @@ -0,0 +1,18 @@ +class Passenger < ApplicationRecord + has_many :trips + + validates :name, presence: true + validates :phone_num, presence: true, uniqueness: true + + def total_amount_charged + passenger_trips = self.trips.all + + total_cost = 0 + + passenger_trips.each do |trip| + total_cost += trip.cost + end + + return (total_cost.to_i / 100.0).round(2) + end +end diff --git a/app/models/trip.rb b/app/models/trip.rb new file mode 100644 index 000000000..3f761103a --- /dev/null +++ b/app/models/trip.rb @@ -0,0 +1,4 @@ +class Trip < ApplicationRecord + belongs_to :passenger + belongs_to :driver +end diff --git a/app/views/drivers/_form.html.erb b/app/views/drivers/_form.html.erb new file mode 100644 index 000000000..f3ec8cca7 --- /dev/null +++ b/app/views/drivers/_form.html.erb @@ -0,0 +1,22 @@ +<% if @driver.errors.any? %> + +<% end %> + +<%= form_with model: @driver do |f| %> + + <%= f.label :name %>
+ <%= f.text_field :name %> +
+
+ <%= f.label :vin %>
+ <%= f.text_field :vin %> + + <%= f.submit action_name %> + +<% end %> \ No newline at end of file diff --git a/app/views/drivers/create.html.erb b/app/views/drivers/create.html.erb new file mode 100644 index 000000000..a3069c65c --- /dev/null +++ b/app/views/drivers/create.html.erb @@ -0,0 +1,2 @@ +

Drivers#create

+

Find me in app/views/drivers/create.html.erb

diff --git a/app/views/drivers/destroy.html.erb b/app/views/drivers/destroy.html.erb new file mode 100644 index 000000000..9955c57cf --- /dev/null +++ b/app/views/drivers/destroy.html.erb @@ -0,0 +1,2 @@ +

Drivers#destroy

+

Find me in app/views/drivers/destroy.html.erb

diff --git a/app/views/drivers/edit.html.erb b/app/views/drivers/edit.html.erb new file mode 100644 index 000000000..2054e7745 --- /dev/null +++ b/app/views/drivers/edit.html.erb @@ -0,0 +1,3 @@ +

Edit Driver

+ +<%= render partial: "form", locals: { action_name: "Update Driver" } %> diff --git a/app/views/drivers/index.html.erb b/app/views/drivers/index.html.erb new file mode 100644 index 000000000..d92d36feb --- /dev/null +++ b/app/views/drivers/index.html.erb @@ -0,0 +1,22 @@ +

All Drivers

+<%= will_paginate @drivers %> + + + + + + + + + + +<% @drivers.all.each do |driver| %> +<% if driver.active? %> + + + + + +<% end %> +<% end %> +
Driver PhotoNameRatingStatus
<%= image_tag "https://robohash.org/#{driver.id}.png?size=50x50" %><%= link_to driver[:name], driver_path(driver.id) %><%= driver.average_rating.round(2) %><%= driver.available %>
\ No newline at end of file diff --git a/app/views/drivers/new.html.erb b/app/views/drivers/new.html.erb new file mode 100644 index 000000000..8d24b5f33 --- /dev/null +++ b/app/views/drivers/new.html.erb @@ -0,0 +1,3 @@ +

Add New Driver

+ +<%= render partial: "form", locals: { action_name: "Add Driver" } %> \ No newline at end of file diff --git a/app/views/drivers/show.html.erb b/app/views/drivers/show.html.erb new file mode 100644 index 000000000..c666e197e --- /dev/null +++ b/app/views/drivers/show.html.erb @@ -0,0 +1,42 @@ +

Driver Profile

+