Skip to content

Commit abc9526

Browse files
committed
Add status
1 parent 64915bf commit abc9526

File tree

9 files changed

+73
-20
lines changed

9 files changed

+73
-20
lines changed

app/controllers/job_applications_controller.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def set_job_application
9696
end
9797

9898
def job_application_params
99-
params.require(:job_application).permit(:date_applied, :company_name, :method_of_contact, :email_address, :point_of_contact, :website_link, :position_type, :position_title, :claimed_for_unemployment)
99+
params.require(:job_application).permit(:date_applied, :company_name, :method_of_contact, :email_address, :point_of_contact, :website_link, :position_type, :position_title, :claimed_for_unemployment, :status)
100100
end
101101

102102
def filter_and_sort_job_applications
@@ -107,6 +107,7 @@ def filter_and_sort_job_applications
107107
job_applications = job_applications.by_position_type(params[:position_type]) if params[:position_type].present?
108108
job_applications = job_applications.claimed_for_unemployment if params[:claimed_for_unemployment] == "true"
109109
job_applications = job_applications.not_claimed_for_unemployment if params[:claimed_for_unemployment] == "false"
110+
job_applications = job_applications.by_status(params[:status]) if params[:status].present?
110111

111112
sort_column = sort_column(params[:sort])
112113
sort_direction = sort_direction(params[:direction])
@@ -121,7 +122,7 @@ def filter_and_sort_job_applications
121122
end
122123

123124
def sort_column(column)
124-
%w[date_applied company_name position_title created_at claimed_for_unemployment].include?(column) ? column : "created_at"
125+
%w[date_applied company_name position_title created_at claimed_for_unemployment status].include?(column) ? column : "created_at"
125126
end
126127

127128
def sort_direction(direction)

app/models/job_application.rb

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
class JobApplication < ApplicationRecord
2+
attribute :status, :string
3+
24
validates :date_applied, :company_name, :method_of_contact, :position_type, :position_title, presence: true
35
validates :email_address, presence: true, if: -> { method_of_contact == "email" }
46
validates :point_of_contact, presence: true, if: -> { ["email", "phone", "recruiter", "other"].include?(method_of_contact) }
@@ -10,17 +12,39 @@ class JobApplication < ApplicationRecord
1012
public_suffix: true
1113
}
1214
validates :claimed_for_unemployment, inclusion: {in: [true, false]}
15+
validates :status, inclusion: {in: %w[hired interviewing job_offer no_response not_hired]}
1316

14-
enum method_of_contact: {email: "email", phone: "phone", internet_job_application: "internet job application", recruiter: "recruiter", other: "other"}
17+
enum method_of_contact: {
18+
email: "email",
19+
internet_job_application: "internet job application",
20+
other: "other",
21+
phone: "phone",
22+
recruiter: "recruiter"
23+
}
1524
enum position_type: {
1625
full_time: "full_time",
17-
part_time: "part_time",
18-
internship: "internship"
26+
internship: "internship",
27+
part_time: "part_time"
28+
}
29+
enum status: {
30+
hired: "hired",
31+
interviewing: "interviewing",
32+
job_offer: "job offer",
33+
no_response: "no response",
34+
not_hired: "not hired"
1935
}
2036

