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

Issue #448 #497

Open
wants to merge 35 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
13be059
ISSUE#448 - Add the relation n-m with institution and professor throu…
IgorMonardez May 24, 2024
57f60ce
ISSUE#448 - Add a link to affiliation at the professor controller, an…
IgorMonardez May 24, 2024
5907456
ISSUE#448 - Little adjustments at affiliation controller and model
IgorMonardez May 24, 2024
8375ed1
ISSUE#448 - Validation tests
IgorMonardez May 24, 2024
8718755
ISSUE#448 - Validation tests
IgorMonardez May 24, 2024
e4ac55d
ISSUE #448 - Adds affiliation population logic based on old professor…
IgorMonardez May 27, 2024
877dda7
ISSUE #448 - Adds affiliation population logic based on old professor…
IgorMonardez May 27, 2024
c7e4038
ISSUE #448 - Refactoring populate code
IgorMonardez May 27, 2024
d23f4e6
ISSUE #448 - Add repopulation logic to ProgramLevel, and adjustments …
IgorMonardez May 27, 2024
89f1a96
ISSUE #448 - Add populate algorithm to ProgramLevel and Affiliation
IgorMonardez Jun 3, 2024
1cdaa04
ISSUE #448 - Fixes tests
IgorMonardez Jun 4, 2024
359f072
ISSUE #448 - Modficações nos dados do pdf
IgorMonardez Jun 4, 2024
cade02b
ISSUE #448 - Changes at validation
IgorMonardez Jun 5, 2024
ce3358f
ISSUE #448 - Changes at academic_transcript_pdf switching to data fro…
IgorMonardez Jun 5, 2024
eaba6cb
ISSUE #448 - Exclude active flag at affiliation and program_level
IgorMonardez Jun 6, 2024
08fc416
ISSUE #448 - Create program_level factory, fix the show of defense_co…
IgorMonardez Jun 6, 2024
a73877b
ISSUE #448 - Fix github action
IgorMonardez Jun 6, 2024
7a87d61
ISSUE #448 - Fix github action
IgorMonardez Jun 6, 2024
00f94fa
Merge branch 'bugfixes' into issue_448
IgorMonardez Jun 6, 2024
3607c98
ISSUE #448 - adjustments at schema
IgorMonardez Jun 6, 2024
64e933f
ISSUE #448 - adjustments at gemfile
IgorMonardez Jun 8, 2024
dfaa001
ISSUE #448 - adjustments at gemfile
IgorMonardez Jun 8, 2024
cb8daa9
Merge branch 'bugfixes' into issue_448
IgorMonardez Jul 25, 2024
8c7d5cd
issue #448 - Adjustment at gemfile.lock
IgorMonardez Jul 25, 2024
1f7eb86
Merge branch 'main' into issue_448
IgorMonardez Sep 2, 2024
fc19ed6
ISSUE #448 - Fixed date format, changed names of "affiliation" and "p…
IgorMonardez Sep 2, 2024
24a180a
ISSUE #448 - Changes at rails_helper
IgorMonardez Sep 3, 2024
fd94a6c
Issue #448 - Removing binding.pry
IgorMonardez Sep 3, 2024
3aecccb
Issue #448 - Changes in validation and migration to only create affil…
IgorMonardez Sep 3, 2024
45341a9
Issue #448 - Fixes at seeds and custom_variables tests
IgorMonardez Sep 3, 2024
b2644e4
Issue #448 - Controller and route for program_level created
IgorMonardez Sep 3, 2024
fdbbd5c
Issue #448 - Rename controller Program Level and route of program lev…
IgorMonardez Sep 4, 2024
cec3b6e
Issue #448 - Fixes at enrollments pdf and show
IgorMonardez Sep 4, 2024
bbbc249
Issue #448 - Change of the name of the "level program" on the configu…
IgorMonardez Sep 24, 2024
af1ff0f
Issue #448 - Fixing tests
IgorMonardez Sep 24, 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
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ GEM
sprockets (>= 3.0.0)
sqlite3 (1.6.8)
mini_portile2 (~> 2.8.0)
sqlite3 (1.6.8-x86_64-linux)
ssrf_filter (1.1.2)
stringio (3.1.1)
strscan (3.1.0)
Expand Down Expand Up @@ -497,6 +498,7 @@ GEM
PLATFORMS
ruby
x86-mingw32
x86_64-linux

DEPENDENCIES
active_scaffold!
Expand Down
25 changes: 25 additions & 0 deletions app/controllers/affiliation_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

class AffiliationController < ApplicationController
authorize_resource

active_scaffold :affiliation do |config|
columns = [:professor, :institution, :start_date, :end_date]

