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

Teacher homeschool feature #56

Merged
merged 29 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
76921c7
add homeschool BJC and dummy school
ArushC Apr 19, 2024
04c3b75
fixed the 'end' bug, which was due to badly indented code
ArushC Apr 19, 2024
088a3bc
in progress modification
ArushC Apr 19, 2024
14f2bf3
hopefully fixed everything now
ArushC Apr 19, 2024
ed7459d
fixed JS
ArushC Apr 19, 2024
02ed04e
further JS fix
ArushC Apr 19, 2024
cb86ce4
realize rails end bug actually WAS a bug
ArushC Apr 19, 2024
07631d2
rubocop fix
ArushC Apr 19, 2024
0243e0d
installed active_storage
ArushC Apr 19, 2024
30defdb
add upload files to frontend
ArushC Apr 19, 2024
13dde00
add JS to render upload file only when status is homeschool
ArushC Apr 19, 2024
3877239
got homeschool file upload working on backend and looking kind of ok …
ArushC Apr 19, 2024
e1d9ca6
got file upload feature working
ArushC Apr 21, 2024
417da08
added frontend styling for adding files
ArushC Apr 21, 2024
828a3a9
moved css from show.html.erb to stylesheets
ArushC Apr 21, 2024
837468e
factor teacher display into partial
ArushC Apr 21, 2024
e8653b4
support for adding MORE files
ArushC Apr 21, 2024
9eeb816
added uploaded files frontend
ArushC Apr 21, 2024
44777d5
aligned code
ArushC Apr 21, 2024
9016d22
fix nil error
ArushC Apr 22, 2024
79ac3f3
merged main into homeschool feature
ArushC Apr 23, 2024
47085fc
fix rails version issue
ArushC Apr 23, 2024
f095b1a
Merge branch 'main' of github.com:cs169/BJC-Teacher-Tracker-App into …
ArushC Apr 23, 2024
9fdec1b
uncomment the amazon s3 line
ArushC Apr 23, 2024
d0c8acf
remove dummy home school
ArushC Apr 23, 2024
698c894
added visibility tests
ArushC Apr 23, 2024
5eb5999
added another sad path test
ArushC Apr 23, 2024
3af102d
added file attachment test
ArushC Apr 23, 2024
2af33f6
finished homeschool feature
ArushC Apr 23, 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
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ gem "activerecord-import", require: false

gem "httparty", "~> 0.21.0"


gem "activestorage"
gem "country_select", "~> 8.0"

group :development do
Expand Down
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,7 @@ PLATFORMS

DEPENDENCIES
activerecord-import
activestorage
annotate
aws-sdk-s3
axe-core-cucumber
Expand Down
24 changes: 23 additions & 1 deletion app/controllers/teachers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ def edit
@readonly = !is_admin?
end

def remove_file
file_attachment = @teacher.files.find(params[:file_id])
file_attachment.purge
flash[:notice] = "File was successfully removed"
redirect_back fallback_location: teacher_path(@teacher)
end

def upload_file
@teacher.files.attach(params[:file])
redirect_back fallback_location: teacher_path(@teacher), notice: "File was successfully uploaded"
end

def update
load_school
ordered_schools
Expand All @@ -116,6 +128,7 @@ def update
return
end

attach_new_files_if_any
send_email_if_application_status_changed_and_email_resend_enabled

if fail_to_update
Expand Down Expand Up @@ -254,9 +267,18 @@ def load_school
@school ||= School.find_or_create_by(**unique_school_params)
end

def attach_new_files_if_any
if params.dig(:teacher, :more_files).present?
params[:teacher][:more_files].each do |file|
@teacher.files.attach(file)
end
end
end

def teacher_params
teacher_attributes = [:first_name, :last_name, :school, :status, :snap,
:more_info, :personal_website, :education_level, :school_id, languages: []]
:more_info, :personal_website, :education_level, :school_id, languages: [], files: [],
more_files: []]
admin_attributes = [:application_status, :request_reason, :skip_email]
teacher_attributes.push(*admin_attributes) if is_admin?

Expand Down
14 changes: 14 additions & 0 deletions app/javascript/styles/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,20 @@ body {
}
}

.btn-purple {
background-color: #8A2BE2; /* Light purple */
}

/* Style for the box around the file upload link */
.box-link {
display: inline-block;
padding: 5px 10px;
height: 40px;
border: 1px solid #ccc;
border-radius: 5px;
background-color: #f9f9f9;
}

.btn-blue {
background-color: #9dc0ee;
}
Expand Down
5 changes: 5 additions & 0 deletions app/models/teacher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ 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

has_many :email_addresses, dependent: :destroy
has_many_attached :files
has_many_attached :more_files
accepts_nested_attributes_for :email_addresses, allow_destroy: true

validates :first_name, :last_name, :status, presence: true
Expand Down Expand Up @@ -83,6 +85,7 @@ class Teacher < ApplicationRecord
developer: 6,
excite: 7,
middle_school_bjc: 8,
home_school_bjc: 9
}

