Skip to content

Commit

Permalink
Replace paginate gem (#436)
Browse files Browse the repository at this point in the history
* Remove Kaminari

* Add Pagy
  • Loading branch information
JuanVqz authored Feb 21, 2024
1 parent 91fda09 commit 1f37a96
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 69 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ gem "bootsnap", require: false
gem "devise"
gem "haml-rails"
gem "jquery-rails"
gem "kaminari"
gem "pagy"
gem "pg"
gem "puma"
gem "pundit"
Expand Down
15 changes: 2 additions & 13 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -129,18 +129,6 @@ GEM
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
json (2.6.3)
kaminari (1.2.2)
activesupport (>= 4.1.0)
kaminari-actionview (= 1.2.2)
kaminari-activerecord (= 1.2.2)
kaminari-core (= 1.2.2)
kaminari-actionview (1.2.2)
actionview
kaminari-core (= 1.2.2)
kaminari-activerecord (1.2.2)
activerecord
kaminari-core (= 1.2.2)
kaminari-core (1.2.2)
language_server-protocol (3.17.0.3)
lint_roller (1.1.0)
listen (3.8.0)
Expand Down Expand Up @@ -181,6 +169,7 @@ GEM
childprocess (>= 0.6.3, < 5)
iniparse (~> 1.4)
rexml (~> 3.2)
pagy (6.5.0)
parallel (1.23.0)
parser (3.2.2.3)
ast (~> 2.4.1)
Expand Down Expand Up @@ -350,9 +339,9 @@ DEPENDENCIES
ffaker
haml-rails
jquery-rails
kaminari
listen
overcommit
pagy
pg
puma
pundit
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
class ApplicationController < ActionController::Base
include Pagy::Backend
include Pundit::Authorization
rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized

layout :layout_by_resource

before_action :scope_current_hospital
Expand Down
8 changes: 1 addition & 7 deletions app/controllers/appoinments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@ class AppoinmentsController < ApplicationController
before_action :set_appoinment, only: [:show, :edit, :update, :destroy]

def index
@appoinments =
Appoinment
.includes(:patient)
.per_doctor(current_user.id)
.search(params[:query])
.recent
.page(params[:page])
@pagy, @appoinments = pagy(Appoinment.includes(:patient).per_doctor(current_user.id).search(params[:query]).recent)
end

def show
Expand Down
6 changes: 1 addition & 5 deletions app/controllers/hospitalizations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ class HospitalizationsController < ApplicationController
before_action :set_hospitalization, only: [:show, :edit, :update, :destroy]

def index
@hospitalizations = Hospitalization.includes(:patient)
.per_doctor(current_user.id)
.search(params[:query])
.recent
.page(params[:page])
@pagy, @hospitalizations = pagy(Hospitalization.includes(:patient).per_doctor(current_user.id).search(params[:query]).recent)
end

def show
Expand Down
6 changes: 1 addition & 5 deletions app/controllers/patient_referrals_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ class PatientReferralsController < ApplicationController

# GET /patient_referrals
def index
@patient_referrals =
current_hospital
.patient_referrals
.order(created_at: :desc)
.page(params[:page])
@pagy, @patient_referrals = pagy(current_hospital.patient_referrals.order(created_at: :desc))
end

# GET /patient_referrals/1
Expand Down
15 changes: 3 additions & 12 deletions app/controllers/patients_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@ class PatientsController < ApplicationController
before_action :set_appoinments, only: [:show, :appoinments]

def index
@patients =
current_hospital
.patients
.recent
.search(params[:query])
.page(params[:page])
@pagy, @patients = pagy(current_hospital.patients.recent.search(params[:query]))
end

def show
Expand Down Expand Up @@ -71,15 +66,11 @@ def set_patient
end

def set_appoinments
@appoinments = Appoinment.by_doctor_and_patient(current_user.id, @patient.id)
.recent
.page(params[:page])
@pagy, @appoinments = pagy(Appoinment.by_doctor_and_patient(current_user.id, @patient.id).recent)
end

def set_hospitalizations
@hospitalizations = Hospitalization.by_doctor_and_patient(current_user.id, @patient.id)
.recent
.page(params[:page])
@pagy, @hospitalizations = pagy(Hospitalization.by_doctor_and_patient(current_user.id, @patient.id).recent)
end

def patient_params
Expand Down
7 changes: 1 addition & 6 deletions app/controllers/referred_doctors_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ class ReferredDoctorsController < ApplicationController

# GET /referred_doctors
def index
@referred_doctors =
ReferredDoctor
.search(params[:query])
.by_doctor(current_user.id)
.order(:full_name)
.page(params[:page])
@pagy, @referred_doctors = pagy(ReferredDoctor.search(params[:query]).by_doctor(current_user.id).order(:full_name))
end

# GET /referred_doctors/1
Expand Down
2 changes: 2 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module ApplicationHelper
include Pagy::Frontend

def sexos_for_select
["Femenino", "Masculino"]
end
Expand Down
13 changes: 0 additions & 13 deletions config/initializers/kaminari_config.rb

This file was deleted.

13 changes: 6 additions & 7 deletions config/locales/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,9 @@ es-MX:
# invalid: "Email o contraseña incorrecto"
# logged_in: "¡Has iniciado sesión!"
# logged_out: "¡Has cerrado sesión!"
# views:
# pagination:
# first: "&laquo; Primera"
# last: "Última &raquo;"
# previous: "&lsaquo; Anterior"
# next: "Siguiente &rsaquo;"
# truncate: "&hellip;"
pagy:
nav:
prev: "&lsaquo; Anterior"
next: "Siguiente &rsaquo;"
info:
single_page: "Mostrando <b>%{count}</b> %{item_name}"

0 comments on commit 1f37a96

Please sign in to comment.