Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ajusta envios de etapas anteriores e possibilita criar registros de conteúdo em lote #153

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
12917a7
Ajusta nome do host para evitar conflitos
gustavomendess May 21, 2022
9e968ba
Remove condição do script para rodar sempre os comandos e cria banco …
gustavomendess May 21, 2022
a464be9
Ajusta readme com senha nova
gustavomendess May 21, 2022
4228333
Adiciona if novamente caso ambiente já tenha sido criado
gustavomendess May 24, 2022
8f6654f
Merge pull request #103 from portabilis/fix-docker-install
gustavomendess May 27, 2022
daa4a47
Merge branch 'portabilis:main' into main
msoares94 Dec 7, 2022
de86e9a
Cria migration de novo parâmetro na tela de configurações gerais
gustavomendess Dec 20, 2022
55bb845
Permite habilitar checkbox de aulas no registro de conteúdos
gustavomendess Dec 20, 2022
2174644
Valida disciplina apenas se não for permitido setar número de aulas
gustavomendess Dec 20, 2022
7aecb7f
Adiciona número de aula ao registro de conteúdo
gustavomendess Dec 20, 2022
ea9b905
Ajusta tradução
gustavomendess Dec 20, 2022
cfd0c22
Adiciona validação de número de aulas caso utilize a configuração
gustavomendess Dec 20, 2022
a12f909
Ajusta migration
gustavomendess Dec 20, 2022
2a2a1a7
Ajusta validações
gustavomendess Dec 21, 2022
ee15cad
Ajusta views para trabalhar com os dois formatos
gustavomendess Dec 21, 2022
5b0c88b
Cria serviço que irá duplicar os conteúdos
gustavomendess Dec 21, 2022
30dc245
Adapta controller para novo funcionamento
gustavomendess Dec 21, 2022
a37f018
Ajusta tela de edição
gustavomendess Dec 21, 2022
6638e53
Ajusta validação
gustavomendess Dec 21, 2022
c86ce1c
Ajusta configuração de banco de dados
gustavomendess Dec 21, 2022
df47e5b
Merge branch '1.4' into melhorias-registro-de-conteudos
gustavomendess Dec 21, 2022
543c8d8
Merge branch '1.4' into melhorias-registro-de-conteudos
msoares94 Jan 17, 2023
f793d01
Merge pull request #1 from marcosoliveirasoares94/melhorias-registro-…
msoares94 Jan 17, 2023
8d30b3b
Ajusta validação composta para número de aula/turma/professor
gustavomendess Mar 2, 2023
40ce3ba
add :record_date in validates_uniqueness_of
msoares94 Mar 2, 2023
5d4ccf3
Merge branch '1.4' of github.com:portabilis/i-diario into 1.4
gustavomendess Mar 3, 2023
3b37b5e
Ajusta recuperação de etapas
gustavomendess Mar 4, 2023
4e9f1cf
Ajusta relatório de notas parciais e registro de avaliações
gustavomendess Mar 4, 2023
c0a75d6
Adiciona vírgula faltante
gustavomendess Mar 4, 2023
59c6a32
Ajusta envio
gustavomendess Mar 4, 2023
39ffc06
Utiliza colspan
gustavomendess Mar 4, 2023
ccb3425
Seta id para atributos
gustavomendess Mar 4, 2023
c24c13a
Ajusta styles
gustavomendess Mar 4, 2023
ee1e7aa
Ajusta edição de recuperação
gustavomendess Mar 4, 2023
4e4b29c
Ajusta envio de recuperação final
gustavomendess Mar 5, 2023
0adb84c
Ajusta estrutura
gustavomendess Mar 6, 2023
0f3912a
Cria rake para rodar migration em tenant específico
gustavomendess Mar 11, 2023
1d8f9b0
Valida se ele pode enviar antes de atribuir outras variáveis
gustavomendess Apr 2, 2023
80f01e3
Atribui chamadas para variável
gustavomendess Apr 2, 2023
0a28ee5
Valida apenas se tiver configuração ativa
gustavomendess May 3, 2023
12c60d2
Merge branch 'fix-validations' of github.com:marcosoliveirasoares94/i…
gustavomendess May 3, 2023
df9c801
Ajustes gerais na estrutura
gustavomendess May 3, 2023
99813cc
Atualiza com o PR base
gustavomendess May 3, 2023
78ddd3c
Ajusta nome do host para evitar conflitos
gustavomendess May 21, 2022
00947bc
Merge remote-tracking branch 'origin/fix-error-with-steps' into group…
gustavomendess Jan 14, 2024
5fe0cf3
Apply sugestions
gustavomendess Jan 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 49 additions & 4 deletions app/controllers/discipline_content_records_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ 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 :allow_class_number, only: [:index, :new, :edit, :show]

