Skip to content

Commit

Permalink
#505: add paper page for quadrenial
Browse files Browse the repository at this point in the history
  • Loading branch information
JoaoFelipe committed Dec 6, 2024
1 parent 961ab31 commit 0517434
Show file tree
Hide file tree
Showing 32 changed files with 711 additions and 21 deletions.
16 changes: 16 additions & 0 deletions app/controllers/paper_professors_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright (c) Universidade Federal Fluminense (UFF).
# This file is part of SAPOS. Please, consult the license terms in the LICENSE file.

# frozen_string_literal: true

class PaperProfessorsController < ApplicationController
authorize_resource

active_scaffold :paper_professor do |config|
config.create.label = :create_paper_professor_label
config.columns = [:paper, :professor]
config.columns[:professor].form_ui = :record_select

config.actions.exclude :deleted_records
end
end
16 changes: 16 additions & 0 deletions app/controllers/paper_students_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright (c) Universidade Federal Fluminense (UFF).
# This file is part of SAPOS. Please, consult the license terms in the LICENSE file.

# frozen_string_literal: true

class PaperStudentsController < ApplicationController
authorize_resource

active_scaffold :paper_student do |config|
config.create.label = :create_paper_student_label
config.columns = [:paper, :student]
config.columns[:student].form_ui = :record_select

config.actions.exclude :deleted_records
end
end
90 changes: 90 additions & 0 deletions app/controllers/papers_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Copyright (c) Universidade Federal Fluminense (UFF).
# This file is part of SAPOS. Please, consult the license terms in the LICENSE file.

# frozen_string_literal: true

class PapersController < ApplicationController
authorize_resource

active_scaffold :paper do |config|
config.create.label = :create_paper_label
config.actions.swap :search, :field_search
config.list.sorting = { period: "DESC", owner: "ASC", order: "ASC" }

config.columns.add :header
config.columns.add :reason_group
config.columns.add :reason_group_end
form_columns = [
:header,
:period, :owner, :reference, :order, :kind, :doi_issn_event,
:paper_professors, :paper_students, :other_authors,
:reason_group,
:reason_impact_factor,
:reason_international_list,
:reason_citations,
:reason_national_interest,
:reason_international_interest,
:reason_national_representativeness,
:reason_scientific_contribution,
:reason_tech_contribution,
:reason_innovation_contribution,
:reason_social_contribution,
:reason_other,
:reason_justify,
:impact_factor,
:reason_group_end,
:other,
]
config.create.columns = form_columns
config.update.columns = form_columns
config.show.columns = [
:period, :owner, :reference, :kind, :doi_issn_event,
:paper_professors, :paper_students, :other_authors,
:reason_impact_factor,
:reason_international_list,
:reason_citations,
:reason_national_interest,
:reason_international_interest,
:reason_national_representativeness,
:reason_scientific_contribution,
:reason_tech_contribution,
:reason_innovation_contribution,
:reason_social_contribution,
:reason_other,
:reason_justify,
:impact_factor,
:order,
:other,
]
config.list.columns = [
:period, :owner, :order, :reference
]

config.columns[:owner].form_ui = :record_select
config.columns[:kind].form_ui = :select
config.columns[:kind].options = {
options: Paper::KINDS,
include_blank: I18n.t("active_scaffold._select_")
}
config.columns[:order].form_ui = :select
config.columns[:order].options = {
options: Paper::ORDERS,
include_blank: I18n.t("active_scaffold._select_")
}


config.columns[:paper_students].show_blank_record = false
config.columns[:paper_professors].show_blank_record = false

config.actions.exclude :deleted_records
end

protected
def do_new
super
@record.period = CustomVariable.quadrennial_period
unless current_user.professor.blank?
@record.owner = current_user.professor
end
end
end
7 changes: 7 additions & 0 deletions app/helpers/paper_professors_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Copyright (c) Universidade Federal Fluminense (UFF).
# This file is part of SAPOS. Please, consult the license terms in the LICENSE file.

# frozen_string_literal: true

module PaperProfessorsHelper
end
7 changes: 7 additions & 0 deletions app/helpers/paper_students_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Copyright (c) Universidade Federal Fluminense (UFF).
# This file is part of SAPOS. Please, consult the license terms in the LICENSE file.

# frozen_string_literal: true

module PaperStudentsHelper
end
31 changes: 31 additions & 0 deletions app/helpers/papers_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright (c) Universidade Federal Fluminense (UFF).
# This file is part of SAPOS. Please, consult the license terms in the LICENSE file.

# frozen_string_literal: true

module PapersHelper
def owner_form_column(record, options)
if can?(:edit_professor, record)
record_select_field :owner, record.owner || Professor.new, options
else
options[:value] = record.owner_id
label(
:record_value_1_params, record.id, record.owner.name
) + hidden_field(:record, :owner, options)
end
end

def period_form_column(record, options)
if can?(:edit_professor, record)
text_field :record, :period, options
else
label(
:record_value_1_params, record.id, record.period
) + hidden_field(:record, :period, options)
end
end

def reason_group_form_column(record, options)
"aaaa"
end
end
13 changes: 12 additions & 1 deletion app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Ability
PROFESSOR_MODELS = [
Professor, Advisement, AdvisementAuthorization,
ThesisDefenseCommitteeParticipation,
ProfessorResearchArea, Grant
ProfessorResearchArea, Grant, Paper, PaperProfessor, PaperStudent
]

