From f978a4f430f46466c8e6ed77d67377d3dbf42bd7 Mon Sep 17 00:00:00 2001 From: Matt Levy Date: Fri, 12 Jul 2024 09:39:16 -0700 Subject: [PATCH] Cleanup and validations --- Brewfile | 2 - app/models/event.rb | 6 ++ .../ticket_requests/_event_role.html.haml | 57 ++++++++++++++++++ app/views/ticket_requests/_form.html.haml | 58 +------------------ .../_table_ticket_requests.html.haml | 11 ++-- spec/controllers/events_controller_spec.rb | 2 +- 6 files changed, 71 insertions(+), 65 deletions(-) create mode 100644 app/views/ticket_requests/_event_role.html.haml diff --git a/Brewfile b/Brewfile index cb197eeb..9b92ad30 100644 --- a/Brewfile +++ b/Brewfile @@ -71,7 +71,6 @@ brew 'minikube' brew 'kubernetes-cli' cask 'chromedriver' -# cask 'github' cask 'font-andale-mono' cask 'font-anonymice-powerline' @@ -112,6 +111,5 @@ cask 'font-roboto' cask 'font-roboto-mono-nerd-font' cask 'font-share-tech-mono' cask 'font-sometype-mono' -# cask 'font-titillium' cask 'font-ubuntu' cask 'font-victor-mono' diff --git a/app/models/event.rb b/app/models/event.rb index a29bcb15..b6885774 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -56,6 +56,7 @@ class Event < ApplicationRecord normalize_attributes :name before_validation :generate_slug! + before_validation :ensure_require_role_set_default validates :name, presence: true, length: { maximum: MAX_NAME_LENGTH } validates :start_time, presence: true @@ -236,4 +237,9 @@ def ensure_prices_set_if_maximum_specified 'can be set only if a cabin price is set') end end + + def ensure_require_role_set_default + attributes[:require_role] = true if attributes[:require_role].nil? + end + end diff --git a/app/views/ticket_requests/_event_role.html.haml b/app/views/ticket_requests/_event_role.html.haml new file mode 100644 index 00000000..b98ba5b1 --- /dev/null +++ b/app/views/ticket_requests/_event_role.html.haml @@ -0,0 +1,57 @@ +%h4 How are you contributing to the event? +.content-fluid + .row + .col-lg-6.col-xl-6.col-md-12.col-sm-12 + .input-group-large + %fieldset + %p + = f.label :role_volunteer do + = f.label :role_volunteer, class: 'radio inline' do + = f.radio_button :role, TicketRequest::ROLE_VOLUNTEER, + data: { 'max-tickets' => TicketRequest::TICKET_LIMITS[TicketRequest::ROLE_VOLUNTEER] } + = TicketRequest::ROLES[TicketRequest::ROLE_VOLUNTEER] + = f.label :role_contributor, class: 'radio inline' do + = f.radio_button :role, TicketRequest::ROLE_CONTRIBUTOR, + data: { 'max-tickets' => TicketRequest::TICKET_LIMITS[TicketRequest::ROLE_CONTRIBUTOR] } + = TicketRequest::ROLES[TicketRequest::ROLE_CONTRIBUTOR] + = f.label :role_coordinator, class: 'radio inline' do + = f.radio_button :role, TicketRequest::ROLE_COORDINATOR, + data: { 'max-tickets' => TicketRequest::TICKET_LIMITS[TicketRequest::ROLE_COORDINATOR] } + = TicketRequest::ROLES[TicketRequest::ROLE_COORDINATOR] + = f.label :role_uber_coordinator, class: 'radio inline' do + = f.radio_button :role, TicketRequest::ROLE_UBER_COORDINATOR, + data: { 'max-tickets' => TicketRequest::TICKET_LIMITS[TicketRequest::ROLE_UBER_COORDINATOR] } + = TicketRequest::ROLES[TicketRequest::ROLE_UBER_COORDINATOR] + = f.label :role_other, class: 'radio inline' do + = f.radio_button :role, TicketRequest::ROLE_OTHER, + data: { 'max-tickets' => TicketRequest::TICKET_LIMITS[TicketRequest::ROLE_OTHER] } + = TicketRequest::ROLES[TicketRequest::ROLE_OTHER] + + .col-lg-6.col-xl-6.col-md-12.col-sm-12.align-content-md-center + %p.muted.role-explanation{ class: TicketRequest::ROLE_VOLUNTEER } + You are working one or more shifts at the event + + %p.muted.role-explanation.hidden{ class: TicketRequest::ROLE_CONTRIBUTOR } + Working before and during or during and after; actively involved in + planning the campout e.g. a coordinator assistant or apprentice. Bringing + gear, driving trucks, art committee, etc. + + %p.muted.role-explanation.hidden{ class: TicketRequest::ROLE_COORDINATOR } + Listed on the Coordinator Sheet as someone who is leading a major area of + camp out planning; working before, during, and after the event including + things like resource coordination, significant gear prep, pre/post-site + visits, etc. + + %p.muted.role-explanation.hidden{ class: TicketRequest::ROLE_OTHER } + Art Grantee or DJ + + = f.text_area :role_explanation, + placeholder: 'Briefly describe your role', + rows: 4, width: 400, maxlength: 200, required: false, style: 'min-width: 100% !important; font-size: 11pt;' + +.row + .col-lg-6.col-xl-6.col-md-12.col-sm-12 + - if @event.require_role + = f.label :previous_contribution, 'What was your role last year?' + = f.text_area :previous_contribution, style: 'min-width: 100%', + rows: 2, maxlength: 250, required: false diff --git a/app/views/ticket_requests/_form.html.haml b/app/views/ticket_requests/_form.html.haml index 80f5dd7f..36d1be06 100644 --- a/app/views/ticket_requests/_form.html.haml +++ b/app/views/ticket_requests/_form.html.haml @@ -88,63 +88,7 @@ - if !@ticket_request.post_payment? || (@event.admin?(current_user) && is_update) %hr - if @event.require_role - %h4 How are you contributing to the event? - .content-fluid - .row - .col-lg-6.col-xl-6.col-md-12.col-sm-12 - .input-group-large - %fieldset - %p - = f.label :role_volunteer do - = f.label :role_volunteer, class: 'radio inline' do - = f.radio_button :role, TicketRequest::ROLE_VOLUNTEER, - data: { 'max-tickets' => TicketRequest::TICKET_LIMITS[TicketRequest::ROLE_VOLUNTEER] } - = TicketRequest::ROLES[TicketRequest::ROLE_VOLUNTEER] - = f.label :role_contributor, class: 'radio inline' do - = f.radio_button :role, TicketRequest::ROLE_CONTRIBUTOR, - data: { 'max-tickets' => TicketRequest::TICKET_LIMITS[TicketRequest::ROLE_CONTRIBUTOR] } - = TicketRequest::ROLES[TicketRequest::ROLE_CONTRIBUTOR] - = f.label :role_coordinator, class: 'radio inline' do - = f.radio_button :role, TicketRequest::ROLE_COORDINATOR, - data: { 'max-tickets' => TicketRequest::TICKET_LIMITS[TicketRequest::ROLE_COORDINATOR] } - = TicketRequest::ROLES[TicketRequest::ROLE_COORDINATOR] - = f.label :role_uber_coordinator, class: 'radio inline' do - = f.radio_button :role, TicketRequest::ROLE_UBER_COORDINATOR, - data: { 'max-tickets' => TicketRequest::TICKET_LIMITS[TicketRequest::ROLE_UBER_COORDINATOR] } - = TicketRequest::ROLES[TicketRequest::ROLE_UBER_COORDINATOR] - = f.label :role_other, class: 'radio inline' do - = f.radio_button :role, TicketRequest::ROLE_OTHER, - data: { 'max-tickets' => TicketRequest::TICKET_LIMITS[TicketRequest::ROLE_OTHER] } - = TicketRequest::ROLES[TicketRequest::ROLE_OTHER] - - .col-lg-6.col-xl-6.col-md-12.col-sm-12.align-content-md-center - %p.muted.role-explanation{ class: TicketRequest::ROLE_VOLUNTEER } - You are working one or more shifts at the event - - %p.muted.role-explanation.hidden{ class: TicketRequest::ROLE_CONTRIBUTOR } - Working before and during or during and after; actively involved in - planning the campout e.g. a coordinator assistant or apprentice. Bringing - gear, driving trucks, art committee, etc. - - %p.muted.role-explanation.hidden{ class: TicketRequest::ROLE_COORDINATOR } - Listed on the Coordinator Sheet as someone who is leading a major area of - camp out planning; working before, during, and after the event including - things like resource coordination, significant gear prep, pre/post-site - visits, etc. - - %p.muted.role-explanation.hidden{ class: TicketRequest::ROLE_OTHER } - Art Grantee or DJ - - = f.text_area :role_explanation, - placeholder: 'Briefly describe your role', - rows: 4, width: 400, maxlength: 200, required: false, style: 'min-width: 100% !important; font-size: 11pt;' - - .row - .col-lg-6.col-xl-6.col-md-12.col-sm-12 - - if @event.require_role - = f.label :previous_contribution, 'What was your role last year?' - = f.text_area :previous_contribution, style: 'min-width: 100%', - rows: 2, maxlength: 250, required: false + = render partial: :event_role - if signed_in? && @event.admin?(current_user) && is_update .well diff --git a/app/views/ticket_requests/_table_ticket_requests.html.haml b/app/views/ticket_requests/_table_ticket_requests.html.haml index 12a152f5..12e5fc6e 100644 --- a/app/views/ticket_requests/_table_ticket_requests.html.haml +++ b/app/views/ticket_requests/_table_ticket_requests.html.haml @@ -7,8 +7,9 @@ %tr %th.bg-dark-subtle Name - %th.bg-dark-subtle.optional-medium Role - %th.bg-dark-subtle + - if event.require_role + %th.bg-dark-subtle.optional-medium Role + %th.bg-dark-subtle Notes %th.bg-dark-subtle.text-end.optional-medium Tickets - if event.kid_ticket_price %th.bg-dark-subtle.text-end.optional-medium Kids @@ -30,9 +31,9 @@ = link_to event_ticket_request_path(event, ticket_request) do = ticket_request.user.name - %td.muted.align-content-center.optional-medium - = TicketRequest::ROLES[ticket_request.role] - - if ticket_request.role_explanation.present? + - if event.require_role + %td.muted.align-content-center.optional-medium + = TicketRequest::ROLES[ticket_request.role] %i.icon-comment.hover-tooltip{ title: ticket_request.role_explanation } %td.align-content-center.text-start.text-nowrap diff --git a/spec/controllers/events_controller_spec.rb b/spec/controllers/events_controller_spec.rb index 204bd1d0..20f5c132 100644 --- a/spec/controllers/events_controller_spec.rb +++ b/spec/controllers/events_controller_spec.rb @@ -80,7 +80,7 @@ expect(new_event.start_time.to_datetime).to be_a(DateTime) end - it 'has requires role to be true' do + it 'has require_role set to true' do expect(new_event.require_role).to be_truthy end