21-
scope :search, ->(query) { where("company_name ILIKE ? OR position_title ILIKE ?", "%#{query}%", "%#{query}%") }
2237
scope :by_method_of_contact, ->(method) { where(method_of_contact: method) }
2338
scope :by_position_type, ->(type) { where(position_type: type) }
39+
scope :by_status, ->(status) { where(status: status) }
2440
scope :claimed_for_unemployment, -> { where(claimed_for_unemployment: true) }
2541
scope :not_claimed_for_unemployment, -> { where(claimed_for_unemployment: false) }
42+
scope :search, ->(query) {
43+
where("company_name ILIKE :query OR
44+
position_title ILIKE :query OR
45+
email_address ILIKE :query OR
46+
point_of_contact ILIKE :query OR
47+
website_link ILIKE :query OR
48+
status ILIKE :query", query: "%#{query}%")
49+
}
2650
end

app/views/job_applications/_form.html.erb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,15 @@
5050
<%= form.label :position_title, class: 'block text-sm font-medium text-gray-700 mb-2' %>
5151
<%= form.text_field :position_title, class: 'shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline' %>
5252
</div>
53-
<div class="mt-2">
54-
<%= form.label :claimed_for_unemployment, class: 'flex items-center' do %>
55-
<%= form.check_box :claimed_for_unemployment, class: 'h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded mr-2' %>
56-
<span class="text-sm font-medium text-gray-700">Claimed for Unemployment</span>
57-
<% end %>
53+
<div>
54+
<%= form.label :status, class: 'block text-sm font-medium text-gray-700 mb-2' %>
55+
<%= form.select :status, JobApplication.statuses.keys.map { |k| [k.humanize, k] }, { include_blank: 'Select a status' }, class: 'shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline' %>
56+
<div class="mt-8">
57+
<%= form.label :claimed_for_unemployment, class: 'flex items-center' do %>
58+
<%= form.check_box :claimed_for_unemployment, class: 'h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded mr-2' %>
59+
<span class="text-sm font-medium text-gray-700">Claimed for Unemployment</span>
60+
<% end %>
61+
</div>
5862
</div>
5963
</div>
6064
<div class="flex items-center justify-end mt-6">

app/views/job_applications/_job_application.html.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
<td class="px-5 py-5 border-b border-gray-200 bg-white text-sm">
2424
<%= job_application.claimed_for_unemployment ? '✔︎' : '-' %>
2525
</td>
26+
<td class="px-5 py-5 border-b border-gray-200 bg-white text-sm">
27+
<%= job_application.status.humanize %>
28+
</td>
2629
<td class="px-5 py-5 border-b border-gray-200 bg-white text-sm">
2730
<% if job_application.website_link.present? %>
2831
<%= link_to 'Visit',

app/views/job_applications/_job_applications_table.html.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
<th class="px-5 py-3">
2929
<%= sort_link_to 'Claimed', 'claimed_for_unemployment' %>
3030
</th>
31+
<th class="px-5 py-3">
32+
<%= sort_link_to 'Status', 'status' %>
33+
</th>
3134
<th class="px-5 py-3">
3235
Website
3336
</th>

app/views/job_applications/index.html.erb

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
</div>
2020
<%= form_with url: job_applications_path, method: :get, data: { controller: "job-filter", turbo_frame: "job_applications_table" } do |form| %>
2121
<div class="flex flex-wrap -mx-2 mb-4">
22-
<div class="w-full md:w-1/5 px-2 mb-4 md:mb-0">
22+
<div class="w-full md:w-1/6 px-2 mb-4 md:mb-0">
2323
<%= form.label :search, "Search", class: "sr-only" %>
24-
<%= form.text_field :search, value: params[:search], class: "shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline", placeholder: "Search by company or position", data: { action: "input->job-filter#submit" } %>
24+
<%= form.text_field :search, value: params[:search], class: "shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline", placeholder: "Search", data: { action: "input->job-filter#submit" } %>
2525
</div>
26-
<div class="w-full md:w-1/5 px-2 mb-4 md:mb-0">
26+
<div class="w-full md:w-1/6 px-2 mb-4 md:mb-0">
2727
<%= form.label :method_of_contact, "Contact Method", class: "sr-only" %>
2828
<%= form.select :method_of_contact,
2929
options_for_select([["All Contact Methods", ""]] + JobApplication.method_of_contacts.map { |k, v| [k.humanize, v] }, params[:method_of_contact]),
@@ -32,16 +32,16 @@
3232
data: { action: "change->job-filter#submit" }
3333
%>
3434
</div>
35-
<div class="w-full md:w-1/5 px-2 mb-4 md:mb-0">
35+
<div class="w-full md:w-1/6 px-2 mb-4 md:mb-0">
3636
<%= form.label :position_type, "Position Type", class: "sr-only" %>
3737
<%= form.select :position_type,
38-
options_for_select([["All Position Types", ""]] + JobApplication.position_types.map { |k, v| [k.humanize, v] }, params[:position_type]),
38+
options_for_select([["All Position Types", ""]] + JobApplication.position_types.map { |k, v| [display_position_type(k), v] }, params[:position_type]),
3939
{},
4040
class: "shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline",
4141
data: { action: "change->job-filter#submit" }
4242
%>
4343
</div>
44-
<div class="w-full md:w-1/5 px-2 mb-4 md:mb-0">
44+
<div class="w-full md:w-1/6 px-2 mb-4 md:mb-0">
4545
<%= form.label :claimed_for_unemployment, "Unemployment Claim", class: "sr-only" %>
4646
<%= form.select :claimed_for_unemployment,
4747
options_for_select([["All Claims", ""], ["Claimed", "true"], ["Not Claimed", "false"]], params[:claimed_for_unemployment]),
@@ -50,7 +50,16 @@
5050
data: { action: "change->job-filter#submit" }
5151
%>
5252
</div>
53-
<div class="w-full md:w-1/5 px-2 mt-4 md:mt-0">
53+
<div class="w-full md:w-1/6 px-2 mb-4 md:mb-0">
54+
<%= form.label :status, "Application Status", class: "sr-only" %>
55+
<%= form.select :status,
56+
options_for_select([["All Statuses", ""]] + JobApplication.statuses.map { |k, v| [k.humanize, v] }, params[:status]),
57+
{},
58+
class: "shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline",
59+
data: { action: "change->job-filter#submit" }
60+
%>
61+
</div>
62+
<div class="w-full md:w-1/6 px-2 mt-4 md:mt-0">
5463
<%= form.button "Reset Filters", type: "button", class: "w-full bg-gray-600 hover:bg-gray-700 text-white font-bold py-2 px-4 rounded cursor-pointer", data: { action: "click->job-filter#reset" } %>
5564
</div>
5665
</div>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class AddStatusToJobApplications < ActiveRecord::Migration[7.1]
2+
def change
3+
add_column :job_applications, :status, :string, null: false, default: "no response"
4+
add_check_constraint :job_applications, "status IN ('interviewing', 'no response', 'hired', 'not hired', 'job offer')", name: "check_valid_status"
5+
end
6+
end

db/schema.rb

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

db/seeds.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
position_type: %w[full_time part_time internship].sample,
1616
position_title: Faker::Job.title,
1717
website_link: website_link,
18-
claimed_for_unemployment: [true, false].sample
18+
claimed_for_unemployment: [true, false].sample,
19+
status: %w[interviewing no_response not_hired job_offer].sample
1920
)
2021
end

0 commit comments

Comments
 (0)