SCHOLARSHIP_MODELS = [
Expand Down Expand Up @@ -146,8 +146,19 @@ def initialize_professors(user, roles)
if roles[Role::ROLE_PROFESSOR]
can :read, Ability::PROFESSOR_MODELS
cannot :edit_professor, Grant
cannot :edit_professor, Paper
can :create, Grant
can :update, Grant, professor: user.professor
can :destroy, Grant, professor: user.professor
can :create, Paper
can :update, Paper, owner: user.professor
can :create, PaperProfessor
can :create, PaperStudent
can :update, PaperProfessor, paper: { owner: user.professor }
can :update, PaperStudent, paper: { owner: user.professor }
can :destroy, PaperProfessor, paper: { owner: user.professor }
can :destroy, PaperStudent, paper: { owner: user.professor }
can :destroy, Paper, owner: user.professor
end
end

Expand Down
7 changes: 7 additions & 0 deletions app/models/custom_variable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class CustomVariable < ApplicationRecord
"year_semester_range" => :text,
"past_calendar_range" => :text,
"academic_calendar_range" => :text,
"quadrennial_period" => :text,
}

validates :variable, presence: true
Expand Down Expand Up @@ -115,6 +116,12 @@ def self.academic_calendar_range
self.parse_calendar_range(config, [20, 10, false])
end

def self.quadrennial_period
config = CustomVariable.find_by_variable(:quadrennial_period)
config.blank? ? "Not defined" : config.value
end


def to_label
self.variable.to_s
end
Expand Down
56 changes: 56 additions & 0 deletions app/models/paper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright (c) Universidade Federal Fluminense (UFF).
# This file is part of SAPOS. Please, consult the license terms in the LICENSE file.

# frozen_string_literal: true

class Paper < ApplicationRecord
has_paper_trail

attr_accessor :reason_group, :reason_group_end, :header

belongs_to :owner, optional: false, class_name: "Professor"
has_many :paper_professors, dependent: :destroy
has_many :paper_students, dependent: :destroy
has_many :professors, through: :paper_professors
has_many :students, through: :paper_students

JOURNAL = I18n.translate(
"activerecord.attributes.paper.kinds.journal"
)
CONFERENCE = I18n.translate(
"activerecord.attributes.paper.kinds.conference"
)
KINDS = [JOURNAL, CONFERENCE]

ORDERS = [1, 2, 3, 4, 5, 6, 7, 8]

validates :reference, presence: true
validates :kind, presence: true, inclusion: { in: KINDS }
validates :doi_issn_event, presence: true
validates :reason_justify, presence: true
validates :impact_factor, presence: true
validates :order, presence: true, inclusion: { in: ORDERS }, uniqueness: {
scope: [:period, :owner_id], message: :order_uniqueness
}

validate :that_professor_cannot_edit_other_papers, if: -> { cannot?(:edit_professor, self) }

def that_professor_cannot_edit_other_papers
current_professor = current_user&.professor
return if current_professor.nil?
if self.changes[:owner_id].present? && self.changes[:owner_id] != [nil, current_professor.id]
self.errors.add(:owner, :cannot_edit_other_papers)
end
end

def to_label
"[#{self.owner.to_label}] #{self.reference}"
end

private
delegate :can?, :cannot?, to: :ability

def ability
@ability ||= Ability.new(current_user)
end
end
15 changes: 15 additions & 0 deletions app/models/paper_professor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright (c) Universidade Federal Fluminense (UFF).
# This file is part of SAPOS. Please, consult the license terms in the LICENSE file.

# frozen_string_literal: true

class PaperProfessor < ApplicationRecord
has_paper_trail

belongs_to :paper, optional: false
belongs_to :professor, optional: false

def to_label
"#{self.professor.to_label} - #{self.paper.to_label}"
end
end
10 changes: 10 additions & 0 deletions app/models/paper_student.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class PaperStudent < ApplicationRecord
has_paper_trail

belongs_to :paper
belongs_to :student

def to_label
"#{self.student.to_label} - #{self.paper.to_label}"
end
end
10 changes: 10 additions & 0 deletions app/views/papers/_header_form_column.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Lembre que o relatório final é a coleção de artigos do programa. Assim:

<ul>
<li>Tente informar entre quatro e oito artigos. Mas não deixe de preencher se sua escolha for menor que essa.</li>
<li>Caso tenha mais de um artigo de destaque por ano, informe também.</li>
<li>Os artigos podem ser publicações em periódicos ou conferências.</li>
</ul>

<br>
<br>
4 changes: 4 additions & 0 deletions app/views/papers/_reason_group_end_form_column.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
</li>
</div>

<li>
25 changes: 25 additions & 0 deletions app/views/papers/_reason_group_form_column.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
</li>
<style>
.paper-reason-group {
width: 35em;
}
.paper-reason-group li.checkbox dl {
display: flex;
flex-direction: row-reverse;
flex-wrap: nowrap;
}
.paper-reason-group li.checkbox dl > dt {
width: 100% !important;
flex: 1 1 100%;
padding: 10px 0;
}
.paper-reason-group li.checkbox dl > dd {
flex: 0 1 23px;
}
</style>

<% id ||= "group_#{SecureRandom.random_number(1_000_000)}" %>
<h5> Motivos <a href="#" class="as-js-button visibility-toggle" data-toggable="<%= id %>" data-show="Mostrar" data-hide="Ocultar">Ocultar</a> </h5>
<div id="<%= id %>" class="paper-reason-group">
Quais aspectos atribui ao artigo para que ele entre na sua lista?
<li>
1 change: 1 addition & 0 deletions config/locales/navigation.pt-BR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pt-BR:
advisement_authorization: Credenciamentos
thesis_defense_committee_participation: Bancas
grant: Coordenações de Projetos
paper: Avaliação quadrienal - 4N

scholarships:
label: Bolsas
Expand Down
Loading

0 comments on commit 0517434

Please sign in to comment.