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

removed pronouns and more #14

Merged
merged 1 commit into from
Mar 31, 2023
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
32 changes: 28 additions & 4 deletions app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,34 @@ body {
margin-left: 0px;
font-style: normal;
font-size: 110%;
flex: 1;
flex: 1;
}
/*rails forms
/* Style for form label and input fields */
.displaytable{
margin-top:15px;
margin-bottom:15px;
}
.form-row {
display: flex;
flex-direction: row;
/*justify-content: space-between;*/
margin-bottom: 10px;
}
.form-row2 {
display: flex;
flex-direction: row;
/*justify-content: space-between;*/
margin-bottom: 20px;
color:cadetblue;
font-weight:bolder;
}
.form-row label {
width: 15%;;
margin-right: 5px;
}

/* end rails forms*/

.btn {
background-color:#e00122;
Expand Down Expand Up @@ -73,10 +98,9 @@ th, td {
input{
line-height:1.5;
font-size:100%;
border:thin black solid;
/*border:thin #e00122 solid;*/
padding:5px;
border-radius:10px;
margin:4px;
margin:4px;
}


Expand Down
36 changes: 23 additions & 13 deletions app/controllers/employees_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,27 @@ def create
end

# PATCH/PUT /employees/1 or /employees/1.json
def update
respond_to do |format|
if @employee.update(employee_params)
format.html { redirect_to employee_url(@employee), notice: "Employee was successfully updated." }
format.json { render :show, status: :ok, location: @employee }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @employee.errors, status: :unprocessable_entity }
end
end
def update
# Find the employee record that should be updated based on the `id` parameter passed in from the form
@employee = Employee.find(params[:id])
# Get the ID of the department that the employee should be assigned to from the `department_id` parameter passed in from the form
department_id = params[:employee][:department_id]
# Find the Department record that corresponds to the ID passed in from the form
department = Department.find(department_id)
# Set the department association of the employee record to the department that was just found
@employee.department = department
# If the update of the employee attributes (e.g. first name, last name) is successful, redirect the user to the employee's show page
if @employee.update(employee_params)
redirect_to @employee
else
#display that there is a problem
flash[:error] = "Update not successful"
# If the update is not successful, re-render the edit form so that the user can fix any errors
render 'edit'
end
end



# DELETE /employees/1 or /employees/1.json
def destroy
Expand All @@ -64,7 +74,7 @@ def set_employee
end

# Only allow a list of trusted parameters through.
def employee_params
params.require(:employee).permit(:lastname, :firstname, :department_id, :pronouns, :email, :phone, :title)
end
def employee_params
params.require(:employee).permit(:lastname, :firstname, :department, :email, :phone, :title)
end
end
72 changes: 72 additions & 0 deletions app/controllers/employees_controller_cp.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
class EmployeesController < ApplicationController
before_action :set_employee, only: %i[ show edit update destroy ]

# GET /employees or /employees.json
def index
@employees = Employee.all
end

# GET /employees/1 or /employees/1.json
def show
end

# GET /employees/new
def new
@employee = Employee.new
end

# GET /employees/1/edit
def edit
end

# POST /employees or /employees.json
def create
@employee = Employee.new(employee_params)

respond_to do |format|
if @employee.save
format.html { redirect_to employee_url(@employee), notice: "Employee was successfully created." }
format.json { render :show, status: :created, location: @employee }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @employee.errors, status: :unprocessable_entity }
end
end
end

# PATCH/PUT /employees/1 or /employees/1.json
def update
respond_to do |format|
if @employee.update(employee_params)
format.html { redirect_to employee_url(@employee), notice: "Employee was successfully updated." }
format.json { render :show, status: :ok, location: @employee }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @employee.errors, status: :unprocessable_entity }
end
end
end

# DELETE /employees/1 or /employees/1.json
def destroy
@employee.destroy

respond_to do |format|
format.html { redirect_to employees_url, notice: "Employee was successfully destroyed." }
format.json { head :no_content }
end
end

private
# Use callbacks to share common setup or constraints between actions.
def set_employee
@employee = Employee.find(params[:id])
end

# Only allow a list of trusted parameters through.
def employee_params
params.require(:employee).permit(:lastname, :firstname, :department, :department_id, :department_name, :email, :phone, :title)
end


end
74 changes: 74 additions & 0 deletions app/controllers/employees_controllerdoesnotwork.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
class EmployeesController < ApplicationController
before_action :set_employee, only: %i[ show edit update destroy ]

