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 25 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.date(enrollment.thesis_defense_date).last
IgorMonardez marked this conversation as resolved.
Show resolved Hide resolved
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
6 changes: 3 additions & 3 deletions app/controllers/professors_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ProfessorsController < ApplicationController
config.columns[:civil_status].options = {
options: [["Solteiro(a)", "solteiro"], ["Casado(a)", "casado"]]
}
config.columns[:institution].form_ui = :record_select
config.nested.add_link(:affiliations)
config.columns[:sex].form_ui = :select
config.columns[:sex].options = { options: [["Masculino", "M"],
["Feminino", "F"]] }
Expand All @@ -53,9 +53,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 Down
9 changes: 6 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.level}</b>"
])

common_header_part(pdf) do
Expand Down Expand Up @@ -614,10 +614,13 @@ def thesis_table(curr_pdf, options = {})
data_table_rows_defense_committee += [[
"#{I18n.t("pdf_content.enrollment.thesis.defense_committee")} "
]]
# TODO: modificar o institution para a affiliation
IgorMonardez marked this conversation as resolved.
Show resolved Hide resolved
thesis_desense_committee.each do |professor|
affiliation = professor.affiliations.date(thesis_defense_date).last
IgorMonardez marked this conversation as resolved.
Show resolved Hide resolved
binding.pry
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
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, optional: true
belongs_to :professor, optional: true

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 :date, ->(date) { where("start_date <= ? AND (end_date > ? OR end_date IS null)", date, date) }
IgorMonardez marked this conversation as resolved.
Show resolved Hide resolved
scope :professor, ->(professor) { where(professor_id: professor.id) }
IgorMonardez marked this conversation as resolved.
Show resolved Hide resolved
scope :date_professor, ->(professor, date) { professor(professor).date(date) }
IgorMonardez marked this conversation as resolved.
Show resolved Hide resolved

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, dependent: :restrict_with_exception
has_many :institutions, through: :affiliations, dependent: :restrict_with_exception
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
12 changes: 12 additions & 0 deletions app/models/program_level.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# 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 :date, -> (date) { where("program_levels.start_date <= ? AND program_levels.end_date > ? OR program_levels.end_date is null", date, date)}
IgorMonardez marked this conversation as resolved.
Show resolved Hide resolved

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(professor.affiliations.date(thesis_defense_date), method_call: :name) %></td>
IgorMonardez marked this conversation as resolved.
Show resolved Hide resolved
</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
5 changes: 4 additions & 1 deletion config/locales/professor.pt-BR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ 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"
name: "Nome"
neighborhood: "Bairro"
professor_research_areas: "Áreas de Pesquisa"
Expand Down
5 changes: 5 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@
end
end

resources :affiliation do
concerns :active_scaffold
record_select_routes
end

resources :professors do
concerns :active_scaffold
record_select_routes
Expand Down
59 changes: 59 additions & 0 deletions db/migrate/20240524135850_create_affiliation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
class CreateAffiliation < ActiveRecord::Migration[7.0]
def up
create_table :affiliations do |t|
t.belongs_to :professor, index: true
t.belongs_to :institution, index: true
t.date :start_date
t.date :end_date

t.timestamps
end
Professor.all.each do |professor|
start_date = professor.updated_at
end_date = nil
institution_id = professor.institution_id
institutions = []
affiliation = Affiliation.create(
professor: professor,
institution_id: institution_id,
start_date: start_date
)
professor = professor.paper_trail.previous_version
while professor.present?
if professor.institution_id != institution_id
if institution_id.present? # Não armazena afiliação em branco
institutions << { institution_id:, start_date:, end_date: }
end
end_date = start_date
start_date = professor.updated_at
institution_id = professor.institution_id
affiliation = Affiliation.create(
professor: professor,
institution_id: institution_id,
start_date: start_date,
end_date: end_date
)
else
# Atualiza data de início para data da primeira mudança em que instituição foi definida com esse valor
start_date = professor.updated_at
affiliation.update(start_date: start_date)
end
professor = professor.paper_trail.previous_version
end
if institution_id.present? # Não armazena afiliação em branco
institutions << { institution_id:, start_date:, end_date: }
end
end

remove_column :professors, :institution_id
end
def down
add_column :professors, :institution_id, :integer
add_index :professors, :institution_id
Professor.all.each do |p|
affiliation = Affiliation.professor(p).where(active: true).last
IgorMonardez marked this conversation as resolved.
Show resolved Hide resolved
p.update(institution_id: affiliation.institution_id)
end
drop_table :affiliations
end
end
Loading
Loading