Skip to content

Commit

Permalink
Merge branch 'main' into about_text
Browse files Browse the repository at this point in the history
  • Loading branch information
Andres-L-Santiago committed Mar 5, 2024
2 parents 7d71d84 + 23fb37e commit 1fdd1d8
Show file tree
Hide file tree
Showing 62 changed files with 1,074 additions and 359 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
[![Maintainability](https://api.codeclimate.com/v1/badges/62f4dd4fb092b4211973/maintainability)](https://codeclimate.com/repos/65caed0abc0d27237b1794c9/maintainability)
![rubocop](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/barnden/c7b2d5e19079e12445b300407e383294/raw/badge.json)

**All project files in rails_root**

Links
- Deployed Application
- https://elrc-app-dfcfc7cd862b.herokuapp.com/
Expand Down
Binary file added documentation/Spring2024/Sprint1Retrospective.pdf
Binary file not shown.
Binary file added documentation/Spring2024/Sprint2Plan.pdf
Binary file not shown.
1 change: 1 addition & 0 deletions rails_root/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# ignore migration files

AllCops:
DisabledByDefault: false
Exclude:
- 'db/**/*'
- 'config/**/*'
Expand Down
3 changes: 3 additions & 0 deletions rails_root/.simplecov
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@

SimpleCov.start 'rails' do
enable_coverage :branch # see https://github.com/colszowka/simplecov#branch-coverage-ruby--25
add_filter '/app/jobs/'
add_filter '/app/mailers/'
add_filter '/app/channels/'
end
2 changes: 2 additions & 0 deletions rails_root/app/controllers/about_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# frozen_string_literal: true

# AboutController
class AboutController < ApplicationController
def index; end
end
71 changes: 71 additions & 0 deletions rails_root/app/controllers/survey_questions_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# frozen_string_literal: true

class SurveyQuestionsController < ApplicationController
before_action :set_survey_question, only: %i[show edit update destroy]

# GET /survey_questions or /survey_questions.json
def index
@survey_questions = SurveyQuestion.all
end

# GET /survey_questions/1 or /survey_questions/1.json
def show; end

# GET /survey_questions/new
def new
@survey_question = SurveyQuestion.new
end

# GET /survey_questions/1/edit
def edit; end

# POST /survey_questions or /survey_questions.json
def create
@survey_question = SurveyQuestion.new(survey_question_params)

respond_to do |format|
if @survey_question.save
format.html { redirect_to survey_question_url(@survey_question), notice: 'Survey question was successfully created.' }
format.json { render :show, status: :created, location: @survey_question }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @survey_question.errors, status: :unprocessable_entity }
end
end
end

# PATCH/PUT /survey_questions/1 or /survey_questions/1.json
def update
respond_to do |format|
if @survey_question.update(survey_question_params)
format.html { redirect_to survey_question_url(@survey_question), notice: 'Survey question was successfully updated.' }
format.json { render :show, status: :ok, location: @survey_question }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @survey_question.errors, status: :unprocessable_entity }
end
end
end

# DELETE /survey_questions/1 or /survey_questions/1.json
def destroy
@survey_question.destroy!

respond_to do |format|
format.html { redirect_to survey_questions_url, notice: 'Survey question was successfully destroyed.' }
format.json { head :no_content }
end
end

private

# Use callbacks to share common setup or constraints between actions.
def set_survey_question
@survey_question = SurveyQuestion.find(params[:id])
end

# Only allow a list of trusted parameters through.
def survey_question_params
params.require(:survey_question).permit(:text, :explanation, :section)
end
end
129 changes: 84 additions & 45 deletions rails_root/app/controllers/survey_responses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

# Controller for survey responses
class SurveyResponsesController < ApplicationController
before_action :set_survey_response, only: %i[show edit update destroy]
before_action :set_survey_data, only: %i[show edit update destroy]
before_action :set_survey_sections, only: %i[show edit update new]

