Skip to content

Commit

Permalink
Merge branch 'override_signature_type' into assertion-pdf-validation
Browse files Browse the repository at this point in the history
  • Loading branch information
anderson-mj committed Dec 23, 2024
2 parents 0a097cf + ba2fc83 commit b663560
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 16 deletions.
8 changes: 5 additions & 3 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, filename = "transcript.pdf")
def render_enrollments_academic_transcript_pdf(enrollment, filename = "transcript.pdf", signature_override = nil)
class_enrollments = enrollment.class_enrollments
.where(situation: ClassEnrollment::APPROVED)
.joins(:course_class)
Expand All @@ -51,11 +51,12 @@ def render_enrollments_academic_transcript_pdf(enrollment, filename = "transcrip
enrollment: enrollment,
class_enrollments: class_enrollments,
accomplished_phases: accomplished_phases,
signature_override: signature_override
}
)
end

def render_enrollments_grades_report_pdf(enrollment, filename = "grades_report.pdf")
def render_enrollments_grades_report_pdf(enrollment, filename = "grades_report.pdf", signature_override = nil)
class_enrollments = enrollment.class_enrollments
.where(situation: ClassEnrollment::APPROVED)
.joins(:course_class)
Expand All @@ -71,7 +72,8 @@ def render_enrollments_grades_report_pdf(enrollment, filename = "grades_report.p
enrollment: enrollment,
class_enrollments: class_enrollments,
accomplished_phases: accomplished_phases,
deferrals: deferrals
deferrals: deferrals,
signature_override: signature_override
}
)
end
Expand Down
19 changes: 14 additions & 5 deletions app/controllers/enrollments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ class EnrollmentsController < ApplicationController
:accomplishments, :deferrals, :phase_due_dates
]
config.update.columns = columns - [:phase_due_dates]
config.show.columns = columns - [:accomplishments]
config.show.columns = columns - [:accomplishments]
config.show.columns.add :academic_transcript, :grades_report

config.actions.exclude :deleted_records
end
Expand Down Expand Up @@ -213,28 +214,36 @@ def to_pdf
end
end

def academic_transcript_pdf
def override_signature_transcript_pdf
academic_transcript_pdf(params[:signature_type])
end

def override_signature_grades_report_pdf
grades_report_pdf(params[:signature_type])
end

def academic_transcript_pdf(signature_type = nil)
enrollment = Enrollment.find(params[:id])
respond_to do |format|
format.pdf do
title = I18n.t("pdf_content.enrollment.academic_transcript.title")
student = enrollment.student.name
filename = "#{title} - #{student}.pdf"
send_data render_enrollments_academic_transcript_pdf(enrollment, filename),
send_data render_enrollments_academic_transcript_pdf(enrollment, filename, signature_type),
filename: filename,
type: "application/pdf"
end
end
end

def grades_report_pdf
def grades_report_pdf(signature_type = nil)
enrollment = Enrollment.find(params[:id])
respond_to do |format|
format.pdf do
title = I18n.t("pdf_content.enrollment.grades_report.title")
student = enrollment.student.name
filename = "#{title} - #{student}.pdf"
send_data render_enrollments_grades_report_pdf(enrollment, filename),
send_data render_enrollments_grades_report_pdf(enrollment, filename, signature_type),
filename: filename,
type: "application/pdf"
end
Expand Down
16 changes: 13 additions & 3 deletions app/helpers/enrollments_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def delayed_phase_search_column(record, input_name)
:record, :phases,
options_for_select([["Alguma", "all"]] +
Phase.where(active: true).map { |phase| [phase.name, phase.id] }
),
),
{ include_blank: as_(:_select_) },
select_html_options
) +
Expand All @@ -120,14 +120,14 @@ def accomplishments_search_column(record, input_name)
select_html_options = { name: "search[accomplishments][phase]" }
day_html_options = { name: "search[accomplishments][day]" }
month_html_options = { name: "search[accomplishments][month]" }
year_html_options = { name: "search[accomplishments][year]"}
year_html_options = { name: "search[accomplishments][year]" }

(
select(
:record, :phases,
options_for_select([["Todas", "all"]] +
Phase.all.map { |phase| [phase.name, phase.id] }
),
),
{ include_blank: as_(:_select_) },
select_html_options
) +
Expand Down Expand Up @@ -339,4 +339,14 @@ def options_for_association_conditions(association, record)
def permit_rs_browse_params
[:page, :update, :utf8]
end

def academic_transcript_show_column(record, column)
render(partial: "enrollments/show_academic_transcript_signature_override_links",
locals: { record: record })
end

def grades_report_show_column(record, column)
render(partial: "enrollments/show_grades_report_signature_override_links",
locals: { record: record })
end
end
11 changes: 8 additions & 3 deletions app/helpers/pdf_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -508,9 +508,14 @@ def qrcode_signature(pdf, options = {})

def setup_pdf_config(pdf_type, options)
pdf_type_property = :"use_at_#{pdf_type}"
options[:pdf_config] ||
ReportConfiguration.where(pdf_type_property => true).order(order: :desc).first ||
ReportConfiguration.new
config = options[:pdf_config] ||
ReportConfiguration.where(pdf_type_property => true).order(order: :desc).first ||
ReportConfiguration.new
if options[:signature_override].present?
config.signature_type = options[:signature_override]
end

config
end

def generate_qr_code_key
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div style="display: flex; gap: 20px;">
<%= link_to 'Sem Assinatura', override_signature_transcript_pdf_enrollment_path(id: @record.id, signature_type: :no_signature), target: "_blank" %>
<%= link_to 'Assinatura Manual', override_signature_transcript_pdf_enrollment_path(id: @record.id, signature_type: :manual), target: "_blank" %>
<%= link_to 'Assinatura por QR Code', override_signature_transcript_pdf_enrollment_path(id: @record.id, signature_type: :qr_code), target: "_blank" %>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div style="display: flex; flex-direction: column; gap: 10px;">
<div style="display: flex; justify-content: space-around; gap: 20px;">
<%= link_to 'Sem Assinatura', override_signature_grades_report_pdf_enrollment_path(id: @record.id, signature_type: :no_signature, transcript: true), target: "_blank" %>
<%= link_to 'Assinatura Manual', override_signature_grades_report_pdf_enrollment_path(id: @record.id, signature_type: :manual, transcript: true), target: "_blank" %>
<%= link_to 'Assinatura por QR Code', override_signature_grades_report_pdf_enrollment_path(id: @record.id, signature_type: :qr_code, transcript: true), target: "_blank" %>
</div>
</div>
3 changes: 2 additions & 1 deletion app/views/enrollments/academic_transcript_pdf.pdf.prawn
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ new_document(
watermark: cannot?(
:generate_report_without_watermark, @enrollment
),
pdf_type: :transcript
pdf_type: :transcript,
signature_override: @signature_override
) do |pdf|
enrollment_student_header(pdf, enrollment: @enrollment)

Expand Down
3 changes: 2 additions & 1 deletion app/views/enrollments/grades_report_pdf.pdf.prawn
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ new_document(
:generate_report_without_watermark, @enrollment
)
),
pdf_type: :grades_report
pdf_type: :grades_report,
signature_override: @signature_override
) do |pdf|
enrollment_student_header(pdf, enrollment: @enrollment)

Expand Down
2 changes: 2 additions & 0 deletions config/locales/enrollment.pt-BR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ pt-BR:
thesis_defense_committee_professors: "Banca Avaliadora"
accomplishment_conclusion_date_not_given: "---------/----"
obs_to_academic_transcript: "Observação para o Histórico"
grades_report: "Boletim"
academic_transcript: "Histórico"

errors:
models:
Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@
end
member do
get "academic_transcript_pdf"
get "academic_transcript/:signature_type.pdf", to: "enrollments#override_signature_transcript_pdf", as: :override_signature_transcript_pdf
get "grades_report_pdf"
get "grades_report/:signature_type.pdf", to: "enrollments#override_signature_grades_report_pdf", as: :override_signature_grades_report_pdf
end
end

Expand Down

0 comments on commit b663560

Please sign in to comment.