def index
params[:filter] ||= {}
Expand Down Expand Up @@ -38,6 +40,7 @@ def new
unity_id: current_unity.id,
classroom_id: current_user_classroom.id
)
@class_numbers = []

unless current_user.current_role_is_admin_or_employee?
classroom_id = @discipline_content_record.content_record.classroom_id
Expand All @@ -58,12 +61,35 @@ def create

authorize @discipline_content_record

if @discipline_content_record.save
respond_with @discipline_content_record, location: discipline_content_records_path
if allow_class_number
@class_numbers = resource_params[:class_number].split(',').sort
@discipline_content_record.class_number = @class_numbers.first

@class_numbers.each do |class_number|
@discipline_content_record.class_number = class_number

return render :new if @discipline_content_record.invalid?
end

multiple_content_creator = CreateMultipleContents.new(@class_numbers, @discipline_content_record)

if multiple_content_creator.call
respond_with @discipline_content_record, location: discipline_content_records_path
else
set_options_by_user

render :new
end
else
set_options_by_user
if @discipline_content_record.save
return unless validate_class_numbers

respond_with @discipline_content_record, location: discipline_content_records_path
else
set_options_by_user

render :new
render :new
end
end
end

Expand Down Expand Up @@ -133,6 +159,24 @@ def fetch_discipline_content_records_by_user
.ordered)
end

def allow_class_number
@allow_class_number ||= GeneralConfiguration.first.allow_class_number_on_content_records
end

def set_number_of_classes
@number_of_classes = current_school_calendar.number_of_classes
end

def validate_class_numbers
return true unless allow_class_number
return true if @class_numbers.present?

@error_on_class_numbers = true
flash.now[:alert] = t('errors.daily_frequencies.class_numbers_required_when_not_global_absence')

false
end

def content_ids
param_content_ids = params[:discipline_content_record][:content_record_attributes][:content_ids] || []
content_descriptions = params[:discipline_content_record][:content_record_attributes][:content_descriptions] || []
Expand All @@ -142,6 +186,7 @@ def content_ids

def resource_params
params.require(:discipline_content_record).permit(
:class_number,
:discipline_id,
content_record_attributes: [
:id,
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/general_configurations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ def permitted_attributes
:remove_lesson_plan_objectives,
:show_experience_fields,
:allows_copy_experience_fields_in_lesson_plans,
:group_children_education
:group_children_education,
:allow_class_number_on_content_records
)

parameters[:types_of_teaching] = parameters[:types_of_teaching].split(',')
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/partial_score_record_report_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def report
@partial_score_record_report_form.students,
@partial_score_record_report_form.unity,
@partial_score_record_report_form.classroom,
current_test_setting)
current_test_setting_step(@partial_score_record_report_form.step))
send_pdf(t("routes.partial_score_record"), partial_score_record_report.render)
else
@partial_score_record_report_form.school_calendar_year = current_school_calendar.year
Expand Down
12 changes: 8 additions & 4 deletions app/controllers/school_term_recovery_diary_records_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,18 @@ def new
@school_term_recovery_diary_record.recovery_diary_record.discipline_id = current_user_discipline.id
set_options_by_user
fetch_disciplines_by_classroom
current_year_last_step = StepsFetcher.new(current_user_classroom).last_step_by_year

if current_test_setting.blank? && @admin_or_teacher
if current_test_setting.blank? && @admin_or_teacher && current_year_last_step.blank?
flash[:error] = t('errors.avaliations.require_setting')

redirect_to(school_term_recovery_diary_records_path)
end

return if performed?

@number_of_decimal_places = current_test_setting.number_of_decimal_places
@number_of_decimal_places = current_test_setting.number_of_decimal_places ||
current_test_setting_step(current_year_last_step)&.number_of_decimal_places
end

def create
Expand Down Expand Up @@ -69,7 +71,8 @@ def create
def edit
@school_term_recovery_diary_record = SchoolTermRecoveryDiaryRecord.find(params[:id]).localized
step_number = @school_term_recovery_diary_record.step_number
@school_term_recovery_diary_record.step_id = steps_fetcher.step(step_number).try(:id)
step = steps_fetcher.step(step_number)
@school_term_recovery_diary_record.step_id = step.try(:id)
set_options_by_user
fetch_disciplines_by_classroom

