Class: HomeController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- HomeController
- Includes:
- Pagy::Backend
- Defined in:
- app/controllers/home_controller.rb
Overview
This controller manage some index views for specific users type
-
before_action :home_redirect, except: [:user] -> #home_redirect
-
before_action :doctor_in!, only: [:report] -> ApplicationController#doctor_in!
Instance Method Summary collapse
-
#index ⇒ Object
GET / GET /home/index.
-
#list ⇒ Object
GET /home/index.
-
#meetings ⇒ Object
GET /home/meetings.
-
#report ⇒ Object
GET /home/report.
-
#reset_password ⇒ Object
PUT /home/reset_password.
-
#user ⇒ Object
GET /home/user.
Methods inherited from ApplicationController
#admin_in!, #doctor_in!, #powered_in!, #secretary_in!, #translate_errors
Instance Method Details
#index ⇒ Object
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 |
#list ⇒ Object
GET /home/index
List users with pagination and filers
-
preset @user with #users
-
set @pagy, @users for the User pagination
39 40 41 42 |
# File 'app/controllers/home_controller.rb', line 39 def list users flash.now[:success] = 'Caricamento completato' end |
#meetings ⇒ Object
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 |
#report ⇒ Object
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_password ⇒ Object
PUT /home/reset_password
Is function for change the user password
-
set @user as current_user
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 |
#user ⇒ Object
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
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 |