From d4f7e64906b2d5d08fd35ac5ad69e2a7b588f81e Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 17 Jan 2024 01:21:20 -0600 Subject: [PATCH] All associated Worker pages have been created (need to edit fields and look) --- app/controllers/employers_controller.rb | 59 +++++++++ app/controllers/workers_controller.rb | 47 ++++++++ app/helpers/employers_helper.rb | 2 + app/helpers/workers_helper.rb | 2 + app/javascript/packs/application.js | 6 +- app/views/employers/_form.html.erb | 99 +++++++++++++++ app/views/employers/edit.html.erb | 10 ++ app/views/employers/index.html.erb | 39 ++++++ app/views/employers/new.html.erb | 5 + app/views/employers/show.html.erb | 48 ++++++++ app/views/participants/_form.html.erb | 24 +--- app/views/workers/_form.html.erb | 114 ++++++++++++++++++ app/views/workers/edit.html.erb | 6 + app/views/workers/index.html.erb | 36 ++++++ app/views/workers/new.html.erb | 5 + app/views/workers/show.html.erb | 33 +++++ config/routes.rb | 3 + test/controllers/employers_controller_test.rb | 7 ++ test/controllers/workers_controller_test.rb | 7 ++ 19 files changed, 527 insertions(+), 25 deletions(-) create mode 100644 app/controllers/employers_controller.rb create mode 100644 app/controllers/workers_controller.rb create mode 100644 app/helpers/employers_helper.rb create mode 100644 app/helpers/workers_helper.rb create mode 100644 app/views/employers/_form.html.erb create mode 100644 app/views/employers/edit.html.erb create mode 100644 app/views/employers/index.html.erb create mode 100644 app/views/employers/new.html.erb create mode 100644 app/views/employers/show.html.erb create mode 100644 app/views/workers/_form.html.erb create mode 100644 app/views/workers/edit.html.erb create mode 100644 app/views/workers/index.html.erb create mode 100644 app/views/workers/new.html.erb create mode 100644 app/views/workers/show.html.erb create mode 100644 test/controllers/employers_controller_test.rb create mode 100644 test/controllers/workers_controller_test.rb diff --git a/app/controllers/employers_controller.rb b/app/controllers/employers_controller.rb new file mode 100644 index 0000000..c9cc066 --- /dev/null +++ b/app/controllers/employers_controller.rb @@ -0,0 +1,59 @@ +class EmployersController < ApplicationController + before_action :set_employer, only: [:show, :edit, :update, :destroy] + + # GET /employers + def index + @employers = Employer.all + end + + # GET /employers/:id + def show + end + + # GET /employers/new + def new + @employer = Employer.new + end + + # POST /employers + def create + @employer = Employer.new(employer_params) + if @employer.save + redirect_to @employer, notice: 'Employer was successfully created.' + else + render :new + end + end + + # GET /employers/:id/edit + def edit + end + + # PATCH/PUT /employers/:id + def update + if @employer.update(employer_params) + redirect_to @employer, notice: 'Employer was successfully updated.' + else + render :edit + end + end + + # DELETE /employers/:id + def destroy + @employer = Employer.find(params[:id]) + @employer.destroy + redirect_to employers_url, notice: 'Employer was successfully destroyed.' + end + + + private + + def set_employer + @employer = Employer.find(params[:id]) + end + + def employer_params + params.require(:employer).permit(:name, :address, :phone, :email, :tin, :dob, :ssn, :gender) + end + end + \ No newline at end of file diff --git a/app/controllers/workers_controller.rb b/app/controllers/workers_controller.rb new file mode 100644 index 0000000..2fe857c --- /dev/null +++ b/app/controllers/workers_controller.rb @@ -0,0 +1,47 @@ +class WorkersController < ApplicationController + def index + @workers = Worker.all + end + + def show + @worker = Worker.find(params[:id]) + end + + def new + @worker = Worker.new + end + + def create + @worker = Worker.new(worker_params) + if @worker.save + redirect_to @worker + else + render :new + end + end + + def edit + @worker = Worker.find(params[:id]) + end + + def update + @worker = Worker.find(params[:id]) + if @worker.update(worker_params) + redirect_to @worker + else + render :edit + end + end + + def destroy + @worker = Worker.find(params[:id]) + @worker.destroy + redirect_to workers_path + end + + private + def worker_params + params.require(:worker).permit(:name, :address, :phone, :email, :dob, :ssn, :gender) + end + end + \ No newline at end of file diff --git a/app/helpers/employers_helper.rb b/app/helpers/employers_helper.rb new file mode 100644 index 0000000..37e5444 --- /dev/null +++ b/app/helpers/employers_helper.rb @@ -0,0 +1,2 @@ +module EmployersHelper +end diff --git a/app/helpers/workers_helper.rb b/app/helpers/workers_helper.rb new file mode 100644 index 0000000..34b8cb0 --- /dev/null +++ b/app/helpers/workers_helper.rb @@ -0,0 +1,2 @@ +module WorkersHelper +end diff --git a/app/javascript/packs/application.js b/app/javascript/packs/application.js index 8f0b644..2fcfe96 100644 --- a/app/javascript/packs/application.js +++ b/app/javascript/packs/application.js @@ -1,3 +1,5 @@ -import "@hotwired/turbo-rails" -import "controllers" +import Rails from "@rails/ujs"; +import "@hotwired/turbo-rails"; +import "controllers"; +Rails.start(); diff --git a/app/views/employers/_form.html.erb b/app/views/employers/_form.html.erb new file mode 100644 index 0000000..d7f7cb3 --- /dev/null +++ b/app/views/employers/_form.html.erb @@ -0,0 +1,99 @@ +<%= form_with(model: employer, local: true) do |form| %> + <% if employer.errors.any? %> +
+