Expand All @@ -90,7 +93,8 @@ def edit
add_missing_students(students_in_recovery)

@any_student_exempted_from_discipline = any_student_exempted_from_discipline?
@number_of_decimal_places = current_test_setting.number_of_decimal_places
@number_of_decimal_places = current_test_setting.number_of_decimal_places ||
current_test_setting_step(step)&.number_of_decimal_places
end

def update
Expand Down
22 changes: 22 additions & 0 deletions app/models/discipline_content_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,25 @@ class DisciplineContentRecord < ActiveRecord::Base
scope :order_by_classroom, lambda {
joins(content_record: :classroom).order(Classroom.arel_table[:description].desc)
}
scope :by_class_number, lambda { |class_number| where(class_number: class_number) }

validates :class_number, presence: true, if: -> { allow_class_number? }
validates :content_record, presence: true
validates :discipline, presence: true

validate :uniqueness_of_discipline_content_record
validate :ensure_is_school_day
validate :uniqueness_of_class_number, if: -> { allow_class_number? }

delegate :contents, :record_date, :classroom, to: :content_record
delegate :grades, to: :classroom

private

def allow_class_number?
GeneralConfiguration.first.allow_class_number_on_content_records
end

def valid_for_destruction?
@valid_for_destruction if defined?(@valid_for_destruction)
@valid_for_destruction = begin
Expand All @@ -89,6 +96,7 @@ def valid_for_destruction?
end

def uniqueness_of_discipline_content_record
return if allow_class_number?
return unless content_record.present? && content_record.classroom.present? && content_record.record_date.present?

discipline_content_records = DisciplineContentRecord.by_teacher_id(content_record.teacher_id)
Expand All @@ -103,6 +111,20 @@ def uniqueness_of_discipline_content_record
end
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
errors.add(:class_number, I18n.t('activerecord.errors.models.discipline_content_record.attributes.discipline_id.class_number_in_use'))
end
end


def ensure_is_school_day
return unless content_record.present? &&
content_record.school_calendar.present? &&
Expand Down
2 changes: 1 addition & 1 deletion app/reports/exam_record_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def daily_notes_table

recovery_average = SchoolTermAverageCalculator.new(classroom)
.calculate(averages[key], recovery_score)
averages[key] = ScoreRounder.new(classroom, RoundedAvaliations::SCHOOL_TERM_RECOVERY)
averages[key] = ScoreRounder.new(classroom, RoundedAvaliations::SCHOOL_TERM_RECOVERY, @school_calendar_step)
.round(recovery_average)

average = averages[key]
Expand Down
25 changes: 25 additions & 0 deletions app/services/create_multiple_contents.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
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
13 changes: 8 additions & 5 deletions app/services/exam_poster/final_recovery_poster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,22 @@ def build_params
end

final_recovery_diary_records.each do |final_recovery_diary_record|
classroom = final_recovery_diary_record.recovery_diary_record.classroom

if final_recovery_diary_record.recovery_diary_record.students.any? { |student| student.score.blank? }
@warning_messages << "Não foi possível enviar as recuperações finais da turma #{final_recovery_diary_record.recovery_diary_record.classroom} pois existem alunos sem nota."
@warning_messages << "Não foi possível enviar as recuperações finais da turma #{classroom} pois existem alunos sem nota."
end

classroom_api_code = final_recovery_diary_record.recovery_diary_record.classroom.api_code
classroom_api_code = classroom.api_code
discipline_api_code = final_recovery_diary_record.recovery_diary_record.discipline.api_code
score_rounder = ScoreRounder.new(
final_recovery_diary_record.recovery_diary_record.classroom,
RoundedAvaliations::FINAL_RECOVERY
classroom,
RoundedAvaliations::FINAL_RECOVERY,
get_step(classroom)
)

