OfficeMomsandDads/scheduler

View on GitHub
app/views/needs/show.html.haml

Summary

Maintainability
Test Coverage
- content_for :page_header do
  .header-text Need at #{@need.effective_start_at.strftime('%l:%M%P on %A, %b %d')}
- if policy(@need).edit? && !@need.expired?
  - content_for :nav_buttons do
    = link_to 'Manage Shifts', need_shifts_path(@need), class: 'button primary'
    = link_to 'Edit Need', edit_need_path(@need), class: 'button secondary'
    = link_to 'Delete Need', need_path(@need), method: :delete, class: 'button alert', data: { confirm: 'Are you sure you want to destroy this Need?' }
%h2 Details
%table.unstriped.need-details
  %tbody
    %tr
      %td Start Time
      %td
        %strong= @need.effective_start_at.strftime('%l:%M%P')
        %br
        = @need.start_at.strftime('%A, %b %d')
    %tr
      %td Office
      %td
        %strong= @need.office
    %tr
      %td Child Welfare Workers
      %td
        %ul.social_workers
          - @need.social_workers.each do |social_worker|
            %li
              %strong= social_worker.name
              - if social_worker.phone.present?
                = "(Phone: #{social_worker.phone})"
    %tr
      %td Requested By
      %td
        %strong= @need.user.name
    %tr
      %td Number of Children
      %td
        %strong= @need.children.count
    %tr
      %td Preferred Language
      %td
        %strong= @need.preferred_language.name
    %tr
      %td Ignore Preferred Language for Notifications
      %td
        %strong= @need.preferred_language_override.to_s.capitalize
    - if @need.notes.present?
      %tr
        %td Notes
        %td
          %strong= simple_format("#{@need.notes}")
.grid-x
  .cell
    - @need.children.each_with_index do |child, index|
      .card{style: "margin-bottom: 3rem;"}
        .card-divider
          %h5{style: "font-weight: bold;"} Child #{index + 1}
        .card-section{style: "padding:0;"}
          %table.unstriped.need-details{style: "border: none;"}
            %tbody{style: "border: none;"}
              %tr
                %td Age
                %td
                  %strong= child.age
              %tr
                %td Gender
                %td
                  %strong= child.sex.dasherize.capitalize
              - if child.notes.present?
                %tr
                  %td Notes
                  %td
                    %strong= child.notes
%h2 Shifts
.shifts-container
  - @shifts.each do |shift|
    %hr
    .grid-x.grid-margin-y.grid-margin-x.align-spaced.align-middle
      .cell.small-12.medium-9.large-10.shift{ class: shift.user_id ? 'secondary claimed' : 'success unclaimed' }
        .grid-x.grid-padding-x.grid-padding-y
          .cell.text-center
            %strong= shift.start_at.strftime('%I:%M%p')
            - if policy(@need).edit?
              = " - #{shift.user&.to_s}"
      .cell.small-12.medium-3.large-2
        - if !shift.expired? && shift.user_id == current_user.id
          = link_to need_shift_path(@need, shift, shift: { user_id: nil }), method: :put, class: 'button alert expanded' do
            .grid-x.hide-for-small-only.align-middle
              .cell.small-6.small-text-right.medium-3
                %i.fas.fa-calendar-minus
              .cell.small-6.medium-9.text-left
                Release Shift
            .grid-x.show-for-small-only
              .cell
                %i.fas.fa-calendar-minus
                Release Shift
        - if !shift.expired? && shift.user_id == nil
          = link_to need_shift_path(@need, shift, shift: { user_id: current_user.id }), method: :put, class: 'button success expanded' do
            .grid-x.hide-for-small-only.align-middle
              .cell.small-6.small-text-right.medium-3
                %i.fas.fa-calendar-plus
              .cell.small-6.small-text-left.medium-9.text-left
                Claim Shift
            .grid-x.show-for-small-only
              .cell
                %i.fas.fa-calendar-plus
                Claim Shift
- if @need.notified_user_ids.present?
  - if @need.notified_user_ids.include?(current_user.id)
    %br
    .unavailable-container
      - if @need.shifts.where(user_id: current_user.id).present?
        %p You have claimed a shift.
      - elsif @need.unavailable_user_ids.include?(current_user.id)
        %p You have marked yourself as unavailable for this request.
      - else
        = form_tag mark_unavailable_need_path(@need), method: :patch do
          = submit_tag 'I am not available for this request.', class: 'button alert'
        %br
  - if policy(@need).view_responses?
    .responses-container{data: { controller: 'needs-show' }}
      %p
        = link_to pluralize(@need.unavailable_users.size, 'volunteer'), '#', id: 'toggle-unavailable-list', data: { action: 'needs-show#toggleUserListDisplay', list_id: '#unavailable-list' }
        cannot fill this request
      %ul#unavailable-list.hide
        - @need.unavailable_users.each do |user|
          %li= user.name
      %p
        = link_to pluralize(@need.users_pending_response.size, 'volunteer'), '#', id: 'toggle-pending-list', data: { action: 'needs-show#toggleUserListDisplay', list_id: '#pending-list' }
        = "have not yet responded"
      %ul#pending-list.hide
        - @need.users_pending_response.each do |user|
          %li= user.name
      %p
        = link_to pluralize(@need.users_language_pending_response.size, 'volunteer'), '#', id: 'toggle-language-list', data: { action: 'needs-show#toggleUserListDisplay', list_id: '#language-list' }
        who speaks the preferred language has not responded
      %ul#language-list.hide
        - @need.users_language_pending_response.each do |user|
          %li= user.name