edit comment and pdf export
This commit is contained in:
parent
110d75f2b7
commit
c36230b8ba
10 changed files with 90 additions and 19 deletions
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
class SuccessCriteriaController < ApplicationController
|
||||
before_action :set_element, only: %i[new create index new_from_checklist create_from_checklist]
|
||||
before_action :set_success_criterion, only: %i[show edit update destroy]
|
||||
before_action :set_success_criterion, only: %i[show edit update destroy edit_comment]
|
||||
|
||||
# GET /success_criteria
|
||||
def index
|
||||
|
|
@ -108,6 +108,10 @@ class SuccessCriteriaController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def edit_comment
|
||||
render_modal()
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@ class Element < ApplicationRecord
|
|||
attachable.variant :thumbnail, resize_to_limit: [ 200, 200 ]
|
||||
end
|
||||
|
||||
scope :failed, -> { where(SuccessCriterion.where(result: SuccessCriterion.results[:failed]).arel.exists) }
|
||||
|
||||
# Calculate actual conformity level:
|
||||
# - if a success_criterion has result :failed -> the confirmity_level
|
||||
# of that success_criterion is not reached.
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
module PdfDocuments
|
||||
class Base
|
||||
attr_reader :params
|
||||
attr_reader :params, :font
|
||||
|
||||
def initialize(prawn_document, **params)
|
||||
@prawn_document = prawn_document
|
||||
|
|
@ -13,7 +13,8 @@ module PdfDocuments
|
|||
# exta_bold: 'vendor/assets/fonts/Lexend-ExtraBold.ttf',
|
||||
# italic: 'vendor/assets/fonts/Lexend-Regular.ttf'
|
||||
# })
|
||||
@prawn_document.font "Helvetica", size: 12
|
||||
@font = "Helvetica"
|
||||
@prawn_document.font @font, size: 12
|
||||
@params = OpenStruct.new(params)
|
||||
end
|
||||
|
||||
|
|
@ -40,6 +41,10 @@ module PdfDocuments
|
|||
@prawn_document.markup "<h3>#{text}</h3>"
|
||||
end
|
||||
|
||||
def heading4(text)
|
||||
@prawn_document.markup "<h4>#{text}</h4>"
|
||||
end
|
||||
|
||||
def text(text)
|
||||
@prawn_document.text text, markup_options[:text]
|
||||
end
|
||||
|
|
@ -56,10 +61,10 @@ module PdfDocuments
|
|||
{
|
||||
text: { size: 12, margin_bottom: 5 },
|
||||
heading1: { style: :bold, size: 26, margin_bottom: 10, margin_top: 0 },
|
||||
heading2: { style: :bold, size: 17, margin_bottom: 10, margin_top: 5 },
|
||||
heading3: { style: :bold, size: 13, margin_bottom: 10, margin_top: 5 },
|
||||
heading4: { style: :bold, size: 12, margin_bottom: 10, margin_top: 5 },
|
||||
heading5: { style: :bold, size: 12, margin_bottom: 10, margin_top: 5 },
|
||||
heading2: { style: :bold, size: 17, margin_bottom: 10, margin_top: 15 },
|
||||
heading3: { style: :bold, size: 13, margin_bottom: 10, margin_top: 15 },
|
||||
heading4: { style: :bold, size: 12, margin_bottom: 10, margin_top: 10 },
|
||||
heading5: { style: :bold, size: 12, margin_bottom: 10, margin_top: 10 },
|
||||
heading6: { style: :thin, size: 12, margin_bottom: 10, margin_top: 5 }
|
||||
}
|
||||
end
|
||||
|
|
@ -70,7 +75,7 @@ module PdfDocuments
|
|||
end
|
||||
|
||||
def prepare_rich_text(rich_text)
|
||||
{ h1: "h4" }.each do |tag, replacement|
|
||||
{ h1: "h5" }.each do |tag, replacement|
|
||||
rich_text = rich_text.to_s.gsub("<#{tag}", "<#{replacement}")
|
||||
rich_text = rich_text.to_s.gsub("</#{tag}>", "</#{replacement}>")
|
||||
end
|
||||
|
|
@ -89,5 +94,17 @@ module PdfDocuments
|
|||
def move_down(...)
|
||||
@prawn_document.move_down(...)
|
||||
end
|
||||
|
||||
def safe_display(value, &block)
|
||||
return if value.blank?
|
||||
|
||||
yield
|
||||
end
|
||||
|
||||
def bold(text)
|
||||
@prawn_document.font(@font, style: :bold) do
|
||||
@prawn_document.text text
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -13,18 +13,39 @@ module PdfDocuments
|
|||
heading1 params.report.name
|
||||
rich_text params.report.comment
|
||||
|
||||
params.report.elements.each.with_index(1) do |element, element_index|
|
||||
params.report.export[:elements].each.with_index(1) do |(element, success_criteria), element_index|
|
||||
heading2 "#{element_index} #{element.title}"
|
||||
formatted_text [ { text: element.path, styles: %i[bold italic underline] } ]
|
||||
move_down(5)
|
||||
rich_text element.description_html
|
||||
bold("Pfad: #{element.page.path}")
|
||||
move_down(5)
|
||||
rich_text element.description
|
||||
|
||||
element.success_criteria.each.with_index(1) do |success_criterion, sc_index|
|
||||
heading3 "#{element_index}.#{sc_index} #{success_criterion.title}"
|
||||
rich_text success_criterion.description_html
|
||||
rich_text success_criterion.comment
|
||||
success_criteria.each.with_index(1) do |success_criterion, sc_index|
|
||||
success_criterion_row(success_criterion, [element_index, sc_index])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def success_criterion_row(success_criterion, index)
|
||||
heading3 "#{index.join(".")} #{success_criterion.title}"
|
||||
safe_display(success_criterion.test_comment) do
|
||||
heading4 "Kommentar"
|
||||
rich_text success_criterion.test_comment
|
||||
end
|
||||
safe_display(success_criterion.quick_criterion) do
|
||||
heading4 "Kriterium"
|
||||
rich_text success_criterion.quick_criterion
|
||||
end
|
||||
safe_display(success_criterion.quick_fail) do
|
||||
heading4 "Fail"
|
||||
rich_text success_criterion.quick_fail
|
||||
end
|
||||
safe_display(success_criterion.quick_fix) do
|
||||
heading4 "Fix"
|
||||
rich_text success_criterion.quick_fix
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,7 +3,20 @@
|
|||
class Report < ApplicationRecord
|
||||
has_many :pages, -> { order(:position) }, dependent: :destroy
|
||||
has_many :elements, through: :pages, dependent: :destroy
|
||||
has_many :success_criteria, through: :elements, dependent: :destroy
|
||||
|
||||
has_rich_text :comment
|
||||
|
||||
validates :name, presence: true
|
||||
|
||||
def export
|
||||
export_success_criteria = success_criteria.failed
|
||||
export_elements = export_success_criteria.group_by(&:element)
|
||||
export_pages = export_elements.group_by { |k, v| k }
|
||||
{
|
||||
pages: export_pages,
|
||||
elements: export_elements,
|
||||
success_criteria: export_success_criteria
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ class SuccessCriterion < ApplicationRecord
|
|||
|
||||
validates :result, inclusion: { in: self.results.keys + [ nil ] }
|
||||
|
||||
scope :failed, -> { where(result: :failed) }
|
||||
|
||||
def level_value
|
||||
return nil unless level
|
||||
|
||||
|
|
|
|||
|
|
@ -43,9 +43,9 @@ div
|
|||
= link_to(report_export_path(@report), class: "btn btn-secondary", target: :_blank) do
|
||||
i.bi.bi-filetype-html
|
||||
| Online HTML
|
||||
/ = link_to report_path(@report, format: :pdf), class: "btn btn-secondary", target: "_blank" do
|
||||
/ i.bi.bi-filetype-pdf
|
||||
/ | PDF
|
||||
= link_to report_path(@report, format: :pdf), class: "btn btn-secondary", target: "_blank" do
|
||||
i.bi.bi-filetype-pdf
|
||||
| PDF
|
||||
/ = link_to report_path(@report, format: :docx), class: "btn btn-secondary", target: "_blank" do
|
||||
/ i.bi.bi-filetype-docx
|
||||
/ | DOCX
|
||||
|
|
|
|||
|
|
@ -11,7 +11,10 @@
|
|||
label.btn.btn-outline-secondary for=dom_id(success_criterion, :result_not_applicable) Nicht anwendbar
|
||||
/= form.radio_button_without_bootstrap :result, nil, class: "btn-check", autocomplete: "off", id: dom_id(success_criterion, :result_not_applicable)
|
||||
/label.btn.btn-outline-secondary for=dom_id(success_criterion, :nil) Reset
|
||||
/ = dropdown_menu([{ text: "Bearbeiten", icon: "pencil", href: edit_success_criterion_path(success_criterion) }, { text: "Löschen", icon: "trash", href: success_criterion, color: :danger, method: :delete, confirm: "Bist du sicher?"}], klass: "mt-3 ms-auto")
|
||||
- unless success_criterion.test_comment.blank?
|
||||
= link_to(edit_comment_success_criterion_path(success_criterion), class: "btn btn-outline-warning my-3 ms-3", data: { turbo_frame: "modal" }) do
|
||||
i.bi.bi-chat>
|
||||
'Kommentar bearbeiten
|
||||
= success_criterion_menu(success_criterion)
|
||||
.row
|
||||
.col
|
||||
|
|
|
|||
5
app/views/success_criteria/edit_comment.html.slim
Normal file
5
app/views/success_criteria/edit_comment.html.slim
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
= bootstrap_form_with(model: @success_criterion.persisted? ? @success_criterion : [:element, @success_criterion], data: { controller: "unsaved-changes" }) do |form|
|
||||
= form.rich_text_area :test_comment
|
||||
= form.submit class: "btn btn-primary"
|
||||
- unless modal?
|
||||
=< link_to "Abbrechen", @success_criterion.persisted? ? @success_criterion : @success_criterion.element, class: "btn btn-outline-secondary"
|
||||
|
|
@ -19,6 +19,10 @@ Rails.application.routes.draw do
|
|||
get "from_checklist", action: :new_from_checklist, as: :new_from_checklist
|
||||
post "from_checklist", action: :create_from_checklist, as: :create_from_checklist
|
||||
end
|
||||
|
||||
member do
|
||||
get "edit_comment"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue