Skip to content

Commit

Permalink
Add Pagy
Browse files Browse the repository at this point in the history
  • Loading branch information
JuanVqz committed Feb 21, 2024
1 parent aee914f commit 21e2253
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 27 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ gem "bootsnap", require: false
gem "devise"
gem "haml-rails"
gem "jquery-rails"
gem "pagy"
gem "pg"
gem "puma"
gem "pundit"
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -169,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 @@ -340,6 +341,7 @@ DEPENDENCIES
jquery-rails
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
7 changes: 1 addition & 6 deletions app/controllers/appoinments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +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
@pagy, @appoinments = pagy(Appoinment.includes(:patient).per_doctor(current_user.id).search(params[:query]).recent)
end

def show
Expand Down
5 changes: 1 addition & 4 deletions app/controllers/hospitalizations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +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
@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/patients_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ class PatientsController < ApplicationController
before_action :set_appoinments, only: [:show, :appoinments]

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

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

# GET /referred_doctors
def index
@referred_doctors =
ReferredDoctor
.search(params[:query])
.by_doctor(current_user.id)
.order(:full_name)
@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: 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 21e2253

Please sign in to comment.