mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-07 13:38:18 -08:00
working on recipient lists
This commit is contained in:
parent
37e01c024b
commit
645d7bc7d5
10 changed files with 49 additions and 17 deletions
|
|
@ -50,5 +50,17 @@ footer {
|
|||
form {
|
||||
.form-group {
|
||||
padding-top: 12px;
|
||||
|
||||
label {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.form-check-collection {
|
||||
.form-check-label {
|
||||
display: block;
|
||||
padding-bottom: 12px;
|
||||
font-weight: normal;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
class RecipientListsController < ApplicationController
|
||||
before_action :stringify_recipient_ids, only: [:create, :update]
|
||||
before_action :set_school
|
||||
before_action :set_recipient_list, only: [:show, :edit, :update, :destroy]
|
||||
|
||||
|
|
@ -57,6 +58,13 @@ class RecipientListsController < ApplicationController
|
|||
@recipient_list = @school.recipient_lists.find(params[:id])
|
||||
end
|
||||
|
||||
def stringify_recipient_ids
|
||||
ids = params[:recipient_list][:recipient_ids]
|
||||
if ids.present? && ids.is_a?(Array)
|
||||
params[:recipient_list][:recipient_ids] = ids.reject { |id| id.empty? }.join(',')
|
||||
end
|
||||
end
|
||||
|
||||
# Only allow a trusted parameter "white list" through.
|
||||
def recipient_list_params
|
||||
params.require(:recipient_list).permit(:name, :description, :recipient_ids)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
class WelcomeController < ApplicationController
|
||||
|
||||
def index
|
||||
@schools = School.all
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -7,17 +7,18 @@
|
|||
%ul
|
||||
- @recipient_list.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 :recipient_ids
|
||||
= f.text_area :description, class: 'form-control'
|
||||
.form-group
|
||||
= f.label :recipient_ids, 'Recipients'
|
||||
%br/
|
||||
= f.text_area :recipient_ids
|
||||
.actions
|
||||
= f.submit
|
||||
.form-check.form-check-collection
|
||||
= f.collection_check_boxes(:recipient_ids, @school.recipients.all, :id, :name) { |c| c.label(class: 'form-check-label') { c.check_box(class: 'form-check-input') + " #{c.text}" } }
|
||||
.form-group
|
||||
= f.submit 'Save List', class: 'btn btn-primary'
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
%h1 New recipient_list
|
||||
= render 'form'
|
||||
= link_to 'Back', school_recipient_lists_path(@recipient_list.school)
|
||||
.row
|
||||
.offset-sm-2.col-sm-8
|
||||
%h3 Create A Recipient List For This School
|
||||
= render 'form'
|
||||
%br
|
||||
%p= link_to 'Back',@school
|
||||
|
|
|
|||
|
|
@ -3,4 +3,4 @@
|
|||
%h3 Add A Recipient To This School
|
||||
= render 'form', recipient: @recipient
|
||||
%br
|
||||
%p= link_to 'Back', school_recipients_path(@school)
|
||||
%p= link_to 'Back', @school
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@
|
|||
|
||||
%p= link_to "Bulk Add Recipients", import_school_recipients_path(@school)
|
||||
|
||||
%p= link_to "Create Recipient List", new_school_recipient_list_path(@school)
|
||||
|
||||
= link_to 'Edit', edit_school_path(@school)
|
||||
|
|
||||
= link_to 'Back', root_path
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ RSpec.describe RecipientListsController, type: :controller do
|
|||
let(:valid_attributes) {
|
||||
{
|
||||
school_id: school.id,
|
||||
recipient_ids: '1,2,3',
|
||||
recipient_ids: ['', '1', '2', '3'],
|
||||
name: 'Parents',
|
||||
description: 'List of parents.'
|
||||
}
|
||||
|
|
@ -88,6 +88,11 @@ RSpec.describe RecipientListsController, type: :controller do
|
|||
expect(assigns(:recipient_list)).to be_persisted
|
||||
end
|
||||
|
||||
it 'stores recipient_ids properly' do
|
||||
post :create, params: {school_id: school.to_param, recipient_list: valid_attributes}, session: valid_session
|
||||
expect(assigns(:recipient_list).recipient_ids).to eq('1,2,3')
|
||||
end
|
||||
|
||||
it "redirects to the created recipient_list" do
|
||||
post :create, params: {school_id: school.to_param, recipient_list: valid_attributes}, session: valid_session
|
||||
expect(response).to redirect_to(school_recipient_list_path(school, RecipientList.last))
|
||||
|
|
@ -110,7 +115,7 @@ RSpec.describe RecipientListsController, type: :controller do
|
|||
describe "PUT #update" do
|
||||
context "with valid params" do
|
||||
let(:new_attributes) {
|
||||
{recipient_ids: '3,4,5'}
|
||||
{recipient_ids: ['', '3', '4', '5']}
|
||||
}
|
||||
|
||||
it "updates the requested recipient_list" do
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ RSpec.describe "recipient_lists/edit", type: :view do
|
|||
|
||||
assert_select "textarea#recipient_list_description[name=?]", "recipient_list[description]"
|
||||
|
||||
assert_select "textarea#recipient_list_recipient_ids[name=?]", "recipient_list[recipient_ids]"
|
||||
assert_select "input[name=?]", "recipient_list[recipient_ids][]"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ RSpec.describe "recipient_lists/new", type: :view do
|
|||
|
||||
assert_select "textarea#recipient_list_description[name=?]", "recipient_list[description]"
|
||||
|
||||
assert_select "textarea#recipient_list_recipient_ids[name=?]", "recipient_list[recipient_ids]"
|
||||
assert_select "input[name=?]", "recipient_list[recipient_ids][]"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue