From 260b1dd2c325d61418cb684733586b2f26241829 Mon Sep 17 00:00:00 2001 From: Jared Cosulich Date: Mon, 6 Mar 2017 13:52:02 -0500 Subject: [PATCH] working on schedules --- app/helpers/schedules_helper.rb | 19 +++ app/views/layouts/application.html.haml | 14 ++- app/views/recipient_lists/new.html.haml | 2 +- app/views/schedules/_form.html.haml | 46 ++++--- app/views/schedules/new.html.haml | 9 +- app/views/schedules/show.html.haml | 9 +- app/views/schools/show.html.haml | 132 ++++++++++++--------- spec/views/schedules/edit.html.erb_spec.rb | 8 +- spec/views/schedules/new.html.erb_spec.rb | 8 +- spec/views/schedules/show.html.erb_spec.rb | 4 +- 10 files changed, 145 insertions(+), 106 deletions(-) diff --git a/app/helpers/schedules_helper.rb b/app/helpers/schedules_helper.rb index 86e05a48..c59a6c79 100644 --- a/app/helpers/schedules_helper.rb +++ b/app/helpers/schedules_helper.rb @@ -1,2 +1,21 @@ module SchedulesHelper + + def options_for_frequency_hours + [ + ['Once A Week', 24 * 7], + ['Every Other Week', 2 * 24 * 7], + ['Once A Month', 4 * 24 * 7] + ] + end + + def frequency_description(hours) + case hours + when (24 * 7) + 'Once A Week' + when (2 * 24 * 7) + 'Every Other Week' + when (4 * 24 * 7) + 'Once A Month' + end + end end diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 43347765..7249aa9f 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -9,12 +9,14 @@ = javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %body .container - = render partial: 'layouts/header' + .row + .col + = render partial: 'layouts/header' - - if notice.present? - %p.notice= notice + - if notice.present? + %p.notice= notice - - if alert.present? - %p.alert= alert + - if alert.present? + %p.alert= alert - = yield + = yield diff --git a/app/views/recipient_lists/new.html.haml b/app/views/recipient_lists/new.html.haml index dab5a4fd..7bb55d77 100644 --- a/app/views/recipient_lists/new.html.haml +++ b/app/views/recipient_lists/new.html.haml @@ -3,4 +3,4 @@ %h3 Create A Recipient List For This School = render 'form', recipient_list: @recipient_list %br - %p= link_to 'Back',@school + %p= link_to 'Back', @school diff --git a/app/views/schedules/_form.html.haml b/app/views/schedules/_form.html.haml index b4d10759..8c3e7ba9 100644 --- a/app/views/schedules/_form.html.haml +++ b/app/views/schedules/_form.html.haml @@ -7,45 +7,41 @@ %ul - @schedule.errors.full_messages.each do |msg| %li= msg - .field + .form-group = f.label :name %br/ - = f.text_field :name - .field + = f.text_field :name, class: 'form-control' + .form-group = f.label :description %br/ - = f.text_area :description - .field - = f.label :school_id + = f.text_area :description, class: 'form-control' + .form-group + = f.label :frequency_hours, 'How often should be people be surveyed?' %br/ - = f.number_field :school_id - .field - = f.label :frequency_hours - %br/ - = f.number_field :frequency_hours - .field + = f.select :frequency_hours, options_for_frequency_hours, class: 'form-control' + .form-group = f.label :start_date %br/ - = f.date_select :start_date - .field + = f.date_select :start_date, class: 'form-control' + .form-group = f.label :end_date %br/ - = f.date_select :end_date - .field + = f.date_select :end_date, class: 'form-control' + .form-group = f.label :active %br/ - = f.check_box :active - .field + = f.check_box :active, class: 'form-control' + .form-group = f.label :random %br/ - = f.check_box :random - .field + = f.check_box :random, class: 'form-control' + .form-group = f.label :recipient_list_id %br/ - = f.number_field :recipient_list_id - .field + = f.collection_select :recipient_list_id, @school.recipient_lists.all, :id, :name, class: 'form-control' + .form-group = f.label :question_list_id %br/ - = f.number_field :question_list_id - .actions - = f.submit + = f.collection_select :question_list_id, QuestionList.all, :id, :name, class: 'form-control' + .form-group + = f.submit 'Save Schedule', class: 'btn btn-primary' diff --git a/app/views/schedules/new.html.haml b/app/views/schedules/new.html.haml index 88d7564c..4bc23bca 100644 --- a/app/views/schedules/new.html.haml +++ b/app/views/schedules/new.html.haml @@ -1,3 +1,6 @@ -%h1 New schedule -= render 'form' -= link_to 'Back', school_schedules_path(@schedule.school) +.row + .offset-2.col-8 + %h3 Create A New Schedule For This School + = render 'form', schedule: @schedule + %br + %p= link_to 'Back', @school diff --git a/app/views/schedules/show.html.haml b/app/views/schedules/show.html.haml index 8cdfa4ee..daa60484 100644 --- a/app/views/schedules/show.html.haml +++ b/app/views/schedules/show.html.haml @@ -7,10 +7,10 @@ = @schedule.description %p %b School: - = @schedule.school.name + = link_to(@school.name, @school) %p %b Frequency hours: - = @schedule.frequency_hours + = frequency_description(@schedule.frequency_hours) %p %b Start date: = @schedule.start_date @@ -25,10 +25,11 @@ = @schedule.random %p %b Recipient list: - = @schedule.recipient_list.name + = link_to(@schedule.recipient_list.name, [@school, @schedule.recipient_list]) %p %b Question list: - = @schedule.question_list.name + = link_to(@schedule.question_list.name, @schedule.question_list) + = link_to 'Edit', edit_school_schedule_path(@schedule.school, @schedule) | = link_to 'Back', school_schedules_path(@schedule.school) diff --git a/app/views/schools/show.html.haml b/app/views/schools/show.html.haml index 0150c8e3..31de8e5c 100644 --- a/app/views/schools/show.html.haml +++ b/app/views/schools/show.html.haml @@ -1,55 +1,77 @@ -%p - %strong Name: - = @school.name -%p - %strong District: - = @school.district_id - -%p= link_to "Add Recipient", new_school_recipient_path(@school) - -%p= link_to "Bulk Add Recipients", import_school_recipients_path(@school) - -%p= link_to "Create Recipient List", new_school_recipient_list_path(@school) - -%p= link_to "Create A Question List", new_question_list_path() - --#%p= link_to "Create A Schedule", new_school_schedule_path(@school) - -= link_to 'Edit', edit_school_path(@school) -| -= link_to 'Back', root_path - -%br -%br -%br -%h4 School Recipient Lists -%table{style: 'width: 100%;'} - %tbody - %thead{style: 'font-weight: bold;'} - %th Name - %th Descriptin - %th{colspan: 2} Actions - - @school.recipient_lists.each do |recipient_list| - %tr.recipient - %td= link_to recipient_list.name, [@school, recipient_list] - %td= recipient_list.description - %td= link_to('Edit', edit_school_recipient_list_path(@school, recipient_list)) - %td= link_to('Delete', school_recipient_list_path(@school, recipient_list), method: :delete, data: {confirm: 'Are you sure you want to delete this list?'}) - - -%br -%br -%br -%h4 School Recipients -%table{style: 'width: 100%;'} - %tbody - %thead{style: 'font-weight: bold;'} - %th Name - %th Phone - %th{colspan: 2} Actions - - @school.recipients.each do |recipient| - %tr.recipient - %td= recipient.name - %td= recipient.phone - %td= link_to('Edit', edit_school_recipient_path(@school, recipient)) - %td= link_to('Delete', school_recipient_path(@school, recipient), method: :delete, data: {confirm: 'Are you sure you want to delete this recipient?'}) +.row + .col + %p + %strong Name: + = @school.name + %p + %strong District: + = @school.district_id + + %p= link_to "Add Recipient", new_school_recipient_path(@school) + + %p= link_to "Bulk Add Recipients", import_school_recipients_path(@school) + + %p= link_to "Create Recipient List", new_school_recipient_list_path(@school) + + %p= link_to "Create A Question List", new_question_list_path() + + %p= link_to "Create A Schedule", new_school_schedule_path(@school) + + = link_to 'Edit', edit_school_path(@school) + | + = link_to 'Back', root_path + + + %br + %br + %br + %h4 School Schedules + %table{style: 'width: 100%;'} + %tbody + %thead{style: 'font-weight: bold;'} + %th Name + %th Start + %th End + %th{colspan: 2} Actions + - @school.schedules.each do |schedule| + %tr.recipient + %td= link_to schedule.name, [@school, schedule] + %td= schedule.start_date + %td= schedule.end_date + %td= link_to('Edit', edit_school_recipient_list_path(@school, schedule)) + %td= link_to('Delete', school_recipient_list_path(@school, schedule), method: :delete, data: {confirm: 'Are you sure you want to delete this schedule?'}) + + %br + %br + %br + %h4 School Recipient Lists + %table{style: 'width: 100%;'} + %tbody + %thead{style: 'font-weight: bold;'} + %th Name + %th Descriptin + %th{colspan: 2} Actions + - @school.recipient_lists.each do |recipient_list| + %tr.recipient + %td= link_to recipient_list.name, [@school, recipient_list] + %td= recipient_list.description + %td= link_to('Edit', edit_school_recipient_list_path(@school, recipient_list)) + %td= link_to('Delete', school_recipient_list_path(@school, recipient_list), method: :delete, data: {confirm: 'Are you sure you want to delete this list?'}) + + + %br + %br + %br + %h4 School Recipients + %table{style: 'width: 100%;'} + %tbody + %thead{style: 'font-weight: bold;'} + %th Name + %th Phone + %th{colspan: 2} Actions + - @school.recipients.each do |recipient| + %tr.recipient + %td= recipient.name + %td= recipient.phone + %td= link_to('Edit', edit_school_recipient_path(@school, recipient)) + %td= link_to('Delete', school_recipient_path(@school, recipient), method: :delete, data: {confirm: 'Are you sure you want to delete this recipient?'}) diff --git a/spec/views/schedules/edit.html.erb_spec.rb b/spec/views/schedules/edit.html.erb_spec.rb index 961de821..84329ad3 100644 --- a/spec/views/schedules/edit.html.erb_spec.rb +++ b/spec/views/schedules/edit.html.erb_spec.rb @@ -29,17 +29,15 @@ RSpec.describe "schedules/edit", type: :view do assert_select "textarea#schedule_description[name=?]", "schedule[description]" - assert_select "input#schedule_school_id[name=?]", "schedule[school_id]" - - assert_select "input#schedule_frequency_hours[name=?]", "schedule[frequency_hours]" + assert_select "select[name=?]", "schedule[frequency_hours]" assert_select "input#schedule_active[name=?]", "schedule[active]" assert_select "input#schedule_random[name=?]", "schedule[random]" - assert_select "input#schedule_recipient_list_id[name=?]", "schedule[recipient_list_id]" + assert_select "select[name=?]", "schedule[recipient_list_id]" - assert_select "input#schedule_question_list_id[name=?]", "schedule[question_list_id]" + assert_select "select[name=?]", "schedule[question_list_id]" end end end diff --git a/spec/views/schedules/new.html.erb_spec.rb b/spec/views/schedules/new.html.erb_spec.rb index 395b5f2b..aa18d30b 100644 --- a/spec/views/schedules/new.html.erb_spec.rb +++ b/spec/views/schedules/new.html.erb_spec.rb @@ -29,17 +29,15 @@ RSpec.describe "schedules/new", type: :view do assert_select "textarea#schedule_description[name=?]", "schedule[description]" - assert_select "input#schedule_school_id[name=?]", "schedule[school_id]" - - assert_select "input#schedule_frequency_hours[name=?]", "schedule[frequency_hours]" + assert_select "select[name=?]", "schedule[frequency_hours]" assert_select "input#schedule_active[name=?]", "schedule[active]" assert_select "input#schedule_random[name=?]", "schedule[random]" - assert_select "input#schedule_recipient_list_id[name=?]", "schedule[recipient_list_id]" + assert_select "select[name=?]", "schedule[recipient_list_id]" - assert_select "input#schedule_question_list_id[name=?]", "schedule[question_list_id]" + assert_select "select[name=?]", "schedule[question_list_id]" end end end diff --git a/spec/views/schedules/show.html.erb_spec.rb b/spec/views/schedules/show.html.erb_spec.rb index a77aac42..2a584e18 100644 --- a/spec/views/schedules/show.html.erb_spec.rb +++ b/spec/views/schedules/show.html.erb_spec.rb @@ -12,7 +12,7 @@ RSpec.describe "schedules/show", type: :view do :name => "Name", :description => "MyText", :school => @school, - :frequency_hours => 3, + :frequency_hours => 2 * 24 * 7, :active => false, :random => false, :recipient_list => @recipient_list, @@ -25,7 +25,7 @@ RSpec.describe "schedules/show", type: :view do expect(rendered).to match(/Name/) expect(rendered).to match(/MyText/) expect(rendered).to match(/#{@school.name}/) - expect(rendered).to match(/3/) + expect(rendered).to match(/Every Other Week/) expect(rendered).to match(/false/) expect(rendered).to match(/false/) expect(rendered).to match(/#{@recipient_list.name}/)