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

187227068 languages feature #304

Closed
wants to merge 72 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
f2ee4d2
Added frontend + db logic for country field in international schools
razztech Mar 8, 2024
1000250
Added some new frontend logic
razztech Mar 8, 2024
277e4de
Made changes to UI logic and updated tests
razztech Mar 11, 2024
43b0a3d
Update tests to use country dropdown
razztech Mar 11, 2024
bfe7a19
Merge pull request #39 from cs169/187129573-change-teacher-status
perryzjc Mar 11, 2024
f3cd0cd
All tests are passing
razztech Mar 11, 2024
dc852f3
Finished table country display
razztech Mar 11, 2024
fa48319
Added filtering with a different column
razztech Mar 11, 2024
fadef9a
Fixed rubocop
razztech Mar 11, 2024
1320a4e
Added state textfield test for international schools
razztech Mar 11, 2024
2fe9505
Merge branch 'main' into 187216522-international-schools
razztech Mar 12, 2024
b2c8e47
Fixed merge issues for cucumber tests
razztech Mar 12, 2024
c9df771
Added international school test, moved custom web step to form_steps.rb:
razztech Mar 12, 2024
5d8654b
Fixed rubocop
razztech Mar 12, 2024
6660f2e
Added country validation
razztech Mar 12, 2024
39123b8
Added new test for country
razztech Mar 12, 2024
d27c514
Changed UI based on Michael's feedback
razztech Mar 13, 2024
29de296
Made UI changes requested by Michael 2
razztech Mar 13, 2024
2c0363d
Changed from VanillaJS to jQuerry suggested by Arush
razztech Mar 13, 2024
5135d22
Merge pull request #38 from cs169/187186207/iter1-golden-repo-fixes
ArushC Mar 13, 2024
677bb6e
Further change from VanillaJS to jQuerry suggested by Arush
perryzjc Mar 13, 2024
772f2df
Add cucumber test for unexpected user behavior
perryzjc Mar 13, 2024
05d989e
fix glitch
ArushC Mar 14, 2024
a2ea667
resolve merge conflict
ArushC Mar 14, 2024
fa1155b
ok actually fixed merge conflict now
ArushC Mar 14, 2024
a155d65
no choice, have to resolve conflict manually
ArushC Mar 14, 2024
da5f122
Merge branch 'main' into 187216522-international-schools
ArushC Mar 14, 2024
71b92b6
Merge pull request #42 from cs169/187216522-international-schools
ArushC Mar 14, 2024
4af15e7
added languages dropdown without selectize
ArushC Mar 14, 2024
db87716
added selectize thingie
ArushC Mar 14, 2024
59eb515
fix migration to accept array typefor languages
ArushC Mar 14, 2024
0124653
link selectize to backend
ArushC Mar 14, 2024
b39901f
display languages on edit page and prevent creating new languages
ArushC Mar 14, 2024
3f190c3
admin update teacher now redirect to show teacher page
ArushC Mar 18, 2024
58abf8d
fix javascript to make state select required
ArushC Mar 18, 2024
7dd7452
standardize all form submission backend validation to have format 'An…
ArushC Mar 20, 2024
8244232
missed one
ArushC Mar 21, 2024
63b3a91
changed tests to reflect more informative error messages
ArushC Mar 21, 2024
1bab7b5
added two more tests
ArushC Mar 21, 2024
4f4d828
rubocop fix
ArushC Mar 21, 2024
f978204
fixed cucumber test bugs
ArushC Mar 21, 2024
291715c
added relevant cucumber step and reverted back to older version of code
ArushC Mar 22, 2024
ddce701
finished testing for languages feature and added backend validations
ArushC Mar 22, 2024
99623ba
uncommented out procfile
ArushC Apr 2, 2024
6f33d63
ok actually uncommented out this time
ArushC Apr 2, 2024
5853ab1
clean up comment
ArushC Apr 2, 2024
4e2b40c
make comment more formal
ArushC Apr 4, 2024
3484fb1
add equivalent of presence validation
ArushC Apr 5, 2024
8b96209
Merge branch 'beautyjoy:main' into 187216522-international-schools
cycomachead Apr 5, 2024
2ded341
Merge branch 'main' into 187216522-international-schools
cycomachead Apr 8, 2024
ef2d3c4
Removed empty lines
razztech Apr 8, 2024
ff543d6
Update email_template.feature
ArushC Apr 12, 2024
2e1c1d1
Update schools_controller.rb
ArushC Apr 12, 2024
d58eda9
fix cucumber tests
ArushC Apr 12, 2024
838c4c0
change new --> edit redirect for update school failure
ArushC Apr 12, 2024
b1fe2d5
actually fixed it now
ArushC Apr 12, 2024
66eb04c
it turns out I don't know how to spell the word 'occured'
ArushC Apr 12, 2024
6e46e5c
fixed another myterious cucumber test bug
ArushC Apr 12, 2024
f9388fc
remove country from teachers table
ArushC Apr 12, 2024
8ca3872
removed one unnecessary deletion
ArushC Apr 12, 2024
05df57c
update location method to display country
ArushC Apr 12, 2024
38b2ce1
update selectize options
ArushC Apr 12, 2024
8f831eb
revert placeholder
ArushC Apr 12, 2024
fb9e877
update location method to display country
ArushC Apr 12, 2024
4cf6fbc
update selectize options
ArushC Apr 12, 2024
92e5647
Merge branch '187216522-international-schools' of github.com:cs169/BJ…
ArushC Apr 12, 2024
eeea4ca
add back teachers to table to prevent cucumber bugs
ArushC Apr 12, 2024
fa97d32
make search_list change
ArushC Apr 13, 2024
c027698
added unique school params and DRY out code
ArushC Apr 13, 2024
f41d0b9
converted valid states list using country gem
ArushC Apr 13, 2024
1f682da
fixed rubocop
ArushC Apr 13, 2024
29b2e68
Merge branch '187216522-international-schools' into 187227068-languag…
ArushC Apr 15, 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 @@ -49,6 +49,9 @@ gem "activerecord-import", require: false

gem "httparty", "~> 0.21.0"


gem "country_select", "~> 8.0"

group :development do
gem "annotate"

Expand Down
6 changes: 6 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ GEM
coercible (1.0.0)
descendants_tracker (~> 0.0.1)
concurrent-ruby (1.2.3)
countries (5.7.2)
unaccent (~> 0.3)
country_select (8.0.3)
countries (~> 5.0)
crass (1.0.6)
cucumber (7.1.0)
builder (~> 3.2, >= 3.2.4)
Expand Down Expand Up @@ -528,6 +532,7 @@ GEM
concurrent-ruby (~> 1.0)
tzinfo-data (1.2021.5)
tzinfo (>= 1.0.0)
unaccent (0.4.0)
unicode-display_width (2.4.2)
version_gem (1.1.3)
virtus (2.0.0)
Expand Down Expand Up @@ -563,6 +568,7 @@ DEPENDENCIES
axe-core-cucumber
axe-core-rspec
bootsnap (>= 1.4.4)
country_select (~> 8.0)
cucumber-rails
database_cleaner
debug
Expand Down
17 changes: 17 additions & 0 deletions app/controllers/concerns/school_params.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

module SchoolParams
private
def unique_school_params
{
name: school_params[:name],
country: school_params[:country],
city: school_params[:city],
state: school_params[:state]
}
end

