Skip to content

Commit

Permalink
Merge pull request #129 from portabilis/fix-error-with-steps
Browse files Browse the repository at this point in the history
Corrige erro de envios e lançamentos para etapas anteriores
  • Loading branch information
AnaPerola authored Feb 22, 2024
2 parents 81ec4ac + 2a25947 commit bfb457a
Show file tree
Hide file tree
Showing 27 changed files with 243 additions and 38 deletions.
10 changes: 0 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,6 @@ idiario | * Listening on tcp://0.0.0.0:3000
idiario | Use Ctrl-C to stop
```

Após finalizada a instalação, descubra em qual endereço o i-Diário está rodando, basta executar o comando:

```
docker-compose port app 3000
```

Acesse o endereço que será exibido após rodar o comando acima.

O usuário padrão é: `admin` / A senha padrão é: `123456789`

#### Personalizando a instalação via Docker

Você pode criar um arquivo `docker-compose.override.yml` para personalizar sua instalação do i-Diário, mudando as portas
Expand Down
52 changes: 52 additions & 0 deletions app/controllers/discipline_content_records_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class DisciplineContentRecordsController < ApplicationController
before_action :require_current_teacher
before_action :require_current_classroom, only: [:index, :new, :create, :edit, :update]
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 @@ -40,6 +42,12 @@ 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
@disciplines = @disciplines.by_classroom_id(classroom_id).not_descriptor
end

unless current_user.current_role_is_admin_or_employee?
classroom_id = @discipline_content_record.content_record.classroom_id
Expand All @@ -60,7 +68,11 @@ def create

authorize @discipline_content_record

return render_content_with_multiple_class_numbers if allow_class_number

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
Expand Down Expand Up @@ -124,6 +136,27 @@ def clone

private

def render_content_with_multiple_class_numbers
@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
end

def fetch_discipline_content_records_by_user
@discipline_content_records =
apply_scopes(DisciplineContentRecord
Expand All @@ -135,6 +168,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 @@ -144,6 +195,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
5 changes: 4 additions & 1 deletion app/controllers/partial_score_record_report_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ def report
@partial_score_record_report_form = PartialScoreRecordReportForm.new(resource_params)
students_ids = resource_params[:students_ids].presence || students.pluck(:id)
@partial_score_record_report_form.students_ids = [students_ids].flatten

if @partial_score_record_report_form.valid?
current_test_setting_step = current_test_setting_step(@partial_score_record_report_form.step)
partial_score_record_report = PartialScoreRecordReport.build(current_entity_configuration,
current_school_calendar.year,
@partial_score_record_report_form.step,
@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)

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
13 changes: 9 additions & 4 deletions app/controllers/school_term_recovery_diary_records_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,18 @@ def new
set_options_by_user
fetch_disciplines_by_classroom

if current_test_setting.blank? && @admin_or_teacher
current_year_last_step = StepsFetcher.new(current_user_classroom).last_step_by_year

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 +72,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 +94,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 @@ -58,21 +58,28 @@ class DisciplineContentRecord < ActiveRecord::Base
joins(:content_record).merge(ContentRecord.where.not(teacher_id: current_teacher_id))
end
}
scope :by_class_number, lambda { |class_number| where(class_number: class_number) }
scope :order_by_classroom, lambda {
joins(content_record: :classroom).order(Classroom.arel_table[:description].desc)
}

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
10 changes: 8 additions & 2 deletions app/services/exam_poster/numerical_exam_poster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,15 @@ def post_by_classrooms
classroom = tdc.classroom
discipline = tdc.discipline
step = get_step(classroom)
school_term_recovery_diary_record = school_term_recovery_diary_record(classroom, discipline, step.id)
school_term_recovery_diary_record = school_term_recovery_diary_record(
classroom, discipline, step.id
)

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

next unless can_post?(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
6 changes: 6 additions & 0 deletions app/services/steps_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ 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
Loading

0 comments on commit bfb457a

Please sign in to comment.