diff --git a/Gemfile b/Gemfile index 2d2a53fea..0381bfc6b 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'https://rubygems.org' git_source(:github) { |repo| "https://github.com/#{repo}.git" } @@ -38,23 +40,22 @@ gem 'bootsnap', '>= 1.1.0', require: false group :development, :test do gem 'capybara' - gem 'shoulda-matchers' gem 'launchy' gem 'orderly' gem 'pry' gem 'rspec-rails' + gem 'shoulda-matchers' gem 'simplecov' 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' + gem 'web-console', '>= 3.3.0' # 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 - # Windows does not include zoneinfo files, so bundle the tzinfo-data gem -gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] +gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby] diff --git a/Rakefile b/Rakefile index 9a5ea7383..488c551fe 100644 --- a/Rakefile +++ b/Rakefile @@ -1,6 +1,8 @@ +# frozen_string_literal: true + # 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" +require_relative 'config/application' Rails.application.load_tasks diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index d05ea0f51..af03b3940 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -13,3 +13,49 @@ *= require_tree . *= require_self */ + +li { + margin: 10px; +} + +.wide { + height: 90px; + width: 50%; +} + +.flash { + color: rgb(107, 107, 107); + font-size: 20px; + font-weight: bold; + text-decoration: underline dotted darkblue; +} + +.topnav a { + float: left; + background-color: rgb(146, 194, 149); + color: rgb(14, 0, 105); + text-align: center; + padding: 14px 16px; + font-size: 22px; + font-family: Georgia, 'Times New Roman', Times, serif; + font-weight: bold; + } + +.topnav a:hover { + background-color: #ddd; + color: black; + } + +h1 { + margin: 10px; +} + +a { + padding: 10px +} + +.right_list { + float: right; + margin: 10px; + background-color: blanchedalmond; + } \ No newline at end of file diff --git a/app/channels/application_cable/channel.rb b/app/channels/application_cable/channel.rb index d67269728..9aec23053 100644 --- a/app/channels/application_cable/channel.rb +++ b/app/channels/application_cable/channel.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ApplicationCable class Channel < ActionCable::Channel::Base end diff --git a/app/channels/application_cable/connection.rb b/app/channels/application_cable/connection.rb index 0ff5442f4..8d6c2a1bf 100644 --- a/app/channels/application_cable/connection.rb +++ b/app/channels/application_cable/connection.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ApplicationCable class Connection < ActionCable::Connection::Base end diff --git a/app/controllers/admin_petitions_controller.rb b/app/controllers/admin_petitions_controller.rb new file mode 100644 index 000000000..052b8e5ad --- /dev/null +++ b/app/controllers/admin_petitions_controller.rb @@ -0,0 +1,12 @@ +class AdminPetitionsController < ApplicationController + def show + @petition = Petition.find(params[:id]) + @associated_pet_petitions = @petition.associated_pet_petitions + if params[:approval] + @pet = Pet.find(params[:pet]) + @pet_petition = PetPetition.select(@pet.id, @petition.id) + @pet_petition.status = params[:approval] + @pet_petition.save + end + end +end diff --git a/app/controllers/admin_shelters_controller.rb b/app/controllers/admin_shelters_controller.rb new file mode 100644 index 000000000..0e77b87d5 --- /dev/null +++ b/app/controllers/admin_shelters_controller.rb @@ -0,0 +1,10 @@ +class AdminSheltersController < ApplicationController + def index + @shelters = Shelter.reverse_alphabet + @pending = Shelter.with_pending + end + + def show + @shelter = Shelter.find(params[:id]) + end +end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 91cee2e54..7969f6fc9 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,6 +1,7 @@ +# frozen_string_literal: true + class ApplicationController < ActionController::Base - def welcome - end + def welcome; end private diff --git a/app/controllers/pet_petitions_controller.rb b/app/controllers/pet_petitions_controller.rb new file mode 100644 index 000000000..e69de29bb diff --git a/app/controllers/petitions_controller.rb b/app/controllers/petitions_controller.rb new file mode 100644 index 000000000..ec1c77c66 --- /dev/null +++ b/app/controllers/petitions_controller.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +class PetitionsController < ApplicationController + def new; end + + def create + @petition = Petition.new(petition_params) + if @petition.save + redirect_to "/petitions/#{@petition.id}" + flash[:status] = 'In Progress' + else + flash[:incomplete] = ' Must Fill In All Fields' + redirect_to '/petitions/new' + end + end + + def show + @petition = Petition.find(params[:id]) + @pets = Pet.all + + @pets = Pet.search(params[:search]) if params[:search] + if params[:pet_id] + new_pet = Pet.find(params[:pet_id]) + @pet_petition = PetPetition.create(petition: @petition, pet: new_pet) + @associated_pets = PetPetition.associated_pets(@petition.id) + end + end + + def submit + @petition = Petition.find(params[:id]) + @petition.goodhome = params[:goodhome] + @petition.status = 'Pending' + @petition.save + redirect_to "/petitions/#{@petition.id}" + end + + private + + def petition_params + params.permit( + :name, + :street_address, + :city, + :state, + :zipcode + ) + end +end diff --git a/app/controllers/pets_controller.rb b/app/controllers/pets_controller.rb index 595602b8f..8922b142e 100644 --- a/app/controllers/pets_controller.rb +++ b/app/controllers/pets_controller.rb @@ -1,10 +1,9 @@ +# frozen_string_literal: true + class PetsController < ApplicationController def index - if params[:search].present? - @pets = Pet.search(params[:search]) - else - @pets = Pet.adoptable - end + @pets = Pet.adoptable + @pets = Pet.search(params[:search]) if params[:search] end def show diff --git a/app/controllers/shelters_controller.rb b/app/controllers/shelters_controller.rb index 036e44995..b2881911c 100644 --- a/app/controllers/shelters_controller.rb +++ b/app/controllers/shelters_controller.rb @@ -1,32 +1,33 @@ +# frozen_string_literal: true + class SheltersController < ApplicationController def index - if params[:sort].present? && params[:sort] == "pet_count" - @shelters = Shelter.order_by_number_of_pets - elsif params[:search].present? - @shelters = Shelter.search(params[:search]) - else - @shelters = Shelter.order_by_recently_created - end + @shelters = if params[:sort].present? && params[:sort] == 'pet_count' + Shelter.order_by_number_of_pets + elsif params[:search].present? + Shelter.search(params[:search]) + else + Shelter.order_by_recently_created + end end def pets @shelter = Shelter.find(params[:shelter_id]) - if params[:sort] == 'alphabetical' - @shelter_pets = @shelter.alphabetical_pets - elsif params[:age] - @shelter_pets = @shelter.shelter_pets_filtered_by_age(params[:age]) - else - @shelter_pets = @shelter.adoptable_pets - end + @shelter_pets = if params[:sort] == 'alphabetical' + @shelter.alphabetical_pets + elsif params[:age] + @shelter.shelter_pets_filtered_by_age(params[:age]) + else + @shelter.adoptable_pets + end end def show @shelter = Shelter.find(params[:id]) end - def new - end + def new; end def create shelter = Shelter.new(shelter_params) diff --git a/app/controllers/veterinarians_controller.rb b/app/controllers/veterinarians_controller.rb index 7aa023976..96e7e3c21 100644 --- a/app/controllers/veterinarians_controller.rb +++ b/app/controllers/veterinarians_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class VeterinariansController < ApplicationController def index @veterinarians = Veterinarian.on_call diff --git a/app/controllers/veterinary_offices_controller.rb b/app/controllers/veterinary_offices_controller.rb index e6d16c9e1..b26858284 100644 --- a/app/controllers/veterinary_offices_controller.rb +++ b/app/controllers/veterinary_offices_controller.rb @@ -1,32 +1,33 @@ +# frozen_string_literal: true + class VeterinaryOfficesController < ApplicationController def index - if params[:sort].present? && params[:sort]== "veterinarian_count" - @veterinary_offices = VeterinaryOffice.order_by_number_of_vets - else - @veterinary_offices = VeterinaryOffice.order_by_recently_created - end + @veterinary_offices = if params[:sort].present? && params[:sort] == 'veterinarian_count' + VeterinaryOffice.order_by_number_of_vets + else + VeterinaryOffice.order_by_recently_created + end end def veterinarians @veterinary_office = VeterinaryOffice.find(params[:veterinary_office_id]) - if params[:sort] == 'alphabetical' - @office_vets = @veterinary_office.alphabetical_vets - elsif params[:review_rating] - @office_vets = @veterinary_office.office_vets_filtered_by_rating( - params[:review_rating] - ) - else - @office_vets = @veterinary_office.on_call_vets - end + @office_vets = if params[:sort] == 'alphabetical' + @veterinary_office.alphabetical_vets + elsif params[:review_rating] + @veterinary_office.office_vets_filtered_by_rating( + params[:review_rating] + ) + else + @veterinary_office.on_call_vets + end end def show @veterinary_office = VeterinaryOffice.find(params[:id]) end - def new - end + def new; end def create vet_office = VeterinaryOffice.new(vet_office_params) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be7945..15b06f0f6 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + module ApplicationHelper end diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb index d394c3d10..bef395997 100644 --- a/app/jobs/application_job.rb +++ b/app/jobs/application_job.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ApplicationJob < ActiveJob::Base # Automatically retry jobs that encountered a deadlock # retry_on ActiveRecord::Deadlocked diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 286b2239d..d84cb6e71 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ApplicationMailer < ActionMailer::Base default from: 'from@example.com' layout 'mailer' diff --git a/app/models/application_record.rb b/app/models/application_record.rb index a5d389403..a65c2be93 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -1,7 +1,9 @@ +# frozen_string_literal: true + class ApplicationRecord < ActiveRecord::Base self.abstract_class = true def self.search(search_params) - where("name ILIKE ?", "%#{search_params}%") + where('name ILIKE ?', "%#{search_params}%") end end diff --git a/app/models/pet.rb b/app/models/pet.rb index 26dfb8e3f..6e0d798e5 100644 --- a/app/models/pet.rb +++ b/app/models/pet.rb @@ -1,7 +1,11 @@ +# frozen_string_literal: true + class Pet < ApplicationRecord validates :name, presence: true validates :age, presence: true, numericality: true belongs_to :shelter + has_many :pet_petitions, dependent: :destroy + has_many :petitions, through: :pet_petitions def shelter_name shelter.name diff --git a/app/models/pet_petition.rb b/app/models/pet_petition.rb new file mode 100644 index 000000000..c8a82deff --- /dev/null +++ b/app/models/pet_petition.rb @@ -0,0 +1,13 @@ +class PetPetition < ApplicationRecord + belongs_to :pet + belongs_to :petition + + def self.associated_pets(id) + pet_ids = where('petition_id = ?', id).pluck(:pet_id) + Pet.find(pet_ids) + end + + def self.select(pet_id, petition_id) + where('pet_id = ? AND petition_id = ?', pet_id, petition_id).first + end +end diff --git a/app/models/petition.rb b/app/models/petition.rb new file mode 100644 index 000000000..c4938b332 --- /dev/null +++ b/app/models/petition.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class Petition < ApplicationRecord + has_many :pet_petitions, dependent: :destroy + has_many :pets, through: :pet_petitions + validates :name, :street_address, :city, :state, :zipcode, presence: true + + def associated_pet_petitions + pet_petitions.all + end +end diff --git a/app/models/shelter.rb b/app/models/shelter.rb index 49dc25421..131df64e7 100644 --- a/app/models/shelter.rb +++ b/app/models/shelter.rb @@ -1,19 +1,32 @@ +# frozen_string_literal: true + class Shelter < ApplicationRecord validates :name, presence: true validates :rank, presence: true, numericality: true validates :city, presence: true has_many :pets, dependent: :destroy + has_many :pet_petitions, through: :pets + has_many :petitions, through: :pet_petitions def self.order_by_recently_created order(created_at: :desc) end def self.order_by_number_of_pets - select("shelters.*, count(pets.id) AS pets_count") - .joins("LEFT OUTER JOIN pets ON pets.shelter_id = shelters.id") - .group("shelters.id") - .order("pets_count DESC") + select('shelters.*, count(pets.id) AS pets_count') + .joins('LEFT OUTER JOIN pets ON pets.shelter_id = shelters.id') + .group('shelters.id') + .order('pets_count DESC') + end + + def self.reverse_alphabet + Shelter.find_by_sql('SELECT * FROM shelters ORDER BY name DESC') + end + + def self.with_pending + pending = joins(:pets).joins(:pet_petitions).joins(:petitions).where(petitions: { status: 'Pending' }).distinct + pending.order(:name) end def pet_count diff --git a/app/models/veterinarian.rb b/app/models/veterinarian.rb index 1112f3369..449ea08bd 100644 --- a/app/models/veterinarian.rb +++ b/app/models/veterinarian.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Veterinarian < ApplicationRecord validates :name, presence: true validates :review_rating, presence: true, numericality: true diff --git a/app/models/veterinary_office.rb b/app/models/veterinary_office.rb index d35f61a0c..e08c5b37d 100644 --- a/app/models/veterinary_office.rb +++ b/app/models/veterinary_office.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class VeterinaryOffice < ApplicationRecord validates :name, presence: true validates :max_patient_capacity, presence: true, numericality: true @@ -9,10 +11,10 @@ def self.order_by_recently_created end def self.order_by_number_of_vets - select("veterinary_offices.*, count(veterinarians.id) AS vets_count") - .joins("LEFT OUTER JOIN veterinarians ON veterinarians.veterinary_office_id = veterinary_offices.id") - .group("veterinary_offices.id") - .order("vets_count DESC") + select('veterinary_offices.*, count(veterinarians.id) AS vets_count') + .joins('LEFT OUTER JOIN veterinarians ON veterinarians.veterinary_office_id = veterinary_offices.id') + .group('veterinary_offices.id') + .order('vets_count DESC') end def vet_count diff --git a/app/views/admin_petitions/show.html.erb b/app/views/admin_petitions/show.html.erb new file mode 100644 index 000000000..96c4b738e --- /dev/null +++ b/app/views/admin_petitions/show.html.erb @@ -0,0 +1,15 @@ +
<%= " #{pet_petition.pet.name} -- #{pet_petition.pet.breed}: #{pet_petition.pet.age} years old." %>
+<%= "Application Status: #{pet_petition.status}" %>
+<%= "Is #{pet_petition.pet.name} adoptable? #{pet_petition.pet.adoptable} " %>
+ <% elsif pet_petition.status == 'Undecided' %> +<%= " #{pet_petition.pet.name} -- #{pet_petition.pet.breed}: #{pet_petition.pet.age} years old." %>
+<%= "Is #{pet_petition.pet.name} adoptable? #{pet_petition.pet.adoptable} " %>
+ <%= button_to "Approve #{@petition.name} for #{pet_petition.pet.name}", "/admin/petitions/#{@petition.id}", method: :get, params: { approval: 'Approved', pet: pet_petition.pet.id} %> + <%= button_to "Reject #{@petition.name} for #{pet_petition.pet.name}", "/admin/petitions/#{@petition.id}", method: :get, params: { approval: 'Rejected', pet: pet_petition.pet.id} %> + <% end %> +<% end %> \ No newline at end of file diff --git a/app/views/admin_shelters/index.html.erb b/app/views/admin_shelters/index.html.erb new file mode 100644 index 000000000..2d96a091c --- /dev/null +++ b/app/views/admin_shelters/index.html.erb @@ -0,0 +1,11 @@ +<%= link_to "Pets", "/pets" %>
-<%= link_to "Shelters", "/shelters" %>
-<%= link_to "Veterinarians", "/veterinarians" %>
-<%= link_to "Veterinary Offices", "/veterinary_offices" %>
-<%= message %>
+ <% end %> + + <%= yield %> + + +