# Always add to the bottom of the list!
Expand All @@ -96,6 +99,7 @@ class Teacher < ApplicationRecord
"I am a BJC curriculum or tool developer.",
"I am teaching with the ExCITE project",
"I am teaching Middle School BJC.",
"I am teaching homeschool with the BJC curriculum."
].freeze

# From an admin perspective, we want to know if a teacher has any **meaningful** change
Expand Down Expand Up @@ -150,6 +154,7 @@ def self.status_options
:excite,
:teals_teacher,
:teals_volunteer,
:home_school_bjc,
:other,
:developer,
]
Expand Down
2 changes: 1 addition & 1 deletion app/views/schools/_selectize_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="form-group">
<%= f.label :name, "Search for your school or add a new one", class: "label-required", for: "school_selectize" %>
<%= f.select :name,
options_for_select(@ordered_schools.collect(&:selectize_options)),
options_for_select( @ordered_schools.map(&:selectize_options)),
{prompt: "Enter the name or city of your school"},
{class: "select", id: "school_selectize" } %>
<%= javascript_pack_tag 'schools' %>
Expand Down
33 changes: 33 additions & 0 deletions app/views/teachers/_files_display.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<div class="col-sm-8">
<% if teacher.files.attached? %>
<% teacher.files.each do |file| %>
<div class='form-group row'>
<%= link_to file.filename.to_s, rails_blob_path(file), target: "_blank", class: "box-link" %>
<% if show_delete_file %>
<%= button_to "❌", remove_file_teacher_path(teacher, file_id: file.id), method: :delete, data: { confirm: "Are you sure you want to remove this file?" }, style: "width: 40px;", class: "box-link" %>
<% end %>
</div>
<% end %>
<% else %>
<p>No files attached yet.</p>
<% end %>

<!-- Add file button -->
<% if show_add_file %>
<%= form_tag(upload_file_teacher_path(teacher), method: :post, multipart: true, id: "file-upload-form") do %>
<%= file_field_tag :file, id: "file-upload-field", style: "display: none;" %>
<label for="file-upload-field" class="btn btn-primary btn-purple mr-2">Add a File</label>
<% end %>
<% end %>
</div>

<% if show_add_file %>
<script>
$(document).ready(function() {
$('#file-upload-field').on('change', function() {
// Submit the form when a file is selected
$('#file-upload-form').submit();
});
});
</script>
<% end %>
82 changes: 55 additions & 27 deletions app/views/teachers/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,35 @@ status ONLY IF the person viewing this page is an admin. %>
:status,
options_for_select(Teacher.status_options, teacher.status_before_type_cast),
{ include_blank: "Select an option" },
{ class: 'form-control', required: true, onchange: 'requireVolunteerHostTeacher();' }
{ class: 'form-control', required: true, onchange: 'listenForStatusOptionChange();' }
) %>
</div>
</div>

<!-- File upload input field -->
<% if is_new_teacher_page %>
<div class='form-group row' id = 'upload_file_field'>
<div class='col-12'>
<%= f.label :files, "Upload supporting files: " %>
<%= f.file_field :files, multiple: true, direct_upload: true %>
</div>
</div>
<% else %>
<!-- Note that edit teacher page CANNOT allow direct adding/removing
of files because the nested forms result in undefined
behavior in Rails, including random controller
actions getting called from unrelated submit buttons -->
<div class='form-group row' id = 'upload_file_field'>
<div class='col-12'>
<label for="uploaded_files">Supporting files:</label>
<%= render 'files_display', teacher: @teacher, show_add_file: false, show_delete_file: false %>
</div>
<div class='col-12'>
<%= f.label :more_files, "Upload More Files: " %>
<%= f.file_field :more_files, multiple: true, direct_upload: true %>
</div>
</div>
<% end %>
<div class='form-group row'>
<div class='col-12'>
<%= f.label :education_level, "What's your education level target?", class: "label-required" %>
Expand All @@ -117,37 +141,35 @@ status ONLY IF the person viewing this page is an admin. %>
multiple: true,
include_blank: "Select an option",
class: 'selectize', required: true
) %>
) %>
</div>
</div>



<div class='form-group row'>
<div class='col-12'>
<%= f.label :more_info, "More Information", class: "label-required" %>
<%= f.text_area :more_info, placeholder: "I applied for access because...",
class: "form-control", required: true, rows: "2" %>
<%= f.label :more_info, "More Information", class: "label-required" %>
<%= f.text_area :more_info, placeholder: "I applied for access because...",
class: "form-control", required: true, rows: "2" %>
</div>
<small class="col-12 form-text text-muted"><strong id='teacher-more-info-reminder'>Please tell us why you need access.</strong></small>
</div>
<%= f.hidden_field :school_id %>
</div>
<%= f.hidden_field :school_id %>
</div>