config.list.columns = columns
config.create.columns = columns
config.update.columns = columns
config.show.columns = columns

config.columns[:professor].form_ui = :record_select
config.columns[:institution].form_ui = :record_select
config.columns[:start_date].form_ui = :date_picker
config.columns[:end_date].form_ui = :date_picker
end
record_select(
per_page: 10,
search_on: [:name],
order_by: "name",
full_text_search: true
)
end
3 changes: 2 additions & 1 deletion app/controllers/concerns/shared_pdf_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def render_enrollments_academic_transcript_pdf(enrollment)
.order("course_classes.year", "course_classes.semester")

accomplished_phases = enrollment.accomplishments.order(:conclusion_date)

program_level = ProgramLevel.on_date(enrollment.thesis_defense_date)&.last&.level || ""
render_to_string(
template: "enrollments/academic_transcript_pdf",
type: "application/pdf",
Expand All @@ -50,6 +50,7 @@ def render_enrollments_academic_transcript_pdf(enrollment)
enrollment: enrollment,
class_enrollments: class_enrollments,
accomplished_phases: accomplished_phases,
program_level: program_level
}
)
end
Expand Down
1 change: 1 addition & 0 deletions app/controllers/enrollments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ def to_pdf

def academic_transcript_pdf
enrollment = Enrollment.find(params[:id])

respond_to do |format|
format.pdf do
title = I18n.t("pdf_content.enrollment.academic_transcript.title")
Expand Down
7 changes: 3 additions & 4 deletions app/controllers/professors_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class ProfessorsController < ApplicationController
config.columns[:civil_status].options = {
options: [["Solteiro(a)", "solteiro"], ["Casado(a)", "casado"]]
}
config.columns[:institution].form_ui = :record_select
config.columns[:sex].form_ui = :select
config.columns[:sex].options = { options: [["Masculino", "M"],
["Feminino", "F"]] }
Expand All @@ -53,9 +52,9 @@ class ProfessorsController < ApplicationController
:address, :zip_code, :telephone1, :telephone2, :cpf,
:identity_expedition_date, :identity_issuing_body,
:identity_issuing_place, :identity_number, :enrollment_number,
:siape, :institution, :scholarships, :academic_title_level,
:siape, :scholarships, :academic_title_level,
:academic_title_institution, :academic_title_country,
:academic_title_date, :obs, :professor_research_areas,
:academic_title_date, :obs, :professor_research_areas, :affiliations
]

config.create.columns = form_columns
Expand All @@ -64,7 +63,7 @@ class ProfessorsController < ApplicationController
config.show.columns = [
:name, :email, :cpf, :birthdate, :address, :birthdate, :civil_status,
:identity_expedition_date, :identity_issuing_body, :identity_number,
:neighborhood, :sex, :enrollment_number, :siape,
:neighborhood, :sex, :enrollment_number, :siape, :institutions,
:telephone1, :telephone2, :zip_code, :scholarships,
:advisement_authorizations, :advisements_with_points,
:academic_title_level, :academic_title_institution,
Expand Down
39 changes: 39 additions & 0 deletions app/controllers/program_levels_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# frozen_string_literal: true

class ProgramLevelsController < ApplicationController
authorize_resource
active_scaffold :program_level do |config|
config.create.columns = [:level, :start_date, :end_date]
config.update.columns = [:level, :start_date, :end_date]
config.show.columns = [:level, :start_date, :end_date]
config.list.columns = [:level, :start_date, :end_date]

config.actions.swap :search, :field_search
config.columns.add :active
config.field_search.columns = [:active]

config.actions.exclude :deleted_records
end

protected
def do_update
# BEFORE UPDATE
# cria o histórico

pl = ProgramLevel.last
unless pl.nil?
ProgramLevel.create!(
level: pl.level,
start_date: pl.start_date,
end_date: Time.now
)
end

super
# AFTER UPDATE
# atualiza a data de início

pl = ProgramLevel.last
pl.update!(start_date: pl.updated_at)
end
end
7 changes: 4 additions & 3 deletions app/helpers/enrollments_pdf_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,12 @@ def grades_report_header(pdf, options = {})

def enrollment_header(pdf, options = {})
enrollment ||= options[:enrollment]
program_level ||= options[:program_level]
pdf.bounding_box([0, pdf.cursor - 3], width: 560) do
pdf.font("FreeMono", size: 8) do
pdf.line_width 0.5

common_header_part1(pdf, enrollment, [
"#{i18n_eht(:program_level)} <b>#{CustomVariable.program_level} </b>"
"#{i18n_eht(:program_level)} <b>#{program_level}</b>"
])

common_header_part(pdf) do
Expand Down Expand Up @@ -615,9 +615,10 @@ def thesis_table(curr_pdf, options = {})
"#{I18n.t("pdf_content.enrollment.thesis.defense_committee")} "
]]
thesis_desense_committee.each do |professor|
affiliation = Affiliation.professor_date(professor, thesis_defense_date)&.last
data_table_rows_defense_committee += [[
"<b>#{professor.name} / #{rescue_blank_text(
professor.institution, method_call: :name
affiliation&.institution, method_call: :name
)}</b>"
]]
end
Expand Down
4 changes: 2 additions & 2 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Ability
CONFIGURATION_MODELS = [
User, Role, Version, Notification, EmailTemplate, Query, NotificationLog,
CustomVariable, ReportConfiguration,
YearSemester
YearSemester, ProgramLevel
]

