-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into admission-tests
- Loading branch information
Showing
13 changed files
with
295 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# 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 GrantsController < ApplicationController | ||
authorize_resource | ||
|
||
active_scaffold :grant do |config| | ||
config.create.label = :create_grant_label | ||
config.columns = [:title, :start_year, :end_year, :professor, :kind, :funder, :amount] | ||
config.actions.swap :search, :field_search | ||
config.columns[:professor].form_ui = :record_select | ||
config.columns[:kind].form_ui = :select | ||
config.columns[:kind].options = { | ||
options: Grant::KINDS, | ||
default: Grant::PUBLIC, | ||
include_blank: I18n.t("active_scaffold._select_") | ||
} | ||
config.columns[:amount].options[:format] = :currency | ||
config.columns[:start_year].options[:format] = "%d" | ||
config.columns[:end_year].options[:format] = "%d" | ||
config.actions.exclude :deleted_records | ||
end | ||
|
||
protected | ||
def do_new | ||
super | ||
unless current_user.professor.blank? | ||
@record.professor = current_user.professor | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
||
# frozen_string_literal: true | ||
|
||
module GrantsHelper | ||
def professor_form_column(record, options) | ||
if can?(:edit_professor, record) | ||
record_select_field :professor, record.professor || Professor.new, options | ||
else | ||
options[:value] = record.professor_id | ||
label( | ||
:record_value_1_params, record.id, record.professor.name | ||
) + hidden_field(:record, :professor, options) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# 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 Grant < ApplicationRecord | ||
has_paper_trail | ||
belongs_to :professor, optional: false | ||
|
||
PUBLIC = I18n.translate( | ||
"activerecord.attributes.grant.kinds.public" | ||
) | ||
PRIVATE = I18n.translate( | ||
"activerecord.attributes.grant.kinds.private" | ||
) | ||
KINDS = [PUBLIC, PRIVATE] | ||
|
||
validates :title, presence: true | ||
validates :start_year, presence: true | ||
validates :kind, presence: true, inclusion: { in: KINDS } | ||
validates :funder, presence: true | ||
validates :amount, presence: true, numericality: { greater_than_or_equal_to: 0 } | ||
validates :professor, presence: true | ||
validate :that_professor_cannot_edit_other_grants, if: -> { cannot?(:edit_professor, self) } | ||
validate :that_end_year_is_greater_than_start_year | ||
|
||
|
||
def that_professor_cannot_edit_other_grants | ||
current_professor = current_user&.professor | ||
return if current_professor.nil? | ||
if self.changes[:professor_id].present? && self.changes[:professor_id] != [nil, current_professor.id] | ||
self.errors.add(:professor, :cannot_edit_other_grants) | ||
end | ||
end | ||
|
||
def that_end_year_is_greater_than_start_year | ||
return if self.end_year.nil? | ||
if self.end_year < self.start_year | ||
self.errors.add(:end_year, :start_greater_than_end) | ||
end | ||
end | ||
|
||
def to_label | ||
"[#{self.start_year}] #{self.title}" | ||
end | ||
|
||
private | ||
delegate :can?, :cannot?, to: :ability | ||
|
||
def ability | ||
@ability ||= Ability.new(current_user) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# 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: | ||
grant: | ||
title: "Título" | ||
start_year: "Ano de Início" | ||
end_year: "Ano de Término" | ||
professor: "Coordenador" | ||
kind: "Tipo de financiamento" | ||
kinds: | ||
public: "Público" | ||
private: "Privado" | ||
funder: "Financiador" | ||
amount: "Valor total" | ||
description: | ||
grant: | ||
funder: "(e.g., CNPq, FAPERJ, nome da empresa, etc)" | ||
|
||
errors: | ||
models: | ||
grant: | ||
cannot_edit_other_grants: "não pode ser editado por este usuário" | ||
start_greater_than_end: "não pode ser menor do que Ano de Início" | ||
|
||
models: | ||
grant: | ||
one: "Coordenação de Projeto" | ||
other: "Coordenações de Projetos" | ||
|
||
active_scaffold: | ||
create_grant_label: "Adicionar Coordenação de Projeto" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# 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 CreateGrants < ActiveRecord::Migration[7.0] | ||
def change | ||
create_table :grants do |t| | ||
t.string :title | ||
t.integer :start_year | ||
t.integer :end_year | ||
t.string :kind | ||
t.string :funder | ||
t.decimal :amount, precision: 14, scale: 2 | ||
t.references :professor, null: false, foreign_key: true | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
FactoryBot.define do | ||
factory :grant do | ||
title { "Projeto" } | ||
start_year { 2024 } | ||
kind { Grant::PUBLIC } | ||
funder { "CNPq" } | ||
amount { 100000 } | ||
professor | ||
end | ||
end |
Oops, something went wrong.