Commit d1626af3 by Van Hau Le

Merge branch 'apply_job' into 'master'

Created ID5-6-7

See merge request !12
parents 7e32986d d2fa7457
Pipeline #1058 canceled with stages
in 0 seconds
......@@ -31,3 +31,4 @@
/config/master.key
config/local_env.yml
public/uploads
// Place all the styles related to the Top_pages controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
.ribbon-mark {
margin: 40px;
position: relative;
}
.arrow-new.active {
width: 250px;
height: 50px;
background: #66c2ff;
position: relative;
&:after {
content: '';
position: absolute;
left: 0; bottom: 0; width: 0; height: 0;
border-left: 25px solid white;
border-top: 25px solid transparent;
border-bottom: 25px solid transparent;
}
&:before {
content: '';
position: absolute;
right: -25px;
bottom: 0;
width: 0;
height: 0;
border-left: 25px solid #66c2ff;
border-top: 25px solid transparent;
border-bottom: 25px solid transparent;
}
.text-ribbon {
position: absolute;
top: 25%;
right: 55%;
}
.number-circle {
color: #66c2ff;
text-align: center;
background: white;
width: 20px;
height: 20px;
border-radius: 50%;
}
.text-near-circle {
font-size: 20px;
color: white;
position: absolute;
top: -25%;
left: 20px;
}
}
.arrow-confirm.active, .arrow-finish.active {
width: 250px;
height: 50px;
background: #66c2ff;
position: relative;
&:after {
content: '';
position: absolute;
left: 0; bottom: 0; width: 0; height: 0;
border-left: 25px solid #66c2ff;
border-top: 25px solid transparent;
border-bottom: 25px solid transparent;
}
&:before {
content: '';
position: absolute;
right: -25px;
bottom: 0;
width: 0;
height: 0;
border-left: 25px solid #66c2ff;
border-top: 25px solid transparent;
border-bottom: 25px solid transparent;
}
.text-ribbon {
position: absolute;
top: 25%;
right: 55%;
}
.number-circle {
color: #66c2ff;
text-align: center;
background: white;
width: 20px;
height: 20px;
border-radius: 50%;
}
.text-near-circle {
font-size: 20px;
color: white;
position: absolute;
top: -25%;
left: 20px;
}
}
.arrow-new, .arrow-confirm, .arrow-finish {
width: 250px;
height: 50px;
color: #666666;
position: relative;
.text-ribbon {
position: absolute;
top: 25%;
right: 55%;
}
.number-circle {
text-align: center;
background: #e6e6e6;
width: 20px;
height: 20px;
border-radius: 50%;
}
.text-near-circle {
font-size: 20px;
position: absolute;
top: -25%;
left: 20px;
}
}
......@@ -63,3 +63,7 @@
.industry:last-child::after, .location:last-child::after {
content: "";
}
.my-job-label, .let-apply{
padding: 30px;
margin: 30px;
}
class AppliedJobsController < ApplicationController
before_action :sign_in_validation, only: %i[new confirmation create show]
before_action :validate_apply_job, only: %i[new confirmation create]
def new
apply_info = session[:apply_job] || {}
apply_info[:job_id] = params[:job_id]
apply_info[:name] ||= current_user.name
apply_info[:email] ||= current_user.email
session[:apply_job] = {job_id: apply_info[:job_id]}
@job_applied = current_user.job_applieds.new(name: apply_info[:name],
email: apply_info[:email])
@job_applied.cv_user.retrieve_from_cache!(session[:cv]) if session[:cv].present?
@job_applied.cv_user = current_user.cv_user if @job_applied.cv_user.blank?
end
def show
@applied_jobs = current_user.job_applieds.order(updated_at: :desc).page(params[:page]).per(Job::LIMIT_PAGE)
end
def confirmation
@job_applied = current_user.job_applieds.new(apply_params)
@job_applied.job_id = session[:apply_job]['job_id'] if @job_applied.job_id.blank?
@job_applied.cv_user.retrieve_from_cache!(session[:cv]) if @job_applied.cv_user.blank? && session[:cv].present?
@job_applied.cv_user = current_user.cv_user if @job_applied.cv_user.blank?
if @job_applied.invalid?
flash.now[:danger] = @job_applied.errors.full_messages.join('<br>')
render :new
end
session[:apply_job] = @job_applied
session[:cv] = @job_applied.cv_user.cache_name
end
def create
@job = Job.find_by(id: session[:apply_job]['job_id'])
@job_applied = current_user.job_applieds.new(apply_params)
@job_applied.job_id = @job.id if @job_applied.job_id.blank?
@job_applied.cv_user.retrieve_from_cache!(apply_params[:cv_user])
if @job_applied.save
AppliedJobMailer.apply_job(@job_applied, @job).deliver_later
AppliedJobMailer.sending_admin(@job_applied, @job, ENV['GMAIL_USERNAME']).deliver_later
session.delete(:apply_job)
else
flash[:danger] = @job_applied.errors.full_messages.join('<br>')
redirect_to apply_job_path(job_id: @job.id)
end
end
private
def sign_in_validation
return if signed_in?
store_location
flash[:warning] = Settings.user.warning_signin
redirect_to login_path
end
def apply_params
params.require(:job_applied).permit(:name, :email, :cv_user)
end
def validate_apply_job
job_id = params[:job_id] || session[:apply_job].try(:[], 'job_id')
return redirect_to jobs_path, flash: { warning: 'Job not found!'} unless Job.find_by_id(job_id)
job_applied = JobApplied.exists?(user_id: current_user.id, job_id: job_id)
return redirect_to job_detail_path(job_id), flash: { info: 'You applied for job'} if job_applied
end
end
......@@ -27,7 +27,10 @@ class JobsController < ApplicationController
end
def show
redirect_to jobs_path unless @job
session.delete(:apply_job)
session.delete(:cv)
return redirect_to jobs_path unless @job
@user = JobApplied.where(user_id: current_user.id, job_id: params[:id]) if signed_in?
end
private
......
......@@ -8,7 +8,7 @@ class SessionsController < ApplicationController
user = User.find_by(email: params[:session][:email].downcase)
if user && user.authenticate(params[:session][:password])
sign_in user
redirect_to my_page_path
redirect_back_or my_page_path
else
flash.now[:danger] = Settings.user.sign_in.failed
render 'new'
......
......@@ -40,6 +40,7 @@ class UsersController < ApplicationController
def sign_in_validation
return if signed_in?
store_location
flash[:warning] = Settings.user.warning_signin
redirect_to login_path
end
......
......@@ -27,4 +27,12 @@ module SessionsHelper
self.current_user = nil
end
def redirect_back_or(default)
redirect_to(session[:return_to] || default)
session.delete(:return_to)
end
def store_location
session[:return_to] = request.url if request.get?
end
end
class AppliedJobMailer < ActionMailer::Base
def apply_job(user, job)
@job = job
@user = user
mail(to: user.email, subject: Settings.email.job_applied)
end
def sending_admin(user, job, email)
@job = job
@user = user
mail(to: email, subject: Settings.email.job_applied)
end
end
class ConfirmationMailer < ActionMailer::Base
def register_email(user)
@user = user
mail(to: user.email, subject: 'Welcome To VeNJOB! Confirm Your Email')
mail(to: user.email, subject: Settings.email.confirmation)
end
end
class ResetPasswordMailer < ActionMailer::Base
def reset_password(user)
@user = user
mail(to: user.email, subject: 'VeNJOB Password Assistance')
mail(to: user.email, subject: Settings.email.reset_password)
end
end
class JobApplied < ApplicationRecord
before_save { self.email = email.downcase }
mount_uploader :cv_user, UserCvUploader
belongs_to :user
belongs_to :job
validates :name, presence: true, length: { maximum: 200 }
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(?:\.[a-z\d\-]+)*\.[a-z]+\z/i
validates :email, presence: true, length: { maximum: 200 }, format: { with: VALID_EMAIL_REGEX }
validates :cv_user, presence: true
end
......@@ -16,6 +16,11 @@ class UserCvUploader < CarrierWave::Uploader::Base
def size_range
0..5.megabytes
end
def extension_whitelist
%w(doc pdf xls xlsx zip)
end
# Provide a default URL as a default if there hasn't been a file uploaded:
# def default_url(*args)
# # For Rails 3.1+ asset pipeline compatibility:
......
<h2>Dear <%= @user.name %></h2>
<p>Thank you for applied with VenJOB. Your applied job's information is as follow:</p>
<p><h3>Title: <%= @job.title %></h3></p>
<p><h3>Cities: <%= @job.cities.map(&:name).join(' | ') %></h3></p>
<p><h3>Company: <%= @job.company.name %></h3></p>
<p>Your submitted information:</p>
<p><h3>Name: <%= @user.name %></h3></p>
<p><h3>Email: <%= @user.email %></h3></p>
<p><h3>Your CV: <%= link_to @user.cv_user.identifier, (root_url.chop + @user.cv_user.url) %></h3></p>
Best,
<h2>Dear <%= @user.name %></h2>
<p>Thank you for applied with VenJOB. Your applied job's information is as follow:</p>
<p><h3>Title: <%= @job.title %></h3></p>
<p><h3>Cities: <%= @job.cities.map(&:name).join(' | ') %></h3></p>
<p><h3>Company: <%= @job.company.name %></h3></p>
<p>Your submitted information:</p>
<p><h3>Name: <%= @user.name %></h3></p>
<p><h3>Email: <%= @user.email %></h3></p>
<p><h3>CV: <%= link_to @user.cv_user.identifier, (root_url.chop + @user.cv_user.url) %></h3></p>
Best,
<div class="border border-dark rounded">
<div class="job-details">
<div class="title">
<%= link_to job_detail_path(applied_job.job.id) do %><strong>
<%= applied_job.job.title %></strong>
<% end %>
</div>
<div class="introduction">
<%= strip_tags(applied_job.job.format_desc) %><br>
<%= link_to 'Read more..', job_detail_path(applied_job.job.id) %>
</div>
<div class="row">
<div class="col-6">
<%= applied_job.job.cities.map(&:name).join(' | ') %>
</div>
<div class="salary col-3">
Salary: <%= applied_job.job.salary %>
</div>
<div class="applied-at col-3">
<strong>Applied at:</strong>
<%= applied_job.updated_at.strftime('%d/%m/%Y') %>
</div>
</div>
</div>
</div>
<br>
<div class="col-4 arrow-new <%= step1 %>">
<div class="text-ribbon">
<div class="row">
<strong>
<div class="number-circle">1</div>
<div class="text-near-circle">New</div>
</strong>
</div>
</div>
</div>
<div class="col-4 text-center arrow-confirm <%= step2 %>">
<div class="text-ribbon">
<div class="row">
<strong>
<div class="number-circle">2</div>
<div class="text-near-circle">Confirm</div>
</strong>
</div>
</div>
</div>
<div class="col-4 text-center arrow-finish <%= step3 %>">
<div class="text-ribbon">
<div class="row">
<strong>
<div class="number-circle">3</div>
<div class="text-near-circle">Finish</div>
</strong>
</div>
</div>
</div>
<div class="container">
<div class="row ribbon-mark">
<%= render partial: 'ribbon_step', locals: { step1: 'active', step2: 'active', step3: '' } %>
</div>
<h1 class="text-center my-page-label">Confirmation</h1>
<div class="form-login">
<div class="row form d-flex justify-content-center">
<%= form_for(@job_applied, url: finished_apply_path) do |f| %>
<div class="email-field">
<div class="col-4-sm">
<%= f.label :email %>
</div>
<div class="col-8-sm">
<strong><%= f.text_field :email, value: @job_applied.email, readonly: true %></strong>
</div>
</div>
<div class="name-field">
<div class="col-4-sm">
<%= f.label :name, 'Full Name' %>
</div>
<div class="col-8-sm">
<strong><%= f.text_field :name, value: @job_applied.name, readonly: true %></strong>
</div>
</div>
<div class="cv-field">
<div class="col-4-sm">
<%= f.label :cv_user, 'CV Upload' %>
</div>
<div class="col-8-sm">
<%= link_to @job_applied.cv_user.identifier, @job_applied.cv_user.url, download: @job_applied.cv_user.identifier %>
</div>
</div>
<%= link_to 'Edit', apply_job_path(job_id: session[:apply_job]['job_id']), class: 'btn btn-outline-primary btn-lg update-btn' %>
<%= f.submit 'Done', class: 'btn btn-outline-primary btn-lg update-btn' %>
<% end %>
</div>
</div>
</div>
<div class="container">
<div class="row ribbon-mark">
<%= render partial: 'ribbon_step', locals: { step1: 'active', step2: 'active', step3: 'active' } %>
</div>
<div class="text-center">
<h1 class="my-page-label">Thank you for apply</h1>
<p>Back to <%= link_to 'TOP', root_path %> page</p>
</div>
</div>
<div class="container">
<div class="row ribbon-mark">
<%= render partial: 'ribbon_step', locals: { step1: 'active', step2: '', step3: '' } %>
</div>
<h1 class="text-center my-page-label">Apply Form</h1>
<div class="form-login">
<%= render 'layouts/flash' %>
<div class="row form d-flex justify-content-center">
<%= form_for(@job_applied, url: confirm_job_path) do |f| %>
<div class="validation"></div>
<div class="email-field">
<div class="col-4-sm">
<%= f.label :email %>
</div>
<div class="col-8-sm">
<%= f.text_field :email, class: 'input-email' %>
</div>
</div>
<div class="name-field">
<div class="col-4-sm">
<%= f.label :name, 'Full Name' %>
</div>
<div class="col-8-sm">
<%= f.text_field :name, class: 'input-name' %>
</div>
</div>
<div class="cv-field">
<div class="col-4-sm">
<%= f.label :cv_user, 'My CV' %>
</div>
<div class="col-8-sm">
<% if @job_applied.cv_user.present? %>
<%= link_to @job_applied.cv_user.identifier, @job_applied.cv_user.url, download: @job_applied.cv_user.identifier %>
<div class="cv-none">
<%= f.file_field :cv_user, accept: '.doc, .pdf, .xls, .xlsx, .zip',class: 'input-cv' %>
</div>
<% else %>
<div class="cv-none">
<%= f.file_field :cv_user, accept: '.doc, .pdf, .xls, .xlsx, .zip',class: 'input-cv' %>
</div>
<% end %>
</div>
</div>
<%= f.submit 'Confirm', class: 'btn btn-outline-primary btn-lg update-btn' %>
<% end %>
</div>
</div>
</div>
<div class="container">
<% if @applied_jobs.count > 0 %>
<h1 class="text-center my-job-label">My Job</h1>
<%= paginate @applied_jobs, outer_window: 2, window: 1 %>
<%= render partial: "job_applieds/my_jobs", collection: @applied_jobs, as: :applied_job %>
<%= paginate @applied_jobs, outer_window: 2, window: 1 %>
<% else %>
<h1 class="let-apply">Let's apply job</h1>
<% end %>
</div>
<% provide(:title, 'Jobs') %>
<div class="container">
<%= render 'layouts/flash' %>
<div class="search-bar">
<%= render 'layouts/search_bar' %>
</div>
......
<div class="container">
<%= render 'layouts/flash' %>
<div class="details-banner">
<div class="job-details-banner">
<div class="job-info">
......@@ -18,10 +19,16 @@
<% end %>/&ensp;
<%= @job.title.truncate_words(5) %>
</div>
<%= link_to '#' do %>
<% if signed_in? && @user.present? %>
<div class="apply-job">
<strong>Apply Now</strong>
<strong>Applied</strong>
</div>
<% else %>
<%= link_to apply_job_path(job_id: @job.id) do %>
<div class="apply-job">
<strong>Apply Now</strong>
</div>
<% end %>
<% end %>
</div>
</div>
......@@ -68,10 +75,16 @@
</div>
<div class="row under-descrip">
<div class="col-6">
<%= link_to '#' do %>
<% if signed_in? && @user.present? %>
<div class="btn btn-info btn-lg apply-btn">
<strong>Apply Now</strong>
<strong>Applied</strong>
</div>
<% else %>
<%= link_to apply_job_path(job_id: @job.id) do %>
<div class="btn btn-info btn-lg apply-btn">
<strong>Apply Now</strong>
</div>
<% end %>
<% end %>
</div>
<div class="col-6">
......
<div class="flash rounded">
<% flash.each do |key, value| %>
<div class="alert alert-<%= key %>"><%= value %></div>
<div class="text-center alert alert-<%= key %>"><strong><%= value.html_safe %></strong></div>
<% end %>
</div>
......@@ -25,9 +25,7 @@
<%= f.label :cv_user, 'My CV' %>
</div>
<div class="col-8-sm">
<% if current_user.cv_user.present? %>
<%= link_to current_user.cv_user.identifier, current_user.cv_user.url, download: current_user.cv_user.identifier %>
<% else %>
<%= link_to_if current_user.cv_user.present? ,current_user.cv_user.identifier, current_user.cv_user.url, download: current_user.cv_user.identifier do %>
<div class="cv-none">
CV hasn't found in your Profile. Upload now!
</div>
......@@ -36,7 +34,7 @@
</div>
<%= link_to 'Update', my_page_info_path, class: 'btn btn-outline-primary btn-lg update-btn' %>
<%= link_to 'My Jobs', '#', class: 'btn btn-outline-info btn-lg my-jobs-btn' %>
<%= link_to 'My Jobs', my_jobs_path, class: 'btn btn-outline-info btn-lg my-jobs-btn' %>
<% end %>
</div>
</div>
......
......@@ -19,6 +19,12 @@ Rails.application.routes.draw do
get '/registation/3', to: 'users#registation', as: :registation
get 'apply', to: 'applied_jobs#new', as: :apply_job
post 'confirm', to: 'applied_jobs#confirmation', as: :confirm_job
post 'done', to: 'applied_jobs#create', as: :finished_apply
get '/my/jobs', to: 'applied_jobs#show', as: :my_jobs
resources :jobs
get 'detail/:id', to: 'jobs#show', as: :job_detail
......@@ -27,6 +33,7 @@ Rails.application.routes.draw do
get 'jobs/industry/:converted_name', to: 'jobs#industry_jobs', as: :industry_jobs
get 'jobs/company/:converted_name', to: 'jobs#company_jobs', as: :company_jobs
resources :applied_jobs, only: [:new, :create]
resources :reset_passwords, only: [:edit, :update]
resources :confirmations, only: [:new]
resources :top_pages, only: [:index]
......
......@@ -18,3 +18,10 @@ user:
existed: 'Email existed. Please change !!!'
format_failed: 'Email formated invalid'
applied_job:
applied: 'You applied for this job'
email:
confirmation: 'Welcome To VeNJOB! Confirm Your Email'
reset_password: 'VeNJOB Password Assistance'
job_applied: 'Thank your for apply with VeNJOB'
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