Skip to content

Commit

Permalink
me-1 back, thats spacing, update seeds
Browse files Browse the repository at this point in the history
  • Loading branch information
aprilrieger committed Apr 29, 2024
1 parent c8a8421 commit 97bf854
Show file tree
Hide file tree
Showing 15 changed files with 116 additions and 128 deletions.
6 changes: 6 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@ DB_NAME=employee360
DB_USER=postgres
DB_TEST_NAME=employee360_test
HOST_URL=http://localhost:3001
INITIAL_SUPER_ADMIN_EMAIL = '[email protected]'
INITIAL_SUPER_ADMIN_PASSWORD = 'testing123'
INITIAL_ADMIN_EMAIL = '[email protected]'
INITIAL_ADMIN_PASSWORD = 'testing123'
INITIAL_USER_EMAIL = '[email protected]'
INITIAL_USER_PASSWORD = 'testing123'
14 changes: 7 additions & 7 deletions app/controllers/admin_dashboard_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class AdminDashboardController < ApplicationController
before_action :require_admin
before_action :require_superadmin
# before_action :require_superadmin

def index
@users = User.all
Expand All @@ -10,16 +10,16 @@ def index
private

def require_admin
unless current_user.admin?
unless current_user.admin? || current_user.superadmin?
redirect_to root_path, alert: "You are not authorized to access this page."
end
end

def require_superadmin
unless current_user.superadmin?
redirect_to root_path, alert: "You are not authorized to access this page."
end
end
# def require_superadmin
# unless current_user.superadmin?
# redirect_to root_path, alert: "You are not authorized to access this page."
# end
# end

def user_params
params.require(:user).permit(:name, :email, :password, :password_confirmation)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def set_title

def set_start_date
@user = User.find(params[:id])
@user_title = @user.salary_histories.order(change_date: :desc)
@set_start_date = @user.salary_histories.order(change_date: :desc)
end

def user_params
Expand Down
8 changes: 5 additions & 3 deletions app/views/admin_dashboard/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
<td><i class="bi bi-envelope-at"></i> <%= user.email %></td>
<td><i class="bi bi-github"></i> <%= user.github_handle %></td>
<td>
<%= link_to "Profile", user_path(user), class: "btn btn-primary" %>
<%= link_to "Goals", user_goals_path(user), class: "btn btn-success" %>
<%= link_to "Salary History", user_salary_histories_path(user), class: "btn btn-warning" %>
<%= link_to "Profile", user_path(user), class: "btn btn-primary me-1" %>
<%= link_to "Goals", user_goals_path(user), class: "btn btn-success me-1" %>
<% if current_user.superadmin? %>
<%= link_to "Salary History", user_salary_histories_path(user), class: "btn btn-warning me-1" %>
<% end %>
</td>
</tr>
<% end %>
Expand Down
10 changes: 5 additions & 5 deletions app/views/goals/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
<td><%= goal.due_date.strftime("%Y-%m-%d") %></td> <!-- Assuming due_date is a Date object -->
<td>
<div class="btn-group" role="group" aria-label="Basic example">
<%= button_to "View", user_goal_path(@user, goal), class: "btn btn-primary", method: :get %>
<%= button_to "Edit", edit_user_goal_path(@user, goal), class: "btn btn-secondary", method: :get %>
<%= button_to "Delete", user_goal_path(@user, goal), class: "btn btn-danger", method: :delete, data: { confirm: "Are you sure?" } %>
<%= button_to "View", user_goal_path(@user, goal), class: "btn btn-primary me-1", method: :get %>
<%= button_to "Edit", edit_user_goal_path(@user, goal), class: "btn btn-secondary me-1", method: :get %>
<%= button_to "Delete", user_goal_path(@user, goal), class: "btn btn-danger me-1", method: :delete, data: { confirm: "Are you sure?" } %>
</div>
</td>
</tr>
Expand All @@ -32,6 +32,6 @@
</div>

<div class="btn-group" role="group" aria-label="Basic example">
<%= button_to "Employee360 Portal", root_url, class: "btn btn-primary", method: :get %>
<%= button_to "New Goal", new_user_goal_path(@user), class: "btn btn-success", method: :get %>
<%= button_to "Employee360 Portal", root_url, class: "btn btn-primary me-1", method: :get %>
<%= button_to "New Goal", new_user_goal_path(@user), class: "btn btn-success me-1", method: :get %>
</div>
6 changes: 3 additions & 3 deletions app/views/goals/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<p><strong>Due Date:</strong> <%= @goal.due_date %></p>

