diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 81e62d9dc..e6cc1539c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -9,10 +9,12 @@ on: jobs: default: - + name: Unit and Integration - - runs-on: self-hosted + + if: '! github.event.pull_request.draft' + + runs-on: ubuntu-latest env: RAILS_ENV: test diff --git a/Gemfile b/Gemfile index 8c6280584..f9ecf7ca6 100644 --- a/Gemfile +++ b/Gemfile @@ -3,8 +3,8 @@ source 'https://rubygems.org' ruby '2.4.10' gem 'active_model_serializers', '0.9.3' -gem 'activerecord-connections', git: 'https://github.com/ricardohsd/activerecord-connections.git' -gem 'activerecord-tableless', '2.0.0' +gem 'activerecord-connections', git: 'https://github.com/portabilis/activerecord-connections.git' +gem "activerecord-tablefree", "~> 3.0" gem 'audited', git: 'https://github.com/portabilis/audited.git' gem 'aws-sdk-s3', '~>1.83.0' gem 'backbone-nested-attributes', '0.3.0', git: 'https://github.com/samuelsimoes/backbone-nested-attributes.git' @@ -23,45 +23,47 @@ gem 'devise', '>= 4.7.1' gem 'discard', '1.0.0' gem 'ejs', '1.1.1' gem 'enumerate_it', '1.3.1' -gem 'foreigner', '1.6.1' gem 'handlebars_assets', '0.23.2' -gem 'has_scope', '0.5.1' +gem 'has_scope', '0.7.2' gem 'honeybadger', '4.5.6' -gem 'i18n_alchemy', '0.2.1', git: 'https://github.com/giustin/i18n_alchemy.git', branch: 'master', tag: 'v0.2.1' +gem 'i18n_alchemy', '0.3.1' gem 'jbuilder', '2.9.1' gem 'js-routes', '1.4.9' gem 'kaminari', '>= 1.2.1' gem 'less-rails', '3.0.0' +gem 'loofah', '2.18.0' gem 'mask_validator', '0.2.1' gem 'momentjs-rails', '>= 2.9.0' gem 'non-stupid-digest-assets', '1.0.9' -gem 'pg', '0.17.1' +gem 'pg', '~> 0.18.0' gem 'pg_query', '1.2.0' gem 'postgres-copy', '1.0.0' -gem 'prawn', '2.1.2', git: 'https://github.com/portabilis/prawn.git', branch: 'master', tag: 'v2.1.2' +gem 'prawn', '2.1.2', git: 'https://github.com/portabilis/prawn.git', branch: 'master' gem 'prawn-table', '0.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' -gem 'rails', '4.2.11.1' +gem 'rails', '5.0.7.2' gem 'rake', '>= 12.3.3' gem 'redis', '3.3.5' gem 'redis-session-store', '0.11.1' -gem 'responders', '2.1.0' +gem 'responders', '2.4.1' gem 'rest-client', '2.0.2' -gem 'route_translator', git: 'https://github.com/enriclluelles/route_translator.git', tag: 'v4.1.0' +gem 'route_translator', git: 'https://github.com/enriclluelles/route_translator.git', tag: 'v5.10.0' gem 'rubyzip', '>= 1.3.0', require: 'zip' 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 'therubyracer', '0.12.3' -gem 'twitter-bootstrap-rails', '3.2.0' +gem 'twitter-bootstrap-rails', '3.2.2' gem 'uglifier', '4.1.20' gem 'uri_validator', '0.2.0' gem 'validates_timeliness', '3.0.14' gem 'webpacker', '~> 4.x' +gem 'scenic', '~> 1.7' +gem 'tilt', '2.1.0' instance_eval File.read('Gemfile.plugins') if File.exist?('Gemfile.plugins') @@ -70,11 +72,12 @@ group :development do gem 'meta_request', '0.7.2' gem 'pry-byebug', '3.4.2' gem 'pry-remote', '0.1.8' - gem 'quiet_assets', '1.1.0' gem 'rubocop', '0.59.2', require: false gem 'spring', '2.0.2' gem 'spring-commands-rspec', '1.0.4' - gem 'letter_opener_web', '~> 1.0' + gem 'letter_opener_web', '~> 1.3.4' + gem 'listen', '~> 3.0.5' + gem 'spring-watcher-listen', '~> 2.0.0' end group :test do @@ -85,9 +88,11 @@ group :test do gem 'factory_girl_rails', '4.5.0' gem 'faker', '1.9.1' gem 'gherkin', '2.12.2' + gem 'nokogiri', '1.9.1' gem 'pdf-inspector', '1.2.1', require: 'pdf/inspector' gem 'pry', '0.10.3' - gem 'rspec-rails', '3.4.0' + gem 'rails-controller-testing', '~> 1.0.5' + gem 'rspec-rails', '3.5.2' gem 'rspec-retry', '0.6.2 ' gem 'rspec-sidekiq', '3.0.3' gem 'rspec-wait', '0.0.9' @@ -101,5 +106,5 @@ group :test do end group :test, :development do - gem 'bullet', '4.14.10' + gem 'bullet', '6.1.5' end diff --git a/Rakefile b/Rakefile index ba6b733dd..e85f91391 100644 --- a/Rakefile +++ b/Rakefile @@ -1,6 +1,6 @@ # Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. -require File.expand_path('../config/application', __FILE__) +require_relative 'config/application' Rails.application.load_tasks diff --git a/app/assets/javascripts/fetch_students_in_recovery.js b/app/assets/javascripts/fetch_students_in_recovery.js index 7305267f3..328e43460 100644 --- a/app/assets/javascripts/fetch_students_in_recovery.js +++ b/app/assets/javascripts/fetch_students_in_recovery.js @@ -1,8 +1,21 @@ +let $loadingClone = $('#page-loading').clone(true).appendTo('body'); + 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) { + let date = moment(recorded_at, 'DD/MM/YYYY', true); + if (_.isEmpty(step_id) || _.isEmpty(date._i) || !date.isValid() || exam_rule.recovery_type === 0) { return; } + $loadingClone.removeClass('hidden'); + + success_callback = (function() { + let cached_function = success_callback; + return function() { + cached_function.apply(this, arguments); + $loadingClone.addClass('hidden'); + }; + })(); + $.ajax({ url: Routes.in_recovery_students_pt_br_path({ classroom_id: classroom, @@ -26,5 +39,6 @@ function loadDecimalMasks() { } function handleFetchStudentsInRecoveryError() { + $loadingClone.addClass('hidden'); flashMessages.error('Ocorreu um erro ao buscar os alunos.'); } diff --git a/app/assets/javascripts/summernote.js b/app/assets/javascripts/summernote.js new file mode 100644 index 000000000..5cd3dfab6 --- /dev/null +++ b/app/assets/javascripts/summernote.js @@ -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', 'class']; + 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 +} \ No newline at end of file diff --git a/app/assets/javascripts/templates/transfer_notes/current_notes_row.jst.ejs b/app/assets/javascripts/templates/transfer_notes/current_notes_row.jst.ejs index 484938bda..3a0c68c5f 100644 --- a/app/assets/javascripts/templates/transfer_notes/current_notes_row.jst.ejs +++ b/app/assets/javascripts/templates/transfer_notes/current_notes_row.jst.ejs @@ -4,25 +4,23 @@ - <% if(id > 0){ %> - <%= note %> - <% } else {%>
+ + id="transfer_note_daily_note_students_attributes_<%= element_id %>_id" value="<%= id %>"> + id="transfer_note_daily_note_students_attributes_<%= element_id %>_student_id" value="<%= student.id %>"> + id="transfer_note_daily_note_students_attributes_<%= element_id %>_daily_note_id" value="<%= daily_note_id %>"> - <% } %> + id="transfer_note_daily_note_students_attributes_<%= element_id %>_active" value="<%= true %>"> + diff --git a/app/assets/javascripts/views/complementary_exams/form.js b/app/assets/javascripts/views/complementary_exams/form.js index 1aa514d8f..f94508165 100644 --- a/app/assets/javascripts/views/complementary_exams/form.js +++ b/app/assets/javascripts/views/complementary_exams/form.js @@ -78,7 +78,8 @@ $(function () { discipline: discipline_id, show_inactive: false, with_recovery_note_in_step: with_recovery_note_in_step, - score_type: 'numeric' + score_type: 'numeric', + status_attending: true }, format: 'json' }), diff --git a/app/assets/javascripts/views/daily_frequencies/edit_multiple.js b/app/assets/javascripts/views/daily_frequencies/edit_multiple.js index 077fc6a43..2345409bb 100644 --- a/app/assets/javascripts/views/daily_frequencies/edit_multiple.js +++ b/app/assets/javascripts/views/daily_frequencies/edit_multiple.js @@ -51,7 +51,7 @@ $(function () { } }; - $('a, button').on('click', function(e) { + $('a:not(.no-confirm), button:not(.no-confirm)').on('click', function(e) { if (!showConfirmation) { return true; } @@ -62,7 +62,7 @@ $(function () { modalOptions = Object.assign(modalOptions, { callback: function(result) { if (result) { - $('input[type=submit]').click(); + $('input[type=submit].new-save-style').click(); } else { e.target.click(); } @@ -86,3 +86,35 @@ $(function () { $('.alert-success, .alert-danger').fadeTo(700, 0.1).fadeTo(700, 1.0); }); + +$(document).ready(function () { + $("label.checkbox-frequency:not(.checkbox-batch) input[type=checkbox]").click(function() { + let el = $(this); + + el.closest('div').find('.hidden-justified').prop('disabled', true).val(null); + + switch (el.data('status')) { + case 'present': + el.data('status', 'absent'); + el.prop('indeterminate', false); + el.prop('checked', true); + el.closest('label').removeClass('justified'); + break; + + case 'justified': + el.data('status', 'present'); + el.prop('indeterminate', true); + el.prop('checked', false); + el.closest('label').addClass('justified'); + el.closest('div').find('.hidden-justified').prop('disabled', false).val(-1); + break; + + case 'absent': + default: + el.data('status', 'justified'); + el.prop('indeterminate', false); + el.prop('checked', false); + el.closest('label').removeClass('justified'); + } + }); +}); diff --git a/app/assets/javascripts/views/daily_frequencies_in_batchs/create_or_update_multiple.js b/app/assets/javascripts/views/daily_frequencies_in_batchs/create_or_update_multiple.js index a951af1f7..2fae5cc23 100644 --- a/app/assets/javascripts/views/daily_frequencies_in_batchs/create_or_update_multiple.js +++ b/app/assets/javascripts/views/daily_frequencies_in_batchs/create_or_update_multiple.js @@ -16,7 +16,7 @@ $(document).ready( function() { checkbox.prop('disabled', disabled) checkbox.prop('checked', true) checkbox.closest('label').addClass('state-disabled'); - checkbox.closest('td').find('.class-number-checkbox').prop('checked', true) + checkbox.closest('td').find('.class-number-checkbox:not(.justified-absence-checkbox)').prop('checked', true) checkbox.closest('label').find('.general-checkbox-icon').removeClass('unchecked') } else { checkbox.closest('label:not(.never-change)').find('.general-checkbox:not(.never-change)').prop('disabled', disabled) @@ -25,10 +25,6 @@ $(document).ready( function() { }).trigger('change'); }) - $('.class-number-checkbox').each( function () { - markGeneralCheckbox($(this).closest('td')) - }); - $('.date-collapse').each( function () { let index = $(this).index() + 1 $(this).closest('table').find('tbody tr td:nth-child(' + index + ') .class-number-collapse').addClass('hidden') @@ -51,7 +47,7 @@ $(function () { } }; - $('a, button').on('click', function(e) { + $('a:not(.no-confirm), button:not(.no-confirm)').on('click', function(e) { if (!showConfirmation) { return true; } @@ -62,7 +58,7 @@ $(function () { modalOptions = Object.assign(modalOptions, { callback: function(result) { if (result) { - $('input[type=submit]').click(); + $('input[type=submit].new-save-style').click(); } else { e.target.click(); } @@ -87,36 +83,64 @@ $(function () { $('.alert-success, .alert-danger').fadeTo(700, 0.1).fadeTo(700, 1.0); }); -$('.general-checkbox').on('change', function() { - let checked = $(this).prop('checked') - if (checked) { - $(this).closest('td').find('.checkbox-frequency-in-batch').removeClass('half-checked') - $(this).closest('td').find('.checkbox-frequency-in-batch').removeClass('unchecked') - } else { - $(this).closest('td').find('.checkbox-frequency-in-batch').addClass('unchecked') - } - $(this).closest('td').find('.class-number-checkbox').prop('checked', checked) - studentAbsencesCount($(this).closest('tr')) -}) +function studentAbsencesCount(tr) { + let count = tr.find('label.checkbox-frequency:not(.checkbox-batch) input[type=checkbox]:not(:checked)').not('.inactive').length + tr.find('.student-absences-count').text(count) +} -$('.class-number-checkbox').on('change', function() { - if ($(this).is(':checked')) { - $(this).closest('label').find('.checkbox-frequency-in-batch').removeClass('unchecked') +function updateCheckboxes(el, init = false) { + let checkboxes = el.closest('td').find('label.checkbox-frequency:not(.checkbox-batch) input[type=checkbox]'); + let general = el.closest('td').find('label.checkbox-batch input[type=checkbox]'); + let total = checkboxes.length; + let present = 0; + let justified = 0; + let absent = 0; + + checkboxes.each(function () { + let checked = $(this).prop('checked'); + let indeterminate = $(this).prop('indeterminate') || $(this).closest('label').hasClass('justified'); + + if (checked && !indeterminate) { + present++; + } else if (!checked && indeterminate) { + justified++; + } else { + absent++; + } + }); + + if (present == total) { + general.data('status', 'absent'); + general.prop('indeterminate', false); + general.prop('checked', true); + general.closest('label').removeClass('justified').removeClass('partial-absence'); + } else if (justified == total) { + general.data('status', 'present'); + general.prop('indeterminate', true); + general.prop('checked', false); + general.closest('label').addClass('justified').removeClass('partial-absence'); + + // Garante que um dia já justificado não possa ser alterado + if (init) { + general.prop('disabled', true); + } + } else if (absent == total) { + general.data('status', 'justified'); + general.prop('indeterminate', false); + general.prop('checked', false); + general.closest('label').removeClass('justified').removeClass('partial-absence'); } else { - $(this).closest('label').find('.checkbox-frequency-in-batch').addClass('unchecked') + general.data('status', 'absent'); + general.prop('indeterminate', false); + general.prop('checked', true); + general.closest('label').removeClass('justified').addClass('partial-absence'); } - markGeneralCheckbox($(this).closest('td')) - studentAbsencesCount($(this).closest('tr')) -}); -function studentAbsencesCount(tr) { - let count = tr.find('.class-number-checkbox:not(:checked)').not('.inactive').length - tr.find('.student-absences-count').text(count) + studentAbsencesCount(el.closest('tr')); } $('.date-collapse').on('click', function () { let index = $(this).index() + 1 - console.log($(this).data('count')) if ($(this).data('count') > 1) { if ($(this).closest('table').find('tbody tr td:nth-child(' + index + ') .class-number-collapse').hasClass('hidden')) { $(this).closest('table').find('tbody tr td:nth-child(' + index + ') .class-number-collapse').removeClass('hidden') @@ -134,22 +158,74 @@ $('.date-collapse').on('click', function () { } }); -function markGeneralCheckbox(td) { - let all_checked = td.find('.class-number-checkbox:not(:checked)').length == 0 - let all_not_checked = td.find('.class-number-checkbox:is(:checked)').length == 0 - td.find('.class-number-checkbox:not(:checked)').closest('label').find('.checkbox-frequency-in-batch').addClass('unchecked') - td.find('.class-number-checkbox:is(:checked)').closest('label').find('.checkbox-frequency-in-batch').removeClass('unchecked') - - if (all_checked) { - td.find('.general-checkbox').prop('checked', true) - td.find('.general-checkbox-icon').removeClass('half-checked') - td.find('.checkbox-frequency-in-batch').removeClass('unchecked') - } else if (all_not_checked) { - td.find('.general-checkbox').prop('checked', false) - td.find('.checkbox-frequency-in-batch').addClass('unchecked') - } else { - td.find('.general-checkbox-icon').addClass('half-checked') - td.find('.general-checkbox-icon').removeClass('unchecked') - td.find('.general-checkbox').prop('checked', true) - } -} +$(document).ready(function () { + $("label.checkbox-frequency:not(.checkbox-batch) input[type=checkbox]").each(function () { + updateCheckboxes($(this), true); + }); + + $("label.checkbox-frequency:not(.checkbox-batch) input[type=checkbox]").click(function() { + let el = $(this); + + el.closest('div').find('.hidden-justified').prop('disabled', true).val(null); + + switch (el.data('status')) { + case 'present': + el.data('status', 'absent'); + el.prop('indeterminate', false); + el.prop('checked', true); + el.closest('label').removeClass('justified'); + break; + + case 'justified': + el.data('status', 'present'); + el.prop('indeterminate', true); + el.prop('checked', false); + el.closest('label').addClass('justified'); + el.closest('div').find('.hidden-justified').prop('disabled', false).val(-1); + break; + + case 'absent': + default: + el.data('status', 'justified'); + el.prop('indeterminate', false); + el.prop('checked', false); + el.closest('label').removeClass('justified'); + } + + updateCheckboxes(el); + }); + + $("label.checkbox-batch input[type=checkbox]").click(function() { + let el = $(this); + let td = el.closest('td'); + + el.closest('label').removeClass('partial-absence'); + td.find('.hidden-justified').prop('disabled', true).val(null); + + switch (el.data('status')) { + case 'present': + td.find('label.checkbox-frequency input[type=checkbox]').data('status', 'absent'); + td.find('label.checkbox-frequency input[type=checkbox]').prop('indeterminate', false); + td.find('label.checkbox-frequency input[type=checkbox]').prop('checked', true); + td.find('label').removeClass('justified'); + break; + + case 'justified': + td.find('label.checkbox-frequency input[type=checkbox]').data('status', 'present'); + td.find('label.checkbox-frequency input[type=checkbox]').prop('indeterminate', true); + td.find('label.checkbox-frequency input[type=checkbox]').prop('checked', false); + td.find('label').addClass('justified'); + td.find('.hidden-justified').prop('disabled', false).val(-1); + break; + + case 'absent': + default: + td.find('label.checkbox-frequency input[type=checkbox]').data('status', 'justified'); + td.find('label.checkbox-frequency input[type=checkbox]').prop('indeterminate', false); + td.find('label.checkbox-frequency input[type=checkbox]').prop('checked', false); + td.find('label').removeClass('justified'); + } + + studentAbsencesCount(el.closest('tr')); + }); +}); diff --git a/app/assets/javascripts/views/discipline_lesson_plans/form.js b/app/assets/javascripts/views/discipline_lesson_plans/form.js index 31de4eb6c..e1946709e 100644 --- a/app/assets/javascripts/views/discipline_lesson_plans/form.js +++ b/app/assets/javascripts/views/discipline_lesson_plans/form.js @@ -240,3 +240,28 @@ $(function () { }); } }); + +$(function () { + $('textarea[maxLength]').maxlength(); + + createSummerNote("textarea[id^=discipline_lesson_plan_lesson_plan_attributes_activities]" , { + toolbar: [ + ['font', ['bold', 'italic', 'underline', 'clear']], + ] + }) + createSummerNote("textarea[id^=discipline_lesson_plan_lesson_plan_attributes_resources]" , { + toolbar: [ + ['font', ['bold', 'italic', 'underline', 'clear']], + ] + }) + createSummerNote("textarea[id^=discipline_lesson_plan_lesson_plan_attributes_evaluation]" , { + toolbar: [ + ['font', ['bold', 'italic', 'underline', 'clear']], + ] + }) + createSummerNote("textarea[id^=discipline_lesson_plan_lesson_plan_attributes_bibliography]" , { + toolbar: [ + ['font', ['bold', 'italic', 'underline', 'clear']], + ] + }) +}); diff --git a/app/assets/javascripts/views/discipline_teaching_plans/form.js.erb b/app/assets/javascripts/views/discipline_teaching_plans/form.js.erb index 9c6bea3b1..7184a0476 100644 --- a/app/assets/javascripts/views/discipline_teaching_plans/form.js.erb +++ b/app/assets/javascripts/views/discipline_teaching_plans/form.js.erb @@ -129,3 +129,24 @@ $(function() { }); } }); + +$(function () { + $('textarea[maxLength]').maxlength(); + + createSummerNote("textarea[id^=discipline_teaching_plan_teaching_plan_attributes_methodology]" , { + toolbar: [ + ['font', ['bold', 'italic', 'underline', 'clear']], + ] + }) + createSummerNote("textarea[id^=discipline_teaching_plan_teaching_plan_attributes_evaluation]" , { + toolbar: [ + ['font', ['bold', 'italic', 'underline', 'clear']], + ] + }) + createSummerNote("textarea[id^=discipline_teaching_plan_teaching_plan_attributes_references]" , { + toolbar: [ + ['font', ['bold', 'italic', 'underline', 'clear']], + ] + }) + +}); diff --git a/app/assets/javascripts/views/knowledge_area_lesson_plans/form.js b/app/assets/javascripts/views/knowledge_area_lesson_plans/form.js index 7ca6784f8..2b04a4fa0 100644 --- a/app/assets/javascripts/views/knowledge_area_lesson_plans/form.js +++ b/app/assets/javascripts/views/knowledge_area_lesson_plans/form.js @@ -169,3 +169,33 @@ $(function () { }); } }); + + +$(function () { + + $('textarea[maxLength]').maxlength(); + + createSummerNote("textarea[id^=knowledge_area_lesson_plan_lesson_plan_attributes_activities]" , { + toolbar: [ + ['font', ['bold', 'italic', 'underline', 'clear']], + ] + }) + + createSummerNote("textarea[id^=knowledge_area_lesson_plan_lesson_plan_attributes_resources]" , { + toolbar: [ + ['font', ['bold', 'italic', 'underline', 'clear']], + ] + }) + + createSummerNote("textarea[id^=knowledge_area_lesson_plan_lesson_plan_attributes_evaluation]" , { + toolbar: [ + ['font', ['bold', 'italic', 'underline', 'clear']], + ] + }) + + createSummerNote("textarea[id^=knowledge_area_lesson_plan_lesson_plan_attributes_bibliography]" , { + toolbar: [ + ['font', ['bold', 'italic', 'underline', 'clear']], + ] + }) +}); \ No newline at end of file diff --git a/app/assets/javascripts/views/knowledge_area_teaching_plans/form.js.erb b/app/assets/javascripts/views/knowledge_area_teaching_plans/form.js.erb index 40942bdbd..c0bf55047 100644 --- a/app/assets/javascripts/views/knowledge_area_teaching_plans/form.js.erb +++ b/app/assets/javascripts/views/knowledge_area_teaching_plans/form.js.erb @@ -77,3 +77,23 @@ $(function() { }); } }); + +$(function () { + $('textarea[maxLength]').maxlength(); + + createSummerNote("textarea[id^=knowledge_area_teaching_plan_teaching_plan_attributes_methodology]" , { + toolbar: [ + ['font', ['bold', 'italic', 'underline', 'clear']], + ] + }) + createSummerNote("textarea[id^=knowledge_area_teaching_plan_teaching_plan_attributes_evaluation]" , { + toolbar: [ + ['font', ['bold', 'italic', 'underline', 'clear']], + ] + }) + createSummerNote("textarea[id^=knowledge_area_teaching_plan_teaching_plan_attributes_references]" , { + toolbar: [ + ['font', ['bold', 'italic', 'underline', 'clear']], + ] + }) +}); diff --git a/app/assets/javascripts/views/layouts/copy-objectives.js b/app/assets/javascripts/views/layouts/copy-objectives.js index 00fb85024..2a01e9bdf 100644 --- a/app/assets/javascripts/views/layouts/copy-objectives.js +++ b/app/assets/javascripts/views/layouts/copy-objectives.js @@ -1,13 +1,22 @@ document.addEventListener('DOMContentLoaded', () => { 'use strict'; - const confirmCopyButton = document.getElementById('confirm-copy-objectives-modal'); + const confirmCopyButton = document.getElementById('confirm-copy-objectives-btn'); + const experienceConfirmButton = document.getElementById('experience-confirm-btn'); + const disciplinesConfirmCopyButton = document.getElementById('disciplines-confirm-btn'); - const requestContents = (itens) => { + const requestContents = (itens, origin) => { return new Promise(resolve => { const url = Routes.contents_learning_objectives_and_skills_pt_br_path(); let params = {} - params[confirmCopyButton.dataset.type] = itens + + if (origin === 'experience') { + params[experienceConfirmButton.dataset.type] = itens + } else if (origin === 'disciplines') { + params[disciplinesConfirmCopyButton.dataset.type] = itens + } else { + params[confirmCopyButton.dataset.type] = itens + } $.getJSON(url, params).done(resolve); }); @@ -48,7 +57,51 @@ document.addEventListener('DOMContentLoaded', () => { addElement(content['description']); }); - $('#copy-objectives-modal').modal('hide'); + $('#confirm-copy-objectives-modal').modal('hide'); + }); + }; + + const disciplinesCopyObjectives = () => { + const selectedItens = []; + + $(checkedExperienceFields()).each(function() { + const experience_field = this.dataset.id; + const grades = $(this).closest('.row').find('input.grade_ids').select2("val"); + selectedItens.push({ type: experience_field, grades: grades }); + }); + + if (selectedItens.length === 0) { + return; + } + + requestContents(selectedItens, 'disciplines').then(data => { + data['contents'].forEach(content => { + addElement(content['description']); + }); + + $('#disciplines-modal').modal('hide'); + }); + }; + + const experienceCopyObjectives = () => { + const selectedItens = []; + + $(checkedExperienceFields()).each(function() { + const experience_field = this.dataset.id; + const grades = $(this).closest('.row').find('input.grade_ids').select2("val"); + selectedItens.push({ type: experience_field, grades: grades }); + }); + + if (selectedItens.length === 0) { + return; + } + + requestContents(selectedItens, 'experience').then(data => { + data['contents'].forEach(content => { + addElement(content['description']); + }); + + $('#experience-modal').modal('hide'); }); }; @@ -56,6 +109,14 @@ document.addEventListener('DOMContentLoaded', () => { confirmCopyButton.addEventListener('click', copyObjectives); } + if (experienceConfirmButton) { + experienceConfirmButton.addEventListener('click', experienceCopyObjectives); + } + + if (disciplinesConfirmCopyButton) { + disciplinesConfirmCopyButton.addEventListener('click', disciplinesCopyObjectives); + } + const clearCheckboxs = () => { checkedExperienceFields().forEach(checkboxInput => { checkboxInput.checked = false; @@ -67,6 +128,8 @@ document.addEventListener('DOMContentLoaded', () => { $('input.grade_ids').select2("val", ""); }; + clearGrades(); + $('[name="experience_fields[]"]').change(function() { if ($(this).is(':checked')) { $(this).closest('.row').find('.grades').show(); @@ -80,4 +143,14 @@ document.addEventListener('DOMContentLoaded', () => { clearCheckboxs(); clearGrades(); }); + + $('#disciplines-modal').on('show.bs.modal', function() { + clearCheckboxs(); + clearGrades(); + }); + + $('#experience-modal').on('show.bs.modal', function() { + clearCheckboxs(); + clearGrades(); + }); }); diff --git a/app/assets/javascripts/views/lessons_boards/new.js b/app/assets/javascripts/views/lessons_boards/new.js index c05a3d069..3ca1e9b7f 100644 --- a/app/assets/javascripts/views/lessons_boards/new.js +++ b/app/assets/javascripts/views/lessons_boards/new.js @@ -89,8 +89,11 @@ $(function () { $('#form-submit').submit(); }) - function checkExistsTeacherOnLessonNumberAndWeekday(teacher_discipline_classroom_id, lesson_number, weekday, classroom_id) { - if (_.isEmpty(teacher_discipline_classroom_id) || teacher_discipline_classroom_id === 'empty' || _.isEmpty(lesson_number) || _.isEmpty(weekday) || _.isEmpty(classroom_id)) { + function checkExistsTeacherOnLessonNumberAndWeekday(teacher_discipline_classroom_id, lesson_number, weekday, classroom_id, lessons_board_period) { + if ( + _.isEmpty(teacher_discipline_classroom_id) || teacher_discipline_classroom_id === 'empty' + || _.isEmpty(lesson_number) || _.isEmpty(weekday) || _.isEmpty(classroom_id) || _.isEmpty(lessons_board_period) + ) { return; } $.ajax({ @@ -99,6 +102,7 @@ $(function () { lesson_number: lesson_number, weekday: weekday, classroom_id: classroom_id, + period: lessons_board_period, format: 'json' }), success: function(data) { @@ -275,11 +279,13 @@ $(function () { async function getTeachersFromClassroom() { let classroom_id = $('#lessons_board_classroom_id').select2('val'); + let grade_id = $('#lessons_board_grade').select2('val'); if (!_.isEmpty(classroom_id)) { return $.ajax({ url: Routes.teachers_classroom_lessons_boards_pt_br_path({ classroom_id: classroom_id, + grade_id: grade_id, format: 'json' }), success: handleFetchTeachersFromTheClassroomSuccess, @@ -291,11 +297,13 @@ $(function () { function getTeachersFromClassroomAndPeriod() { let classroom_id = $('#lessons_board_classroom_id').select2('val'); let period = $('#lessons_board_period').select2('val'); + let grade_id = $('#lessons_board_grade').select2('val'); if (!_.isEmpty(classroom_id)) { $.ajax({ url: Routes.teachers_classroom_period_lessons_boards_pt_br_path({ classroom_id: classroom_id, + grade_id: grade_id, period: period, format: 'json' }), @@ -366,8 +374,9 @@ $(function () { let lesson_number = $(this).closest('tr').find('[data-id="lesson_number"]').val(); let weekday = $(this).closest('td').find('[data-id="weekday"]').val(); let classroom_id = $('#lessons_board_classroom_id').select2('val'); + let period = $('#lessons_board_period').select2('val'); - checkExistsTeacherOnLessonNumberAndWeekday(teacher_discipline_classroom_id, lesson_number, weekday, classroom_id); + checkExistsTeacherOnLessonNumberAndWeekday(teacher_discipline_classroom_id, lesson_number, weekday, classroom_id, period); }) } diff --git a/app/assets/javascripts/views/school_term_recovery_diary_records/form.js b/app/assets/javascripts/views/school_term_recovery_diary_records/form.js index 0d1562dc9..86dbd0cab 100644 --- a/app/assets/javascripts/views/school_term_recovery_diary_records/form.js +++ b/app/assets/javascripts/views/school_term_recovery_diary_records/form.js @@ -192,5 +192,4 @@ $(function () { fetchExamRule(); loadDecimalMasks(); - checkPersistedDailyNote(); }); diff --git a/app/assets/javascripts/views/transfer_notes/form.js b/app/assets/javascripts/views/transfer_notes/form.js index 3e4ddf141..4fa63fae2 100644 --- a/app/assets/javascripts/views/transfer_notes/form.js +++ b/app/assets/javascripts/views/transfer_notes/form.js @@ -148,7 +148,9 @@ $(function () { var $equivalentLine = $('#current-notes-rows tr:eq('+i+')'); if($equivalentLine.length){ - $equivalentLine.find('input[id$=_note]').val(note > recovery_note ? note : recovery_note); + if (note.length) { + $equivalentLine.find('input[id$=_note]').val(note > recovery_note ? note : recovery_note); + } } }); diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index b4a6ae9d2..131a73f25 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -436,3 +436,20 @@ span.multiline { #header form .select-role { margin-top: 11px; } + +.student-name { + font-weight: bold; +} + +.student-name-cell { + background-color: #5D98CC !important; + color: white; +} + +.help-link { + text-decoration-line: underline; + color: #838A90; + float: right; + margin-right: 10px; + line-height: 34px; +} diff --git a/app/assets/stylesheets/educacao.css.erb b/app/assets/stylesheets/educacao.css.erb index 4783f7acf..aa358ad90 100644 --- a/app/assets/stylesheets/educacao.css.erb +++ b/app/assets/stylesheets/educacao.css.erb @@ -118,10 +118,6 @@ table#history tbody td.history-changes { padding: 2px 4px 0px 0px; } -.pre_registration_confirmation_student_code .popover { - width: 340px; -} - #registration-page #parents-fields { display: none; } diff --git a/app/assets/stylesheets/resources/frequency_in_batch.css b/app/assets/stylesheets/resources/frequency_in_batch.css index 9b1cd59b2..534a59803 100644 --- a/app/assets/stylesheets/resources/frequency_in_batch.css +++ b/app/assets/stylesheets/resources/frequency_in_batch.css @@ -1,33 +1,68 @@ -.collapsed { - width: 25px; +label.checkbox-frequency input[type=checkbox]:checked + i { + border-color: #28a745 !important; } -.checkbox-collapsed { - left: 3px; +label.checkbox-frequency input[type=checkbox]:checked + i::after { + color: #28a745; } -.checkbox-frequency-in-batch { - border-color: #28a745 !important; +label.checkbox-frequency input[type=checkbox]:checked:hover + i::after { + content: '\f00c' !important; } -.checkbox-frequency-in-batch::after { - color: #28a745 !important; +label.checkbox-frequency input[type=checkbox]:not(:checked) + i { + border-color: #dc3545 !important; } -.half-checked { +label.checkbox-frequency input[type=checkbox]:not(:checked) + i::after { + color: #dc3545 !important; + content: '\f00d' !important; + opacity: 1; +} + +label.checkbox-frequency.partial-absence input[type=checkbox] + i { border-color: #0779fb !important; } -.half-checked::after { +label.checkbox-frequency.partial-absence input[type=checkbox] + i::after { color: #0779fb !important; } -.unchecked { - border-color: #dc3545 !important; +label.checkbox-frequency.justified input[type=checkbox]:not(:checked) + i { + border-color: #0779fb !important; } -.smart-form .checkbox input:not(:checked) + i.unchecked:after { - content: '\f00d' !important; - opacity: 1; - color: #dc3545 !important; +label.checkbox-frequency.justified input[type=checkbox]:not(:checked) + i::after { + color: #0779fb !important; + content: 'FJ' !important; + font: bold 12px/19px Arial, sans-serif; + letter-spacing: -1px; +} + +.collapsed { + width: 25px; +} + +.frequency-legend { + display: flex; + padding: 20px; + flex-wrap: wrap; + justify-content: right; + align-items: center; + border-bottom: 1px solid #DDD; +} + +.frequency-legend-item { + display: flex; + margin-left: 10px; +} +.frequency-legend-item .checkbox { + display: flex; + margin: -2px 5px 0 0; + padding: 0; + width: 20px; + height: 20px; +} +.frequency-legend-button { + margin-left: 15px; } diff --git a/app/channels/application_cable/channel.rb b/app/channels/application_cable/channel.rb new file mode 100644 index 000000000..d67269728 --- /dev/null +++ b/app/channels/application_cable/channel.rb @@ -0,0 +1,4 @@ +module ApplicationCable + class Channel < ActionCable::Channel::Base + end +end diff --git a/app/channels/application_cable/connection.rb b/app/channels/application_cable/connection.rb new file mode 100644 index 000000000..0ff5442f4 --- /dev/null +++ b/app/channels/application_cable/connection.rb @@ -0,0 +1,4 @@ +module ApplicationCable + class Connection < ActionCable::Connection::Base + end +end diff --git a/app/controllers/absence_justifications_controller.rb b/app/controllers/absence_justifications_controller.rb index bc29db6ff..a2ca9903e 100644 --- a/app/controllers/absence_justifications_controller.rb +++ b/app/controllers/absence_justifications_controller.rb @@ -1,6 +1,7 @@ class AbsenceJustificationsController < ApplicationController before_action :require_current_teacher before_action :require_current_classroom + before_action :is_frequency_by_discipline?, only: [:new, :edit, :create, :update] has_scope :page, default: 1 has_scope :per, default: 10 @@ -8,8 +9,6 @@ class AbsenceJustificationsController < ApplicationController before_action :require_allow_to_modify_prev_years, only: [:create, :update, :destroy] def index - current_discipline = fetch_current_discipline - @classrooms = Classroom.where(id: current_user_classroom) author_type = (params[:search] || []).delete(:by_author) @@ -24,8 +23,6 @@ def index .filter(filtering_params(params[:search])) .includes(:students).uniq.ordered) - @absence_justifications = @absence_justifications.by_discipline_id(current_discipline) if current_discipline - if author_type.present? user_id = UserDiscriminatorService.new(current_user, current_user.current_role_is_admin_or_employee?).user_id @@ -48,16 +45,72 @@ def new authorize @absence_justification end - def create - @absence_justification = AbsenceJustification.new(resource_params) - @absence_justification.teacher = current_teacher - @absence_justification.user = current_user - @absence_justification.unity = current_unity - @absence_justification.school_calendar = current_school_calendar + def show + @absence_justification = AbsenceJustification + .includes(absence_justifications_students: [{ daily_frequency_students: { daily_frequency: [:discipline] } }, :student]) + .find(params[:id]) + .localized authorize @absence_justification - if @absence_justification.save + @absences_justified = [] + + @absence_justification.absence_justifications_students.each do |absence_justifications_students| + absence_justifications_students.daily_frequency_students.each do |daily_frequency_students| + @absences_justified << { + student_name: absence_justifications_students.student.name, + frequency_date: daily_frequency_students.daily_frequency.frequency_date.to_date.strftime('%d/%m/%Y'), + class_number: daily_frequency_students.daily_frequency.class_number || 0, + discipline_name: daily_frequency_students.daily_frequency.discipline&.description || 'Geral', + } + end + end + + @absences_justified = @absences_justified.sort { |a,b| a[:class_number] <=> b[:class_number] } + @absences_justified = @absences_justified.sort { |a,b| a[:frequency_date] <=> b[:frequency_date] } + @absences_justified = @absences_justified.sort { |a,b| a[:student_name] <=> b[:student_name] } + + fetch_students + end + + def create + class_numbers = params[:absence_justification][:class_number]&.split(',') + + if class_numbers.nil? || class_numbers.empty? + class_numbers = [nil] + end + + valid = class_numbers.map do |class_number| + @absence_justification = AbsenceJustification.new(resource_params) + @absence_justification.class_number = class_number + @absence_justification.teacher = current_teacher + @absence_justification.user = current_user + @absence_justification.unity = current_unity + @absence_justification.school_calendar = current_school_calendar + + authorize @absence_justification + + @absence_justification.save + end + + valid = valid.reject { |is_valid| is_valid }.empty? + + parameters = params[:absence_justification] + + # Se vier da tela de lançamento de frequência em lote, redireciona para ela + if valid && parameters[:start_date] && parameters[:end_date] + redirect_to form_daily_frequencies_in_batchs_path(start_date: parameters[:start_date], end_date: parameters[:end_date]) + # Se vier da tela de lançamento de diário de frequência + elsif valid && parameters[:frequency_date] + redirect_to form_daily_frequencies_path( + unity_id: parameters[:unity_id], + classroom_id: parameters[:classroom_id], + frequency_date: parameters[:frequency_date], + discipline_id: parameters[:discipline_id], + period: parameters[:period], + class_numbers: parameters[:class_numbers_original], + ) + elsif valid respond_with @absence_justification, location: absence_justifications_path else clear_invalid_dates @@ -78,7 +131,7 @@ def edit def update @absence_justification = AbsenceJustification.find(params[:id]) - @absence_justification.assign_attributes resource_params + @absence_justification.assign_attributes resource_params_edit @absence_justification.current_user = current_user @absence_justification.school_calendar = current_school_calendar if @absence_justification.persisted? && @absence_justification.school_calendar.blank? fetch_collections @@ -120,7 +173,7 @@ def resource_params :absence_date_end, :unity_id, :classroom_id, - :discipline_ids, + :period, absence_justification_attachments_attributes: [ :id, :attachment, @@ -129,11 +182,21 @@ def resource_params ) parameters[:student_ids] = parameters[:student_ids].split(',') - parameters[:discipline_ids] = parameters[:discipline_ids].split(',') parameters end + def resource_params_edit + params.require(:absence_justification).permit( + :justification, + absence_justification_attachments_attributes: [ + :id, + :attachment, + :_destroy + ] + ) + end + private def filtering_params(params) @@ -149,7 +212,7 @@ def filtering_params(params) def fetch_students student_enrollments = StudentEnrollmentsList.new( classroom: current_user_classroom, - discipline: fetch_current_discipline, + discipline: nil, search_type: :by_date, date: Date.current ).student_enrollments @@ -167,15 +230,15 @@ def configuration @configuration ||= IeducarApiConfiguration.current end - def fetch_current_discipline - frequency_type_definer = FrequencyTypeDefiner.new(current_user_classroom, current_teacher) - frequency_type_definer.define! + def is_frequency_by_discipline? + if @is_frequency_by_discipline.nil? + frequency_type_definer = FrequencyTypeDefiner.new(current_user_classroom, current_teacher) + frequency_type_definer.define! - if frequency_type_definer.frequency_type == FrequencyTypes::BY_DISCIPLINE - current_user_discipline - else - nil + @is_frequency_by_discipline = frequency_type_definer.frequency_type == FrequencyTypes::BY_DISCIPLINE end + + @is_frequency_by_discipline end def clear_invalid_dates diff --git a/app/controllers/api/v2/daily_frequency_students_controller.rb b/app/controllers/api/v2/daily_frequency_students_controller.rb index ca4b39326..ed6cc073c 100644 --- a/app/controllers/api/v2/daily_frequency_students_controller.rb +++ b/app/controllers/api/v2/daily_frequency_students_controller.rb @@ -22,15 +22,38 @@ def update_or_create ) creator.find_or_create! + frequency_date = params[:frequency_date] + student_id = params[:student_id] + daily_frequency = creator.daily_frequencies[0] + absence_justifications = AbsenceJustifiedOnDate.call( + students: [params[:student_id]], + date: frequency_date, + end_date: frequency_date, + classroom: params[:classroom_id], + period: period + ) + if daily_frequency begin daily_frequency_student = DailyFrequencyStudent.find_or_initialize_by( daily_frequency_id: daily_frequency.id, - student_id: params[:student_id] + student_id: student_id ) - daily_frequency_student.assign_attributes(present: params[:present], active: true) + + absence_justification = absence_justifications[student_id] || {} + absence_justification = absence_justification[frequency_date] || {} + absence_justification_student_id = absence_justification[0] || absence_justification[daily_frequency.class_number] + + if absence_justification_student_id + daily_frequency_student.present = false + daily_frequency_student.absence_justification_student_id = absence_justification_student_id + elsif + daily_frequency_student.present = params[:present] + end + + daily_frequency_student.active = true daily_frequency_student.save rescue ActiveRecord::RecordNotUnique retry diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index b87f7c607..ff3e9d758 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -9,18 +9,18 @@ class ApplicationController < ActionController::Base include BootstrapFlashHelper include Pundit - skip_around_filter :set_locale_from_url + skip_around_action :set_locale_from_url around_action :handle_customer before_action :set_honeybadger_context - around_filter :set_user_current - around_filter :set_thread_origin_type + around_action :set_user_current + around_action :set_thread_origin_type respond_to :html, :json # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. #protect_from_forgery with: :exception - protect_from_forgery with: :null_session + protect_from_forgery with: :null_session, prepend: true before_action :check_entity_status before_action :authenticate_user! diff --git a/app/controllers/avaliation_recovery_diary_records_controller.rb b/app/controllers/avaliation_recovery_diary_records_controller.rb index 2abe4ba78..24413941d 100644 --- a/app/controllers/avaliation_recovery_diary_records_controller.rb +++ b/app/controllers/avaliation_recovery_diary_records_controller.rb @@ -44,7 +44,7 @@ def new def create @avaliation_recovery_diary_record = AvaliationRecoveryDiaryRecord.new.localized - @avaliation_recovery_diary_record.assign_attributes(resource_params) + @avaliation_recovery_diary_record.assign_attributes(resource_params.to_h) @avaliation_recovery_diary_record.recovery_diary_record.teacher_id = current_teacher_id authorize @avaliation_recovery_diary_record @@ -80,7 +80,7 @@ def edit def update @avaliation_recovery_diary_record = AvaliationRecoveryDiaryRecord.find(params[:id]).localized - @avaliation_recovery_diary_record.assign_attributes(resource_params) + @avaliation_recovery_diary_record.assign_attributes(resource_params.to_h) @avaliation_recovery_diary_record.recovery_diary_record.teacher_id = current_teacher_id @avaliation_recovery_diary_record.recovery_diary_record.current_user = current_user @@ -107,7 +107,7 @@ def history def destroy @avaliation_recovery_diary_record = AvaliationRecoveryDiaryRecord.find(params[:id]) - @avaliation_recovery_diary_record.destroy + @avaliation_recovery_diary_record.recovery_diary_record.destroy respond_with @avaliation_recovery_diary_record, location: avaliation_recovery_diary_records_path end diff --git a/app/controllers/avaliation_recovery_lowest_notes_controller.rb b/app/controllers/avaliation_recovery_lowest_notes_controller.rb index 6927e5714..841c94757 100644 --- a/app/controllers/avaliation_recovery_lowest_notes_controller.rb +++ b/app/controllers/avaliation_recovery_lowest_notes_controller.rb @@ -52,7 +52,7 @@ def new def create @lowest_note_recovery = AvaliationRecoveryLowestNote.new.localized - @lowest_note_recovery.assign_attributes(resource_params) + @lowest_note_recovery.assign_attributes(resource_params.to_h) @lowest_note_recovery.step_number = @lowest_note_recovery.step.try(:step_number) @lowest_note_recovery.recovery_diary_record.teacher_id = current_teacher_id @@ -85,7 +85,7 @@ def edit def update @lowest_note_recovery = AvaliationRecoveryLowestNote.find(params[:id]).localized - @lowest_note_recovery.assign_attributes(resource_params) + @lowest_note_recovery.assign_attributes(resource_params.to_h) @lowest_note_recovery.recovery_diary_record.teacher_id = current_teacher_id @lowest_note_recovery.recovery_diary_record.current_user = current_user @@ -103,7 +103,7 @@ def update def destroy @lowest_note_recovery = AvaliationRecoveryLowestNote.find(params[:id]) - @lowest_note_recovery.destroy + @lowest_note_recovery.recovery_diary_record.destroy respond_with @lowest_note_recovery, location: avaliation_recovery_lowest_notes_path end diff --git a/app/controllers/avaliations_controller.rb b/app/controllers/avaliations_controller.rb index a53bf276c..d8e5c9c53 100644 --- a/app/controllers/avaliations_controller.rb +++ b/app/controllers/avaliations_controller.rb @@ -71,9 +71,10 @@ def multiple_classrooms def create_multiple_classrooms authorize Avaliation.new + params_avaliation_multiple = params[:avaliation_multiple_creator_form].to_unsafe_h @avaliation_multiple_creator_form = AvaliationMultipleCreatorForm.new( - params[:avaliation_multiple_creator_form].merge(teacher_id: current_teacher_id) + params_avaliation_multiple.merge(teacher_id: current_teacher_id) ) if @avaliation_multiple_creator_form.save @@ -218,7 +219,6 @@ def resource_params :classroom_id, :discipline_id, :test_date, - :classes, :description, :test_setting_test_id, :weight, diff --git a/app/controllers/complementary_exams_controller.rb b/app/controllers/complementary_exams_controller.rb index 2e545b515..c46e04236 100644 --- a/app/controllers/complementary_exams_controller.rb +++ b/app/controllers/complementary_exams_controller.rb @@ -33,7 +33,7 @@ def new def create @complementary_exam = ComplementaryExam.new.localized - @complementary_exam.assign_attributes(resource_params) + @complementary_exam.assign_attributes(resource_params.to_h) @complementary_exam.step_number = @complementary_exam.step.try(:step_number) @complementary_exam.teacher_id = current_teacher_id @@ -56,7 +56,7 @@ def edit def update @complementary_exam = ComplementaryExam.find(params[:id]).localized - @complementary_exam.assign_attributes(resource_params) + @complementary_exam.assign_attributes(resource_params.to_h) @complementary_exam.teacher_id = current_teacher_id @complementary_exam.current_user = current_user @@ -67,12 +67,14 @@ def update if @complementary_exam.save respond_with @complementary_exam, location: complementary_exams_path else + reload_students_list render :edit end end def destroy @complementary_exam = ComplementaryExam.find(params[:id]) + @complementary_exam.step_id = @complementary_exam.step.try(:id) @complementary_exam.destroy respond_with @complementary_exam, location: complementary_exams_path end @@ -139,8 +141,7 @@ def unities helper_method :unities def classrooms - @classrooms ||= Classroom.where(id: current_user_classroom) - .ordered + @classrooms ||= Classroom.where(id: current_user_classroom).ordered end helper_method :classrooms @@ -156,14 +157,17 @@ def steps def fetch_student_enrollments return unless @complementary_exam.complementary_exam_setting && @complementary_exam.recorded_at - StudentEnrollmentsList.new(classroom: @complementary_exam.classroom, - discipline: @complementary_exam.discipline, - score_type: StudentEnrollmentScoreTypeFilters::NUMERIC, - show_inactive: false, - with_recovery_note_in_step: @complementary_exam.complementary_exam_setting.affected_score == AffectedScoreTypes::STEP_RECOVERY_SCORE, - date: @complementary_exam.recorded_at, - search_type: :by_date) - .student_enrollments + + @student_enrollments ||= StudentEnrollmentsList.new( + classroom: @complementary_exam.classroom, + discipline: @complementary_exam.discipline, + score_type: StudentEnrollmentScoreTypeFilters::NUMERIC, + show_inactive: false, + with_recovery_note_in_step: @complementary_exam.complementary_exam_setting.affected_score == AffectedScoreTypes::STEP_RECOVERY_SCORE, + date: @complementary_exam.recorded_at, + status_attending: true, + search_type: :by_date + ).student_enrollments end def reload_students_list diff --git a/app/controllers/conceptual_exams_controller.rb b/app/controllers/conceptual_exams_controller.rb index 87bcf1c32..f24b191d0 100644 --- a/app/controllers/conceptual_exams_controller.rb +++ b/app/controllers/conceptual_exams_controller.rb @@ -295,7 +295,7 @@ def disciplines_with_assignment end def fetch_collections - if @conceptual_exam.step_id.present? + if @conceptual_exam.step_id.present? && @conceptual_exam.student_id.present? fetch_unities_classrooms_disciplines_by_teacher fetch_students end diff --git a/app/controllers/custom_rounding_tables_controller.rb b/app/controllers/custom_rounding_tables_controller.rb index 9ed611be0..b9afe0eea 100644 --- a/app/controllers/custom_rounding_tables_controller.rb +++ b/app/controllers/custom_rounding_tables_controller.rb @@ -19,12 +19,16 @@ def new value.action = RoundingTableAction::NONE end + @custom_rounding_table_values = @custom_rounding_table.custom_rounding_table_values + authorize @custom_rounding_table end def edit @custom_rounding_table = CustomRoundingTable.find(params[:id]) + @custom_rounding_table_values = @custom_rounding_table.custom_rounding_table_values.ordered_asc + authorize @avaliation_recovery_diary_record fetch_filtered_grades diff --git a/app/controllers/daily_frequencies_controller.rb b/app/controllers/daily_frequencies_controller.rb index 23c182a89..9bdd31c44 100644 --- a/app/controllers/daily_frequencies_controller.rb +++ b/app/controllers/daily_frequencies_controller.rb @@ -1,7 +1,7 @@ class DailyFrequenciesController < ApplicationController before_action :require_current_classroom before_action :require_teacher - before_action :set_number_of_classes, only: [:new, :create, :edit_multiple] + before_action :set_number_of_classes, only: [:new, :form, :create, :edit_multiple] before_action :require_allow_to_modify_prev_years, only: [:create, :destroy_multiple] before_action :require_valid_daily_frequency_classroom @@ -15,6 +15,18 @@ def new authorize @daily_frequency end + def form + redirect_to edit_multiple_daily_frequencies_path( + daily_frequency: { + unity_id: params[:unity_id], + classroom_id: params[:classroom_id], + frequency_date: params[:frequency_date], + discipline_id: params[:discipline_id], + period: params[:period], + }, + class_numbers: params[:class_numbers].split(',').sort + ) + end def create @daily_frequency = DailyFrequency.new(daily_frequency_params) @daily_frequency.school_calendar = current_school_calendar @@ -30,9 +42,9 @@ def create return if @frequency_type == FrequencyTypes::BY_DISCIPLINE && !(validate_class_numbers && validate_discipline) redirect_to edit_multiple_daily_frequencies_path( - daily_frequency: daily_frequency_params, - class_numbers: @class_numbers - ) + daily_frequency: daily_frequency_params, + class_numbers: @class_numbers + ) else render :new end @@ -48,19 +60,37 @@ def edit_multiple authorize @daily_frequency @students = [] + @students_list = [] @any_exempted_from_discipline = false @any_inactive_student = false @any_in_active_search = false @dependence_students = false + @absence_justification = AbsenceJustification.new + @absence_justification.school_calendar = current_school_calendar student_enrollment_ids = fetch_enrollment_classrooms.map { |student_enrollment| student_enrollment[:student_enrollment_id] } - dependencies = student_has_dependence?(student_enrollment_ids, @daily_frequency.discipline) - exempt = student_has_exempt_from_discipline?(@daily_frequency, student_enrollment_ids) - active = active_student_on_date?(@daily_frequency.frequency_date, student_enrollment_ids) + student_ids = fetch_enrollment_classrooms.map { |student_enrollment| + student_enrollment[:student].id + } + + step = @daily_frequency.school_calendar.step(@daily_frequency.frequency_date).try(:to_number) + discipline = @daily_frequency.discipline + frequency_date = @daily_frequency.frequency_date + + dependencies = StudentsInDependency.call(student_enrollments: student_enrollment_ids, disciplines: discipline) + exempt = StudentsExemptFromDiscipline.call(student_enrollments: student_enrollment_ids, discipline: discipline, step: step) + active = ActiveStudentsOnDate.call(student_enrollments: student_enrollment_ids, date: frequency_date) active_search = in_active_searches(student_enrollment_ids, @daily_frequency.frequency_date) + absence_justifications = AbsenceJustifiedOnDate.call( + students: student_ids, + date: frequency_date, + end_date: frequency_date, + classroom: @daily_frequency.classroom_id, + period: @period + ) fetch_enrollment_classrooms.each do |enrollment_classroom| student = enrollment_classroom[:student] @@ -68,6 +98,7 @@ def edit_multiple activated_student = active.include?(enrollment_classroom[:student_enrollment_classroom_id]) has_dependence = dependencies[student_enrollment_id] ? true : false has_exempted = exempt[student_enrollment_id] ? true : false + absence_justification = absence_justifications[student.id] || {} in_active_search = active_search[@daily_frequency.frequency_date]&.include?(student_enrollment_id) sequence = enrollment_classroom[:sequence] if show_inactive_enrollments @@ -77,12 +108,14 @@ def edit_multiple @any_inactive_student ||= !activated_student if activated_student || show_inactive_enrollments + @students_list << student @students << { student: student, dependence: has_dependence, active: activated_student, exempted_from_discipline: has_exempted, in_active_search: in_active_search, + absence_justification: absence_justification, sequence: sequence } end @@ -109,7 +142,7 @@ def create_or_update_multiple daily_frequency_record = nil daily_frequency_attributes = daily_frequency_params daily_frequencies_attributes = daily_frequencies_params - receive_email_confirmation = ActiveRecord::Type::Boolean.new.type_cast_from_user( + receive_email_confirmation = ActiveRecord::Type::Boolean.new.cast( params[:daily_frequency][:receive_email_confirmation] ) @@ -137,6 +170,31 @@ def create_or_update_multiple daily_frequency_record, daily_frequency_students_params ) + + daily_frequency_students_params[:students_attributes].each_value do |daily_frequency_student| + if daily_frequency_student[:absence_justification_student_id].to_i.eql?(-1) + params = { + student_ids: [daily_frequency_student[:student_id]], + absence_date: daily_frequency_attributes[:frequency_date], + justification: nil, + absence_date_end: daily_frequency_attributes[:frequency_date], + unity_id: daily_frequency_attributes[:unity_id], + classroom_id: daily_frequency_attributes[:classroom_id], + class_number: daily_frequency_students_params[:class_number], + } + + absence_justification = AbsenceJustification.new(params) + absence_justification.teacher = current_teacher + absence_justification.user = current_user + absence_justification.school_calendar = current_school_calendar + absence_justification.period = daily_frequency_attributes[:period] + + absence_justification.save + + daily_frequency_student[:absence_justification_student_id] = absence_justification.absence_justifications_students.first.id + end + end + daily_frequency_record.assign_attributes(daily_frequency_students_params) daily_frequency_record.save! end @@ -156,7 +214,8 @@ def create_or_update_multiple if receive_email_confirmation ReceiptMailer.delay.notify_daily_frequency_success( - current_user, + current_user.first_name, + current_user.email, "#{request.base_url}#{edit_multiple_daily_frequencies_path}", daily_frequency_attributes[:frequency_date].to_date.strftime('%d/%m/%Y'), daily_frequency_record.classroom.description, @@ -221,7 +280,7 @@ def daily_frequencies_params daily_frequencies: [ :class_number, students_attributes: [ - [:id, :daily_frequency_id, :student_id, :present, :dependence, :active, :type_of_teaching] + [:id, :daily_frequency_id, :student_id, :present, :dependence, :active, :type_of_teaching, :absence_justification_student_id] ] ] ).require(:daily_frequencies) @@ -353,19 +412,6 @@ def fetch_enrollment_classrooms ).student_enrollment_classrooms end - def active_student_on_date?(frequency_date, student_enrollments) - inactive_on_date = {} - student_enrollment_classrooms = StudentEnrollmentClassroom.by_student_enrollment(student_enrollments) - .by_date(frequency_date) - - student_enrollment_classrooms.each do |enrollment_classroom| - inactive_on_date[enrollment_classroom.id] ||= [] - inactive_on_date[enrollment_classroom.id] << frequency_date - end - - inactive_on_date - end - def set_number_of_classes @number_of_classes = current_school_calendar.number_of_classes end @@ -381,45 +427,6 @@ def in_active_searches(student_enrollment_ids, frequency_date) @in_active_searches ||= ActiveSearch.new.enrollments_in_active_search?(student_enrollment_ids, frequency_date) end - def student_has_dependence?(student_enrollments, discipline) - return {} unless discipline - - student_enrollment_dependencies = StudentEnrollmentDependence.where( - student_enrollment_id: student_enrollments, - discipline_id: discipline - ) - - dependencies = {} - - student_enrollment_dependencies.each do |student_enrollment_dependence| - student_enrollment_id = student_enrollment_dependence.student_enrollment_id - discipline_id = student_enrollment_dependence.discipline_id - - dependencies[student_enrollment_id] ||= [] - dependencies[student_enrollment_id] << discipline_id - end - dependencies - end - - def student_has_exempt_from_discipline?(daily_frequency, student_enrollments) - return {} if daily_frequency.discipline_id.blank? - - discipline_id = daily_frequency.discipline_id - exempts_from_discipline = {} - - step = daily_frequency.school_calendar.step(daily_frequency.frequency_date).try(:to_number) - - StudentEnrollmentExemptedDiscipline.by_discipline(discipline_id) - .by_step_number(step) - .by_student_enrollment(student_enrollments) - .includes(student_enrollment: [:student]) - .each do |student_exempted| - exempts_from_discipline[student_exempted.student_enrollment_id] ||= step - end - - exempts_from_discipline - end - def class_numbers_from_params daily_frequencies_params.map { |daily_frequency_students_params| daily_frequency_students_params.second[:class_number].presence diff --git a/app/controllers/daily_frequencies_in_batchs_controller.rb b/app/controllers/daily_frequencies_in_batchs_controller.rb index b90fd034e..77439a6f2 100644 --- a/app/controllers/daily_frequencies_in_batchs_controller.rb +++ b/app/controllers/daily_frequencies_in_batchs_controller.rb @@ -2,24 +2,35 @@ class DailyFrequenciesInBatchsController < ApplicationController before_action :require_current_classroom before_action :require_teacher before_action :require_allocation_on_lessons_board - before_action :set_number_of_classes, only: [:new, :create, :create_or_update_multiple] + before_action :set_number_of_classes, only: [:new, :form, :create, :create_or_update_multiple] before_action :authorize_daily_frequency, only: [:new, :create, :create_or_update_multiple] before_action :require_allow_to_modify_prev_years, only: [:create, :destroy_multiple] before_action :require_valid_daily_frequency_classroom + before_action :require_valid_dates, only: [:create, :form] def new @frequency_type = current_frequency_type(current_user_classroom) end - def create + # TODO método duplicado para ser acessado via GET, unificar + def form start_date = params[:frequency_in_batch_form][:start_date].to_date end_date = params[:frequency_in_batch_form][:end_date].to_date - return redirect_to new_daily_frequencies_in_batch_path if invalid_dates?(start_date, end_date) + @dates = [*start_date..end_date] + + return unless view_data + + render :create_or_update_multiple + end + + def create + start_date = params[:frequency_in_batch_form][:start_date].to_date + end_date = params[:frequency_in_batch_form][:end_date].to_date @dates = [*start_date..end_date] - view_data + return unless view_data render :create_or_update_multiple end @@ -27,7 +38,7 @@ def create def create_or_update_multiple daily_frequency_attributes = daily_frequency_in_batchs_params daily_frequencies_attributes = daily_frequencies_in_batch_params - receive_email_confirmation = ActiveRecord::Type::Boolean.new.type_cast_from_user( + receive_email_confirmation = ActiveRecord::Type::Boolean.new.cast( daily_frequency_attributes[:frequency_in_batch_form][:receive_email_confirmation] ) dates = [] @@ -54,9 +65,33 @@ def create_or_update_multiple daily_frequency_students_params[:students_attributes].each_value do |student_attributes| away = 0 daily_frequency_student = daily_frequency.build_or_find_by_student(student_attributes[:student_id]) + + if student_attributes[:absence_justification_student_id].to_i.eql?(-1) + params = { + student_ids: [student_attributes[:student_id]], + absence_date: daily_frequency_data[:frequency_date], + justification: nil, + absence_date_end: daily_frequency_data[:frequency_date], + unity_id: daily_frequency_data[:unity_id], + classroom_id: daily_frequency_data[:classroom_id], + class_number: daily_frequency_data[:class_number], + } + + absence_justification = AbsenceJustification.new(params) + absence_justification.teacher = current_teacher + absence_justification.user = current_user + absence_justification.school_calendar = current_school_calendar + absence_justification.period = daily_frequency_data[:period] + + absence_justification.save + + student_attributes[:absence_justification_student_id] = absence_justification.absence_justifications_students.first.id + end + daily_frequency_student.present = student_attributes[:present].blank? ? away : student_attributes[:present] daily_frequency_student.type_of_teaching = student_attributes[:type_of_teaching] daily_frequency_student.active = student_attributes[:active] + daily_frequency_student.absence_justification_student_id = student_attributes[:absence_justification_student_id] daily_frequency_student.save! end @@ -76,7 +111,8 @@ def create_or_update_multiple if receive_email_confirmation ReceiptMailer.delay.notify_daily_frequency_in_batch_success( - current_user, + current_user.first_name, + current_user.email, "#{request.base_url}#{create_or_update_multiple_daily_frequencies_in_batchs_path}", dates, Classroom.find(daily_frequency_attributes[:classroom_id].to_i).description, @@ -125,6 +161,8 @@ def history_multiple private + + def authorize_daily_frequency @daily_frequency = DailyFrequency.new.localized @@ -139,15 +177,24 @@ def view_data @frequency_type = current_frequency_type(@classroom) params['dates'] = allocation_dates(@dates) @frequency_form = FrequencyInBatchForm.new - - + @absence_justification = AbsenceJustification.new + @absence_justification.school_calendar = current_school_calendar @students = [] + @students_list = [] student_enrollments_ids = [] student_ids = [] dates = [] params['dates'].each { |date| dates << date['date'] } + if dates.empty? + flash.now[:warning] = t('daily_frequencies_in_batchs.create_or_update_multiple.no_school_day') + + render :new + + return false + end + fetch_student_enrollments.each do |student_enrollment| student_enrollments_ids << student_enrollment.id student = student_enrollment.student @@ -159,6 +206,7 @@ def view_data next if student.blank? + @students_list << student @students << { student: student, type_of_teaching: type_of_teaching @@ -170,7 +218,7 @@ def view_data render :new - return + return false end dependences = student_has_dependence(student_enrollments_ids, dates) @@ -178,6 +226,14 @@ def view_data 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) + @absence_justifications = AbsenceJustifiedOnDate.call( + students: student_ids, + date: dates.first, + end_date: dates.last, + classroom: current_user_classroom.id, + period: @period + ) + @additional_data = additional_data(dates, student_ids, dependences, inactives_on_date, exempteds_from_discipline, active_searchs) end @@ -251,7 +307,7 @@ def allocation_dates(dates) allocations.by_period(@period) if @period.present? - valid_day = SchoolDayChecker.new(current_school_calendar, date, nil, nil, nil).school_day? + valid_day = SchoolDayChecker.new(current_school_calendar, date, nil, nil, nil).day_allows_entry? next if allocations.empty? || !valid_day @@ -322,7 +378,7 @@ def daily_frequencies_in_batch_params :date, :class_number, students_attributes: [ - :id, :daily_frequency_id, :student_id, :present, :active, :dependence, :type_of_teaching + :id, :daily_frequency_id, :student_id, :present, :active, :dependence, :type_of_teaching, :absence_justification_student_id ] ] ) @@ -519,5 +575,14 @@ def invalid_dates?(start_date, end_date) true end end + + def require_valid_dates + start_date = params[:frequency_in_batch_form][:start_date].to_date + end_date = params[:frequency_in_batch_form][:end_date].to_date + + if invalid_dates?(start_date, end_date) + redirect_to(new_daily_frequencies_in_batch_path) and return + end + end end diff --git a/app/controllers/daily_notes_controller.rb b/app/controllers/daily_notes_controller.rb index 6123393da..1fcec2d45 100644 --- a/app/controllers/daily_notes_controller.rb +++ b/app/controllers/daily_notes_controller.rb @@ -87,7 +87,7 @@ def edit def update @daily_note = DailyNote.find(params[:id]).localized - @daily_note.assign_attributes resource_params + @daily_note.assign_attributes(resource_params.to_h) authorize @daily_note diff --git a/app/controllers/descriptive_exams_controller.rb b/app/controllers/descriptive_exams_controller.rb index a0f7b7d84..35ea09a3b 100644 --- a/app/controllers/descriptive_exams_controller.rb +++ b/app/controllers/descriptive_exams_controller.rb @@ -235,9 +235,7 @@ def set_opinion_types end if @opinion_types.blank? - redirect_with_message(t('descriptive_exams.new.exam_rule_not_allow_descriptive_exam')) - - return + redirect_with_message(t('descriptive_exams.new.exam_rule_not_allow_descriptive_exam')) && return end @opinion_type = params.dig('descriptive_exam', 'opinion_type') diff --git a/app/controllers/discipline_content_records_controller.rb b/app/controllers/discipline_content_records_controller.rb index eefe77a9a..6e5af9ac9 100644 --- a/app/controllers/discipline_content_records_controller.rb +++ b/app/controllers/discipline_content_records_controller.rb @@ -4,7 +4,7 @@ class DisciplineContentRecordsController < ApplicationController before_action :require_current_teacher before_action :require_allow_to_modify_prev_years, only: [:create, :update, :destroy, :clone] - before_action :set_number_of_classes, only: [:new, :create, :edit, :show] + before_action :set_number_of_classes before_action :allow_class_number, only: [:index, :new, :edit, :show] def index @@ -66,7 +66,7 @@ def create return render :new if @discipline_content_record.invalid? end - multiple_content_creator = CreateMultipleContents.new(@class_numbers, @discipline_content_record) + multiple_content_creator = CreateOrUpdateMultipleContents.new(@class_numbers, @discipline_content_record, true) if multiple_content_creator.call respond_with @discipline_content_record, location: discipline_content_records_path @@ -100,10 +100,37 @@ def update authorize @discipline_content_record - if @discipline_content_record.save - respond_with @discipline_content_record, location: discipline_content_records_path + if allow_class_number + @new_discipline_content_record = @discipline_content_record.dup + @new_discipline_content_record.content_record = @discipline_content_record.content_record.dup + @class_numbers = class_numbers_without_current( + resource_params[:class_number], + @discipline_content_record.class_number + ) + + @class_numbers.each do |class_number| + @new_discipline_content_record.class_number = class_number + + if @new_discipline_content_record.invalid? + flash[:error] = I18n.t('activerecord.errors.models.discipline_content_record.not_editable_in_batch', lesson_number: class_number) + + return render :edit + end + end + + service = CreateOrUpdateMultipleContents.new(@class_numbers, @discipline_content_record, false) + + if service.call + respond_with @discipline_content_record, location: discipline_content_records_path + else + render :new + end else - render :edit + if @discipline_content_record.save + respond_with @discipline_content_record, location: discipline_content_records_path + else + render :edit + end end end @@ -135,6 +162,12 @@ def clone private + def class_numbers_without_current(class_numbers, current_class_number) + class_numbers.split(',').sort.reject do |class_number| + class_number == current_class_number.to_s + end + end + def allow_class_number @allow_class_number ||= GeneralConfiguration.first.allow_class_number_on_content_records end diff --git a/app/controllers/discipline_lesson_plans_controller.rb b/app/controllers/discipline_lesson_plans_controller.rb index f8c0dc7fd..8ac433ac5 100644 --- a/app/controllers/discipline_lesson_plans_controller.rb +++ b/app/controllers/discipline_lesson_plans_controller.rb @@ -5,6 +5,7 @@ class DisciplineLessonPlansController < ApplicationController before_action :require_current_classroom, only: [:new, :edit, :create, :update] before_action :require_current_teacher before_action :require_allow_to_modify_prev_years, only: [:create, :update, :destroy, :clone] + before_action :require_allows_copy_experience_fields_in_lesson_plans, only: [:new, :edit] def index params[:filter] ||= {} @@ -78,6 +79,18 @@ def create @discipline_lesson_plan.lesson_plan.objective_ids = objective_ids @discipline_lesson_plan.lesson_plan.teacher = current_teacher @discipline_lesson_plan.teacher_id = current_teacher_id + @discipline_lesson_plan.lesson_plan.activities = ActionController::Base.helpers.sanitize( + resource_params[:lesson_plan_attributes][:activities], tags: ['b', 'br', 'i', 'u', 'p'] + ) + @discipline_lesson_plan.lesson_plan.resources = ActionController::Base.helpers.sanitize( + resource_params[:lesson_plan_attributes][:resources], tags: ['b','br', 'i', 'u', 'p'] + ) + @discipline_lesson_plan.lesson_plan.evaluation = ActionController::Base.helpers.sanitize( + resource_params[:lesson_plan_attributes][:evaluation], tags: ['b', 'br', 'i', 'u', 'p'] + ) + @discipline_lesson_plan.lesson_plan.bibliography = ActionController::Base.helpers.sanitize( + resource_params[:lesson_plan_attributes][:bibliography], tags: ['b', 'br', 'i', 'u', 'p'] + ) authorize @discipline_lesson_plan @@ -100,6 +113,18 @@ def update @discipline_lesson_plan.lesson_plan.content_ids = content_ids @discipline_lesson_plan.lesson_plan.objective_ids = objective_ids @discipline_lesson_plan.teacher_id = current_teacher_id + @discipline_lesson_plan.lesson_plan.activities = ActionController::Base.helpers.sanitize( + resource_params[:lesson_plan_attributes][:activities], tags: ['b', 'br', 'i', 'u', 'p'] + ) + @discipline_lesson_plan.lesson_plan.resources = ActionController::Base.helpers.sanitize( + resource_params[:lesson_plan_attributes][:resources], tags: ['b','br', 'i', 'u', 'p'] + ) + @discipline_lesson_plan.lesson_plan.evaluation = ActionController::Base.helpers.sanitize( + resource_params[:lesson_plan_attributes][:evaluation], tags: ['b', 'br', 'i', 'u', 'p'] + ) + @discipline_lesson_plan.lesson_plan.bibliography = ActionController::Base.helpers.sanitize( + resource_params[:lesson_plan_attributes][:bibliography], tags: ['b', 'br', 'i', 'u', 'p'] + ) authorize @discipline_lesson_plan @@ -285,4 +310,8 @@ def fetch_disciplines Discipline.where(id: current_user_discipline) .ordered end + + def require_allows_copy_experience_fields_in_lesson_plans + @allows_copy_experience_fields_in_lesson_plans ||= GeneralConfiguration.current.allows_copy_experience_fields_in_lesson_plans + end end diff --git a/app/controllers/discipline_teaching_plans_controller.rb b/app/controllers/discipline_teaching_plans_controller.rb index 20e043a95..c34607edf 100644 --- a/app/controllers/discipline_teaching_plans_controller.rb +++ b/app/controllers/discipline_teaching_plans_controller.rb @@ -7,16 +7,14 @@ class DisciplineTeachingPlansController < ApplicationController before_action :require_allow_to_modify_prev_years, only: [:create, :update, :destroy] before_action :yearly_term_type_id, only: [:show, :edit, :new] before_action :require_current_classroom, only: [:index] + before_action :require_allows_copy_experience_fields_in_lesson_plans, only: [:new, :edit] + def index params[:filter] ||= {} - author_type = PlansAuthors::MY_PLANS if params[:filter].empty? + author_type = PlansAuthors::MY_PLANS if params[:filter].blank? author_type ||= (params[:filter] || []).delete(:by_author) - discipline = if current_user_discipline.grouper? - Discipline.where(knowledge_area_id: current_user_discipline.knowledge_area_id).all - else - current_user_discipline - end + discipline = current_user_discipline.grouper? ? Discipline.where(knowledge_area_id: current_user_discipline.knowledge_area_id).all : current_user_discipline @discipline_teaching_plans = apply_scopes( DisciplineTeachingPlan.includes(:discipline, @@ -24,17 +22,11 @@ def index .by_discipline(discipline) .by_unity(current_unity) .by_year(current_school_year) + .order('teaching_plans.school_term_type_step_id') ) - unless current_user_is_employee_or_administrator? - @discipline_teaching_plans = @discipline_teaching_plans.by_grade(current_user_classroom.grades.pluck(:id)) - .by_discipline(discipline) - end - - if author_type.present? - @discipline_teaching_plans = @discipline_teaching_plans.by_author(author_type, current_teacher) - params[:filter][:by_author] = author_type - end + @discipline_teaching_plans = filter_by_grade(@discipline_teaching_plans) unless current_user_is_employee_or_administrator? + @discipline_teaching_plans = filter_by_author(@discipline_teaching_plans, author_type) if author_type.present? authorize @discipline_teaching_plans @@ -43,8 +35,7 @@ def index end def show - @discipline_teaching_plan = DisciplineTeachingPlan.find(params[:id]) - .localized + @discipline_teaching_plan = DisciplineTeachingPlan.find(params[:id]).localized authorize @discipline_teaching_plan @@ -79,6 +70,15 @@ def create @discipline_teaching_plan.teaching_plan.content_ids = content_ids @discipline_teaching_plan.teaching_plan.objective_ids = objective_ids @discipline_teaching_plan.teacher_id = current_teacher_id + @discipline_teaching_plan.teaching_plan.methodology = ActionController::Base.helpers.sanitize( + resource_params[:teaching_plan_attributes][:methodology], tags: ['b', 'br', 'i', 'u', 'p'] + ) + @discipline_teaching_plan.teaching_plan.evaluation = ActionController::Base.helpers.sanitize( + resource_params[:teaching_plan_attributes][:evaluation], tags: ['b', 'br', 'i', 'u', 'p'] + ) + @discipline_teaching_plan.teaching_plan.references = ActionController::Base.helpers.sanitize( + resource_params[:teaching_plan_attributes][:references], tags: ['b', 'br', 'i', 'u', 'p'] + ) authorize @discipline_teaching_plan @@ -93,8 +93,7 @@ def create end def edit - @discipline_teaching_plan = DisciplineTeachingPlan.find(params[:id]) - .localized + @discipline_teaching_plan = DisciplineTeachingPlan.find(params[:id]).localized authorize @discipline_teaching_plan @@ -103,11 +102,20 @@ def edit def update @discipline_teaching_plan = DisciplineTeachingPlan.find(params[:id]).localized - @discipline_teaching_plan.assign_attributes(resource_params) + @discipline_teaching_plan.assign_attributes(resource_params.to_h) @discipline_teaching_plan.teaching_plan.content_ids = content_ids @discipline_teaching_plan.teaching_plan.objective_ids = objective_ids @discipline_teaching_plan.teacher_id = current_teacher_id @discipline_teaching_plan.current_user = current_user + @discipline_teaching_plan.teaching_plan.methodology = ActionController::Base.helpers.sanitize( + resource_params[:teaching_plan_attributes][:methodology], tags: ['b', 'br', 'i', 'u', 'p'] + ) + @discipline_teaching_plan.teaching_plan.evaluation = ActionController::Base.helpers.sanitize( + resource_params[:teaching_plan_attributes][:evaluation], tags: ['b', 'br', 'i', 'u', 'p' ] + ) + @discipline_teaching_plan.teaching_plan.references = ActionController::Base.helpers.sanitize( + resource_params[:teaching_plan_attributes][:references], tags: ['b', 'br', 'i', 'u', 'p' ] + ) authorize @discipline_teaching_plan @@ -122,8 +130,7 @@ def update end def destroy - @discipline_teaching_plan = DisciplineTeachingPlan.find(params[:id]) - .localized + @discipline_teaching_plan = DisciplineTeachingPlan.find(params[:id]).localized authorize @discipline_teaching_plan @@ -191,6 +198,16 @@ def do_copy private + def filter_by_grade(plans) + plans.by_grade(current_user_classroom.grades.pluck(:id)) + end + + def filter_by_author(plans, author_type) + params[:filter][:by_author] = author_type + + plans.by_author(author_type, current_teacher) + end + def content_ids param_content_ids = params[:discipline_teaching_plan][:teaching_plan_attributes][:content_ids] || [] content_descriptions = params[:discipline_teaching_plan][:teaching_plan_attributes][:content_descriptions] || [] @@ -328,4 +345,8 @@ def fetch_disciplines def yearly_term_type_id @yearly_term_type_id ||= SchoolTermType.find_by(description: 'Anual').id end + + def require_allows_copy_experience_fields_in_lesson_plans + @allows_copy_experience_fields_in_lesson_plans ||= GeneralConfiguration.current.allows_copy_experience_fields_in_lesson_plans + end end diff --git a/app/controllers/final_recovery_diary_records_controller.rb b/app/controllers/final_recovery_diary_records_controller.rb index 3e0ba34ce..a40912b3d 100644 --- a/app/controllers/final_recovery_diary_records_controller.rb +++ b/app/controllers/final_recovery_diary_records_controller.rb @@ -33,7 +33,7 @@ def new def create @final_recovery_diary_record = FinalRecoveryDiaryRecord.new.localized - @final_recovery_diary_record.assign_attributes(resource_params) + @final_recovery_diary_record.assign_attributes(resource_params.to_h) @final_recovery_diary_record.recovery_diary_record.teacher_id = current_teacher_id @final_recovery_diary_record.recovery_diary_record.creator_type = 'final_recovery_diary_record' @@ -67,7 +67,7 @@ def edit def update @final_recovery_diary_record = FinalRecoveryDiaryRecord.find(params[:id]).localized - @final_recovery_diary_record.assign_attributes(resource_params) + @final_recovery_diary_record.assign_attributes(resource_params.to_h) @final_recovery_diary_record.recovery_diary_record.teacher_id = current_teacher_id @final_recovery_diary_record.recovery_diary_record.current_user = current_user @@ -87,7 +87,7 @@ def update def destroy @final_recovery_diary_record = FinalRecoveryDiaryRecord.find(params[:id]) - @final_recovery_diary_record.destroy + @final_recovery_diary_record.recovery_diary_record.destroy respond_with @final_recovery_diary_record, location: final_recovery_diary_records_path end diff --git a/app/controllers/general_configurations_controller.rb b/app/controllers/general_configurations_controller.rb index a01cbfea5..58cc8908f 100644 --- a/app/controllers/general_configurations_controller.rb +++ b/app/controllers/general_configurations_controller.rb @@ -55,8 +55,12 @@ def permitted_attributes :days_to_disable_access, :show_inactive_enrollments, :show_percentage_on_attendance_record_report, + :do_not_send_justified_absence, + :require_daily_activities_record, + :remove_lesson_plan_objectives, + :show_experience_fields, + :allows_copy_experience_fields_in_lesson_plans, :allow_class_number_on_content_records, - :require_daily_activities_record ) parameters[:types_of_teaching] = parameters[:types_of_teaching].split(',') diff --git a/app/controllers/knowledge_area_content_records_controller.rb b/app/controllers/knowledge_area_content_records_controller.rb index 3520be1f0..204d15b63 100644 --- a/app/controllers/knowledge_area_content_records_controller.rb +++ b/app/controllers/knowledge_area_content_records_controller.rb @@ -120,6 +120,7 @@ def content_ids def resource_params params.require(:knowledge_area_content_record).permit( :knowledge_area_ids, + :experience_fields, content_record_attributes: [ :id, :unity_id, diff --git a/app/controllers/knowledge_area_lesson_plans_controller.rb b/app/controllers/knowledge_area_lesson_plans_controller.rb index a2a3f48fe..4da30dc3d 100644 --- a/app/controllers/knowledge_area_lesson_plans_controller.rb +++ b/app/controllers/knowledge_area_lesson_plans_controller.rb @@ -80,6 +80,18 @@ def create @knowledge_area_lesson_plan.lesson_plan.objective_ids = objective_ids @knowledge_area_lesson_plan.lesson_plan.teacher = current_teacher @knowledge_area_lesson_plan.teacher_id = current_teacher_id + @knowledge_area_lesson_plan.lesson_plan.activities = ActionController::Base.helpers.sanitize( + resource_params[:lesson_plan_attributes][:activities], tags: ['b', 'br', 'i', 'u', 'p'] + ) + @knowledge_area_lesson_plan.lesson_plan.resources = ActionController::Base.helpers.sanitize( + resource_params[:lesson_plan_attributes][:resources], tags: ['b', 'br', 'i', 'u', 'p'] + ) + @knowledge_area_lesson_plan.lesson_plan.evaluation = ActionController::Base.helpers.sanitize( + resource_params[:lesson_plan_attributes][:evaluation], tags: ['b', 'br', 'i', 'u', 'p'] + ) + @knowledge_area_lesson_plan.lesson_plan.bibliography = ActionController::Base.helpers.sanitize( + resource_params[:lesson_plan_attributes][:bibliography], tags: ['b', 'br', 'i', 'u', 'p'] + ) authorize @knowledge_area_lesson_plan @@ -111,6 +123,18 @@ def update @knowledge_area_lesson_plan.lesson_plan.objective_ids = objective_ids @knowledge_area_lesson_plan.knowledge_area_ids = resource_params[:knowledge_area_ids].split(',') @knowledge_area_lesson_plan.teacher_id = current_teacher_id + @knowledge_area_lesson_plan.lesson_plan.activities = ActionController::Base.helpers.sanitize( + resource_params[:lesson_plan_attributes][:activities], tags: ['b', 'br', 'i', 'u', 'p'] + ) + @knowledge_area_lesson_plan.lesson_plan.resources = ActionController::Base.helpers.sanitize( + resource_params[:lesson_plan_attributes][:resources], tags: ['b', 'br', 'i', 'u', 'p'] + ) + @knowledge_area_lesson_plan.lesson_plan.evaluation = ActionController::Base.helpers.sanitize( + resource_params[:lesson_plan_attributes][:evaluation], tags: ['b', 'br', 'i', 'u', 'p'] + ) + @knowledge_area_lesson_plan.lesson_plan.bibliography = ActionController::Base.helpers.sanitize( + resource_params[:lesson_plan_attributes][:bibliography], tags: ['b', 'br', 'i', 'u', 'p'] + ) authorize @knowledge_area_lesson_plan diff --git a/app/controllers/knowledge_area_teaching_plans_controller.rb b/app/controllers/knowledge_area_teaching_plans_controller.rb index c435afe6d..6e726de0e 100644 --- a/app/controllers/knowledge_area_teaching_plans_controller.rb +++ b/app/controllers/knowledge_area_teaching_plans_controller.rb @@ -73,6 +73,15 @@ def create @knowledge_area_teaching_plan.teaching_plan.objective_ids = objective_ids @knowledge_area_teaching_plan.teacher_id = current_teacher_id @knowledge_area_teaching_plan.knowledge_area_ids = resource_params[:knowledge_area_ids].split(',') + @knowledge_area_teaching_plan.teaching_plan.methodology = ActionController::Base.helpers.sanitize( + resource_params[:teaching_plan_attributes][:methodology], tags: ['b', 'br', 'i', 'u', 'p'] + ) + @knowledge_area_teaching_plan.teaching_plan.evaluation = ActionController::Base.helpers.sanitize( + resource_params[:teaching_plan_attributes][:evaluation], tags: ['b', 'br', 'i', 'u', 'p' ] + ) + @knowledge_area_teaching_plan.teaching_plan.references = ActionController::Base.helpers.sanitize( + resource_params[:teaching_plan_attributes][:references], tags: ['b', 'br', 'i', 'u', 'p' ] + ) authorize @knowledge_area_teaching_plan @@ -96,12 +105,21 @@ def edit def update @knowledge_area_teaching_plan = KnowledgeAreaTeachingPlan.find(params[:id]).localized - @knowledge_area_teaching_plan.assign_attributes(resource_params) + @knowledge_area_teaching_plan.assign_attributes(resource_params.to_h) @knowledge_area_teaching_plan.teaching_plan.content_ids = content_ids @knowledge_area_teaching_plan.teaching_plan.objective_ids = objective_ids @knowledge_area_teaching_plan.knowledge_area_ids = resource_params[:knowledge_area_ids].split(',') @knowledge_area_teaching_plan.teacher_id = current_teacher_id @knowledge_area_teaching_plan.teaching_plan.teacher_id = current_teacher_id + @knowledge_area_teaching_plan.teaching_plan.methodology = ActionController::Base.helpers.sanitize( + resource_params[:teaching_plan_attributes][:methodology], tags: ['b', 'br', 'i', 'u', 'p'] + ) + @knowledge_area_teaching_plan.teaching_plan.evaluation = ActionController::Base.helpers.sanitize( + resource_params[:teaching_plan_attributes][:evaluation], tags: ['b', 'br', 'i', 'u', 'p' ] + ) + @knowledge_area_teaching_plan.teaching_plan.references = ActionController::Base.helpers.sanitize( + resource_params[:teaching_plan_attributes][:references], tags: ['b', 'br', 'i', 'u', 'p' ] + ) authorize @knowledge_area_teaching_plan diff --git a/app/controllers/knowledge_areas_controller.rb b/app/controllers/knowledge_areas_controller.rb index 8d98ab4d3..40138532d 100644 --- a/app/controllers/knowledge_areas_controller.rb +++ b/app/controllers/knowledge_areas_controller.rb @@ -15,7 +15,7 @@ def index disciplines_ids = Discipline.by_teacher_and_classroom(current_teacher.id, classroom_id) .ordered - .uniq + .distinct .map { |discipline| discipline.id } @knowledge_areas = @knowledge_areas.by_discipline_id(disciplines_ids) diff --git a/app/controllers/lessons_boards_controller.rb b/app/controllers/lessons_boards_controller.rb index 2447bfa71..bb433fd13 100644 --- a/app/controllers/lessons_boards_controller.rb +++ b/app/controllers/lessons_boards_controller.rb @@ -10,7 +10,7 @@ def index def show @lessons_board = resource - @teachers = teachers_to_select2(resource.classroom.id, resource.period) + @teachers = teachers_to_select2(resource.classroom.id, resource.period, resource.grade_id) ActiveRecord::Associations::Preloader.new.preload( @lessons_board, @@ -27,7 +27,7 @@ def new end def create - resource.assign_attributes resource_params + resource.assign_attributes(resource_params.to_h) authorize resource @@ -40,7 +40,7 @@ def create def edit @lessons_board = resource - @teachers = teachers_to_select2(resource.classroom.id, resource.period) + @teachers = teachers_to_select2(resource.classroom.id, resource.period, resource.grade_id) @classroom = resource.classroom validate_lessons_number @@ -48,7 +48,7 @@ def edit end def update - resource.assign_attributes resource_params + resource.assign_attributes(resource_params.to_h) authorize resource @@ -178,15 +178,15 @@ def number_of_lessons end def teachers_classroom - return if params[:classroom_id].blank? + return if params[:classroom_id].blank? || params[:grade_id].blank? - render json: teachers_to_select2(params[:classroom_id], nil) + render json: teachers_to_select2(params[:classroom_id], nil, params[:grade_id]) end def teachers_classroom_period - return if params[:classroom_id].blank? || params[:period].blank? + return if params[:classroom_id].blank? || params[:period].blank? || params[:grade_id].blank? - render json: teachers_to_select2(params[:classroom_id], params[:period]) + render json: teachers_to_select2(params[:classroom_id], params[:period], params[:grade_id]) end def classrooms_filter @@ -212,22 +212,23 @@ def not_exists_by_classroom_and_period return if params[:classroom_id].blank? render json: LessonsBoard.by_classroom(params[:classroom_id]) - .by_period(period: params[:period]) + .by_period(params[:period]) .empty? end def teacher_in_other_classroom any_blank_param = ( params[:teacher_discipline_classroom_id].blank? || - params[:lesson_number].blank? || - params[:weekday].blank? || - params[:classroom_id].blank? + params[:lesson_number].blank? || + params[:weekday].blank? || + params[:classroom_id].blank? || + params[:period].blank? ) return if any_blank_param render json: linked_teacher(params[:teacher_discipline_classroom_id], params[:lesson_number], params[:weekday], - params[:classroom_id]) + params[:classroom_id], params[:period]) end private @@ -255,12 +256,12 @@ def service @service ||= LessonBoardsService.new end - def linked_teacher(teacher_discipline_classroom_id, lesson_number, weekday, classroom) - service.linked_teacher(teacher_discipline_classroom_id, lesson_number, weekday, classroom) + def linked_teacher(teacher_discipline_classroom_id, lesson_number, weekday, classroom, period) + service.linked_teacher(teacher_discipline_classroom_id, lesson_number, weekday, classroom, period) end - def teachers_to_select2(classroom_id, period) - service.teachers(classroom_id, period) + def teachers_to_select2(classroom_id, period, grade_id) + service.teachers(classroom_id, period, grade_id) end def classrooms_to_select2(grade_id, unity_id) diff --git a/app/controllers/observation_diary_records_controller.rb b/app/controllers/observation_diary_records_controller.rb index 688f3d04a..0f9db3e8d 100644 --- a/app/controllers/observation_diary_records_controller.rb +++ b/app/controllers/observation_diary_records_controller.rb @@ -16,6 +16,31 @@ def index .by_teacher(teachers_by_discipline) .by_discipline([current_discipline.id, nil]) .ordered + + @students = fetch_students_with_observation_diary_records + end + + def show + @observation_diary_record = ObservationDiaryRecord.find(params[:id]).localized + + @observation_record_report_form = ObservationRecordReportForm.new( + teacher_id: @observation_diary_record.teacher.id, + discipline_id: @observation_diary_record.discipline.id, + unity_id: @observation_diary_record.unity_id, + classroom_id: @observation_diary_record.classroom.id, + start_at: @observation_diary_record.date, + end_at: @observation_diary_record.date + ).localized + + if @observation_record_report_form.valid? + observation_record_report = ObservationRecordReport.new( + current_entity_configuration, + @observation_record_report_form + ).build + send_pdf(t("routes.observation_record"), observation_record_report.render) + else + render @observation_diary_records + end end def new @@ -27,7 +52,7 @@ def new end def create - @observation_diary_record = ObservationDiaryRecord.new(resource_params) + @observation_diary_record = ObservationDiaryRecord.new(resource_params.to_unsafe_h) @observation_diary_record.teacher = current_teacher authorize @observation_diary_record @@ -53,7 +78,7 @@ def edit def update @observation_diary_record = ObservationDiaryRecord.find(params[:id]) @observation_diary_record.current_user = current_user - @observation_diary_record.assign_attributes(resource_params) + @observation_diary_record.assign_attributes(resource_params.to_unsafe_h) authorize @observation_diary_record @@ -148,4 +173,11 @@ def fetch_teachers_by_discipline(discipline) ) discipline_teachers_fetcher.teachers_by_classroom end + + def fetch_students_with_observation_diary_records + Student.joins(observation_diary_record_note_students: :observation_diary_record_note) + .where(observation_diary_record_notes: { observation_diary_record_id: @observation_diary_records }) + .distinct + .ordered + end end diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index df2b7f13d..779c37c11 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -10,8 +10,8 @@ def create Rails.logger.info( "LOG: RegistrationsController#create: #{params[:signup].except(:password, :password_confirmation).to_json}" ) if params[:signup] - @signup = Signup.new(params[:signup]) + @signup = Signup.new(params[:signup].to_unsafe_h) password = params[:signup][:password] if weak_password?(password) diff --git a/app/controllers/roles_controller.rb b/app/controllers/roles_controller.rb index c9fb0e7f2..57d9427dc 100644 --- a/app/controllers/roles_controller.rb +++ b/app/controllers/roles_controller.rb @@ -135,6 +135,6 @@ def access_level_permissions(role) end def to_boolean(param) - ActiveRecord::Type::Boolean.new.type_cast_from_user(param) + ActiveRecord::Type::Boolean.new.cast(param) end end diff --git a/app/controllers/school_calendars_controller.rb b/app/controllers/school_calendars_controller.rb index 2a2f9e3dd..e66f2e554 100644 --- a/app/controllers/school_calendars_controller.rb +++ b/app/controllers/school_calendars_controller.rb @@ -24,7 +24,7 @@ def edit end def update - resource.assign_attributes resource_params + resource.assign_attributes(resource_params.to_h) authorize resource @@ -57,7 +57,7 @@ def history end def years_from_unity - only_opened_years = ActiveRecord::Type::Boolean.new.type_cast_from_user(params[:only_opened_years]) + only_opened_years = ActiveRecord::Type::Boolean.new.cast(params[:only_opened_years]) @years = YearsFromUnityFetcher.new(params[:unity_id], only_opened_years).fetch.map { |year| { id: year, name: year } } diff --git a/app/controllers/school_term_recovery_diary_records_controller.rb b/app/controllers/school_term_recovery_diary_records_controller.rb index 5d695136c..e587d3f20 100644 --- a/app/controllers/school_term_recovery_diary_records_controller.rb +++ b/app/controllers/school_term_recovery_diary_records_controller.rb @@ -52,7 +52,7 @@ def new def create @school_term_recovery_diary_record = SchoolTermRecoveryDiaryRecord.new.localized - @school_term_recovery_diary_record.assign_attributes(resource_params) + @school_term_recovery_diary_record.assign_attributes(resource_params.to_h) @school_term_recovery_diary_record.step_number = @school_term_recovery_diary_record.step.try(:step_number) @school_term_recovery_diary_record.recovery_diary_record.teacher_id = current_teacher_id @@ -62,7 +62,6 @@ def create respond_with @school_term_recovery_diary_record, location: school_term_recovery_diary_records_path else @number_of_decimal_places = current_test_setting.number_of_decimal_places - reload_students_list render :new end end @@ -96,7 +95,7 @@ def edit def update @school_term_recovery_diary_record = SchoolTermRecoveryDiaryRecord.find(params[:id]).localized - @school_term_recovery_diary_record.assign_attributes(resource_params) + @school_term_recovery_diary_record.assign_attributes(resource_params.to_h) @school_term_recovery_diary_record.recovery_diary_record.teacher_id = current_teacher_id @school_term_recovery_diary_record.recovery_diary_record.current_user = current_user @@ -114,7 +113,7 @@ def update def destroy @school_term_recovery_diary_record = SchoolTermRecoveryDiaryRecord.find(params[:id]) - @school_term_recovery_diary_record.destroy + @school_term_recovery_diary_record.recovery_diary_record.destroy respond_with @school_term_recovery_diary_record, location: school_term_recovery_diary_records_path end diff --git a/app/controllers/schools_controller.rb b/app/controllers/schools_controller.rb index ce0eced0b..9b323f4c1 100644 --- a/app/controllers/schools_controller.rb +++ b/app/controllers/schools_controller.rb @@ -3,7 +3,7 @@ class SchoolsController < ApplicationController def index begin - codes = result["escolas"].map { |r| r["cod_escola"] } + codes = result["info-escolas"].map { |r| r["cod_escola"] } @unities = Unity.where(api_code: codes) rescue Exception => e @@ -14,12 +14,7 @@ def index protected def result - api.fetch_with_vacancy( - ano: params[:year], - curso_id: params[:lecture_id], - serie_id: params[:grade_id], - turma_turno_id: params[:period] - ) + api.fetch_all end def api diff --git a/app/controllers/student_enrollments_lists_controller.rb b/app/controllers/student_enrollments_lists_controller.rb index bba39439d..168bb98e6 100644 --- a/app/controllers/student_enrollments_lists_controller.rb +++ b/app/controllers/student_enrollments_lists_controller.rb @@ -8,12 +8,13 @@ def by_date discipline: params[:filter][:discipline], score_type: params[:filter][:score_type], opinion_type: params[:filter][:opinion_type], - show_inactive: ActiveRecord::Type::Boolean.new.type_cast_from_user(params[:filter][:show_inactive]), - with_recovery_note_in_step: ActiveRecord::Type::Boolean.new.type_cast_from_user( + show_inactive: ActiveRecord::Type::Boolean.new.cast(params[:filter][:show_inactive]), + with_recovery_note_in_step: ActiveRecord::Type::Boolean.new.cast( params[:filter][:with_recovery_note_in_step] ), date: params[:filter][:date], - period: @period + period: @period, + status_attending: params[:filter][:status_attending] ).student_enrollments render json: student_enrollments @@ -28,7 +29,7 @@ def by_date_range score_type: params[:filter][:score_type], opinion_type: params[:filter][:opinion_type], search_type: :by_date_range, - show_inactive: ActiveRecord::Type::Boolean.new.type_cast_from_user(params[:filter][:show_inactive]), + show_inactive: ActiveRecord::Type::Boolean.new.cast(params[:filter][:show_inactive]), period: @period ).student_enrollments diff --git a/app/controllers/students_controller.rb b/app/controllers/students_controller.rb index 36398f7ae..748ec1f22 100644 --- a/app/controllers/students_controller.rb +++ b/app/controllers/students_controller.rb @@ -1,5 +1,4 @@ class StudentsController < ApplicationController - skip_before_action :authenticate_user!, only: :search_api def index return render json: nil if params[:classroom_id].blank? @@ -45,17 +44,6 @@ def search_autocomplete render json: structured_students end - def search_api - begin - api = IeducarApi::Students.new(configuration.to_api) - result = api.fetch_by_cpf(params[:document], params[:student_code]) - - render json: result["alunos"].to_json - rescue IeducarApi::Base::ApiError => e - render json: e.message, status: "404" - end - end - def recovery_lowest_note return render json: nil if params[:classroom_id].blank? || params[:date].blank? diff --git a/app/controllers/teacher_avaliations_controller.rb b/app/controllers/teacher_avaliations_controller.rb index bd0927f2d..18847b6bb 100644 --- a/app/controllers/teacher_avaliations_controller.rb +++ b/app/controllers/teacher_avaliations_controller.rb @@ -6,6 +6,6 @@ def index classroom_id = params[:classroom_id] discipline_id = params[:discipline_id] - @avaliations = Avaliation.teacher_avaliations(teacher_id, classroom_id, discipline_id).ordered.uniq + @avaliations = Avaliation.teacher_avaliations(teacher_id, classroom_id, discipline_id).ordered.distinct end end diff --git a/app/controllers/test_settings_controller.rb b/app/controllers/test_settings_controller.rb index 8b59aa727..b4323918b 100644 --- a/app/controllers/test_settings_controller.rb +++ b/app/controllers/test_settings_controller.rb @@ -26,7 +26,7 @@ def new end def create - resource.assign_attributes resource_params + resource.assign_attributes(resource_params.to_h) authorize resource @@ -48,7 +48,7 @@ def edit end def update - resource.assign_attributes resource_params + resource.assign_attributes(resource_params.to_h) authorize resource diff --git a/app/controllers/transfer_notes_controller.rb b/app/controllers/transfer_notes_controller.rb index 6fbeb1213..5cdedd61c 100644 --- a/app/controllers/transfer_notes_controller.rb +++ b/app/controllers/transfer_notes_controller.rb @@ -31,13 +31,15 @@ def new def create @transfer_note = TransferNote.new.localized - @transfer_note.assign_attributes(resource_params) + @transfer_note.assign_attributes(resource_params.to_unsafe_h.except(:daily_note_students_attributes)) @transfer_note.step_number = @transfer_note.step.try(:step_number) @transfer_note.teacher = current_teacher authorize @transfer_note if @transfer_note.save + update_daily_note_student(resource_params[:daily_note_students_attributes]) + respond_with @transfer_note, location: transfer_notes_path else render :new @@ -55,8 +57,10 @@ def edit def update @transfer_note = TransferNote.find(params[:id]).localized @transfer_note.current_user = current_user - @transfer_note.assign_attributes(resource_params) + @transfer_note.assign_attributes(resource_params.to_unsafe_h) + daily_note_students = resource_params[:daily_note_students_attributes] + require_daily_note_student(daily_note_students) authorize @transfer_note if @transfer_note.save @@ -101,6 +105,7 @@ def history def destroy @transfer_note = TransferNote.find(params[:id]) + @transfer_note.step_id = @transfer_note.step.try(:id) authorize @transfer_note @@ -156,4 +161,27 @@ def students @students = (@transfer_note.student_id.present? ? [@transfer_note.student] : []) end helper_method :students + + def update_daily_note_student(daily_note_students_attributes) + ActiveRecord::Base.transaction do + daily_note_students_attributes.values.each do |data| + record = DailyNoteStudent.find_or_initialize_by( + daily_note_id: data[:daily_note_id], + student_id: data[:student_id] + ).localized + + record.assign_attributes( + note: data[:note], + transfer_note_id: @transfer_note.id + ) + record.save! + end + end + end + + def require_daily_note_student(daily_note_students) + data = daily_note_students.values.map(&:any?) + + flash[:alert] = t('errors.daily_note.at_least_one_daily_note_student') if data.include?(false) + end end diff --git a/app/decorators/knowledge_area_content_record_decorator.rb b/app/decorators/knowledge_area_content_record_decorator.rb index 98683aabe..2a568a0b7 100644 --- a/app/decorators/knowledge_area_content_record_decorator.rb +++ b/app/decorators/knowledge_area_content_record_decorator.rb @@ -9,4 +9,7 @@ def daily_activities_required? true end + def show_experience_fields + @show_experience_fields ||= GeneralConfiguration.current.show_experience_fields + end end diff --git a/app/decorators/lesson_plan_decorator.rb b/app/decorators/lesson_plan_decorator.rb index a48f0069c..3712e30be 100644 --- a/app/decorators/lesson_plan_decorator.rb +++ b/app/decorators/lesson_plan_decorator.rb @@ -4,4 +4,8 @@ class LessonPlanDecorator def author(current_teacher) PlanAuthorFetcher.new(component, current_teacher).author end + + def removed_objectives? + @remove_lesson_plan_objectives ||= GeneralConfiguration.current.remove_lesson_plan_objectives + end end diff --git a/app/decorators/observation_diary_record_decorator.rb b/app/decorators/observation_diary_record_decorator.rb new file mode 100644 index 000000000..90b8dfbc1 --- /dev/null +++ b/app/decorators/observation_diary_record_decorator.rb @@ -0,0 +1,35 @@ +class ObservationDiaryRecordDecorator + include Decore + include ActionView::Helpers::TagHelper + include ActionView::Context + include ActionView::Helpers::UrlHelper + + def students_labels(selected_id = nil) + return unless component.students + + student_cell = if all_students.count == component.students.count + student_class = 'student-name' if selected_id + content_tag(:span, 'Todos', class: student_class) + else + student_label_for(component.students.ordered.distinct, selected_id) + end + + student_cell + end + + def student_label_for(students, selected_id) + students.map { |student| + student_class = 'student-name' if selected_id && selected_id == student.id + content_tag(:span, student, class: student_class) + }.join(', ').html_safe + end + + def all_students + student_enrollments = StudentEnrollmentsList.new( + classroom: component.classroom_id, + discipline: nil, + date: component.date, + search_type: :by_date + ).student_enrollments + end +end diff --git a/app/forms/absence_justification_report_form.rb b/app/forms/absence_justification_report_form.rb index 8d049ae76..69eed09d1 100644 --- a/app/forms/absence_justification_report_form.rb +++ b/app/forms/absence_justification_report_form.rb @@ -41,7 +41,7 @@ def absence_justifications @absence_justifications = @absence_justifications.by_author(author, user_id) if author.present? - @absence_justifications.ordered.uniq + @absence_justifications.ordered.distinct end def frequence_type_by_discipline? diff --git a/app/forms/attendance_record_report_form.rb b/app/forms/attendance_record_report_form.rb index e7329f231..21f047269 100644 --- a/app/forms/attendance_record_report_form.rb +++ b/app/forms/attendance_record_report_form.rb @@ -31,13 +31,24 @@ class AttendanceRecordReportForm validate :must_have_daily_frequencies def daily_frequencies - @daily_frequencies ||= DailyFrequencyQuery.call( + @daily_frequencies ||= fetch_daily_frequencies + end + + def fetch_daily_frequencies + DailyFrequencyQuery.call( classroom_id: classroom_id, period: period, frequency_date: start_at..end_at, discipline_id: !global_absence? && discipline_id, class_numbers: !global_absence? && class_numbers - ) + ).group_by(&:frequency_date).map do |frequency_date, frequencies| + if frequencies.map(&:class_number).uniq.size > 1 + frequencies + else + daily_frequency = frequencies.find { |f| f.period == Periods::FULL.to_i } + daily_frequency || frequencies.first + end + end.flatten end def school_calendar_events @@ -101,9 +112,8 @@ def students_frequencies_percentage def days_enrollment days = daily_frequencies.map(&:frequency_date) - students_ids = daily_frequencies.map do |daily_frequency| - daily_frequency.students.map(&:student_id) - end.flatten.uniq + + students_ids = daily_frequencies.flat_map(&:students).map(&:student_id).uniq EnrollmentFromStudentFetcher.new.current_enrollments(students_ids, classroom_id, days) end @@ -190,7 +200,7 @@ def active_searches end def in_active_searches - dates = daily_frequencies.pluck(:frequency_date).uniq + dates = daily_frequencies.map(&:frequency_date).uniq active_searches = {} diff --git a/app/forms/discipline_content_record_cloner_form.rb b/app/forms/discipline_content_record_cloner_form.rb index 1a55a169f..79fe8f4e8 100644 --- a/app/forms/discipline_content_record_cloner_form.rb +++ b/app/forms/discipline_content_record_cloner_form.rb @@ -1,4 +1,4 @@ -class DisciplineContentRecordClonerForm< ActiveRecord::Base +class DisciplineContentRecordClonerForm< ApplicationRecord has_no_table attr_accessor :discipline_content_record_id, :teacher diff --git a/app/forms/discipline_content_record_item_cloner_form.rb b/app/forms/discipline_content_record_item_cloner_form.rb index 2a1c95e94..a83fb34e3 100644 --- a/app/forms/discipline_content_record_item_cloner_form.rb +++ b/app/forms/discipline_content_record_item_cloner_form.rb @@ -1,4 +1,4 @@ -class DisciplineContentRecordItemClonerForm < ActiveRecord::Base +class DisciplineContentRecordItemClonerForm < ApplicationRecord has_no_table attr_accessor :uuid, :discipline_content_record_cloner_form_id, :classroom_id, :record_date diff --git a/app/forms/discipline_lesson_plan_cloner_form.rb b/app/forms/discipline_lesson_plan_cloner_form.rb index 505a687bc..55089e295 100644 --- a/app/forms/discipline_lesson_plan_cloner_form.rb +++ b/app/forms/discipline_lesson_plan_cloner_form.rb @@ -1,4 +1,4 @@ -class DisciplineLessonPlanClonerForm < ActiveRecord::Base +class DisciplineLessonPlanClonerForm < ApplicationRecord has_no_table attr_accessor :discipline_lesson_plan_id, :teacher, :entity_id diff --git a/app/forms/discipline_lesson_plan_item_cloner_form.rb b/app/forms/discipline_lesson_plan_item_cloner_form.rb index a8a76a2d9..2602c7be8 100644 --- a/app/forms/discipline_lesson_plan_item_cloner_form.rb +++ b/app/forms/discipline_lesson_plan_item_cloner_form.rb @@ -1,4 +1,4 @@ -class DisciplineLessonPlanItemClonerForm < ActiveRecord::Base +class DisciplineLessonPlanItemClonerForm < ApplicationRecord has_no_table attr_accessor :uuid, :discipline_lesson_plan_cloner_form_id, :classroom_id, :start_at, :end_at diff --git a/app/forms/frequency_in_batch_form.rb b/app/forms/frequency_in_batch_form.rb index 735da6db9..c1a847722 100644 --- a/app/forms/frequency_in_batch_form.rb +++ b/app/forms/frequency_in_batch_form.rb @@ -1,4 +1,4 @@ -class FrequencyInBatchForm < ActiveRecord::Base +class FrequencyInBatchForm < ApplicationRecord has_no_table attr_accessor :unity_id, :classroom_id, :period, :discipline_id, :start_date, :end_date, :receive_email_confirmation diff --git a/app/forms/knowledge_area_content_record_cloner_form.rb b/app/forms/knowledge_area_content_record_cloner_form.rb index 9d952ceb5..cd4c9d196 100644 --- a/app/forms/knowledge_area_content_record_cloner_form.rb +++ b/app/forms/knowledge_area_content_record_cloner_form.rb @@ -1,4 +1,4 @@ -class KnowledgeAreaContentRecordClonerForm < ActiveRecord::Base +class KnowledgeAreaContentRecordClonerForm < ApplicationRecord has_no_table attr_accessor :knowledge_area_content_record_id, :teacher diff --git a/app/forms/knowledge_area_content_record_item_cloner_form.rb b/app/forms/knowledge_area_content_record_item_cloner_form.rb index a49ce9e18..91d15173a 100644 --- a/app/forms/knowledge_area_content_record_item_cloner_form.rb +++ b/app/forms/knowledge_area_content_record_item_cloner_form.rb @@ -1,4 +1,4 @@ -class KnowledgeAreaContentRecordItemClonerForm < ActiveRecord::Base +class KnowledgeAreaContentRecordItemClonerForm < ApplicationRecord has_no_table attr_accessor :uuid, :knowledge_area_content_record_cloner_form_id, :classroom_id, :record_date diff --git a/app/forms/knowledge_area_lesson_plan_cloner_form.rb b/app/forms/knowledge_area_lesson_plan_cloner_form.rb index 2f257efaa..0a0af73ff 100644 --- a/app/forms/knowledge_area_lesson_plan_cloner_form.rb +++ b/app/forms/knowledge_area_lesson_plan_cloner_form.rb @@ -1,4 +1,4 @@ -class KnowledgeAreaLessonPlanClonerForm < ActiveRecord::Base +class KnowledgeAreaLessonPlanClonerForm < ApplicationRecord has_no_table attr_accessor :knowledge_area_lesson_plan_id, :teacher, :entity_id diff --git a/app/forms/knowledge_area_lesson_plan_item_cloner_form.rb b/app/forms/knowledge_area_lesson_plan_item_cloner_form.rb index 82d14ea6b..d96d5242e 100644 --- a/app/forms/knowledge_area_lesson_plan_item_cloner_form.rb +++ b/app/forms/knowledge_area_lesson_plan_item_cloner_form.rb @@ -1,4 +1,4 @@ -class KnowledgeAreaLessonPlanItemClonerForm < ActiveRecord::Base +class KnowledgeAreaLessonPlanItemClonerForm < ApplicationRecord has_no_table attr_accessor :uuid, :knowledge_area_lesson_plan_cloner_form_id, :classroom_id, :start_at, :end_at diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb new file mode 100644 index 000000000..a009ace51 --- /dev/null +++ b/app/jobs/application_job.rb @@ -0,0 +1,2 @@ +class ApplicationJob < ActiveJob::Base +end diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb new file mode 100644 index 000000000..ab973584f --- /dev/null +++ b/app/mailers/application_mailer.rb @@ -0,0 +1,3 @@ +class ApplicationMailer < ActionMailer::Base + default from: "sample@#{ActionMailer::Base.smtp_settings[:domain]}" +end diff --git a/app/mailers/base_mailer.rb b/app/mailers/base_mailer.rb index fa7d5a1ee..4fac801b2 100644 --- a/app/mailers/base_mailer.rb +++ b/app/mailers/base_mailer.rb @@ -1,6 +1,6 @@ # encoding: utf-8 -class BaseMailer < ActionMailer::Base +class BaseMailer < ApplicationMailer default from: "Notificação i-Diário <#{Rails.application.secrets.NO_REPLY_ADDRESS}>".freeze default 'IsTransactional' => 'True' SKIP_DOMAINS = (Rails.application.secrets.EMAIL_SKIP_DOMAINS || []).split(',').flatten.freeze diff --git a/app/mailers/receipt_mailer.rb b/app/mailers/receipt_mailer.rb index e8e4d1460..4ba5b56ed 100644 --- a/app/mailers/receipt_mailer.rb +++ b/app/mailers/receipt_mailer.rb @@ -1,27 +1,29 @@ class ReceiptMailer < BaseMailer - def notify_daily_frequency_success(user, url, date, classroom, unity) - @name = user.first_name + def notify_daily_frequency_success(name, email, url, date, classroom, unity) + @name = name + @email = email @url = url @classroom = classroom @unity = unity - return unless (email = user.email) + return unless @email - skip_domains([email]) + skip_domains([@email]) mail(to: @recipient, subject: "Frequência do dia #{date} lançada com sucesso") if @recipient.present? end - def notify_daily_frequency_in_batch_success(user, url, dates, classroom, unity) - @name = user.first_name + def notify_daily_frequency_in_batch_success(name, email, url, dates, classroom, unity) + @name = name + @email = email @url = url @classroom = classroom @unity = unity @dates = dates - return unless (email = user.email) + return unless @email - skip_domains([email]) + skip_domains([@email]) mail(to: @recipient, subject: "Frequências foram lançadas com sucesso") if @recipient.present? end diff --git a/app/models/absence_justification.rb b/app/models/absence_justification.rb index 4e3cd5480..aacc4d886 100644 --- a/app/models/absence_justification.rb +++ b/app/models/absence_justification.rb @@ -1,4 +1,4 @@ -class AbsenceJustification < ActiveRecord::Base +class AbsenceJustification < ApplicationRecord include Audit include Filterable include Discardable @@ -37,13 +37,13 @@ class AbsenceJustification < ActiveRecord::Base validates :school_calendar, presence: true validates :absence_date_end, presence: true, school_calendar_day: true, posting_date: true validates :absence_date, presence: true, school_calendar_day: true, posting_date: true - validates :justification, presence: true validate :at_least_one_student - validate :at_least_one_discipline, if: :frequence_type_by_discipline? validate :period_absence validate :no_retroactive_dates + has_enumeration_for :period, with: Periods, skip_validation: true + default_scope -> { kept } scope :ordered, -> { order(absence_date: :desc) } @@ -81,6 +81,7 @@ class AbsenceJustification < ActiveRecord::Base where.not(user_id: current_user_id) end } + scope :by_period, ->(period) { where(period: period) } private @@ -102,6 +103,9 @@ def no_retroactive_dates errors.add(:absence_date_end, :not_less_than_initial) end + # TODO: release-absence-justification + # - [ ] Remover vínculo com professor + # - [ ] Remover vínculo com disciplina def period_absence return if absence_date.blank? || absence_date_end.blank? diff --git a/app/models/absence_justifications_discipline.rb b/app/models/absence_justifications_discipline.rb index 85d67e0a3..563bf9d03 100644 --- a/app/models/absence_justifications_discipline.rb +++ b/app/models/absence_justifications_discipline.rb @@ -1,4 +1,4 @@ -class AbsenceJustificationsDiscipline < ActiveRecord::Base +class AbsenceJustificationsDiscipline < ApplicationRecord audited belongs_to :discipline diff --git a/app/models/absence_justifications_student.rb b/app/models/absence_justifications_student.rb index eee69f1d7..566de4b99 100644 --- a/app/models/absence_justifications_student.rb +++ b/app/models/absence_justifications_student.rb @@ -1,10 +1,34 @@ -class AbsenceJustificationsStudent < ActiveRecord::Base +class AbsenceJustificationsStudent < ApplicationRecord include Discardable audited belongs_to :student belongs_to :absence_justification + has_many :daily_frequency_students, dependent: :nullify, foreign_key: :absence_justification_student_id + + after_save :justify_old_absences default_scope -> { kept } + + private + + def justify_old_absences + absence_date = absence_justification.absence_date + absence_date_end = absence_justification.absence_date_end + classroom_id = absence_justification.classroom_id + + daily_frequency_students = DailyFrequencyStudent.by_classroom_id(classroom_id) + .by_frequency_date_between(absence_date, absence_date_end) + .by_student_id(student_id) + + daily_frequency_students = daily_frequency_students.by_class_number(absence_justification.class_number) if absence_justification.class_number.present? + daily_frequency_students = daily_frequency_students.by_period(absence_justification.period) unless absence_justification.period.nil? || absence_justification.period == Periods::FULL + + daily_frequency_students.each do |daily_frequency_student| + daily_frequency_student.present = false + daily_frequency_student.absence_justification_student_id = id + daily_frequency_student.save + end + end end diff --git a/app/models/active_search.rb b/app/models/active_search.rb index f594c957d..08fa902a6 100644 --- a/app/models/active_search.rb +++ b/app/models/active_search.rb @@ -1,4 +1,4 @@ -class ActiveSearch < ActiveRecord::Base +class ActiveSearch < ApplicationRecord include Audit include Discardable diff --git a/app/models/address.rb b/app/models/address.rb index abfbf3ad7..b8822297e 100644 --- a/app/models/address.rb +++ b/app/models/address.rb @@ -1,4 +1,4 @@ -class Address < ActiveRecord::Base +class Address < ApplicationRecord acts_as_copy_target audited associated_with: :source, except: [:source_id, :source_type, :latitude, :longitude] diff --git a/app/models/application_record.rb b/app/models/application_record.rb new file mode 100644 index 000000000..10a4cba84 --- /dev/null +++ b/app/models/application_record.rb @@ -0,0 +1,3 @@ +class ApplicationRecord < ActiveRecord::Base + self.abstract_class = true +end diff --git a/app/models/avaliation.rb b/app/models/avaliation.rb index 7f97a2acd..9cf49ea36 100644 --- a/app/models/avaliation.rb +++ b/app/models/avaliation.rb @@ -1,4 +1,4 @@ -class Avaliation < ActiveRecord::Base +class Avaliation < ApplicationRecord include Audit include ColumnsLockable include TeacherRelationable @@ -35,7 +35,6 @@ class Avaliation < ActiveRecord::Base validates :classroom, presence: true validates :discipline, presence: true validates :test_date, presence: true, school_calendar_day: true, posting_date: true - validates :classes, presence: true validates :school_calendar, presence: true validates :test_setting, presence: true validates :test_setting_test, presence: true, if: :sum_calculation_type? @@ -43,7 +42,6 @@ class Avaliation < ActiveRecord::Base validates :weight, presence: true, if: :should_validate_weight? validates :grade_ids, presence: true - validate :uniqueness_of_avaliation validate :unique_test_setting_test_per_step, if: -> { sum_calculation_type? && !allow_break_up? } validate :test_setting_test_weight_available, if: :allow_break_up? validate :classroom_score_type_must_be_numeric, if: :should_validate_classroom_score_type? @@ -53,7 +51,7 @@ class Avaliation < ActiveRecord::Base validate :discipline_in_grade? scope :teacher_avaliations, lambda { |teacher_id, classroom_id, discipline_id| joins(:teacher_discipline_classrooms).where(teacher_discipline_classrooms: { teacher_id: teacher_id, classroom_id: classroom_id, discipline_id: discipline_id}) } - scope :by_teacher, lambda { |teacher_id| joins(:teacher_discipline_classrooms).where(teacher_discipline_classrooms: { teacher_id: teacher_id }).uniq } + scope :by_teacher, lambda { |teacher_id| joins(:teacher_discipline_classrooms).where(teacher_discipline_classrooms: { teacher_id: teacher_id }).distinct } scope :by_unity_id, lambda { |unity_id| joins(:classroom).merge(Classroom.by_unity(unity_id))} scope :by_classroom_id, lambda { |classroom_id| where(classroom_id: classroom_id) } scope :by_grade_id, lambda { |grade_id| @@ -63,7 +61,6 @@ class Avaliation < ActiveRecord::Base scope :exclude_discipline_ids, lambda { |discipline_ids| where.not(discipline_id: discipline_ids) } scope :by_test_date, lambda { |test_date| where(test_date: test_date.try(:to_date)) } scope :by_test_date_between, lambda { |start_at, end_at| where(test_date: start_at.to_date..end_at.to_date) } - scope :by_classes, lambda { |classes| where("classes && ARRAY#{classes}::INTEGER[]") } scope :by_description, lambda { |description| joins(arel_table.join(TestSettingTest.arel_table, Arel::Nodes::OuterJoin) .on(TestSettingTest.arel_table[:id] .eq(arel_table[:test_setting_test_id])).join_sources) @@ -104,10 +101,6 @@ def current_step school_calendar.step(test_date) end - def classes=(classes) - write_attribute(:classes, classes ? classes.split(',').sort.map(&:to_i) : classes) - end - def description_to_teacher I18n.l(test_date) + ' - ' + (self.to_s || '') end @@ -209,17 +202,6 @@ def step steps_fetcher.step_by_date(test_date) end - def uniqueness_of_avaliation - avaliations = Avaliation.by_classroom_id(classroom_id) - .by_grade_id(grade_ids) - .by_discipline_id(discipline) - .by_test_date(test_date) - .by_classes(classes) - avaliations = avaliations.where.not(id: id) if persisted? - - errors.add(:classes, :uniqueness_of_avaliation, count: classes.count) if avaliations.any? - end - def unique_test_setting_test_per_step return unless step @@ -241,7 +223,7 @@ def test_setting_test_weight_available .by_discipline_id(discipline) .by_test_setting_test_id(test_setting_test_id) .by_test_date_between(step.start_at, step.end_at) - .uniq + .distinct avaliations = avaliations.where.not(id: id) if persisted? diff --git a/app/models/avaliation_recovery_diary_record.rb b/app/models/avaliation_recovery_diary_record.rb index 4c4c2e1fd..953c1b21e 100644 --- a/app/models/avaliation_recovery_diary_record.rb +++ b/app/models/avaliation_recovery_diary_record.rb @@ -8,7 +8,7 @@ class AvaliationRecoveryDiaryRecord < ActiveRecord::Base before_destroy :valid_for_destruction? - belongs_to :recovery_diary_record, dependent: :destroy + belongs_to :recovery_diary_record belongs_to :avaliation belongs_to :unity belongs_to :classroom diff --git a/app/models/avaliation_recovery_lowest_note.rb b/app/models/avaliation_recovery_lowest_note.rb index b13289122..7907d4a49 100644 --- a/app/models/avaliation_recovery_lowest_note.rb +++ b/app/models/avaliation_recovery_lowest_note.rb @@ -1,4 +1,4 @@ -class AvaliationRecoveryLowestNote < ActiveRecord::Base +class AvaliationRecoveryLowestNote < ApplicationRecord include Audit include Stepable include Filterable @@ -8,7 +8,7 @@ class AvaliationRecoveryLowestNote < ActiveRecord::Base audited has_associated_audits - belongs_to :recovery_diary_record, dependent: :destroy + belongs_to :recovery_diary_record accepts_nested_attributes_for :recovery_diary_record diff --git a/app/models/classroom.rb b/app/models/classroom.rb index 0b827fe20..acdf4197d 100644 --- a/app/models/classroom.rb +++ b/app/models/classroom.rb @@ -1,4 +1,4 @@ -class Classroom < ActiveRecord::Base +class Classroom < ApplicationRecord include Discardable LABEL_COLORS = YAML.safe_load( @@ -37,11 +37,11 @@ class Classroom < ActiveRecord::Base scope :by_unity_and_teacher, lambda { |unity_id, teacher_id| joins(:teacher_discipline_classrooms) .where(unity_id: unity_id, teacher_discipline_classrooms: { teacher_id: teacher_id }) - .uniq + .distinct } scope :by_unity, ->(unity) { where(unity: unity) } - scope :by_unity_and_grade, ->(unity_id, grade_id) { where(unity_id: unity_id).by_grade(grade_id).uniq } + scope :by_unity_and_grade, ->(unity_id, grade_id) { where(unity_id: unity_id).by_grade(grade_id).distinct } scope :different_than, ->(classroom_id) { where(arel_table[:id].not_eq(classroom_id)) } scope :by_grade, ->(grade_id) { joins(:classrooms_grades).merge(ClassroomsGrade.by_grade_id(grade_id)) } scope :by_year, ->(year) { where(year: year) } @@ -50,7 +50,7 @@ class Classroom < ActiveRecord::Base scope :by_teacher_id, lambda { |teacher_id| joins(:teacher_discipline_classrooms) .where(teacher_discipline_classrooms: { teacher_id: teacher_id }) - .uniq + .distinct } scope :by_score_type, lambda { |score_type| @@ -62,7 +62,7 @@ class Classroom < ActiveRecord::Base scope :by_teacher_discipline, lambda { |discipline_id| joins(:teacher_discipline_classrooms) .where(teacher_discipline_classrooms: { discipline_id: discipline_id }) - .uniq + .distinct } scope :by_api_code, ->(api_code) { where(api_code: api_code) } diff --git a/app/models/classrooms_grade.rb b/app/models/classrooms_grade.rb index dcbf6a280..33ed829f7 100644 --- a/app/models/classrooms_grade.rb +++ b/app/models/classrooms_grade.rb @@ -1,4 +1,4 @@ -class ClassroomsGrade < ActiveRecord::Base +class ClassroomsGrade < ApplicationRecord include Discardable belongs_to :classroom diff --git a/app/models/complementary_exam.rb b/app/models/complementary_exam.rb index 982bb9181..a4fd3745f 100644 --- a/app/models/complementary_exam.rb +++ b/app/models/complementary_exam.rb @@ -1,4 +1,4 @@ -class ComplementaryExam < ActiveRecord::Base +class ComplementaryExam < ApplicationRecord include Audit include Stepable include ColumnsLockable @@ -29,7 +29,7 @@ class ComplementaryExam < ActiveRecord::Base lambda { |teacher_id| joins(discipline: :teacher_discipline_classrooms) .where(teacher_discipline_classrooms: { teacher_id: teacher_id }) - .uniq + .distinct } scope :by_complementary_exam_setting, lambda { |complementary_exam_setting_id| where(complementary_exam_setting_id: complementary_exam_setting_id) } diff --git a/app/models/complementary_exam_setting.rb b/app/models/complementary_exam_setting.rb index 9757491e4..8178cd1d6 100644 --- a/app/models/complementary_exam_setting.rb +++ b/app/models/complementary_exam_setting.rb @@ -1,4 +1,4 @@ -class ComplementaryExamSetting < ActiveRecord::Base +class ComplementaryExamSetting < ApplicationRecord acts_as_copy_target audited @@ -70,6 +70,7 @@ def uniqueness_of_calculation_type_by_grade .by_calculation_type([CalculationTypes::SUBSTITUTION, CalculationTypes::SUBSTITUTION_IF_GREATER]) .by_affected_score(affected_score) .by_grade_id(grades.map(&:id)) + .by_year(year) .exists? errors.add(:base, :uniqueness_of_calculation_type_by_grade) diff --git a/app/models/complementary_exam_student.rb b/app/models/complementary_exam_student.rb index 869f90cbf..71ef3bb9c 100644 --- a/app/models/complementary_exam_student.rb +++ b/app/models/complementary_exam_student.rb @@ -1,4 +1,4 @@ -class ComplementaryExamStudent < ActiveRecord::Base +class ComplementaryExamStudent < ApplicationRecord include Audit include Discardable diff --git a/app/models/conceptual_exam.rb b/app/models/conceptual_exam.rb index 96123ad35..51578175b 100644 --- a/app/models/conceptual_exam.rb +++ b/app/models/conceptual_exam.rb @@ -72,7 +72,7 @@ def self.active def self.by_teacher(teacher_id) active.where( TeacherDisciplineClassroom.arel_table[:teacher_id].eq(teacher_id) - ).uniq + ).distinct end def self.by_status(classroom_id, teacher_id, status) @@ -151,7 +151,7 @@ def ignore_date_validates private def student_must_have_conceptual_exam_score_type - return if student.blank? || classroom.blank? + return if student.blank? || classroom.blank? || validation_type.eql?(:destroy) permited_score_types = [ScoreTypes::CONCEPT, ScoreTypes::NUMERIC_AND_CONCEPT] classroom_grade = ClassroomsGrade.by_student_id(student.id).by_classroom_id(classroom.id)&.first diff --git a/app/models/conceptual_exam_value.rb b/app/models/conceptual_exam_value.rb index c21007fa8..11be8007f 100644 --- a/app/models/conceptual_exam_value.rb +++ b/app/models/conceptual_exam_value.rb @@ -75,7 +75,7 @@ def self.active_query differentiated_exam_rules[:score_type].eq(ScoreTypes::CONCEPT). and(differentiated_exam_rule_students[:id].not_eq(nil)) ) - ).uniq + ).distinct end def valid_for_destruction? diff --git a/app/models/concerns/school_calendar_filterable.rb b/app/models/concerns/school_calendar_filterable.rb index a791c490c..4aeb46ca1 100644 --- a/app/models/concerns/school_calendar_filterable.rb +++ b/app/models/concerns/school_calendar_filterable.rb @@ -24,7 +24,7 @@ def self.current_year_school_term_types(year, unity_id, add_yearly) step_type_description_formatter(calendar) }.uniq - school_term_types = SchoolTermType.where(description: school_calendar + school_calendar_classroom) + school_term_types = SchoolTermType.where(description: school_calendar + school_calendar_classroom).to_a school_term_types << SchoolTermType.find_by(description: 'Anual') if add_yearly school_term_types diff --git a/app/models/content.rb b/app/models/content.rb index 775aaee05..eb5c4b02e 100644 --- a/app/models/content.rb +++ b/app/models/content.rb @@ -1,4 +1,4 @@ -class Content < ActiveRecord::Base +class Content < ApplicationRecord include Audit audited diff --git a/app/models/content_record.rb b/app/models/content_record.rb index d3eb55570..3bd4a8499 100644 --- a/app/models/content_record.rb +++ b/app/models/content_record.rb @@ -1,4 +1,4 @@ -class ContentRecord < ActiveRecord::Base +class ContentRecord < ApplicationRecord include Audit include ColumnsLockable include TeacherRelationable diff --git a/app/models/content_records_content.rb b/app/models/content_records_content.rb index edde57829..36c42ea6d 100644 --- a/app/models/content_records_content.rb +++ b/app/models/content_records_content.rb @@ -1,4 +1,4 @@ -class ContentRecordsContent < ActiveRecord::Base +class ContentRecordsContent < ApplicationRecord include Audit audited except: [:content_record_id], allow_mass_assignment: true, @@ -6,4 +6,4 @@ class ContentRecordsContent < ActiveRecord::Base belongs_to :content_record belongs_to :content -end \ No newline at end of file +end diff --git a/app/models/course.rb b/app/models/course.rb index 895178bd6..c82e50381 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -16,7 +16,7 @@ class Course < ActiveRecord::Base scope :ordered, -> { order(arel_table[:description].asc) } def self.by_unity(unity) - joins(grades: [:classrooms]).where(classrooms: { unity_id: unity }).uniq + joins(grades: [:classrooms]).where(classrooms: { unity_id: unity }).distinct end def to_s diff --git a/app/models/custom_rounding_table.rb b/app/models/custom_rounding_table.rb index e68badeb7..29dc49bb7 100644 --- a/app/models/custom_rounding_table.rb +++ b/app/models/custom_rounding_table.rb @@ -1,4 +1,4 @@ -class CustomRoundingTable < ActiveRecord::Base +class CustomRoundingTable < ApplicationRecord acts_as_copy_target include Audit diff --git a/app/models/custom_rounding_table_value.rb b/app/models/custom_rounding_table_value.rb index c0e86f38c..582008b9a 100644 --- a/app/models/custom_rounding_table_value.rb +++ b/app/models/custom_rounding_table_value.rb @@ -1,4 +1,4 @@ -class CustomRoundingTableValue < ActiveRecord::Base +class CustomRoundingTableValue < ApplicationRecord acts_as_copy_target include Audit diff --git a/app/models/daily_frequency.rb b/app/models/daily_frequency.rb index 26865fd74..fe14520d9 100644 --- a/app/models/daily_frequency.rb +++ b/app/models/daily_frequency.rb @@ -1,4 +1,4 @@ -class DailyFrequency < ActiveRecord::Base +class DailyFrequency < ApplicationRecord include Audit include TeacherRelationable @@ -61,16 +61,44 @@ class DailyFrequency < ActiveRecord::Base lambda { |teacher_id| joins(discipline: :teacher_discipline_classrooms) .where(teacher_discipline_classrooms: { teacher_id: teacher_id }) + .distinct + } + + scope :by_teacher_classroom_id, + lambda { |teacher_id, classroom_id| + joins(teacher: :teacher_discipline_classrooms) + .where( + teacher_discipline_classrooms: { + teacher_id: teacher_id, + classroom_id: classroom_id + } + ) + .distinct + } + + scope :by_teacher_discipline_classroom, + lambda { |teacher_id, classroom_id| + joins(teacher: :teacher_discipline_classrooms) + .where.not(owner_teacher_id: nil) + .where( + teacher_discipline_classrooms: + { + teacher_id: teacher_id, + classroom_id: classroom_id, + allow_absence_by_discipline: 0 + } + ) .uniq } + scope :by_owner_teacher_id, lambda { |teacher_id| where(owner_teacher_id: teacher_id) } scope :by_unity_id, lambda { |unity_id| where(unity_id: unity_id) } scope :by_classroom_id, lambda { |classroom_id| where(classroom_id: classroom_id) } scope :by_period, ->(period) { where(period: period) } - scope :by_period_or_by_teacher, ->(period, teacher) { where('period = ? OR owner_teacher_id = ?', period, teacher) } + scope :by_period_or_by_teacher, ->(period, teacher) { where('period = ? OR owner_teacher_id = ?', period, teacher)} scope :by_discipline_id, lambda { |discipline_id| where(discipline_id: discipline_id) } scope :by_frequency_date, lambda { |frequency_date| where(frequency_date: frequency_date.to_date) } - scope :by_frequency_date_between, lambda { |start_at, end_at| where(frequency_date: start_at.to_date..end_at.to_date) } + scope :by_frequency_date_between, lambda { |start_at, end_at| where(frequency_date: start_at.to_date..end_at.to_date)} scope :by_class_number, lambda { |class_number| where(class_number: class_number) } scope :by_school_calendar_id, ->(school_calendar_id) { where(school_calendar_id: school_calendar_id) } scope :by_not_poster, ->(poster_sent) { joins(:students).where("daily_frequency_students.updated_at > ?", poster_sent) } diff --git a/app/models/daily_frequency_student.rb b/app/models/daily_frequency_student.rb index d5007bbc9..d5aee040c 100644 --- a/app/models/daily_frequency_student.rb +++ b/app/models/daily_frequency_student.rb @@ -29,8 +29,12 @@ class DailyFrequencyStudent < ActiveRecord::Base scope :by_classroom_id, lambda { |classroom_id| joins(:daily_frequency).merge(DailyFrequency.by_classroom_id(classroom_id)) } scope :by_discipline_id, lambda { |discipline_id| joins(:daily_frequency).merge(DailyFrequency.by_discipline_id(discipline_id)) } scope :by_student_id, lambda { |student_id| where(student_id: student_id) } + scope :by_absence_justification_student_id, lambda { |absence_justification_student_id| where(absence_justification_student_id: absence_justification_student_id) } + scope :by_not_justified, lambda { where(absence_justification_student_id: nil) } scope :by_frequency_date, lambda { |frequency_date| joins(:daily_frequency).merge(DailyFrequency.by_frequency_date(frequency_date)) } + scope :by_period, lambda { |period| joins(:daily_frequency).merge(DailyFrequency.by_period(period)) } scope :by_frequency_date_between, lambda { |start_at, end_at| joins(:daily_frequency).merge(DailyFrequency.by_frequency_date_between(start_at, end_at)) } + scope :by_class_number, lambda { |class_number| joins(:daily_frequency).merge(DailyFrequency.by_class_number(class_number)) } scope :by_not_poster, ->(poster_sent) { where("daily_frequency_students.updated_at > ?", poster_sent) } scope :general_by_classroom_student_date_between, lambda { |classroom_id, student_id, start_at, end_at| where( @@ -48,7 +52,9 @@ class DailyFrequencyStudent < ActiveRecord::Base .includes(:daily_frequency) } def to_s - if present? + if absence_justification_student_id + 'FJ' + elsif present? TermsDictionary.cached_current.try(:presence_identifier_character) || '.' else 'F' diff --git a/app/models/daily_note.rb b/app/models/daily_note.rb index 63aa33566..b555b16ad 100644 --- a/app/models/daily_note.rb +++ b/app/models/daily_note.rb @@ -1,4 +1,4 @@ -class DailyNote < ActiveRecord::Base +class DailyNote < ApplicationRecord include Audit acts_as_copy_target @@ -14,7 +14,7 @@ class DailyNote < ActiveRecord::Base }, class_name: 'DailyNoteStudent', dependent: :destroy accepts_nested_attributes_for :students, allow_destroy: true, reject_if: proc { |attributes| - !ActiveRecord::Type::Boolean.new.type_cast_from_user(attributes[:active]) + !ActiveRecord::Type::Boolean.new.cast(attributes[:active]) } has_enumeration_for :status, with: DailyNoteStatuses, create_helpers: true diff --git a/app/models/daily_note_student.rb b/app/models/daily_note_student.rb index ba2249a74..f1a9eedb6 100644 --- a/app/models/daily_note_student.rb +++ b/app/models/daily_note_student.rb @@ -1,4 +1,4 @@ -class DailyNoteStudent < ActiveRecord::Base +class DailyNoteStudent < ApplicationRecord include Discardable acts_as_copy_target @@ -45,7 +45,7 @@ def maximum_score end def recovered_note - recovery_note.to_f > note.to_f ? recovery_note : note + recovery_note.to_f > note.to_f ? recovery_note : note.to_f end def minimum_score diff --git a/app/models/data_exportation.rb b/app/models/data_exportation.rb index c4db9d5f9..3c5acbaab 100644 --- a/app/models/data_exportation.rb +++ b/app/models/data_exportation.rb @@ -1,4 +1,4 @@ -class DataExportation < ActiveRecord::Base +class DataExportation < ApplicationRecord has_enumeration_for :backup_type, with: BackupTypes, create_helpers: true has_enumeration_for :backup_status, with: BackupStatus, create_helpers: true diff --git a/app/models/deficiency.rb b/app/models/deficiency.rb index 0e3e27f3d..bdc58dc92 100644 --- a/app/models/deficiency.rb +++ b/app/models/deficiency.rb @@ -1,4 +1,4 @@ -class Deficiency < ActiveRecord::Base +class Deficiency < ApplicationRecord include Audit include Discardable diff --git a/app/models/descriptive_exam.rb b/app/models/descriptive_exam.rb index eee2c8607..bb0c44fe2 100644 --- a/app/models/descriptive_exam.rb +++ b/app/models/descriptive_exam.rb @@ -1,4 +1,4 @@ -class DescriptiveExam < ActiveRecord::Base +class DescriptiveExam < ApplicationRecord include Audit include Stepable include TeacherRelationable @@ -25,7 +25,7 @@ class DescriptiveExam < ActiveRecord::Base lambda { |teacher_id| joins(discipline: :teacher_discipline_classrooms) .where(teacher_discipline_classrooms: { teacher_id: teacher_id }) - .uniq + .distinct } scope :by_unity_id, ->(unity_id) { joins(:classroom).where(classrooms: { unity_id: unity_id }) } diff --git a/app/models/descriptive_exam_student.rb b/app/models/descriptive_exam_student.rb index 1bc0c876a..2d4feb147 100644 --- a/app/models/descriptive_exam_student.rb +++ b/app/models/descriptive_exam_student.rb @@ -1,4 +1,4 @@ -class DescriptiveExamStudent < ActiveRecord::Base +class DescriptiveExamStudent < ApplicationRecord include Discardable acts_as_copy_target diff --git a/app/models/discipline.rb b/app/models/discipline.rb index 028f2560a..06f1ace1a 100644 --- a/app/models/discipline.rb +++ b/app/models/discipline.rb @@ -1,4 +1,4 @@ -class Discipline < ActiveRecord::Base +class Discipline < ApplicationRecord acts_as_copy_target LABEL_COLORS = YAML.safe_load( @@ -19,9 +19,12 @@ class Discipline < ActiveRecord::Base validates :api_code, uniqueness: true scope :by_unity_id, lambda { |unity_id| by_unity_id(unity_id) } - scope :by_teacher_id, lambda { |teacher_id| joins(:teacher_discipline_classrooms).where(teacher_discipline_classrooms: { teacher_id: teacher_id }).uniq } + scope :by_teacher_id, lambda { |teacher_id| + joins(:teacher_discipline_classrooms).where(teacher_discipline_classrooms: + { teacher_id: teacher_id }).distinct + } scope :by_classroom_id, lambda { |classroom_id| - joins(:teacher_discipline_classrooms).where(teacher_discipline_classrooms: { classroom_id: classroom_id }).uniq + joins(:teacher_discipline_classrooms).where(teacher_discipline_classrooms: { classroom_id: classroom_id }).distinct } # It works only when the query chain has join with @@ -44,7 +47,7 @@ class Discipline < ActiveRecord::Base ).or( differentiated_exam_rules[:score_type].eq(score_type) ) - ).uniq + ).distinct else scoped.where( ExamRule.arel_table[:score_type].eq(score_type). @@ -52,13 +55,13 @@ class Discipline < ActiveRecord::Base ExamRule.arel_table[:score_type].eq(ScoreTypes::NUMERIC_AND_CONCEPT). and(TeacherDisciplineClassroom.arel_table[:score_type].eq(score_type)) ) - ).uniq + ).distinct end } scope :by_grade, lambda { |grade| by_grade(grade) } scope :by_classroom, lambda { |classroom| by_classroom(classroom) } - scope :by_teacher_and_classroom, lambda { |teacher_id, classroom_id| joins(:teacher_discipline_classrooms).where(teacher_discipline_classrooms: { teacher_id: teacher_id, classroom_id: classroom_id }).uniq } + scope :by_teacher_and_classroom, lambda { |teacher_id, classroom_id| joins(:teacher_discipline_classrooms).where(teacher_discipline_classrooms: { teacher_id: teacher_id, classroom_id: classroom_id }).distinct } scope :ordered, -> { order(arel_table[:description].asc) } scope :order_by_sequence, -> { order(arel_table[:sequence].asc) } scope :not_grouper, -> { where(grouper: false) } @@ -118,19 +121,19 @@ def self.by_unity_id(unity_id) .join_sources ) .where(classrooms: { unity_id: unity_id }) - .uniq + .distinct end def self.by_grade(grade_id) joins(teacher_discipline_classrooms: [classroom: :classrooms_grades]) - .where(classrooms_grades: { grade_id: grade_id }).uniq + .where(classrooms_grades: { grade_id: grade_id }).distinct end def self.by_classroom(classroom) joins(:teacher_discipline_classrooms).where( teacher_discipline_classrooms: { classroom_id: classroom } ) - .uniq + .distinct end private diff --git a/app/models/discipline_content_record.rb b/app/models/discipline_content_record.rb index 7cd5f0492..333457bff 100644 --- a/app/models/discipline_content_record.rb +++ b/app/models/discipline_content_record.rb @@ -91,14 +91,15 @@ def uniqueness_of_discipline_content_record end def uniqueness_of_class_number - discipline_content_record = DisciplineContentRecord.by_teacher_id(content_record.teacher_id) - .by_classroom_id(content_record.classroom_id) - .by_discipline_id(discipline_id) - .by_date(content_record.record_date) - .by_class_number(class_number) - .exists? - - if discipline_content_record + relation = DisciplineContentRecord.by_teacher_id(content_record.teacher_id) + .by_classroom_id(content_record.classroom_id) + .by_discipline_id(discipline_id) + .by_date(content_record.record_date) + .by_class_number(class_number) + + relation = relation.where.not(id: id) if persisted? + + if relation.exists? errors.add(:class_number, I18n.t('activerecord.errors.models.discipline_content_record.attributes.discipline_id.class_number_in_use')) end end @@ -110,7 +111,7 @@ def ensure_is_school_day record_date.present? grades.each do |grade| - unless content_record.school_calendar.school_day?(record_date, grade, classroom, discipline) + unless content_record.school_calendar.school_day?(record_date, grade, classroom_id, discipline) errors.add(:base, "") content_record.errors.add(:record_date, :not_school_calendar_day) end diff --git a/app/models/discipline_lesson_plan.rb b/app/models/discipline_lesson_plan.rb index c9c6f97c5..80d3fc2dd 100644 --- a/app/models/discipline_lesson_plan.rb +++ b/app/models/discipline_lesson_plan.rb @@ -1,4 +1,4 @@ -class DisciplineLessonPlan < ActiveRecord::Base +class DisciplineLessonPlan < ApplicationRecord include Audit include Filterable include TeacherRelationable diff --git a/app/models/discipline_teaching_plan.rb b/app/models/discipline_teaching_plan.rb index 74e634333..b2e91924f 100644 --- a/app/models/discipline_teaching_plan.rb +++ b/app/models/discipline_teaching_plan.rb @@ -1,4 +1,4 @@ -class DisciplineTeachingPlan < ActiveRecord::Base +class DisciplineTeachingPlan < ApplicationRecord include Audit include ColumnsLockable include TeacherRelationable diff --git a/app/models/entity.rb b/app/models/entity.rb index 4e36b2844..4d77a4072 100644 --- a/app/models/entity.rb +++ b/app/models/entity.rb @@ -1,4 +1,4 @@ -class Entity < ActiveRecord::Base +class Entity < ApplicationRecord acts_as_copy_target cattr_accessor :current diff --git a/app/models/entity_configuration.rb b/app/models/entity_configuration.rb index dfdbaac51..2e8e393cb 100644 --- a/app/models/entity_configuration.rb +++ b/app/models/entity_configuration.rb @@ -1,4 +1,4 @@ -class EntityConfiguration < ActiveRecord::Base +class EntityConfiguration < ApplicationRecord acts_as_copy_target audited except: [:logo] diff --git a/app/models/exam_rule.rb b/app/models/exam_rule.rb index 00859ea87..79d0ac54a 100644 --- a/app/models/exam_rule.rb +++ b/app/models/exam_rule.rb @@ -1,4 +1,4 @@ -class ExamRule < ActiveRecord::Base +class ExamRule < ApplicationRecord acts_as_copy_target audited diff --git a/app/models/final_recovery_diary_record.rb b/app/models/final_recovery_diary_record.rb index 423b5f958..dc3f64787 100644 --- a/app/models/final_recovery_diary_record.rb +++ b/app/models/final_recovery_diary_record.rb @@ -1,4 +1,4 @@ -class FinalRecoveryDiaryRecord < ActiveRecord::Base +class FinalRecoveryDiaryRecord < ApplicationRecord include Audit include Filterable @@ -9,7 +9,7 @@ class FinalRecoveryDiaryRecord < ActiveRecord::Base before_destroy :valid_for_destruction? - belongs_to :recovery_diary_record, dependent: :destroy + belongs_to :recovery_diary_record belongs_to :school_calendar accepts_nested_attributes_for :recovery_diary_record diff --git a/app/models/grade.rb b/app/models/grade.rb index 722fd0e3a..41560746f 100644 --- a/app/models/grade.rb +++ b/app/models/grade.rb @@ -11,6 +11,7 @@ class Grade < ActiveRecord::Base has_many :unity_discipline_grades has_many :disciplines, through: :unity_discipline_grades has_many :mvw_infrequency_tracking_classrooms + has_many :teacher_discipline_classrooms, dependent: :destroy has_and_belongs_to_many :custom_rounding_tables @@ -26,7 +27,7 @@ class Grade < ActiveRecord::Base validates :api_code, uniqueness: true def self.by_unity(unity) - joins(:classrooms).where(classrooms: { unity_id: unity }).uniq + joins(:classrooms).where(classrooms: { unity_id: unity }).distinct end def self.by_teacher(teacher) @@ -36,7 +37,7 @@ def self.by_teacher(teacher) .join_sources ) .where(TeacherDisciplineClassroom.arel_table[:teacher_id].eq(teacher)) - .uniq + .distinct end def self.by_year(year) diff --git a/app/models/grouped_discipline.rb b/app/models/grouped_discipline.rb index 11dacda2e..0e24a9098 100644 --- a/app/models/grouped_discipline.rb +++ b/app/models/grouped_discipline.rb @@ -1,4 +1,4 @@ -class GroupedDiscipline < ActiveRecord::Base +class GroupedDiscipline < ApplicationRecord scope :by_teacher_unity_and_year, lambda { |teacher_id, unity_id, year| where(teacher_id: teacher_id, unity_id: unity_id, year: year) } diff --git a/app/models/grouped_teacher_discipline_classrooms.rb b/app/models/grouped_teacher_discipline_classrooms.rb new file mode 100644 index 000000000..87f0608ad --- /dev/null +++ b/app/models/grouped_teacher_discipline_classrooms.rb @@ -0,0 +1,5 @@ +class GroupedTeacherDisciplineClassrooms < ActiveRecord::Base + def readonly? + true + end +end diff --git a/app/models/ieducar_api_exam_posting.rb b/app/models/ieducar_api_exam_posting.rb index 284e47a19..2a3662605 100644 --- a/app/models/ieducar_api_exam_posting.rb +++ b/app/models/ieducar_api_exam_posting.rb @@ -1,4 +1,4 @@ -class IeducarApiExamPosting < ActiveRecord::Base +class IeducarApiExamPosting < ApplicationRecord audited only: [:teacher_id] acts_as_copy_target diff --git a/app/models/ieducar_api_synchronization.rb b/app/models/ieducar_api_synchronization.rb index 212083253..303a1cdd8 100644 --- a/app/models/ieducar_api_synchronization.rb +++ b/app/models/ieducar_api_synchronization.rb @@ -1,4 +1,4 @@ -class IeducarApiSynchronization < ActiveRecord::Base +class IeducarApiSynchronization < ApplicationRecord acts_as_copy_target has_enumeration_for :status, diff --git a/app/models/knowledge_area.rb b/app/models/knowledge_area.rb index 9d94d8d68..8b7bbe75f 100644 --- a/app/models/knowledge_area.rb +++ b/app/models/knowledge_area.rb @@ -1,4 +1,4 @@ -class KnowledgeArea < ActiveRecord::Base +class KnowledgeArea < ApplicationRecord include Discardable acts_as_copy_target @@ -18,22 +18,22 @@ class KnowledgeArea < ActiveRecord::Base scope :by_unity, lambda { |unity_id| joins(disciplines: { teacher_discipline_classrooms: :classroom }).where( classrooms: { unity_id: unity_id } - ).uniq + ).distinct } scope :by_teacher, lambda { |teacher_id| joins(disciplines: :teacher_discipline_classrooms).where( teacher_discipline_classrooms: { teacher_id: teacher_id } - ).uniq + ).distinct } scope :by_classroom_id, lambda { |classroom_id| joins(disciplines: :teacher_discipline_classrooms).where( teacher_discipline_classrooms: { classroom_id: classroom_id } - ).uniq + ).distinct } scope :by_grade, lambda { |grade_id| joins(disciplines: { teacher_discipline_classrooms: { classroom: :classrooms_grades } }).where( classrooms_grades: { grade_id: grade_id } - ).uniq + ).distinct } scope :by_discipline_id, ->(discipline_id) { joins(:disciplines).where(disciplines: { id: discipline_id }) } scope :ordered, -> { order(arel_table[:description].asc) } diff --git a/app/models/knowledge_area_content_record.rb b/app/models/knowledge_area_content_record.rb index 2b0449e3a..3b42d8c2c 100644 --- a/app/models/knowledge_area_content_record.rb +++ b/app/models/knowledge_area_content_record.rb @@ -86,7 +86,7 @@ def ensure_is_school_day content_record.school_calendar.present? && record_date.present? - unless content_record.school_calendar.school_day?(record_date, grades.first, classroom) + unless content_record.school_calendar.school_day?(record_date, grades.first, classroom_id) errors.add(:base, "") content_record.errors.add(:record_date, :not_school_calendar_day) end diff --git a/app/models/knowledge_area_teaching_plan.rb b/app/models/knowledge_area_teaching_plan.rb index 69d79ade4..dd4a5b8c1 100644 --- a/app/models/knowledge_area_teaching_plan.rb +++ b/app/models/knowledge_area_teaching_plan.rb @@ -1,4 +1,4 @@ -class KnowledgeAreaTeachingPlan < ActiveRecord::Base +class KnowledgeAreaTeachingPlan < ApplicationRecord include Audit include TeacherRelationable include Translatable @@ -96,7 +96,7 @@ def self.by_teacher(teacher) .eq(teacher) .and(TeacherDisciplineClassroom.arel_table[:active] .eq('t'))) - .uniq + .distinct end def self.by_knowledge_area(knowledge_area) diff --git a/app/models/knowledge_area_teaching_plan_knowledge_area.rb b/app/models/knowledge_area_teaching_plan_knowledge_area.rb index a8c51528b..bc664c9cb 100644 --- a/app/models/knowledge_area_teaching_plan_knowledge_area.rb +++ b/app/models/knowledge_area_teaching_plan_knowledge_area.rb @@ -1,4 +1,4 @@ -class KnowledgeAreaTeachingPlanKnowledgeArea < ActiveRecord::Base +class KnowledgeAreaTeachingPlanKnowledgeArea < ApplicationRecord audited belongs_to :knowledge_area_teaching_plan diff --git a/app/models/label.rb b/app/models/label.rb index 46a10c699..5a8cb227a 100644 --- a/app/models/label.rb +++ b/app/models/label.rb @@ -1,4 +1,4 @@ -class Label < ActiveRecord::Base +class Label < ApplicationRecord COLORS = %w(#9121AD #AD2121 #AD6421 #C9AC13 #21AD27 #21A5AD #212FAD #BC62D2 #D26262 #C88F5A #D8BC59 #5AB8CD #5AB8CD #6274D2 #7A7A7A) diff --git a/app/models/learning_objectives_and_skill.rb b/app/models/learning_objectives_and_skill.rb index c54242068..869f5bc7a 100644 --- a/app/models/learning_objectives_and_skill.rb +++ b/app/models/learning_objectives_and_skill.rb @@ -1,4 +1,4 @@ -class LearningObjectivesAndSkill < ActiveRecord::Base +class LearningObjectivesAndSkill < ApplicationRecord include Audit audited diff --git a/app/models/lesson_plan.rb b/app/models/lesson_plan.rb index fe31838d8..b6f657b09 100644 --- a/app/models/lesson_plan.rb +++ b/app/models/lesson_plan.rb @@ -1,4 +1,4 @@ -class LessonPlan < ActiveRecord::Base +class LessonPlan < ApplicationRecord include Audit include TeacherRelationable include Translatable diff --git a/app/models/lesson_plan_attachment.rb b/app/models/lesson_plan_attachment.rb index 75f7f336f..046541ee2 100644 --- a/app/models/lesson_plan_attachment.rb +++ b/app/models/lesson_plan_attachment.rb @@ -1,4 +1,4 @@ -class LessonPlanAttachment < ActiveRecord::Base +class LessonPlanAttachment < ApplicationRecord audited belongs_to :lesson_plan diff --git a/app/models/lessons_board_lesson_weekday.rb b/app/models/lessons_board_lesson_weekday.rb index edcac054b..477320dba 100644 --- a/app/models/lessons_board_lesson_weekday.rb +++ b/app/models/lessons_board_lesson_weekday.rb @@ -1,4 +1,4 @@ -class LessonsBoardLessonWeekday < ActiveRecord::Base +class LessonsBoardLessonWeekday < ApplicationRecord include Audit include Discardable diff --git a/app/models/maintenance_adjustment.rb b/app/models/maintenance_adjustment.rb index a7d56aa23..52cbcc2a6 100644 --- a/app/models/maintenance_adjustment.rb +++ b/app/models/maintenance_adjustment.rb @@ -1,4 +1,4 @@ -class MaintenanceAdjustment < ActiveRecord::Base +class MaintenanceAdjustment < ApplicationRecord acts_as_copy_target include Audit diff --git a/app/models/mvw_content_record_by_school_classroom_teacher.rb b/app/models/mvw_content_record_by_school_classroom_teacher.rb index 5e4493042..aff9b90a1 100644 --- a/app/models/mvw_content_record_by_school_classroom_teacher.rb +++ b/app/models/mvw_content_record_by_school_classroom_teacher.rb @@ -1,4 +1,4 @@ -class MvwContentRecordBySchoolClassroomTeacher < ActiveRecord::Base +class MvwContentRecordBySchoolClassroomTeacher < ApplicationRecord belongs_to :unity belongs_to :classroom belongs_to :teacher diff --git a/app/models/mvw_frequency_by_school_classroom_teacher.rb b/app/models/mvw_frequency_by_school_classroom_teacher.rb index f91235f00..7654c88d9 100644 --- a/app/models/mvw_frequency_by_school_classroom_teacher.rb +++ b/app/models/mvw_frequency_by_school_classroom_teacher.rb @@ -1,4 +1,4 @@ -class MvwFrequencyBySchoolClassroomTeacher < ActiveRecord::Base +class MvwFrequencyBySchoolClassroomTeacher < ApplicationRecord belongs_to :unity belongs_to :classroom belongs_to :teacher diff --git a/app/models/notice.rb b/app/models/notice.rb index 400a99dbc..1daf8b6cf 100644 --- a/app/models/notice.rb +++ b/app/models/notice.rb @@ -1,4 +1,4 @@ -class Notice < ActiveRecord::Base +class Notice < ApplicationRecord has_enumeration_for :kind, with: NoticeTypes, create_scopes: true belongs_to :noticeable, polymorphic: true diff --git a/app/models/objective.rb b/app/models/objective.rb index 39fd0a1b0..756294159 100644 --- a/app/models/objective.rb +++ b/app/models/objective.rb @@ -1,4 +1,4 @@ -class Objective < ActiveRecord::Base +class Objective < ApplicationRecord audited has_associated_audits diff --git a/app/models/objectives_lesson_plan.rb b/app/models/objectives_lesson_plan.rb index a5786e9ea..80edb505a 100644 --- a/app/models/objectives_lesson_plan.rb +++ b/app/models/objectives_lesson_plan.rb @@ -1,4 +1,4 @@ -class ObjectivesLessonPlan < ActiveRecord::Base +class ObjectivesLessonPlan < ApplicationRecord audited except: [:lesson_plan_id], allow_mass_assignment: true, associated_with: [:lesson_plan, :objective] diff --git a/app/models/objectives_teaching_plan.rb b/app/models/objectives_teaching_plan.rb index d45ea09dc..f874474a1 100644 --- a/app/models/objectives_teaching_plan.rb +++ b/app/models/objectives_teaching_plan.rb @@ -1,4 +1,4 @@ -class ObjectivesTeachingPlan < ActiveRecord::Base +class ObjectivesTeachingPlan < ApplicationRecord audited except: [:teaching_plan_id], allow_mass_assignment: true, associated_with: [:teaching_plan, :objective] diff --git a/app/models/observation_diary_record.rb b/app/models/observation_diary_record.rb index 564dd3a6e..51def5328 100644 --- a/app/models/observation_diary_record.rb +++ b/app/models/observation_diary_record.rb @@ -1,4 +1,4 @@ -class ObservationDiaryRecord < ActiveRecord::Base +class ObservationDiaryRecord < ApplicationRecord include Discardable include Audit include ColumnsLockable @@ -23,6 +23,7 @@ class ObservationDiaryRecord < ActiveRecord::Base belongs_to :discipline has_many :notes, class_name: 'ObservationDiaryRecordNote', dependent: :destroy has_many :observation_diary_record_attachments, dependent: :destroy + has_many :students, through: :notes accepts_nested_attributes_for :observation_diary_record_attachments, allow_destroy: true accepts_nested_attributes_for :notes, allow_destroy: true @@ -34,6 +35,7 @@ class ObservationDiaryRecord < ActiveRecord::Base scope :by_classroom, -> classroom_ids { where(classroom_id: classroom_ids) } scope :by_discipline, -> discipline_ids { where(discipline_id: discipline_ids) } scope :by_date, -> date { where(date: date.to_date) } + scope :by_student_id, -> student_id { joins(:notes).merge(ObservationDiaryRecordNote.by_student_id(student_id)) } scope :ordered, -> { order(date: :desc) } validates_date :date diff --git a/app/models/observation_diary_record_note.rb b/app/models/observation_diary_record_note.rb index 17fd228f7..9798a743d 100644 --- a/app/models/observation_diary_record_note.rb +++ b/app/models/observation_diary_record_note.rb @@ -1,4 +1,4 @@ -class ObservationDiaryRecordNote < ActiveRecord::Base +class ObservationDiaryRecordNote < ApplicationRecord include Discardable include Audit @@ -16,6 +16,8 @@ class ObservationDiaryRecordNote < ActiveRecord::Base default_scope -> { kept } + scope :by_student_id, -> student_id { joins(:students).where(students: { id: student_id }) } + validates :observation_diary_record, presence: true validates :description, presence: true diff --git a/app/models/observation_diary_record_note_student.rb b/app/models/observation_diary_record_note_student.rb index c9852b969..5e991384d 100644 --- a/app/models/observation_diary_record_note_student.rb +++ b/app/models/observation_diary_record_note_student.rb @@ -1,4 +1,4 @@ -class ObservationDiaryRecordNoteStudent < ActiveRecord::Base +class ObservationDiaryRecordNoteStudent < ApplicationRecord include Discardable include Audit diff --git a/app/models/recovery_diary_record.rb b/app/models/recovery_diary_record.rb index 303d0bc2b..761c8b53f 100644 --- a/app/models/recovery_diary_record.rb +++ b/app/models/recovery_diary_record.rb @@ -21,16 +21,16 @@ class RecoveryDiaryRecord < ActiveRecord::Base accepts_nested_attributes_for :students, allow_destroy: true - has_one :school_term_recovery_diary_record - has_one :final_recovery_diary_record - has_one :avaliation_recovery_diary_record - has_one :avaliation_recovery_lowest_note + has_one :school_term_recovery_diary_record, dependent: :destroy + has_one :final_recovery_diary_record, dependent: :destroy + has_one :avaliation_recovery_diary_record, dependent: :destroy + has_one :avaliation_recovery_lowest_note, dependent: :destroy scope :by_teacher_id, lambda { |teacher_id| joins(discipline: :teacher_discipline_classrooms) .where(teacher_discipline_classrooms: { teacher_id: teacher_id }) - .uniq + .distinct } scope :by_classroom_id, lambda { |classroom_id| where(classroom_id: classroom_id) } diff --git a/app/models/recovery_diary_record_student.rb b/app/models/recovery_diary_record_student.rb index 789b69382..b6b794ad6 100644 --- a/app/models/recovery_diary_record_student.rb +++ b/app/models/recovery_diary_record_student.rb @@ -1,4 +1,4 @@ -class RecoveryDiaryRecordStudent < ActiveRecord::Base +class RecoveryDiaryRecordStudent < ApplicationRecord include Audit include Discardable diff --git a/app/models/recovery_exam_rule.rb b/app/models/recovery_exam_rule.rb index be189e019..4191b151f 100644 --- a/app/models/recovery_exam_rule.rb +++ b/app/models/recovery_exam_rule.rb @@ -1,4 +1,4 @@ -class RecoveryExamRule < ActiveRecord::Base +class RecoveryExamRule < ApplicationRecord include Discardable acts_as_copy_target diff --git a/app/models/role_permission.rb b/app/models/role_permission.rb index b457d9e6b..f42d6961d 100644 --- a/app/models/role_permission.rb +++ b/app/models/role_permission.rb @@ -1,4 +1,4 @@ -class RolePermission < ActiveRecord::Base +class RolePermission < ApplicationRecord acts_as_copy_target audited associated_with: :role, only: [:feature, :permission] diff --git a/app/models/school_calendar.rb b/app/models/school_calendar.rb index f46344f13..ee204f599 100644 --- a/app/models/school_calendar.rb +++ b/app/models/school_calendar.rb @@ -1,4 +1,4 @@ -class SchoolCalendar < ActiveRecord::Base +class SchoolCalendar < ApplicationRecord acts_as_copy_target before_validation :self_assign_to_steps diff --git a/app/models/school_calendar_classroom_step.rb b/app/models/school_calendar_classroom_step.rb index b07a2a3bf..c5195968b 100644 --- a/app/models/school_calendar_classroom_step.rb +++ b/app/models/school_calendar_classroom_step.rb @@ -1,4 +1,4 @@ -class SchoolCalendarClassroomStep < ActiveRecord::Base +class SchoolCalendarClassroomStep < ApplicationRecord include SchoolTermable audited @@ -46,7 +46,7 @@ def school_calendar_step_day?(date) return false unless step_from_date.eql?(self) - school_calendar.school_day?(date, classroom.grade_ids, classroom) + school_calendar.school_day?(date, classroom.grade_ids, classroom_id) end def school_calendar_day_allows_entry?(date) @@ -54,7 +54,7 @@ def school_calendar_day_allows_entry?(date) return false unless step_from_date.eql?(self) - school_calendar.day_allows_entry?(date, classroom.grade_ids, classroom) + school_calendar.day_allows_entry?(date, classroom.grade_ids, classroom_id) end def first_school_calendar_date diff --git a/app/models/school_calendar_discipline_grade.rb b/app/models/school_calendar_discipline_grade.rb index 0bd562caf..507e33ddc 100644 --- a/app/models/school_calendar_discipline_grade.rb +++ b/app/models/school_calendar_discipline_grade.rb @@ -1,4 +1,4 @@ -class SchoolCalendarDisciplineGrade < ActiveRecord::Base +class SchoolCalendarDisciplineGrade < ApplicationRecord belongs_to :school_calendar belongs_to :discipline belongs_to :grade diff --git a/app/models/school_calendar_event.rb b/app/models/school_calendar_event.rb index 8ea94f5e2..f78a3ee9d 100644 --- a/app/models/school_calendar_event.rb +++ b/app/models/school_calendar_event.rb @@ -1,4 +1,4 @@ -class SchoolCalendarEvent < ActiveRecord::Base +class SchoolCalendarEvent < ApplicationRecord acts_as_copy_target audited diff --git a/app/models/school_calendar_event_batch.rb b/app/models/school_calendar_event_batch.rb index f18f740bd..21b48b46c 100644 --- a/app/models/school_calendar_event_batch.rb +++ b/app/models/school_calendar_event_batch.rb @@ -1,4 +1,4 @@ -class SchoolCalendarEventBatch < ActiveRecord::Base +class SchoolCalendarEventBatch < ApplicationRecord audited has_many :school_calendar_events, dependent: :nullify, foreign_key: 'batch_id' diff --git a/app/models/school_term_recovery_diary_record.rb b/app/models/school_term_recovery_diary_record.rb index 3ed7100c9..3802ed90a 100644 --- a/app/models/school_term_recovery_diary_record.rb +++ b/app/models/school_term_recovery_diary_record.rb @@ -1,4 +1,4 @@ -class SchoolTermRecoveryDiaryRecord < ActiveRecord::Base +class SchoolTermRecoveryDiaryRecord < ApplicationRecord include Audit include Stepable include Filterable @@ -10,7 +10,7 @@ class SchoolTermRecoveryDiaryRecord < ActiveRecord::Base before_destroy :valid_for_destruction? - belongs_to :recovery_diary_record, dependent: :destroy + belongs_to :recovery_diary_record accepts_nested_attributes_for :recovery_diary_record @@ -88,14 +88,14 @@ def uniqueness_of_school_term_recovery_diary_record end def classroom_grades_with_recovery_rule - return @classroom_grade if @classroom_grade + return @classroom_grade if @classroom_grade.present? @classroom_grade = [] classroom_grades&.each { |classroom_grade| @classroom_grade << classroom_grade unless classroom_grade.exam_rule.recovery_type.eql?(0) } if @classroom_grade.empty? - classroom_grades.first + classroom_grades else @classroom_grade end diff --git a/app/models/school_term_type.rb b/app/models/school_term_type.rb index 84d8dc187..79686a2a5 100644 --- a/app/models/school_term_type.rb +++ b/app/models/school_term_type.rb @@ -1,4 +1,4 @@ -class SchoolTermType < ActiveRecord::Base +class SchoolTermType < ApplicationRecord include SchoolCalendarFilterable has_many :school_term_type_steps, -> { kept }, dependent: :destroy diff --git a/app/models/school_term_type_step.rb b/app/models/school_term_type_step.rb index 25a966d2e..65077f9c9 100644 --- a/app/models/school_term_type_step.rb +++ b/app/models/school_term_type_step.rb @@ -1,4 +1,4 @@ -class SchoolTermTypeStep < ActiveRecord::Base +class SchoolTermTypeStep < ApplicationRecord include Discardable include SchoolCalendarFilterable diff --git a/app/models/specific_step.rb b/app/models/specific_step.rb index d9375475b..314bcf8ed 100644 --- a/app/models/specific_step.rb +++ b/app/models/specific_step.rb @@ -1,4 +1,4 @@ -class SpecificStep < ActiveRecord::Base +class SpecificStep < ApplicationRecord include Discardable audited diff --git a/app/models/student.rb b/app/models/student.rb index 2fc5bc361..d0cb119f5 100644 --- a/app/models/student.rb +++ b/app/models/student.rb @@ -1,4 +1,4 @@ -class Student < ActiveRecord::Base +class Student < ApplicationRecord include Discardable acts_as_copy_target @@ -76,14 +76,14 @@ def average(classroom, discipline, step) end def classrooms - Classroom.joins(classrooms_grades: :student_enrollment_classrooms).merge(StudentEnrollmentClassroom.by_student(self.id)).uniq + Classroom.joins(classrooms_grades: :student_enrollment_classrooms).merge(StudentEnrollmentClassroom.by_student(self.id)).distinct end def current_classrooms Classroom.joins(classrooms_grades: :student_enrollment_classrooms).merge( StudentEnrollmentClassroom.by_student(id) .by_date(Date.current) - ).uniq + ).distinct end private diff --git a/app/models/student_enrollment.rb b/app/models/student_enrollment.rb index a04c9bfde..e75fae89e 100644 --- a/app/models/student_enrollment.rb +++ b/app/models/student_enrollment.rb @@ -21,6 +21,9 @@ class StudentEnrollment < ActiveRecord::Base scope :by_grade, lambda { |grade_id| joins(:student_enrollment_classrooms).merge(StudentEnrollmentClassroom.by_grade(grade_id)) } + scope :by_classroom_grades, lambda { |classrooms_grade_id| + joins(:student_enrollment_classrooms).merge(StudentEnrollmentClassroom.by_classroom_grade(classrooms_grade_id)) + } scope :by_discipline, lambda {|discipline_id| by_discipline_query(discipline_id)} scope :by_score_type, lambda {|score_type, classroom_id| by_score_type_query(score_type, classroom_id)} scope :by_opinion_type, lambda {|opinion_type, classroom_id| by_opinion_type_query(opinion_type, classroom_id)} @@ -31,11 +34,26 @@ class StudentEnrollment < ActiveRecord::Base scope :by_date, lambda { |date| joins(:student_enrollment_classrooms).merge(StudentEnrollmentClassroom.by_date(date)) } scope :by_date_range, lambda { |start_at, end_at| joins(:student_enrollment_classrooms).merge(StudentEnrollmentClassroom.by_date_range(start_at, end_at)) } scope :by_date_not_before, lambda { |date| joins(:student_enrollment_classrooms).merge(StudentEnrollmentClassroom.by_date_not_before(date)) } + scope :by_date_not_after, lambda { |date| joins(:student_enrollment_classrooms).merge(StudentEnrollmentClassroom.by_date_not_after(date)) } scope :by_period, lambda { |period| joins(:student_enrollment_classrooms).merge(StudentEnrollmentClassroom.by_period(period)) } scope :show_as_inactive, lambda { joins(:student_enrollment_classrooms).merge(StudentEnrollmentClassroom.show_as_inactive) } scope :with_recovery_note_in_step, lambda { |step, discipline_id| with_recovery_note_in_step_query(step, discipline_id) } scope :active, -> { where(active: 1) } scope :ordered, -> { joins(:student, :student_enrollment_classrooms).order('sequence ASC, students.name ASC') } + scope :status_attending, lambda { + where( + student_enrollments: { + status: [ + StudentEnrollmentStatus::STUDYING, + StudentEnrollmentStatus::APPROVED, + StudentEnrollmentStatus::APPROVED_WITH_DEPENDENCY, + StudentEnrollmentStatus::RECLASSIFIED, + StudentEnrollmentStatus::APPROVE_BY_COUNCIL, + StudentEnrollmentStatus::REPPROVED + ] + } + ) + } def self.by_discipline_query(discipline_id) unless discipline_id.blank? diff --git a/app/models/student_enrollment_classroom.rb b/app/models/student_enrollment_classroom.rb index d78ac4753..a82f37ea9 100644 --- a/app/models/student_enrollment_classroom.rb +++ b/app/models/student_enrollment_classroom.rb @@ -26,9 +26,11 @@ class StudentEnrollmentClassroom < ActiveRecord::Base where("? >= joined_at AND (? < left_at OR coalesce(left_at, '') = '')", date.to_date, date.to_date) } scope :by_date_not_before, ->(date) { where.not('joined_at < ?', date.to_date) } + scope :by_date_not_after, ->(date) { where("left_at IN (NULL, '') OR left_at > ?", date.to_date) } scope :by_score_type, lambda {|score_type, classroom_id| by_score_type_query(score_type, classroom_id)} scope :show_as_inactive, -> { where(show_as_inactive_when_not_in_date: 't') } scope :by_grade, ->(grade_id) { joins(:classrooms_grade).where(classrooms_grades: { grade_id: grade_id }) } + scope :by_classroom_grade, ->(classrooms_grade_id) { where(classrooms_grades: classrooms_grade_id) } scope :by_student, ->(student_id) { joins(student_enrollment: :student).where(students: { id: student_id }) } scope :by_student_enrollment, ->(student_enrollment_id) { where(student_enrollment_id: student_enrollment_id) } scope :active, lambda { @@ -36,7 +38,7 @@ class StudentEnrollmentClassroom < ActiveRecord::Base } scope :ordered, -> { order(:joined_at, :index) } scope :ordered_student, -> { joins(student_enrollment: :student).order('sequence ASC, students.name ASC') } - + scope :status_attending, -> { joins(:student_enrollment).merge(StudentEnrollment.status_attending) } delegate :student_id, to: :student_enrollment, allow_nil: true def self.by_date_range(start_at, end_at) diff --git a/app/models/student_enrollment_dependence.rb b/app/models/student_enrollment_dependence.rb index 00e8a7ef9..cfed6278a 100644 --- a/app/models/student_enrollment_dependence.rb +++ b/app/models/student_enrollment_dependence.rb @@ -1,4 +1,4 @@ -class StudentEnrollmentDependence < ActiveRecord::Base +class StudentEnrollmentDependence < ApplicationRecord include Discardable audited diff --git a/app/models/student_unification.rb b/app/models/student_unification.rb index e2caa1ad7..c5425a0b2 100644 --- a/app/models/student_unification.rb +++ b/app/models/student_unification.rb @@ -1,4 +1,4 @@ -class StudentUnification < ActiveRecord::Base +class StudentUnification < ApplicationRecord audited belongs_to :student diff --git a/app/models/system_notification_target.rb b/app/models/system_notification_target.rb index 5ddfd2130..dcc5c6863 100644 --- a/app/models/system_notification_target.rb +++ b/app/models/system_notification_target.rb @@ -1,4 +1,4 @@ -class SystemNotificationTarget < ActiveRecord::Base +class SystemNotificationTarget < ApplicationRecord belongs_to :system_notification belongs_to :user diff --git a/app/models/teacher.rb b/app/models/teacher.rb index 6ac39e921..fc1dd417d 100644 --- a/app/models/teacher.rb +++ b/app/models/teacher.rb @@ -1,4 +1,4 @@ -class Teacher < ActiveRecord::Base +class Teacher < ApplicationRecord include Discardable acts_as_copy_target @@ -47,7 +47,7 @@ class Teacher < ActiveRecord::Base def self.active_query joins_teacher_discipline_classrooms.where( active: true - ).uniq + ).distinct end def self.search(value) @@ -65,7 +65,7 @@ def self.search(value) def self.by_unity_id(unity_id) joins_teacher_discipline_classrooms.where(classrooms: { unity_id: unity_id }) .active - .uniq + .distinct end def self.filter_current_teachers_by_year(year) diff --git a/app/models/teacher_discipline_classroom.rb b/app/models/teacher_discipline_classroom.rb index a1423dc05..03db90cc3 100644 --- a/app/models/teacher_discipline_classroom.rb +++ b/app/models/teacher_discipline_classroom.rb @@ -1,4 +1,4 @@ -class TeacherDisciplineClassroom < ActiveRecord::Base +class TeacherDisciplineClassroom < ApplicationRecord include Audit include Discardable @@ -9,6 +9,7 @@ class TeacherDisciplineClassroom < ActiveRecord::Base belongs_to :teacher belongs_to :discipline belongs_to :classroom + belongs_to :grade delegate :knowledge_area, to: :discipline @@ -24,7 +25,7 @@ class TeacherDisciplineClassroom < ActiveRecord::Base scope :by_score_type, ->(score_type) { where(score_type: score_type) } scope :by_teacher_id, ->(teacher_id) { where(teacher_id: teacher_id) } scope :by_discipline_id, ->(discipline_id) { where(discipline_id: discipline_id) } - scope :by_grade_id, ->(grade_id) { joins(:classroom).merge(Classroom.by_grade(grade_id)) } + scope :by_grade_id, ->(grade_id) { where(grade_id: grade_id) } scope :by_year, ->(year) { where(year: year) } scope :by_knowledge_area_id, ->(knowledge_area_id) { joins(:discipline).where(disciplines: { knowledge_area_id: knowledge_area_id }) diff --git a/app/models/teaching_plan.rb b/app/models/teaching_plan.rb index 1328a62ad..5c57030ac 100644 --- a/app/models/teaching_plan.rb +++ b/app/models/teaching_plan.rb @@ -1,4 +1,4 @@ -class TeachingPlan < ActiveRecord::Base +class TeachingPlan < ApplicationRecord include Audit include TeacherRelationable include Translatable diff --git a/app/models/teaching_plan_attachment.rb b/app/models/teaching_plan_attachment.rb index 74c4bcba3..fd9e0c562 100644 --- a/app/models/teaching_plan_attachment.rb +++ b/app/models/teaching_plan_attachment.rb @@ -1,4 +1,4 @@ -class TeachingPlanAttachment < ActiveRecord::Base +class TeachingPlanAttachment < ApplicationRecord belongs_to :teaching_plan mount_uploader :attachment, DocUploader diff --git a/app/models/terms_dictionary.rb b/app/models/terms_dictionary.rb index 7896628dc..038c122fe 100644 --- a/app/models/terms_dictionary.rb +++ b/app/models/terms_dictionary.rb @@ -1,4 +1,4 @@ -class TermsDictionary < ActiveRecord::Base +class TermsDictionary < ApplicationRecord acts_as_copy_target audited diff --git a/app/models/test_setting.rb b/app/models/test_setting.rb index ac3d818b6..8a6f13705 100644 --- a/app/models/test_setting.rb +++ b/app/models/test_setting.rb @@ -1,4 +1,4 @@ -class TestSetting < ActiveRecord::Base +class TestSetting < ApplicationRecord acts_as_copy_target audited diff --git a/app/models/test_setting_test.rb b/app/models/test_setting_test.rb index 0aa01a2b9..14ef0dd23 100644 --- a/app/models/test_setting_test.rb +++ b/app/models/test_setting_test.rb @@ -1,4 +1,4 @@ -class TestSettingTest < ActiveRecord::Base +class TestSettingTest < ApplicationRecord acts_as_copy_target audited associated_with: :test_setting, except: :test_setting_id diff --git a/app/models/transfer_note.rb b/app/models/transfer_note.rb index efe8e2a4f..7822bf6ca 100644 --- a/app/models/transfer_note.rb +++ b/app/models/transfer_note.rb @@ -1,4 +1,4 @@ -class TransferNote < ActiveRecord::Base +class TransferNote < ApplicationRecord include Audit include Stepable include ColumnsLockable @@ -16,6 +16,7 @@ class TransferNote < ActiveRecord::Base attr_writer :unity_id before_destroy :valid_for_destruction? + before_destroy :before_destroy belongs_to :classroom belongs_to :discipline @@ -28,10 +29,7 @@ class TransferNote < ActiveRecord::Base before_validation :set_transfer_date, on: [:create, :update] - before_destroy :before_destroy - validates :unity_id, :discipline_id, :student_id, :teacher, presence: true - validate :at_least_one_daily_note_student default_scope -> { kept } @@ -69,18 +67,15 @@ def set_transfer_date self.transfer_date = recorded_at end - def at_least_one_daily_note_student - if daily_note_students.reject { |daily_note_student| daily_note_student.note.blank? }.empty? - errors.add(:daily_note_students, :at_least_one_daily_note_student) - end - end - def valid_for_destruction? @valid_for_destruction if defined?(@valid_for_destruction) @valid_for_destruction = begin self.validation_type = :destroy - valid? - !errors[:transfer_date].include?(I18n.t('errors.messages.not_allowed_to_post_in_date')) + forbidden_error = I18n.t('errors.messages.not_allowed_to_post_in_date') + + return false if errors[:transfer_date].include?(forbidden_error) + + self.valid? end end diff --git a/app/models/unique_daily_frequency_student.rb b/app/models/unique_daily_frequency_student.rb index 43d300c16..44afc6083 100644 --- a/app/models/unique_daily_frequency_student.rb +++ b/app/models/unique_daily_frequency_student.rb @@ -1,4 +1,4 @@ -class UniqueDailyFrequencyStudent < ActiveRecord::Base +class UniqueDailyFrequencyStudent < ApplicationRecord audited belongs_to :student diff --git a/app/models/unity.rb b/app/models/unity.rb index 1219680fa..a2b8ab792 100644 --- a/app/models/unity.rb +++ b/app/models/unity.rb @@ -38,11 +38,11 @@ class Unity < ActiveRecord::Base scope :ordered, -> { order(arel_table[:name].asc) } scope :by_api_codes, -> (codes) { where(arel_table[:api_code].in(codes)) } scope :with_api_code, -> { where(arel_table[:api_code].not_eq("")) } - scope :by_teacher, -> (teacher_id) { joins(:teacher_discipline_classrooms).where(teacher_discipline_classrooms: { teacher_id: teacher_id }).uniq } - scope :by_year, -> (year) { joins(:teacher_discipline_classrooms).where(teacher_discipline_classrooms: { year: year }).uniq } + scope :by_teacher, -> (teacher_id) { joins(:teacher_discipline_classrooms).where(teacher_discipline_classrooms: { teacher_id: teacher_id }).distinct } + scope :by_year, -> (year) { joins(:teacher_discipline_classrooms).where(teacher_discipline_classrooms: { year: year }).distinct } scope :by_teacher_with_school_calendar_year, lambda { joins(:teacher_discipline_classrooms, :school_calendars) - .where(TeacherDisciplineClassroom.arel_table[:year].eq(SchoolCalendar.arel_table[:year])).uniq + .where(TeacherDisciplineClassroom.arel_table[:year].eq(SchoolCalendar.arel_table[:year])).distinct } scope :by_date, lambda { |date| joins(school_calendars: :steps).where( diff --git a/app/models/unity_equipment.rb b/app/models/unity_equipment.rb index f474113da..646d0f912 100644 --- a/app/models/unity_equipment.rb +++ b/app/models/unity_equipment.rb @@ -1,4 +1,4 @@ -class UnityEquipment < ActiveRecord::Base +class UnityEquipment < ApplicationRecord acts_as_copy_target audited associated_with: :unity, except: :unity_id diff --git a/app/models/unity_school_day.rb b/app/models/unity_school_day.rb index a40218e34..4b5e3880b 100644 --- a/app/models/unity_school_day.rb +++ b/app/models/unity_school_day.rb @@ -1,4 +1,4 @@ -class UnitySchoolDay < ActiveRecord::Base +class UnitySchoolDay < ApplicationRecord audited belongs_to :unity diff --git a/app/models/user.rb b/app/models/user.rb index f28b31f32..18691715d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,4 +1,4 @@ -class User < ActiveRecord::Base +class User < ApplicationRecord acts_as_copy_target audited allow_mass_assignment: true, @@ -114,7 +114,8 @@ def self.to_csv 'Status', 'Aluno vinculado', 'Professor Vinculado', - 'Permissões' + 'Permissões', + 'Data de expiração' ] CSV.generate(headers: true) do |csv| @@ -131,7 +132,8 @@ def self.to_csv I18n.t("enumerations.user_status.#{user.status}"), user.student, user.teacher, - user.user_roles.map { |user_role| [user_role&.role&.name, user_role&.unity&.name].compact } + user.user_roles.map { |user_role| [user_role&.role&.name, user_role&.unity&.name].compact }, + user.expiration_date&.strftime("%d/%m/%Y") ] end end diff --git a/app/models/user_login.rb b/app/models/user_login.rb index 7148ec268..d7944638b 100644 --- a/app/models/user_login.rb +++ b/app/models/user_login.rb @@ -1,4 +1,4 @@ -class UserLogin < ActiveRecord::Base +class UserLogin < ApplicationRecord acts_as_copy_target belongs_to :user diff --git a/app/models/user_role.rb b/app/models/user_role.rb index 1416e90b1..533d4524a 100644 --- a/app/models/user_role.rb +++ b/app/models/user_role.rb @@ -1,4 +1,4 @@ -class UserRole < ActiveRecord::Base +class UserRole < ApplicationRecord include Searchable acts_as_copy_target diff --git a/app/models/worker_batch.rb b/app/models/worker_batch.rb index f3a4f5718..55e23f3d3 100644 --- a/app/models/worker_batch.rb +++ b/app/models/worker_batch.rb @@ -1,4 +1,4 @@ -class WorkerBatch < ActiveRecord::Base +class WorkerBatch < ApplicationRecord include LifeCycleTimeLoggable belongs_to :stateable, polymorphic: true diff --git a/app/queries/daily_frequency_query.rb b/app/queries/daily_frequency_query.rb index 5cf2ee458..57f0146a3 100644 --- a/app/queries/daily_frequency_query.rb +++ b/app/queries/daily_frequency_query.rb @@ -19,7 +19,11 @@ def by_classroom_id(classroom_id) def by_period(period) return self if period.blank? - where(period: period) + if period.eql?(Periods::FULL) + where(period: [Periods::FULL, Periods::MATUTINAL, Periods::VESPERTINE, Periods::NIGHTLY]) + else + where(period: period) + end end def by_frequency_date_between(frequency_date) diff --git a/app/reports/attendance_record_report.rb b/app/reports/attendance_record_report.rb index 4d9ce3a14..60ce91e8c 100644 --- a/app/reports/attendance_record_report.rb +++ b/app/reports/attendance_record_report.rb @@ -54,18 +54,19 @@ def build( @enrollment_classrooms = enrollment_classrooms_list @events = events @school_calendar = school_calendar - @second_teacher_signature = ActiveRecord::Type::Boolean.new.type_cast_from_user(second_teacher_signature) + @second_teacher_signature = ActiveRecord::Type::Boolean.new.cast(second_teacher_signature) @show_legend_hybrid = false @show_legend_remote = false @exists_legend_hybrid = false @exists_legend_remote = false @students_frequency_percentage = students_frequencies_percentage - self.legend = 'Legenda: N - Não enturmado, D - Dispensado da disciplina' + self.legend = 'Legenda: N - Não enturmado, D - Dispensado da disciplina, FJ - Falta justificada' @general_configuration = GeneralConfiguration.first @show_percentage_on_attendance = @general_configuration.show_percentage_on_attendance_record_report @show_inactive_enrollments = @general_configuration.show_inactive_enrollments + @do_not_send_justified_absence = @general_configuration.do_not_send_justified_absence header content @@ -126,7 +127,7 @@ def daily_frequencies_table daily_frequencies = @daily_frequencies.reject { |daily_frequency| !daily_frequency.students.any? } frequencies_and_events = daily_frequencies.to_a + @events.to_a - @daily_frequency_students = DailyFrequencyStudent.by_daily_frequency_id(@daily_frequencies.ids.to_a).to_a + @daily_frequency_students = DailyFrequencyStudent.by_daily_frequency_id(@daily_frequencies.map(&:id)).to_a frequencies_and_events = frequencies_and_events.sort_by do |obj| daily_frequency?(obj) ? obj.frequency_date : obj[:date] @@ -199,7 +200,13 @@ def daily_frequencies_table end unless student_frequency.present? - students[student_enrollment_classroom.id][:absences] = students[student_enrollment_classroom.id][:absences] + 1 + absences = 1 + + if @do_not_send_justified_absence && student_frequency.absence_justification_student_id + absences = 0 + end + + students[student_enrollment_classroom.id][:absences] = students[student_enrollment_classroom.id][:absences] + absences end hybrid_or_remote = frequency_hybrid_or_remote(student_enrollment, daily_frequency) @@ -348,7 +355,7 @@ def daily_frequencies_table text_box(self.legend, size: 8, at: [0, 30 + bottom_offset], width: 825, height: 20) - self.legend = 'Legenda: N - Não enturmado, D - Dispensado da disciplina' + self.legend = 'Legenda: N - Não enturmado, D - Dispensado da disciplina, FJ - Falta justificada' if index < sliced_frequencies_and_events.count - 1 start_new_page diff --git a/app/reports/base_report.rb b/app/reports/base_report.rb index 9a0cb2361..493e0c1c8 100644 --- a/app/reports/base_report.rb +++ b/app/reports/base_report.rb @@ -92,18 +92,39 @@ def text_box_truncate(title, information) draw_text(title, size: 8, style: :bold, at: [5, cursor - 10]) begin - text_height = height_of(information, width: bounds.width - 10, size: 10) + 30 + if information.class.eql?(Array) + text_formatted = [] + + information.each do |text| + if text[:styles].include?(:bold) + text[:text] = "#{text[:text]}" + end + if text[:styles].include?(:italic) + text[:text] = "#{text[:text]}" + end + if text[:styles].include?(:underline) + text[:text]= "#{text[:text]}" + end + + text_formatted << text[:text] + end + + information = text_formatted.join(" ") + end + + text_height = height_of(information, width: bounds.width - 10, size: 10) + 180 box_height = (text_height > cursor ? cursor : text_height) bounding_box([0, cursor], width: bounds.width, height: box_height - 5) do line_width 0.5 stroke_bounds information = text_box( - information, + information.gsub("

", "


"), width: bounds.width - 10, overflow: :truncate, size: 10, - at: [5, box_height - 20] + at: [5, box_height - 20], + inline_format: true ) end @@ -113,13 +134,22 @@ def text_box_truncate(title, information) def text_box_overflow_to_new_page(information, size, at, width, height) begin + if information.class.eql?(Array) + text_formatted = [] + + text_formatted << information.map { |text| text[:text] } + + information = text_formatted.join(" ") + end + information = text_box( information, size: size, at: at, width: width, height: height, - overflow: :truncate + overflow: :truncate, + inline_format: true ) if information.present? diff --git a/app/reports/discipline_content_record_report.rb b/app/reports/discipline_content_record_report.rb index 5c6f85b11..571f4f19d 100644 --- a/app/reports/discipline_content_record_report.rb +++ b/app/reports/discipline_content_record_report.rb @@ -108,7 +108,7 @@ def attributes @classroom_header = make_cell(content: 'Turma', size: 8, font_style: :bold, borders: [:left, :right, :top], background_color: 'FFFFFF', padding: [2, 2, 4, 4]) @conteudo_header = make_cell(content: Translator.t('activerecord.attributes.discipline_content_record.contents'), size: 8, font_style: :bold, borders: [:left, :right, :top], background_color: 'FFFFFF', padding: [2, 2, 4, 4]) if @display_daily_activies_log - @daily_acitivies_header = make_cell(content: 'Registro diário das atividades', size: 8, font_style: :bold, borders: [:left, :right, :top], background_color: 'FFFFFF', padding: [2, 2, 4, 4]) + @daily_acitivies_header = make_cell(content: 'Registro das atividades', size: 8, font_style: :bold, borders: [:left, :right, :top], background_color: 'FFFFFF', padding: [2, 2, 4, 4]) end @period_header = make_cell(content: 'Período', size: 8, font_style: :bold, borders: [:left, :right, :top], background_color: 'FFFFFF', padding: [2, 2, 4, 4]) diff --git a/app/reports/discipline_lesson_plan_pdf.rb b/app/reports/discipline_lesson_plan_pdf.rb index 88d57e418..5c5ff02d7 100644 --- a/app/reports/discipline_lesson_plan_pdf.rb +++ b/app/reports/discipline_lesson_plan_pdf.rb @@ -218,10 +218,22 @@ def class_plan column(-1).border_right_width = 0.25 end - text_box_truncate('Atividades/metodologia', (lesson_plan.activities || '-')) - text_box_truncate('Recursos', (lesson_plan.resources || '-')) - text_box_truncate('Avaliação', (lesson_plan.evaluation || '-')) - text_box_truncate('Referências', (lesson_plan.bibliography || '-')) + actives_methodology_translation = Translation.find_by(key: 'navigation.actives_methodology_by_discipline', group: 'lesson_plans').translation + actives_methodology_label = actives_methodology_translation.present? ? actives_methodology_translation : 'Atividades/metodologia' + + resources_translation = Translation.find_by(key: 'navigation.resources_by_discipline', group: 'lesson_plans').translation + resources_label = resources_translation.present? ? resources_translation : 'Recursos' + + evaluation_translation = Translation.find_by(key: 'navigation.avaliation_by_discipline', group: 'lesson_plans').translation + evaluation_label = evaluation_translation.present? ? evaluation_translation : 'Avaliação' + + references_translation = Translation.find_by(key: 'navigation.references_by_discipline', group: 'lesson_plans').translation + references_label = references_translation.present? ? references_translation : 'Referências' + + text_box_truncate(actives_methodology_label, (lesson_plan.activities || '-')) + text_box_truncate(resources_label, (lesson_plan.resources || '-')) + text_box_truncate(evaluation_label, (lesson_plan.evaluation || '-')) + text_box_truncate(references_label, (lesson_plan.bibliography || '-')) end def additional_information diff --git a/app/reports/discipline_teaching_plan_pdf.rb b/app/reports/discipline_teaching_plan_pdf.rb index 475e045b6..880ed7893 100644 --- a/app/reports/discipline_teaching_plan_pdf.rb +++ b/app/reports/discipline_teaching_plan_pdf.rb @@ -138,12 +138,21 @@ def class_plan thematic_unit_label = Translator.t('activerecord.attributes.discipline_teaching_plan.thematic_unit') contents_label = Translator.t('activerecord.attributes.discipline_teaching_plan.contents') objectives_label = Translator.t('activerecord.attributes.discipline_teaching_plan.objectives') + methodology_label_translation = Translation.find_by(key: 'navigation.methodology_by_discipline', group: 'teaching_plans').translation + methodology_label = methodology_label_translation.present? ? methodology_label_translation : 'Metodologia' + + evaluation_label_translation = Translation.find_by(key: 'navigation.avaliation_by_discipline', group: 'teaching_plans').translation + evaluation_label = evaluation_label_translation.present? ? evaluation_label_translation : 'Avaliação' + + references_label_translation = Translation.find_by(key: 'navigation.references_by_discipline', group: 'teaching_plans').translation + references_label = references_label_translation.present? ? references_label_translation : 'Referências' + text_box_truncate(thematic_unit_label, thematic_unit) if thematic_unit text_box_truncate(contents_label, content) text_box_truncate(objectives_label, objectives) - text_box_truncate('Metodologia', methodology) - text_box_truncate('Avaliação', evaluation) - text_box_truncate('Referências', references) + text_box_truncate(methodology_label, methodology) + text_box_truncate(evaluation_label, evaluation) + text_box_truncate(references_label, references) end def body diff --git a/app/reports/knowledge_area_content_record_report.rb b/app/reports/knowledge_area_content_record_report.rb index d9125abcb..faf0bcc45 100644 --- a/app/reports/knowledge_area_content_record_report.rb +++ b/app/reports/knowledge_area_content_record_report.rb @@ -105,7 +105,7 @@ def attributes @teacher_header = make_cell(content: 'Professor', size: 8, font_style: :bold, borders: [:left, :right, :top], background_color: 'FFFFFF', padding: [2, 2, 4, 4]) @period_header = make_cell(content: 'Período', size: 8, font_style: :bold, borders: [:left, :right, :top], background_color: 'FFFFFF', padding: [2, 2, 4, 4]) if @show_daily_activities_in_knowledge_area_content_record_report - @daily_acitivies_header = make_cell(content: 'Registro diário das atividades', size: 8, font_style: :bold, borders: [:left, :right, :top], background_color: 'FFFFFF', padding: [2, 2, 4, 4]) + @daily_acitivies_header = make_cell(content: 'Registro das atividades', size: 8, font_style: :bold, borders: [:left, :right, :top], background_color: 'FFFFFF', padding: [2, 2, 4, 4]) end @unity_cell = make_cell(content: @knowledge_area_content_records.first.content_record.unity.name, borders: [:bottom, :left, :right], size: 10, width: 240, align: :left, padding: [0, 2, 4, 4]) diff --git a/app/reports/knowledge_area_lesson_plan_pdf.rb b/app/reports/knowledge_area_lesson_plan_pdf.rb index b8b3a62d7..5b63a0b1b 100644 --- a/app/reports/knowledge_area_lesson_plan_pdf.rb +++ b/app/reports/knowledge_area_lesson_plan_pdf.rb @@ -47,7 +47,7 @@ def header position: :center, vposition: :center ) - rescue + rescue StandardError entity_logo_cell = make_cell(content: '', width: 70, rowspan: 4) end @@ -125,9 +125,9 @@ def attributes knowledge_area_ids << knowledge_area_lesson_plans_knowledge_area.knowledge_area_id end - knowledge_areas = KnowledgeArea.where id: [knowledge_area_ids] + knowledge_areas = KnowledgeArea.where(id: knowledge_area_ids) - knowledge_area_descriptions = (knowledge_areas.map { |descriptions| descriptions}.join(", ")) + knowledge_area_descriptions = knowledge_areas.map { |descriptions| descriptions }.join(', ') @teacher_header = make_cell(content: 'Professor', size: 8, font_style: :bold, borders: [:left, :right, :top], padding: [2, 2, 4, 4], colspan: 2) @teacher_cell = make_cell(content: @current_teacher.name, size: 10, borders: [:bottom, :left, :right], padding: [0, 2, 4, 4], colspan: 2) @@ -136,10 +136,10 @@ def attributes @unity_cell = make_cell(content: @knowledge_area_lesson_plan.lesson_plan.unity.name, size: 10, borders: [:bottom, :left, :right], padding: [0, 2, 4, 4], colspan: 4) @start_at_header = make_cell(content: 'Data inicial', size: 8, font_style: :bold, borders: [:top, :left, :right], padding: [2, 2, 4, 4]) - @start_at_cell = make_cell(content: @knowledge_area_lesson_plan.lesson_plan.start_at.strftime("%d/%m/%Y"), size: 10, borders: [:bottom, :left, :right], padding: [0, 2, 4, 4]) + @start_at_cell = make_cell(content: @knowledge_area_lesson_plan.lesson_plan.start_at.strftime('%d/%m/%Y'), size: 10, borders: [:bottom, :left, :right], padding: [0, 2, 4, 4]) @end_at_header = make_cell(content: 'Data final', size: 8, font_style: :bold, borders: [:top, :left, :right], padding: [2, 2, 4, 4]) - @end_at_cell = make_cell(content: @knowledge_area_lesson_plan.lesson_plan.end_at.strftime("%d/%m/%Y"), size: 10, borders: [:bottom, :left, :right], padding: [0, 2, 4, 4]) + @end_at_cell = make_cell(content: @knowledge_area_lesson_plan.lesson_plan.end_at.strftime('%d/%m/%Y'), size: 10, borders: [:bottom, :left, :right], padding: [0, 2, 4, 4]) @classroom_header = make_cell(content: 'Turma', size: 8, font_style: :bold, borders: [:top, :left, :right], padding: [2, 2, 4, 4], colspan: 2) @classroom_cell = make_cell(content: @knowledge_area_lesson_plan.lesson_plan.classroom.description, size: 10, borders: [:bottom, :left, :right], padding: [0, 2, 4, 4], colspan: 2) @@ -195,6 +195,12 @@ def attributes @opinion_cell = make_cell(content: opinion_cell_content, size: 10, borders: [:bottom, :left, :right, :top], padding: [0, 2, 4, 4], colspan: 4) end + def removed_objectives? + return false if GeneralConfiguration.current.remove_lesson_plan_objectives + + true + end + def identification identification_table_data = [ [@identification_header_cell], @@ -218,11 +224,18 @@ def identification end def class_plan - class_plan_table_data = [ - [@class_plan_header_cell], - [@content_cell], - [@objectives_cell] - ] + class_plan_table_data = if removed_objectives? + [ + [@class_plan_header_cell], + [@content_cell], + [@objectives_cell] + ] + else + [ + [@class_plan_header_cell], + [@content_cell] + ] + end if @knowledge_area_lesson_plan.experience_fields.present? class_plan_table_data.insert(1, [@experience_fields_cell]) @@ -236,10 +249,22 @@ def class_plan column(-1).border_right_width = 0.25 end - text_box_truncate('Atividades/metodologia', (@knowledge_area_lesson_plan.lesson_plan.activities || '-')) - text_box_truncate('Recursos', (@knowledge_area_lesson_plan.lesson_plan.resources || '-')) - text_box_truncate('Avaliação', (@knowledge_area_lesson_plan.lesson_plan.evaluation || '-')) - text_box_truncate('Referências', (@knowledge_area_lesson_plan.lesson_plan.bibliography || '-')) + actives_methodology_translation = Translation.find_by(key: 'navigation.actives_methodology_by_knowledge_area', group: 'lesson_plans').translation + actives_methodology_label = actives_methodology_translation.present? ? actives_methodology_translation : 'Atividades/metodologia' + + resources_translation = Translation.find_by(key: 'navigation.resources_by_knowledge_area', group: 'lesson_plans').translation + resources_label = resources_translation.present? ? resources_translation : 'Recursos' + + evaluation_translation = Translation.find_by(key: 'navigation.avaliation_by_knowledge_area', group: 'lesson_plans').translation + evaluation_label = evaluation_translation.present? ? evaluation_translation : 'Avaliação' + + references_translation = Translation.find_by(key: 'navigation.references_by_knowledge_area', group: 'lesson_plans').translation + references_label = references_translation.present? ? references_translation : 'Referências' + + text_box_truncate(actives_methodology_label, (@knowledge_area_lesson_plan.lesson_plan.activities || '-')) + text_box_truncate(resources_label, (@knowledge_area_lesson_plan.lesson_plan.resources || '-')) + text_box_truncate(evaluation_label, (@knowledge_area_lesson_plan.lesson_plan.evaluation || '-')) + text_box_truncate(references_label, (@knowledge_area_lesson_plan.lesson_plan.bibliography || '-')) end def additional_information diff --git a/app/reports/knowledge_area_teaching_plan_pdf.rb b/app/reports/knowledge_area_teaching_plan_pdf.rb index c347c4c0c..40f119527 100644 --- a/app/reports/knowledge_area_teaching_plan_pdf.rb +++ b/app/reports/knowledge_area_teaching_plan_pdf.rb @@ -179,12 +179,22 @@ def class_plan experience_fields_label = Translator.t('activerecord.attributes.knowledge_area_teaching_plan.experience_fields') contents_label = Translator.t('activerecord.attributes.knowledge_area_teaching_plan.contents') objectives_label = Translator.t('activerecord.attributes.discipline_teaching_plan.objectives') + + methodology_label_translation = Translation.find_by(key: 'navigation.methodology_by_knowledge_area', group: 'teaching_plans').translation + methodology_label = methodology_label_translation.present? ? methodology_label_translation : 'Metodologia' + + evaluation_label_translation = Translation.find_by(key: 'navigation.avaliation_by_knowledge_area', group: 'teaching_plans').translation + evaluation_label = evaluation_label_translation.present? ? evaluation_label_translation : 'Avaliação' + + references_label_translation = Translation.find_by(key: 'navigation.references_by_knowledge_area', group: 'teaching_plans').translation + references_label = references_label_translation.present? ? references_label_translation : 'Referências' + text_box_truncate(experience_fields_label, experience_fields) if experience_fields text_box_truncate(contents_label, content) text_box_truncate(objectives_label, objectives) - text_box_truncate('Metodologia', methodology) - text_box_truncate('Avaliação', evaluation) - text_box_truncate('Referências', references) + text_box_truncate(methodology_label, methodology) + text_box_truncate(evaluation_label, evaluation) + text_box_truncate(references_label, references) end def teaching_plan diff --git a/app/services/absence_count_service.rb b/app/services/absence_count_service.rb index 7364ac807..1f3c95c7f 100644 --- a/app/services/absence_count_service.rb +++ b/app/services/absence_count_service.rb @@ -1,17 +1,15 @@ class AbsenceCountService - def initialize(student, classroom, start_date, end_date, discipline = nil) - @student = student - @classroom = classroom - @start_date = start_date - @end_date = end_date - @discipline = discipline + def initialize(do_not_send_justified_absence) + @do_not_send_justified_absence = do_not_send_justified_absence end - def count - return student_frequencies_in_date_range.absences.count unless @classroom.period == Periods::FULL + def count(student, classroom, start_date, end_date, discipline = nil) + unless classroom.period == Periods::FULL + return student_frequencies_in_date_range(student, classroom, start_date, end_date, discipline).absences.count + end - grouped_frequencies_by_date.sum { |_key, value| - if @discipline + grouped_frequencies_by_date(student, classroom, start_date, end_date, discipline).sum { |_key, value| + if discipline value[:absence_count] elsif value[:presence_count].zero? && value[:absence_count] >= 1 1 @@ -23,34 +21,40 @@ def count private - def student_frequencies_in_date_range - if @discipline - DailyFrequencyStudent.general_by_classroom_discipline_student_date_between( - @classroom.id, - @discipline.id, - @student.id, - @start_date, - @end_date + def student_frequencies_in_date_range(student, classroom, start_date, end_date, discipline) + if discipline + daily_frequency_student = DailyFrequencyStudent.general_by_classroom_discipline_student_date_between( + classroom.id, + discipline.id, + student.id, + start_date, + end_date ).active else - DailyFrequencyStudent.general_by_classroom_student_date_between( - @classroom, - @student.id, - @start_date, - @end_date + daily_frequency_student = DailyFrequencyStudent.general_by_classroom_student_date_between( + classroom, + student.id, + start_date, + end_date ) end + + if @do_not_send_justified_absence + daily_frequency_student = daily_frequency_student.by_not_justified + end + + daily_frequency_student end - def grouped_frequencies_by_date - frequecies_by_date = student_frequencies_in_date_range.group_by { |daily_frequency_student| + def grouped_frequencies_by_date(student, classroom, start_date, end_date, discipline) + frequecies_by_date = student_frequencies_in_date_range(student, classroom, start_date, end_date, discipline).group_by { |daily_frequency_student| daily_frequency_student.daily_frequency.frequency_date } daily_frequencies = create_hash frequecies_by_date.each do |frequency_date, daily_frequency_students| - frequencies = count_frequencies(daily_frequency_students) + frequencies = count_frequencies(daily_frequency_students, discipline) daily_frequencies[frequency_date] = { presence_count: frequencies[:presences], absence_count: frequencies[:absences] @@ -60,11 +64,11 @@ def grouped_frequencies_by_date daily_frequencies end - def count_frequencies(daily_frequency_students) + def count_frequencies(daily_frequency_students, discipline) frequencies = create_hash presences = absences = 0 - daily_frequency_students = unify_same_component_frequencies(daily_frequency_students) if @discipline + daily_frequency_students = unify_same_component_frequencies(daily_frequency_students) if discipline daily_frequency_students.each do |frequency| presences += 1 if frequency.present diff --git a/app/services/absence_justified_on_date.rb b/app/services/absence_justified_on_date.rb new file mode 100644 index 000000000..778301b0d --- /dev/null +++ b/app/services/absence_justified_on_date.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +class AbsenceJustifiedOnDate + def self.call(params) + new(params).call + end + + def initialize(params) + @students = params.fetch(:students) + @date = params.fetch(:date) + @end_date = params.fetch(:end_date) + @classroom = params.fetch(:classroom) + @period = params.fetch(:period) + end + + def call + periods = [@period, Periods::FULL.to_i, nil].uniq + + absence_justifications = AbsenceJustification.includes(:absence_justifications_students) + .by_date_range(@date, @end_date) + .by_student_id(@students) + .by_classroom(@classroom) + .by_period(periods) + + absence_justified = {} + + absence_justifications.each do |absence_justification| + class_number = absence_justification.class_number || 0 + dates = absence_justification.absence_date..absence_justification.absence_date_end + + dates.each do |date| + absence_justification.absence_justifications_students.each do |absence_justifications_student| + absence_justified[absence_justifications_student.student_id] ||= {} + absence_justified[absence_justifications_student.student_id][date] ||= {} + absence_justified[absence_justifications_student.student_id][date][class_number] = absence_justifications_student.id + end + end + end + + absence_justified + end +end diff --git a/app/services/active_students_on_date.rb b/app/services/active_students_on_date.rb new file mode 100644 index 000000000..f67d162aa --- /dev/null +++ b/app/services/active_students_on_date.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +class ActiveStudentsOnDate + def self.call(params) + new(params).call + end + + def initialize(params) + @student_enrollments = params.fetch(:student_enrollments) + @date = params.fetch(:date) + end + + def call + return if @date.blank? || @student_enrollments.blank? + + enrollment_classrooms = StudentEnrollmentClassroom.by_student_enrollment(@student_enrollments) + .by_date(@date) + + student_active_on_date(enrollment_classrooms) + rescue NoMethodError => errors + raise errors + end + + private + + def student_active_on_date(enrollment_classrooms) + return {} unless enrollment_classrooms + + active_on_date = {} + + enrollment_classrooms.each do |enrollment_classroom| + active_on_date[enrollment_classroom.id] ||= [] + active_on_date[enrollment_classroom.id] << @date + end + + active_on_date + end +end diff --git a/app/services/api/teacher_classroom_activity.rb b/app/services/api/teacher_classroom_activity.rb index 898986776..ad732cb90 100644 --- a/app/services/api/teacher_classroom_activity.rb +++ b/app/services/api/teacher_classroom_activity.rb @@ -18,7 +18,7 @@ def any_activity? return true if DailyFrequency .by_classroom_id(@classroom_id) - .by_teacher_id(@teacher_id) + .by_teacher_classroom_id(@teacher_id, @classroom_id) .joins(join_audits('daily_frequencies.id', 'DailyFrequency')) .where('audits.user_id' => @user_id) .exists? diff --git a/app/services/aws_s3_handler_service.rb b/app/services/aws_s3_handler_service.rb index 137890ff5..d209a6624 100644 --- a/app/services/aws_s3_handler_service.rb +++ b/app/services/aws_s3_handler_service.rb @@ -1,9 +1,7 @@ class AwsS3HandlerService def initialize - aws_access_key_id = Rails.application.secrets[:DOC_UPLOADER_AWS_ACCESS_KEY_ID] || - Rails.application.secrets[:AWS_ACCESS_KEY_ID] - aws_secret_access_key = Rails.application.secrets[:DOC_UPLOADER_AWS_SECRET_ACCESS_KEY] || - Rails.application.secrets[:AWS_SECRET_ACCESS_KEY] + aws_access_key_id = Rails.application.secrets[:AWS_ACCESS_KEY_ID] + aws_secret_access_key = Rails.application.secrets[:AWS_SECRET_ACCESS_KEY] aws_region = Rails.application.secrets[:DOC_UPLOADER_AWS_REGION] || Rails.application.secrets[:AWS_REGION] aws_credentials = Aws::Credentials.new(aws_access_key_id, aws_secret_access_key) diff --git a/app/services/conceptual_exam_value_creator.rb b/app/services/conceptual_exam_value_creator.rb index 121151366..646aa6aad 100644 --- a/app/services/conceptual_exam_value_creator.rb +++ b/app/services/conceptual_exam_value_creator.rb @@ -1,13 +1,15 @@ class ConceptualExamValueCreator - def self.create_empty_by(classroom_id, teacher_id) - new(classroom_id, teacher_id).create_empty + def self.create_empty_by(classroom_id, teacher_id, grade_id, discipline_id) + new(classroom_id, teacher_id, grade_id, discipline_id).create_empty end - def initialize(classroom_id, teacher_id) - raise ArgumentError if classroom_id.blank? || teacher_id.blank? + def initialize(classroom_id, teacher_id, grade_id, discipline_id) + raise ArgumentError if classroom_id.blank? || teacher_id.blank? || grade_id.blank? || discipline_id.blank? @classroom_id = classroom_id @teacher_id = teacher_id + @discipline_id = discipline_id + @grade_id = grade_id end def create_empty @@ -23,7 +25,7 @@ def create_empty exempted_discipline: false ).find_or_create_by!( conceptual_exam_id: record.conceptual_exam_id, - discipline_id: record.discipline_id, + discipline_id: record.discipline_id ) rescue ActiveRecord::RecordNotUnique retry @@ -33,13 +35,15 @@ def create_empty private - attr_accessor :teacher_id, :classroom_id + attr_accessor :teacher_id, :classroom_id, :grade_id, :discipline_id def conceptual_exam_values_to_create TeacherDisciplineClassroom.joins(classroom: :conceptual_exams) .joins(join_conceptual_exam_value) .by_teacher_id(teacher_id) .by_classroom(classroom_id) + .by_discipline_id(discipline_id) + .by_grade_id(grade_id) .where(conceptual_exams: { classroom_id: classroom_id }) .where(conceptual_exam_values: { id: nil }) .select( diff --git a/app/services/contents_record_fetcher.rb b/app/services/contents_record_fetcher.rb index e13a2f69d..83acdf3fc 100644 --- a/app/services/contents_record_fetcher.rb +++ b/app/services/contents_record_fetcher.rb @@ -64,6 +64,6 @@ def school_term_type_steps_ids end def yearly_school_term_type_id - SchoolTermType.find_by(description: 'Anual').id + SchoolTermType.where("description = ? OR description = ?", 'Anual', 'Anual (1 etapa)').pluck(:id) end end diff --git a/app/services/create_multiple_contents.rb b/app/services/create_multiple_contents.rb deleted file mode 100644 index b9216053a..000000000 --- a/app/services/create_multiple_contents.rb +++ /dev/null @@ -1,25 +0,0 @@ -class CreateMultipleContents - attr_accessor :lessons_to_create, :base_content - - def initialize(lessons_to_create, base_content) - @lessons_to_create = lessons_to_create - @base_content = base_content - end - - def call - create_multiple - end - - private - - def create_multiple - ActiveRecord::Base.transaction do - lessons_to_create.each do |class_number| - discipline_content = base_content.dup - discipline_content.content_record = base_content.content_record.dup - discipline_content.class_number = class_number - discipline_content.save - end - end - end -end diff --git a/app/services/create_or_update_multiple_contents.rb b/app/services/create_or_update_multiple_contents.rb new file mode 100644 index 000000000..151614fee --- /dev/null +++ b/app/services/create_or_update_multiple_contents.rb @@ -0,0 +1,44 @@ +class CreateOrUpdateMultipleContents + attr_accessor :lessons_to_create, :base_content + attr_reader :create + + def initialize(lessons_to_create, base_content, create) + @lessons_to_create = lessons_to_create + @base_content = base_content + @create = create + end + + def call + return create_multiple if create + + update_multiple + end + + private + + def create_multiple + ActiveRecord::Base.transaction do + lessons_to_create.each do |class_number| + discipline_content = base_content.dup + discipline_content.content_record = base_content.content_record.dup + discipline_content.content_record.contents = base_content.content_record.contents.map(&:dup) + discipline_content.class_number = class_number + discipline_content.save + end + end + end + + def update_multiple + ActiveRecord::Base.transaction do + lessons_to_create.each do |class_number| + discipline_content = base_content.dup + discipline_content.content_record = base_content.content_record.dup + discipline_content.content_record.contents = base_content.content_record.contents.map(&:dup) + discipline_content.class_number = class_number + discipline_content.save + end + + base_content.save + end + end +end diff --git a/app/services/current_profile.rb b/app/services/current_profile.rb index 0d05c40b8..095ef96af 100644 --- a/app/services/current_profile.rb +++ b/app/services/current_profile.rb @@ -79,7 +79,7 @@ def classrooms return Classroom.none if unity.blank? classrooms = Classroom.by_unity(unity).ordered - if user_role&.role&.teacher? && teacher.present? && user.teacher? + if user_role&.role&.teacher? && teacher.present? classrooms = classrooms.by_teacher_id(teacher).ordered end classrooms = classrooms.by_year(school_year) if school_year @@ -100,8 +100,8 @@ def teachers return Teacher.none if unity.blank? || classroom.blank? return Teacher.where(id: user.teacher_id) if user_role&.role&.teacher? - teachers_ids = TeacherDisciplineClassroom.where(classroom_id: classroom.id).uniq.pluck(:teacher_id) - teachers = Teacher.where(id: teachers_ids).uniq.order_by_name + teachers_ids = TeacherDisciplineClassroom.where(classroom_id: classroom.id).distinct.pluck(:teacher_id) + teachers = Teacher.where(id: teachers_ids).distinct.order_by_name teachers.to_a end end diff --git a/app/services/daily_frequencies_creator.rb b/app/services/daily_frequencies_creator.rb index 05f0f038c..3e6a21445 100644 --- a/app/services/daily_frequencies_creator.rb +++ b/app/services/daily_frequencies_creator.rb @@ -52,18 +52,38 @@ def find_or_create_daily_frequency(params) def find_or_create_daily_frequency_students @daily_frequencies.each do |daily_frequency| - student_ids = daily_frequency.students.map(&:student_id) + not_student_ids = daily_frequency.students.map(&:student_id) + student_enrollments = student_enrollments(not_student_ids) + student_ids = student_enrollments.map(&:student_id) + + absence_justifications = AbsenceJustifiedOnDate.call( + students: student_ids, + date: daily_frequency.frequency_date, + end_date: daily_frequency.frequency_date, + classroom: daily_frequency.classroom_id, + period: daily_frequency.period + ) - student_enrollments(student_ids).each do |student_enrollment| - find_or_create_daily_frequency_student(daily_frequency, student_enrollment) + student_enrollments.each do |student_enrollment| + find_or_create_daily_frequency_student(daily_frequency, student_enrollment, absence_justifications) end end end - def find_or_create_daily_frequency_student(daily_frequency, student_enrollment) + def find_or_create_daily_frequency_student(daily_frequency, student_enrollment, absence_justifications) daily_frequency.students.find_or_create_by(student_id: student_enrollment.student_id) do |daily_frequency_student| + absence_justification = absence_justifications[daily_frequency_student.student_id] || {} + absence_justification = absence_justification[daily_frequency.frequency_date] || {} + absence_justification_student_id = absence_justification[0] || absence_justification[daily_frequency.class_number] + + if absence_justification_student_id + daily_frequency_student.present = false + daily_frequency_student.absence_justification_student_id = absence_justification_student_id + elsif + daily_frequency_student.present = true + end + daily_frequency_student.dependence = student_has_dependence?(student_enrollment.id, first_daily_frequency.discipline_id) - daily_frequency_student.present = true daily_frequency_student.active = true end rescue ActiveRecord::RecordNotUnique diff --git a/app/services/exam_poster/absence_poster.rb b/app/services/exam_poster/absence_poster.rb index 488543b3b..b7619fcc6 100644 --- a/app/services/exam_poster/absence_poster.rb +++ b/app/services/exam_poster/absence_poster.rb @@ -54,6 +54,10 @@ def generate_requests def post_general_classrooms absences = Hash.new { |hash, key| hash[key] = Hash.new(&hash.default_proc) } + absence_count_service = AbsenceCountService.new( + GeneralConfiguration.current.do_not_send_justified_absence + ) + teacher.classrooms.uniq.each do |classroom| next unless can_post?(classroom) next if frequency_by_discipline?(classroom) @@ -70,7 +74,7 @@ def post_general_classrooms students.each do |student| next unless not_posted?({ classroom: classroom, student: student })[:absence] - value = AbsenceCountService.new(student, classroom, start_date, end_date).count + value = absence_count_service.count(student, classroom, start_date, end_date) absences[classroom.api_code][student.api_code]['valor'] = value end @@ -82,6 +86,10 @@ def post_general_classrooms def post_by_discipline_classrooms absences = Hash.new { |hash, key| hash[key] = Hash.new(&hash.default_proc) } + absence_count_service = AbsenceCountService.new( + GeneralConfiguration.current.do_not_send_justified_absence + ) + teacher.classrooms.uniq.each do |classroom| teacher_discipline_classrooms = teacher.teacher_discipline_classrooms.where(classroom_id: classroom) @@ -107,7 +115,7 @@ def post_by_discipline_classrooms students.each do |student| next unless not_posted?({ classroom: classroom, discipline: discipline, student: student })[:absence] - value = AbsenceCountService.new(student, classroom, start_date, end_date, discipline).count + value = absence_count_service.count(student, classroom, start_date, end_date, discipline) absences[classroom.api_code][student.api_code][discipline.api_code]['valor'] = value end diff --git a/app/services/exam_poster/conceptual_exam_poster.rb b/app/services/exam_poster/conceptual_exam_poster.rb index 99bd7de38..c9a485f6a 100644 --- a/app/services/exam_poster/conceptual_exam_poster.rb +++ b/app/services/exam_poster/conceptual_exam_poster.rb @@ -47,7 +47,7 @@ def post_conceptual_exams .where(conceptual_exam_id: conceptual_exam_ids) .where.not(discipline_id: exempted_discipline_ids) .where(discipline_id: discipline_ids) - .uniq + .distinct conceptual_exam_values.each do |conceptual_exam_value| conceptual_exam = conceptual_exam_value.conceptual_exam diff --git a/app/services/exam_poster/numerical_exam_poster.rb b/app/services/exam_poster/numerical_exam_poster.rb index 5af06259f..5847d430c 100644 --- a/app/services/exam_poster/numerical_exam_poster.rb +++ b/app/services/exam_poster/numerical_exam_poster.rb @@ -81,7 +81,7 @@ def post_by_classrooms next if exempted_discipline(classroom, discipline.id, student_score.id) next unless correct_score_type(student_score.uses_differentiated_exam_rule, exam_rule) - next unless numerical_or_school_term_recovery?(classroom, discipline, student_score) + next unless numerical_or_school_term_recovery?(classroom, discipline, student_score) || exist_complementary_exam?(classroom, discipline, student_score) exempted_discipline_ids = ExemptedDisciplinesInStep.discipline_ids(classroom.id, step.to_number) @@ -93,7 +93,6 @@ def post_by_classrooms scores[classroom.api_code][student_score.api_code][discipline.api_code]['nota'] = value end - school_term_recovery = fetch_school_term_recovery_score(classroom, discipline, student_score.id) next unless school_term_recovery @@ -108,6 +107,17 @@ def post_by_classrooms scores end + def exist_complementary_exam?(classroom, discipline, student_score) + start_at = get_step(classroom).start_at + end_at = get_step(classroom).end_at + + ComplementaryExamStudent.by_complementary_exam_id( + ComplementaryExam.by_classroom_id(classroom) + .by_discipline_id(discipline) + .by_date_range(start_at, end_at) + ).by_student_id(student_score) + end + def numerical_or_school_term_recovery?(classroom, discipline, student_score) numerical_exam = not_posted?({ classroom: classroom, discipline: discipline, student: student_score })[:numerical_exam] school_term_recovery = not_posted?({ classroom: classroom, discipline: discipline, student: student_score })[:school_term_recovery] @@ -177,4 +187,4 @@ def exempted_discipline(classroom, discipline_id, student_id) end end -end +end \ No newline at end of file diff --git a/app/services/exam_poster/teacher_scores_fetcher.rb b/app/services/exam_poster/teacher_scores_fetcher.rb index 0b987eb06..6abcf84dd 100644 --- a/app/services/exam_poster/teacher_scores_fetcher.rb +++ b/app/services/exam_poster/teacher_scores_fetcher.rb @@ -27,8 +27,7 @@ def fetch! validate_exam_quantity_for_fix_test(number_of_exams) validate_pending_exams(daily_notes, exams) - student_ids = fetch_student_ids(daily_notes.by_active_student_enrollment_classroom(@classroom.id)) - students = Student.find(student_ids) + students = fetch_student(daily_notes) @scores = students.each do |student| student_exams = DailyNoteStudent.by_classroom_id(@classroom) @@ -74,11 +73,17 @@ def validate_pending_exams(daily_notes, exams) end end - def fetch_student_ids(daily_notes) - student_ids = [] - daily_notes.each { |d| student_ids << d.students.map(&:student_id) } - student_ids.flatten!.uniq! if student_ids.any? - student_ids + def fetch_student(daily_notes) + student_enrollment_classrooms = daily_notes.map(&:avaliation).map do |avaliation| + date_avaliation = avaliation.test_date + + StudentEnrollmentClassroom.includes(student_enrollment: :student) + .by_classroom(@classroom.id) + .by_date(date_avaliation) + .active + end + student_enrollments = student_enrollment_classrooms.flatten.map(&:student_enrollment) + student_enrollments.flatten.map(&:student) end def current_test_setting diff --git a/app/services/frequency_type_definer.rb b/app/services/frequency_type_definer.rb index 8ddb8a23e..ba7cd22b8 100644 --- a/app/services/frequency_type_definer.rb +++ b/app/services/frequency_type_definer.rb @@ -31,11 +31,14 @@ def self.allow_frequency_by_discipline?(classroom, teacher, exam_rule = nil) private def define_frequency_type + grade_ids = @classroom.classrooms_grades.pluck(:grade_id) + allow_absence_by_discipline_record = TeacherDisciplineClassroom.find_by( teacher_id: @teacher.id, classroom_id: @classroom.id, year: current_year, allow_absence_by_discipline: 1, + grade_id: grade_ids, active: true ) diff --git a/app/services/ieducar_api/schools.rb b/app/services/ieducar_api/schools.rb index d6fb14ce3..52b311681 100644 --- a/app/services/ieducar_api/schools.rb +++ b/app/services/ieducar_api/schools.rb @@ -1,17 +1,5 @@ module IeducarApi class Schools < Base - def fetch_with_vacancy(params = {}) - params[:path] = 'module/Api/Escola' - params[:resource] = 'escolas' - - raise ApiError, 'É necessário informar pelo menos um ano' if params[:ano].blank? - raise ApiError, 'É necessário informar pelo menos um curso' if params[:curso_id].blank? - raise ApiError, 'É necessário informar pelo menos uma série' if params[:serie_id].blank? - raise ApiError, 'É necessário informar pelo menos um turno de turma' if params[:turma_turno_id].blank? - - fetch(params) - end - def fetch_all(params = {}) params[:path] = 'module/Api/Escola' params[:resource] = 'info-escolas' diff --git a/app/services/ieducar_api/students.rb b/app/services/ieducar_api/students.rb index 86872f370..014d97034 100644 --- a/app/services/ieducar_api/students.rb +++ b/app/services/ieducar_api/students.rb @@ -16,23 +16,5 @@ def fetch_by_cpf(document, student_code) aluno_id: student_code ) end - - def fetch_registereds(params = {}) - params[:resource] = 'alunos-matriculados' - - raise ApiError, 'É necessário informar a escola: unity_code' if params[:unity_api_code].blank? - raise ApiError, 'É necessário informar o ano: year' if params[:year].blank? - raise ApiError, 'É necessário informar a data: date' if params[:date].blank? - - params['escola_id'] = params.delete(:unity_api_code) - params['ano'] = params.delete(:year) - params['data'] = params.delete(:date) - params['curso_id'] = params.delete(:course_api_code) - params['serie_id'] = params.delete(:grade_api_code) - params['turma_id'] = params.delete(:classroom_api_code) - params['turno_id'] = params.delete(:period) - - fetch(params) - end end end diff --git a/app/services/ieducar_synchronizers/school_calendars_synchronizer.rb b/app/services/ieducar_synchronizers/school_calendars_synchronizer.rb index 807733862..b086f9adf 100644 --- a/app/services/ieducar_synchronizers/school_calendars_synchronizer.rb +++ b/app/services/ieducar_synchronizers/school_calendars_synchronizer.rb @@ -43,7 +43,10 @@ def update_school_calendars(school_calendars) school_calendar.step_type_description = school_calendar_record.descricao school_calendar.opened_year = school_calendar_record.ano_em_aberto - school_calendar.save! if school_calendar.changed? + if school_calendar.changed? + school_calendar.save! + update_or_create_school_term_types(school_calendar) + end @school_calendar_steps_ids = [] @changed_steps = false diff --git a/app/services/ieducar_synchronizers/students_synchronizer.rb b/app/services/ieducar_synchronizers/students_synchronizer.rb index 1966f6e04..48ec70768 100644 --- a/app/services/ieducar_synchronizers/students_synchronizer.rb +++ b/app/services/ieducar_synchronizers/students_synchronizer.rb @@ -16,6 +16,8 @@ def api_class end def update_students(students) + allow_create_users_for_students = GeneralConfiguration.current.create_users_for_students_when_synchronize + students.each do |student_record| next if student_record.nome_aluno.blank? @@ -25,19 +27,20 @@ def update_students(students) student.avatar_url = student_record.foto_aluno student.birth_date = student_record.data_nascimento student.api = true + student.uses_differentiated_exam_rule = false if student.uses_differentiated_exam_rule.nil? student.save! if student.changed? + create_users(student) if student.changed? && allow_create_users_for_students + discarded = student_record.deleted_at.present? student.discard_or_undiscard(discarded) end end - - create_users if GeneralConfiguration.current.create_users_for_students_when_synchronize end - def create_users - UserForStudentCreatorWorker.perform_in(1.second, entity_id) + def create_users(student) + UserForStudentCreatorWorker.perform_in(1.second, entity_id, student) end end diff --git a/app/services/ieducar_synchronizers/teacher_discipline_classrooms_synchronizer.rb b/app/services/ieducar_synchronizers/teacher_discipline_classrooms_synchronizer.rb index bf2a3dc1e..67d901569 100644 --- a/app/services/ieducar_synchronizers/teacher_discipline_classrooms_synchronizer.rb +++ b/app/services/ieducar_synchronizers/teacher_discipline_classrooms_synchronizer.rb @@ -22,18 +22,39 @@ def update_teacher_discipline_classrooms(teacher_discipline_classrooms) existing_discipline_api_codes = [] created_linked_teachers = [] - (teacher_discipline_classroom_record.disciplinas || []).each do |discipline_by_score_type| - discipline_api_code, score_type = discipline_by_score_type.split + classroom = classroom(teacher_discipline_classroom_record.turma_id) + teacher = teacher(teacher_discipline_classroom_record.servidor_id) + + next if classroom.blank? || classroom.discarded? + next if teacher.blank? || teacher.discarded? + + teacher_id = teacher.try(:id) + classroom_id = classroom.try(:id) + + teacher_discipline_classroom_record.disciplinas.each do |discipline_by_grade| + discipline_api_code = discipline_by_grade.id + score_type = discipline_by_grade.tipo_nota + grade_api_code = discipline_by_grade.serie_id + existing_discipline_api_codes << discipline_api_code created_linked_teachers << create_or_update_teacher_discipline_classrooms( teacher_discipline_classroom_record, + classroom_id, + teacher_id, discipline_api_code, + grade_api_code, score_type ) + + if teacher_discipline_classroom_record.deleted_at.blank? + create_empty_conceptual_exam_value(discipline_by_grade, classroom_id, teacher_id) + end end - create_or_destroy_teacher_disciplines_classrooms(created_linked_teachers) + links_fake_disciplines = teacher_discipline_classroom_record if teacher_discipline_classroom_record.disciplinas.blank? + + create_or_destroy_teacher_disciplines_classrooms(created_linked_teachers, teacher_id, classroom_id, links_fake_disciplines) discard_inexisting_teacher_discipline_classrooms( teacher_discipline_classrooms_to_discard( @@ -41,36 +62,41 @@ def update_teacher_discipline_classrooms(teacher_discipline_classrooms) existing_discipline_api_codes ) ) - - create_empty_conceptual_exam_value(teacher_discipline_classroom_record) end end end def create_or_update_teacher_discipline_classrooms( teacher_discipline_classroom_record, + classroom_id, + teacher_id, discipline_api_code, + grade_api_code, score_type ) - teacher_id = teacher(teacher_discipline_classroom_record.servidor_id).try(:id) - - return if teacher_id.blank? - - classroom_id = classroom(teacher_discipline_classroom_record.turma_id).try(:id) - - return if classroom_id.blank? - discipline_id = discipline(discipline_api_code).try(:id) return if discipline_id.blank? + grade_id = grade(grade_api_code).try(:id) + + return if grade_id.blank? + teacher_discipline_classrooms = TeacherDisciplineClassroom.unscoped.where( api_code: teacher_discipline_classroom_record.id, year: year, discipline_id: discipline_id, - discipline_api_code: discipline_api_code + teacher_id: teacher_id, + grade_id: grade_id, + classroom_id: classroom_id ) + TeacherDisciplineClassroom.unscoped.where( + api_code: teacher_discipline_classroom_record.id + ).where.not(classroom_id: classroom_id).each do |teacher_discipline_classroom| + teacher_discipline_classroom.destroy + end + teacher_discipline_classroom = if teacher_discipline_classrooms.size == 1 teacher_discipline_classrooms.first @@ -83,6 +109,7 @@ def create_or_update_teacher_discipline_classrooms( year: year, teacher_id: teacher_id, teacher_api_code: teacher_discipline_classroom_record.servidor_id, + grade_id: grade_id, discipline_id: discipline_id, discipline_api_code: discipline_api_code ) @@ -95,6 +122,7 @@ def create_or_update_teacher_discipline_classrooms( teacher_discipline_classroom.period = teacher_discipline_classroom_record.turno_id teacher_discipline_classroom.score_type = score_type teacher_discipline_classroom.active = true if teacher_discipline_classroom.active.nil? + teacher_discipline_classroom.save! if teacher_discipline_classroom.changed? if teacher_discipline_classroom.new_record? @@ -119,33 +147,44 @@ def teacher_discipline_classrooms_to_discard(teacher_discipline_classroom_record year: year ) - existing_disciplines_ids = Discipline.where(api_code: existing_discipline_api_codes) - .pluck(:id) + existing_disciplines_ids = Discipline.where(api_code: existing_discipline_api_codes).pluck(:id) return teacher_discipline_classrooms if teacher_discipline_classroom_record.deleted_at.present? teacher_discipline_classrooms.where.not(discipline_id: existing_disciplines_ids) end - def create_empty_conceptual_exam_value(teacher_discipline_classroom_record) - classroom = classroom(teacher_discipline_classroom_record.turma_id) - classroom_id = classroom.try(:id) - - teacher_id = teacher(teacher_discipline_classroom_record.servidor_id).try(:id) + def create_empty_conceptual_exam_value(discipline_by_grade, classroom_id, teacher_id) + discipline_id = discipline(discipline_by_grade.id).try(:id) + grade_id = grade(discipline_by_grade.serie_id).try(:id) - return if teacher_id.nil? - return if classroom_id.nil? - return if classroom.discarded? + return if grade_id.nil? + return if discipline_id.nil? CreateEmptyConceptualExamValueWorker.perform_in( 1.second, entity_id, classroom_id, - teacher_id + teacher_id, + grade_id, + discipline_id ) end - def create_or_destroy_teacher_disciplines_classrooms(linked_teachers) + def create_or_destroy_teacher_disciplines_classrooms( + linked_teachers, + teacher_id, + classroom_id, + links_fake_disciplines = nil + ) + if links_fake_disciplines.present? && links_fake_disciplines.deleted_at.present? + link_fake = TeacherDisciplineClassroom.find_by(teacher_id: teacher_id, classroom_id: classroom_id) + + return if link_fake.nil? + + link_fake.api_code.include?('grouper') ? link_fake.discard : return + end + teacher_discipline_classrooms_ids = linked_teachers.map(&:id) TeacherDisciplineClassroom.includes(discipline: { knowledge_area: :disciplines }) @@ -159,16 +198,28 @@ def create_or_destroy_teacher_disciplines_classrooms(linked_teachers) return if fake_discipline.nil? - TeacherDisciplineClassroom.find_or_initialize_by( + link_teacher = TeacherDisciplineClassroom.with_discarded.find_or_initialize_by( api_code: "grouper:#{fake_discipline.id}", year: year, teacher_id: teacher_discipline_classroom.teacher_id, teacher_api_code: teacher_discipline_classroom.teacher_api_code, + grade_id: teacher_discipline_classroom.grade_id, discipline_id: fake_discipline.id, discipline_api_code: "grouper:#{fake_discipline.id}", classroom_id: teacher_discipline_classroom.classroom_id, classroom_api_code: "grouper:#{fake_discipline.id}" - ).save! + ) + + link_teacher.undiscard if link_teacher.discarded? + + link_teacher.save! if link_teacher.new_record? end + + grouped_link_id = GroupedTeacherDisciplineClassrooms.where( + teacher_id: teacher_id, + classroom_id: classroom_id + ).map(&:link_id) + + TeacherDisciplineClassroom.where(id: grouped_link_id).each(&:destroy) end end diff --git a/app/services/lesson_boards_service.rb b/app/services/lesson_boards_service.rb index 1421e1a3c..d03009ddf 100644 --- a/app/services/lesson_boards_service.rb +++ b/app/services/lesson_boards_service.rb @@ -1,10 +1,12 @@ class LessonBoardsService - def teachers(classroom_id, period) + def teachers(classroom_id, period, grade_id) teachers_to_select2 = [] classroom_period = Classroom.find(classroom_id).period + allocations = TeacherDisciplineClassroom.where(classroom_id: classroom_id) .includes(:teacher, discipline: :knowledge_area) .where(disciplines: { descriptor: false }) + .where(grade_id: grade_id) .order('teachers.name') allocations.where(period: period) if classroom_period == Periods::FULL && period @@ -22,12 +24,11 @@ def teachers(classroom_id, period) teachers_to_select2.insert(0, OpenStruct.new(id: 'empty', name: '', text: '')) end - def linked_teacher(teacher_discipline_classroom_id, lesson_number, weekday, classroom) + def linked_teacher(teacher_discipline_classroom_id, lesson_number, weekday, classroom, period) teacher_discipline_classroom = TeacherDisciplineClassroom.includes(:teacher, classroom: :unity) .find(teacher_discipline_classroom_id) teacher_id = teacher_discipline_classroom.teacher.id year = teacher_discipline_classroom.classroom.year - period = teacher_discipline_classroom.classroom.period linked = LessonsBoardLessonWeekday.includes(teacher_discipline_classroom: [:teacher, classroom: :unity]) .where(weekday: weekday) diff --git a/app/services/student_enrollment_classrooms_retriever.rb b/app/services/student_enrollment_classrooms_retriever.rb new file mode 100644 index 000000000..6d114a5ce --- /dev/null +++ b/app/services/student_enrollment_classrooms_retriever.rb @@ -0,0 +1,103 @@ +class StudentEnrollmentClassroomsRetriever + SEARCH_TYPES = [ + :by_date, :by_date_range, :by_year + ].freeze + + def self.call(params) + new(params).call + end + + def initialize(params) + @search_type = params.fetch(:search_type, :by_date) + @classrooms = params.fetch(:classrooms) + @disciplines = params.fetch(:disciplines) + @date = params.fetch(:date, nil) + @start_at = params.fetch(:start_at, nil) + @end_at = params.fetch(:end_at, nil) + @year = params.fetch(:year, nil) + @grade = params.fetch(:grade, nil) + @include_date_range = params.fetch(:include_date_range, nil) + @period = params.fetch(:period, nil) + @opinion_type = params.fetch(:opinion_type, nil) + @with_recovery_note_in_step = params.fetch(:with_recovery_note_in_step, nil) + @score_type = params.fetch(:score_type, nil) + + ensure_has_valid_search_params + end + + def call + return if classrooms.blank? || disciplines.blank? + + enrollment_classrooms ||= StudentEnrollmentClassroom.by_classroom(classrooms) + .by_discipline(disciplines) + .by_score_type(score_type, classrooms) + .joins(student_enrollment: :student) + .includes(student_enrollment: :student) + .includes(student_enrollment: :dependences) + .active + + enrollment_classrooms = enrollment_classrooms.by_grade(grade) if grade + enrollment_classrooms = enrollment_classrooms.by_period(period) if period + enrollment_classrooms = enrollment_classrooms.with_recovery_note_in_step(step, discipline) if with_recovery_note_in_step + enrollment_classrooms = search_by_dates(enrollment_classrooms) if include_date_range + + enrollment_classrooms = search_by_search_type(enrollment_classrooms) + enrollment_classrooms = search_by_status_attending(enrollment_classrooms) + enrollment_classrooms = order_by_name_and_sequence(enrollment_classrooms) + + enrollment_classrooms + end + + private + + attr_accessor :classrooms, :disciplines, :year, :date, :start_at, :end_at, :search_type, + :include_date_range, :grade, :period, :opinion_type, :with_recovery_note_in_step, :score_type + + def ensure_has_valid_search_params + if search_type.eql?(:by_date) + raise ArgumentError, 'Should define date argument on search by date' unless date + elsif search_type.eql?(:by_date_range) + raise ArgumentError, 'Should define start_at or end_at argument on search by date_range' unless start_at || end_at + elsif search_type.eql?(:by_year) + raise ArgumentError, 'Should define start_at or end_at argument on search by date_range' unless year + end + end + + def search_by_dates(enrollment_classrooms) + enrollment_in_date = enrollment_classrooms.by_date_range(start_at, end_at).by_date_not_before(start_at) + + return enrollment_classrooms unless enrollment_in_date.present? + + enrollment_in_date + end + + def search_by_search_type(enrollment_classrooms) + return enrollment_classrooms if include_date_range + + if search_type.eql?(:by_date) + enrollments_on_period = enrollment_classrooms.by_date(date) + elsif search_type.eql?(:by_date_range) + enrollments_on_period = enrollment_classrooms.by_date_range(start_at, end_at) + elsif search_type.eql?(:by_year) + enrollments_on_period = enrollment_classrooms.by_year(year) + end + + enrollments_on_period + end + + def order_by_name_and_sequence(enrollment_classrooms) + return enrollment_classrooms if show_inactive_enrollments + + enrollment_classrooms.ordered + end + + def search_by_status_attending(enrollment_classrooms) + return enrollment_classrooms if show_inactive_enrollments + + enrollment_classrooms.status_attending + end + + def show_inactive_enrollments + @show_inactive_enrollments = GeneralConfiguration.first.show_inactive_enrollments + end +end diff --git a/app/services/student_enrollments_list.rb b/app/services/student_enrollments_list.rb index dcdaad722..e043ce16d 100644 --- a/app/services/student_enrollments_list.rb +++ b/app/services/student_enrollments_list.rb @@ -19,6 +19,7 @@ def initialize(params) @with_recovery_note_in_step = params.fetch(:with_recovery_note_in_step, false) @include_date_range = params.fetch(:include_date_range, false) @period = params.fetch(:period, nil) + @status_attending = params.fetch(:status_attending, false) ensure_has_valid_params if search_type == :by_year && params[:year].blank? @@ -57,6 +58,8 @@ def student_enrollment_classrooms students_enrollment_classrooms = order_by_name(students_enrollment_classrooms) + students_enrollment_classrooms = enrollment_classrooms_by_status(students_enrollment_classrooms) unless show_inactive + students_enrollment_classrooms = remove_not_displayable_classrooms(students_enrollment_classrooms) students_enrollment_classrooms.map do |student_enrollment_classroom| @@ -77,7 +80,7 @@ def student_enrollment_classrooms attr_accessor :classroom, :discipline, :year, :date, :start_at, :end_at, :search_type, :show_inactive, :show_inactive_outside_step, :score_type, :opinion_type, :with_recovery_note_in_step, - :include_date_range, :period, :grade + :include_date_range, :period, :grade, :status_attending def ensure_has_valid_params if search_type == :by_date @@ -97,6 +100,8 @@ def fetch_student_enrollments(as_relation) .includes(:student_enrollment_classrooms) .active + students_enrollments = students_enrollments.status_attending if status_attending + students_enrollments = students_enrollments.by_grade(grade) if grade if include_date_range @@ -142,6 +147,10 @@ def reject_duplicated_students(student_enrollments) unique_student_enrollments.uniq end + def enrollment_classrooms_by_status(enrollment_classrooms) + enrollment_classrooms.status_attending if show_inactive_outside_step + end + def student_active?(student_enrollment) enrollments_on_period = StudentEnrollment.where(id: student_enrollment) .by_classroom(classroom) diff --git a/app/services/student_enrollments_retriever.rb b/app/services/student_enrollments_retriever.rb new file mode 100644 index 000000000..0665f605f --- /dev/null +++ b/app/services/student_enrollments_retriever.rb @@ -0,0 +1,107 @@ +class StudentEnrollmentsRetriever + SEARCH_TYPES = [ + :by_date, :by_date_range, :by_year + ].freeze + + def self.call(params) + new(params).call + end + + def initialize(params) + @search_type = params.fetch(:search_type, :by_date) + @classrooms = params.fetch(:classrooms) + @disciplines = params.fetch(:disciplines) + @date = params.fetch(:date, nil) + @start_at = params.fetch(:start_at, nil) + @end_at = params.fetch(:end_at, nil) + @year = params.fetch(:year, nil) + @grade = params.fetch(:grade, nil) + @include_date_range = params.fetch(:include_date_range, nil) + @period = params.fetch(:period, nil) + @opinion_type = params.fetch(:opinion_type, nil) + @with_recovery_note_in_step = params.fetch(:with_recovery_note_in_step, nil) + @score_type = params.fetch(:score_type, StudentEnrollmentScoreTypeFilters::BOTH) + @classroom_grades = params.fetch(:classrooms_grade_ids, nil) + + ensure_has_valid_search_params + end + + def call + return if classrooms.blank? || disciplines.blank? + + student_enrollments ||= StudentEnrollment.by_classroom(classrooms) + .by_discipline(disciplines) + .by_score_type(score_type, classrooms) + .joins(:student) + .includes(:student) + .includes(:dependences) + .includes(:student_enrollment_classrooms) + .active + + student_enrollments = student_enrollments.by_classroom_grades(classroom_grades) if classroom_grades + student_enrollments = student_enrollments.by_grade(grade) if grade + student_enrollments = student_enrollments.by_period(period) if period + student_enrollments = student_enrollments.by_opinion_type(opinion_type, classrooms) if opinion_type + student_enrollments = student_enrollments.with_recovery_note_in_step(step, discipline) if with_recovery_note_in_step + student_enrollments = search_by_dates(student_enrollments) if include_date_range + + student_enrollments = search_by_search_type(student_enrollments) + student_enrollments = search_by_status_attending(student_enrollments) + student_enrollments = order_by_name_and_sequence(student_enrollments) + + student_enrollments + end + + private + + attr_accessor :classrooms, :disciplines, :year, :date, :start_at, :end_at, :search_type, :classroom_grades, + :include_date_range, :grade, :period, :opinion_type, :with_recovery_note_in_step, :score_type + + def ensure_has_valid_search_params + if search_type.eql?(:by_date) + raise ArgumentError, 'Should define date argument on search by date' unless date + elsif search_type.eql?(:by_date_range) + raise ArgumentError, 'Should define start_at or end_at argument on search by date_range' unless start_at || end_at + elsif search_type.eql?(:by_year) + raise ArgumentError, 'Should define start_at or end_at argument on search by date_range' unless year + end + end + + def search_by_dates(student_enrollments) + enrollment_in_date = student_enrollments.by_date_range(start_at, end_at).by_date_not_before(start_at) + + return student_enrollments unless enrollment_in_date.present? + + enrollment_in_date + end + + def search_by_search_type(student_enrollments) + return student_enrollments if include_date_range + + if search_type.eql?(:by_date) + enrollments_on_period = student_enrollments.by_date(date) + elsif search_type.eql?(:by_date_range) + enrollments_on_period = student_enrollments.by_date_range(start_at, end_at) + elsif search_type.eql?(:by_year) + enrollments_on_period = student_enrollments.by_year(year) + end + + enrollments_on_period + end + + def order_by_name_and_sequence(student_enrollments) + return student_enrollments if show_inactive_enrollments + + student_enrollments.ordered + end + + def search_by_status_attending(student_enrollments) + return student_enrollments if show_inactive_enrollments + + student_enrollments.status_attending + end + + def show_inactive_enrollments + @show_inactive_enrollments = GeneralConfiguration.first.show_inactive_enrollments + end +end diff --git a/app/services/student_recovery_average_calculator.rb b/app/services/student_recovery_average_calculator.rb index 8c47fb98b..b9db4da86 100644 --- a/app/services/student_recovery_average_calculator.rb +++ b/app/services/student_recovery_average_calculator.rb @@ -17,7 +17,7 @@ def recovery_average attr_accessor :student, :classroom, :discipline, :step def exam_rule - classroom.first_exam_rule + classroom.first_exam_rule_with_recovery end def steps_fetcher diff --git a/app/services/students_exempt_from_discipline.rb b/app/services/students_exempt_from_discipline.rb new file mode 100644 index 000000000..4d49b70ad --- /dev/null +++ b/app/services/students_exempt_from_discipline.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +class StudentsExemptFromDiscipline + def self.call(params) + new(params).call + end + + def initialize(params) + @student_enrollments = params.fetch(:student_enrollments) + @discipline = params.fetch(:discipline) + @step = params.fetch(:step) + end + + def call + return {} if @discipline.blank? || @student_enrollments.blank? + + student_enrollments_exempt = StudentEnrollmentExemptedDiscipline.by_discipline(@discipline.id) + .by_step_number(@step) + .by_student_enrollment(@student_enrollments) + .includes(student_enrollment: [:student]) + + student_has_exempt_for_step(student_enrollments_exempt) + rescue NoMethodError => errors + raise errors + end + + private + + def student_has_exempt_for_step(student_enrollments_exempt) + exempts_from_discipline = {} + + student_enrollments_exempt.each do |student_exempted| + exempts_from_discipline[student_exempted.student_enrollment_id] ||= @step + end + + exempts_from_discipline + end +end diff --git a/app/services/students_in_dependency.rb b/app/services/students_in_dependency.rb new file mode 100644 index 000000000..0ee0ce624 --- /dev/null +++ b/app/services/students_in_dependency.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +class StudentsInDependency + def self.call(params) + new(params).call + end + + def initialize(params) + @student_enrollments = params.fetch(:student_enrollments) + @disciplines = params.fetch(:disciplines) + end + + def call + return {} unless @disciplines || @student_enrollments + + student_enrollment_dependencies = StudentEnrollmentDependence.where( + student_enrollment_id: @student_enrollments, + discipline_id: @disciplines + ) + + student_has_dependency_for_discipline(student_enrollment_dependencies) + rescue NoMethodError => errors + raise errors + end + + private + + def student_has_dependency_for_discipline(student_enrollment_dependencies) + dependencies = {} + + student_enrollment_dependencies.each do |student_enrollment_dependence| + student_enrollment_id = student_enrollment_dependence.student_enrollment_id + discipline_id = student_enrollment_dependence.discipline_id + + dependencies[student_enrollment_id] ||= [] + dependencies[student_enrollment_id] << discipline_id + end + + dependencies + end +end diff --git a/app/services/students_in_recovery_fetcher.rb b/app/services/students_in_recovery_fetcher.rb index 51abe3a0e..526b80925 100644 --- a/app/services/students_in_recovery_fetcher.rb +++ b/app/services/students_in_recovery_fetcher.rb @@ -43,14 +43,14 @@ def classroom end def classroom_grades_with_recovery_rule - return @classroom_grade if @classroom_grade + return @classroom_grade if @classroom_grade.present? @classroom_grade = [] classroom_grades&.each { |classroom_grade| @classroom_grade << classroom_grade unless classroom_grade.exam_rule.recovery_type.eql?(0) } if @classroom_grade.empty? - classroom_grades.first + classroom_grades else @classroom_grade end @@ -72,17 +72,18 @@ def step @step ||= steps_fetcher.step_by_id(@step_id) end - def enrollment_students - @enrollment_students ||= begin + def student_enrollments(classroom_grade_ids) + @student_enrollments ||= begin end_at = @date.to_date > step.end_at ? step.end_at : @date.to_date - StudentEnrollmentsList.new( - classroom: classroom, - discipline: discipline, + StudentEnrollmentsRetriever.call( + classrooms: classroom, + disciplines: discipline, start_at: step.start_at, + classroom_grades: classroom_grade_ids, end_at: end_at, search_type: :by_date_range - ).student_enrollments + ).by_date_not_after(end_at) end end @@ -100,10 +101,8 @@ def fetch_students_in_parallel_recovery(differentiated = nil) end def filter_students_in_recovery - classrooms_grade_ids = classroom_grades_with_recovery_rule.map(&:id) - ids_in_recovery = StudentEnrollmentClassroom.where(classrooms_grade_id: classrooms_grade_ids).pluck(:student_enrollment_id) - in_recovery_and_enrolled = ids_in_recovery & enrollment_students.map(&:id) - student_enrollments_in_recovery = StudentEnrollment.where(id: in_recovery_and_enrolled) + classroom_grade_ids = classroom_grades_with_recovery_rule.map(&:id) + student_enrollments_in_recovery = student_enrollments(classroom_grade_ids) student_enrollments_in_recovery.map(&:student) end diff --git a/app/services/teacher_period_fetcher.rb b/app/services/teacher_period_fetcher.rb index 7f84949ad..39b1d441f 100644 --- a/app/services/teacher_period_fetcher.rb +++ b/app/services/teacher_period_fetcher.rb @@ -8,9 +8,12 @@ def initialize(teacher_id, classroom_id, discipline_id) def teacher_period return classroom_period if @teacher_id.blank? + grade_ids = ClassroomsGrade.where(classroom_id: @classroom_id).map(&:grade) + teacher_discipline_classrooms = TeacherDisciplineClassroom.where( teacher_id: @teacher_id, - classroom_id: @classroom_id + classroom_id: @classroom_id, + grade_id: grade_ids ) if @discipline_id diff --git a/app/services/unique_daily_frequency_students_creator.rb b/app/services/unique_daily_frequency_students_creator.rb index 52a7ab4e1..49d8f6da1 100644 --- a/app/services/unique_daily_frequency_students_creator.rb +++ b/app/services/unique_daily_frequency_students_creator.rb @@ -21,7 +21,7 @@ def create!(classroom_id, frequency_date, teacher_id) daily_frequency_students = {} daily_frequencies = DailyFrequency.by_classroom_id(classroom_id) .by_frequency_date(frequency_date) - .by_teacher_id(teacher_id) + .by_teacher_discipline_classroom(teacher_id, classroom_id) if daily_frequencies.present? daily_frequencies.each do |current_daily_frequency| diff --git a/app/services/unities_classrooms_disciplines_by_teacher.rb b/app/services/unities_classrooms_disciplines_by_teacher.rb index 4214ed21c..912734f30 100644 --- a/app/services/unities_classrooms_disciplines_by_teacher.rb +++ b/app/services/unities_classrooms_disciplines_by_teacher.rb @@ -11,12 +11,12 @@ def fetch! self.unities = Unity.by_teacher(teacher_id) .ordered - .uniq + .distinct if unity_id self.classrooms = Classroom.by_unity_and_teacher(unity_id, teacher_id) .ordered - .uniq + .distinct else self.classrooms = {} end @@ -24,7 +24,7 @@ def fetch! if classroom_id @disciplines = Discipline.by_teacher_and_classroom(teacher_id, classroom_id) .ordered - .uniq + .distinct else @disciplines = {} end @@ -32,7 +32,7 @@ def fetch! if discipline_id @avaliations = Avaliation.teacher_avaliations(teacher_id, classroom_id, discipline_id) .ordered - .uniq + .distinct else @avaliations = {} end diff --git a/app/services/uploads_storage.rb b/app/services/uploads_storage.rb index 4e0169f0a..438a1115a 100644 --- a/app/services/uploads_storage.rb +++ b/app/services/uploads_storage.rb @@ -1,9 +1,7 @@ class UploadsStorage def self.s3? - (Rails.application.secrets[:DOC_UPLOADER_AWS_ACCESS_KEY_ID] || - Rails.application.secrets[:AWS_ACCESS_KEY_ID]).present? && - (Rails.application.secrets[:DOC_UPLOADER_AWS_SECRET_ACCESS_KEY] || - Rails.application.secrets[:AWS_SECRET_ACCESS_KEY]).present? && + (Rails.application.secrets[:AWS_ACCESS_KEY_ID]).present? && + (Rails.application.secrets[:AWS_SECRET_ACCESS_KEY]).present? && (Rails.application.secrets[:DOC_UPLOADER_AWS_REGION] || Rails.application.secrets[:AWS_REGION]).present? && (Rails.application.secrets[:DOC_UPLOADER_AWS_BUCKET] || diff --git a/app/services/user_for_student_creator.rb b/app/services/user_for_student_creator.rb index da0bba295..3721c3577 100644 --- a/app/services/user_for_student_creator.rb +++ b/app/services/user_for_student_creator.rb @@ -1,47 +1,43 @@ class UserForStudentCreator - def self.create! - new.create! + def self.create!(student) + new.create!(student) end - def create! - create_user + def create!(student) + create_user(student) end private - def create_user + def create_user(student) role_id = Role.find_by(access_level: AccessLevel::STUDENT)&.id raise 'Permissão de aluno não encontrada.' if role_id.blank? - Student.joins('LEFT JOIN users ON users.student_id = students.id') - .where(users: { student_id: nil }) - .find_each(batch_size: 100) do |student| - email = "#{student.api_code}@#{Rails.application.secrets[:STUDENT_DOMAIN]}" - - next if User.find_by(student_id: student.id, kind: RoleKind::STUDENT) - next if User.find_by(email: email, kind: RoleKind::STUDENT) - - password = "estudante#{student.api_code}" - login = User.find_by(login: student.api_code) ? '' : student.api_code - - user = User.find_or_initialize_by( - login: login, - email: email, - kind: RoleKind::STUDENT, - student_id: student.id - ) - - next unless user.new_record? - - user.first_name = student.name - user.password = password - user.password_confirmation = password - user.status = UserStatus::ACTIVE - user.user_roles.build(role_id: role_id) - user.without_auditing do - user.save!(validate: false) - end + email = "#{student.api_code}@#{Rails.application.secrets[:STUDENT_DOMAIN]}" + + return if User.find_by(student_id: student.id, kind: RoleKind::STUDENT) + return if User.find_by(email: email, kind: RoleKind::STUDENT) + + password = "estudante#{student.api_code}" + login = User.find_by(login: student.api_code) ? '' : student.api_code + + user = User.find_or_initialize_by( + login: login, + email: email, + kind: RoleKind::STUDENT, + student_id: student.id + ) + + return unless user.new_record? + + user.first_name = student.name + user.password = password + user.password_confirmation = password + user.status = UserStatus::ACTIVE + user.user_roles.build(role_id: role_id) + user.without_auditing do + user.save!(validate: false) end end end diff --git a/app/uploaders/doc_uploader.rb b/app/uploaders/doc_uploader.rb index 983ecacf2..83f7dfeec 100644 --- a/app/uploaders/doc_uploader.rb +++ b/app/uploaders/doc_uploader.rb @@ -17,8 +17,8 @@ def aws_bucket def aws_credentials { - access_key_id: Rails.application.secrets['DOC_UPLOADER_AWS_ACCESS_KEY_ID'], - secret_access_key: Rails.application.secrets['DOC_UPLOADER_AWS_SECRET_ACCESS_KEY'], + access_key_id: Rails.application.secrets['AWS_ACCESS_KEY_ID'], + secret_access_key: Rails.application.secrets['AWS_SECRET_ACCESS_KEY'], region: Rails.application.secrets['DOC_UPLOADER_AWS_REGION'], stub_responses: Rails.env.test? } diff --git a/app/views/absence_justifications/_form.html.erb b/app/views/absence_justifications/_form.html.erb index a960d732f..ca187fad9 100644 --- a/app/views/absence_justifications/_form.html.erb +++ b/app/views/absence_justifications/_form.html.erb @@ -6,6 +6,15 @@ <%= f.error_notification %> <%= render 'base_errors', f: f %> + <% readonly = @absence_justification.legacy || !['new', 'create'].include?(action_name) %> + + <% if @absence_justification.legacy %> + +
+ Não é possível editar uma justificativa de falta anterior ao ano de 2023. +
+ <% end %> +
@@ -14,6 +23,9 @@
<%= f.association :classroom, as: :select2_classroom, user: current_user, record: f.object %>
+ + <% if @absence_justification.legacy %> +
<%= f.association :disciplines, as: :select2_discipline, @@ -22,28 +34,61 @@ classroom_id: @absence_justification.classroom_id, admin_or_employee: current_user.current_role_is_admin_or_employee?, required: true, - input_html: { value: f.object.discipline_ids.join(','), - data: { without_json_parser: true } } %> + input_html: { + value: f.object.discipline_ids.join(','), + readonly: readonly, + data: { without_json_parser: true } + } %>
+ <% end %> +
- <%= f.input :absence_date %> + <%= f.input :absence_date, input_html: { readonly: readonly } %>
- <%= f.input :absence_date_end %> + <%= f.input :absence_date_end, input_html: { readonly: readonly } %>
+ <% if @absence_justification.legacy %> +
<%= f.association :students, as: :select2, elements: @students, multiple: true, required: true, - input_html: { value: f.object.student_ids.join(','), data: { without_json_parser: true } } %> + input_html: { value: f.object.student_ids.join(','), readonly: readonly, data: { without_json_parser: true } } %>
+ <% end %>
+ + <% unless @absence_justification.legacy %>
+
+ <%= f.input :period, as: :select2, elements: Periods.to_select_specific_values(false, %w[1 2 3 4]).to_json, readonly: readonly %> +
+
+ <%= f.association :students, as: :select2, elements: @students, multiple: true, required: true, + input_html: { + value: f.object.student_ids.join(','), + readonly: readonly, + data: { without_json_parser: true } + } %> +
+ <% if @is_frequency_by_discipline %> +
+ <%= f.input :class_number, as: :select2, multiple: true, + hint: "O não preenchimento do campo 'Aula' vincula a justificativa de falta com todas as aulas do período selecionado.", + elements: number_of_classes_elements(@absence_justification.school_calendar.number_of_classes), + input_html: { value: @absence_justification.class_number, readonly: readonly, data: { without_json_parser: true } } %> +
+ <% end %> +
+ <% end %> + +
- <%= f.input :justification %> + <%= f.input :justification, input_html: { readonly: @absence_justification.legacy || action_name == 'show' } %>
@@ -85,6 +130,7 @@ <%= link_to_add_association t('.add_attachment'), f, :absence_justification_attachments, class: 'btn btn-success btn-sm', + disabled: @absence_justification.legacy || action_name == 'show', :"data-association-insertion-method" => "append", :"data-association-insertion-node" => "#absence-justification-attachments" %> @@ -94,6 +140,39 @@
+ <% if action_name == 'show' %> +
+
+ Faltas justificadas + + + + + + + + + + + <% if @absences_justified.empty? %> + + + + <% end %> + <% @absences_justified.each do |absence_justified| %> + + + + + + + <% end %> + +
AlunoDiaAulaDisciplina
Nenhuma falta foi justificada.
<%= absence_justified[:student_name] %><%= absence_justified[:frequency_date] %><%= absence_justified[:class_number] == 0 ? 'Todas' : absence_justified[:class_number] %><%= absence_justified[:discipline_name] %>
+
+
+ <% end %> + <%= hidden_field_tag :current_date, Time.now.strftime("%d/%m/%Y") %> <%= hidden_field_tag :teacher_id, current_teacher %> @@ -106,7 +185,9 @@ <%= link_to 'Histórico', history_absence_justification_path(@absence_justification), class: 'btn btn-info' %> <% end %> - <%= f.submit 'Salvar', class: 'btn btn-primary' %> + <% unless @absence_justification.legacy || action_name == 'show' %> + <%= f.submit 'Salvar', class: 'btn btn-primary' %> + <% end %> <% end %> diff --git a/app/views/absence_justifications/_resources.html.erb b/app/views/absence_justifications/_resources.html.erb index e75552c81..f0efebea5 100644 --- a/app/views/absence_justifications/_resources.html.erb +++ b/app/views/absence_justifications/_resources.html.erb @@ -11,20 +11,32 @@ <%= absence_justification.decorator.students_labels %> <%= l absence_justification.absence_date %> <%= l absence_justification.absence_date_end %> - - <%= absence_justification.decorator.author( - current_user, - current_user.current_role_is_admin_or_employee? - ) %> - + <%= absence_justification.class_number || 'Todas' %> + <%= absence_justification.user %> - <%= link_to 'Editar', edit_absence_justification_path(absence_justification), - class: "btn btn-success" %> - <%= link_to 'Excluir', absence_justification_path(absence_justification), - class: "btn btn-danger", - disabled: !absence_justification_destroy?(absence_justification), - method: "delete", - data: { confirm: "Tem certeza?" } %> + + <%= link_to( + t('helpers.links.show_html'), + absence_justification_path(absence_justification), + class: 'btn btn-info apply_tooltip', + data: { original_title: t('views.index.tooltips.show') }) %> + <%= link_to( + t('helpers.links.edit_html'), + edit_absence_justification_path(absence_justification), + class: 'btn btn-success apply_tooltip', + data: { original_title: t('views.index.tooltips.edit') } + ) %> + <%= link_to( + t('helpers.links.destroy_html'), + absence_justification_path(absence_justification), + class: 'btn btn-danger apply_tooltip', + disabled: !absence_justification_destroy?(absence_justification), + method: 'delete', + data: { + confirm: t('views.index.confirm'), + original_title: t('views.index.tooltips.delete') + } + ) %> <% end %> diff --git a/app/views/absence_justifications/index.html.erb b/app/views/absence_justifications/index.html.erb index 658a54e19..1c64a5974 100644 --- a/app/views/absence_justifications/index.html.erb +++ b/app/views/absence_justifications/index.html.erb @@ -12,7 +12,7 @@ <%= f.input :by_classroom, as: :select2, elements: @classrooms, label: false, placeholder: "Filtrar turma" %> <%= f.input :by_student, label: false, placeholder: "Filtrar aluno" %> - <%= f.input :by_date, as: :date, label: false, placeholder: "Filtrar data" %> + <%= f.input :by_date, as: :date, label: false, placeholder: "Filtrar data" %> <%= f.input :by_author, as: :select2, elements: AbsenceJustificationAuthors.to_select.to_json, label: false, placeholder: t('.by_author') %> <%= link_to t('.new_html'), new_absence_justification_path, class: "btn btn-primary" %> @@ -23,6 +23,7 @@ <%= AbsenceJustification.human_attribute_name :student %> <%= AbsenceJustification.human_attribute_name :absence_date %> <%= AbsenceJustification.human_attribute_name :absence_date_end %> + <%= AbsenceJustification.human_attribute_name :class_number %> <%= AbsenceJustification.human_attribute_name :author %> @@ -30,7 +31,7 @@ <%= render 'resources' %> - + diff --git a/app/views/absence_justifications/show.html.erb b/app/views/absence_justifications/show.html.erb new file mode 100644 index 000000000..9ba7ceb8f --- /dev/null +++ b/app/views/absence_justifications/show.html.erb @@ -0,0 +1,3 @@ +
+ <%= render 'form' %> +
diff --git a/app/views/avaliations/_avaliation_fields.html.erb b/app/views/avaliations/_avaliation_fields.html.erb index 9dca69b38..e99923fea 100644 --- a/app/views/avaliations/_avaliation_fields.html.erb +++ b/app/views/avaliations/_avaliation_fields.html.erb @@ -18,7 +18,4 @@ <%= f.input :test_date, as: :date, input_html: { value: f.object.localized.test_date }, label: false %> - - <%= f.input :classes, as: :select2, elements: number_of_classes_elements(@number_of_classes), multiple: true, input_html: { value: f.object.classes.join(','), data: { without_json_parser: true } }, label: false %> - diff --git a/app/views/avaliations/_form.html.erb b/app/views/avaliations/_form.html.erb index 680a4a547..a85c2d41d 100644 --- a/app/views/avaliations/_form.html.erb +++ b/app/views/avaliations/_form.html.erb @@ -7,7 +7,11 @@
- <%= f.association :test_setting, as: :select2, elements: @test_settings, hide_empty_element: true, input_html: { data: { hide_empty_element: true }, value: @test_settings.first.id } %> + <%= f.association :test_setting, as: :select2, elements: @test_settings, hide_empty_element: true, + input_html: { + data: { hide_empty_element: true }, value: @test_settings.first.id + } + %>
@@ -32,23 +36,23 @@
- <%= f.input :classes, as: :select2, elements: number_of_classes_elements(@number_of_classes), multiple: true, input_html: { value: f.object.classes.join(','), data: { without_json_parser: true } } %> + <%= f.input :description, required: true %>
<%= f.association :test_setting_test, as: :select2, elements: [] %>
- -
- <%= f.input :description, required: true %> -
- -
- <%= f.input :weight, required: true, label_html: show_avaliation_weight, input_html: show_avaliation_weight.merge({ data: { inputmask: "'digits': #{@avaliation.test_setting&.number_of_decimal_places || 0}" } }) %> + <%= f.input :weight, required: true, label_html: show_avaliation_weight, + input_html: show_avaliation_weight.merge({ + data: { inputmask: "'digits': #{@avaliation.test_setting&.number_of_decimal_places || 0}" } + }) + %>
+
+
<%= f.association :grades, as: :select2, elements: grades, multiple: true, required: true, input_html: { diff --git a/app/views/avaliations/multiple_classrooms.html.erb b/app/views/avaliations/multiple_classrooms.html.erb index c394e6b3c..6d35a8998 100644 --- a/app/views/avaliations/multiple_classrooms.html.erb +++ b/app/views/avaliations/multiple_classrooms.html.erb @@ -21,20 +21,19 @@
<%= f.input :unity_id, as: :select2_unity, user: current_user %>
-
<%= f.input :discipline_id, as: :select2, elements: disciplines_for_multiple_classrooms %>
<%= f.input :test_setting_test_id, as: :select2, elements: [], required: true %>
+
+ <%= f.input :description, required: true %> +
-
- <%= f.input :description, required: true %> -
<%= f.input :weight, required: true, input_html: { data: { inputmask: "'digits': 0" } } %> @@ -73,9 +72,8 @@
<%= Avaliation.human_attribute_name(:classroom) %> - <%= Avaliation.human_attribute_name(:grade) %> - <%= Avaliation.human_attribute_name(:test_date) %> - <%= Avaliation.human_attribute_name(:classes) %> + <%= Avaliation.human_attribute_name(:grade) %> + <%= Avaliation.human_attribute_name(:test_date) %> diff --git a/app/views/custom_rounding_tables/_form.html.erb b/app/views/custom_rounding_tables/_form.html.erb index 87ce41b9a..7e4c96eac 100644 --- a/app/views/custom_rounding_tables/_form.html.erb +++ b/app/views/custom_rounding_tables/_form.html.erb @@ -56,7 +56,7 @@ - <%= f.simple_fields_for :custom_rounding_table_values, f.object.custom_rounding_table_values.ordered_asc do |item| %> + <%= f.simple_fields_for :custom_rounding_table_values, @custom_rounding_table_values do |item| %> <%= render 'custom_rounding_table_values_fields', f: item %> <% end %> diff --git a/app/views/daily_frequencies/_absence_justification.html.erb b/app/views/daily_frequencies/_absence_justification.html.erb new file mode 100644 index 000000000..d66eedc3c --- /dev/null +++ b/app/views/daily_frequencies/_absence_justification.html.erb @@ -0,0 +1,67 @@ +<%= simple_form_for @absence_justification, url: absence_justifications_path, html: { class: "smart-form", id: 'absence_justification' } do |f| %> + <%= f.hidden_field :unity_id, value: @daily_frequencies.first.classroom.unity.id %> + <%= f.hidden_field :classroom_id, value: @daily_frequencies.first.classroom.id %> + <%= f.hidden_field :frequency_date, value: @daily_frequencies.first.frequency_date %> + <%= f.hidden_field :discipline_id, value: @daily_frequencies.first.discipline_id %> + <%= f.hidden_field :period, value: @daily_frequencies.first.period %> + <%= f.hidden_field :class_numbers_original, value: @daily_frequencies&.map(&:class_number).join(',') %> + +<% end %> diff --git a/app/views/daily_frequencies/_student_fields.html.erb b/app/views/daily_frequencies/_student_fields.html.erb index 3c31c2c2c..1767d2719 100644 --- a/app/views/daily_frequencies/_student_fields.html.erb +++ b/app/views/daily_frequencies/_student_fields.html.erb @@ -27,25 +27,36 @@ <% end %> - <% ignore_student = !active || exempted_from_discipline || in_active_search %> - <%= f.hidden_field :id, value: daily_frequency_student.id, disabled: ignore_student %> - <%= f.hidden_field :daily_frequency_id, value: daily_frequency.id, disabled: ignore_student %> - <%= f.hidden_field :student_id, value: student.id, disabled: ignore_student %> - <%= f.hidden_field :dependence, value: dependence, disabled: ignore_student %> - <%= f.hidden_field :active, value: active, disabled: ignore_student %> +
+ <% absence_justifications = absence_justification[@daily_frequency.frequency_date] || {} %> + <% absence_justification_student_id = absence_justifications[0] || absence_justifications[class_number] %> + <% ignore_student = !active || exempted_from_discipline || in_active_search.present? %> + <%= f.hidden_field :id, value: daily_frequency_student.id, disabled: ignore_student %> + <%= f.hidden_field :daily_frequency_id, value: daily_frequency.id, disabled: ignore_student %> + <%= f.hidden_field :student_id, value: student.id, disabled: ignore_student %> + <%= f.hidden_field :dependence, value: dependence, disabled: ignore_student %> + <%= f.hidden_field :active, value: active, disabled: ignore_student %> + <%= f.hidden_field :absence_justification_student_id, class: 'hidden-justified', value: absence_justification_student_id, disabled: ignore_student %> - + <% if absence_justification_student_id %> + + <% else %> + + <% end %> - <% if @general_configuration.type_of_teaching == true && index != 0 %> + <% if @general_configuration.type_of_teaching == true && index != 0 && active %> - <% end %> + <% end %> +
<% end %> <% end %> diff --git a/app/views/daily_frequencies/edit_multiple.html.erb b/app/views/daily_frequencies/edit_multiple.html.erb index 7109632bc..5c70235f6 100644 --- a/app/views/daily_frequencies/edit_multiple.html.erb +++ b/app/views/daily_frequencies/edit_multiple.html.erb @@ -20,6 +20,39 @@ <%= simple_form_for @daily_frequency, url: create_or_update_multiple_daily_frequencies_path, method: :put, html: { class: 'smart-form daily_frequency' } do |f| %> + +
+ Legenda: + +
+ + Presente +
+ +
+ + Ausente +
+ +
+ + Falta justificada +
+ + + Inserir falta justificada por período + +
+ @@ -48,13 +81,15 @@ <% if student[:sequence] %> <%= render 'student_fields', exempted_from_discipline: student[:exempted_from_discipline], student: student[:student], sequence: student[:sequence], dependence: student[:dependence], - active: student[:active], in_active_search: student[:in_active_search] + active: student[:active], in_active_search: student[:in_active_search], + absence_justification: student[:absence_justification] %> <% else %> <% sequence += 1 %> <%= render 'student_fields', exempted_from_discipline: student[:exempted_from_discipline], student: student[:student], sequence: sequence, dependence: student[:dependence], - active: student[:active], in_active_search: student[:in_active_search] + active: student[:active], in_active_search: student[:in_active_search], + absence_justification: student[:absence_justification] %> <% end %> <% end %> @@ -144,4 +179,7 @@ <% end %> + + <%= render 'absence_justification' %> + diff --git a/app/views/daily_frequencies_in_batchs/_absence_justification.html.erb b/app/views/daily_frequencies_in_batchs/_absence_justification.html.erb new file mode 100644 index 000000000..8a3a0336b --- /dev/null +++ b/app/views/daily_frequencies_in_batchs/_absence_justification.html.erb @@ -0,0 +1,65 @@ +<%= simple_form_for @absence_justification, url: absence_justifications_path, html: { class: "smart-form", id: 'absence_justification' } do |f| %> + <%= f.hidden_field :unity_id, value: @classroom.unity.id %> + <%= f.hidden_field :classroom_id, value: @classroom.id %> + <%= f.hidden_field :start_date, value: @dates.first %> + <%= f.hidden_field :end_date, value: @dates.last %> + +<% end %> diff --git a/app/views/daily_frequencies_in_batchs/_student_fields.html.erb b/app/views/daily_frequencies_in_batchs/_student_fields.html.erb index 78b954e3a..f8d5cc544 100644 --- a/app/views/daily_frequencies_in_batchs/_student_fields.html.erb +++ b/app/views/daily_frequencies_in_batchs/_student_fields.html.erb @@ -32,14 +32,14 @@ <% end %> <% end %> <% end %> -
Sequencial +
 
-