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

Add request more info feature as an admin #32

Merged
merged 8 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def page_params
# teacher_school_website: @teacher.school.website,
# piazza_password: Rails.application.secrets[:piazza_password],
# denial_reason: @denial_reason
# request_reason: @request_reason
# }.with_indifferent_access
# end

Expand Down
3 changes: 2 additions & 1 deletion app/controllers/teachers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def update
def request_info
@teacher.info_needed!
if !params[:skip_email].present?
TeacherMailer.request_info_email(@teacher, params[:denial_reason]).deliver_now
TeacherMailer.request_info_email(@teacher, params[:request_reason]).deliver_now
end
redirect_to root_path
end
Expand All @@ -146,6 +146,7 @@ def deny
@teacher.denied!
if !params[:skip_email].present?
# TODO: Update dropdown to select the email template.
puts params[:denial_reason]
TeacherMailer.deny_email(@teacher, params[:denial_reason]).deliver_now
end
redirect_to root_path
Expand Down
4 changes: 3 additions & 1 deletion app/mailers/teacher_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ def liquid_assigns
base_rules = {
bjc_password: Rails.application.secrets[:bjc_password],
piazza_password: Rails.application.secrets[:piazza_password],
denial_reason: @denial_reason
# TODO: Review if below two are needed, or can they be refractored?
denial_reason: @denial_reason,
request_reason: @request_reason
}
base_rules.merge!(@teacher.email_attributes)
base_rules.with_indifferent_access
Expand Down
4 changes: 4 additions & 0 deletions app/views/email_templates/_liquid_fields.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,9 @@
<td><code>{{denial_reason}}</code></td>
<td>(Only on denial emails.)</td>
</tr>
<tr>
<td><code>{{request_reason}}</code></td>
<td>(Only on request emails.)</td>
</tr>
</tbody>
</table>
98 changes: 56 additions & 42 deletions app/views/main/_deny_modal.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,25 @@
<h4 class="modal-title"></h4>
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
</div>
<!-- default action is deny, but it can be dynamically changed. Check the js at the bottom of this file -->
<%= form_tag deny_teacher_path(0), method: :post, class: "form-horizontal" do %>
<div class="modal-body">
<%= label_tag 'denial_reason', 'Reason', class: 'control-label' %>
<%= text_field_tag :denial_reason, params[:denial_reason], class: "form-control" %>
<!-- <div class="form-group">
<label for="reason-select">Reason for Denial (Select)</label>
<select id="reason-select" name="reason-select" class="form-control">
<option value="">Select a reason</option>
<option value="Incomplete Application">Incomplete Application</option>
<option value="Insufficient Experience">Insufficient Experience</option>
<option value="Unfavorable References">Unfavorable References</option>
</select>
</div> -->
<div class="form-check">
<%= check_box_tag :skip_email, 'skip_email', false, class: 'form-check-input' %>
<%= label_tag 'skip_email', 'Skip email notifcation?', class: 'form-check-label' %>
</div>
<%= hidden_field_tag :action_type, '', class: "form-control action-type" %>
<%= label_tag 'action_reason', 'Reason', class: 'control-label' %>
<%= text_field_tag :action_reason_placeholder, '', class: "form-control action-reason", id: "action_reason" %>
<!-- <div class="form-group">
<label for="reason-select">Reason for Denial (Select)</label>
<select id="reason-select" name="reason-select" class="form-control">
<option value="">Select a reason</option>
<option value="Incomplete Application">Incomplete Application</option>
<option value="Insufficient Experience">Insufficient Experience</option>
<option value="Unfavorable References">Unfavorable References</option>
</select>
</div> -->
<div class="form-check">
<%= check_box_tag :skip_email, 'skip_email', false, class: 'form-check-input' %>
<%= label_tag 'skip_email', 'Skip email notifcation?', class: 'form-check-label' %>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Cancel</button>
Expand All @@ -33,31 +35,43 @@
</div>

