Skip to content

Commit

Permalink
ui and things
Browse files Browse the repository at this point in the history
  • Loading branch information
baldarn committed Aug 28, 2024
1 parent 4eacdf8 commit 70b7981
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 96 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ Metrics/MethodLength:
- db/migrate/*

Metrics/AbcSize:
Max: 30
Max: 50
Exclude:
- db/migrate/*
10 changes: 5 additions & 5 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2024-08-24 12:47:20 UTC using RuboCop version 1.65.1.
# on 2024-08-24 12:55:00 UTC using RuboCop version 1.65.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 2
# Offense count: 3
# Configuration parameters: AllowedMethods, AllowedPatterns.
Metrics/CyclomaticComplexity:
Max: 11
Max: 13

# Offense count: 2
# Offense count: 3
# Configuration parameters: AllowedMethods, AllowedPatterns.
Metrics/PerceivedComplexity:
Max: 11
Max: 13

# Offense count: 2
# Configuration parameters: Include.
Expand Down
59 changes: 15 additions & 44 deletions app/models/member.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,20 @@ class Member < ApplicationRecord
:tax_code,
:municipality, presence: true

validates :first_parent_first_name,
:first_parent_last_name,
:first_parent_born_at,
:first_parent_born_in,
:first_parent_citizenship,
:first_parent_address,
:first_parent_postal_code,
:first_parent_email,
:first_parent_tax_code,
:first_parent_municipality, presence: true, if: -> { child? }

validates :email, format: { with: URI::MailTo::EMAIL_REGEXP }
validates :groups, length: { minimum: 1 }

validate :at_least_a_parent?, if: -> { born_at && born_at >= (Time.zone.today - 18.years) }

scope :with_expiring_medical_certificate,
-> { where(medical_certificate_expires_at: Time.zone.today.beginning_of_day..2.months.from_now) }

Expand All @@ -45,6 +54,10 @@ def full_name
"#{last_name} #{first_name}".capitalize
end

def child?
born_at ? born_at >= 18.years.ago : false
end

def status
return 'error' if statuses.find { |s| s == 'error' }
return 'warning' if statuses.find { |s| s == 'warning' }
Expand Down Expand Up @@ -79,46 +92,4 @@ def payments_status

'ok'
end

private

def at_least_a_parent?
return true if first_parent_present? || second_parent_present?

errors.add(:at_least_a_parent, 'add at least a parent')
end

def first_parent_present?
if first_parent_first_name.present? &&
first_parent_last_name.present? &&
first_parent_born_at.present? &&
first_parent_born_in.present? &&
first_parent_citizenship.present? &&
first_parent_address.present? &&
first_parent_postal_code.present? &&
first_parent_email.present? &&
first_parent_tax_code.present? &&
first_parent_municipality.present?
return true
end

false
end

def second_parent_present?
if second_parent_first_name.present? &&
second_parent_last_name.present? &&
second_parent_born_at.present? &&
second_parent_born_in.present? &&
second_parent_citizenship.present? &&
second_parent_address.present? &&
second_parent_postal_code.present? &&
second_parent_email.present? &&
second_parent_tax_code.present? &&
second_parent_municipality.present?
return true
end

false
end
end
34 changes: 17 additions & 17 deletions app/views/members/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</h3>
<%= f.input :first_name, wrapper_html: { class: 'col-sm-6' } %>
<%= f.input :last_name, wrapper_html: { class: 'col-sm-6' } %>
<%= f.input :born_at, start_year: Date.today.year - 90, end_year: Date.today.year - 5 %>
<%= f.input :born_at, include_blank: true, start_year: Date.today.year - 100, end_year: Date.today.year - 5 %>
<%= f.input :born_in %>
<%= f.input :tax_code %>
<%= f.input :citizenship, wrapper_html: { class: 'col-sm-6' } %>
Expand All @@ -17,24 +17,24 @@
<div class="accordion accordion-flush" id="parents">
<div class="accordion-item">
<h2 class="accordion-header">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#parent-1" aria-expanded="false" aria-controls="parent-1">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#parent-1" aria-expanded="<%= member.child? %>" aria-controls="parent-1">
<%= I18n.t('members.first_parent')%>
</button>
</h2>
<div id="parent-1" class="accordion-collapse collapse" data-bs-parent="#parents">
<div id="parent-1" class="accordion-collapse collapse <%= member.child? ? 'show' : '' %>" data-bs-parent="#parents">
<div class="accordion-body row">
<%= f.input :first_parent_first_name, wrapper_html: { class: 'col-sm-6' } %>
<%= f.input :first_parent_last_name, wrapper_html: { class: 'col-sm-6' } %>
<%= f.input :first_parent_born_at, start_year: Date.today.year - 90, end_year: Date.today.year - 5 %>
<%= f.input :first_parent_born_in %>
<%= f.input :first_parent_tax_code %>
<%= f.input :first_parent_citizenship, wrapper_html: { class: 'col-sm-6' } %>
<%= f.input :first_parent_address, wrapper_html: { class: 'col-sm-6' } %>
<%= f.input :first_parent_postal_code, wrapper_html: { class: 'col-sm-2' } %>
<%= f.input :first_parent_municipality, wrapper_html: { class: 'col-sm-8' } %>
<%= f.input :first_parent_province, wrapper_html: { class: 'col-sm-2' } %>
<%= f.input :first_parent_telephone, wrapper_html: { class: 'col-sm-6' } %>
<%= f.input :first_parent_email, wrapper_html: { class: 'col-sm-6' } %>
<%= f.input :first_parent_first_name, required: true, wrapper_html: { class: 'col-sm-6' } %>
<%= f.input :first_parent_last_name, required: true, wrapper_html: { class: 'col-sm-6' } %>
<%= f.input :first_parent_born_at, required: true, include_blank: true, start_year: Date.today.year - 100, end_year: Date.today.year - 18 %>
<%= f.input :first_parent_born_in, required: true %>
<%= f.input :first_parent_tax_code, required: true %>
<%= f.input :first_parent_citizenship, required: true, wrapper_html: { class: 'col-sm-6' } %>
<%= f.input :first_parent_address, required: true, wrapper_html: { class: 'col-sm-6' } %>
<%= f.input :first_parent_postal_code, required: true, wrapper_html: { class: 'col-sm-2' } %>
<%= f.input :first_parent_municipality, required: true, wrapper_html: { class: 'col-sm-8' } %>
<%= f.input :first_parent_province, required: true, wrapper_html: { class: 'col-sm-2' } %>
<%= f.input :first_parent_telephone, required: true, wrapper_html: { class: 'col-sm-6' } %>
<%= f.input :first_parent_email, required: true, wrapper_html: { class: 'col-sm-6' } %>
</div>
</div>
</div>
Expand All @@ -48,7 +48,7 @@
<div class="accordion-body row">
<%= f.input :second_parent_first_name, wrapper_html: { class: 'col-sm-6' } %>
<%= f.input :second_parent_last_name, wrapper_html: { class: 'col-sm-6' } %>
<%= f.input :second_parent_born_at, start_year: Date.today.year - 90, end_year: Date.today.year - 5 %>
<%= f.input :second_parent_born_at, include_blank: true, start_year: Date.today.year - 100, end_year: Date.today.year - 18 %>
<%= f.input :second_parent_born_in %>
<%= f.input :second_parent_tax_code %>
<%= f.input :second_parent_citizenship, wrapper_html: { class: 'col-sm-6' } %>
Expand All @@ -74,7 +74,7 @@
<%= f.input :medical_certificate_kind,
prompt: 'Seleziona tipo',
collection: Member.medical_certificate_kinds.map { |kind, v| [Member.human_attribute_name("medical_certificate_kind.#{kind}"), kind] },
wrapper_html: { class: 'col-sm-6' }
wrapper_html: { class: 'col-sm-6' }
%>
<%= f.association :tags, collection: @club.tags, as: :check_boxes %>
<%= f.association :groups, collection: @club.groups, as: :check_boxes %>
Expand Down
19 changes: 17 additions & 2 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,40 @@
require 'faker'

def random_member(club, groups: [], tags: [])
born_at = Faker::Date.between(from: 10.years.ago, to: 40.years.ago)
minor = born_at >= 18.years.ago
Member.create!(
club:,
groups:,
tags:,
first_name: Faker::Name.first_name,
last_name: Faker::Name.last_name,
born_at: Faker::Date.between(from: '2015-12-31', to: '2000-01-01'),
born_at:,
born_in: Faker::Address.city,
citizenship: Faker::Address.country,
address: Faker::Address.full_address,
postal_code: Faker::Address.postcode,
municipality: Faker::Address.community,
tax_code: Faker::Alphanumeric::ALPHANUMS,
province: Faker::Address.community.first(2),
telephone: Faker::PhoneNumber.cell_phone,
email: Faker::Internet.email,
medical_certificate_kind: %i[regular competitive].sample,
medical_certificate_expires_at: Faker::Date.forward,
membership_id: Faker::Number.number,
membership_expires_at: Faker::Date.forward
membership_expires_at: Faker::Date.forward,
first_parent_first_name: minor ? Faker::Name.first_name : nil,
first_parent_last_name: minor ? Faker::Name.last_name : nil,
first_parent_born_at: minor ? Faker::Date.between(from: 20.years.ago, to: 70.years.ago) : nil,
first_parent_born_in: minor ? Faker::Address.city : nil,
first_parent_citizenship: minor ? Faker::Address.country : nil,
first_parent_address: minor ? Faker::Address.full_address : nil,
first_parent_postal_code: minor ? Faker::Address.postcode : nil,
first_parent_municipality: minor ? Faker::Address.community : nil,
first_parent_tax_code: minor ? Faker::Alphanumeric::ALPHANUMS : nil,
first_parent_province: minor ? Faker::Address.community.first(2) : nil,
first_parent_telephone: minor ? Faker::PhoneNumber.cell_phone : nil,
first_parent_email: minor ? Faker::Internet.email : nil
)
end

Expand Down
27 changes: 1 addition & 26 deletions test/fixtures/members.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ minor_with_first_parent:
first_parent_first_name: gino
first_parent_last_name: ginetti
first_parent_email: [email protected]
first_parent_telephone: 123123213
first_parent_born_at: <%= Time.zone.today - 30.years %>
first_parent_born_in: comunino
first_parent_tax_code: TAX_CODE
Expand All @@ -55,29 +56,3 @@ minor_with_first_parent:
first_parent_postal_code: 12345
first_parent_province: provinciona
first_parent_municipality: comunone

minor_with_second_parent:
club: club
groups: [group]
first_name: gino
last_name: ginetti
email: [email protected]
born_at: <%= Time.zone.today - 17.years %>
born_in: comunino
citizenship: italiano
address: via delle vie 123 R
postal_code: 12345
province: provinciona
tax_code: TAXCODE
municipality: comunone
second_parent_first_name: gino
second_parent_last_name: ginetti
second_parent_email: [email protected]
second_parent_born_at: <%= Time.zone.today - 30.years %>
second_parent_born_in: comunino
second_parent_tax_code: TAX_CODE
second_parent_citizenship: italiano
second_parent_address: via delle vie 123 R
second_parent_postal_code: 12345
second_parent_province: provinciona
second_parent_municipality: comunone
1 change: 0 additions & 1 deletion test/models/member_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,5 @@ class MemberTest < ActiveSupport::TestCase
assert_not(members(:minor_with_no_parents).valid?)

assert(members(:minor_with_first_parent).valid?)
assert(members(:minor_with_second_parent).valid?)
end
end

0 comments on commit 70b7981

Please sign in to comment.