Skip to content

Commit

Permalink
Merge pull request #96 from portabilis/portabilis-patch-2022-04-01
Browse files Browse the repository at this point in the history
Portabilis patch 01/04/2022
  • Loading branch information
edersoares authored May 4, 2022
2 parents 16b3e0b 0ecdb50 commit 4d39b5b
Show file tree
Hide file tree
Showing 197 changed files with 2,009 additions and 643 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 66,7 @@ gem 'webpacker', '~> 4.x'
instance_eval File.read('Gemfile.plugins') if File.exist?('Gemfile.plugins')

group :development do
gem 'rack-mini-profiler'
gem 'rack-mini-profiler', '~> 2.3.4'
gem 'meta_request', '0.7.2'
gem 'pry-byebug', '3.4.2'
gem 'pry-remote', '0.1.8'
Expand Down
4 changes: 4 additions & 0 deletions app/assets/javascripts/flash_messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 17,7 @@ FlashMessages.prototype.warning = function(message) {
FlashMessages.prototype.error = function(message) {
this.pop("<div class='alert alert-danger'><i class='fa-fw fa fa-times'></i> " message "</div>");
};

FlashMessages.prototype.info = function(message) {
this.pop("<div class='alert alert-info'><i class='fa-fw fa fa-info'></i> " message "</div>");
};
4 changes: 4 additions & 0 deletions app/assets/javascripts/views/avaliations/form.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 174,10 @@ $(function () {
});
}

if ($('#avaliation_grade_ids').data('elements').length == 2) {
$('.avaliation_grades').hide();
}

function initFields() {
if (!!document.getElementById('avaliation_test_setting_id')) {
updateFieldsBasedOnTestSetting();
Expand Down
19 changes: 17 additions & 2 deletions app/assets/javascripts/views/conceptual_exams/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 83,7 @@ $(function() {
show_inactive: false,
date: recorded_at
};

if (!_.isEmpty(classroom_id) && !_.isEmpty(recorded_at)) {
$.ajax({
url: Routes.by_date_student_enrollments_lists_pt_br_path({
Expand Down Expand Up @@ -310,6 310,18 @@ $(function() {
flashMessages.error('Ocorreu um erro ao buscar as disciplinas dispensadas.');
};

function exists_conceptual_exam(conceptual_exam_id) {
removeDisciplines();
let text_step = $step.closest('div').find('#s2id_conceptual_exam_step_id').find('.select2-choice').text().trim();
let student_name = $student.closest('div').find('#s2id_conceptual_exam_student_id').find('.select2-choice').text().trim();
let redirect_link = Routes.edit_conceptual_exam_pt_br_path(conceptual_exam_id);
let message = `O(a) aluno(a) ${student_name} já possui uma avaliação conceitual na etapa ${text_step}, para modificar a mesma clique aqui <a href="${redirect_link}" style="color: white"><b>Avaliação</b></a>.`;
$('#btn-save').attr('disabled', true);
$('#btn-save-and-next').attr('disabled', true);

flashMessages.error(message);
}

$student.on('change', function(){
$.get(
Routes.find_conceptual_exam_by_student_conceptual_exams_pt_br_path(
Expand All @@ -323,9 335,12 @@ $(function() {
}
)
).done(function(conceptual_exam_id) {
flashMessages.pop('');
if (conceptual_exam_id) {
window.location.href = Routes.edit_conceptual_exam_pt_br_path(conceptual_exam_id);
exists_conceptual_exam(conceptual_exam_id);
} else {
$('#btn-save').attr('disabled', false);
$('#btn-save-and-next').attr('disabled', false);
fetchExamRule();
removeDisciplines();
fetchDisciplines();
Expand Down
29 changes: 28 additions & 1 deletion app/assets/javascripts/views/descriptive_exams/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 8,8 @@ $(function () {
$stepContainer = $('[data-descriptive-exam-step-container]'),
should_clear_discipline = true,
should_clear_step = true,
discipline_id = $discipline.val();
discipline_id = $discipline.val(),
view_btn = $('#view-btn');

if ($opinionType.data('elements').length === 2) {
$opinionType.attr('readonly', true)
Expand Down Expand Up @@ -53,4 54,30 @@ $(function () {
});

setFields();

$step.on('change', function() {
let step_id = $step.val(),
discipline_id = $discipline.val(),
opinion_type = $('#descriptive_exam_opinion_type').val();

$.ajax({
url: Routes.find_descriptive_exams_pt_br_path({
discipline_id: discipline_id,
step_id: step_id,
opinion_type: opinion_type,
format: 'json'
}),
success: function(descriptive_exam_id) {
if (descriptive_exam_id === null || !$.isNumeric(descriptive_exam_id)) {
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))
}
});
})
});
68 changes: 68 additions & 0 deletions app/assets/javascripts/views/descriptive_exams/functions.js
Original file line number Diff line number Diff line change
@@ -0,0 1,68 @@
function createSummerNote(element, options = {}) {
$(element).summernote({
lang: 'pt-BR',
toolbar: options.toolbar || [],
disableDragAndDrop : true,
callbacks : {
onPaste : function (event) {
var thisNote = $(this);
var updatePastedText = function(someNote){
var original = someNote.summernote('code');
var cleaned = CleanPastedHTML(original);

someNote.summernote('code', cleaned);
};

setTimeout(function () {
updatePastedText(thisNote);
}, 10);
}
}
});

if (options.disabled) {
$(element).each(function(index, el) {
$(el).summernote('disable');
})
}
}

function CleanPastedHTML(input) {
var stringStripper = /(\n|\r| class=(")?Mso[a-zA-Z] (")?)/g;
var output = input.replace(stringStripper, ' ');
var commentSripper = new RegExp('<!--(.*?)-->','g');
var output = output.replace(commentSripper, '');
var tagStripper = new RegExp('<(/)*(meta|link|span|\\?xml:|st1:|o:|font)(.*?)>','gi');
output = output.replace(tagStripper, '');
var badTags = getTags(output)
for (var i=0; i< badTags.length; i ) {
tagStripper = new RegExp('<' badTags[i] '.*?' badTags[i] '(.*?)>', 'gi');
output = output.replace(tagStripper, '');
}
var badAttributes = ['style', 'start'];
for (var i=0; i< badAttributes.length; i ) {
var attributeStripper = new RegExp(' ' badAttributes[i] '="(.*?)"','gi');
output = output.replace(attributeStripper, '');
}

return output;
}

function getTags(htmlString){
var tmpTag = document.createElement("div");
tmpTag.innerHTML = htmlString;

var all = tmpTag.getElementsByTagName("*");
var goodTags = ['DIV', 'P', 'B', 'I', 'U', 'BR'];
var tags = [];

for (var i = 0, max = all.length; i < max; i ) {
var tagname = all[i].tagName;

if (tags.indexOf(tagname) == -1 && !goodTags.includes(tagname)) {
tags.push(tagname);
}
}

return tags
}
3 changes: 3 additions & 0 deletions app/assets/javascripts/views/descriptive_exams/show.js
Original file line number Diff line number Diff line change
@@ -0,0 1,3 @@
$(function () {
createSummerNote("textarea[id^=descriptive_exam_students_attributes_]", { disabled: true })
});
70 changes: 3 additions & 67 deletions app/assets/javascripts/views/descriptive_exams/student_fields.js
Original file line number Diff line number Diff line change
@@ -1,73 1,9 @@
$(function () {
$('textarea[maxLength]').maxlength();

$("textarea[id^=descriptive_exam_students_attributes_]").summernote({
lang: 'pt-BR',
createSummerNote("textarea[id^=descriptive_exam_students_attributes_]", {
toolbar: [
['font', ['bold', 'italic', 'underline', 'clear']],
],
disableDragAndDrop : true,
callbacks : {
onPaste : function (event) {
var thisNote = $(this);
var updatePastedText = function(someNote){
var original = someNote.summernote('code');
var cleaned = CleanPastedHTML(original);

someNote.summernote('code', cleaned);
};

setTimeout(function () {
//the function is called after the text is really pasted.
updatePastedText(thisNote);
}, 10);
}
}
});

function CleanPastedHTML(input) {
// 1. remove line breaks / Mso classes
var stringStripper = /(\n|\r| class=(")?Mso[a-zA-Z] (")?)/g;
var output = input.replace(stringStripper, ' ');
// 2. strip Word generated HTML comments
var commentSripper = new RegExp('<!--(.*?)-->','g');
var output = output.replace(commentSripper, '');
var tagStripper = new RegExp('<(/)*(meta|link|span|\\?xml:|st1:|o:|font)(.*?)>','gi');
// 3. remove tags leave content if any
output = output.replace(tagStripper, '');
// 4. Remove everything in between and including tags '<style(.)style(.)>'
var badTags = getTags(output)
// remove all tags except ['DIV', 'P', 'B', 'I', 'U', 'BR'];
for (var i=0; i< badTags.length; i ) {
tagStripper = new RegExp('<' badTags[i] '.*?' badTags[i] '(.*?)>', 'gi');
output = output.replace(tagStripper, '');
}
// 5. remove attributes ' style="..."'
var badAttributes = ['style', 'start'];
for (var i=0; i< badAttributes.length; i ) {
var attributeStripper = new RegExp(' ' badAttributes[i] '="(.*?)"','gi');
output = output.replace(attributeStripper, '');
}

return output;
}

function getTags(htmlString){
var tmpTag = document.createElement("div");
tmpTag.innerHTML = htmlString;

var all = tmpTag.getElementsByTagName("*");
var goodTags = ['DIV', 'P', 'B', 'I', 'U', 'BR'];
var tags = [];

for (var i = 0, max = all.length; i < max; i ) {
var tagname = all[i].tagName;

if (tags.indexOf(tagname) == -1 && !goodTags.includes(tagname)) {
tags.push(tagname);
}
}

return tags
}
]
})
});
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 45,25 @@ $(function() {
};

$grade.on('change', function() {
fetchDisciplines();
validateMulti();
});

function validateMulti() {
$.ajax({
url: Routes.multi_grade_classrooms_pt_br_path({ format: 'json' }),
success: function(classroom_multi) {
if (classroom_multi) {
return
}

fetchDisciplines();
},
error: function() {
flashMessages.error('Ocorreu um erro ao validar se a turma é multisseriada');
}
});
}

$schoolTermType.on('change', function() {
updateSchoolTermInput($schoolTermType, $schoolTerm, $schoolTermContainer, flashMessages);
$('#copy_plan_info').show();
Expand Down
11 changes: 11 additions & 0 deletions app/assets/javascripts/views/exam_record_report/form.js
Original file line number Diff line number Diff line change
@@ -0,0 1,11 @@
$(document).ready(function() {
'use strict';

let flashMessages = new FlashMessages(),
redirect_link_report_card = Routes.teacher_report_cards_pt_br_path(),
redirect_link_conceptual_exams = Routes.conceptual_exams_pt_br_path(),
redirect_link_descriptive_exams = Routes.new_descriptive_exam_pt_br_path(),
message = `O <b>Registros de avaliações numéricas</b> apresentará somente as notas lançadas nos diários de avaliação e recuperações numéricas. Para conferência de notas conceituais e/ou descritivas acessar, respectivamente, o <a href="${redirect_link_report_card}"><b>Boletim do professor</b></a> ou as telas de <a href="${redirect_link_conceptual_exams}"><b>Diário de avaliações conceituais</b></a> e <a href="${redirect_link_descriptive_exams}"><b>Avaliações descritivas</b></a>.`;

flashMessages.info(message);
});
30 changes: 29 additions & 1 deletion app/assets/javascripts/views/lessons_boards/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 46,28 @@ $(function () {
}

period_div.show();

populateClassroomGradeId();
})

function populateClassroomGradeId() {
let grade_id = $('#lessons_board_grade').select2('val');
let classroom_id = $('#lessons_board_classroom_id').select2('val');

$.ajax({
url: Routes.classroom_grade_lessons_boards_pt_br_path({
grade_id: grade_id,
classroom_id: classroom_id,
}),
success: function(data) {
$('#lessons_board_classrooms_grade_id').val(data)
},
error: function() {
flashMessages.error('Ocorreu um erro ao buscar a série vinculada a turma.');
}
});
}

$('#lessons_board_period').on('change', function() {
errors = {};
let period = $('#lessons_number_classroom_id').val();
Expand Down Expand Up @@ -295,11 315,19 @@ $(function () {
});

$("input[id*='_teacher_discipline_classroom_id']").each(function (index, teachers) {
$(teachers).select2({ data: teachers_to_select, escapeMarkup: function(data) { return data; }})
$(teachers).select2({ data: teachers_to_select, escapeMarkup, formatResult })
})
}
}

function escapeMarkup(data) {
return data;
}

function formatResult(state) {
return state.name;
}

function handleFetchTeachersFromTheClassroomError() {
flashMessages.error('Ocorreu um erro ao buscar os professores da turma.');
}
Expand Down
Loading

0 comments on commit 4d39b5b

Please sign in to comment.