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
|
||||
|
||||
module ActionText
|
||||
class RichText < Record
|
||||
before_save do
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Admin
|
||||
class Backup
|
||||
class << self
|
||||
def zip
|
||||
create_records_xlsx
|
||||
|
||||
ZipFileGenerator.new(Rails.root.join('storage')).write
|
||||
ZipFileGenerator.new(Rails.root.join("storage")).write
|
||||
end
|
||||
|
||||
def db_xlsx
|
||||
|
|
@ -21,7 +23,7 @@ module Admin
|
|||
end
|
||||
end
|
||||
end
|
||||
path = Rails.root.join('storage/data.xls')
|
||||
path = Rails.root.join("storage/data.xls")
|
||||
xlsx.serialize(path)
|
||||
path
|
||||
end
|
||||
|
|
@ -29,7 +31,7 @@ module Admin
|
|||
private
|
||||
|
||||
def file_path(name)
|
||||
Rails.root.join('storage', name)
|
||||
Rails.root.join("storage", name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -53,9 +55,9 @@ module Admin
|
|||
# Zip the input directory.
|
||||
def write
|
||||
entries = Dir.entries(@input_dir) - %w[. ..]
|
||||
path = Rails.root.join('tmp', Time.now.to_i.to_s)
|
||||
path = Rails.root.join("tmp", Time.now.to_i.to_s)
|
||||
::Zip::File.open(path, create: true) do |zipfile|
|
||||
write_entries entries, '', zipfile
|
||||
write_entries entries, "", zipfile
|
||||
end
|
||||
path
|
||||
end
|
||||
|
|
@ -65,7 +67,7 @@ module Admin
|
|||
# A helper method to make the recursion work.
|
||||
def write_entries(entries, path, zipfile)
|
||||
entries.each do |e|
|
||||
zipfile_path = path == '' ? e : File.join(path, e)
|
||||
zipfile_path = path == "" ? e : File.join(path, e)
|
||||
disk_file_path = File.join(@input_dir, zipfile_path)
|
||||
|
||||
if File.directory? disk_file_path
|
||||
|
|
|
|||
|
|
@ -2,4 +2,17 @@
|
|||
|
||||
class ApplicationRecord < ActiveRecord::Base
|
||||
primary_abstract_class
|
||||
|
||||
class << self
|
||||
def translates_attributes(*attributes)
|
||||
attributes.each do |attribute|
|
||||
define_method("t_#{attribute}") do
|
||||
lang = I18n.locale.to_s.split("-").first
|
||||
send("#{attribute}_#{lang}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
alias_method :translates_attribute, :translates_attributes
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,11 +1,67 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Check < ApplicationRecord
|
||||
include RichTextTargetBlank
|
||||
|
||||
enum :level, %i[A AA AAA]
|
||||
belongs_to :principle
|
||||
|
||||
has_rich_text :success_criterion_html
|
||||
has_and_belongs_to_many :links
|
||||
has_and_belongs_to_many :standards
|
||||
|
||||
scope :search, lambda { |term|
|
||||
joins("INNER JOIN action_text_rich_texts ON action_text_rich_texts.record_id = checks.id AND record_type = 'Check'").where('checks.name LIKE :term OR action_text_rich_texts.body_text LIKE :term', term: "%#{term}%")
|
||||
}
|
||||
accepts_nested_attributes_for :links, allow_destroy: true
|
||||
|
||||
enum :conformity_level, %i[A AA AAA]
|
||||
enum :priority, %i[highest high normal low]
|
||||
|
||||
has_rich_text :conformity_notice_de
|
||||
has_rich_text :conformity_notice_en
|
||||
has_rich_text :quick_criterion_de
|
||||
has_rich_text :quick_criterion_en
|
||||
has_rich_text :quick_fail_de
|
||||
has_rich_text :quick_fail_en
|
||||
has_rich_text :quick_fix_de
|
||||
has_rich_text :quick_fix_en
|
||||
|
||||
has_rich_text :criterion_de
|
||||
has_rich_text :criterion_en
|
||||
has_rich_text :criterion_details_de
|
||||
has_rich_text :criterion_details_en
|
||||
has_rich_text :example_de
|
||||
has_rich_text :example_en
|
||||
has_rich_text :exemption_details_de
|
||||
has_rich_text :exemption_details_en
|
||||
has_rich_text :standard_text_de
|
||||
has_rich_text :standard_text_en
|
||||
|
||||
has_rich_text :test_instructions
|
||||
|
||||
has_rich_text :powerpoint_text_de
|
||||
has_rich_text :powerpoint_text_en
|
||||
|
||||
has_rich_text :comment
|
||||
|
||||
translates_attributes :name,
|
||||
:conformity_notice,
|
||||
:quick_criterion,
|
||||
:quick_fail,
|
||||
:quick_fix,
|
||||
:criterion,
|
||||
:criterion_details,
|
||||
:example,
|
||||
:exemption_details,
|
||||
:standard_text,
|
||||
:powerpoint_text
|
||||
|
||||
scope(:search, lambda do |term|
|
||||
# TODO: Search only fields for current locale.
|
||||
joins("INNER JOIN action_text_rich_texts ON action_text_rich_texts.record_id = checks.id AND record_type = 'Check'").where("checks.name_de LIKE :term OR checks.name_de LIKE :term OR action_text_rich_texts.body LIKE :term", term: "%#{term}%").distinct
|
||||
end)
|
||||
|
||||
def display_target_disabilities
|
||||
%i[visual auditory physical cognitive].select { |d| send(:"#{d}?") }.map { |d| I18n.t("disability.#{d}") }.map(&:first).join(", ")
|
||||
end
|
||||
|
||||
def display_applicabilities
|
||||
%i[applicable_to_app applicable_to_web].select { |a| send(:"#{a}?") }.map { |a| I18n.t("applicability.#{a}") }.map(&:first).join(", ")
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Checklist < ApplicationRecord
|
||||
has_many :checklist_entries, -> { order(position: :asc) }, dependent: :destroy, inverse_of: :checklist
|
||||
has_many :checks, through: :checklist_entries
|
||||
|
|
|
|||
|
|
@ -1,12 +1,15 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class ChecklistEntry < ApplicationRecord
|
||||
belongs_to :checklist
|
||||
belongs_to :check
|
||||
|
||||
before_validation :set_position
|
||||
after_validation :normalize_positions
|
||||
before_create :update_positions
|
||||
before_update :update_positions, if: :position_changed?
|
||||
|
||||
def set_position
|
||||
self.position ||= checklist.checklist_entries.maximum(:position).to_i + 1
|
||||
self.position ||= (checklist.checklist_entries.pluck(:position).max || 0) + 1
|
||||
end
|
||||
|
||||
def normalize_positions
|
||||
|
|
@ -15,4 +18,11 @@ class ChecklistEntry < ApplicationRecord
|
|||
# entry.update_column(:position, index + 1) if entry.position != index + 1
|
||||
# end
|
||||
end
|
||||
|
||||
def update_positions
|
||||
if position_was
|
||||
checklist.checklist_entries.where("position > ?", position_was).update_all("position = position - 1")
|
||||
end
|
||||
checklist.checklist_entries.where(position: position..).update_all("position = position + 1")
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module RichTextTargetBlank
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
|
|
@ -11,7 +13,7 @@ module RichTextTargetBlank
|
|||
rich_text_attribute = send(name)
|
||||
if rich_text_attribute.present?
|
||||
doc = Nokogiri::HTML::DocumentFragment.parse(rich_text_attribute.body.to_html)
|
||||
doc.css('a').each { |a| a['target'] ||= '_blank' }
|
||||
doc.css("a").each { |a| a["target"] ||= "_blank" }
|
||||
rich_text_attribute.body = doc.to_html
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Element < ApplicationRecord
|
||||
attr_accessor :checklist_id
|
||||
|
||||
|
|
@ -22,8 +24,8 @@ class Element < ApplicationRecord
|
|||
|
||||
return nil if possible_levels.empty?
|
||||
|
||||
puts possible_levels.inspect
|
||||
puts min_failed
|
||||
Rails.logger.debug possible_levels.inspect
|
||||
Rails.logger.debug min_failed
|
||||
possible_levels[possible_levels.find_index(min_failed) - 1]
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,11 @@
|
|||
require 'net/http'
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "net/http"
|
||||
|
||||
class Link < ApplicationRecord
|
||||
belongs_to :link_category
|
||||
has_and_belongs_to_many :checks
|
||||
|
||||
has_rich_text :description_html
|
||||
|
||||
validates :url, :text, presence: true
|
||||
|
|
@ -10,13 +14,21 @@ class Link < ApplicationRecord
|
|||
|
||||
before_validation :ensure_absolute_url
|
||||
|
||||
def t_text
|
||||
text
|
||||
end
|
||||
|
||||
def ok?
|
||||
fail_count == 0
|
||||
fail_count.zero?
|
||||
end
|
||||
|
||||
def to_s
|
||||
"#{text} (#{url})"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
USER_AGENT = 'Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0'
|
||||
USER_AGENT = "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0"
|
||||
|
||||
def check_url(input = url, add_error = true)
|
||||
response = begin
|
||||
|
|
|
|||
|
|
@ -1,5 +1,11 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class LinkCategory < ApplicationRecord
|
||||
has_many :links
|
||||
|
||||
has_rich_text :description_html
|
||||
|
||||
has_rich_text :description
|
||||
|
||||
def t_name
|
||||
name
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module PdfDocuments
|
||||
class Base
|
||||
attr_reader :params
|
||||
|
|
@ -11,7 +13,7 @@ module PdfDocuments
|
|||
# exta_bold: 'vendor/assets/fonts/Lexend-ExtraBold.ttf',
|
||||
# italic: 'vendor/assets/fonts/Lexend-Regular.ttf'
|
||||
# })
|
||||
@prawn_document.font 'Helvetica', size: 12
|
||||
@prawn_document.font "Helvetica", size: 12
|
||||
@params = OpenStruct.new(params)
|
||||
end
|
||||
|
||||
|
|
@ -47,7 +49,7 @@ module PdfDocuments
|
|||
end
|
||||
|
||||
def hr
|
||||
@prawn_document.markup '<hr>'
|
||||
@prawn_document.markup "<hr>"
|
||||
end
|
||||
|
||||
def markup_options
|
||||
|
|
@ -63,12 +65,12 @@ module PdfDocuments
|
|||
end
|
||||
|
||||
def logo
|
||||
@prawn_document.image 'app/assets/images/logo-apfelschule.png', width: 150
|
||||
@prawn_document.image "app/assets/images/logo-apfelschule.png", width: 150
|
||||
@prawn_document.move_down 30
|
||||
end
|
||||
|
||||
def prepare_rich_text(rich_text)
|
||||
{ h1: 'h4' }.each do |tag, replacement|
|
||||
{ h1: "h4" }.each do |tag, replacement|
|
||||
rich_text = rich_text.to_s.gsub("<#{tag}", "<#{replacement}")
|
||||
rich_text = rich_text.to_s.gsub("</#{tag}>", "</#{replacement}>")
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,19 +1,21 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module PdfDocuments
|
||||
class CustomerReport < Base
|
||||
private
|
||||
|
||||
def generate
|
||||
logo
|
||||
@prawn_document.formatted_text_box [{
|
||||
@prawn_document.formatted_text_box [ {
|
||||
text: "Dieses Dokument wurd am #{Time.current.strftime('%d %B %Y')} um #{Time.current.strftime('%H:%M:%S')} erstellt.", size: 8, align: :right
|
||||
}], align: :right
|
||||
} ], align: :right
|
||||
|
||||
heading1 params.report.name
|
||||
rich_text params.report.comment_html
|
||||
|
||||
params.report.elements.each.with_index(1) do |element, element_index|
|
||||
heading2 "#{element_index} #{element.title}"
|
||||
formatted_text [{ text: element.path, styles: %i[bold italic underline] }]
|
||||
formatted_text [ { text: element.path, styles: %i[bold italic underline] } ]
|
||||
move_down(5)
|
||||
rich_text element.description_html
|
||||
|
||||
|
|
|
|||
3
app/models/principle.rb
Normal file
3
app/models/principle.rb
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
class Principle < ApplicationRecord
|
||||
translates_attribute :name
|
||||
end
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Report < ApplicationRecord
|
||||
has_rich_text :comment_html
|
||||
|
||||
|
|
|
|||
5
app/models/standard.rb
Normal file
5
app/models/standard.rb
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
class Standard < ApplicationRecord
|
||||
has_and_belongs_to_many :checks
|
||||
|
||||
translates_attribute :name
|
||||
end
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class SuccessCriterion < ApplicationRecord
|
||||
enum :result, %i[passed failed not_applicable]
|
||||
enum :level, %i[A AA AAA]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue