Skip to content

Commit

Permalink
Merge pull request #175 from portabilis/portabilis-patch-2024-12-24
Browse files Browse the repository at this point in the history
Portabilis patch 24/12/2024
  • Loading branch information
AnaPerola authored Dec 27, 2024
2 parents ea73fa8 + 1a4f137 commit 073d7c6
Show file tree
Hide file tree
Showing 20 changed files with 607 additions and 459 deletions.
138 changes: 77 additions & 61 deletions app/assets/javascripts/views/descriptive_exams/form.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
$(function () {
'use strict';

var $opinionType = $('#descriptive_exam_opinion_type'),
$discipline = $('#descriptive_exam_discipline_id'),
$step = $('#descriptive_exam_step_id'),
$classroom_id = $('#descriptive_exam_classroom_id'),
$disciplineContainer = $('[data-descriptive-exam-discipline-container]'),
$stepContainer = $('[data-descriptive-exam-step-container]'),
$(function() {
"use strict";

var $opinionType = $("#descriptive_exam_opinion_type"),
$discipline = $("#descriptive_exam_discipline_id"),
$step = $("#descriptive_exam_step_id"),
$classroom_id = $("#descriptive_exam_classroom_id"),
$disciplineContainer = $("[data-descriptive-exam-discipline-container]"),
$stepContainer = $("[data-descriptive-exam-step-container]"),
should_clear_discipline = true,
should_clear_step = true,
discipline_id = $discipline.val(),
view_btn = $('#view-btn');
view_btn = $("#view-btn");

if ($opinionType.data('elements').length === 2) {
$opinionType.attr('readonly', true)
if ($opinionType.data("elements").length === 2) {
$opinionType.attr("readonly", true);
}

$classroom_id.on('change', async function () {
$classroom_id.on("change", async function() {
await getOpinionType();
await getStep();
await getDisciplines();
setFields()
})
await setFields();
});

async function getOpinionType() {
let classroom_id = $('#descriptive_exam_classroom_id').select2('val');
let classroom_id = $("#descriptive_exam_classroom_id").select2("val");

if (!_.isEmpty(classroom_id)) {
return $.ajax({
url: Routes.opinion_types_descriptive_exams_pt_br_path({
classroom_id: classroom_id,
format: 'json'
format: "json"
}),
success: handleFetchOpinionTypeByClassroomSuccess,
error: handleFetchOpinionTypeByClassroomError
Expand All @@ -40,150 +39,167 @@ $(function () {

function handleFetchOpinionTypeByClassroomSuccess(data) {
var opinion_type = $("#descriptive_exam_opinion_type");
var first_opinion = data[0]['table']
var first_opinion = data[0]["table"];

opinion_type.select2('data', first_opinion);
opinion_type.select2("data", first_opinion);
}

function handleFetchOpinionTypeByClassroomError() {
flashMessages.error('Ocorreu um erro ao buscar o tipo de avaliação da turma.');
flashMessages.error(
"Ocorreu um erro ao buscar o tipo de avaliação da turma."
);
}

async function getStep() {
let classroom_id = $('#descriptive_exam_classroom_id').select2('val');
let classroom_id = $("#descriptive_exam_classroom_id").select2("val");
$step.select2({ data: [] });

if (!_.isEmpty(classroom_id)) {
return $.ajax({
url: Routes.find_step_number_by_classroom_descriptive_exams_pt_br_path({
classroom_id: classroom_id,
format: 'json'
format: "json"
}),
success: handleFetchStepByClassroomSuccess,
error: handleFetchStepByClassroomError,
error: handleFetchStepByClassroomError
});
}
}

function handleFetchStepByClassroomSuccess(data) {
if (data) {
let selectedSteps = data.map(function (step) {
return { id: step['id'], text: step['description'] };
let selectedSteps = data.map(function(step) {
return { id: step["id"], text: step["description"] };
});

$step.select2({ data: selectedSteps });
// Define a primeira opção como selecionada por padrão
$step.val(selectedSteps[0].id).trigger('change');
$step.val(selectedSteps[0].id).trigger("change");
}
}

function handleFetchStepByClassroomError() {
flashMessages.error('Ocorreu um erro ao buscar a etapa da turma.');
flashMessages.error("Ocorreu um erro ao buscar a etapa da turma.");
}

async function getDisciplines() {
let classroom_id = $('#descriptive_exam_classroom_id').select2('val');
let classroom_id = $("#descriptive_exam_classroom_id").select2("val");

if (!_.isEmpty($classroom_id.val())) {
$.ajax({
url: Routes.by_classroom_disciplines_pt_br_path({ classroom_id: classroom_id, format: 'json' }),
success: handleFetchDisciplinesSuccess,
error: handleFetchDisciplinesError
});
try {
const data = await $.ajax({
url: Routes.by_classroom_disciplines_pt_br_path({
classroom_id: classroom_id,
format: "json"
})
});
handleFetchDisciplinesSuccess(data);
} catch (error) {
handleFetchDisciplinesError();
}
}
};
}

function handleFetchDisciplinesSuccess(data) {
if (data.disciplines.length == 0) {
blockFields();
flashMessages.error('Não existem disciplinas para a turma selecionada.');
flashMessages.error("Não existem disciplinas para a turma selecionada.");
return;
} else {
var selectedDisciplines = data.disciplines.map(function (discipline) {
return { id: discipline.table.id, name: discipline.table.name, text: discipline.table.text };
var selectedDisciplines = data.disciplines.map(function(discipline) {
return {
id: discipline.table.id,
name: discipline.table.name,
text: discipline.table.text
};
});

$discipline.select2({ data: selectedDisciplines });
$discipline.val(selectedDisciplines[0].id).trigger('change');
$discipline.val(selectedDisciplines[0].id).trigger("change");
}
};
}

function handleFetchDisciplinesError() {
flashMessages.error('Ocorreu um erro ao buscar as disciplinas da turma selecionada.');
};
flashMessages.error(
"Ocorreu um erro ao buscar as disciplinas da turma selecionada."
);
}

function setFields() {
async function setFields() {
var opinionType = $opinionType.val();
should_clear_discipline = true;
should_clear_step = true;

$disciplineContainer.addClass('hidden');
$stepContainer.addClass('hidden');
$disciplineContainer.addClass("hidden");
$stepContainer.addClass("hidden");

if ($.inArray(opinionType, ["2", "3", "5", "6"]) >= 0) {
if ($.inArray(opinionType, ["2", "5"]) >= 0) {
$disciplineContainer.removeClass('hidden');
$disciplineContainer.removeClass("hidden");
should_clear_discipline = false;
}

if ($.inArray(opinionType, ["2", "3"]) >= 0) {
$stepContainer.removeClass('hidden');
$stepContainer.removeClass("hidden");
should_clear_step = false;
}
} else {
$opinionType.val('');
$step.select2('val', '');
$opinionType.val("");
$step.select2("val", "");
}

if (should_clear_discipline) {
$discipline.val('');
$discipline.val(null).trigger("change");
} else {
$discipline.val(discipline_id);
}

if (should_clear_step) {
$step.val('');
$step.val("");
}
}

function validateExistingExams() {
let step_id = $step.val(),
discipline_id = $discipline.val(),
classroom_id = $classroom_id.val(),
opinion_type = $('#descriptive_exam_opinion_type').val();
opinion_type = $("#descriptive_exam_opinion_type").val();

$.ajax({
url: Routes.find_descriptive_exams_pt_br_path({
discipline_id: discipline_id,
classroom_id: classroom_id,
step_id: step_id,
opinion_type: opinion_type,
format: 'json'
format: "json"
}),
success: function (descriptive_exam_id) {
success: function(descriptive_exam_id) {
if (descriptive_exam_id === null || !$.isNumeric(descriptive_exam_id)) {
view_btn.addClass('disabled');
view_btn.attr('href', '');
view_btn.addClass("disabled");
view_btn.attr("href", "");

return;
}

view_btn.removeClass('disabled');
view_btn.attr('href', Routes.descriptive_exam_pt_br_path(descriptive_exam_id))
view_btn.removeClass("disabled");
view_btn.attr(
"href",
Routes.descriptive_exam_pt_br_path(descriptive_exam_id)
);
}
});
}

$opinionType.on('change', function () {
$opinionType.on("change", function() {
setFields();
validateExistingExams();
});

setFields();

$step.on('change', function () {
$step.on("change", function() {
validateExistingExams();
})
});

validateExistingExams();
});
14 changes: 0 additions & 14 deletions app/assets/javascripts/views/pedagogical_trackings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,27 +162,13 @@ $('#search_end_date').on('change', function(e){
});

var unity_id = $('#unity_id').val();
var start_date = $('#start_date').val();
var end_date = $('#end_date').val();
var step_start_date = $('#step_start_date').val();
var step_end_date = $('#step_end_date').val();

if (unity_id) {
$('#search_unity_id').val(unity_id);
}

if (start_date) {
$('#search_start_date').val(start_date);
} else {
$('#search_start_date').attr('placeholder', step_start_date)
}

if (end_date) {
$('#search_end_date').val(end_date);
} else {
$('#search_end_date').attr('placeholder', step_end_date)
}

if (_.isEmpty($('#filter_frequency_operator').val())){
$('#filter_frequency_percentage').attr('readonly', true).val('');
}
Expand Down
10 changes: 7 additions & 3 deletions app/controllers/daily_frequencies_in_batchs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,17 @@ def view_data
student = student_enrollment[:student]
student_ids << student.id
type_of_teaching = student_enrollment[:student_enrollment_classroom].type_of_teaching
left_at = student_enrollment[:student_enrollment_classroom].left_at
joined_at = student_enrollment[:student_enrollment_classroom].joined_at

next if student.blank?

@students_list << student
@students << {
student: student,
type_of_teaching: type_of_teaching
type_of_teaching: type_of_teaching,
left_at: left_at,
joined_at: joined_at
}
end

Expand All @@ -254,8 +258,8 @@ def view_data

dependences = student_has_dependence(student_enrollments_ids, dates)
inactives_on_date = students_inactive_on_range(enrollment_classrooms.map{|i|
i[:student_enrollment_classroom]
}, dates)
i[:student_enrollment_classroom]
}, dates)
exempteds_from_discipline = student_exempted_from_discipline_in_range(student_enrollments_ids, dates)
active_searchs = ActiveSearch.new.in_active_search_in_range(student_enrollments_ids, dates)

Expand Down
10 changes: 1 addition & 9 deletions app/controllers/daily_notes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def reload_students_list
set_enrollment_classrooms.each do |enrollment_classroom|
student = enrollment_classroom[:student]
student_enrollment_id = enrollment_classroom[:student_enrollment].id
note_student = create_or_select_daily_note_student(student)
note_student = @daily_note.students.find_or_initialize_by(student_id: student.id)
note_student.active = @active.include?(enrollment_classroom[:student_enrollment_classroom].id)
note_student.dependence = @dependencies[student_enrollment_id] ? true : false
note_student.exempted = @exempted_from_avaliation.map(&:student_id).include?(student.id) ? true : false
Expand Down Expand Up @@ -293,12 +293,4 @@ def students_exempted_from_avaliations(avaliation_id, student_ids)
students_exempt_from_avaliation[exempt.student_id] << exempt.avaliation_id
end
end

def create_or_select_daily_note_student(student)
if action_name.eql?('edit') || action_name.eql?('create')
@daily_note.students.find_or_initialize_by(student_id: student.id)
else
@daily_note.students.select{ |dns| dns.student_id.eql?(student.id) }.first
end
end
end
Loading

0 comments on commit 073d7c6

Please sign in to comment.