diff --git a/README.md b/README.md index 2ce799e1e..7730cc9c5 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/app/controllers/discipline_content_records_controller.rb b/app/controllers/discipline_content_records_controller.rb index e40c350f4..eefe77a9a 100644 --- a/app/controllers/discipline_content_records_controller.rb +++ b/app/controllers/discipline_content_records_controller.rb @@ -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] ||= {} @@ -38,6 +40,7 @@ def new record_date: Time.zone.now, unity_id: current_unity.id ) + @class_numbers = [] authorize @discipline_content_record end @@ -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 @@ -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] || [] @@ -120,6 +162,7 @@ def content_ids def resource_params params.require(:discipline_content_record).permit( + :class_number, :discipline_id, content_record_attributes: [ :id, diff --git a/app/controllers/general_configurations_controller.rb b/app/controllers/general_configurations_controller.rb index 67b246f73..a01cbfea5 100644 --- a/app/controllers/general_configurations_controller.rb +++ b/app/controllers/general_configurations_controller.rb @@ -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 ) diff --git a/app/models/discipline_content_record.rb b/app/models/discipline_content_record.rb index 26c04b41f..7cd5f0492 100644 --- a/app/models/discipline_content_record.rb +++ b/app/models/discipline_content_record.rb @@ -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 @@ -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) @@ -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? && diff --git a/app/services/create_multiple_contents.rb b/app/services/create_multiple_contents.rb new file mode 100644 index 000000000..b9216053a --- /dev/null +++ b/app/services/create_multiple_contents.rb @@ -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 diff --git a/app/views/discipline_content_records/_form.html.erb b/app/views/discipline_content_records/_form.html.erb index 8ec1632d1..835a522b4 100644 --- a/app/views/discipline_content_records/_form.html.erb +++ b/app/views/discipline_content_records/_form.html.erb @@ -31,6 +31,16 @@
<%= content_record.input :record_date, as: :date %>
+ + <% if @allow_class_number %> +
+ <% 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 %> +
+ <% end %>
diff --git a/app/views/discipline_content_records/_resources.html.erb b/app/views/discipline_content_records/_resources.html.erb index ae2f507f8..97dab51c6 100644 --- a/app/views/discipline_content_records/_resources.html.erb +++ b/app/views/discipline_content_records/_resources.html.erb @@ -10,6 +10,11 @@ <%= discipline_content_record.discipline %> <%= l(discipline_content_record.content_record.record_date) %> <%= discipline_content_record.content_record.decorator.author(current_teacher) %> + + <% if @allow_class_number %> + <%= discipline_content_record.class_number %> + <% end %> + <%= link_to( t('helpers.links.copy_html'), diff --git a/app/views/discipline_content_records/index.html.erb b/app/views/discipline_content_records/index.html.erb index 1e7f5aeca..d5a4ec9fb 100644 --- a/app/views/discipline_content_records/index.html.erb +++ b/app/views/discipline_content_records/index.html.erb @@ -13,6 +13,11 @@ <%= f.input :by_author, as: :select2_plans, label: false %> + + <% if @allow_class_number %> + + <% end %> + <%= link_to t('.new_html'), new_discipline_content_record_path, class: 'btn btn-primary pull-right', style: 'width: 165px;' %> @@ -24,6 +29,11 @@ <%= DisciplineContentRecord.human_attribute_name :discipline %> <%= ContentRecord.human_attribute_name :record_date %> <%= DisciplineContentRecord.human_attribute_name :author %> + + <% if @allow_class_number %> + <%= DisciplineContentRecord.human_attribute_name :class_number %> + <% end %> + @@ -31,7 +41,7 @@ <%= render 'resources' %> - + <%= render 'shared/pagination', records: @discipline_content_records %> diff --git a/app/views/discipline_content_records/show.html.erb b/app/views/discipline_content_records/show.html.erb index 4d030dfaf..bc734f733 100644 --- a/app/views/discipline_content_records/show.html.erb +++ b/app/views/discipline_content_records/show.html.erb @@ -26,6 +26,15 @@
<%= content_record.input :record_date, as: :date, readonly: true %>
+ + <% if @allow_class_number %> +
+ <%= 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 %> +
+ <% end %>
diff --git a/app/views/general_configurations/edit.html.erb b/app/views/general_configurations/edit.html.erb index 56ef87954..aa9c462bd 100644 --- a/app/views/general_configurations/edit.html.erb +++ b/app/views/general_configurations/edit.html.erb @@ -93,6 +93,11 @@ <%= f.input :type_of_teaching, as: :boolean, label: false, inline_label: true %>
+
+
+ <%= f.input :allow_class_number_on_content_records, as: :boolean, label: false, inline_label: true %> +
+
diff --git a/config/locales/models/discipline_content_record.yml b/config/locales/models/discipline_content_record.yml index 00907e10f..4a621f8c9 100644 --- a/config/locales/models/discipline_content_record.yml +++ b/config/locales/models/discipline_content_record.yml @@ -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" diff --git a/config/locales/models/general_configuration.yml b/config/locales/models/general_configuration.yml index 9d341aea5..ad84b5c76 100644 --- a/config/locales/models/general_configuration.yml +++ b/config/locales/models/general_configuration.yml @@ -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!" diff --git a/db/migrate/20221220170255_add_allow_class_number_on_content_records_to_general_configurations.rb b/db/migrate/20221220170255_add_allow_class_number_on_content_records_to_general_configurations.rb new file mode 100644 index 000000000..4ef7ace8a --- /dev/null +++ b/db/migrate/20221220170255_add_allow_class_number_on_content_records_to_general_configurations.rb @@ -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 diff --git a/db/migrate/20230503013503_add_class_number_to_discipline_content_record.rb b/db/migrate/20230503013503_add_class_number_to_discipline_content_record.rb new file mode 100644 index 000000000..b22871a0c --- /dev/null +++ b/db/migrate/20230503013503_add_class_number_to_discipline_content_record.rb @@ -0,0 +1,5 @@ +class AddClassNumberToDisciplineContentRecord < ActiveRecord::Migration + def change + add_column :discipline_content_records, :class_number, :integer, default: 0 + end +end diff --git a/script/start b/script/start index 5f89487a5..f4ad812af 100755 --- a/script/start +++ b/script/start @@ -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