mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-07 21:48:16 -08:00
admin recipients
This commit is contained in:
parent
df594b9666
commit
683fc31c5d
10 changed files with 99 additions and 37 deletions
|
|
@ -1,4 +1,5 @@
|
|||
class QuestionsController < ApplicationController
|
||||
before_action :set_school, only: [:show]
|
||||
before_action :set_question, only: [:show, :edit, :update, :destroy]
|
||||
|
||||
# GET /questions
|
||||
|
|
@ -62,6 +63,12 @@ class QuestionsController < ApplicationController
|
|||
end
|
||||
|
||||
private
|
||||
def set_school
|
||||
redirect_to root_path and return false unless params.include?(:school_id)
|
||||
@school = School.find(params[:school_id])
|
||||
redirect_to root_path and return false if @school.nil?
|
||||
end
|
||||
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_question
|
||||
@question = Question.find(params[:id])
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
class SchoolsController < ApplicationController
|
||||
before_action :set_school, only: [:show, :edit, :update, :destroy]
|
||||
before_action :set_school, only: [:admin, :show, :edit, :update, :destroy]
|
||||
|
||||
# GET /schools
|
||||
# GET /schools.json
|
||||
|
|
@ -65,7 +65,7 @@ class SchoolsController < ApplicationController
|
|||
private
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_school
|
||||
@school = School.find(params[:id])
|
||||
@school = School.find(params[:id] || params[:school_id])
|
||||
end
|
||||
|
||||
# Never trust parameters from the scary internet, only allow the white list through.
|
||||
|
|
|
|||
|
|
@ -27,6 +27,11 @@ class Attempt < ApplicationRecord
|
|||
recipient.update_attributes(phone: client.messages.get(message.sid).to)
|
||||
end
|
||||
|
||||
def response
|
||||
return 'No Answer Yet' if answer_index.blank?
|
||||
question.options[answer_index - 1]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def update_school_categories
|
||||
|
|
|
|||
|
|
@ -28,3 +28,12 @@
|
|||
= link_to 'Edit', edit_question_path(@question)
|
||||
|
|
||||
= link_to 'Back', questions_path
|
||||
|
||||
|
||||
%br
|
||||
%br
|
||||
%br
|
||||
%h4
|
||||
Results For
|
||||
= @school.name
|
||||
= render @question
|
||||
|
|
|
|||
|
|
@ -1,33 +1,70 @@
|
|||
%p
|
||||
%strong Name:
|
||||
= @recipient.name
|
||||
%p
|
||||
%strong Phone:
|
||||
= @recipient.phone
|
||||
%p
|
||||
%strong Birth date:
|
||||
= @recipient.birth_date
|
||||
%p
|
||||
%strong Gender:
|
||||
= @recipient.gender
|
||||
%p
|
||||
%strong Race:
|
||||
= @recipient.race
|
||||
%p
|
||||
%strong Ethnicity:
|
||||
= @recipient.ethnicity
|
||||
%p
|
||||
%strong Home language:
|
||||
= @recipient.home_language_id
|
||||
%p
|
||||
%strong Income:
|
||||
= @recipient.income
|
||||
%p
|
||||
%strong Opted out:
|
||||
= @recipient.opted_out
|
||||
%p
|
||||
%strong School:
|
||||
= @recipient.school_id
|
||||
.row
|
||||
.col
|
||||
%p
|
||||
%strong School:
|
||||
= @school.name
|
||||
%p
|
||||
%strong Recipient:
|
||||
= @recipient.name
|
||||
|
||||
- if @recipient.phone.present?
|
||||
%p
|
||||
%strong Phone:
|
||||
= @recipient.phone
|
||||
|
||||
- if @recipient.birth_date.present?
|
||||
%p
|
||||
%strong Birth date:
|
||||
= @recipient.birth_date
|
||||
|
||||
- if @recipient.gender.present?
|
||||
%p
|
||||
%strong Gender:
|
||||
= @recipient.gender
|
||||
|
||||
- if @recipient.race.present?
|
||||
%p
|
||||
%strong Race:
|
||||
= @recipient.race
|
||||
|
||||
- if @recipient.ethnicity.present?
|
||||
%p
|
||||
%strong Ethnicity:
|
||||
= @recipient.ethnicity
|
||||
|
||||
- if @recipient.home_language_id.present?
|
||||
%p
|
||||
%strong Home language:
|
||||
= @recipient.home_language_id
|
||||
|
||||
- if @recipient.income.present?
|
||||
%p
|
||||
%strong Income:
|
||||
= @recipient.income
|
||||
|
||||
%p
|
||||
%strong Opted out:
|
||||
= @recipient.opted_out
|
||||
|
||||
= link_to 'Edit', edit_school_recipient_path(@school, @recipient)
|
||||
|
|
||||
= link_to 'Back', school_path(@school)
|
||||
|
||||
|
||||
|
||||
%br
|
||||
%br
|
||||
%br
|
||||
%h4 Attempts
|
||||
%table{style: 'width: 100%;'}
|
||||
%tbody
|
||||
%thead{style: 'font-weight: bold;'}
|
||||
%th Date
|
||||
%th Question
|
||||
%th Response
|
||||
- @recipient.attempts.each do |attempt|
|
||||
%tr.attempt
|
||||
%td
|
||||
= attempt.sent_at.strftime('%x') if attempt.sent_at.present?
|
||||
%td= link_to truncate(attempt.question.text, length: 60), [@school, attempt.question], title: attempt.question.text
|
||||
%td= "(#{attempt.answer_index}) #{attempt.response}"
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@
|
|||
%th{colspan: 2} Actions
|
||||
- @school.recipients.each do |recipient|
|
||||
%tr.recipient
|
||||
%td= recipient.name
|
||||
%td= link_to recipient.name, [@school, recipient]
|
||||
%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?'})
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ Rails.application.routes.draw do
|
|||
end
|
||||
resources :schedules
|
||||
resources :categories, only: [:show]
|
||||
resources :questions, only: [:show]
|
||||
get :admin
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -55,9 +55,11 @@ RSpec.describe QuestionsController, type: :controller do
|
|||
|
||||
describe "GET #show" do
|
||||
it "assigns the requested question as @question" do
|
||||
school = School.create!(name: 'School')
|
||||
question = Question.create! valid_attributes
|
||||
get :show, params: {id: question.to_param}, session: valid_session
|
||||
get :show, params: {school_id: school.id, id: question.to_param}, session: valid_session
|
||||
expect(assigns(:question)).to eq(question)
|
||||
expect(assigns(:school)).to eq(school)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,9 @@ require 'rails_helper'
|
|||
|
||||
RSpec.describe "questions/show", type: :view do
|
||||
before(:each) do
|
||||
@school = assign(:school, School.create!(name: 'School'))
|
||||
@question = assign(:question, Question.create!(
|
||||
:text => "Text",
|
||||
:text => "Question Text",
|
||||
:option1 => "Option1",
|
||||
:option2 => "Option2",
|
||||
:option3 => "Option3",
|
||||
|
|
@ -15,7 +16,8 @@ RSpec.describe "questions/show", type: :view do
|
|||
|
||||
it "renders attributes in <p>" do
|
||||
render
|
||||
expect(rendered).to match(/Text/)
|
||||
expect(rendered).to match(/School/)
|
||||
expect(rendered).to match(/Question Text/)
|
||||
expect(rendered).to match(/Option1/)
|
||||
expect(rendered).to match(/Option2/)
|
||||
expect(rendered).to match(/Option3/)
|
||||
|
|
|
|||
|
|
@ -29,6 +29,5 @@ RSpec.describe "recipients/show", type: :view do
|
|||
expect(rendered).to match(/2/)
|
||||
expect(rendered).to match(/Income/)
|
||||
expect(rendered).to match(/false/)
|
||||
expect(rendered).to match(/#{@school.to_param}/)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue