Skip to content

Commit

Permalink
Merge pull request #109 from portabilis/portabilis-patch-2022-07-10
Browse files Browse the repository at this point in the history
[1.4] Portabilis patch 10/07/2022
  • Loading branch information
edersoares authored Jul 14, 2022
2 parents 4d39b5b + 2f66060 commit 5666148
Show file tree
Hide file tree
Showing 125 changed files with 2,263 additions and 387 deletions.
5 changes: 3 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ gem 'pg_query', '1.2.0'
gem 'postgres-copy', '1.0.0'
gem 'prawn', '2.1.1', git: 'https://github.com/portabilis/prawn.git', branch: 'master', tag: 'v2.1.1'
gem 'prawn-table', '0.2.2'
gem 'puma', '5.2.2'
gem 'puma', '5.6.4'
gem 'pundit', '0.3.0'
gem 'rack-cors', '>= 1.0.4 ', require: 'rack/cors'
gem 'rack-protection', '1.5.5'
Expand All @@ -52,7 +52,8 @@ gem 'responders', '2.1.0'
gem 'rest-client', '2.0.2'
gem 'route_translator', git: 'https://github.com/enriclluelles/route_translator.git', tag: 'v4.1.0'
gem 'rubyzip', '>= 1.3.0', require: 'zip'
gem 'sidekiq', '5.0.3'
gem 'sd_notify', '0.1.1'
gem 'sidekiq', '5.2.5'
gem 'sidekiq-unique-jobs', '6.0.22'
gem 'simple_form', '4.0.0'
gem 'skylight', '4.3.2'
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ gem install bundler -v '1.17.3'
bundle install
```

- Instale as dependencias do projeto

```bash
yarn install
```

- Crie e configure o arquivo `config/secrets.yml` conforme o exemplo:

```yaml
Expand Down
30 changes: 30 additions & 0 deletions app/assets/javascripts/fetch_students_in_recovery.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
function fetchStudentsInRecovery(classroom, discipline, exam_rule, step_id, recorded_at, success_callback) {
if (_.isEmpty(step_id) || _.isEmpty(moment(recorded_at, 'MM-DD-YYYY')._i) || exam_rule.recovery_type === 0) {
return;
}

$.ajax({
url: Routes.in_recovery_students_pt_br_path({
classroom_id: classroom,
discipline_id: discipline,
step_id: step_id,
date: recorded_at,
format: 'json'
}),
success: success_callback,
error: handleFetchStudentsInRecoveryError
});
}

function hideNoItemMessage() {
$('.no_item_found').hide();
}

function loadDecimalMasks() {
let numberOfDecimalPlaces = $('#recovery-diary-record-students').data('scale');
$('.nested-fields input.decimal').inputmask('customDecimal', { digits: numberOfDecimalPlaces });
}