<div class='form-group form-input-group'>
<%= form_with model: @teacher.school, local: true do |school| %>
<h2>Your School</h2>
<%= render 'schools/selectize_form', f: school %>
<%# NO END HERE -- NOTE BELOW %>
</div>

<%= f.submit (f.object.new_record? ? 'Submit' : 'Update'), class: 'btn btn-primary' %>
<%# TWO ENDS MUST COME AFTER SUBMIT -- Rails bug??? %>
<div class='form-group form-input-group' id='school_container'>
<%= form_with model: @teacher.school, local: true do |school| %>
<h2>Your School</h2>
<%= render 'schools/selectize_form', f: school %>
</div>

<%= f.submit (f.object.new_record? ? 'Submit' : 'Update'), class: 'btn btn-primary' %>
<!-- This apparent Rails bug of requiring two ends after a submit is likely related
to the use of the nested forms (here, the school form inside the teacher form)
which can result in inexplicable, and sometimes undefined behavior -->
<% end %>
<% end %>

<script>

$(document).ready(function() {
$('.selectize').selectize({
plugins: ['remove_button'],
Expand All @@ -156,8 +178,9 @@ status ONLY IF the person viewing this page is an admin. %>
create: false
});
//on loading the page, immediately update the reason field depending on
//the value of the application status
//the value of the application status and check teacher status option
updateReasonField();
listenForStatusOptionChange();
});

//JS to update the text description for the denial/request reason input
Expand Down Expand Up @@ -186,16 +209,21 @@ status ONLY IF the person viewing this page is an admin. %>
}
}

function requireVolunteerHostTeacher() {
var status_val = $( "#teacher_status" ).val();

function listenForStatusOptionChange() {
var status_val = $("#teacher_status").val();
debugger;
<%# For TEALS volunteer, we also ask for the name of their host teacher. %>
if (status_val == 3) {
$('#upload_file_field').hide();
$("#teacher-more-info-reminder").text("Please tell us why you need access, and include the name of your host teacher here.");
}
else {
} else {
$("#teacher-more-info-reminder").text("Please tell us why you need access.");
}

<%# If homeschool, then show upload file field %>
if (status_val == 9) {
$('#upload_file_field').show();
} else {
$('#upload_file_field').hide();
}
}
}
</script>
6 changes: 6 additions & 0 deletions app/views/teachers/_teacher_info.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@
<%= teacher.display_application_status %>
</div>
</div>
<% if teacher.status_before_type_cast == 9 %>
<div class="row mb-4">
<div class="col-sm-4 font-weight-bold">Supporting Files:</div>
<%= render 'files_display', teacher: @teacher, show_add_file: true, show_delete_file: true %>
</div>
<% end %>
<div class="row mb-4">
<div class="col-sm-4 font-weight-bold">Personal or Course Website:</div>
<div class="col-sm-8">
Expand Down
2 changes: 1 addition & 1 deletion app/views/teachers/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
<hr/>
</div>
<div id='sign-up-form-container'>
<%= render 'form', teacher: @teacher, admin: @is_admin %>
<%= render 'form', teacher: @teacher, admin: @is_admin, is_new_teacher_page: false %>
</div>
2 changes: 1 addition & 1 deletion app/views/teachers/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<div id='sign-up-form-container'>
<%# If submission was successful, don't re-render the form. %>
<% if !flash[:success] %>
<%= render 'form', teacher: @teacher, admin: @is_admin %>
<%= render 'form', teacher: @teacher, admin: @is_admin, is_new_teacher_page: true %>
<% end %>
</div>
1 change: 1 addition & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# require "action_text/engine"
require "action_view/railtie"
# require "action_cable/engine"
require "active_storage/engine"
# require "sprockets/railtie"
# require "rails/test_unit/railtie"

Expand Down
2 changes: 1 addition & 1 deletion config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,5 @@

# Store files locally
# config.active_storage.service = :amazon
# config.active_storage.service = :local
config.active_storage.service = :local
end
2 changes: 1 addition & 1 deletion config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,5 @@
}

# Store files on Amazon S3. (Uncomment this when S3 is setup)
# config.active_storage.service = :amazon
config.active_storage.service = :amazon
end
2 changes: 1 addition & 1 deletion config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@
# config.action_view.annotate_rendered_view_with_filenames = true

# Store uploaded files on the local file system in a temporary directory.
# config.active_storage.service = :test
config.active_storage.service = :test
end
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
root to: "main#index"

resources :teachers do
post "upload_file", on: :member
resource :email_address, only: [:edit, :update, :create]
member do
post :resend_welcome_email
post :validate
post :deny
post :request_info
delete "remove_file", to: "teachers#remove_file"
end
collection { post :import }
end
Expand Down
2 changes: 1 addition & 1 deletion db/seed_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def self.create_schools
city: "Berkeley",
country: "US",
website: "https://bjc.berkeley.edu",
state: "CA",
state: "CA"
)
end

Expand Down
Loading
Loading