A lot :)
This commit is contained in:
parent
aad67af0d1
commit
63fc206c27
153 changed files with 2043 additions and 646 deletions
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class ReportsController < ApplicationController
|
||||
before_action :set_report, only: %i[show edit update destroy work]
|
||||
|
||||
|
|
@ -12,26 +14,56 @@ class ReportsController < ApplicationController
|
|||
format.html
|
||||
format.pdf
|
||||
format.xlsx do
|
||||
response.headers['Content-Disposition'] = %(attachment; filename="#{filename(@report, extension: 'xlsx')}")
|
||||
response.headers["Content-Disposition"] = %(attachment; filename="#{filename(@report, extension: 'xlsx')}")
|
||||
render
|
||||
end
|
||||
format.xml do
|
||||
response.headers['Content-Disposition'] = %(attachment; filename="#{filename(@report, extension: 'html')}")
|
||||
render formats: [:odt], layout: false
|
||||
response.headers["Content-Disposition"] = %(attachment; filename="#{filename(@report, extension: 'html')}")
|
||||
render formats: [ :odt ], layout: false
|
||||
end
|
||||
format.rtf do
|
||||
html = render_to_string(template: 'reports/show', formats: [:odt],
|
||||
html = render_to_string(template: "reports/show", formats: [ :odt ],
|
||||
layout: false)
|
||||
rtf = "{\\rtf1\n#{PandocRuby.html(html).to_rtf}}"
|
||||
send_data rtf, filename: filename(@report, extension: 'rtf')
|
||||
send_data rtf, filename: filename(@report, extension: "rtf")
|
||||
end
|
||||
format.odt do
|
||||
html = render_to_string(layout: false)
|
||||
odt = PandocRuby.html(html).to_odt
|
||||
send_data odt, filename: filename(@report, extension: 'odt')
|
||||
send_data odt, filename: filename(@report, extension: "odt")
|
||||
end
|
||||
format.docx do
|
||||
template = Sablon.template(Rails.root.join('lib/templates/docx/report.docx'))
|
||||
send_file(Docx::Document.new.generate do |document|
|
||||
document.heading1(@report.name)
|
||||
document.paragraph(@report.comment_html)
|
||||
# document.heading1("slfkj")
|
||||
# document.paragraph("sldkfj")
|
||||
@report.elements.each do |element|
|
||||
document.heading2(element.title)
|
||||
element.success_criteria.each do |sc|
|
||||
document.heading3(sc.title)
|
||||
document.paragraph(sc.description_html)
|
||||
end
|
||||
end
|
||||
end, filename: filename(@report, extension: "docx"),
|
||||
type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document")
|
||||
|
||||
return
|
||||
|
||||
text = OpenXml::Docx::Elements::Text.new(@report.name)
|
||||
run = OpenXml::Docx::Elements::Run.new
|
||||
run.bold = true
|
||||
run << text
|
||||
paragraph = OpenXml::Docx::Elements::Paragraph.new
|
||||
paragraph << run
|
||||
|
||||
document = OpenXml::Docx::Package.new
|
||||
document.document << paragraph
|
||||
document.save(Rails.root.join("tmp", "output.docx"))
|
||||
send_file Rails.root.join("tmp", "output.docx")
|
||||
return
|
||||
|
||||
template = Sablon.template(Rails.root.join("lib/templates/docx/report.docx"))
|
||||
context = {
|
||||
person: OpenStruct.new(first_name: @report.name),
|
||||
skills: [],
|
||||
|
|
@ -40,10 +72,10 @@ class ReportsController < ApplicationController
|
|||
referees: []
|
||||
}
|
||||
|
||||
template.render_to_file(Rails.root.join('tmp/output.docx'), context)
|
||||
send_file Rails.root.join('tmp/output.docx'),
|
||||
filename: filename(@report, extension: 'docx'),
|
||||
type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
|
||||
template.render_to_file(Rails.root.join("tmp/output.docx"), context)
|
||||
send_file Rails.root.join("tmp/output.docx"),
|
||||
filename: filename(@report, extension: "docx"),
|
||||
type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -54,15 +86,14 @@ class ReportsController < ApplicationController
|
|||
end
|
||||
|
||||
# GET /reports/1/edit
|
||||
def edit
|
||||
end
|
||||
def edit; end
|
||||
|
||||
# POST /reports
|
||||
def create
|
||||
@report = Report.new(report_params)
|
||||
|
||||
if @report.save
|
||||
redirect_to @report, notice: 'Report was successfully created.'
|
||||
redirect_to @report, notice: "Report was successfully created."
|
||||
else
|
||||
render :new, status: :unprocessable_entity
|
||||
end
|
||||
|
|
@ -71,7 +102,7 @@ class ReportsController < ApplicationController
|
|||
# PATCH/PUT /reports/1
|
||||
def update
|
||||
if @report.update(report_params)
|
||||
redirect_to @report, notice: 'Report was successfully updated.', status: :see_other
|
||||
redirect_to @report, notice: "Report was successfully updated.", status: :see_other
|
||||
else
|
||||
render :edit, status: :unprocessable_entity
|
||||
end
|
||||
|
|
@ -80,7 +111,7 @@ class ReportsController < ApplicationController
|
|||
# DELETE /reports/1
|
||||
def destroy
|
||||
@report.destroy!
|
||||
redirect_to reports_url, notice: 'Report was successfully destroyed.', status: :see_other
|
||||
redirect_to reports_url, notice: "Report was successfully destroyed.", status: :see_other
|
||||
end
|
||||
|
||||
def work
|
||||
|
|
@ -99,7 +130,7 @@ class ReportsController < ApplicationController
|
|||
params.require(:report).permit(:name, :comment_html)
|
||||
end
|
||||
|
||||
def filename(report, extension: 'html')
|
||||
def filename(report, extension: "html")
|
||||
"#{report.name}-#{Time.current.strftime('%Y%m%d%H%M')}.#{extension}"
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue