forked from beautyjoy/BJC-Teacher-Tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
1,398 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# frozen_string_literal: true | ||
|
||
class EmailAddressesController < ApplicationController | ||
before_action :require_login | ||
before_action :require_admin | ||
before_action :set_teacher | ||
|
||
def edit | ||
end | ||
|
||
def update | ||
if update_personal_emails | ||
redirect_to teacher_path(@teacher), notice: "Personal email addresses updated successfully." | ||
else | ||
flash.now[:alert] = "An error occurred: " + (@error_messages || "Unknown error") | ||
render :edit | ||
end | ||
end | ||
|
||
private | ||
def set_teacher | ||
@teacher = Teacher.find(params[:teacher_id]) | ||
end | ||
|
||
def update_personal_emails | ||
EmailAddress.transaction do | ||
params[:teacher][:email_addresses_attributes].each do |_, email_attr| | ||
if email_attr[:id].present? | ||
email = EmailAddress.find(email_attr[:id]) | ||
if email_attr[:_destroy] == "1" | ||
email.destroy! | ||
else | ||
email.update!(email: email_attr[:email]) | ||
end | ||
else | ||
@teacher.email_addresses.create!(email: email_attr[:email]) unless email_attr[:email].blank? | ||
end | ||
end | ||
end | ||
true | ||
rescue ActiveRecord::RecordInvalid => e | ||
@error_messages = e.record&.errors&.full_messages&.join(", ") | ||
@error_messages ||= "A validation error occurred, but no specific error details are available." | ||
false | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# frozen_string_literal: true | ||
|
||
class PdRegistrationsController < ApplicationController | ||
before_action :require_login | ||
before_action :require_admin | ||
before_action :set_pd_registration, only: [:show, :edit, :update, :destroy] | ||
before_action :set_professional_development, only: [:new, :create, :edit, :update, :destroy] | ||
|
||
def index | ||
end | ||
|
||
def show | ||
end | ||
|
||
def new | ||
@pd_registration = PdRegistration.new | ||
end | ||
|
||
def edit | ||
end | ||
|
||
def create | ||
@pd_registration = PdRegistration.new(pd_registration_params.merge( | ||
professional_development_id: @professional_development.id)) | ||
|
||
if @pd_registration.save | ||
redirect_to professional_development_path(@professional_development), | ||
notice: "Registration for professional development was successfully created." | ||
else | ||
flash.now[:alert] = @pd_registration.errors.full_messages.to_sentence | ||
render "professional_developments/show" | ||
end | ||
end | ||
|
||
def update | ||
if @pd_registration.update(pd_registration_params) | ||
redirect_to professional_development_path(@professional_development), | ||
notice: "Registration was successfully updated." | ||
else | ||
flash.now[:alert] = @pd_registration.errors.full_messages.to_sentence | ||
render "professional_developments/show" | ||
end | ||
end | ||
|
||
def destroy | ||
if @pd_registration.destroy | ||
redirect_to professional_development_path(@professional_development), | ||
notice: "Registration was successfully cancelled." | ||
else | ||
flash.now[:alert] = @pd_registration.errors.full_messages.to_sentence | ||
render "professional_developments/show" | ||
end | ||
end | ||
|
||
private | ||
def set_pd_registration | ||
@pd_registration = PdRegistration.find(params[:id]) | ||
rescue ActiveRecord::RecordNotFound | ||
redirect_to professional_development_path, alert: "Registration not found." | ||
end | ||
|
||
def set_professional_development | ||
@professional_development = ProfessionalDevelopment.find_by(id: params[:professional_development_id]) | ||
unless @professional_development | ||
redirect_to professional_developments_path, alert: "Professional Development not found." | ||
end | ||
end | ||
|
||
def pd_registration_params | ||
params.require(:pd_registration).permit(:teacher_id, :attended, :role, :professional_development_id) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# frozen_string_literal: true | ||
|
||
class ProfessionalDevelopmentsController < ApplicationController | ||
before_action :set_professional_development, only: [:show, :edit, :update, :destroy] | ||
before_action :require_login | ||
before_action :require_admin | ||
|
||
def index | ||
@professional_developments = ProfessionalDevelopment.all | ||
end | ||
|
||
def show | ||
end | ||
|
||
def new | ||
@professional_development = ProfessionalDevelopment.new | ||
end | ||
|
||
def edit | ||
end | ||
|
||
def create | ||
@professional_development = ProfessionalDevelopment.new(professional_development_params) | ||
|
||
if @professional_development.save | ||
redirect_to @professional_development, notice: "Professional development created successfully." | ||
else | ||
flash.now[:alert] = @professional_development.errors.full_messages.to_sentence | ||
render :new | ||
end | ||
end | ||
|
||
def update | ||
if @professional_development.update(professional_development_params) | ||
redirect_to @professional_development, notice: "Professional development updated successfully." | ||
else | ||
flash.now[:alert] = @professional_development.errors.full_messages.to_sentence | ||
render :edit | ||
end | ||
end | ||
|
||
def destroy | ||
if @professional_development.destroy | ||
redirect_to professional_developments_url, notice: "Professional development deleted successfully." | ||
else | ||
redirect_to professional_developments_url, alert: "Failed to delete professional development." | ||
end | ||
end | ||
|
||
private | ||
def set_professional_development | ||
@professional_development = ProfessionalDevelopment.find(params[:id]) | ||
rescue ActiveRecord::RecordNotFound | ||
redirect_to professional_developments_url, alert: "Professional development not found." | ||
end | ||
|
||
def professional_development_params | ||
params.require(:professional_development).permit(:name, :city, :state, :country, :start_date, :end_date, | ||
:grade_level) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# frozen_string_literal: true | ||
|
||
# == Schema Information | ||
# | ||
# Table name: pd_registrations | ||
# | ||
# id :bigint not null, primary key | ||
# attended :boolean default(FALSE) | ||
# role :string not null | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# professional_development_id :integer not null | ||
# teacher_id :integer not null | ||
# | ||
# Indexes | ||
# | ||
# index_pd_reg_on_teacher_id_and_pd_id (teacher_id,professional_development_id) UNIQUE | ||
# | ||
# Foreign Keys | ||
# | ||
# fk_rails_... (professional_development_id => professional_developments.id) | ||
# fk_rails_... (teacher_id => teachers.id) | ||
# | ||
class PdRegistration < ApplicationRecord | ||
belongs_to :teacher | ||
belongs_to :professional_development | ||
|
||
validates :teacher_id, uniqueness: { scope: :professional_development_id, message: "already has a registration for this PD" } | ||
validates :role, inclusion: { in: %w[leader attendee], message: "%{value} is not a valid role" } | ||
validates :attended, inclusion: { in: [true, false] } | ||
|
||
def teacher_name | ||
teacher = Teacher.find_by(id: teacher_id) | ||
if teacher.present? | ||
"#{teacher.first_name} #{teacher.last_name}" | ||
else | ||
"Teacher not found" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# frozen_string_literal: true | ||
|
||
# == Schema Information | ||
# | ||
# Table name: professional_developments | ||
# | ||
# id :bigint not null, primary key | ||
# city :string not null | ||
# country :string not null | ||
# end_date :date not null | ||
# grade_level :integer not null | ||
# name :string not null | ||
# start_date :date not null | ||
# state :string | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# | ||
class ProfessionalDevelopment < ApplicationRecord | ||
VALID_STATES = %w[AL AK AS AZ AR CA CO CT DE DC FM FL GA GU HI ID IL IN IA KS KY LA ME MH MD MA MI MN MS MO MT NE NV | ||
NH NJ NM NY NC ND MP OH OK OR PW PA PR RI SC SD TN TX UT VT VI VA WA WV WI WY].freeze | ||
|
||
validates :name, :city, :country, :start_date, :end_date, presence: true | ||
validates :state, presence: true, if: -> { country == "US" } | ||
validates :state, inclusion: { in: VALID_STATES, message: "%{value} is not a valid state" }, | ||
if: -> { country == "US" } | ||
validate :end_date_after_start_date | ||
|
||
enum grade_level: { | ||
elementary: 0, | ||
middle_school: 1, | ||
high_school: 2, | ||
community_college: 3, | ||
university: 4 | ||
} | ||
|
||
has_many :pd_registrations, dependent: :destroy | ||
has_many :teachers, through: :pd_registrations | ||
|
||
def location | ||
"#{city}, #{state}, #{country}" | ||
end | ||
|
||
def display_grade_level | ||
return "Unknown" if grade_level_before_type_cast.to_i == -1 | ||
|
||
grade_level.to_s.titlecase | ||
end | ||
|
||
def registration_open | ||
@professional_development.registration_open ? "Yes" : "No" | ||
end | ||
|
||
private | ||
def end_date_after_start_date | ||
return if end_date.blank? || start_date.blank? | ||
|
||
errors.add(:end_date, "must be after the start date") if end_date < start_date | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.