<div class="btn-group" role="group" aria-label="Basic example">
<%= button_to "Edit", edit_user_goal_path(@user, @goal), class: "btn btn-secondary", method: :get %>
<%= button_to "Delete", user_goal_path(@user, @goal), class: "btn btn-danger", method: :delete, data: { confirm: "Are you sure?" } %>
<%= button_to "Back to Goals", user_goals_path(@user, @goal), class: "btn btn-success", method: :get %>
<%= button_to "Edit", edit_user_goal_path(@user, @goal), class: "btn btn-secondary me-1", method: :get %>
<%= button_to "Delete", user_goal_path(@user, @goal), class: "btn btn-danger me-1", method: :delete, data: { confirm: "Are you sure?" } %>
<%= button_to "Back to Goals", user_goals_path(@user, @goal), class: "btn btn-success me-1", method: :get %>
</div>
2 changes: 1 addition & 1 deletion app/views/pages/home.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<%= link_to user_goals_path(current_user.id), class: "btn btn-success btn-lg px-4 me-md-2" do %>
Goals
<% end %>
<% if current_user.superadmin? %>
<% if current_user.superadmin? || current_user.admin? %>
<%= link_to admin_dashboard_path(current_user.id), class: "btn btn-warning btn-lg px-4 me-md-2" do %>
Admin Area
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/salary_histories/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="card">
<div class="card-body">
<%= render 'form' %>
<%= button_to "Back to Salary History", user_salary_history_path(@user, @salary_history), class: "btn btn-success", method: :get %>
<%= button_to "Back to Salary Histories", user_salary_histories_path(@user, @salary_histories), class: "btn btn-success", method: :get %>
</div>
</div>
</div>
12 changes: 6 additions & 6 deletions app/views/salary_histories/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
<td><%= number_to_currency(salary_history.salary) %></td>
<td><%= salary_history.change_date.strftime("%Y-%m-%d") %></td>
<td><%= salary_history.change_reason %></td>
<td><%= number_to_currency(salary_history.current_salary) %></td>
<td><%= salary_history.current_salary %></td>
<td>
<div class="btn-group" role="group" aria-label="Basic example">
<%= button_to "View", user_salary_history_path(@user, salary_history), class: "btn btn-primary", method: :get %>
<%= button_to "Edit", edit_user_salary_history_path(@user, salary_history), class: "btn btn-secondary", method: :get %>
<%= button_to "Delete", user_salary_history_path(@user, salary_history), class: "btn btn-danger", method: :delete, data: { confirm: "Are you sure?" } %>
<%= button_to "View", user_salary_history_path(@user, salary_history), class: "btn btn-primary me-1", method: :get %>
<%= button_to "Edit", edit_user_salary_history_path(@user, salary_history), class: "btn btn-secondary me-1", method: :get %>
<%= button_to "Delete", user_salary_history_path(@user, salary_history), class: "btn btn-danger me-1", method: :delete, data: { confirm: "Are you sure?" } %>
</div>
</td>
</tr>
Expand All @@ -36,6 +36,6 @@
</div>

<div class="btn-group" role="group" aria-label="Basic example">
<%= button_to "Employee360 Portal", root_url, class: "btn btn-primary", method: :get %>
<%= button_to "New Salary History", new_user_salary_history_path(@user), class: "btn btn-success", method: :get %>
<%= button_to "Employee360 Portal", root_url, class: "btn btn-primary me-1", method: :get %>
<%= button_to "New Salary History", new_user_salary_history_path(@user), class: "btn btn-success me-1", method: :get %>
</div>
8 changes: 4 additions & 4 deletions app/views/salary_histories/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<h1 class="mt-3"><%= @salary_history.job_title %></h1>

