Skip to content

Commit

Permalink
WIP: Add file upload to general agenda (add-general-agenda-app)
Browse files Browse the repository at this point in the history
  • Loading branch information
Laykou committed Oct 7, 2023
1 parent 9cc519e commit 909a747
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 1 deletion.
37 changes: 37 additions & 0 deletions app/assets/stylesheets/direct_upload.css
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
70 changes: 70 additions & 0 deletions app/views/apps/general_agenda_app/general_agenda/index.html.erb

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<%= render partial: 'header' %>

<div class="govuk-error-summary" aria-labelledby="error-summary-title" role="alert" tabindex="-1" data-module="govuk-error-summary">
<h2 class="govuk-error-summary__title" id="error-summary-title">
Tento formulár nie je možné zobraziť
</h2>
<div class="govuk-error-summary__body">
<ul class="govuk-list govuk-error-summary__list" data-turbolinks="false">
<% @application_form.template_errors.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
</div>

0 comments on commit 909a747

Please sign in to comment.