Class: HomeController

Inherits:
ApplicationController show all
Includes:
Pagy::Backend
Defined in:
app/controllers/home_controller.rb

Overview

This controller manage some index views for specific users type

Instance Method Summary collapse

Methods inherited from ApplicationController

#admin_in!, #doctor_in!, #powered_in!, #secretary_in!, #translate_errors

Instance Method Details

#indexObject

GET / GET /home/index

Is application’s root index. The access is granted onl for doctor, secretary an admin, other user are redirect to #user (GET /home/user)

  • preset @users with all User

Returns:

  • (Object)

    render /home/index



20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/home_controller.rb', line 20

def index
  @riepilogo ||= 'expired'
  @expire = ''
  @users = User.all.unsystem.left_outer_joins(:categories).distinct
  @start_at = Time.zone.today.at_beginning_of_month
  @stop_at = Time.zone.today.end_of_month
  @next_start_at = Time.zone.today.at_beginning_of_month.next_month
  @next_stop_at = Time.zone.today.end_of_month.next_month
  @next_2_start_at = (Time.zone.today + 2.months).at_beginning_of_month
  @next_2_stop_at = (Time.zone.today + 2.months).end_of_month.next_month
end

#listObject

GET /home/index

List users with pagination and filers

  • preset @user with #users

  • set @pagy, @users for the User pagination

Returns:

  • (Object)

    render partial /home/_index



39
40
41
42
# File 'app/controllers/home_controller.rb', line 39

def list
  users
  flash.now[:success] = 'Caricamento completato'
end

#meetingsObject

GET /home/meetings

List meetings with pagination

  • set @meetings searching the future Meeting

Returns:

  • (Object)

    render partial /home/_meetings



50
51
52
53
# File 'app/controllers/home_controller.rb', line 50

def meetings
  @meetings = Event.future.where(id: Meeting.waiting.distinct(:event_id).pluck(:event_id))
  # render partial: 'meetings', collection: @meetings, as: :event
end

#reportObject

GET /home/report

Is an excel report available only for doctors

  • set @year with params[:year]

  • set @range as 0

  • set @city with params[:city]

  • set @start_at, @stop_at with #get_dates_range

  • set @users from the history

Returns:

  • (Object)

    render /home/report



78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'app/controllers/home_controller.rb', line 78

def report
  return if params[:report].blank?

  @year = params[:report][:year].presence || Time.zone.today.year
  @range = 0
  @city = params[:report][:city].presence || :roma
  get_dates_range(@range, @year)
  @users = History.unscoped.joins(:user, :risk).where('users.city=?', User.cities[@city])
  @filename = @city.blank? ? 'report-medicina.xlsx' : "#{@city}-#{@year}.xlsx"
  respond_to do |format|
    format.js
    format.xlsx
  end
end

#reset_passwordObject

PUT /home/reset_password

Is function for change the user password

  • set @user as current_user

Returns:

  • (Object)

    render /home/new_password



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'app/controllers/home_controller.rb', line 98

def reset_password
  status = :ok
  @user = current_user
  if user_params[:password] != user_params[:password_confirmation]
    @user.errors.add(:password, 'Not valid')
    @user.errors.add(:current_password, 'Not valid')
  else
    @user.password = user_params[:password]
    if @user.save
      flash.now[:success] = 'Modifica avvenuta con successo'
    else
      status = 500
      flash.now[:error] = 'Si è verificato un errore durante la modifica'
    end
  end
  redirect_to new_user_session_path
end

#userObject

GET /home/user

Is standard user home page, show the future events and the user status for each category risk

  • set @user with current_user

  • set @analisys with the future analisy events

  • set @visits with the future visit events

Returns:

  • (Object)

    render /home/user



62
63
64
65
66
67
# File 'app/controllers/home_controller.rb', line 62

def user
  @user = current_user
  @analisys = @user.events.analisys.future
  @visits = @user.events.visit.future
  respond_to :html, :json
end