def initialize(user)
Expand Down Expand Up @@ -228,7 +228,7 @@ def initialize_configurations(user, roles)
alias_action :execute_now, :execute_now, :notify, to: :update
if roles[Role::ROLE_COORDENACAO]
can :manage, (Ability::CONFIGURATION_MODELS - [
CustomVariable, ReportConfiguration
CustomVariable, ReportConfiguration, ProgramLevel
])
end
if roles[Role::ROLE_SECRETARIA]
Expand Down
30 changes: 30 additions & 0 deletions app/models/affiliation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# frozen_string_literal: true

class Affiliation < ApplicationRecord
has_paper_trail

belongs_to :institution
belongs_to :professor

validates :start_date, presence: true
validates :end_date, presence: false
validates_uniqueness_of :start_date, scope: [:professor_id],
allow_nil: true, allow_blank: true,
message: "A afiliação só pode ser iniciada em uma data por professor"
validate :uniqueness_end_date

scope :on_date, ->(date) { where("DATE(start_date) <= ? AND (DATE(end_date) > ? OR end_date IS null)", date, date) }
scope :of_professor, ->(professor) { where(professor_id: professor.id) }
scope :professor_date, ->(professor, date) { of_professor(professor).on_date(date) }
scope :active, -> { where(end_date: nil) }

private
def uniqueness_end_date
exists = Affiliation.where(professor_id: professor_id, end_date: end_date).where.not(id: id).exists?
if exists
errors.add(:end_date,"Apenas uma afiliação pode estar ativa por professor e só pode ter uma data de fim por professor")
end
exists
end

