From 909a7470534c1f5bcb71f31e845612daaed188b9 Mon Sep 17 00:00:00 2001 From: Ladislav Gallay Date: Sat, 7 Oct 2023 14:09:56 +0200 Subject: [PATCH] WIP: Add file upload to general agenda (add-general-agenda-app) --- app/assets/stylesheets/direct_upload.css | 37 ++++++++++ .../general_agenda_controller.rb | 4 +- app/helpers/application_helper.rb | 6 ++ .../general_agenda/application_form.rb | 21 ++++++ .../general_agenda/index.html.erb | 70 +++++++++++++++++++ .../general_agenda/invalid_template.html.erb | 14 ++++ 6 files changed, 151 insertions(+), 1 deletion(-) create mode 100644 app/assets/stylesheets/direct_upload.css create mode 100644 app/views/apps/general_agenda_app/general_agenda/invalid_template.html.erb diff --git a/app/assets/stylesheets/direct_upload.css b/app/assets/stylesheets/direct_upload.css new file mode 100644 index 00000000..d314bdf7 --- /dev/null +++ b/app/assets/stylesheets/direct_upload.css @@ -0,0 +1,37 @@ +.direct-upload { + display: inline-block; + position: relative; + padding: 2px 4px; + margin: 0 3px 3px 0; + border: 1px solid rgba(0, 0, 0, 0.3); + border-radius: 3px; + font-size: 11px; + line-height: 13px; +} + +.direct-upload--pending { + opacity: 0.6; +} + +.direct-upload__progress { + position: absolute; + top: 0; + left: 0; + bottom: 0; + opacity: 0.2; + background: #0076ff; + transition: width 120ms ease-out, opacity 60ms 60ms ease-in; + transform: translate3d(0, 0, 0); +} + +.direct-upload--complete .direct-upload__progress { + opacity: 0.4; +} + +.direct-upload--error { + border-color: red; +} + +input[type=file][data-direct-upload-url][disabled] { + display: none; +} diff --git a/app/controllers/apps/general_agenda_app/general_agenda_controller.rb b/app/controllers/apps/general_agenda_app/general_agenda_controller.rb index 0a4d466d..c997b966 100644 --- a/app/controllers/apps/general_agenda_app/general_agenda_controller.rb +++ b/app/controllers/apps/general_agenda_app/general_agenda_controller.rb @@ -10,11 +10,13 @@ def index text: params[:text_placeholder], signed_required: params[:signed_required], text_hint: params[:text_hint], - attachments_template: params[:attachments], + attachments_template: params[:attachments] || [{name: 'Subor 1', description: 'Popis suboru 1', signed_required: '1'},{name: 'Subor 2', description: 'Popis suboru 1', signed_required: '0'}], }.merge(general_agenda_params || {}) @application_form = Apps::GeneralAgendaApp::GeneralAgenda::ApplicationForm.new(attributes) + return render :invalid_template unless @application_form.valid_template? + redirect_to_upvs_submission if @application_form.is_submitted && @application_form.valid? end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 76d78d9e..022e948c 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -18,4 +18,10 @@ def sanitize_description(description, length: 500) def dont_show_small_search_bar? current_page?(root_path) || current_page?(search_path) end + + def localize_boolean(value) + value.to_s.in?(['1', 'true']) ? 'Áno' : 'Nie' + end + + alias :lb :localize_boolean end diff --git a/app/models/apps/general_agenda_app/general_agenda/application_form.rb b/app/models/apps/general_agenda_app/general_agenda/application_form.rb index 8ce1ec2f..fb41511e 100644 --- a/app/models/apps/general_agenda_app/general_agenda/application_form.rb +++ b/app/models/apps/general_agenda_app/general_agenda/application_form.rb @@ -26,6 +26,27 @@ class ApplicationForm :is_submitted ) + def template_errors + @template_errors || [] + end + + def valid_template? + @template_errors = [] + + if attachments_template.present? && !attachments_template.is_a?(Array) + @template_errors << 'Premenná "attachments_template" musí byť pole súborov' + elsif attachments_template.is_a?(Array) + attachments_template.each_with_index do |attachment_template, index| + @template_errors << "Hodnota \"name\" pre #{index + 1} attachments_template musí byť povinne text" if attachment_template[:name].blank? || !attachment_template[:name].is_a?(String) + @template_errors << "Hodnota \"description\" pre #{index + 1} attachments_template má byť text" if attachment_template[:description].present? && !attachment_template[:description].is_a?(String) + @template_errors << "Hodnota \"required\" pre #{index + 1} attachments_template musí byť 1 alebo 0" unless attachment_template[:required].in?(['1', '0', nil]) + @template_errors << "Hodnota \"signed_required\" pre #{index + 1} attachments_template musí byť 1 alebo 0" unless attachment_template[:signed_required].in?(['1', '0', nil]) + end + end + + @template_errors.blank? + end + private def recipient_present? diff --git a/app/views/apps/general_agenda_app/general_agenda/index.html.erb b/app/views/apps/general_agenda_app/general_agenda/index.html.erb index dd41a851..acbeed80 100644 --- a/app/views/apps/general_agenda_app/general_agenda/index.html.erb +++ b/app/views/apps/general_agenda_app/general_agenda/index.html.erb @@ -49,6 +49,38 @@ + <% if @application_form.attachments_template.present? %> +

+ Prílohy +

+ + + + + + + + + + + + + + + + + <% end %> + +
Požadovaný súborPovinnýVyžaduje podpis?Príloha
+ <%= attachment_template[:name] %>
+ <%= attachment_template[:description] %> +
<%= lb attachment_template[:required] %><%= lb attachment_template[:signed_required] %> + <%= %> +
+ <% end %> +

Používaním tejto služby súhlasíte so spracovaním osobných údajov v rozsahu nevyhnutnom na odoslanie podania. Vaše údaje neukladáme, sú použité výlučne na vyplnenie podania.