Skip to content

Commit

Permalink
Little cleanup CS169L work
Browse files Browse the repository at this point in the history
  • Loading branch information
cycomachead authored May 10, 2024
1 parent dbd7417 commit 9efdd79
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 37 deletions.
8 changes: 1 addition & 7 deletions app/models/pd_registration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,5 @@ class PdRegistration < ApplicationRecord
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
self.teacher.full_name
end
5 changes: 1 addition & 4 deletions app/models/professional_development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@
# 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" },
validates :state, inclusion: { in: School::VALID_STATES, message: "%{value} is not a valid state" },
if: -> { country == "US" }
validate :end_date_after_start_date

Expand Down
5 changes: 1 addition & 4 deletions app/models/teacher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,7 @@ def short_application_status
end

def self.user_from_omniauth(omniauth)
teacher = EmailAddress.find_by(email: omniauth.email.downcase)&.teacher
teacher
EmailAddress.find_by(email: omniauth.email.downcase)&.teacher
end

def try_append_ip(ip)
Expand Down Expand Up @@ -292,8 +291,6 @@ def email
end

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
email_addresses.find_by(primary: true)&.email
end

Expand Down
14 changes: 5 additions & 9 deletions app/views/professional_developments/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
<%= provide(:h1, "Update #{@professional_development.name}") %>

<% if @professional_development.nil? %>
<p>Professional Development not found.</p>
<% else %>
<%= form_for @professional_development do |f| %>
<%= render 'professional_developments/form', f: f, professional_development: @professional_development %>
<div>
<%= f.submit 'Submit', {class: 'btn btn-primary', id: 'submit_button'} %>
</div>
<% end %>
<%= form_for @professional_development do |f| %>
<%= render 'professional_developments/form', f: f, professional_development: @professional_development %>
<div>
<%= f.submit 'Submit', {class: 'btn btn-primary', id: 'submit_button'} %>
</div>
<% end %>
4 changes: 1 addition & 3 deletions app/views/professional_developments/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= provide(:title, "BJC Schools") %>
<%= provide(:title, "BJC PD") %>
<%= provide(:header_button, "New Professional Development") %>

<table class="table table-striped js-dataTable">
Expand All @@ -9,8 +9,6 @@
<th scope="col">Start Date</th>
<th scope="col">End Date</th>
<th scope="col">Grade Level</th>
<!-- skip this for now-->
<!-- <th scope="col">Registration Open</th>-->
<th scope="col">Actions</th>
</tr>
</thead>
Expand Down
1 change: 0 additions & 1 deletion app/views/professional_developments/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@

function setFormActionForUpdate(pdId, registrationId) {
form.action = `/professional_developments/${pdId}/pd_registrations/${registrationId}`;
console.debug("Setting form action to:", form.action);
form.method = 'post';
ensureMethodInput('patch');
}
Expand Down
2 changes: 1 addition & 1 deletion app/views/schools/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@

} else {
stateTextfieldContainer.show();
stateSelect.removeAttr('required') //else make state select not required
stateSelect.removeAttr('required');
stateSelectContainer.hide();


Expand Down
15 changes: 7 additions & 8 deletions app/views/teachers/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ status ONLY IF the person viewing this page is an admin. %>
</div>
</div>

<%# For now... only admins can enter/edit personal emails. %>

<div class='form-group row'>
<div class='col-12'>
Expand Down Expand Up @@ -111,13 +110,13 @@ status ONLY IF the person viewing this page is an admin. %>
<%= f.label :languages, "What language(s) are spoken in the classroom?",
class: "label-required" %>
<%= f.select(
:languages,
options_for_select(Teacher.language_options, @teacher.languages),
{},
multiple: true,
include_blank: "Select an option",
class: 'selectize', required: true
) %>
:languages,
options_for_select(Teacher.language_options, @teacher.languages),
{},
multiple: true,
include_blank: "Select an option",
class: 'selectize', required: true
) %>
</div>
</div>

Expand Down

0 comments on commit 9efdd79

Please sign in to comment.