Commit 5a3ba82e authored by Bruno Freitas Tissei's avatar Bruno Freitas Tissei

Add possibility to specify page number for dependants in schedule history

Signed-off-by: Bruno Freitas Tissei's avatarBruno Freitas Tissei <bft15@inf.ufpr.br>
parent 12743b40
......@@ -7,8 +7,13 @@ module Api::V1
# GET /schedules
def index
if not params[:history].nil?
@schedules = Schedule.citizen_history(current_user[0].id,
params[:q], params[:page])
@schedules = Schedule.citizen_history(
current_user[0].id,
params[:q],
params[:page],
params[:dependant_citizen_id],
params[:dependant_page]
)
render json: @schedules
return
......@@ -107,6 +112,14 @@ module Api::V1
errors: [" Schedule #{params[:id]} does not exist."]
}, status: 404
else
# Check if schedule's situation is available
if @schedule.situation.id != 1
render json: {
errors: ["This schedule is not available."]
}, status: 409
return
end
# schedule_confirm_params contains information provided in the last step
# of scheduling process (note and remider_time)
update_params = schedule_confirm_params
......@@ -130,7 +143,7 @@ module Api::V1
end
# NEVER USED (TODO: Check if is save to remove)
# NEVER USED (TODO: Check if is save to remove - definitely not safe to leave it there)
# POST /schedules
def create
@schedule = Schedule.new(schedule_params)
......
......@@ -7,7 +7,7 @@ module Searchable
# @params npage [String] number of page to be returned
# @return [Array] result of search given the parameters and page
def self.search(params, npage)
return self.ransack(params).result.page(npage).per(25)
return self.ransack(params).result.page(npage).per(2)
end
# @params params [ActionController::Parameters] Unfiltered parameters
......
......@@ -144,9 +144,11 @@ class Schedule < ApplicationRecord
# @params id [Integer] Citizen the schedules are being returned for
# @params params [ActionController::Parameters] Parameters for searching
# @params npage [String] number of page to be returned
# @params dep_page_id [Integer] id of the dependant where the page is being specified
# @params dep_page_num [Integer] page number for the dep_page_id's schedules
# @return [Json] every schedule for each dependant from a citizen and the
# citizen himself for showing in the schedule history screen
def self.citizen_history(id, params, npage)
def self.citizen_history(id, params, npage, dep_page_id, dep_page_num)
# Citizen's dependants
citizens = Citizen.where(responsible_id: id).pluck(:id, :name)
......@@ -170,7 +172,12 @@ class Schedule < ApplicationRecord
citizens.each do |i,name|
schedules = Schedule.where(citizen_id: i)
sectors = get_sectors_response(schedules.where(situation_id: 2))
schedules = schedules.filter(params, npage, "citizen")
if i == dep_page_id.to_i and not dep_page_num.nil?
schedules = schedules.filter(params, dep_page_num, "citizen")
else
schedules = schedules.filter(params, 1, "citizen")
end
entry = Hash.new.as_json
......
......@@ -177,8 +177,6 @@ class Shift < ApplicationRecord
start_t = end_t
end
#return false
# Bulk insert for schedules
Schedule.transaction do
columns = [:shift_id, :situation_id, :service_place_id,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment