Skip to content

Commit

Permalink
Merge branch 'main' into portabilis-patch-2024-09-24
Browse files Browse the repository at this point in the history
  • Loading branch information
AnaPerola committed Sep 24, 2024
2 parents 4f39a24 + cbd3c32 commit 29ca7ff
Show file tree
Hide file tree
Showing 48 changed files with 1,416 additions and 548 deletions.
3 changes: 3 additions & 0 deletions app/assets/javascripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ $(function(){

$('.remote .pagination a').on('click',
function() {
var onPageChange = new CustomEvent('onPageChange');
document.dispatchEvent(onPageChange);

$.getScript(this.href);
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ $(function () {

var $unity = $('#discipline_teaching_plan_teaching_plan_attributes_unity_id');
var $grade = $('#discipline_teaching_plan_teaching_plan_attributes_grade_id');
var $year =$('#discipline_teaching_plan_teaching_plan_attributes_year');
var $discipline = $('#discipline_teaching_plan_discipline_id');
var $schoolTermType = $('#discipline_teaching_plan_teaching_plan_attributes_school_term_type_id');
var $schoolTermContainer = $('#school-term-container');
Expand All @@ -16,6 +17,7 @@ $(function () {
function fetchDisciplines() {
var unity_id = $unity.select2('val');
var grade_id = $grade.select2('val');
var year = $year.val();

$discipline.select2('val', '');
$discipline.select2({ data: [] });
Expand All @@ -25,6 +27,7 @@ $(function () {
url: Routes.search_by_grade_and_unity_disciplines_pt_br_path({
by_unity_id: unity_id,
by_grade: grade_id,
year: year,
format: 'json'
}),
success: handleFetchDisciplinesSuccess,
Expand Down
13 changes: 12 additions & 1 deletion app/assets/javascripts/views/observation_record_report/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ $(function () {
return { id: discipline.table.id, name: discipline.table.name, text: discipline.table.text };
});

selectedDisciplines.unshift({ id: 'all', name: '<option>Todas</option>', text: 'Todas' });
if (selectedDisciplines.length > 1) {
selectedDisciplines.unshift({ id: 'all', name: '<option>Todas</option>', text: 'Todas' });
}

$discipline.select2({ data: selectedDisciplines });
}
Expand All @@ -95,4 +97,13 @@ $(function () {
$classroom.val('').select2({ data: [] });
$discipline.val('').select2({ data: [] });
}

$('form').submit(function () {
var tempoEspera = 2000;

// Define um timeout para habilitar o botão após o tempo de espera
setTimeout(function () {
$('#btn-submit').prop('disabled', false);
}, tempoEspera);
});
});
28 changes: 21 additions & 7 deletions app/assets/javascripts/views/users/index.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,39 @@
$(function() {
var selected = [];

$(document).on('click', 'ul.pagination > li > a', function(e) {
var onPageChange = new CustomEvent('onPageChange');
document.dispatchEvent(onPageChange);
});

document.addEventListener("onPageChange", function (e) {
$("#select-all").prop("checked", false)
})

$('body').on('change', '.selected_users', function(event) {
selected = [];
$('.selected_users:checked').each(function() {
selected.push($(this).attr('value'));
});
selected = $('#export_selected_selected_users').val().split(",");

if ($(this).prop('checked')) {
selected.push($(this).attr('value'))
} else {
selected.pop($(this).attr('value'))
}

$('#export_selected_selected_users').val(selected);
});

$('body').on('change', '#select-all', function(e) {
selected = [];
selected = $('#export_selected_selected_users').val().split(",");

$('.selected_users:checked').each(function() {
if (!_.contains(selected, $(this).attr('value'))) {
if (!_.includes(selected, $(this).attr('value'))) {
selected.push($(this).attr('value'));
}
$('#export_selected_selected_users').val(selected);
});

$('.selected_users').each(function() {
if (!_.contains(selected, $(this).attr('value'))) {
if (!_.includes(selected, $(this).attr('value'))) {
selected.pop($(this).attr('value'));
}
$('#export_selected_selected_users').val(selected);
Expand Down
29 changes: 29 additions & 0 deletions app/controllers/api/v2/list_attendances_by_classroom_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module Api
module V2
class ListAttendancesByClassroomController < Api::V2::BaseController
respond_to :json

def index
required_params = %i[classrooms start_at end_at year]
missing_params = validate_required_params(required_params)

return if missing_params

classrooms_api_code = params[:classrooms]
start_at = params[:start_at]
end_at = params[:end_at]
year = params[:year]

render json: ClassroomAttendanceService.call(classrooms_api_code, start_at, end_at, year)
end

def validate_required_params(required_params)
missing_params = required_params.select { |param| params[param].blank? }

return false unless missing_params.any?

render json: { error: "Os seguintes parâmetros são obrigatórios: #{missing_params.join(', ')}" }, status: :unprocessable_entity
end
end
end
end
30 changes: 30 additions & 0 deletions app/controllers/api/v2/student_classroom_attendances_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module Api
module V2
class StudentClassroomAttendancesController < Api::V2::BaseController
respond_to :json
def index
required_params = %i[classroom_id start_at end_at year student_ids]
missing_params = validate_required_params(required_params)

return if missing_params
classroom_api_code = params[:classroom_id]
start_at = params[:start_at]
end_at = params[:end_at]
year = params[:year]
students_api_code = params[:student_ids]

render json: ListStudentAttendancesByClassroomService.call(
classroom_api_code, start_at, end_at, year, students_api_code
)
end

def validate_required_params(required_params)
missing_params = required_params.select { |param| params[param].blank? }

return false unless missing_params.any?

render json: { error: "Os seguintes parâmetros são obrigatórios: #{missing_params.join(', ')}" }, status: :unprocessable_entity
end
end
end
end
5 changes: 4 additions & 1 deletion app/controllers/api/v2/teaching_plans_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ class TeachingPlansController < Api::V2::BaseController
def index
return unless params[:teacher_id]

@unities = Unity.by_teacher(params[:teacher_id]).ordered.uniq
@unities = Unity.by_teacher(params[:teacher_id]).ordered.distinct
@unities = @unities.select do |unity|
TeachingPlan.by_unity_id(unity.id).exists?
end
@teacher_id = params[:teacher_id]
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def teacher_discipline_score_type_by_exam_rule(exam_rule, classroom = nil, disci
classroom: classroom,
teacher: current_teacher,
discipline: discipline
).score_type
)&.score_type
end

def set_user_current
Expand Down
52 changes: 38 additions & 14 deletions app/controllers/avaliation_recovery_diary_records_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def index

authorize @avaliation_recovery_diary_records

@school_calendar_steps = current_school_calendar.steps
@school_calendar_steps = steps_fetcher.steps
end

def new
Expand All @@ -25,7 +25,7 @@ def new
@avaliation_recovery_diary_record.recovery_diary_record.discipline = current_user_discipline

@unities = fetch_unities
@school_calendar_steps = current_school_calendar.steps
@school_calendar_steps = steps_fetcher.steps

fetch_disciplines_by_classroom

Expand Down Expand Up @@ -74,7 +74,7 @@ def edit

@student_notes = fetch_student_notes
@unities = fetch_unities
@school_calendar_steps = current_school_calendar.steps
@school_calendar_steps = steps_fetcher.steps
@avaliations = fetch_avaliations
reload_students_list

Expand Down Expand Up @@ -128,10 +128,12 @@ def destroy
def fetch_avaliation_recovery_diary_records_by_user
@avaliation_recovery_diary_records =
apply_scopes(AvaliationRecoveryDiaryRecord)
.select('DISTINCT ON (avaliation_recovery_diary_records.id, recovery_diary_records.recorded_at) avaliation_recovery_diary_records.*')
.includes(:avaliation, recovery_diary_record: [:unity, :classroom, :discipline])
.by_unity_id(current_unity.id)
.by_classroom_id(@classrooms.map(&:id))
.by_discipline_id(@disciplines.map(&:id))
.by_teacher_id(current_teacher.id)
.ordered
end

Expand Down Expand Up @@ -241,7 +243,9 @@ def reload_students_list
note_student = recovery_student || recovery_diary_record.students.build(student_id: student.id, student: student)
note_student.dependence = student_has_dependence?(student_enrollment, @avaliation_recovery_diary_record.recovery_diary_record.discipline)
note_student.active = student_active_on_date?(student_enrollment)
note_student.exempted_from_discipline = student_exempted_from_discipline?(student_enrollment, recovery_diary_record, @avaliation_recovery_diary_record)
note_student.exempted_from_discipline = student_exempted_from_discipline?(
student_enrollment, recovery_diary_record, @avaliation_recovery_diary_record
)

@students << note_student
end
Expand Down Expand Up @@ -287,11 +291,23 @@ def student_exempted_from_discipline?(student_enrollment, recovery_diary_record,

discipline_id = recovery_diary_record.discipline.id
test_date = avaliation_recovery_diary_record.avaliation.test_date
step_number = avaliation_recovery_diary_record.avaliation.school_calendar.step(test_date).to_number

student_enrollment.exempted_disciplines.by_discipline(discipline_id)
.by_step_number(step_number)
.any?
step_number = fetch_step_number(avaliation_recovery_diary_record, recovery_diary_record.classroom_id, test_date)

student_enrollment.exempted_disciplines
.by_discipline(discipline_id)
.by_step_number(step_number)
.any?
end

def fetch_step_number(avaliation_recovery_diary_record, classroom_id, date)
school_calendar = avaliation_recovery_diary_record.avaliation.school_calendar

school_calendar_classroom = school_calendar.classrooms.find_by_classroom_id(classroom_id)

return school_calendar_classroom.classroom_step(date) if school_calendar_classroom.present?

school_calendar.step(date).to_number
end

def any_student_exempted_from_discipline?
Expand All @@ -317,12 +333,10 @@ def list_students_by_active(resource_params_hash)
end

def set_options_by_user
if current_user.current_role_is_admin_or_employee?
@classrooms ||= fetch_classrooms
@disciplines ||= fetch_disciplines
else
fetch_linked_by_teacher
end
return fetch_linked_by_teacher unless current_user.current_role_is_admin_or_employee?

@classrooms ||= fetch_classrooms
@disciplines ||= fetch_disciplines
end

def fetch_linked_by_teacher
Expand All @@ -337,4 +351,14 @@ def fetch_disciplines_by_classroom
classroom = @avaliation_recovery_diary_record.recovery_diary_record.classroom
@disciplines = @disciplines.by_classroom(classroom).not_descriptor
end

def steps_fetcher
classroom = if @avaliation_recovery_diary_record.present?
@avaliation_recovery_diary_record.recovery_diary_record.classroom
else
current_user_classroom
end

@steps_fetcher ||= StepsFetcher.new(classroom)
end
end
8 changes: 7 additions & 1 deletion app/controllers/daily_note_students_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,13 @@ def fetch_student_enrollments(classroom, avaliation, discipline, date)
def student_exempted_from_discipline?(student_enrollment, daily_note)
discipline_id = daily_note.discipline.id
test_date = daily_note.avaliation.test_date
step_number = daily_note.avaliation.school_calendar.step(test_date).to_number
classroom = daily_note.classroom

step_number = if classroom.calendar.present?
classroom.calendar.classroom_step(test_date).to_number
else
daily_note.avaliation.school_calendar.step(test_date).to_number
end

student_enrollment.exempted_disciplines.by_discipline(discipline_id)
.by_step_number(step_number)
Expand Down
Loading

0 comments on commit 29ca7ff

Please sign in to comment.