Commit b3f131ec by Son Do Hong

Merge branch 'feature/job_apply' into 'master'

Feature/job apply

See merge request !18
parents 039891b2 67578cc5
......@@ -151,12 +151,6 @@ dl, dt, dd {
line-height: normal;
}
.breadcrumb {
font-weight: lighter;
font-size: 12px;
margin-bottom: 15px;
}
.job_detail_button {
margin: 10px;
padding: 5px;
......
......@@ -16,4 +16,32 @@ class JobsController < ApplicationController
def show
@job = Job.find(params[:id]).decorate
end
def apply
redirect_to new_user_session_path unless user_signed_in?
redirect_to jobs_path if params[:job_id].blank?
@job_id = params[:job_id]
end
def confirm_apply
end
def finish_apply
@apply_info = params[:confirm_apply_info]
@job_id = params[:confirm_apply_info][:job_id]
if params[:commit] == "Edit"
redirect_to apply_path(job_id: @job_id, params: confirm_apply_info_params)
else
current_user.user_jobs.find_by(user_id: current_user.id, job_id: @job_id) ||
current_user.user_jobs.create!(user_id: current_user.id, job_id: @job_id, applied_at: Time.current)
end
end
private
def confirm_apply_info_params
params.require(:confirm_apply_info).permit(:job_id, :first_name, :last_name, :email)
end
end
......@@ -3,6 +3,7 @@ class JobDecorator < ApplicationDecorator
delegate_all
decorates_association :city
decorates_association :user
def city_name
object.cities&.first&.name
......@@ -19,4 +20,8 @@ class JobDecorator < ApplicationDecorator
def display_description
simple_format object.description
end
def apply_available(user)
object.users.find_by(id: user.id)
end
end
......@@ -37,7 +37,15 @@ class Job < ApplicationRecord
has_many :industry_jobs
has_many :industries, through: :industry_jobs
has_many :user_jobs
has_many :users, through: :user_jobs
def self.latest_job
@latest_job ||= order(updated_at: :desc).take(Settings.top.job.limit)
end
def apply_available
user = User.find_by(:id)
user_jobs.find_by(job_id: @job_id, user_id: user.id)
end
end
......@@ -28,6 +28,9 @@
#
class User < ApplicationRecord
has_many :user_jobs
has_many :jobs, through: :user_jobs
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :database_authenticatable, :registerable,
......
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item active" aria-current="page">New</li>
<li class="breadcrumb-item">Confirmation</li>
<li class="breadcrumb-item">Finish</li>
</ol>
</nav>
<h3>Apply form</h3>
<%= form_for "apply_info", url: confirm_path, method: :get do |f| %>
<%= f.hidden_field :job_id, value: @job_id %>
<div class="form-group">
<%= f.label :first_name %>
<%= f.text_field :first_name, value: params[:first_name] || @current_user.first_name,
class: "form-control", required: "true" %>
</div>
<div class="form-group">
<%= f.label :last_name %>
<%= f.text_field :last_name, value: params[:last_name] || @current_user.last_name,
class: "form-control", required: "true" %>
</div>
<div class="form-group">
<%= f.label :email %>
<%= f.email_field :email, value: params[:email] || @current_user.email,
class: "form-control", required: "true" %>
</div>
<div class="field">
<%= f.label :cv_path %>
<input type="file" class="form-control-file" id="cv_path">
</div>
<div class="actions text-center">
<%= f.submit "Confirm", class: "btn btn-lg btn-primary"%>
</div>
<% end %>
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item">New</li>
<li class="breadcrumb-item active" aria-current="page">Confirmation</li>
<li class="breadcrumb-item">Finish</li>
</ol>
</nav>
<h3>Confirmation</h3>
<%= form_for "confirm_apply_info", url: done_path, method: :post do |f| %>
<%= f.hidden_field :job_id, value: params[:apply_info][:job_id] %>
<%= f.hidden_field :first_name, value: params[:apply_info][:first_name] %>
<%= f.hidden_field :last_name, value: params[:apply_info][:last_name] %>
<%= f.hidden_field :email, value: params[:apply_info][:email] %>
<div class="form-group">
First name: <%= f.label :first_name, params[:apply_info][:first_name] %>
</div>
<div class="form-group">
Last name: <%= f.label :last_name, params[:apply_info][:last_name] %>
</div>
<div class="form-group">
Email: <%= f.label :email, params[:apply_info][:email] %>
</div>
<div class="actions text-center">
<%= f.submit "Edit", class: "btn btn-lg btn-primary"%>
<%= f.submit "Done", class: "btn btn-lg btn-primary"%>
</div>
<% end %>
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item">New</li>
<li class="breadcrumb-item">Confirmation</li>
<li class="breadcrumb-item active" aria-current="page">Finish</li>
</ol>
</nav>
<h2>Thank you for apply</h2>
<%= link_to "Back to the TOP page", root_path %>
<div class="breadcrumb">
<%= link_to "Top", root_path %> >
<%= link_to "City", cities_path %> >
<%= link_to "Industry", industries_path %> >
<%= @job.title %>
</div>
<nav aria-label="breadcrumb mb-4">
<ol class="breadcrumb">
<li class="breadcrumb-item"><%= link_to "Top", root_path %></li>
<li class="breadcrumb-item"><%= link_to "City", cities_path %></li>
<li class="breadcrumb-item"><%= link_to "Industry", industries_path %></li>
<li class="breadcrumb-item active" aria-current="page"><%= @job.title %></li>
</ol>
</nav>
<div class="box">
<h1>
<%= @job.title %>
......@@ -30,5 +32,9 @@
<div class="job_detail_button">
<%= link_to "Favorite", "#", class: "btn btn-primary float-right" %>
<%= link_to "Apply", "#", class: "btn btn-primary float-right mx-3" %>
<% if user_signed_in? && @job.apply_available(current_user) %>
<button type="button" class="btn btn-primary float-right mx-3" disabled>Apply</button>
<% else %>
<%= link_to "Apply", apply_path(job_id: @job.id), class: "btn btn-primary float-right mx-3" %>
<% end %>
</div>
......@@ -15,6 +15,7 @@
<div>
<%= render partial: "shared/latest_job", collection: @latest_jobs %>
</div>
<%= link_to "All jobs", jobs_path, class: "btn btn-info" %>
</div>
<div class="top_cities text-center">
......
......@@ -9,12 +9,6 @@
</div>
<div class="form-group">
<%= f.label :username %>
<em>(optional)</em><br/>
<%= f.text_field :username, class: "form-control" %>
</div>
<div class="form-group">
<%= f.label :password %>
<% if @minimum_password_length %>
<em>(<%= @minimum_password_length %> characters minimum)</em>
......
......@@ -5,6 +5,9 @@ Rails.application.routes.draw do
resources :jobs, only: [:index, :show]
get "jobs/city/:city_id", to: "jobs#index", as: :city_jobs
get "jobs/industry/:industry_id", to: "jobs#index", as: :industry_jobs
get "apply", to: "jobs#apply"
get "confirm", to: "jobs#confirm_apply"
post "done", to: 'jobs#finish_apply'
devise_for :users
root "tops#index"
namespace :users do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment