Commit a8e21f8c by Huỳnh Thiên Phước

Merge branch 'master' into 'favorite_history'

# Conflicts:
#   config/routes.rb
parents 6ccea578 f95ce8a2
Pipeline #1067 failed with stages
in 0 seconds
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!(session[:cv])
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
class JobAppliedsController < ApplicationController
before_action :sign_in_validation, only: %i[new confirmation create show]
before_action :find_job_id, only: [:new]
def new
session[:job_id] = params[:job_id]
if session[:job_applied].present?
user_name = session[:job_applied]['name']
user_email = session[:job_applied]['email']
end
session[:job_id] ||= session[:get_job_id]
user_name ||= current_user.name
user_email ||= current_user.email
founded_application = JobApplied.exists?(user_id: current_user.id, job_id: session[:job_id])
return redirect_to job_detail_path(session[:job_id]) if founded_application
@job_applied = current_user.job_applieds.new(name: user_name,
email: user_email)
end
def show
@users = current_user.job_applieds.order("job_applieds.updated_at DESC").page(params[:page]).per(Job::LIMIT_PAGE)
end
def confirmation
session[:get_job_id] = session[:job_id]
@job_applied = current_user.job_applieds.new(apply_params)
session[:job_applied] = @job_applied
@job_applied.cv_user = current_user.cv_user if apply_params[:cv_user].blank?
@job_applied.job_id = session[:get_job_id] if @job_applied.job_id.blank?
if @job_applied.invalid?
flash.now[:danger] = @job_applied.errors.full_messages.join('<br>')
render :new
end
end
def create
@job = Job.find_by(id: session[:get_job_id])
@job_applied = current_user.job_applieds.new(apply_params)
@job_applied.job_id = session[:get_job_id] if @job_applied.job_id.blank?
@job_applied.cv_user.retrieve_from_cache!(apply_params[:cv_user])
if @job_applied.save
JobAppliedMailer.apply_job(@job_applied, @job).deliver_later
JobAppliedMailer.sending_admin(@job_applied, @job, ENV['GMAIL_USERNAME']).deliver_later
end
session.delete(:job_applied)
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 find_job_id
return redirect_to jobs_path unless Job.find_by(id: params[:job_id])
end
end
...@@ -27,7 +27,8 @@ class JobsController < ApplicationController ...@@ -27,7 +27,8 @@ class JobsController < ApplicationController
end end
def show def show
session.delete(:job_applied) session.delete(:apply_job)
session.delete(:cv)
return redirect_to jobs_path unless @job return redirect_to jobs_path unless @job
if signed_in? if signed_in?
@is_job_applied = current_user.job_applieds.pluck(:job_id).include?@job.id @is_job_applied = current_user.job_applieds.pluck(:job_id).include?@job.id
......
class JobAppliedMailer < ActionMailer::Base class AppliedJobMailer < ActionMailer::Base
def apply_job(user, job) def apply_job(user, job)
@job = job @job = job
@user = user @user = user
......
...@@ -16,6 +16,11 @@ class UserCvUploader < CarrierWave::Uploader::Base ...@@ -16,6 +16,11 @@ class UserCvUploader < CarrierWave::Uploader::Base
def size_range def size_range
0..5.megabytes 0..5.megabytes
end 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: # Provide a default URL as a default if there hasn't been a file uploaded:
# def default_url(*args) # def default_url(*args)
# # For Rails 3.1+ asset pipeline compatibility: # # For Rails 3.1+ asset pipeline compatibility:
......
<div class="border border-dark rounded"> <div class="border border-dark rounded">
<div class="job-details"> <div class="job-details">
<div class="title"> <div class="title">
<%= link_to job_detail_path(user.job.id) do %><strong> <%= link_to job_detail_path(applied_job.job.id) do %><strong>
<%= user.job.title %></strong> <%= applied_job.job.title %></strong>
<% end %> <% end %>
</div> </div>
<div class="introduction"> <div class="introduction">
<%= strip_tags(user.job.format_desc) %><br> <%= strip_tags(applied_job.job.format_desc) %><br>
<%= link_to 'Read more..', job_detail_path(user.job.id) %> <%= link_to 'Read more..', job_detail_path(applied_job.job.id) %>
</div> </div>
<div class="row"> <div class="row">
<div class="col-6"> <div class="col-6">
<%= user.job.cities.map(&:name).join(' | ') %> <%= applied_job.job.cities.map(&:name).join(' | ') %>
</div> </div>
<div class="salary col-3"> <div class="salary col-3">
Salary: <%= user.job.salary %> Salary: <%= applied_job.job.salary %>
</div> </div>
<div class="applied-at col-3"> <div class="applied-at col-3">
<strong>Applied at:</strong> <strong>Applied at:</strong>
<%= user.updated_at.strftime('%d/%m/%Y') %> <%= applied_job.updated_at.strftime('%d/%m/%Y') %>
</div> </div>
</div> </div>
</div> </div>
......
...@@ -28,11 +28,10 @@ ...@@ -28,11 +28,10 @@
</div> </div>
<div class="col-8-sm"> <div class="col-8-sm">
<%= link_to @job_applied.cv_user.identifier, @job_applied.cv_user.url, download: @job_applied.cv_user.identifier %> <%= link_to @job_applied.cv_user.identifier, @job_applied.cv_user.url, download: @job_applied.cv_user.identifier %>
<%= f.hidden_field :cv_user, value: @job_applied.cv_user.cache_name %>
</div> </div>
</div> </div>
<%= link_to 'Edit', apply_job_path(job_id: session[:get_job_id]), class: 'btn btn-outline-primary btn-lg update-btn' %> <%= 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' %> <%= f.submit 'Done', class: 'btn btn-outline-primary btn-lg update-btn' %>
<% end %> <% end %>
</div> </div>
......
...@@ -29,8 +29,8 @@ ...@@ -29,8 +29,8 @@
<%= f.label :cv_user, 'My CV' %> <%= f.label :cv_user, 'My CV' %>
</div> </div>
<div class="col-8-sm"> <div class="col-8-sm">
<% if current_user.cv_user.present? %> <% if @job_applied.cv_user.present? %>
<%= link_to current_user.cv_user.identifier, current_user.cv_user.url, download: current_user.cv_user.identifier %> <%= link_to @job_applied.cv_user.identifier, @job_applied.cv_user.url, download: @job_applied.cv_user.identifier %>
<div class="cv-none"> <div class="cv-none">
<%= f.file_field :cv_user, accept: '.doc, .pdf, .xls, .xlsx, .zip',class: 'input-cv' %> <%= f.file_field :cv_user, accept: '.doc, .pdf, .xls, .xlsx, .zip',class: 'input-cv' %>
</div> </div>
......
<div class="container"> <div class="container">
<% if @users.count > 0 %> <% if @applied_jobs.count > 0 %>
<h1 class="text-center my-job-label">My Job</h1> <h1 class="text-center my-job-label">My Job</h1>
<%= paginate @users, outer_window: 2, window: 1 %> <%= paginate @applied_jobs, outer_window: 2, window: 1 %>
<%= render partial: "job_applieds/my_jobs", collection: @users, as: :user %> <%= render partial: "job_applieds/my_jobs", collection: @applied_jobs, as: :applied_job %>
<%= paginate @users, outer_window: 2, window: 1 %> <%= paginate @applied_jobs, outer_window: 2, window: 1 %>
<% else %> <% else %>
<h1 class="let-apply">Let's apply job</h1> <h1 class="let-apply">Let's apply job</h1>
<% end %> <% end %>
......
<% provide(:title, 'Jobs') %> <% provide(:title, 'Jobs') %>
<div class="container"> <div class="container">
<%= render 'layouts/flash' %>
<div class="search-bar"> <div class="search-bar">
<%= render 'layouts/search_bar' %> <%= render 'layouts/search_bar' %>
</div> </div>
......
<div class="container"> <div class="container">
<%= render 'layouts/flash' %>
<div class="details-banner"> <div class="details-banner">
<div class="job-details-banner"> <div class="job-details-banner">
<div class="job-info"> <div class="job-info">
......
...@@ -19,12 +19,12 @@ Rails.application.routes.draw do ...@@ -19,12 +19,12 @@ Rails.application.routes.draw do
get '/registation/3', to: 'users#registation', as: :registation get '/registation/3', to: 'users#registation', as: :registation
get 'apply', to: 'job_applieds#new', as: :apply_job get 'apply', to: 'applied_jobs#new', as: :apply_job
post 'confirm', to: 'job_applieds#confirmation', as: :confirm_job post 'confirm', to: 'applied_jobs#confirmation', as: :confirm_job
post 'done', to: 'job_applieds#create', as: :finished_apply post 'done', to: 'applied_jobs#create', as: :finished_apply
get '/my/jobs', to: 'job_applieds#show', as: :my_jobs get '/my/jobs', to: 'applied_jobs#show', as: :my_jobs
resources :jobs resources :jobs
get 'detail/:id', to: 'jobs#show', as: :job_detail get 'detail/:id', to: 'jobs#show', as: :job_detail
...@@ -41,7 +41,7 @@ Rails.application.routes.draw do ...@@ -41,7 +41,7 @@ Rails.application.routes.draw do
resources :history_jobs, only: [:index] resources :history_jobs, only: [:index]
resources :favorite_jobs, only: [:create, :destroy, :index] resources :favorite_jobs, only: [:create, :destroy, :index]
resources :job_applieds,only: [:new, :create] resources :applied_jobs, only: [:new, :create]
resources :reset_passwords, only: [:edit, :update] resources :reset_passwords, only: [:edit, :update]
resources :confirmations, only: [:new] resources :confirmations, only: [:new]
resources :top_pages, only: [:index] resources :top_pages, only: [:index]
......
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