<%= pluralize(employer.errors.count, "error") %> prohibited this employer from being saved:

+ +
+ <% end %> + +
+ <%= form.label :name %> + <%= form.text_field :name %> +
+ + +
+ <%= form.label :address %> + <%= form.text_area :address, rows: 1, class: 'auto-expand' %> +
+ +
+ <%= form.label :phone %> + <%= form.telephone_field :phone, id: 'phone-field' %> +
+ +
+ <%= form.label :email %> + <%= form.email_field :email, id: 'email-field', required: true %> +
+ +
+ <%= form.label :tin, 'TIN' %> + <%= form.text_field :tin, maxlength: 9 %> +
+ +
+ <%= form.label :dob, 'Date of Birth' %> + <%= form.date_field :dob %> +
+ +
+ <%= form.label :ssn, 'Social Security Number' %> + <%= form.text_field :ssn, id: 'ssn-field', maxlength: 11, placeholder: 'XXX-XX-XXXX' %> +
+ +
+ <%= form.label :gender %> + <%= form.select :gender, ['Unknown', 'Female', 'Male', 'Non-Binary', 'Other'] %> +
+ +
+ <%= form.submit %> +
+ <% end %> + + + <%# This is to correct phone number entry %> + + +<%# This is for auto resizing the address field %> + \ No newline at end of file diff --git a/app/views/employers/edit.html.erb b/app/views/employers/edit.html.erb new file mode 100644 index 0000000..9325784 --- /dev/null +++ b/app/views/employers/edit.html.erb @@ -0,0 +1,10 @@ +

Edit Employer

+ +<%= render 'form', employer: @employer %> + +<%= link_to 'Show', @employer %> | +<%= link_to 'Back to List', employers_path %> +<%= link_to 'Destroy', @employer, method: :delete, data: { confirm: 'Are you sure?', turbo: 'false' } %> + + + diff --git a/app/views/employers/index.html.erb b/app/views/employers/index.html.erb new file mode 100644 index 0000000..5dca4bc --- /dev/null +++ b/app/views/employers/index.html.erb @@ -0,0 +1,39 @@ +

Employers

+ +<%= link_to 'New Employer', new_employer_path %> + + + + + + + + + + + + + + + + + <% @employers.each do |employer| %> + + + + + + + + + + + + <% end %> + +
NameAddressPhoneEmailTINDOBSSNGenderActions
<%= employer.name %><%= employer.address %><%= employer.phone %><%= employer.email %><%= employer.tin %><%= employer.dob %><%= employer.ssn %><%= employer.gender %> + <%= link_to 'Show', employer %> + <%= link_to 'Edit', edit_employer_path(employer) %> + <%= link_to 'Destroy', @employer, method: :delete, data: { confirm: 'Are you sure?', turbo: 'false' } %> + +
diff --git a/app/views/employers/new.html.erb b/app/views/employers/new.html.erb new file mode 100644 index 0000000..2498a9c --- /dev/null +++ b/app/views/employers/new.html.erb @@ -0,0 +1,5 @@ +

New Employer

+ +<%= render 'form', employer: @employer %> + +<%= link_to 'Back to List', employers_path %> diff --git a/app/views/employers/show.html.erb b/app/views/employers/show.html.erb new file mode 100644 index 0000000..fe12b3a --- /dev/null +++ b/app/views/employers/show.html.erb @@ -0,0 +1,48 @@ +

Employer Details

+ +

+ Name: + <%= @employer.name %> +

+ +

+ Address: + <%= @employer.address %> +

+ +

+ Phone: + <%= @employer.phone %> +

+ +

+ Email: + <%= @employer.email %> +

+ +

+ TIN: + <%= @employer.tin %> +

+ +

+ Date of Birth: + <%= @employer.dob %> +

+ +

+ SSN: + <%= @employer.ssn %> +

+ +

+ Gender: + <%= @employer.gender %> +

+ +<%= link_to 'Edit', edit_employer_path(@employer) %> | +<%= link_to 'Back to List', employers_path %> +<%= link_to 'Destroy', @employer, method: :delete, data: { confirm: 'Are you sure?', turbo: 'false' } %> + + + diff --git a/app/views/participants/_form.html.erb b/app/views/participants/_form.html.erb index 236c3cb..9d709a2 100644 --- a/app/views/participants/_form.html.erb +++ b/app/views/participants/_form.html.erb @@ -30,7 +30,6 @@
<%= form.label :email %> <%= form.email_field :email, id: 'email-field', required: true %> -
@@ -121,28 +120,7 @@ <%# This is for Social Security formatting and # of digits %> - + diff --git a/app/views/workers/_form.html.erb b/app/views/workers/_form.html.erb new file mode 100644 index 0000000..b207be8 --- /dev/null +++ b/app/views/workers/_form.html.erb @@ -0,0 +1,114 @@ +<%= form_with(model: worker, local: true) do |form| %> + <% if worker.errors.any? %> +
+