function handleFetchStudentsInRecoveryError() {
flashMessages.error('Ocorreu um erro ao buscar os alunos.');
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<tr class="nested-fields" id="<%= id %>">
<td>
<div class="control-group hidden avaliation_recovery_lowest_note_recovery_diary_record_students_student_id">
<div class="controls input">
<input class="hidden" type="hidden" name="avaliation_recovery_lowest_note[recovery_diary_record_attributes][students_attributes][<%= element_id %>][student_id]" id="avaliation_recovery_lowest_note_recovery_diary_record_attributes_students_attributes_<%= element_id %>_student_id" value=<%= id %>>
</div>
</div>

<% if(exempted_from_discipline) { %>
<span class="exempted-student-from-discipline">****<%= name %></span>
<% } else { %>
<span class="multiline"><%= name %></span>
<% } %>
</td>

<td>
<span class="current-lowest-note">
<%= lowest_note_in_step %>
</span>
</td>

<td>
<div class="control-group decimal optional school_term_recovery_diary_record_recovery_diary_record_students_score">
<label class="decimal optional control-label hidden" for="avaliation_recovery_lowest_note_recovery_diary_record_attributes_students_attributes_<%= element_id %>_score">
Nota
</label>
<div class="controls input">
<input class="string decimal form-control decimal form-control decimal optional" type="decimal"
name="avaliation_recovery_lowest_note[recovery_diary_record_attributes][students_attributes][<%= element_id %>][score]"
id="avaliation_recovery_lowest_note_recovery_diary_record_attributes_students_attributes_<%= element_id %>_score"
<% if(exempted_from_discipline) { %> readonly <% } %>>
</div>
</div>
</td>
</tr>
210 changes: 210 additions & 0 deletions app/assets/javascripts/views/avaliation_recovery_lowest_notes/form.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
$(function () {
'use strict';

let flashMessages = new FlashMessages();
let examRule = null;
let $unity = $('#avaliation_recovery_lowest_note_recovery_diary_record_attributes_unity_id');
let $classroom = $('#avaliation_recovery_lowest_note_recovery_diary_record_attributes_classroom_id');
let $discipline = $('#avaliation_recovery_lowest_note_recovery_diary_record_attributes_discipline_id');
let $step = $('#avaliation_recovery_lowest_note_step_id');
let $recorded_at = $('#avaliation_recovery_lowest_note_recorded_at');
let $submitButton = $('input[type=submit]');

function fetchExamRule() {
let classroom_id = $classroom.select2('val');

if (_.isEmpty(classroom_id)) {
flashMessages.error('É necessário selecionar uma turma.');
} else {
$.ajax({
url: Routes.exam_rules_pt_br_path({ classroom_id: classroom_id, format: 'json' }),
success: handleFetchExamRuleSuccess,
error: handleFetchExamRuleError
});
}
}

function handleFetchExamRuleSuccess(data) {
examRule = data.exam_rule;
}

function handleFetchExamRuleError() {
flashMessages.error('Ocorreu um erro ao buscar a regra de avaliação da turma selecionada.');
}

$recorded_at.on('focusin', function(){
$(this).data('oldDate', $(this).val());
});

function checkPersistedDailyNote() {
let step_id = $step.select2('val');

let filter = {
by_classroom_id: $classroom.select2('val'),
by_unity_id: $unity.select2('val'),
by_discipline_id: $discipline.select2('val'),
by_step_id: step_id,
with_daily_note_students: true
};

if (!_.isEmpty(step_id)) {
$.ajax({
url: Routes.search_daily_notes_pt_br_path({ filter: filter, format: 'json' }),
success: handleFetchCheckPersistedDailyNoteSuccess,
error: handleFetchCheckPersistedDailyNoteError
});
}
}

function handleFetchCheckPersistedDailyNoteSuccess(data) {
if(_.isEmpty(data.daily_notes)){
flashMessages.error('A turma selecionada não possui notas lançadas nesta etapa.');
} else {
flashMessages.pop('');
let step_id = $step.select2('val');
let recorded_at = $recorded_at.val();
fetchStudents($classroom.select2('val'), $discipline.select2('val'), examRule, step_id, recorded_at);
}
}

function fetchStudents(classroom, discipline, exam_rule, step_id, recorded_at) {
if (_.isEmpty(step_id) || _.isEmpty(moment(recorded_at, 'MM-DD-YYYY')._i)) {
return;
}

$.ajax({
url: Routes.recovery_lowest_note_students_pt_br_path({
classroom_id: classroom,
discipline_id: discipline,
step_id: step_id,
date: recorded_at,
format: 'json'
}),
success: studentInLowestNoteRecovery,
error: handleFetchStudentsError
});
}

function handleFetchStudentsError() {
flashMessages.error('Ocorreu um erro ao buscar os alunos.');
}

function studentInLowestNoteRecovery(data) {
let students = data.students;

if (!_.isEmpty(students)) {
let element_counter = 0;
hideNoItemMessage();

$('#recovery-diary-record-students').empty();

_.each(students, function(student) {
let element_id = new Date().getTime() + element_counter++;
buildStudentField(element_id, student);
});

loadDecimalMasks();
} else {
$recorded_at.val($recorded_at.data('oldDate'));

flashMessages.error('Nenhum aluno encontrado.');
}

function buildStudentField(element_id, student, index = null){
let html = JST['templates/avaliation_recovery_lowest_notes/student_fields']({
id: student.id,
name: student.name,
lowest_note_in_step: student.lowest_note_in_step,
scale: 2,
element_id: element_id,
exempted_from_discipline: student.exempted_from_discipline
});

let $tbody = $('#recovery-diary-record-students');

if ($.isNumeric(index)) {
$(html).insertAfter($tbody.children('tr')[index]);
} else {
$tbody.append(html);
}
}
}

function handleFetchCheckPersistedDailyNoteError() {
flashMessages.error('Ocorreu um erro ao buscar as notas lançadas para esta turma nesta etapa.');
}

function checkExistsRecoveryLowestNoteOnStep() {
let step_id = $step.select2('val');
let classroom_id = $classroom.select2('val');
let discipline_id = $discipline.select2('val');

if (_.isEmpty(step_id)) {
flashMessages.error('É necessário selecionar uma etapa.');
} else {
$.ajax({
url: Routes.exists_recovery_on_step_avaliation_recovery_lowest_notes_pt_br_path({
format: 'json',
classroom_id: classroom_id,
step_id: step_id,
discipline_id: discipline_id
}),
success: handleFetchCheckExistsRecoveryLowestNoteOnStepSuccess,
error: handleFetchCheckExistsRecoveryLowestNoteOnStepError
});
}
}

function handleFetchCheckExistsRecoveryLowestNoteOnStepSuccess(data) {
if (data === true) {
flashMessages.error('A turma selecionada já possui uma Recuperação de menor nota nesta etapa.');
} else {
flashMessages.pop('');
}
}

function handleFetchCheckExistsRecoveryLowestNoteOnStepError() {
flashMessages.error('Ocorreu um erro ao buscar as recuperações de menor nota da etapa');
}

function validDateOnStep() {
let recorded_at = $recorded_at.val();
let step_id = $step.select2('val');
let classroom_id = $classroom.select2('val');

$.ajax({
url: Routes.recorded_at_in_selected_step_avaliation_recovery_lowest_notes_pt_br_path({
format: 'json',
classroom_id: classroom_id,
step_id: step_id,
recorded_at: recorded_at
}),
success: handleFetchRecordedAtOnStepSuccess,
error: handleFetchRecordedAtOnStepError
});
}

function handleFetchRecordedAtOnStepSuccess(data) {
if (data === true) {
flashMessages.pop('');
checkPersistedDailyNote();
} else {
flashMessages.error('Data deve estar dentro da etapa selecionada');
}
}

function handleFetchRecordedAtOnStepError() {
flashMessages.error('Ocorreu um erro ao validar a data');
}

$step.on('change', checkExistsRecoveryLowestNoteOnStep);

$recorded_at.on('change', validDateOnStep);

$submitButton.on('click', function() {
$recorded_at.unbind();
});

fetchExamRule();
loadDecimalMasks();
});
Loading

0 comments on commit 5666148

Please sign in to comment.