<script type="text/javascript">
let modal = $('.js-denialModal');
modal.on('shown.bs.modal', function (event) {
let button = $(event.relatedTarget);
let teacherId = button.data('teacher-id');
let teacherName = button.data('teacher-name');
let newAction = null;
let newTitle = null;
switch(button.data('modal-type')) {
case "deny":
newAction = `/teachers/${teacherId}/deny`;
newTitle = 'Deny ' + teacherName;
break;
case "request_info":
newAction = `/teachers/${teacherId}/request_info`;
newTitle = 'Request Info from ' + teacherName;
break;
default:
newAction = `/teachers/${teacherId}/deny`;
newTitle = 'Deny ' + teacherName;
}
modal.find('.form-horizontal').attr('action', newAction);
modal.find('.modal-title').text(newTitle);
});
modal.on('hidden.bs.modal', function () {
$('input[name="denial_reason"]').val('');
modal.find('.modal-title').text('');
});
let modal = $('.js-denialModal');
modal.on('shown.bs.modal', function (event) {
let button = $(event.relatedTarget); // Button that triggered the modal
let teacherId = button.data('teacher-id');
let teacherName = button.data('teacher-name');
let actionType = button.data('modal-type'); // Action type, e.g., "deny", "request_info"
let newAction, newTitle, inputName;

// Determine the action and title based on the button clicked
switch(actionType) {
case "deny":
newAction = `/teachers/${teacherId}/deny`;
newTitle = 'Deny ' + teacherName;
inputName = 'denial_reason'; // The dynamic part for the input's name attribute
break;
case "request_info":
newAction = `/teachers/${teacherId}/request_info`;
newTitle = 'Request Info from ' + teacherName;
inputName = 'request_reason'; // Change accordingly
break;
default:
newAction = `/teachers/${teacherId}/deny`;
newTitle = 'Deny ' + teacherName;
inputName = 'denial_reason'; // Fallback option
}

// Update the form's action and the modal's title
modal.find('.form-horizontal').attr('action', newAction);
modal.find('.modal-title').text(newTitle);

// Dynamically change the name attribute of the input field
modal.find('#action_reason').attr('name', inputName);
});

// Reset the input field when the modal is closed
modal.on('hidden.bs.modal', function () {
modal.find('#action_reason').val('').attr('name', 'action_reason_placeholder');
modal.find('.modal-title').text('');
});
</script>
110 changes: 55 additions & 55 deletions app/views/main/dashboard.html.erb
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
<% provide(:title, "BJC Teacher Dashboard") %>
<div class="requests-dashboard">
<h2>New Requests</h2>
<table class="table js-dataTable">
<thead class="thead-dark">
<tr>
<%= render 'teachers/table_headers' %>
<th scope="col">Actions</th>
</tr>
</thead>
<tbody>
<% @unreviewed_teachers.each do |teacher| %>
<tr>
<%= render 'teachers/teacher', teacher: teacher %>
<td>
<div class="btn-group" role="group" aria-label="Validate or Remove Teacher">
<%= button_to("✔️", validate_teacher_path(teacher.id),
class: 'btn-group btn btn-outline-success', type: 'button') %>
<!-- <span>
<table class="table js-dataTable">
<thead class="thead-dark">
<tr>
<%= render 'teachers/table_headers' %>
<th scope="col">Actions</th>
</tr>
</thead>
<tbody>
<% @unreviewed_teachers.each do |teacher| %>
<tr>
<%= render 'teachers/teacher', teacher: teacher %>
<td>
<div class="btn-group" role="group" aria-label="Validate or Remove Teacher">
<%= button_to("✔️", validate_teacher_path(teacher.id),
class: 'btn-group btn btn-outline-success', type: 'button') %>
<span>
<button class="btn btn-outline-warning" type="button" data-toggle="modal" data-target=".js-denialModal"
data-modal-type="request_info" data-teacher-id="<%= teacher.id %>" data-teacher-name="<%= teacher.full_name %>">
data-modal-type="request_info" data-teacher-id="<%= teacher.id %>" data-teacher-name="<%= teacher.full_name %>">
</button>
</span> -->
<span>
</span>
<span>
<button class="btn btn-outline-danger" type="button" data-toggle="modal" data-target=".js-denialModal"
data-modal-type="deny" data-teacher-id="<%= teacher.id %>" data-teacher-name="<%= teacher.full_name %>">
data-modal-type="deny" data-teacher-id="<%= teacher.id %>" data-teacher-name="<%= teacher.full_name %>">
</button>
</span>
</div>
</td>
</tr>
<% end %>
</tbody>
</table>
<% if @unreviewed_teachers.empty? %>
<div class="alert alert-success" role="alert">
<strong>No unreviewed forms!</strong>
</div>
</div>
</td>
</tr>
<% end %>
</tbody>
</table>
<% if @unreviewed_teachers.empty? %>
<div class="alert alert-success" role="alert">
<strong>No unreviewed forms!</strong>
</div>
<% end %>
</div>

<%= render 'deny_modal' %>
Expand All @@ -52,65 +52,65 @@
<h2>Course Statistics</h2>
<table class="table">
<thead class="thead-dark">
<tr>
<tr>
<th scope="col"> Status </th>
<th scope="col"> Count </th>
</tr>
</tr>
</thead>
<tbody>
<% @statuses.each do |key, value| %>
<% @statuses.each do |key, value| %>
<tr>
<td> <%= key.humanize.titlecase %> </td>
<td> <%= value %> </td>
</tr>
<% end %>
<% end %>
</tbody>
</table>
</table>
</div>

<div class="col-6">
<h2>School Statistics</h2>
<table class="table">
<thead class="thead-dark">
<tr>
<tr>
<th scope="col">School</th>
<th scope="col">Location</th>
<th scope="col">Teachers</th>
</tr>
</tr>
</thead>
<tbody>
<% @schools.each do |school| %>
<% @schools.each do |school| %>
<tr>
<td><%= link_to(school.name, school_path(school)) %></td>
<td><%= school.location %></td>
<td><%= school.teachers_count %></td>
</tr>
<% end %>
<% end %>
</tbody>
</table>
</div>
</div>

<script>
let map;
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
center: {lat: 39.50, lng: -98.35},
zoom: 4
});
let map;
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
center: {lat: 39.50, lng: -98.35},
zoom: 4
});

let school_data = <%= School.all_maps_data.html_safe %>;
for (let school of school_data) {
let marker = new google.maps.Marker({
position: school.position,
map: map
});
let infoWindow = new google.maps.InfoWindow({ content: school.name });
marker.addListener('click', () => { infoWindow.open(map, marker) });
let school_data = <%= School.all_maps_data.html_safe %>;
for (let school of school_data) {
let marker = new google.maps.Marker({
position: school.position,
map: map
});
let infoWindow = new google.maps.InfoWindow({ content: school.name });
marker.addListener('click', () => { infoWindow.open(map, marker) });
}
}
}
</script>

<script async defer
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyA9YjQt1uyBo0rEKe7UWMeW9GUryKtaMVo&callback=initMap">
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyA9YjQt1uyBo0rEKe7UWMeW9GUryKtaMVo&callback=initMap">
</script>
25 changes: 24 additions & 1 deletion db/seed_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,29 @@ module SeedData

DENY_EMAIL3

@request_info_email = <<-REQUEST_INFO_EMAIL
<p>Dear {{teacher_first_name}},</p>

<p>We hope this message finds you well. We're writing to you regarding your ongoing application with BJC. As part of our review process, we've identified that some additional information is required to move forward.</p>

<p><strong>Required Information:</strong><br>
We kindly ask you to provide the following details to complete your application:</p>
<p>{{ request_reason | strip_tags }}</p>

<p>To submit the requested information, please follow these steps:</p>
<ol>
<li>Log into your BJC account using your registered email and password.</li>
<li>Locate your current application and update the information.</li>
<li>Fill in the necessary details in the provided fields and submit the update.</li>
</ol>

<p>Thank you for your attention to this matter. We look forward to receiving the additional information and advancing your application process.</p>

<p>Warm regards,</p>
<p>[Your Name]</p>
REQUEST_INFO_EMAIL


def self.emails
[
{
Expand Down Expand Up @@ -95,7 +118,7 @@ def self.emails
subject: "Deny Email"
},
{
body: @basic_email_with_reason,
body: @request_info_email,
path: "teacher_mailer/request_info_email",
locale: nil,
handler: "liquid",
Expand Down
Loading
Loading