def school_params
params.require(:school).permit(:name, :country, :city, :state, :website, :grade_level, :school_type, :country, { tags: [] }, :nces_id)
end
end
4 changes: 2 additions & 2 deletions app/controllers/email_templates_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def update
flash[:success] = "Updated #{@email_template.title} template successfully."
redirect_to email_templates_path
else
flash.now[:alert] = "Failed to save #{@email_template.title} template: #{@email_template.errors.full_messages.join(", ")}"
flash.now[:alert] = "An error occurred: #{@email_template.errors.full_messages.join(", ")}"
render "edit"
end
end
Expand All @@ -36,7 +36,7 @@ def create
flash[:success] = "Created #{@email_template.title} successfully."
redirect_to email_templates_path
else
flash.now[:alert] = "Failed to submit information: #{@email_template.errors.full_messages.join(", ")}"
flash.now[:alert] = "An error occurred: #{@email_template.errors.full_messages.join(", ")}"
render "new"
end
end
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def create
flash[:success] = "Created #{@page.title} page successfully."
redirect_to action: "show", url_slug: @page.url_slug
else
flash.now[:alert] = "An error occurred! #{@page.errors.full_messages}"
flash.now[:alert] = "An error occurred: #{@page.errors.full_messages.join(", ")}"
render "edit"
end
end
Expand Down Expand Up @@ -58,7 +58,7 @@ def update
flash[:success] = "Updated #{@page.title} page successfully."
redirect_to pages_path
else
flash.now[:alert] = "An error occurred! #{@page.errors.full_messages.to_sentence}"
flash.now[:alert] = "An error occurred: #{@page.errors.full_messages.join(', ')}"
render "edit"
end
end
Expand Down
16 changes: 7 additions & 9 deletions app/controllers/schools_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

class SchoolsController < ApplicationController
include SchoolParams
before_action :require_admin

def index
Expand All @@ -12,11 +13,11 @@ def show
end

def search
School.all.collect { |school| ["#{school.name}, #{school.city}, #{school.state}", school.name] }
School.search_list
end

def create
@school = School.find_by(name: school_params[:name], city: school_params[:city], state: school_params[:state])
@school = School.find_by(**unique_school_params)
if @school
@school.assign_attributes(school_params)
else
Expand All @@ -27,7 +28,7 @@ def create
flash[:success] = "Created #{@school.name} successfully."
redirect_to schools_path
else
flash[:alert] = "Failed to submit information :("
flash[:alert] = "An error occurred: #{@school.errors.full_messages.join(', ')}"
render "new"
end
end
Expand All @@ -45,10 +46,11 @@ def update
@school = School.find(params[:id])
@school.assign_attributes(school_params)
if @school.save
flash[:success] = "Update #{@school.name} successfully."
flash[:success] = "Updated #{@school.name} successfully."
redirect_to school_path(@school)
else
render "edit", alert: "Failed to submit information :("
flash[:alert] = "An error occurred: #{@school.errors.full_messages.join(', ')}"
render "edit"
end
end

Expand All @@ -63,10 +65,6 @@ def destroy
end

private
def school_params
params.require(:school).permit(:name, :city, :state, :website, :grade_level, :school_type, { tags: [] }, :nces_id)
end

def load_ordered_schools
@ordered_schools ||= School.all.order(:name)
end
Expand Down
24 changes: 12 additions & 12 deletions app/controllers/teachers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
require "activerecord-import"

class TeachersController < ApplicationController
include SchoolParams
include CsvProcess

before_action :load_pages, only: [:new, :create, :edit, :update]
Expand Down Expand Up @@ -63,9 +64,10 @@ def create

load_school
if @school.new_record?
return unless params[:school]
@school = School.new(school_params)
unless @school.save
flash[:alert] = "An error occurred! #{@school.errors.full_messages}"
flash[:alert] = "An error occurred: #{@school.errors.full_messages.join(', ')}"
render "new" && return
end
end
Expand All @@ -81,7 +83,7 @@ def create
TeacherMailer.teacher_form_submission(@teacher).deliver_now
redirect_to root_path
else
redirect_to new_teacher_path, alert: "An error occurred while trying to save. #{@teacher.errors.full_messages}"
redirect_to new_teacher_path, alert: "An error occurred: #{@teacher.errors.full_messages.join(', ')}"
end
end