end
6 changes: 0 additions & 6 deletions app/models/custom_variable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class CustomVariable < ApplicationRecord
VARIABLES = {
"single_advisor_points" => :text,
"multiple_advisor_points" => :text,
"program_level" => :text,
"identity_issuing_country" => :text,
"class_schedule_text" => :text,
"redirect_email" => :text,
Expand Down Expand Up @@ -42,11 +41,6 @@ def self.multiple_advisor_points
config.blank? ? 0.5 : config.value.to_f
end

def self.program_level
config = CustomVariable.find_by_variable(:program_level)
config.blank? ? nil : config.value.to_i
end

def self.identity_issuing_country
config = CustomVariable.find_by_variable(:identity_issuing_country)
config.blank? ? "" : config.value
Expand Down
4 changes: 3 additions & 1 deletion app/models/institution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ class Institution < ApplicationRecord
has_paper_trail

has_many :majors, dependent: :restrict_with_exception
has_many :professors, dependent: :restrict_with_exception
has_many :affiliations, dependent: :destroy
has_many :professors, through: :affiliations, dependent: :destroy


validates :name, presence: true, uniqueness: true

Expand Down
4 changes: 3 additions & 1 deletion app/models/professor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ class Professor < ApplicationRecord
dependent: :restrict_with_exception
has_many :thesis_defense_committee_enrollments,
source: :enrollment, through: :thesis_defense_committee_participations
has_many :affiliations
has_many :institutions, through: :affiliations
accepts_nested_attributes_for :affiliations, allow_destroy: true, reject_if: :all_blank

belongs_to :city, optional: true
belongs_to :institution, optional: true
belongs_to :academic_title_country,
optional: true,
class_name: "Country",
Expand Down
13 changes: 13 additions & 0 deletions app/models/program_level.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

class ProgramLevel < ApplicationRecord
has_paper_trail

validates :level, presence: true, on: [:create, :update]
validates :start_date, presence: true, on: [:create, :update]
validates :end_date, presence: false

scope :active, -> { where(end_date: nil) }
scope :on_date, -> (date) { where("program_levels.start_date <= ? AND program_levels.end_date > ? OR program_levels.end_date is null", date, date)}

end
4 changes: 2 additions & 2 deletions app/views/enrollments/_show_defense_committee_table.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<thead>
<tr>
<th><%= I18n.t("activerecord.attributes.professor.name") %></th>
<th><%= I18n.t("activerecord.attributes.professor.institution") %></th>
<th><%= I18n.t("activerecord.attributes.professor.institution.one") %></th>
</tr>
</thead>
<tbody class="records">
Expand All @@ -12,7 +12,7 @@
<% tr_class = count.even? ? "even-record" : "" %>
<tr class="record <%= tr_class %>">
<td><%= professor.name %></td>
<td><%= rescue_blank_text(professor.institution, method_call: :name) %></td>
<td><%= rescue_blank_text(Affiliation.professor_date(professor, thesis_defense_date)&.last&.institution, method_call: :name) %></td>
</tr>
<% end %>
</tbody>
Expand Down
2 changes: 1 addition & 1 deletion app/views/enrollments/academic_transcript_pdf.pdf.prawn
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ new_document(
) do |pdf|
enrollment_student_header(pdf, enrollment: @enrollment)

enrollment_header(pdf, enrollment: @enrollment)
enrollment_header(pdf, enrollment: @enrollment, program_level: @program_level)

transcript_table(pdf, class_enrollments: @class_enrollments)

Expand Down
3 changes: 2 additions & 1 deletion app/views/student_enrollment/_show_dismissal.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
<% unless thesis_defense_committee_professors.empty? %>
<h4><%= t "activerecord.attributes.enrollment.thesis_defense_committee_professors" %></h4>
<%= render partial: "enrollments/show_defense_committee_table", locals: {
thesis_defense_committee_professors: thesis_defense_committee_professors
thesis_defense_committee_professors: thesis_defense_committee_professors,
thesis_defense_date: enrollment.thesis_defense_date,
} %>
<% end %>
</details>
Expand Down
2 changes: 2 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ class Application < Rails::Application
# config.autoload_paths += %W(#{config.root}/extras)
config.autoload_paths << "#{config.root}/lib"


# Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named.
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
config.active_record.yaml_column_permitted_classes = [Symbol, Date, Time]

# Activate observers that should always be running.
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
Expand Down
17 changes: 17 additions & 0 deletions config/locales/affiliation.pt-BR.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright (c) Universidade Federal Fluminense (UFF).
# This file is part of SAPOS. Please, consult the license terms in the LICENSE file.

pt-BR:
activerecord:
attributes:
affiliation:
institution: "Instituição"
professor: "Professor"
start_date: "Data de início"
end_date: "Data de fim"
active: "Ativo"

models:
affiliation:
one: "Afiliação"
other: "Afiliações"
1 change: 1 addition & 0 deletions config/locales/institution.pt-BR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pt-BR:
code: "Sigla"
majors: "Cursos"
name: "Nome"
affiliations: "Afiliações"

models:
institution:
Expand Down
2 changes: 1 addition & 1 deletion config/locales/navigation.pt-BR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ pt-BR:
student: Alunos
dismissal: Desligamentos
enrollment: Matrículas
enrollment: Matrículas
enrollment_hold: Trancamentos
level: Níveis
dismissal_reason: Razões de Desligamento
Expand Down Expand Up @@ -82,6 +81,7 @@ pt-BR:
notification_log: Notificações Enviadas
custom_variable: Variáveis
report_configuration: Configurações de Relatório
program_level: Conceito CAPES

logout:
label: 'Logout'
6 changes: 5 additions & 1 deletion config/locales/professor.pt-BR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ pt-BR:
identity_issuing_body: "Órgão Expeditor"
identity_issuing_place: "Local de Expedição"
identity_number: "Número da identidade"
institution: "Instituição"
affiliations: "Afiliações"
institution:
one: "Instituição"
other: "Instituições"
institutions: "Instituições"
name: "Nome"
neighborhood: "Bairro"
professor_research_areas: "Áreas de Pesquisa"
Expand Down
13 changes: 13 additions & 0 deletions config/locales/program_level.pt-BR.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
pt-BR:
activerecord:
attributes:
program_level:
active: Ativo?
level: Nível
start_date: Data de início
end_date: Data de fim

models:
program_level:
one: Conceito CAPES
other: Conceito CAPES
1 change: 1 addition & 0 deletions config/navigation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ def can_read?(*args)
submenu.modelitem NotificationLog
submenu.modelitem CustomVariable
submenu.modelitem ReportConfiguration
submenu.modelitem ProgramLevel
end

mainhelper.item :logout, destroy_user_session_path
Expand Down
Loading
Loading