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 validações #128

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 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
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
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
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
49 changes: 46 additions & 3 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
record_date: Time.zone.now,
unity_id: current_unity.id
)
@class_numbers = []

authorize @discipline_content_record
end
Expand All @@ -53,10 +56,31 @@ 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
render :new
end
else
render :new
if @discipline_content_record.save
return unless validate_class_numbers

respond_with @discipline_content_record, location: discipline_content_records_path
else
render :new
end
end
end

Expand Down Expand Up @@ -111,6 +135,24 @@ def clone

private

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 @@ -120,6 +162,7 @@ def content_ids

def resource_params
params.require(:discipline_content_record).permit(
:class_number,
:discipline_id,
content_record_attributes: [
:id,
Expand Down
1 change: 1 addition & 0 deletions app/controllers/general_configurations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def permitted_attributes
:days_to_disable_access,
:show_inactive_enrollments,
:show_percentage_on_attendance_record_report,
:allow_class_number_on_content_records,
:require_daily_activities_record
)

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 @@ -40,18 +40,25 @@ 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) }

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 @@ -68,6 +75,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 @@ -82,6 +90,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
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
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 @@ -31,6 +31,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
12 changes: 11 additions & 1 deletion app/views/discipline_content_records/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,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 @@ -24,14 +29,19 @@
<th><%= DisciplineContentRecord.human_attribute_name :discipline %>
<th><%= ContentRecord.human_attribute_name :record_date %></th>
<th width="10%"><%= DisciplineContentRecord.human_attribute_name :author %></th>

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

<td width="160px"></td>
</tr>
</thead>

<%= render 'resources' %>

<tfoot id="paginator" class="remote">
<td id="pagination-tfoot" colspan="5">
<td id="pagination-tfoot" colspan="6">
<%= render 'shared/pagination', records: @discipline_content_records %>
</td>
</tfoot>
Expand Down
9 changes: 9 additions & 0 deletions app/views/discipline_content_records/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@
<div class="col col-sm-4">
<%= content_record.input :record_date, as: :date, readonly: true %>
</div>

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

<div class="row">
Expand Down
5 changes: 5 additions & 0 deletions app/views/general_configurations/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@
<%= f.input :type_of_teaching, as: :boolean, label: false, inline_label: true %>
</div>
</div>
<div class="row">
<div class="col col-sm-6">
<%= f.input :allow_class_number_on_content_records, as: :boolean, label: false, inline_label: true %>
</div>
</div>
<div class="row margin-top-10" id="types_of_teaching_container">
<div class='col col-xs-12 col-sm-12 col-md-6'>
<div style="float:right;">
Expand Down
2 changes: 2 additions & 0 deletions config/locales/models/discipline_content_record.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ pt-BR:
discipline_id: "Disciplina"
author: "Autor"
contents: "Conteúdos"
class_number: "Aula"
errors:
models:
discipline_content_record:
attributes:
discipline_id:
discipline_in_use: "já existe um registro de conteúdo para a disciplina informada"
class_number_in_use: "Já existe um registro de conteúdo para a Turma/Disciplina/Data/Número de aula infomado"
1 change: 1 addition & 0 deletions config/locales/models/general_configuration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pt-BR:
days_to_disable_access: "Quantidade de dias permitidos sem acessar o sistema para inativação automática de usuário"
show_inactive_enrollments: "Apresentar enturmações inativas de alunos(as) nas telas de lançamento e relatórios (avaliação e frequência)"
show_percentage_on_attendance_record_report: "Exibir frequência em porcentagem no Registro de frequência"
allow_class_number_on_content_records: "Permitir informar número de aula no Registro de conteúdos?"
require_daily_activities_record: "Obrigar preenchimento do campo 'Registro diário das atividades' no lançamento de Registro de conteúdos?"
backup:
completed: "Exportação de dados realizada com sucesso! Clique %{link} para fazer download!"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddAllowClassNumberOnContentRecordsToGeneralConfigurations < ActiveRecord::Migration
def change
add_column :general_configurations, :allow_class_number_on_content_records, :boolean, default: false
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddClassNumberToDisciplineContentRecord < ActiveRecord::Migration
def change
add_column :discipline_content_records, :class_number, :integer, default: 0
end
end
4 changes: 2 additions & 2 deletions script/start
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ if ! test -f ".setup"; then

bundle exec rake db:create
bundle exec rake db:migrate
bundle exec rake entity:setup NAME=prefeitura DOMAIN=localhost DATABASE=prefeitura_diario
bundle exec rake entity:admin:create NAME=prefeitura ADMIN_PASSWORD=123456789
bundle exec rake entity:setup NAME=prefeitura DOMAIN=localhost DATABASE=idiario
bundle exec rake entity:admin:create NAME=prefeitura ADMIN_PASSWORD=A123456789$

cp public/404.html.sample public/404.html
cp public/500.html.sample public/500.html
Expand Down