<p><strong>Salary:</strong> <%= @salary_history.salary %></p>
<p><strong>Salary:</strong> <%= number_to_currency(@salary_history.salary) %></p>
<p><strong>Change Date:</strong> <%= @salary_history.change_date %></p>
<p><strong>Change Reason:</strong> <%= @salary_history.change_reason %></p>
<p><strong>Current Salary:</strong> <%= @salary_history.current_salary %></p>
<div class="btn-group" role="group" aria-label="Basic example">
<%= button_to "Edit", edit_user_salary_history_path(@user, @salary_history), class: "btn btn-secondary", method: :get %>
<%= button_to "Delete", user_salary_history_path(@user, @salary_history), class: "btn btn-danger", method: :delete, data: { confirm: "Are you sure?" } %>
<%= button_to "Back to Salary Histories", user_salary_histories_path(@user, @salary_histories), class: "btn btn-success", method: :get %>
<%= button_to "Edit", edit_user_salary_history_path(@user, @salary_history), class: "btn btn-secondary me-1", method: :get %>
<%= button_to "Delete", user_salary_history_path(@user, @salary_history), class: "btn btn-danger me-1", method: :delete, data: { confirm: "Are you sure?" } %>
<%= button_to "Back to Salary Histories", user_salary_histories_path(@user, @salary_histories), class: "btn btn-success me-1", method: :get %>
</div>
2 changes: 1 addition & 1 deletion app/views/users/_current_salary.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<td>
<details>
<summary>Salary</summary>
<%= salary_history.salary %>
<%= number_to_currency(salary_history.salary) %>
</details>
</td>
<td><%= salary_history.change_reason %></td>
Expand Down
1 change: 0 additions & 1 deletion app/views/users/_employment_data.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
<tr>
<th>Start Date</th>
<th>Last Promotion</th>
<th>Due for Promotion</th>
</tr>
</thead>
<tbody>
Expand Down
60 changes: 28 additions & 32 deletions app/views/users/_salary_history.erb
Original file line number Diff line number Diff line change
@@ -1,34 +1,30 @@
<div class="col-sm m-3">
<div class="card">
<div class="card-body">
<h4 class="card-title">Salary History</h4>
<table class="table">
<thead>
<tr>
<th>Date</th>
<th>Title</th>
<th>Salary</th>
<th>Change Reason</th>
<th>Current Salary</th>
</tr>
</thead>
<tbody>
<% @user.salary_histories.order(change_date: :desc).each do |salary_history| %>
<tr>
<td><%= salary_history.change_date %></td>
<td><%= salary_history.job_title %></td>
<td>
<details>
<summary>Salary</summary>
<%= salary_history.salary %>
</details>
</td>
<td><%= salary_history.change_reason %></td>
<td><%= salary_history.current_salary %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>
<h4>Salary History</h4>
<table class="table">
<thead>
<tr>
<th>Date</th>
<th>Title</th>
<th>Salary</th>
<th>Change Reason</th>
<th>Current Salary</th>
</tr>
</thead>
<tbody>
<% @user.salary_histories.order(change_date: :desc).each do |salary_history| %>
<tr>
<td><%= salary_history.change_date %></td>
<td><%= salary_history.job_title %></td>
<td>
<details>
<summary>Salary</summary>
<%= number_to_currency(salary_history.salary) %>
</details>
</td>
<td><%= salary_history.change_reason %></td>
<td><%= salary_history.current_salary %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
8 changes: 4 additions & 4 deletions app/views/users/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<p class="card-text"><i class="bi bi-github"></i> <%= @user.github_handle %></p>
<p class="card-text">Start Date: <%= @user.start_date %></p>
<p>
<%= link_to @user.review_document, target: "_blank", class: "btn btn-primary" do %>
<%= link_to @user.review_document, target: "_blank", class: "btn btn-primary me-1" do %>
<i class="bi bi-file-earmark-text"></i> Review Document
<% end %>
</p>
Expand All @@ -23,9 +23,9 @@
</div>

<div class="btn-group" role="group" aria-label="Basic example">
<%= button_to "Employee360 Portal", root_url, class: "btn btn-primary", method: :get %>
<%= button_to "Edit Profile", edit_user_path(@user), class: "btn btn-success", method: :get %>
<%= button_to "Employee360 Portal", root_url, class: "btn btn-primary me-1", method: :get %>
<%= button_to "Edit Profile", edit_user_path(@user), class: "btn btn-success me-1", method: :get %>
<% if current_user.superadmin? %>
<%= button_to "Edit Salary History", user_salary_histories_path(@user, @salary_histories), class: "btn btn-warning", method: :get %>
<%= button_to "Back to Salary Histories", user_salary_histories_path(@user, @salary_histories), class: "btn btn-warning me-1", method: :get %>
<% end %>
</div>
103 changes: 44 additions & 59 deletions db/seeds.rb
Original file line number Diff line number Diff line change
@@ -1,80 +1,65 @@
# Create a seeded Rob User with Superadmin role
superadmin_email = '[email protected]'
# This file should contain all the record creation
# needed to seed the database with its default values.