# GET /survey_responses or /survey_responses.json
def index
Expand All @@ -15,39 +16,15 @@ def show; end
# GET /survey_responses/new
def new
@survey_response = SurveyResponse.new
@survey_sections = [
{
title: 'Part 1: Leadership Behavior - Management',
prompt: 'To what extent do you agree the following behaviors reflect your personal leadership behaviors?',
questions: %i[leads_by_example ability_to_juggle communicator]
},
{
title: 'Part 2: Leadership Behavior - Interpersonal',
prompt: 'To what extent do you agree the following behaviors reflect your personal leadership behaviors?',
questions: %i[lifelong_learner high_expectations cooperative empathetic people_oriented]
}
]
@questions = SurveyQuestion
end

# GET /survey_responses/1/edit
def edit
# FIXME: DRY
@survey_sections = [
{
title: 'Part 1: Leadership Behavior - Management',
prompt: 'To what extent do you agree the following behaviors reflect your personal leadership behaviors?',
questions: %i[leads_by_example ability_to_juggle communicator]
},
{
title: 'Part 2: Leadership Behavior - Interpersonal',
prompt: 'To what extent do you agree the following behaviors reflect your personal leadership behaviors?',
questions: %i[lifelong_learner high_expectations cooperative empathetic people_oriented]
}
]
end
def edit; end

# POST /survey_responses or /survey_responses.json
def create
# If any of the survey_response_params values are nil, then the form is invalid
if survey_response_params.values.any? { |value| value.nil? || value.empty? }
respond_to do |format|
format.html do
Expand All @@ -56,11 +33,35 @@ def create
format.json { render json: { error: 'invalid form' }, status: :unprocessable_entity }
end
else
@survey_response = SurveyResponse.new(survey_response_params)
begin
# FIXME: Validation
profile = get_user_profile_from_params(survey_response_params)
# puts "profile: #{profile.inspect}"
rescue ActiveRecord::RecordNotFound
return respond_with_error 'invalid user_id'
end
@survey_response = SurveyResponse.new(profile:)
# puts "survey_response: #{@survey_response.inspect}"

# puts "survey_response_params: #{survey_response_params.inspect}"
survey_response_params.each do |question_id, choice|
next if question_id == 'user_id'

# puts "question_id: #{question_id}, choice: #{choice}"

# print all the questions in the database
# puts "SurveyQuestion.all: #{SurveyQuestion.all.inspect}"

# FIXME: Validation
question = SurveyQuestion.where(id: question_id).first!
# puts "question: #{question.inspect}"
SurveyAnswer.create(choice:, question:, response: @survey_response)
end

respond_to do |format|
if @survey_response.save
format.html do
puts 'survey response created successfully'
redirect_to survey_response_url(@survey_response), notice: 'Survey response was successfully created.'
end
format.json { render :show, status: :created, location: @survey_response }
Expand All @@ -72,22 +73,33 @@ def create

# PATCH/PUT /survey_responses/1 or /survey_responses/1.json
def update
if survey_response_params.values.any?(&:nil?)
respond_to do |format|
format.html do
redirect_to edit_survey_response_url(@survey_response), notice: 'invalid form', status: :unprocessable_entity
return respond_with_error 'invalid form' if survey_response_params.values.any?(&:nil?)

begin
# FIXME: Validation
get_user_profile_from_params(survey_response_params)
rescue ActiveRecord::RecordNotFound
return respond_with_error 'invalid user id'
end

respond_to do |format|
survey_response_params.each do |question_id, choice|
next if question_id == 'user_id'

begin
# FIXME: Validation
question = SurveyQuestion.where(id: question_id).first!
answer = SurveyAnswer.where(question:, response: @survey_response).first!
rescue ApplicationRecord::RecordNotFound
return respond_with_error 'invalid question or answer'
end
format.json { render json: { error: 'invalid form' }, status: :unprocessable_entity }

answer.update(choice:)
end
else
respond_to do |format|
if @survey_response.update(survey_response_params)
format.html do
redirect_to survey_response_url(@survey_response), notice: 'Survey response was successfully updated.'
end
format.json { render :show, status: :ok, location: @survey_response }