final_recovery_diary_record.recovery_diary_record.students.each do |recovery_diary_record_student|
next unless not_posted?({ classroom: recovery_diary_record_student.recovery_diary_record.classroom,
next unless not_posted?({ classroom: classroom,
discipline: recovery_diary_record_student.recovery_diary_record.discipline,
student: recovery_diary_record_student.student })[:final_recovery]

Expand Down
4 changes: 2 additions & 2 deletions app/services/exam_poster/numerical_exam_poster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ def post_by_classrooms
step = get_step(classroom)
school_term_recovery_diary_record = school_term_recovery_diary_record(classroom, discipline, step.id)

score_rounder = ScoreRounder.new(classroom, RoundedAvaliations::SCHOOL_TERM_RECOVERY)

next unless can_post?(classroom)

score_rounder = ScoreRounder.new(classroom, RoundedAvaliations::SCHOOL_TERM_RECOVERY, step)

teacher_score_fetcher = TeacherScoresFetcher.new(
teacher,
classroom,
Expand Down
5 changes: 3 additions & 2 deletions app/services/score_rounder.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
class ScoreRounder
def initialize(classroom, rounded_avaliation)
def initialize(classroom, rounded_avaliation, step = nil)
@classroom = classroom
@rounded_avaliation = rounded_avaliation
@step = step
end

def round(score)
Expand Down Expand Up @@ -74,7 +75,7 @@ def round_to_below(score)
end

def number_of_decimal_places
TestSettingFetcher.current(@classroom).number_of_decimal_places
TestSettingFetcher.current(@classroom, @step).number_of_decimal_places
end

def truncate_score(score)
Expand Down
7 changes: 7 additions & 0 deletions app/services/steps_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ def step_by_id(step_id)
school_calendar_steps.find_by(id: step_id)
end

def last_step_by_year
return if school_calendar.blank?

school_calendar_steps.last
end


def current_step
step_by_date(Date.current)
end
Expand Down
2 changes: 1 addition & 1 deletion app/services/student_average_calculator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def calculate(classroom, discipline, step)
step
).calculate(result)

ScoreRounder.new(classroom, RoundedAvaliations::NUMERICAL_EXAM).round(result)
ScoreRounder.new(classroom, RoundedAvaliations::NUMERICAL_EXAM, step).round(result)
end

private
Expand Down
10 changes: 10 additions & 0 deletions app/views/discipline_content_records/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@
<div class="col col-sm-4">
<%= content_record.input :record_date, as: :date %>
</div>

<% if @allow_class_number %>
<div class="col col-sm-4">
<% show_classes = action_name == ('new' || 'create') ? false : true %>
<%= f.input :class_number, as: :select2, multiple: true,
elements: number_of_classes_elements(@number_of_classes),
placeholder: 'Selecione uma ou mais aulas',
disabled: show_classes %>
</div>
<% end %>
</div>

<div class="row">
Expand Down
5 changes: 5 additions & 0 deletions app/views/discipline_content_records/_resources.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
<td class="discipline"><%= discipline_content_record.discipline %></td>
<td class="record_date"><%= l(discipline_content_record.content_record.record_date) %></td>
<td><%= discipline_content_record.content_record.decorator.author(current_teacher) %></td>

<% if @allow_class_number %>
<td><%= discipline_content_record.class_number %></td>
<% end %>

<td class="actions">
<%= link_to(
t('helpers.links.copy_html'),
Expand Down
16 changes: 13 additions & 3 deletions app/views/discipline_content_records/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
<td>
<%= f.input :by_author, as: :select2_plans, label: false %>
</td>

<% if @allow_class_number %>
<td></td>
<% end %>

<td>
<%= link_to t('.new_html'), new_discipline_content_record_path,
class: 'btn btn-primary pull-right', style: 'width: 165px;' %>
Expand All @@ -29,15 +34,20 @@
<th><%= ContentRecord.human_attribute_name :classroom %></th>
<th><%= DisciplineContentRecord.human_attribute_name :discipline %>
<th><%= ContentRecord.human_attribute_name :record_date %></th>
<th width="10%"><%= DisciplineContentRecord.human_attribute_name :author %></th>
<td width="160px"></td>
<th style='width: 10%' id='author'><%= DisciplineContentRecord.human_attribute_name :author %></th>

<% if @allow_class_number %>
<th width="10%"><%= DisciplineContentRecord.human_attribute_name :class_number %></th>
<% end %>

<td style='width: 160px'></td>
</tr>
</thead>

<%= render 'resources' %>

<tfoot id="paginator" class="remote">
<td id="pagination-tfoot" colspan="5">
<td id="pagination-tfoot" colspan="<%= @allow_class_number ? 6 : 5 %>">
<%= render 'shared/pagination', records: @discipline_content_records %>
</td>
</tfoot>
Expand Down
Loading
Loading