diff --git a/app/controllers/districts_controller.rb b/app/controllers/districts_controller.rb index 89c95611..e9e0fedb 100644 --- a/app/controllers/districts_controller.rb +++ b/app/controllers/districts_controller.rb @@ -10,6 +10,7 @@ class DistrictsController < ApplicationController # GET /districts/1 # GET /districts/1.json def show + @schools = @district.schools end # GET /districts/new diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index cbb3b2f7..e9c6739c 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -1,6 +1,7 @@ class WelcomeController < ApplicationController def index + @districts = District.all @schools = School.all end diff --git a/app/views/districts/show.html.haml b/app/views/districts/show.html.haml index a317b859..d5a2fd1e 100644 --- a/app/views/districts/show.html.haml +++ b/app/views/districts/show.html.haml @@ -1,10 +1,19 @@ -%p#notice= notice -%p - %strong Name: - = @district.name -%p - %strong State: - = @district.state_id -= link_to 'Edit', edit_district_path(@district) -| -= link_to 'Back', districts_path +.row + .col-12 + %p + %strong Name: + = @district.name + %p + %strong State: + = @district.state_id + + %p + = link_to 'Edit', edit_district_path(@district) + | + = link_to 'Back', districts_path + +.row.mt-3 + .col-12 + %h4 Schools + - @schools.each do |school| + %p= link_to school.name, school diff --git a/app/views/schools/admin.html.haml b/app/views/schools/admin.html.haml new file mode 100644 index 00000000..31de8e5c --- /dev/null +++ b/app/views/schools/admin.html.haml @@ -0,0 +1,77 @@ +.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/app/views/schools/show.html.haml b/app/views/schools/show.html.haml index 31de8e5c..96a86490 100644 --- a/app/views/schools/show.html.haml +++ b/app/views/schools/show.html.haml @@ -6,72 +6,3 @@ %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/app/views/welcome/index.html.haml b/app/views/welcome/index.html.haml index 0bec712b..fc3a0d73 100644 --- a/app/views/welcome/index.html.haml +++ b/app/views/welcome/index.html.haml @@ -1,9 +1,17 @@ -%p= link_to "Create A New District", new_district_path +.row + .col-12 + %p= link_to "Create A New District", new_district_path -%p= link_to "Create A New School", new_school_path + %p= link_to "Create A New School", new_school_path -%br -%h4 Schools -- @schools.each do |school| - %p= link_to school.name, school +.row.mt-3 + .col-6 + %h4 Districts + - @districts.each do |district| + %p= link_to district.name, district + + .col-6 + %h4 Schools + - @schools.each do |school| + %p= link_to school.name, school diff --git a/config/routes.rb b/config/routes.rb index 7f64348f..86e3dd10 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -14,6 +14,7 @@ Rails.application.routes.draw do end resources :schedules resources :categories, only: [:show] + get :admin end # resources :attempts, only: [:get, :update] diff --git a/spec/views/districts/show.html.erb_spec.rb b/spec/views/districts/show.html.erb_spec.rb index 06831d9f..a997b88d 100644 --- a/spec/views/districts/show.html.erb_spec.rb +++ b/spec/views/districts/show.html.erb_spec.rb @@ -3,14 +3,21 @@ require 'rails_helper' RSpec.describe "districts/show", type: :view do before(:each) do @district = assign(:district, District.create!( - :name => "Name", + :name => "District Name", :state_id => 2 )) + + schools = [] + 3.times { |i| schools << @district.schools.create!(name: "School #{i}")} + @schools = assign(:schools, schools) end it "renders attributes in
" do render - expect(rendered).to match(/Name/) + expect(rendered).to match(/District Name/) expect(rendered).to match(/2/) + 3.times do |i| + expect(rendered).to match(/School #{i}/) + end end end