<%= pluralize(worker.errors.count, "error") %> prohibited this worker from being saved:

+ + +
+ <% end %> + +
+ <%= form.label :name %> + <%= form.text_field :name %> +
+ +
+ <%= form.label :address %> + <%= form.text_area :address, rows: 1, class: 'auto-expand' %> +
+ +
+ <%= form.label :phone %> + <%= form.telephone_field :phone, id: 'phone-field' %> +
+ +
+ <%= form.label :email %> + <%= form.email_field :email, id: 'email-field', required: true %> +
+ +
+ <%= form.label :dob %> + <%= form.date_field :dob %> +
+ +
+ <%= form.label :ssn, 'Social Security Number' %> + <%= form.text_field :ssn, id: 'ssn-field', maxlength: 11, placeholder: 'XXX-XX-XXXX' %> +
+ +
+ <%= form.label :gender %> + <%= form.select :gender, ['Unknown', 'Female', 'Male', 'Non-Binary', 'Other'] %> +
+ +
+ <%= form.submit %> +
+ <% end %> + + + <%# This is to correct phone number entry %> + + +<%# This is for auto resizing the address field %> + + +<%# This is to require 1 @ sign for email entry %> + + +<%# This is for Social Security formatting and # of digits %> \ No newline at end of file diff --git a/app/views/workers/edit.html.erb b/app/views/workers/edit.html.erb new file mode 100644 index 0000000..e6699ea --- /dev/null +++ b/app/views/workers/edit.html.erb @@ -0,0 +1,6 @@ +

Edit Worker

+ +<%= render 'form', worker: @worker %> + +<%= link_to 'Cancel', worker_path(@worker) %> | +<%= link_to 'Back to List', workers_path %> diff --git a/app/views/workers/index.html.erb b/app/views/workers/index.html.erb new file mode 100644 index 0000000..a310928 --- /dev/null +++ b/app/views/workers/index.html.erb @@ -0,0 +1,36 @@ +

Workers

+ + + + + + + + + + + + + + + + <% @workers.each do |worker| %> + + + + + + + + + + + <% end %> + +
NameAddressPhoneEmailDOBSSNGenderActions
<%= worker.name %><%= worker.address %><%= worker.phone %><%= worker.email %><%= worker.dob %><%= worker.ssn %><%= worker.gender %> + <%= link_to 'Show', worker_path(worker) %> | + <%= link_to 'Edit', edit_worker_path(worker) %> | + <%= link_to 'Destroy', worker_path(worker), method: :delete, data: { confirm: 'Are you sure?' } %> +
+ +<%= link_to 'New Worker', new_worker_path %> diff --git a/app/views/workers/new.html.erb b/app/views/workers/new.html.erb new file mode 100644 index 0000000..4cb2434 --- /dev/null +++ b/app/views/workers/new.html.erb @@ -0,0 +1,5 @@ +

New Worker

+ +<%= render 'form', worker: @worker %> + +<%= link_to 'Back to List', workers_path %> diff --git a/app/views/workers/show.html.erb b/app/views/workers/show.html.erb new file mode 100644 index 0000000..a034fea --- /dev/null +++ b/app/views/workers/show.html.erb @@ -0,0 +1,33 @@ +

Worker Details

+ +

+ Name: + <%= @worker.name %> +

+

+ Address: + <%= @worker.address %> +

+

+ Phone: + <%= @worker.phone %> +

+

+ Email: + <%= @worker.email %> +

+

+ DOB: + <%= @worker.dob %> +

+

+ SSN: + <%= @worker.ssn %> +

+

+ Gender: + <%= @worker.gender %> +

+ +<%= link_to 'Edit', edit_worker_path(@worker) %> | +<%= link_to 'Back to List', workers_path %> diff --git a/config/routes.rb b/config/routes.rb index b3eebb0..f77262c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -10,6 +10,9 @@ Rails.application.routes.draw do end resources :participants + resources :employers + resources :workers + diff --git a/test/controllers/employers_controller_test.rb b/test/controllers/employers_controller_test.rb new file mode 100644 index 0000000..1fa9bd6 --- /dev/null +++ b/test/controllers/employers_controller_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class EmployersControllerTest < ActionDispatch::IntegrationTest + # test "the truth" do + # assert true + # end +end diff --git a/test/controllers/workers_controller_test.rb b/test/controllers/workers_controller_test.rb new file mode 100644 index 0000000..3a925af --- /dev/null +++ b/test/controllers/workers_controller_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class WorkersControllerTest < ActionDispatch::IntegrationTest + # test "the truth" do + # assert true + # end +end