New Participant page fields edited except for working SSN formatting
This commit is contained in:
parent
294758c7b2
commit
d9873c0672
|
@ -0,0 +1,49 @@
|
|||
class ParticipantsController < ApplicationController
|
||||
before_action :set_participant, only: [:show, :edit, :update, :destroy]
|
||||
|
||||
def index
|
||||
@participants = Participant.all
|
||||
end
|
||||
|
||||
def show
|
||||
end
|
||||
|
||||
def new
|
||||
@participant = Participant.new
|
||||
end
|
||||
|
||||
def create
|
||||
@participant = Participant.new(participant_params)
|
||||
if @participant.save
|
||||
redirect_to @participant, notice: 'Participant was successfully created.'
|
||||
else
|
||||
render :new
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def update
|
||||
if @participant.update(participant_params)
|
||||
redirect_to @participant, notice: 'Participant was successfully updated.'
|
||||
else
|
||||
render :edit
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@participant.destroy
|
||||
redirect_to participants_url, notice: 'Participant was successfully destroyed.'
|
||||
end
|
||||
|
||||
private
|
||||
def set_participant
|
||||
@participant = Participant.find(params[:id])
|
||||
end
|
||||
|
||||
def participant_params
|
||||
params.require(:participant).permit(:name, :address, :phone, :email, :mci, :dob, :ssn, :gender, :employer_id)
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
module ParticipantsHelper
|
||||
end
|
|
@ -1,6 +1,3 @@
|
|||
// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails
|
||||
import "@hotwired/turbo-rails"
|
||||
import "controllers"
|
||||
|
||||
import Rails from '@rails/ujs';
|
||||
Rails.start();
|
||||
|
|
|
@ -5,40 +5,22 @@
|
|||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Obdev</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
|
||||
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
|
||||
<%= javascript_include_tag 'rails-ujs', 'data-turbolinks-track': 'reload' %>
|
||||
<%= csrf_meta_tags %>
|
||||
<%= javascript_importmap_tags %>
|
||||
|
||||
</head>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
||||
<!-- Navbar content -->
|
||||
</nav>
|
||||
|
||||
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
||||
<div class="container-fluid">
|
||||
<%= link_to 'Home', root_path, class: 'navbar-brand' %>
|
||||
<div class="collapse navbar-collapse">
|
||||
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
|
||||
<% if user_signed_in? %>
|
||||
<li class="nav-item">
|
||||
<%= link_to 'Sign Out', destroy_user_session_path, method: :delete, class: 'nav-link' %>
|
||||
</li>
|
||||
<% else %>
|
||||
<li class="nav-item">
|
||||
<%= link_to 'Sign In', new_user_session_path, class: 'nav-link' %>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
|
||||
<%= yield %>
|
||||
<%= yield %>
|
||||
|
||||
<p class="notice"><%= notice %></p>
|
||||
<p class="alert"><%= alert %></p>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>
|
||||
|
||||
</body>
|
||||
|
||||
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -0,0 +1,148 @@
|
|||
<%= form_with(model: participant, local: true) do |form| %>
|
||||
<% if participant.errors.any? %>
|
||||
<div id="error_explanation">
|
||||
<h2><%= pluralize(participant.errors.count, "error") %> prohibited this participant from being saved:</h2>
|
||||
|
||||
<ul>
|
||||
<% participant.errors.full_messages.each do |message| %>
|
||||
<li><%= message %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div class="field">
|
||||
<%= form.label :name %>
|
||||
<%= form.text_field :name %>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<%= form.label :address %>
|
||||
<%= form.text_area :address, rows: 1, class: 'auto-expand' %>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<%= form.label :phone %>
|
||||
<%= form.telephone_field :phone, id: 'phone-field' %>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="field">
|
||||
<%= form.label :email %>
|
||||
<%= form.email_field :email, id: 'email-field', required: true %>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<div class="field">
|
||||
<%= form.label :mci, 'MCI' %>
|
||||
<%= form.text_field :mci %>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<%= form.label :dob, 'Date of Birth' %>
|
||||
<%= form.date_field :dob %>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<%= form.label :ssn, 'Social Security Number' %>
|
||||
<%= form.text_field :ssn, id: 'ssn-field', maxlength: 11, placeholder: 'XXX-XX-XXXX' %>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<%= form.label :gender %>
|
||||
<%= form.select :gender, ['Unknown', 'Female', 'Male', 'Non-Binary', 'Other'] %>
|
||||
</div>
|
||||
|
||||
<div class="actions">
|
||||
<%= form.submit %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<%# This is to correct phone number entry %>
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
const phoneField = document.getElementById('phone-field');
|
||||
|
||||
phoneField.addEventListener('input', function() {
|
||||
let input = phoneField.value.replace(/\D/g, ''); // Remove non-numeric characters
|
||||
const inputLength = input.length;
|
||||
|
||||
if (inputLength > 3 && inputLength <= 6) {
|
||||
input = `(${input.slice(0, 3)}) ${input.slice(3)}`;
|
||||
} else if (inputLength > 6) {
|
||||
input = `(${input.slice(0, 3)}) ${input.slice(3, 6)}-${input.slice(6, 10)}`;
|
||||
}
|
||||
|
||||
phoneField.value = input;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
<%# This is for auto resizing the address field %>
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
const textareas = document.querySelectorAll('.auto-expand');
|
||||
|
||||
const resizeTextarea = function(el) {
|
||||
el.style.height = 'auto';
|
||||
el.style.height = (el.scrollHeight) + 'px';
|
||||
}
|
||||
|
||||
textareas.forEach(textarea => {
|
||||
textarea.addEventListener('input', function() {
|
||||
resizeTextarea(textarea);
|
||||
});
|
||||
|
||||
// Initial resize
|
||||
resizeTextarea(textarea);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<%# This is to require 1 @ sign for email entry %>
|
||||
<script>
|
||||
document.addEventListener('turbolinks:load', function() {
|
||||
const emailField = document.getElementById('email-field');
|
||||
|
||||
emailField.addEventListener('input', function() {
|
||||
const emailValue = emailField.value;
|
||||
const atSignCount = (emailValue.match(/@/g) || []).length;
|
||||
|
||||
if (atSignCount !== 1) {
|
||||
emailField.setCustomValidity("Email must contain exactly one '@' sign.");
|
||||
} else {
|
||||
emailField.setCustomValidity('');
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
<%# This is for Social Security formatting and # of digits %>
|
||||
<script>
|
||||
document.addEventListener('turbolinks:load', function() {
|
||||
const ssnField = document.getElementById('ssn-field');
|
||||
|
||||
ssnField.addEventListener('input', function(event) {
|
||||
let input = event.target.value.replace(/\D/g, ''); // Remove non-numeric characters
|
||||
if (input.length > 9) {
|
||||
input = input.substring(0, 9); // Limit to 9 digits
|
||||
}
|
||||
|
||||
let formattedSSN = '';
|
||||
for (let i = 0; i < input.length; i++) {
|
||||
if (i === 3 || i === 5) {
|
||||
formattedSSN += '-';
|
||||
}
|
||||
formattedSSN += input[i];
|
||||
}
|
||||
|
||||
event.target.value = formattedSSN;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
<h1>Edit Participant</h1>
|
||||
|
||||
<%= render 'form', participant: @participant %>
|
||||
|
||||
<%= link_to 'Show', @participant %> |
|
||||
<%= link_to 'Back to List', participants_path %>
|
|
@ -0,0 +1,27 @@
|
|||
<h1>Participants</h1>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Address</th>
|
||||
<!-- Add other participant attributes here -->
|
||||
<th colspan="3"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<% @participants.each do |participant| %>
|
||||
<tr>
|
||||
<td><%= participant.name %></td>
|
||||
<td><%= participant.address %></td>
|
||||
<!-- Display other participant attributes here -->
|
||||
<td><%= link_to 'Show', participant %></td>
|
||||
<td><%= link_to 'Edit', edit_participant_path(participant) %></td>
|
||||
<td><%= link_to 'Destroy', participant, method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<%= link_to 'New Participant', new_participant_path %>
|
|
@ -0,0 +1,8 @@
|
|||
<h1>New Participant</h1>
|
||||
|
||||
<%= render 'form', participant: @participant %>
|
||||
|
||||
<%= link_to 'Back to List', participants_path %>
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
<h1>Participant Details</h1>
|
||||
|
||||
<p>
|
||||
<strong>Name:</strong>
|
||||
<%= @participant.name %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<strong>Address:</strong>
|
||||
<%= @participant.address %>
|
||||
</p>
|
||||
|
||||
<!-- Repeat the above pattern for other attributes like phone, email, etc. -->
|
||||
|
||||
<%= link_to 'Edit', edit_participant_path(@participant) %> |
|
||||
<%= link_to 'Back to List', participants_path %>
|
|
@ -4,4 +4,5 @@ pin "application"
|
|||
pin "@hotwired/turbo-rails", to: "turbo.min.js", preload: true
|
||||
pin "@hotwired/stimulus", to: "stimulus.min.js"
|
||||
pin "@hotwired/stimulus-loading", to: "stimulus-loading.js"
|
||||
pin "auto_expand_textarea", to: "auto_expand_textarea.js"
|
||||
pin_all_from "app/javascript/controllers", under: "controllers"
|
||||
|
|
|
@ -9,6 +9,8 @@ Rails.application.routes.draw do
|
|||
root to: 'devise/sessions#new'
|
||||
end
|
||||
|
||||
resources :participants
|
||||
|
||||
|
||||
|
||||
get 'home/index'
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
require "test_helper"
|
||||
|
||||
class ParticipantsControllerTest < ActionDispatch::IntegrationTest
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
Loading…
Reference in New Issue