Skip to content

Commit

Permalink
Prezidentské voľby 2024 (#635)
Browse files Browse the repository at this point in the history
* add is number validation to vote app

* fix syntax

* fix: go back button (#622)

* added Go Back button to pages where missing
* fix: test in spec/features/apps/parliament_vote_app_spec.rb

* add ux tweaks and rewords based on ux recommendations

* add president_vote_app

* udpate date calculation in president vote app

* change president election app email addresses sheet

* disable birth number validation

* use checkboxes instead of radios on place selection

* update president app after testing

* minor wording update

* add minor text hint to place selection

* revert unwanted changes

* rm email client button from auth person send

* add tests and refactor a bit

* rm unused code

* magically fix parliament vote app tests

* make checkbox labels clickable

* fix conditionally revealing address option

---------

Co-authored-by: zuzana <zuza.har@gmail.com>
  • Loading branch information
celuchmarek and zuzana authored Feb 8, 2024
1 parent 4d9e19e commit 45eb0cc
Show file tree
Hide file tree
Showing 35 changed files with 1,548 additions and 31 deletions.
13 changes: 13 additions & 0 deletions app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,19 @@
margin-bottom: 0;
}

.light-button {
border: 2px solid #3a67e8;
color: #3a67e8;
background-color: inherit;
border-radius: 3px;
margin-bottom: 0;
}

.light-button:hover {
background-color: #3a67e8;
color: white;
}

.active-topic {
background-color: #F3F2F1;
padding: 20px 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
class Apps::PresidentVoteApp::ApplicationFormsController < ApplicationController
helper FormatDaysHelper
before_action :set_metadata, :check_inactive_president_application
before_action :disable_feedback, only: [:show, :delivery, :create]

def show
render_step('start')
end

def delivery
return render_self if request.post?
render_step('delivery')
end

def permanent_resident
return render_self if request.post?
render_step('permanent_resident')
end

def create
render_self
end

private def render_self
@application_form = Apps::PresidentVoteApp::ApplicationForm.new(form_params)
@application_form.run(self)
end

private def render_step(step)
@application_form = Apps::PresidentVoteApp::ApplicationForm.new(step: step)
render step
end

private def form_params
params.require(:apps_president_vote_app_application_form).permit(
:step,
:place_first_round,
:place_second_round,
:sk_citizen,
:delivery,
:full_name, :pin, :nationality, :maiden_name,
:authorized_person_full_name, :authorized_person_pin,
:street, :pobox, :municipality,
:same_delivery_address,
:delivery_street, :delivery_pobox, :delivery_municipality, :delivery_country,
:municipality_email,
:municipality_email_verified,
:permanent_resident,
:back
)
end

private def set_metadata
@metadata.og.title = 'Žiadosť o hlasovací preukaz'
@metadata.og.image = 'facebook_share_2020.png'
@metadata.og.description = 'Aj keď budete počas volieb mimo trvalého pobytu, voliť sa dá. Stačí požiadať.'
end

private def check_inactive_president_application
return if Apps::PresidentVoteApp::ApplicationForm.active?
return redirect_to apps_president_vote_app_application_forms_path if action_name != "show"
render 'inactive'
end
end
14 changes: 12 additions & 2 deletions app/helpers/format_days_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ def format_remaining_days(remaining_days)
"Dnes je posledný možný termín."
end
end
end


def format_remaining_days_count(remaining_days)
if remaining_days > 4
"#{remaining_days} dní"
elsif remaining_days > 1
"#{remaining_days} dni"
elsif remaining_days == 1
"1 deň"
elsif remaining_days == 0
"posledný deň"
end
end
end
43 changes: 40 additions & 3 deletions app/models/apps/parliament_vote_app/application_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class ApplicationForm
on: [:identity, :world_sk_permanent_resident, :world_abroad_permanent_resident, :authorized_person]
validates_presence_of :pin, message: 'Rodné číslo je povinná položka',
on: [:identity, :world_sk_permanent_resident, :world_abroad_permanent_resident, :authorized_person]
# validate :pin_is_ok, on: [:identity, :world_sk_permanent_resident, :world_abroad_permanent_resident, :authorized_person]
validates_presence_of :street, message: 'Zadajte ulicu alebo názov obce ak obec nemá ulice',
on: [:identity, :world_sk_permanent_resident, :authorized_person]
validates_presence_of :pobox, message: 'Zadajte poštové smerové čislo',
Expand Down Expand Up @@ -155,6 +156,33 @@ def world_sk_resident_email_body
)
end

private def pin_is_ok
return errors.add(:pin, 'Rodné číslo je pocinná položka') if pin.blank?

begin
pin.to_i
rescue ArgumentError
return errors.add(:pin, 'Rodné číslo obsahuje neplatné znaky')
end

pin = self.pin.gsub(%r{/}, '')
return errors.add(:pin, 'Rodné číslo nie je deliteľné číslom 11') if pin.length == 10 and pin.to_i % 11 != 0
return errors.add(:pin, 'Rodné číslo má nesprávnu dĺžku') if pin.length != 10 and pin.length != 9

case pin[2..3].to_i
when 0, 13..50, 63..99
return errors.add(:pin, 'Rodné číslo obsahuje neplatný mesiac')
end

month = pin[2..3].to_i % 50
year = pin[0..1].to_i + (pin[2..3].to_i > 12 ? 1900 : 2000)
begin
Date.new(year, month, pin[4..5].to_i)
rescue ArgumentError
errors.add(:pin, 'Rodné číslo obsahuje neplatný dátum')
end
end

def run(listener)
case step
when 'start'
Expand Down Expand Up @@ -192,7 +220,10 @@ def run(listener)
end

private def sk_citizen_step(listener)
if valid?(:sk_citizen)
if go_back?
self.step = 'start'
listener.render :start
elsif valid?(:sk_citizen)
case sk_citizen
when 'yes'
self.step = 'permanent_resident'
Expand All @@ -206,7 +237,10 @@ def run(listener)
end

private def permanent_resident_step(listener)
if valid?(:permanent_resident)
if go_back?
self.step = 'sk_citizen'
listener.render :sk_citizen
elsif valid?(:permanent_resident)
case permanent_resident
when 'yes'
self.step = 'place'
Expand Down Expand Up @@ -241,7 +275,10 @@ def run(listener)

# Home flow
private def delivery_step(listener)
if valid?(:delivery)
if go_back?
self.step = 'place'
listener.render :place
elsif valid?(:delivery)
case delivery
when 'post'
self.step = 'identity'
Expand Down
Loading

0 comments on commit 45eb0cc

Please sign in to comment.