# GET /employees or /employees.json
def index
@employees = Employee.all
end

# GET /employees/1 or /employees/1.json
def show
end

# GET /employees/new
def new
@employee = Employee.new
end

# GET /employees/1/edit
def edit
end

# POST /employees or /employees.json
def create
@employee = Employee.new(employee_params)
department = Department.find_or_create_by(name: employee_params[:department_name])
@employee.department = department

respond_to do |format|
if @employee.save
format.html { redirect_to @employee, notice: 'Employee was successfully created.' }
format.json { render :show, status: :created, location: @employee }
else
format.html { render :new }
format.json { render json: @employee.errors, status: :unprocessable_entity }
end
end
end
#update
def update
respond_to do |format|
if @employee.update(employee_params)
format.html { redirect_to @employee, notice: 'Employee was successfully updated.' }
format.json { render :show, status: :ok, location: @employee }
else
format.html { render :edit }
format.json { render json: @employee.errors, status: :unprocessable_entity }
end
end
end

# DELETE /employees/1 or /employees/1.json
def destroy
@employee.destroy

respond_to do |format|
format.html { redirect_to employees_url, notice: "Employee was successfully destroyed." }
format.json { head :no_content }
end
end

private
# Use callbacks to share common setup or constraints between actions.
def set_employee
@employee = Employee.find(params[:id])
end

# Only allow a list of trusted parameters through.

def employee_params
params.require(:employee).permit(:lastname, :firstname, :email, :phone, :title, :department_name, :department_id)
end


end
3 changes: 2 additions & 1 deletion app/views/departments/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
</thead>

<tbody>
<% @departments.each do |department| %>
<% @departments.order(:name).each do |department| %>

<tr>
<td><%= department.id %></td>
<td><%= department.name %></td>
Expand Down
35 changes: 31 additions & 4 deletions app/views/employees/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,28 +1,55 @@
<h1>Edit Employee</h1>

<%= form_for @employee do |f| %>


<% if flash[:error] %>
<div class="alert alert-danger">
<%= flash[:error] %>
</div>
<% end %>



<div class="form-row">
<%= f.label :firstname %>
<%= f.text_field :firstname %>
</div>

<div class="form-row">
<%= f.label :lastname %>
<%= f.text_field :lastname %>
</div>

<div class="form-row">
<%= f.label :email %>
<%= f.text_field :email %>
</div>

<div class="form-row">
<%= f.label :phone %>
<%= f.text_field :phone %>
</div>

<div class="form-row">
<%= f.label :title %>
<%= f.text_field :title %>
</div>

<%= f.label :department %>
<%= f.collection_select :department_id, Department.all, :id, :name %>
<div class="form-row">
<%= f.label :Current_Department %>
<%= (@employee.department.nil? ? "None Assigned" : @employee.department.name) %>
</div>

<%= f.label :pronouns %>
<%= f.text_field :pronouns %>
<div class="form-row">
<%= f.label :Change_dept_to %>
<%= f.collection_select :department_id, Department.order(:name), :id, :name %>
</div>

<div class="form-row">
<%= f.submit "Save" %>
</div>
<% end %>


<%= link_to "Back", employees_path %>
20 changes: 0 additions & 20 deletions app/views/employees/edit_employee.html.erb

This file was deleted.

16 changes: 8 additions & 8 deletions app/views/employees/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@

<p id="notice"><%= notice %></p>

<h1>Employees</h1>

<table>
<table class ="displaytable">
<thead>
<tr>
<th>Lastname</th>
<th>Firstname</th>
<th>Department</th>
<th>Pronouns</th>
<!--<th>Pronouns</th>-->
<th>Title</th>
<th>Email</th>
<th>Phone</th>
<th colspan="3"></th>
</tr>
</thead>

<tbody>
<% @employees.each do |employee| %>
<% @employees.order(lastname: :asc).each do |employee| %>

<tr>
<td><%= employee.lastname %></td>
<td><%= employee.firstname %></td>
<td><%= employee.department.nil? ? "" : employee.department.name %></td>
<td><%= employee.pronouns %></td>
<td><%= employee.email %></td>
<td><%= employee.title %></td>
<td><%= link_to employee.email, "mailto:#{employee.email}" %></td>
<td><%= employee.phone %></td>
<td><%= link_to 'Show', employee %></td>
<td><%= link_to 'Edit', edit_employee_path(employee) %></td>
Expand All @@ -35,4 +35,4 @@

<br>

<%= link_to 'New Employee', new_employee_path %>

Loading