Skip to content

Commit

Permalink
Merge branch 'refs/heads/main' into issue_477
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorMonardez committed Dec 11, 2024
2 parents ecf8ccc + 2ba309e commit 0a4ab36
Show file tree
Hide file tree
Showing 79 changed files with 1,557 additions and 84 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ gem "prawn"
gem "prawn-table"
gem "prawn-rails"
gem "matrix", "~> 0.4.2"
gem "prawn-qrcode"

# Redcarpet for Readme MarkDown (or README.md) - Credits Page
gem "redcarpet"
Expand Down
11 changes: 10 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ GEM
childprocess (5.1.0)
logger (~> 1.5)
choice (0.2.0)
chunky_png (1.4.0)
cocoon (1.2.15)
coderay (1.1.3)
coffee-rails (5.0.0)
Expand Down Expand Up @@ -295,6 +296,9 @@ GEM
prawn (2.4.0)
pdf-core (~> 0.9.0)
ttfunk (~> 1.7)
prawn-qrcode (0.5.2)
prawn (>= 1)
rqrcode (>= 1.0.0)
prawn-rails (1.4.2)
actionview (>= 3.1.0)
prawn
Expand Down Expand Up @@ -365,6 +369,10 @@ GEM
railties (>= 5.2)
rexml (3.3.9)
rouge (4.2.0)
rqrcode (2.2.0)
chunky_png (~> 1.0)
rqrcode_core (~> 1.0)
rqrcode_core (1.2.0)
rspec-collection_matchers (1.2.1)
rspec-expectations (>= 2.99.0.beta1)
rspec-core (3.12.2)
Expand Down Expand Up @@ -533,6 +541,7 @@ DEPENDENCIES
nokogiri (>= 1.16.5)
paper_trail
prawn
prawn-qrcode
prawn-rails
prawn-table
pry
Expand Down Expand Up @@ -564,7 +573,7 @@ DEPENDENCIES
web-console

RUBY VERSION
ruby 3.2.2p53
ruby 3.2.5p208

BUNDLED WITH
2.4.19
2 changes: 1 addition & 1 deletion app/controllers/admissions/admission_phases_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Admissions::AdmissionPhasesController < ApplicationController
form_columns = [
:name, :member_form, :shared_form, :consolidation_form, :candidate_form, :can_edit_candidate,
:candidate_can_edit, :candidate_can_see_member, :candidate_can_see_shared,
:candidate_can_see_consolidation,
:candidate_can_see_consolidation, :committee_can_see_other_individual,
:approval_condition, :keep_in_phase_condition, :admission_phase_committees,
]

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admissions/filled_forms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Admissions::FilledFormsController < ApplicationController
protected
def self.filled_form_params_definition
[
:id, :is_filled, :form_template_id, :disable_submission,
:id, :is_filled, :form_template_id, :enable_submission,
fields_attributes: [
:id, :form_field_id, :value, :_destroy, :remove_file, :file,
list: [],
Expand Down
6 changes: 4 additions & 2 deletions app/controllers/concerns/shared_pdf_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def render_course_classes_summary_pdf(course_class)
)
end

def render_enrollments_academic_transcript_pdf(enrollment)
def render_enrollments_academic_transcript_pdf(enrollment, filename = "transcript.pdf")
class_enrollments = enrollment.class_enrollments
.where(situation: ClassEnrollment::APPROVED)
.joins(:course_class)
Expand All @@ -47,14 +47,15 @@ def render_enrollments_academic_transcript_pdf(enrollment)
type: "application/pdf",
formats: [:pdf],
assigns: {
filename: filename,
enrollment: enrollment,
class_enrollments: class_enrollments,
accomplished_phases: accomplished_phases,
}
)
end