# Create a seeded Rob User with Superadmin role
superadmin_salary_history = SalaryHistory.create(
job_title: 'Superadmin Role Example Title',
salary: 200000,
change_date: Date.new(2015, 1, 1),
change_reason: 'Annual Raise',
current_salary: true,
change_reason: 'New Hire',
current_salary: true
)

User.create!(
email: superadmin_email,
password: 'testing123',
roles: [:employee, :superadmin],
name: 'Super Admin User',
github_handle: 'superadmin',
salary_histories: [superadmin_salary_history],
)
if ENV['INITIAL_SUPER_ADMIN_EMAIL'] && ENV['INITIAL_SUPER_ADMIN_PASSWORD']
superadmin = User.find_or_create_by(email: ENV['INITIAL_SUPER_ADMIN_EMAIL']) do |u|
u.password = ENV['INITIAL_SUPER_ADMIN_PASSWORD']
u.role = 'superadmin'
u.name = 'Super Admin User'
u.github_handle = 'superadmin'
u.review_document = 'https://example.com'
end
superadmin.salary_histories << superadmin_salary_history unless superadmin.salary_histories.include?(superadmin_salary_history)
superadmin.save
end

# Create a seeded User with default Employee role
employee_email = '[email protected]'
# Create a seeded User with Admin role

employee_salary_history = SalaryHistory.create(
job_title: 'Employee Example Title',
admin_salary_history = SalaryHistory.create(
job_title: 'Admin Role Example Title',
salary: 200000,
change_date: Date.new(2015, 1, 1),
change_reason: 'New Hire',
current_salary: true,
current_salary: true
)

User.create!(
email: employee_email,
password: 'testing123',
name: 'Employee',
github_handle: 'employee',
salary_histories: [employee_salary_history],
)
if ENV['INITIAL_ADMIN_EMAIL'] && ENV['INITIAL_ADMIN_PASSWORD']
admin = User.find_or_create_by(email: ENV['INITIAL_ADMIN_EMAIL']) do |u|
u.password = ENV['INITIAL_ADMIN_PASSWORD']
u.role = 'admin'
u.name = 'Admin User'
u.github_handle = 'admin'
u.review_document = 'https://example.com'
end
admin.salary_histories << admin_salary_history unless admin.salary_histories.include?(admin_salary_history)
admin.save
end

# # Admin is not a role in the application yet
# # Create a seeded User with Admin role
admin_email = '[email protected]'

admin_salary_history = SalaryHistory.create(
# Create a seeded User with default Employee role
employee_salary_history = SalaryHistory.create(
job_title: 'Employee Example Title',
salary: 200000,
change_date: Date.new(2015, 1, 1),
change_reason: 'New Hire',
current_salary: true,
current_salary: true
)

User.create!(
email: admin_email,
password: 'testing123',
name: 'Employee',
github_handle: 'employee',
roles: [:employee, :admin],
salary_histories: [admin_salary_history],
)

# # Mentor is not a role in the application yet
# # Create a seeded User with Mentor role
# mentor_email = '[email protected]'

# mentor_salary_history = SalaryHistory.create(
# job_title: 'Employee with Mentor Role Example Title',
# salary: 200000,
# change_date: Date.new(2015, 1, 1),
# change_reason: 'Annual Increase',
# current_salary: true,
# )

# User.create!(
# email: mentor_email,
# password: 'testing123',
# name: 'Mentor User',
# github_handle: 'mentor',
# roles: [:employee, :mentor],
# salary_histories: [mentor_salary_history],
# )
if ENV['INITIAL_USER_EMAIL'] && ENV['INITIAL_USER_PASSWORD']
employee = User.find_or_create_by(email: ENV['INITIAL_USER_EMAIL']) do |u|
u.password = ENV['INITIAL_USER_PASSWORD']
u.name = 'Default Employee User'
u.github_handle = 'employee'
u.review_document = 'https://example.com'
end
employee.salary_histories << employee_salary_history unless employee.salary_histories.include?(employee_salary_history)
employee.save
end

0 comments on commit 97bf854

Please sign in to comment.