end
format.html do
redirect_to survey_response_url(@survey_response), notice: 'Survey response was successfully updated.'
format.json { render :show, status: :ok, location: @survey_response }
end
end
end
Expand All @@ -105,13 +117,40 @@ def destroy
private

# Use callbacks to share common setup or constraints between actions.
def set_survey_response
def set_survey_data
@survey_response = SurveyResponse.find(params[:id])
@questions = @survey_response.questions
end

def set_survey_sections
@sections = [
{
title: 'Part 1: Leadership Behavior - Management',
prompt: 'To what extent do you agree the following behaviors reflect your personal leadership behaviors?'
},
{
title: 'Part 2: Leadership Behavior - Interpersonal',
prompt: 'To what extent do you agree the following behaviors reflect your personal leadership behaviors?'
}
]
end

def get_user_profile_from_params(params)
SurveyProfile.where(user_id: params[:user_id]).first!
# params.delete(:user_id)
end

def respond_with_error(message, status = :unprocessable_entity)
respond_to do |format|
format.html do
redirect_to new_survey_response_url, notice: message, status:
end
format.json { render json: { error: message }, status: }
end
end

# Only allow a list of trusted parameters through.
def survey_response_params
params.require(:survey_response).permit(:user_id, :leads_by_example, :ability_to_juggle, :communicator,
:lifelong_learner, :high_expectations, :cooperative, :empathetic, :people_oriented)
params.require(:survey_response).permit! # FIXME: Figure out how to use strong params with new model
end
end
3 changes: 1 addition & 2 deletions rails_root/app/helpers/home_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ def greeting_message
'Good afternoon!'
when 18..23, 0..4
'Good evening!'
else
'Hello!'

end
end
end
4 changes: 4 additions & 0 deletions rails_root/app/helpers/survey_questions_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

module SurveyQuestionsHelper
end
10 changes: 4 additions & 6 deletions rails_root/app/helpers/survey_responses_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
module SurveyResponsesHelper
# method to calculate the average score of a survey response
def average_score(survey_response)
score_fields = %i[leads_by_example ability_to_juggle communicator lifelong_learner high_expectations
cooperative empathetic people_oriented]
scores = score_fields.map { |field| survey_response.send(field) }
scores.sum.to_f / scores.size
# returns the average score of the survey response
survey_response.answers.average(:choice).to_f
end

# method to format the date of a survey response
Expand All @@ -17,7 +15,7 @@ def formatted_date(survey_response)

# method to find the user of a survey response
def user_of_response(survey_response)
# returns user_id of the survey response
survey_response.user_id
# returns profile_id of the survey response
survey_response.profile_id
end
end
4 changes: 1 addition & 3 deletions rails_root/app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# frozen_string_literal: true

# rubocop:disable Style/Documentation

# ApplicationMailer
class ApplicationMailer < ActionMailer::Base
default from: '[email protected]'
layout 'mailer'
end
# rubocop:enable Style/Documentation
9 changes: 9 additions & 0 deletions rails_root/app/models/survey_answer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

class SurveyAnswer < ApplicationRecord
belongs_to :question,
class_name: 'SurveyQuestion'

belongs_to :response,
class_name: 'SurveyResponse'
end
4 changes: 4 additions & 0 deletions rails_root/app/models/survey_profile.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# frozen_string_literal: true

class SurveyProfile < ApplicationRecord
has_many :responses,
foreign_key: :profile_id,
class_name: 'SurveyResponse',
dependent: :destroy
end
4 changes: 4 additions & 0 deletions rails_root/app/models/survey_question.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class SurveyQuestion < ApplicationRecord
end
13 changes: 13 additions & 0 deletions rails_root/app/models/survey_response.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
# frozen_string_literal: true

class SurveyResponse < ApplicationRecord
has_many :answers,
foreign_key: :response_id,
class_name: 'SurveyAnswer',
dependent: :delete_all

validates_associated :answers

has_many :questions,
class_name: 'SurveyQuestion',
through: :answers

belongs_to :profile,
class_name: 'SurveyProfile'
end
Loading

0 comments on commit 1fdd1d8

Please sign in to comment.