A lot :)
This commit is contained in:
parent
aad67af0d1
commit
63fc206c27
153 changed files with 2043 additions and 646 deletions
|
|
@ -1,8 +1,10 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Admin
|
||||
class BackupsController < ApplicationController
|
||||
# GET /admin/backups/1
|
||||
def show
|
||||
send_file Backup.db_xlsx, filename: 'backup.xlsx', disposition: :attachment
|
||||
send_file Backup.db_xlsx, filename: "backup.xlsx", disposition: :attachment
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,20 +3,24 @@
|
|||
class ApplicationController < ActionController::Base
|
||||
include Pagy::Backend
|
||||
|
||||
# allow_browser versions: :modern
|
||||
|
||||
before_action :initialize_navbar
|
||||
|
||||
private
|
||||
|
||||
def initialize_navbar
|
||||
@nav_path = controller_name
|
||||
return unless request.get?
|
||||
|
||||
@navbar_items = [
|
||||
{ label: 'Dashboard', icon: :speedometer2, path: :root },
|
||||
{ label: Report.model_name.human(count: 2), icon: :'journal-text', path: :reports },
|
||||
{ label: Checklist.model_name.human(count: 2), icon: :'list-check', path: :checklists },
|
||||
{ label: Check.model_name.human(count: 2), icon: :check2, path: :checks },
|
||||
{ label: Link.model_name.human(count: 2), icon: :link, path: :links },
|
||||
{ label: LinkCategory.model_name.human(count: 2), icon: :"folder", path: :link_categories }
|
||||
{ label: "Dashboard", icon: :speedometer2, path: :root },
|
||||
{ label: Report.model_name.human(count: 2), icon: :'journal-text', path: :reports },
|
||||
{ label: Checklist.model_name.human(count: 2), icon: :'list-check', path: :checklists },
|
||||
{ label: Check.model_name.human(count: 2), icon: :check2, path: :checks },
|
||||
{ label: Link.model_name.human(count: 2), icon: :link, path: :links },
|
||||
{ label: LinkCategory.model_name.human(count: 2), icon: :folder, path: :link_categories }
|
||||
]
|
||||
@search_url = nil # root_url
|
||||
@nav_path = controller_name
|
||||
@search_url = nil
|
||||
end
|
||||
end
|
||||
|
|
|
|||
213
app/controllers/benchmarking_controller.rb
Normal file
213
app/controllers/benchmarking_controller.rb
Normal file
|
|
@ -0,0 +1,213 @@
|
|||
class BenchmarkingController < ApplicationController
|
||||
protect_from_forgery with: :null_session
|
||||
before_action :set_user_update_last_seen_at
|
||||
|
||||
# POST /benchmarking/read_heavy
|
||||
def read_heavy
|
||||
act_and_respond(
|
||||
link_create: 0.1,
|
||||
link_destroy: 0.1,
|
||||
link_show: 0.4,
|
||||
links_index: 0.4,
|
||||
)
|
||||
end
|
||||
|
||||
# POST /benchmarking/write_heavy
|
||||
def write_heavy
|
||||
act_and_respond(
|
||||
link_create: 0.4,
|
||||
link_destroy: 0.4,
|
||||
link_show: 0.1,
|
||||
links_index: 0.1,
|
||||
)
|
||||
end
|
||||
|
||||
# POST /benchmarking/balanced
|
||||
def balanced
|
||||
act_and_respond(
|
||||
link_create: 0.25,
|
||||
link_destroy: 0.25,
|
||||
link_show: 0.25,
|
||||
links_index: 0.25,
|
||||
)
|
||||
end
|
||||
|
||||
def link_create
|
||||
link = LinkCategory.create!(name: "Benchmark #{request.uuid}", description_html: "<pre>#{format(request:)}</pre>")
|
||||
redirect_to link
|
||||
end
|
||||
|
||||
def link_destroy
|
||||
link = LinkCategory.where("id >= ?", rand(LinkCategory.minimum(:id)..LinkCategory.maximum(:id))).limit(1).first
|
||||
link.destroy!
|
||||
redirect_to links_path
|
||||
end
|
||||
|
||||
def link_show
|
||||
@link_category = LinkCategory.where("id >= ?", rand(LinkCategory.minimum(:id)..LinkCategory.maximum(:id))).limit(1).first
|
||||
render "link_categories/show", status: :ok
|
||||
end
|
||||
|
||||
def links_index
|
||||
@link_categories = LinkCategory.where("id >= ?", rand(LinkCategory.minimum(:id)..LinkCategory.maximum(:id))).limit(100)
|
||||
render "link_categories/index", status: :ok
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_user_update_last_seen_at
|
||||
# @user = User.where("id >= ?", rand(User.minimum(:id)..User.maximum(:id))).limit(1).first
|
||||
# @user.update!(last_seen_at: Time.now)
|
||||
end
|
||||
|
||||
def act_and_respond(actions_with_weighted_distribution)
|
||||
action = actions_with_weighted_distribution.max_by { |_, weight| rand ** (1.0 / weight) }.first
|
||||
|
||||
send(action)
|
||||
end
|
||||
|
||||
def format(request:)
|
||||
request.headers.to_h.slice(
|
||||
"GATEWAY_INTERFACE",
|
||||
"HTTP_ACCEPT",
|
||||
"HTTP_HOST",
|
||||
"HTTP_USER_AGENT",
|
||||
"HTTP_VERSION",
|
||||
"ORIGINAL_FULLPATH",
|
||||
"ORIGINAL_SCRIPT_NAME",
|
||||
"PATH_INFO",
|
||||
"QUERY_STRING",
|
||||
"REMOTE_ADDR",
|
||||
"REQUEST_METHOD",
|
||||
"REQUEST_PATH",
|
||||
"REQUEST_URI",
|
||||
"SCRIPT_NAME",
|
||||
"SERVER_NAME",
|
||||
"SERVER_PORT",
|
||||
"SERVER_PROTOCOL",
|
||||
"SERVER_SOFTWARE",
|
||||
"action_dispatch.request_id",
|
||||
"puma.request_body_wait",
|
||||
).map { _1.join(": ") }.join("\n")
|
||||
end
|
||||
end
|
||||
|
||||
# class BenchmarkingController < ApplicationController
|
||||
# skip_before_action :verify_authenticity_token
|
||||
# skip_before_action :ensure_user_authenticated!
|
||||
# before_action :set_user_update_last_seen_at
|
||||
|
||||
# # POST /benchmarking/read_heavy
|
||||
# def read_heavy
|
||||
# act_and_respond(
|
||||
# link_create: 0.10,
|
||||
# comment_create: 0.10,
|
||||
# post_destroy: 0.02,
|
||||
# comment_destroy: 0.03,
|
||||
# post_show: 0.25,
|
||||
# posts_index: 0.25,
|
||||
# user_show: 0.25,
|
||||
# )
|
||||
# end
|
||||
|
||||
# # POST /benchmarking/write_heavy
|
||||
# def write_heavy
|
||||
# act_and_respond(
|
||||
# link_create: 0.25,
|
||||
# comment_create: 0.25,
|
||||
# post_destroy: 0.05,
|
||||
# comment_destroy: 0.20,
|
||||
# post_show: 0.05,
|
||||
# posts_index: 0.15,
|
||||
# user_show: 0.05,
|
||||
# )
|
||||
# end
|
||||
|
||||
# # POST /benchmarking/balanced
|
||||
# def balanced
|
||||
# act_and_respond(
|
||||
# link_create: 0.17,
|
||||
# comment_create: 0.17,
|
||||
# post_destroy: 0.05,
|
||||
# comment_destroy: 0.11,
|
||||
# post_show: 0.17,
|
||||
# posts_index: 0.17,
|
||||
# user_show: 0.16,
|
||||
# )
|
||||
# end
|
||||
|
||||
# def link_create
|
||||
# post = Post.create!(user: @user, title: "Post #{request.uuid}", description: format(request:))
|
||||
# redirect_to post
|
||||
# end
|
||||
|
||||
# def comment_create
|
||||
# post = Post.where("id >= ?", rand(Post.minimum(:id)..Post.maximum(:id))).limit(1).first
|
||||
# comment = Comment.create!(user: @user, post: post, body: "Comment #{request.uuid}")
|
||||
# redirect_to comment.post
|
||||
# end
|
||||
|
||||
# def post_destroy
|
||||
# post = Post.where("id >= ?", rand(Post.minimum(:id)..Post.maximum(:id))).limit(1).first
|
||||
# post.destroy!
|
||||
# redirect_to posts_path
|
||||
# end
|
||||
|
||||
# def comment_destroy
|
||||
# comment = Comment.where("id >= ?", rand(Comment.minimum(:id)..Comment.maximum(:id))).limit(1).first
|
||||
# comment.destroy!
|
||||
# redirect_to comment.post
|
||||
# end
|
||||
|
||||
# def post_show
|
||||
# @post = Post.where("id >= ?", rand(Post.minimum(:id)..Post.maximum(:id))).limit(1).first
|
||||
# render "posts/show", status: :ok
|
||||
# end
|
||||
|
||||
# def posts_index
|
||||
# @posts = Post.where("id >= ?", rand(Post.minimum(:id)..Post.maximum(:id))).limit(100)
|
||||
# render "posts/index", status: :ok
|
||||
# end
|
||||
|
||||
# def user_show
|
||||
# render "users/show", status: :ok
|
||||
# end
|
||||
|
||||
# private
|
||||
|
||||
# def set_user_update_last_seen_at
|
||||
# @user = User.where("id >= ?", rand(User.minimum(:id)..User.maximum(:id))).limit(1).first
|
||||
# @user.update!(last_seen_at: Time.now)
|
||||
# end
|
||||
|
||||
# def act_and_respond(actions_with_weighted_distribution)
|
||||
# action = actions_with_weighted_distribution.max_by { |_, weight| rand ** (1.0 / weight) }.first
|
||||
|
||||
# send(action)
|
||||
# end
|
||||
|
||||
# def format(request:)
|
||||
# request.headers.to_h.slice(
|
||||
# "GATEWAY_INTERFACE",
|
||||
# "HTTP_ACCEPT",
|
||||
# "HTTP_HOST",
|
||||
# "HTTP_USER_AGENT",
|
||||
# "HTTP_VERSION",
|
||||
# "ORIGINAL_FULLPATH",
|
||||
# "ORIGINAL_SCRIPT_NAME",
|
||||
# "PATH_INFO",
|
||||
# "QUERY_STRING",
|
||||
# "REMOTE_ADDR",
|
||||
# "REQUEST_METHOD",
|
||||
# "REQUEST_PATH",
|
||||
# "REQUEST_URI",
|
||||
# "SCRIPT_NAME",
|
||||
# "SERVER_NAME",
|
||||
# "SERVER_PORT",
|
||||
# "SERVER_PROTOCOL",
|
||||
# "SERVER_SOFTWARE",
|
||||
# "action_dispatch.request_id",
|
||||
# "puma.request_body_wait",
|
||||
# ).map { _1.join(": ") }.join("\n")
|
||||
# end
|
||||
# end
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class ChecklistEntriesController < ApplicationController
|
||||
before_action :set_checklist_entry, only: %i[show edit update destroy]
|
||||
|
||||
|
|
@ -7,8 +9,7 @@ class ChecklistEntriesController < ApplicationController
|
|||
end
|
||||
|
||||
# GET /checklist_entries/1
|
||||
def show
|
||||
end
|
||||
def show; end
|
||||
|
||||
# GET /checklist_entries/new
|
||||
def new
|
||||
|
|
@ -16,15 +17,14 @@ class ChecklistEntriesController < ApplicationController
|
|||
end
|
||||
|
||||
# GET /checklist_entries/1/edit
|
||||
def edit
|
||||
end
|
||||
def edit; end
|
||||
|
||||
# POST /checklist_entries
|
||||
def create
|
||||
@checklist_entry = ChecklistEntry.new(checklist_entry_params)
|
||||
|
||||
if @checklist_entry.save
|
||||
redirect_to @checklist_entry.checklist, notice: 'Checklist entry was successfully created.'
|
||||
redirect_to @checklist_entry.checklist, notice: "Checklist entry was successfully created."
|
||||
else
|
||||
render :new, status: :unprocessable_entity
|
||||
end
|
||||
|
|
@ -33,7 +33,7 @@ class ChecklistEntriesController < ApplicationController
|
|||
# PATCH/PUT /checklist_entries/1
|
||||
def update
|
||||
if @checklist_entry.update(checklist_entry_params)
|
||||
redirect_to @checklist_entry.checklist, notice: 'Checklist entry was successfully updated.',
|
||||
redirect_to @checklist_entry.checklist, notice: "Checklist entry was successfully updated.",
|
||||
status: :see_other
|
||||
else
|
||||
render :edit, status: :unprocessable_entity
|
||||
|
|
@ -45,7 +45,7 @@ class ChecklistEntriesController < ApplicationController
|
|||
@checklist_entry.destroy!
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
redirect_to checklist_entries_url, notice: 'Checklist entry was successfully destroyed.', status: :see_other
|
||||
redirect_to checklist_entries_url, notice: "Checklist entry was successfully destroyed.", status: :see_other
|
||||
end
|
||||
format.turbo_stream
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class ChecklistsController < ApplicationController
|
||||
before_action :set_checklist, only: %i[show edit update destroy]
|
||||
|
||||
|
|
@ -7,8 +9,7 @@ class ChecklistsController < ApplicationController
|
|||
end
|
||||
|
||||
# GET /checklists/1
|
||||
def show
|
||||
end
|
||||
def show; end
|
||||
|
||||
# GET /checklists/new
|
||||
def new
|
||||
|
|
@ -16,15 +17,14 @@ class ChecklistsController < ApplicationController
|
|||
end
|
||||
|
||||
# GET /checklists/1/edit
|
||||
def edit
|
||||
end
|
||||
def edit; end
|
||||
|
||||
# POST /checklists
|
||||
def create
|
||||
@checklist = Checklist.new(checklist_params)
|
||||
|
||||
if @checklist.save
|
||||
redirect_to @checklist, notice: 'Checklist was successfully created.'
|
||||
redirect_to @checklist, notice: "Checklist was successfully created."
|
||||
else
|
||||
render :new, status: :unprocessable_entity
|
||||
end
|
||||
|
|
@ -33,7 +33,7 @@ class ChecklistsController < ApplicationController
|
|||
# PATCH/PUT /checklists/1
|
||||
def update
|
||||
if @checklist.update(checklist_params)
|
||||
redirect_to @checklist, notice: 'Checklist was successfully updated.', status: :see_other
|
||||
redirect_to @checklist, notice: "Checklist was successfully updated.", status: :see_other
|
||||
else
|
||||
render :edit, status: :unprocessable_entity
|
||||
end
|
||||
|
|
@ -42,7 +42,7 @@ class ChecklistsController < ApplicationController
|
|||
# DELETE /checklists/1
|
||||
def destroy
|
||||
@checklist.destroy!
|
||||
redirect_to checklists_url, notice: 'Checklist was successfully destroyed.', status: :see_other
|
||||
redirect_to checklists_url, notice: "Checklist was successfully destroyed.", status: :see_other
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
|||
|
|
@ -1,14 +1,19 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class ChecksController < ApplicationController
|
||||
before_action :set_check, only: %i[show edit update destroy]
|
||||
|
||||
# GET /checks or /checks.json
|
||||
def index
|
||||
@pagy, @checks = pagy(Check.search(filter_params[:s]))
|
||||
@pagy, @checks = if filter_params[:s]
|
||||
pagy(Check.search(filter_params[:s]).order(:conformity_level))
|
||||
else
|
||||
pagy(Check.all.order(:conformity_level))
|
||||
end
|
||||
end
|
||||
|
||||
# GET /checks/1 or /checks/1.json
|
||||
def show
|
||||
end
|
||||
def show; end
|
||||
|
||||
# GET /checks/new
|
||||
def new
|
||||
|
|
@ -16,8 +21,7 @@ class ChecksController < ApplicationController
|
|||
end
|
||||
|
||||
# GET /checks/1/edit
|
||||
def edit
|
||||
end
|
||||
def edit; end
|
||||
|
||||
# POST /checks or /checks.json
|
||||
def create
|
||||
|
|
@ -27,11 +31,11 @@ class ChecksController < ApplicationController
|
|||
if @check.save
|
||||
format.html do
|
||||
redirect_to check_url(@check),
|
||||
notice: t('scaffold.model_created_successfully', model: @check.model_name.human)
|
||||
notice: t("scaffold.model_created_successfully", model: @check.model_name.human)
|
||||
end
|
||||
format.json { render :show, status: :created, location: @check }
|
||||
else
|
||||
flash[:alert] = t('there_were_errors', count: @check.errors.size)
|
||||
flash[:alert] = t("there_were_errors", count: @check.errors.size)
|
||||
format.html { render :new, status: :unprocessable_entity }
|
||||
format.json { render json: @check.errors, status: :unprocessable_entity }
|
||||
end
|
||||
|
|
@ -44,7 +48,7 @@ class ChecksController < ApplicationController
|
|||
if @check.update(check_params)
|
||||
format.html do
|
||||
redirect_to check_url(@check),
|
||||
notice: t('scaffold.model_updated_successfully', model: @check.model_name.human)
|
||||
notice: t("scaffold.model_updated_successfully", model: @check.model_name.human)
|
||||
end
|
||||
format.json { render :show, status: :ok, location: @check }
|
||||
else
|
||||
|
|
@ -60,7 +64,7 @@ class ChecksController < ApplicationController
|
|||
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
redirect_to checks_url, notice: t('scaffold.model_destroyed_successfully', model: @check.model_name.human)
|
||||
redirect_to checks_url, notice: t("scaffold.model_destroyed_successfully", model: @check.model_name.human)
|
||||
end
|
||||
format.json { head :no_content }
|
||||
end
|
||||
|
|
@ -79,6 +83,43 @@ class ChecksController < ApplicationController
|
|||
|
||||
# Only allow a list of trusted parameters through.
|
||||
def check_params
|
||||
params.require(:check).permit(:position, :name, :success_criterion, :success_criterion_html, :level)
|
||||
params.require(:check).permit(:principle_id,
|
||||
:number,
|
||||
:name_de,
|
||||
:name_en,
|
||||
:standard_id,
|
||||
:visual,
|
||||
:auditory,
|
||||
:physical,
|
||||
:cognitive,
|
||||
:applicable_to_app,
|
||||
:applicable_to_web,
|
||||
:external_number,
|
||||
:conformity_level,
|
||||
:conformity_notice_de,
|
||||
:conformity_notice_en,
|
||||
:priority,
|
||||
:quick_criterion_de,
|
||||
:quick_criterion_en,
|
||||
:quick_fail_de,
|
||||
:quick_fail_en,
|
||||
:quick_fix_de,
|
||||
:quick_fix_en,
|
||||
:criterion_de,
|
||||
:criterion_en,
|
||||
:criterion_details_de,
|
||||
:criterion_details_en,
|
||||
:example_de,
|
||||
:example_en,
|
||||
:exemption_details_de,
|
||||
:exemption_details_en,
|
||||
:standard_text_de,
|
||||
:standard_text_en,
|
||||
:test_instructions,
|
||||
:powerpoint_text_de,
|
||||
:powerpoint_text_en,
|
||||
:comment,
|
||||
link_ids: [],
|
||||
standard_ids: [])
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class ElementsController < ApplicationController
|
||||
before_action :set_element, only: %i[show edit update destroy]
|
||||
|
||||
|
|
@ -7,8 +9,7 @@ class ElementsController < ApplicationController
|
|||
end
|
||||
|
||||
# GET /elements/1
|
||||
def show
|
||||
end
|
||||
def show; end
|
||||
|
||||
# GET /elements/new
|
||||
def new
|
||||
|
|
@ -16,8 +17,7 @@ class ElementsController < ApplicationController
|
|||
end
|
||||
|
||||
# GET /elements/1/edit
|
||||
def edit
|
||||
end
|
||||
def edit; end
|
||||
|
||||
# POST /elements
|
||||
def create
|
||||
|
|
@ -28,11 +28,11 @@ class ElementsController < ApplicationController
|
|||
|
||||
if @element.save
|
||||
checklist.checks.each do |check|
|
||||
@element.success_criteria.create!(title: check.name, description_html: check.success_criterion_html,
|
||||
@element.success_criteria.create!(title: check.t_name, description_html: check.t_criterion,
|
||||
level: check.level)
|
||||
end
|
||||
respond_to do |format|
|
||||
format.html { redirect_to @element.report, notice: 'Element was successfully created.' }
|
||||
format.html { redirect_to @element.report, notice: "Element was successfully created." }
|
||||
format.turbo_stream
|
||||
end
|
||||
else
|
||||
|
|
@ -43,7 +43,7 @@ class ElementsController < ApplicationController
|
|||
# PATCH/PUT /elements/1
|
||||
def update
|
||||
if @element.update(element_params)
|
||||
redirect_to @element, notice: 'Element was successfully updated.', status: :see_other
|
||||
redirect_to @element, notice: "Element was successfully updated.", status: :see_other
|
||||
else
|
||||
render :edit, status: :unprocessable_entity
|
||||
end
|
||||
|
|
@ -52,7 +52,7 @@ class ElementsController < ApplicationController
|
|||
# DELETE /elements/1
|
||||
def destroy
|
||||
@element.destroy!
|
||||
redirect_to elements_url, notice: 'Element was successfully destroyed.', status: :see_other
|
||||
redirect_to elements_url, notice: "Element was successfully destroyed.", status: :see_other
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class HomeController < ApplicationController
|
||||
def show; end
|
||||
def show
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class LinkCategoriesController < ApplicationController
|
||||
before_action :set_link_category, only: %i[ show edit update destroy ]
|
||||
before_action :set_link_category, only: %i[show edit update destroy]
|
||||
|
||||
# GET /link_categories
|
||||
def index
|
||||
|
|
@ -7,8 +9,7 @@ class LinkCategoriesController < ApplicationController
|
|||
end
|
||||
|
||||
# GET /link_categories/1
|
||||
def show
|
||||
end
|
||||
def show; end
|
||||
|
||||
# GET /link_categories/new
|
||||
def new
|
||||
|
|
@ -16,8 +17,7 @@ class LinkCategoriesController < ApplicationController
|
|||
end
|
||||
|
||||
# GET /link_categories/1/edit
|
||||
def edit
|
||||
end
|
||||
def edit; end
|
||||
|
||||
# POST /link_categories
|
||||
def create
|
||||
|
|
@ -46,13 +46,14 @@ class LinkCategoriesController < ApplicationController
|
|||
end
|
||||
|
||||
private
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_link_category
|
||||
@link_category = LinkCategory.find(params[:id])
|
||||
end
|
||||
|
||||
# Only allow a list of trusted parameters through.
|
||||
def link_category_params
|
||||
params.require(:link_category).permit(:name, :description, :rich_text)
|
||||
end
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_link_category
|
||||
@link_category = LinkCategory.find(params[:id])
|
||||
end
|
||||
|
||||
# Only allow a list of trusted parameters through.
|
||||
def link_category_params
|
||||
params.require(:link_category).permit(:name, :description, :rich_text)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class LinksController < ApplicationController
|
||||
before_action :set_link, only: %i[show edit update destroy]
|
||||
|
||||
|
|
@ -7,8 +9,7 @@ class LinksController < ApplicationController
|
|||
end
|
||||
|
||||
# GET /links/1
|
||||
def show
|
||||
end
|
||||
def show; end
|
||||
|
||||
# GET /links/new
|
||||
def new
|
||||
|
|
@ -16,15 +17,14 @@ class LinksController < ApplicationController
|
|||
end
|
||||
|
||||
# GET /links/1/edit
|
||||
def edit
|
||||
end
|
||||
def edit; end
|
||||
|
||||
# POST /links
|
||||
def create
|
||||
@link = Link.new(link_params)
|
||||
|
||||
if @link.save
|
||||
redirect_to @link, notice: 'Link was successfully created.'
|
||||
redirect_to @link, notice: "Link was successfully created."
|
||||
else
|
||||
render :new, status: :unprocessable_entity
|
||||
end
|
||||
|
|
@ -33,7 +33,7 @@ class LinksController < ApplicationController
|
|||
# PATCH/PUT /links/1
|
||||
def update
|
||||
if @link.update(link_params)
|
||||
redirect_to @link, notice: 'Link was successfully updated.', status: :see_other
|
||||
redirect_to @link, notice: "Link was successfully updated.", status: :see_other
|
||||
else
|
||||
render :edit, status: :unprocessable_entity
|
||||
end
|
||||
|
|
@ -42,7 +42,7 @@ class LinksController < ApplicationController
|
|||
# DELETE /links/1
|
||||
def destroy
|
||||
@link.destroy!
|
||||
redirect_to links_url, notice: 'Link was successfully destroyed.', status: :see_other
|
||||
redirect_to links_url, notice: "Link was successfully destroyed.", status: :see_other
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class SuccessCriteriaController < ApplicationController
|
||||
before_action :set_success_criterion, only: %i[show edit update destroy]
|
||||
|
||||
|
|
@ -7,8 +9,7 @@ class SuccessCriteriaController < ApplicationController
|
|||
end
|
||||
|
||||
# GET /success_criteria/1
|
||||
def show
|
||||
end
|
||||
def show; end
|
||||
|
||||
# GET /success_criteria/new
|
||||
def new
|
||||
|
|
@ -16,15 +17,14 @@ class SuccessCriteriaController < ApplicationController
|
|||
end
|
||||
|
||||
# GET /success_criteria/1/edit
|
||||
def edit
|
||||
end
|
||||
def edit; end
|
||||
|
||||
# POST /success_criteria
|
||||
def create
|
||||
@success_criterion = SuccessCriterion.new(success_criterion_params)
|
||||
|
||||
if @success_criterion.save
|
||||
redirect_to @success_criterion, notice: 'Erfolgskriterium was successfully created.'
|
||||
redirect_to @success_criterion, notice: "Erfolgskriterium was successfully created."
|
||||
else
|
||||
render :new, status: :unprocessable_entity
|
||||
end
|
||||
|
|
@ -33,7 +33,7 @@ class SuccessCriteriaController < ApplicationController
|
|||
# PATCH/PUT /success_criteria/1
|
||||
def update
|
||||
if @success_criterion.update(success_criterion_params)
|
||||
redirect_to @success_criterion, notice: 'Erfolgskriterium was successfully updated.', status: :see_other
|
||||
redirect_to @success_criterion, notice: "Erfolgskriterium was successfully updated.", status: :see_other
|
||||
else
|
||||
render :edit, status: :unprocessable_entity
|
||||
end
|
||||
|
|
@ -44,7 +44,7 @@ class SuccessCriteriaController < ApplicationController
|
|||
@success_criterion.destroy!
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
redirect_to success_criteria_url, notice: 'Erfolgskriterium was successfully destroyed.', status: :see_other
|
||||
redirect_to success_criteria_url, notice: "Erfolgskriterium was successfully destroyed.", status: :see_other
|
||||
end
|
||||
format.turbo_stream
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue