Commit 7f7df78b by Quang Vinh Nguyen

add some job detail

parent 77d9a1de
...@@ -26,6 +26,7 @@ class JobsController < ApplicationController ...@@ -26,6 +26,7 @@ class JobsController < ApplicationController
def home def home
@jobs = Job.all.order(updated_at: :desc).take(5) @jobs = Job.all.order(updated_at: :desc).take(5)
@cities = City.all.select { |city| city.jobs.any? }.take(8) @cities = City.all.select { |city| city.jobs.any? }.take(9)
@industries = Industry.all.select { |industry| industry.jobs.any? }.take(9)
end end
end end
...@@ -3,15 +3,15 @@ class Company < ApplicationRecord ...@@ -3,15 +3,15 @@ class Company < ApplicationRecord
validates :name, presence: true, length: { maximum: 255 }, validates :name, presence: true, length: { maximum: 255 },
uniqueness: { case_sensitive: false } uniqueness: { case_sensitive: false }
validates :description, presence: true, length: { maximum: 1000 } # validates :description, presence: true, length: { maximum: 1000 }
validates :address, presence: true, length: { maximum: 255 } # validates :address, presence: true, length: { maximum: 255 }
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i # VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i
validates :email, length: { maximum: 255 }, # validates :email, length: { maximum: 255 },
format: { with: VALID_EMAIL_REGEX } # format: { with: VALID_EMAIL_REGEX }
VALID_PHONE_REGEX = /\A^(\+\d{1,2}\s)?\(?\d{3}\)?[\s.-]\d{3}[\s.-]\d{4}\z/ # VALID_PHONE_REGEX = /\A^(\+\d{1,2}\s)?\(?\d{3}\)?[\s.-]\d{3}[\s.-]\d{4}\z/
validates :phone, length: { maximum: 50 }, # validates :phone, length: { maximum: 50 },
format: { with: VALID_PHONE_REGEX } # format: { with: VALID_PHONE_REGEX }
validates :fax, length: { maximum: 50 } # validates :fax, length: { maximum: 50 }
validates :number_of_employees, length: { maximum: 255 } # validates :number_of_employees, length: { maximum: 255 }
end end
...@@ -18,13 +18,15 @@ class Job < ApplicationRecord ...@@ -18,13 +18,15 @@ class Job < ApplicationRecord
uniqueness: { case_sensitive: false } uniqueness: { case_sensitive: false }
validates :position, presence: true, length: { maximum: 255 } validates :position, presence: true, length: { maximum: 255 }
VALID_NUMBER_REGEX = /\A((\d{0,12}(\.\d{0,2})?)|(\.\d{0,2}))\z/ # VALID_NUMBER_REGEX = /\A((\d{0,12}(\.\d{0,2})?)|(\.\d{0,2}))\z/
validates :salary, presence: true, # validates :salary, presence: true,
format: { with: VALID_NUMBER_REGEX }, # format: { with: VALID_NUMBER_REGEX },
numericality: { # numericality: {
greater_than: 0.00, # greater_than: 0.00,
less_than: 999_999_999_999.99 # less_than: 999_999_999_999.99
} # }
validates :salary, presence: true
validates :expiry_date, presence: true validates :expiry_date, presence: true
validates :description, presence: true, length: { maximum: 1000 } validates :description, presence: true, length: { maximum: 1000 }
validates :update_date, presence: true validates :update_date, presence: true
......
<div class="card" style="width: 40rem;"> <div class='card' style='width: 40rem;'>
<div class="card-body"> <span class='card-body'>
<h5 class="card-title"><%= job.title %></h5> <h4 class='card-title'><%=link_to job.title, job %></h4>
<p class="card-text">some job description</p> <p class='card-text' ><strong>Description:</strong> <%= job.description.split('.').first %></p>
<p>Update date: <%= time_ago_in_words(job.created_at) %> ago. </p> <span class='card-text col-md-4'><strong>Location:</strong> <%= job.cities.map(&:name).reject(&:blank?).join(', ') %> </span>
<!-- <a href="#" class="card-link">Show job</a> --> <span class='card-text col-md-4'><strong>Salary:</strong> <%= job.salary %></span><br>
<%= link_to 'Show job', job, class: 'card-link' %> <span class='card-link col-md-4'><%= link_to 'Show', job %></span>
</div> </div>
</div> <br>
<br>
<h3>show all <%= pluralize(@cities.count, 'city') %></h3> <h3>Show all <%= pluralize(@cities.count, 'city') %></h3>
<ul class='list-group'> <ul class='list-group'>
<% @cities.each do |city| %> <% @cities.each do |city| %>
......
<div class='container'> <div class='container'>
<h3>Total: <%= pluralize(Job.count , 'job') %></h3><br>
<div class='container'> <div class='container'>
<nav class='navbar navbar-light bg-light'>
<%= form_tag( jobs_path, <%= form_tag( jobs_path,
method: 'get', method: 'get',
class: 'form-inline') do %> class: 'form-inline') do %>
<%= text_field_tag :search, params[:search], <%= text_field_tag :search, params[:search],
placeholder: 'Search Jobs', placeholder: 'search job',
class: 'form-control mr-sm-2'%> class: 'form-control mr-sm-2'%>
<%= submit_tag 'Search', name: nil, <%= submit_tag 'Search', name: nil,
class: 'btn btn-outline-success my-2 my-sm-0' %> class: 'btn btn-outline-success my-2 my-sm-0' %>
<% end %> <% end %>
</nav> </div> <br>
</div>
<div class='jobs-list'> <div class='container'>
<ul> <ul class='list-group'>
<%= render @jobs %> <% @jobs.each do |job| %>
<li class='list-group-item link'>
<%= link_to job.title, job %>
</li>
<% end %>
</ul> </ul>
</div> </div><br>
<h4> Cities list </h4> <div class='container'>
<div class='cities-list'> <h4>City:</h4>
<ul>
<div class="container">
<div class="row">
<% @cities.each do |city| %> <% @cities.each do |city| %>
<li> <div class="col-6 col-md-4 list-group-item">
<%= city.name %> <%= city.name %>
<%= link_to pluralize(city.jobs.count, 'job'), <%= link_to pluralize(city.jobs.count, 'job'),
controller: 'jobs', controller: 'jobs',
action: 'jobs_in_city', action: 'jobs_in_city',
slug: city.slug %> slug: city.slug %>
</li> </div>
<% end %> <% end %>
</ul> </div>
</div </div><br>
<h4>Industry:</h4>
<div class="container">
<div class="row">
<% @industries.each do |industry| %>
<div class="col-6 col-md-4 list-group-item">
<%= industry.name %>
<%= link_to pluralize(industry.jobs.count, 'job'),
controller: 'jobs',
action: 'jobs_in_city',
slug: industry.slug %>
</div>
<% end %>
</div>
</div>
</div> </div>
<h3>Search result: <%= pluralize(@job_num , 'job') %></h3> <div class='container'>
<div class='container'>
<nav class='navbar navbar-light bg-light'>
<%= form_tag(jobs_path, method: 'get', <%= form_tag(jobs_path, method: 'get',
class: 'form-inline') do %> class: 'form-inline') do %>
<%= text_field_tag :search, params[:search], <%= text_field_tag :search, params[:search],
...@@ -9,7 +8,13 @@ ...@@ -9,7 +8,13 @@
<%= submit_tag 'Search', name: nil, <%= submit_tag 'Search', name: nil,
class: 'btn btn-outline-success my-2 my-sm-0' %> class: 'btn btn-outline-success my-2 my-sm-0' %>
<% end %> <% end %>
</nav> </div><br>
<div class='container'>
<h3>Search result: <%= pluralize(@job_num , 'job') %></h3><br>
<%= paginate @jobs%> <%= paginate @jobs%>
<%= render @jobs %> <%= render @jobs %>
<%= paginate @jobs%>
</div>
</div>
<div class="row"> <div class="row">
<aside class="col-md-16"> <aside class="col-md-16">
<section class="user_info"> <section class="user_info">
<h2>Job detail</h2>
<h4> <h4>
<%= @job.title %> <%= @job.title %>
</h4> </h4>
<p> <p>
<%= @job.description %> <%= link_to "Apply", apply_path(job_id: @job.id),
</p> class: "btn btn-secondary" %>
</p><br>
<table class="table table-hover">
<tbody>
<tr>
<th scope="row col-8">Job title</th>
<td><%= @job.title %></td>
</tr>
<tr>
<th scope="row">Company</th>
<td><%= @job.company.name %></td>
</tr>
<tr>
<th scope="row">Location</th>
<td colspan="2">
<%= @job.cities.map(&:name).reject(&:blank?).join(', ') %>
</td>
</tr>
<tr>
<th scope="row">Salary</th>
<td colspan="2"><%= @job.salary %></td>
</tr>
<tr>
<th scope="row">Description</th>
<td colspan="2"><%= @job.description %></td>
</tr>
</tbody>
</table>
<%= link_to "Apply", apply_path(job_id: @job.id), <%= link_to "Apply", apply_path(job_id: @job.id),
class: "btn btn-secondary" %> class: "btn btn-secondary" %>
<%= link_to 'Back', :back, class: "btn btn-secondary" %> <%= link_to 'Back', :back, class: "btn btn-secondary" %>
</section> </section>
</aside> </aside>
</div> </div>
...@@ -8,9 +8,6 @@ ...@@ -8,9 +8,6 @@
<li class="nav-item active"> <li class="nav-item active">
<%= link_to 'Home', root_path, class: 'nav-link' %> <%= link_to 'Home', root_path, class: 'nav-link' %>
</li> </li>
<li class="nav-item active">
<%= link_to 'City', city_jobs_path, class: 'nav-link' %>
</li>
<% if user_signed_in? %> <% if user_signed_in? %>
<li class="nav-item active"> <li class="nav-item active">
<%= link_to 'Edit profile', edit_user_registration_path, class: 'nav-link' %> <%= link_to 'Edit profile', edit_user_registration_path, class: 'nav-link' %>
......
...@@ -4,7 +4,8 @@ class CreateJobs < ActiveRecord::Migration[5.2] ...@@ -4,7 +4,8 @@ class CreateJobs < ActiveRecord::Migration[5.2]
t.string :title, index: true t.string :title, index: true
t.references :company, foreign_key: true t.references :company, foreign_key: true
t.string :position t.string :position
t.decimal :salary, precision: 12, scale: 2 # t.decimal :salary, precision: 12, scale: 2
t.string :salary
t.datetime :expiry_date t.datetime :expiry_date
t.text :description t.text :description
t.datetime :update_date t.datetime :update_date
......
...@@ -22,15 +22,15 @@ namespace :importdb do ...@@ -22,15 +22,15 @@ namespace :importdb do
desc 'import data to companies table' desc 'import data to companies table'
task companies: :environment do task companies: :environment do
Company.create!( # Company.create!(
name: Faker::Company.name, # name: Faker::Company.name,
description: Faker::Lorem.paragraph, # description: Faker::Lorem.paragraph,
address: Faker::Address.street_address, # address: Faker::Address.street_address,
email: Faker::Internet.email, # email: Faker::Internet.email,
phone: '123-456-7890', # phone: '123-456-7890',
fax: '123-456-7890', # fax: '123-456-7890',
number_of_employees: '1000 - 2000' # number_of_employees: '1000 - 2000'
) # )
end end
desc 'seed industries data' desc 'seed industries data'
...@@ -51,16 +51,33 @@ namespace :importdb do ...@@ -51,16 +51,33 @@ namespace :importdb do
jobs_redis = Redis.new jobs_redis = Redis.new
jobs_yaml_arr = jobs_redis.smembers 'crawled' jobs_yaml_arr = jobs_redis.smembers 'crawled'
jobs_yaml_arr.each_with_index do |row,id| jobs_yaml_arr.each_with_index do |row,id|
# break if id == 3 # break if id == 100
job = YAML.safe_load(row) job = YAML.safe_load(row)
next if job[1].blank? || !!Job.find_by(title: job[1]) || !!Job.find_by(link: job[14]) next if job[1].blank? || !!Job.find_by(title: job[1]) || !!Job.find_by(link: job[14])
# create job company
next if job[2].blank?
company = Company.find_by(name: job[2])
unless company
company = Company.create( name: job[2],
description: Faker::Lorem.paragraph,
address: Faker::Address.street_address,
email: Faker::Internet.email,
phone: '123-456-7890',
fax: '123-456-7890',
number_of_employees: '1000 - 2000'
)
end
next unless company
# create job
job_new = Job.create!( job_new = Job.create!(
title: job[1], title: job[1],
company_id: 1, company_id: company.id,
position: 'NA', position: 'NA',
salary: '1_000', salary: job[7],
expiry_date: Time.now, expiry_date: Time.now,
description: 'NA', description: job[10],
update_date: Time.now, update_date: Time.now,
published: true, published: true,
welfare: 'NA', welfare: 'NA',
...@@ -78,7 +95,7 @@ namespace :importdb do ...@@ -78,7 +95,7 @@ namespace :importdb do
job_new.industries_jobs.create!(industry_id: City.first.id) job_new.industries_jobs.create!(industry_id: City.first.id)
end end
# import job industry # import job city
city_arr = job[3].split(',').map { |city| city.strip } city_arr = job[3].split(',').map { |city| city.strip }
if city_arr.any? if city_arr.any?
city_arr.each do |city| city_arr.each do |city|
......
...@@ -8,8 +8,8 @@ namespace :update do ...@@ -8,8 +8,8 @@ namespace :update do
jobs = Job.all jobs = Job.all
if jobs.any? if jobs.any?
jobs.each_with_index do |job, _id| jobs.each_with_index do |job, id|
# break if id == 102 # break if id == 10
# check is job_id is exist and not update job to solr # check is job_id is exist and not update job to solr
response_solr = solr.get 'select', params: { q: "job_id: #{job['id']}" } response_solr = solr.get 'select', params: { q: "job_id: #{job['id']}" }
next if response_solr['response']['docs'].any? next if response_solr['response']['docs'].any?
...@@ -17,26 +17,31 @@ namespace :update do ...@@ -17,26 +17,31 @@ namespace :update do
# hash of job attribute array: city_name, ... # hash of job attribute array: city_name, ...
h = {} h = {}
h['city_id'] = job.cities.collect { |city| city['id'].to_s } # h['city_id'] = job.cities.collect { |city| city['id'].to_s }
h['city_name'] = job.cities.collect { |city| city['name'].downcase } h['city_name'] = job.cities.collect { |city| city['name'].downcase }
h['city_slug'] = job.cities.collect { |city| city['slug'] } h['city_slug'] = job.cities.collect { |city| city['slug'] }
h['industry_id'] = job.industries.collect { |ind| ind['id'].to_s } # h['industry_id'] = job.industries.collect { |ind| ind['id'].to_s }
h['industry_name'] = job.industries.collect { |ind| ind['name'].downcase } h['industry_name'] = job.industries.collect { |ind| ind['name'].downcase }
h['industry_slug'] = job.industries.collect { |ind| ind['slug'] } h['industry_slug'] = job.industries.collect { |ind| ind['slug'] }
h['company_name'] = job.company.name.downcase
doc = { doc = {
job_id: job.id, job_id: job.id,
job_title: job.title.downcase, job_title: job.title.downcase,
job_city_id: h['city_id'], # job_city_id: h['city_id'],
job_city_name: h['city_name'], job_city_name: h['city_name'],
job_city_slug: h['city_slug'], job_city_slug: h['city_slug'],
job_industry_id: h['industry_id'], # job_industry_id: h['industry_id'],
job_industry_name: h['industry_name'], job_industry_name: h['industry_name'],
job_industry_slug: h['industry_slug'] job_industry_slug: h['industry_slug'],
job_company_name: h['company_name']
} }
solr.add [doc] solr.add [doc]
end end
solr.commit solr.commit
end end
# solr.delete_by_query '*:*'
# solr.commit
end end
end end
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