Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Professional Development Feature #48

Merged
merged 39 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
9210f08
Add starter code for pd frontend
perryzjc Mar 17, 2024
a194ed6
Backup work for frontend
perryzjc Mar 18, 2024
292e245
Backup frontend work
perryzjc Mar 18, 2024
4ee54b6
Back temporary work for frontend
perryzjc Mar 18, 2024
c0e5634
Rename workshop to professional developments
perryzjc Mar 20, 2024
12b28ac
Add new fields to mock model for pd
perryzjc Mar 20, 2024
21e8587
Implemented frontend for pd registrations
perryzjc Mar 20, 2024
669e1a2
Refract and clean up current frontend code
perryzjc Mar 20, 2024
8117d90
Merge pull request #44 from cs169/187242903/features/pd-frontend
JacksonXu33 Mar 22, 2024
edfedf5
crud, but no schema yet
JacksonXu33 Mar 23, 2024
1a6c703
add comments
JacksonXu33 Mar 30, 2024
08273f2
link registrations and pd and teacher
JacksonXu33 Mar 30, 2024
c9f448a
Merge pull request #46 from cs169/187227079/features/pd-backend
perryzjc Apr 2, 2024
3b1625f
Implement backend model & migration
perryzjc Apr 4, 2024
67dfaf5
Adjust frontend view to align with backend implementation
perryzjc Apr 4, 2024
abd5e9f
Implement backend controller
perryzjc Apr 4, 2024
fe605ba
Fix rubocop check
perryzjc Apr 4, 2024
12479b7
Fix title issue
perryzjc Apr 5, 2024
66ac823
Shorthand PD name on navbar
perryzjc Apr 5, 2024
d26123d
Remove past event validation
perryzjc Apr 5, 2024
788c1f5
Fix minor details on views
perryzjc Apr 5, 2024
27351f1
Add cucumber tests
perryzjc Apr 5, 2024
a6a1c01
Remove debugging msg
perryzjc Apr 6, 2024
9e122ed
Fix indexing & uniqueness check for pd
perryzjc Apr 6, 2024
700c87e
Add rspec tests
perryzjc Apr 6, 2024
dbeb705
Add admin check for pd registrations
perryzjc Apr 6, 2024
30294f6
Add email data migration script
perryzjc Apr 13, 2024
3788f17
Improve edge case handling
perryzjc Apr 13, 2024
0748edd
Merge branch 'main' of github.com:cs169/BJC-Teacher-Tracker-App into …
perryzjc Apr 13, 2024
122c23e
Remove email deletion
perryzjc Apr 15, 2024
26a8b6a
Add migration to drop teacher email relevant column
perryzjc Apr 15, 2024
41dacda
Add migration to drop teacher email relevant column
perryzjc Apr 15, 2024
02f32bb
Remove other dependencies on old teacher email column
perryzjc Apr 15, 2024
d6bb607
Merge branch '187384622/new-email-model' into pd-frontend+backend
perryzjc Apr 19, 2024
c909c95
Merge branch '187384622/new-email-model-pr2' into pd-frontend+backend
perryzjc Apr 19, 2024
45bc536
Merge branch '187384622/new-email-model-pr3' into pd-frontend+backend
perryzjc Apr 19, 2024
b0fa3d5
Fix cucumber tests to adapt new schema from new email address model
perryzjc Apr 19, 2024
436485f
Remove unused variable
perryzjc Apr 19, 2024
417adea
Add more rspec tests
perryzjc Apr 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,7 @@ group :test do
# Accessibility Testing
gem "axe-core-rspec"
gem "axe-core-cucumber"

# Test suite speedup
gem "rails-controller-testing"
end
5 changes: 5 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,10 @@ GEM
bundler (>= 1.15.0)
railties (= 6.1.7.6)
sprockets-rails (>= 2.0.0)
rails-controller-testing (1.0.5)
actionpack (>= 5.0.1.rc1)
actionview (>= 5.0.1.rc1)
activesupport (>= 5.0.1.rc1)
rails-dom-testing (2.2.0)
activesupport (>= 5.0.0)
minitest
Expand Down Expand Up @@ -595,6 +599,7 @@ DEPENDENCIES
puma (~> 5)
rack-mini-profiler (~> 2.0)
rails (= 6.1.7.6)
rails-controller-testing
rspec-rails
rubocop
rubocop-faker
Expand Down
72 changes: 72 additions & 0 deletions app/controllers/pd_registrations_controller.rb
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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This path was not tested

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."
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if possible, test

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."
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing test

end
end

def pd_registration_params
params.require(:pd_registration).permit(:teacher_id, :attended, :role, :professional_development_id)
end
end
61 changes: 61 additions & 0 deletions app/controllers/professional_developments_controller.rb
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."
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing test, i think arush mentioned this already?

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."
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test if possible

end

def professional_development_params
params.require(:professional_development).permit(:name, :city, :state, :country, :start_date, :end_date,
:grade_level)
end
end
3 changes: 2 additions & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def admin_nav_links
"Dashboard": dashboard_path,
"Schools": schools_path,
"Teachers": teachers_path,
"Email Templates": email_templates_path
"Email Templates": email_templates_path,
"PD": professional_developments_path,
}
end

Expand Down
40 changes: 40 additions & 0 deletions app/models/pd_registration.rb
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
59 changes: 59 additions & 0 deletions app/models/professional_development.rb
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
17 changes: 7 additions & 10 deletions app/models/teacher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@
# admin :boolean default(FALSE)
# application_status :string default("not_reviewed")
# education_level :integer default(NULL)
# email :string
# first_name :string
# ip_history :inet default([]), is an Array
# languages :string default(["\"English\""]), is an Array
# last_name :string
# last_session_at :datetime
# more_info :string
# personal_email :string
# personal_website :string
# session_count :integer default(0)
# snap :string
Expand All @@ -26,12 +24,9 @@
#
# Indexes
#
# index_teachers_on_email (email) UNIQUE
# index_teachers_on_email_and_first_name (email,first_name)
# index_teachers_on_email_and_personal_email (email,personal_email) UNIQUE
# index_teachers_on_school_id (school_id)
# index_teachers_on_snap (snap) UNIQUE WHERE ((snap)::text <> ''::text)
# index_teachers_on_status (status)
# index_teachers_on_school_id (school_id)
# index_teachers_on_snap (snap) UNIQUE WHERE ((snap)::text <> ''::text)
# index_teachers_on_status (status)
#
# Foreign Keys
#
Expand Down Expand Up @@ -59,6 +54,8 @@ class Teacher < ApplicationRecord
validates_inclusion_of :application_status, in: application_statuses.keys

belongs_to :school, counter_cache: true
has_many :professional_development_registrations
has_many :professional_developments, through: :professional_development_registrations

# Non-admin teachers whose application has neither been accepted nor denied
# It might or might not have been reviewed.
Expand Down Expand Up @@ -297,7 +294,7 @@ def email
def primary_email
# ||:email this code is temporary for this PR: https://github.com/cs169/BJC-Teacher-Tracker-App/pull/49
# to make sure at least original data in db still work and passed the existing tests
self[:email] || email_addresses.find_by(primary: true)&.email
email_addresses.find_by(primary: true)&.email
end

def personal_emails
Expand All @@ -308,6 +305,6 @@ def personal_emails
def non_primary_emails
# email_addresses.where(primary: false)&.pluck(:email)
# below code is temporary for current PR, to make sure the frontend same as before (only one personal email)
personal_email || email_addresses.where(primary: false)&.pluck(:email)&.first
email_addresses.where(primary: false)&.pluck(:email)&.first
end
end
Loading
Loading