edit comment and pdf export
Some checks failed
/ Run tests (push) Successful in 2m6s
/ Run system tests (push) Failing after 2m29s
/ Build, push and deploy image (push) Successful in 1m46s

This commit is contained in:
david 2024-11-23 21:11:01 +01:00
parent 110d75f2b7
commit c36230b8ba
10 changed files with 90 additions and 19 deletions

View file

@ -2,7 +2,7 @@
class SuccessCriteriaController < ApplicationController class SuccessCriteriaController < ApplicationController
before_action :set_element, only: %i[new create index new_from_checklist create_from_checklist] 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 # GET /success_criteria
def index def index
@ -108,6 +108,10 @@ class SuccessCriteriaController < ApplicationController
end end
end end
def edit_comment
render_modal()
end
private private
# Use callbacks to share common setup or constraints between actions. # Use callbacks to share common setup or constraints between actions.

View file

@ -15,6 +15,8 @@ class Element < ApplicationRecord
attachable.variant :thumbnail, resize_to_limit: [ 200, 200 ] attachable.variant :thumbnail, resize_to_limit: [ 200, 200 ]
end end
scope :failed, -> { where(SuccessCriterion.where(result: SuccessCriterion.results[:failed]).arel.exists) }
# Calculate actual conformity level: # Calculate actual conformity level:
# - if a success_criterion has result :failed -> the confirmity_level # - if a success_criterion has result :failed -> the confirmity_level
# of that success_criterion is not reached. # of that success_criterion is not reached.

View file

@ -2,7 +2,7 @@
module PdfDocuments module PdfDocuments
class Base class Base
attr_reader :params attr_reader :params, :font
def initialize(prawn_document, **params) def initialize(prawn_document, **params)
@prawn_document = prawn_document @prawn_document = prawn_document
@ -13,7 +13,8 @@ module PdfDocuments
# exta_bold: 'vendor/assets/fonts/Lexend-ExtraBold.ttf', # exta_bold: 'vendor/assets/fonts/Lexend-ExtraBold.ttf',
# italic: 'vendor/assets/fonts/Lexend-Regular.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) @params = OpenStruct.new(params)
end end
@ -40,6 +41,10 @@ module PdfDocuments
@prawn_document.markup "<h3>#{text}</h3>" @prawn_document.markup "<h3>#{text}</h3>"
end end
def heading4(text)
@prawn_document.markup "<h4>#{text}</h4>"
end
def text(text) def text(text)
@prawn_document.text text, markup_options[:text] @prawn_document.text text, markup_options[:text]
end end
@ -56,10 +61,10 @@ module PdfDocuments
{ {
text: { size: 12, margin_bottom: 5 }, text: { size: 12, margin_bottom: 5 },
heading1: { style: :bold, size: 26, margin_bottom: 10, margin_top: 0 }, heading1: { style: :bold, size: 26, margin_bottom: 10, margin_top: 0 },
heading2: { style: :bold, size: 17, 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: 5 }, heading3: { style: :bold, size: 13, margin_bottom: 10, margin_top: 15 },
heading4: { style: :bold, size: 12, margin_bottom: 10, margin_top: 5 }, heading4: { style: :bold, size: 12, margin_bottom: 10, margin_top: 10 },
heading5: { style: :bold, size: 12, margin_bottom: 10, margin_top: 5 }, heading5: { style: :bold, size: 12, margin_bottom: 10, margin_top: 10 },
heading6: { style: :thin, size: 12, margin_bottom: 10, margin_top: 5 } heading6: { style: :thin, size: 12, margin_bottom: 10, margin_top: 5 }
} }
end end
@ -70,7 +75,7 @@ module PdfDocuments
end end
def prepare_rich_text(rich_text) 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}")
rich_text = rich_text.to_s.gsub("</#{tag}>", "</#{replacement}>") rich_text = rich_text.to_s.gsub("</#{tag}>", "</#{replacement}>")
end end
@ -89,5 +94,17 @@ module PdfDocuments
def move_down(...) def move_down(...)
@prawn_document.move_down(...) @prawn_document.move_down(...)
end 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
end end

View file

@ -13,18 +13,39 @@ module PdfDocuments
heading1 params.report.name heading1 params.report.name
rich_text params.report.comment 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}" heading2 "#{element_index} #{element.title}"
formatted_text [ { text: element.path, styles: %i[bold italic underline] } ]
move_down(5) 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| success_criteria.each.with_index(1) do |success_criterion, sc_index|
heading3 "#{element_index}.#{sc_index} #{success_criterion.title}" success_criterion_row(success_criterion, [element_index, sc_index])
rich_text success_criterion.description_html
rich_text success_criterion.comment
end end
end 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
end end

View file

@ -3,7 +3,20 @@
class Report < ApplicationRecord class Report < ApplicationRecord
has_many :pages, -> { order(:position) }, dependent: :destroy has_many :pages, -> { order(:position) }, dependent: :destroy
has_many :elements, through: :pages, dependent: :destroy has_many :elements, through: :pages, dependent: :destroy
has_many :success_criteria, through: :elements, dependent: :destroy
has_rich_text :comment has_rich_text :comment
validates :name, presence: true 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 end

View file

@ -19,6 +19,8 @@ class SuccessCriterion < ApplicationRecord
validates :result, inclusion: { in: self.results.keys + [ nil ] } validates :result, inclusion: { in: self.results.keys + [ nil ] }
scope :failed, -> { where(result: :failed) }
def level_value def level_value
return nil unless level return nil unless level

View file

@ -43,9 +43,9 @@ div
= link_to(report_export_path(@report), class: "btn btn-secondary", target: :_blank) do = link_to(report_export_path(@report), class: "btn btn-secondary", target: :_blank) do
i.bi.bi-filetype-html i.bi.bi-filetype-html
| Online HTML | Online HTML
/ = link_to report_path(@report, format: :pdf), class: "btn btn-secondary", target: "_blank" do = link_to report_path(@report, format: :pdf), class: "btn btn-secondary", target: "_blank" do
/ i.bi.bi-filetype-pdf i.bi.bi-filetype-pdf
/ | PDF | PDF
/ = link_to report_path(@report, format: :docx), class: "btn btn-secondary", target: "_blank" do / = link_to report_path(@report, format: :docx), class: "btn btn-secondary", target: "_blank" do
/ i.bi.bi-filetype-docx / i.bi.bi-filetype-docx
/ | DOCX / | DOCX

View file

@ -11,7 +11,10 @@
label.btn.btn-outline-secondary for=dom_id(success_criterion, :result_not_applicable) Nicht anwendbar 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) /= 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 /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) = success_criterion_menu(success_criterion)
.row .row
.col .col

View 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"

View file

@ -19,6 +19,10 @@ Rails.application.routes.draw do
get "from_checklist", action: :new_from_checklist, as: :new_from_checklist get "from_checklist", action: :new_from_checklist, as: :new_from_checklist
post "from_checklist", action: :create_from_checklist, as: :create_from_checklist post "from_checklist", action: :create_from_checklist, as: :create_from_checklist
end end
member do
get "edit_comment"
end
end end
end end
end end