Expand All @@ -100,7 +102,10 @@ def update
@teacher.school = @school
else
@school.update(school_params) if school_params
@school.save!
unless @school.save
flash[:alert] = "An error occurred: #{@school.errors.full_messages.join(', ')}"
render "edit" && return
end
@teacher.school = @school
end
send_email_if_application_status_changed_and_email_resend_enabled
Expand All @@ -114,15 +119,15 @@ def update
end
if [email protected]
redirect_to edit_teacher_path(current_user.id),
alert: "Failed to update data. #{@teacher.errors.full_messages.to_sentence}"
alert: "An error occurred: #{@teacher.errors.full_messages.join(', ')}"
return
end
if [email protected]? && !current_user.admin?
TeacherMailer.form_submission(@teacher).deliver_now
TeacherMailer.teacher_form_submission(@teacher).deliver_now
end
if is_admin?
redirect_to teachers_path, notice: "Saved #{@teacher.full_name}"
redirect_to edit_teacher_path(current_user.id), notice: "Saved #{@teacher.full_name}"
return
else
@teacher.try_append_ip(request.remote_ip)
Expand Down Expand Up @@ -202,7 +207,7 @@ def load_school
if teacher_params[:school_id].present?
@school ||= School.find(teacher_params[:school_id])
end
@school ||= School.find_or_create_by(name: school_params[:name], city: school_params[:city], state: school_params[:state])
@school ||= School.find_or_create_by(**unique_school_params)
end

def teacher_params
Expand All @@ -212,12 +217,7 @@ def teacher_params
teacher_attributes << [:personal_email, :application_status,
:request_reason, :skip_email]
end
params.require(:teacher).permit(*teacher_attributes)
end

def school_params
return unless params[:school]
params.require(:school).permit(:name, :city, :state, :website, :grade_level, :school_type)
params.require(:teacher).permit(*teacher_attributes, languages: [])
end

