Commit 5aec5521 by Thai Ha

applied jobs search function

parent 57d07585
=> [#<ApplyJob:0x0000556661e18800
id: 74,
job_id: 893,
user_id: 2,
created_at: Thu, 07 Oct 2021 09:47:21.987489000 UTC +00:00,
updated_at: Thu, 07 Oct 2021 09:47:22.006742000 UTC +00:00,
user_name: "Mai Hoang Thai Ha`",
email: "messidauhoi@gmail.com">,
#<ApplyJob:0x0000556661e68b98
id: 75,
job_id: 893,
user_id: 2,
created_at: Fri, 08 Oct 2021 09:05:41.687605000 UTC +00:00,
updated_at: Fri, 08 Oct 2021 09:05:41.707387000 UTC +00:00,
user_name: "Mai Hoang Thai Ha`",
email: "messidauhoi@gmail.com">,
#<ApplyJob:0x0000556661e68a80
id: 76,
job_id: 890,
user_id: 6,
created_at: Thu, 21 Oct 2021 07:29:30.011249000 UTC +00:00,
updated_at: Thu, 21 Oct 2021 07:29:30.023913000 UTC +00:00,
user_name: "Mai Hoang Thai Ha`",
email: "mhthaiha@gmail.com">,
#<ApplyJob:0x0000556661e688f0
id: 77,
job_id: 889,
user_id: 6,
created_at: Thu, 21 Oct 2021 07:29:45.888611000 UTC +00:00,
updated_at: Thu, 21 Oct 2021 07:29:45.899844000 UTC +00:00,
user_name: "aasfasff ",
email: "mhthaiha@gmail.com">]
=> [#<ApplyJob:0x00005572d6d6c498
id: 74,
job_id: 893,
user_id: 2,
created_at: Thu, 07 Oct 2021 09:47:21.987489000 UTC +00:00,
updated_at: Thu, 07 Oct 2021 09:47:22.006742000 UTC +00:00,
user_name: "Mai Hoang Thai Ha`",
email: "messidauhoi@gmail.com">,
#<ApplyJob:0x00005572d6d6c3d0
id: 75,
job_id: 893,
user_id: 2,
created_at: Fri, 08 Oct 2021 09:05:41.687605000 UTC +00:00,
updated_at: Fri, 08 Oct 2021 09:05:41.707387000 UTC +00:00,
user_name: "Mai Hoang Thai Ha`",
email: "messidauhoi@gmail.com">,
#<ApplyJob:0x00005572d6d6c308
id: 76,
job_id: 890,
user_id: 6,
created_at: Thu, 21 Oct 2021 07:29:30.011249000 UTC +00:00,
updated_at: Thu, 21 Oct 2021 07:29:30.023913000 UTC +00:00,
user_name: "Mai Hoang Thai Ha`",
email: "mhthaiha@gmail.com">,
#<ApplyJob:0x00005572d6d6c240
id: 77,
job_id: 889,
user_id: 6,
created_at: Thu, 21 Oct 2021 07:29:45.888611000 UTC +00:00,
updated_at: Thu, 21 Oct 2021 07:29:45.899844000 UTC +00:00,
user_name: "aasfasff ",
email: "mhthaiha@gmail.com">]
...@@ -2,7 +2,54 @@ class AdminsController < ApplicationController ...@@ -2,7 +2,54 @@ class AdminsController < ApplicationController
before_action :authenticate_admin! before_action :authenticate_admin!
def applies def applies
@apply_jobs = ApplyJob.includes(:job, cv_attachment: :blob).all @city = City.all.map { |c| [c.name, c.id] }
.page(params[:page]).per(Job::JOB_PER_PAGE) @industry = Industry.all.map { |i| [i.name, i.id] }
search
return :applies if params[:search]
redirect_to admin_export_csv_path(format: :csv, params: applied_params) if params[:csv]
end
def export_csv
date = DateTime.current.to_formatted_s(:number)
search
csv = ExportCsvService.new(@apply_jobs, Admin::CSV_ATTRIBUTES)
respond_to do |format|
format.csv { send_data csv.perform, filename: "#{date}_applied.csv" }
end
end
private
def search
if applied_params.present?
date_value
params_query
@apply_jobs = Kaminari.paginate_array(@query).page(params[:page]).per(Job::JOB_PER_PAGE)
else
@apply_jobs = ApplyJob.includes(:job, cv_attachment: :blob).all
.page(params[:page]).per(Job::JOB_PER_PAGE)
end
end
def date_value
return unless applied_params[:date_start].present? && params[:date_end].present?
@d_start = Date.parse(applied_params[:date_start]).beginning_of_day
@d_end = Date.parse(applied_params[:date_end]).end_of_day
end
def params_query
search_params = { apply_jobs: { email: applied_params[:email],
created_at: (@d_start..@d_end if @d_start && @d_end) },
cities_jobs: { city_id: applied_params[:city] },
industries_jobs: { industry_id: applied_params[:industry] } }
.transform_values { |v| v.delete_if { |_, value| value.blank? } }
mapping = search_params.delete_if { |_, value| value.blank? }
@query = ApplyJob.admin_queries.where(mapping).uniq
end
def applied_params
params.permit(:email, :city, :industry, :date_start, :date_end)
end end
end end
...@@ -5,7 +5,6 @@ class ApplicationController < ActionController::Base ...@@ -5,7 +5,6 @@ class ApplicationController < ActionController::Base
before_action :configure_permitted_parameters, if: :devise_controller? before_action :configure_permitted_parameters, if: :devise_controller?
protected protected
def configure_permitted_parameters def configure_permitted_parameters
...@@ -15,13 +14,6 @@ class ApplicationController < ActionController::Base ...@@ -15,13 +14,6 @@ class ApplicationController < ActionController::Base
private private
def logged_in_user
unless user_signed_in?
flash[:danger] = 'Please log in.'
redirect_to new_user_session_path
end
end
def salary_search def salary_search
@salary_range = [0, 3_000_000, 7_000_000, 10_000_000, 15_000_000, 20_000_000, 30_000_000] @salary_range = [0, 3_000_000, 7_000_000, 10_000_000, 15_000_000, 20_000_000, 30_000_000]
end end
......
class FavoriteJobsController < ApplicationController class FavoriteJobsController < ApplicationController
before_action :logged_in_user # before_action :logged_in_user
before_action :authenticate_user!
before_action :load_job, only: %i[create destroy] before_action :load_job, only: %i[create destroy]
def index def index
......
class HistoryJobsController < ApplicationController class HistoryJobsController < ApplicationController
before_action :logged_in_user # before_action :logged_in_user
before_action :authenticate_user!
def index def index
@history_jobs = current_user.history_jobs.eager_load(job: %i[cities cities_jobs company]) @history_jobs = current_user.history_jobs.eager_load(job: %i[cities cities_jobs company])
......
class UsersController < ApplicationController class UsersController < ApplicationController
# before_action :logged_in_user
def show def show
@user = current_user @user = current_user
end end
......
class Admin < ApplicationRecord class Admin < ApplicationRecord
CSV_ATTRIBUTES = %w[id job_id user_id created_at updated_at user_name email].freeze
# Include default devise modules. Others available are: # Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :database_authenticatable, :registerable, devise :database_authenticatable, :registerable,
......
...@@ -15,4 +15,9 @@ class ApplyJob < ApplicationRecord ...@@ -15,4 +15,9 @@ class ApplyJob < ApplicationRecord
size: size:
{ less_than: 5.megabytes, { less_than: 5.megabytes,
message: 'should be less than 5MB' } message: 'should be less than 5MB' }
def self.admin_queries
includes(:job, cv_attachment: :blob)
.joins('INNER JOIN cities_jobs ON cities_jobs.job_id = apply_jobs.job_id')
.joins('INNER JOIN industries_jobs ON industries_jobs.job_id = apply_jobs.job_id')
end
end end
class ExportCsvService
def initialize(object, attributes)
@attributes = attributes
@object = object
@header = attributes.map { |attr| I18n.t("header_csv.#{attr}") }
end
def perform
CSV.generate do |csv|
csv << header
object.each do |object|
csv << attributes.map { |attr| object.public_send(attr) }
end
end
end
private
attr_reader :attributes, :object, :header
end
...@@ -22,7 +22,6 @@ class Solr ...@@ -22,7 +22,6 @@ class Solr
end end
jobs_index.each do |add_jobs| jobs_index.each do |add_jobs|
# byebug
@solr.add(add_jobs) @solr.add(add_jobs)
rescue Exception rescue Exception
next next
......
- provide(:title, 'All applies jobs') - provide(:title, 'All applies jobs')
/ search
.container.mt-5
= form_with(url: admin_applies_jobs_path, method: :get, local: true) do |f|
.row.mb-2.form-group
.col-2
= f.label :email, 'Email', class: 'form-label'
.col-10
= f.text_field :email, class: 'form-control', value: params[:email]
.row.mb-2.form-group
.col-2
= f.label :city, 'City'
.col-10
= f.select :city, @city, selected: params[:city], include_blank: 'Select city', class:"form-select bg-light h-100"
/ = f.select :city, @city, {include_blank: 'Select city'}, {class: 'form-select bg-light h-100'}
/ =f.select :sex, %w{ Male Female }, :prompt => "Gender..."
.row.mb-2.form-group
.col-2
= f.label :industry, 'Industry', class: 'form-label'
.col-10
= f.select :industry, @industry, selected: params[:industry], include_blank: 'Select industry', class:'form-select bg-light h-100'
.row.mb-2.form-group
.col-6
.row
.col-4
= f.label :date_start, 'From', class: 'form-label'
.col-8
= f.date_field :date_start, value: params[:date_start], class: 'form-control'
.col-6
.row
.col-4
= f.label :date_end, 'To', class: 'form-label'
.col-8
= f.date_field :date_end, value: params[:date_end], class: 'form-control'
.row
.col-6.d-flex.justify-content-center
= f.submit 'Search', name: 'search', class: 'btn btn-primary w-50 my-4 btn-height',data: { disable_with: false }
.col-6.d-flex.justify-content-center
= f.submit 'Export', name: 'csv',class: 'btn btn-primary w-50 my-4 btn-height',data: { disable_with: false }
/ = link_to 'Export csv', admin_export_csv_path(format: :csv), class: 'btn btn-primary w-50 my-4 btn-height'
.container .container
h2.my-5.text-center h2.my-5.text-center
| All applies jobs | All applies jobs
......
...@@ -31,3 +31,11 @@ ...@@ -31,3 +31,11 @@
en: en:
hello: "Hello world" hello: "Hello world"
header_csv:
id: ID
job_id: Job ID
user_id: User ID
created_at: Applied at
updated_at: Updated at
user_name: User name
email: Email
...@@ -42,4 +42,5 @@ Rails.application.routes.draw do ...@@ -42,4 +42,5 @@ Rails.application.routes.draw do
post '/done', to: 'applies#create', as: :done_job post '/done', to: 'applies#create', as: :done_job
get '/history', to: 'history_jobs#index', as: :history_jobs get '/history', to: 'history_jobs#index', as: :history_jobs
get '/admin/applies', to: 'admins#applies', as: :admin_applies_jobs get '/admin/applies', to: 'admins#applies', as: :admin_applies_jobs
get '/admin/export', to: 'admins#export_csv', as: :admin_export_csv
end end
...@@ -65,22 +65,20 @@ namespace :crawler do ...@@ -65,22 +65,20 @@ namespace :crawler do
# salary # salary
if salary.include?('USD') if salary.include?('USD')
parsed = parse_salary(salary.remove('USD', ','), 23_000) parsed = parse_salary(salary.remove('USD', ','), 23_000)
if parsed.length == 1 min_salary = parsed[0]
min_salary = parsed[0] max_salary = if parsed.length == 1
max_salary = parsed[0] parsed[0]
else else
min_salary = parsed[0] parsed[1]
max_salary = parsed[1] end
end
elsif salary.include?('VND') elsif salary.include?('VND')
parsed = parse_salary(salary.remove('tr', 'VND'), 1_000_000) parsed = parse_salary(salary.remove('tr', 'VND'), 1_000_000)
if parsed.length == 1 min_salary = parsed[0]
min_salary = parsed[0] max_salary = if parsed.length == 1
max_salary = parsed[0] parsed[0]
else else
min_salary = parsed[0] max_salary = parsed[1]
max_salary = parsed[1] end
end
else else
min_salary = 999_999_999 min_salary = 999_999_999
max_salary = 999_999_999 max_salary = 999_999_999
......
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