def render_enrollments_grades_report_pdf(enrollment)
def render_enrollments_grades_report_pdf(enrollment, filename = "grades_report.pdf")
class_enrollments = enrollment.class_enrollments
.where(situation: ClassEnrollment::APPROVED)
.joins(:course_class)
Expand All @@ -66,6 +67,7 @@ def render_enrollments_grades_report_pdf(enrollment)
type: "application/pdf",
formats: [:pdf],
assigns: {
filename: filename,
enrollment: enrollment,
class_enrollments: class_enrollments,
accomplished_phases: accomplished_phases,
Expand Down
10 changes: 6 additions & 4 deletions app/controllers/enrollments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,9 @@ def academic_transcript_pdf
format.pdf do
title = I18n.t("pdf_content.enrollment.academic_transcript.title")
student = enrollment.student.name
send_data render_enrollments_academic_transcript_pdf(enrollment),
filename: "#{title} - #{student}.pdf",
filename = "#{title} - #{student}.pdf"
send_data render_enrollments_academic_transcript_pdf(enrollment, filename),
filename: filename,
type: "application/pdf"
end
end
Expand All @@ -232,8 +233,9 @@ def grades_report_pdf
format.pdf do
title = I18n.t("pdf_content.enrollment.grades_report.title")
student = enrollment.student.name
send_data render_enrollments_grades_report_pdf(enrollment),
filename: "#{title} - #{student}.pdf",
filename = "#{title} - #{student}.pdf"
send_data render_enrollments_grades_report_pdf(enrollment, filename),
filename: filename,
type: "application/pdf"
end
end
Expand Down
33 changes: 33 additions & 0 deletions app/controllers/grants_controller.rb
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
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
86 changes: 86 additions & 0 deletions app/controllers/papers_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# 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 :reason_group
config.columns.add :reason_group_end
form_columns = [
: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,
: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,
: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
21 changes: 13 additions & 8 deletions app/controllers/report_configurations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,28 @@

class ReportConfigurationsController < ApplicationController
authorize_resource
skip_before_action :verify_authenticity_token, only: [:preview] # noqa # do not remove this line based on Code Scanner suggestions

include ApplicationHelper
active_scaffold :report_configuration do |config|
config.create.label = :create_report_configuration_label
columns = [
:name, :image, :scale, :x, :y, :order, :text, :signature_footer,
:preview, :use_at_report, :use_at_transcript, :use_at_grades_report,
:use_at_schedule,
:name, :image, :scale, :x, :y, :order, :text, :signature_type,
:preview, :use_at_report, :use_at_transcript,
:use_at_grades_report, :use_at_schedule, :expiration_in_months
]
config.create.columns = columns
config.update.columns = columns
columns.delete(:preview)
config.columns = columns
config.list.columns = [
:name, :order, :text, :signature_footer, :use_at_report,
:use_at_transcript, :use_at_grades_report, :use_at_schedule
:name, :order, :text, :signature_type,
:use_at_report, :use_at_transcript, :use_at_grades_report,
:use_at_schedule, :expiration_in_months
]
config.columns[:signature_type].form_ui = :select
config.columns[:signature_type].options = { options: ReportConfiguration.signature_types.keys.map(&:to_sym) }
config.columns[:expiration_in_months].description = I18n.t("active_scaffold.report_configurations.expiration_in_months_description")
config.list.sorting = { name: "ASC" }
config.actions << :duplicate
config.duplicate.link.label = "
Expand All @@ -40,7 +45,7 @@ def preview
record.assign_attributes(record_params.except(:image_cache, :remove_image))
# up = ImageUploader.new record, :image
# up.store(File.open(params[:record][:image]))
@pdf_config = record
@pdf_config = record.tap { |r| r.preview = true }
respond_to do |format|
format.pdf do
title = I18n.t("pdf_content.report_configurations.preview")
Expand All @@ -60,8 +65,8 @@ def logo
def record_params
params.required(:record).permit(
:name, :use_at_report, :use_at_transcript, :use_at_grades_report,
:use_at_schedule, :text, :image, :signature_footer, :order, :scale,
:x, :y
:use_at_schedule, :text, :image, :order, :scale,
:x, :y, :signature_type, :expiration_in_months
)
end
end
52 changes: 52 additions & 0 deletions app/controllers/reports_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# frozen_string_literal: true

class ReportsController < ApplicationController
before_action :set_report, only: [:download, :download_by_identifier]
before_action :check_downloadable, only: [:download, :download_by_identifier]
authorize_resource

skip_authorization_check only: :download_by_identifier
skip_authorize_resource only: :download_by_identifier
skip_before_action :authenticate_user!, only: :download_by_identifier

active_scaffold :report do |config|
config.list.columns = [:user, :file_name, :identifier, :created_at, :expires_at]
config.show.columns = [:user, :file_name, :identifier, :created_at, :expires_at]
config.update.columns = [:expires_at]
config.columns[:user].clear_link
config.actions.exclude :create, :delete
config.action_links.add "download",
label: "
<i title='#{I18n.t("active_scaffold.download_link")}'
class='fa fa-download'></i>
".html_safe,
page: true,
type: :member,
parameters: { format: :pdf },
method: :get,
html_options: { target: "_blank" },
ignore_method: :cant_download?
end

def download
redirect_to download_path(medium_hash: @report.carrierwave_file.medium_hash)
end

def download_by_identifier
send_data(@report.carrierwave_file.read, filename: @report.carrierwave_file.original_filename, disposition: :inline)
end

private
def set_report
@report = params[:id] ? Report.find(params[:id]) : Report.find_by_identifier(params[:identifier])
raise ActionController::RoutingError.new("Este documento não foi encontrado.") if @report.nil?
end

def check_downloadable
raise ActionController::RoutingError.new("Este documento expirou.") if cant_download?(@report)
end

def cant_download?(record)
record.carrierwave_file.blank?
end
end
Loading

0 comments on commit 0a4ab36

Please sign in to comment.