def omniauth_data
Expand Down
2 changes: 1 addition & 1 deletion app/javascript/packs/datatables.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ $(function() {
$.fn.dataTable.ext.search.push((_, searchData) => {
let enabled = $('input:checkbox[name="statusFilter"]:checked').map((_i, el) => el.value).get();
// Include all rows when no checkboxes are selected.
return enabled.length === 0 || enabled.includes(searchData[6]);
return enabled.length === 0 || enabled.includes(searchData[7]);
});

let $tables = $('.js-dataTable').DataTable({
Expand Down
4 changes: 2 additions & 2 deletions app/javascript/packs/schools.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ let create_school = function (input, callback) {
$("#school_form").show();
toggle_required(['name', 'city', 'state', 'website'], true);
$(".btn-primary").show();
let oringial_school_id = $('#teacher_school_id').val();
let original_school_id = $('#teacher_school_id').val();
var reset_button = $("#close_button");
var name_input = $("#school_name");
// Unset the existing saved school id.
Expand All @@ -38,7 +38,7 @@ let create_school = function (input, callback) {
if (selectizeCallback != null) {
selectizeCallback();
selectizeCallback = null;
$('#teacher_school_id').val(oringial_school_id);
$('#teacher_school_id').val(original_school_id);
}
toggle_required(['name', 'city', 'state', 'website'], true);
$("#school_form").hide();
Expand Down
4 changes: 2 additions & 2 deletions app/models/email_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class EmailTemplate < ApplicationRecord
validates :title,
inclusion: TeacherMailer.instance_methods(false).map { |method| method.to_s.titlecase },
if: -> { self.required? }
validates :body, presence: { message: "cannot be blank" }
validates :to, presence: { message: "cannot be blank" }
validates :body, presence: true
validates :to, presence: true

before_destroy :prevent_deleting_required_emails

Expand Down
28 changes: 21 additions & 7 deletions app/models/school.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#
# id :integer not null, primary key
# city :string
# country :string
# grade_level :integer
# lat :float
# lng :float
Expand All @@ -25,10 +26,11 @@
#

class School < ApplicationRecord
VALID_STATES = [ "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", "International"].freeze

validates :state, inclusion: { in: VALID_STATES }
validates :name, :city, :state, :website, presence: true
VALID_STATES = ISO3166::Country["US"].subdivisions.keys.freeze
validates :name, :city, :website, :country, presence: true
validates :country, inclusion: { in: ISO3166::Country.all.map(&:alpha2), message: "%{value} is not a valid country" }
validates :state, presence: true, if: -> { country == "US" }
validates :state, inclusion: { in: VALID_STATES }, if: -> { country == "US" }
validates_format_of :website, with: /.+\..+/, on: :create

before_save :update_gps_data, if: -> { lat.nil? || lng.nil? }
Expand Down Expand Up @@ -58,7 +60,7 @@ def website
end

def location
"#{city}, #{state}"
"#{city}, #{state}, #{country}"
end

# TODO: Consider renaming this.
Expand All @@ -75,11 +77,11 @@ def display_grade_level
end

def selectize_options
[name_location, to_json(only: [:id, :name, :city, :state, :website]) ]
[name_location, to_json(only: [:id, :name, :city, :state, :country, :website]) ]
end

def name_location
"#{name} (#{city}, #{state})"
"#{name} (#{city}, #{state}, #{country})"
end

def update_gps_data
Expand All @@ -98,6 +100,18 @@ def maps_marker_data
}
end

def format_school(data)
name, city, state, country = data
country_str = country == "US" ? "" : ", #{country}"
"#{name} (#{city}, #{state}#{country_str})"
end

def self.search_list
School.pluck(:name, :city, :state, :country).map do |data|
format_school(data)
end
end

def self.grade_level_options
School.grade_levels.map { |key, _val| [key.to_s.titlecase, key] }
end
Expand Down
23 changes: 23 additions & 0 deletions app/models/teacher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# 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
Expand All @@ -37,10 +38,14 @@
# fk_rails_... (school_id => schools.id)
#
class Teacher < ApplicationRecord
WORLD_LANGUAGES = [ "Afrikaans", "Albanian", "Arabic", "Armenian", "Basque", "Bengali", "Bulgarian", "Catalan", "Cambodian", "Chinese (Mandarin)", "Croatian", "Czech", "Danish", "Dutch", "English", "Estonian", "Fiji", "Finnish", "French", "Georgian", "German", "Greek", "Gujarati", "Hebrew", "Hindi", "Hungarian", "Icelandic", "Indonesian", "Irish", "Italian", "Japanese", "Javanese", "Korean", "Latin", "Latvian", "Lithuanian", "Macedonian", "Malay", "Malayalam", "Maltese", "Maori", "Marathi", "Mongolian", "Nepali", "Norwegian", "Persian", "Polish", "Portuguese", "Punjabi", "Quechua", "Romanian", "Russian", "Samoan", "Serbian", "Slovak", "Slovenian", "Spanish", "Swahili", "Swedish ", "Tamil", "Tatar", "Telugu", "Thai", "Tibetan", "Tonga", "Turkish", "Ukrainian", "Urdu", "Uzbek", "Vietnamese", "Welsh", "Xhosa" ].freeze

validates :first_name, :last_name, :email, :status, presence: true
validates :email, uniqueness: true
validates :personal_email, uniqueness: true, if: -> { personal_email.present? }
validate :ensure_unique_personal_email, if: -> { email_changed? || personal_email_changed? }
validate :valid_languages
before_validation :sort_and_clean_languages

enum application_status: {
validated: "Validated",
Expand Down Expand Up @@ -163,6 +168,24 @@ def self.education_level_options
Teacher.education_levels.map { |sym, val| [sym.to_s.titlecase, val] }
end

def self.language_options
WORLD_LANGUAGES
end

def display_languages
languages.join(", ")
end

def valid_languages
!languages.empty? && languages.all? { |value| WORLD_LANGUAGES.include?(value) }
end

def sort_and_clean_languages
# Due to an identified bug in the Selectize plugin, an empty string is occasionally appended to the 'languages' list.
# To ensure data integrity, the following code removes any occurrences of empty strings from the list.
languages.sort!.reject!(&:blank?)
end

def display_education_level
if education_level_before_type_cast.to_i == -1
"?"
Expand Down
Loading
Loading