Commit 7f7df78b by Quang Vinh Nguyen

add some job detail

parent 77d9a1de
......@@ -26,6 +26,7 @@ class JobsController < ApplicationController
def home
@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
......@@ -3,15 +3,15 @@ class Company < ApplicationRecord
validates :name, presence: true, length: { maximum: 255 },
uniqueness: { case_sensitive: false }
validates :description, presence: true, length: { maximum: 1000 }
validates :address, presence: true, length: { maximum: 255 }
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i
validates :email, length: { maximum: 255 },
format: { with: VALID_EMAIL_REGEX }
# validates :description, presence: true, length: { maximum: 1000 }
# validates :address, presence: true, length: { maximum: 255 }
# VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i
# validates :email, length: { maximum: 255 },
# format: { with: VALID_EMAIL_REGEX }
VALID_PHONE_REGEX = /\A^(\+\d{1,2}\s)?\(?\d{3}\)?[\s.-]\d{3}[\s.-]\d{4}\z/
validates :phone, length: { maximum: 50 },
format: { with: VALID_PHONE_REGEX }
validates :fax, length: { maximum: 50 }
validates :number_of_employees, length: { maximum: 255 }
# VALID_PHONE_REGEX = /\A^(\+\d{1,2}\s)?\(?\d{3}\)?[\s.-]\d{3}[\s.-]\d{4}\z/
# validates :phone, length: { maximum: 50 },
# format: { with: VALID_PHONE_REGEX }
# validates :fax, length: { maximum: 50 }
# validates :number_of_employees, length: { maximum: 255 }
end
......@@ -18,13 +18,15 @@ class Job < ApplicationRecord
uniqueness: { case_sensitive: false }
validates :position, presence: true, length: { maximum: 255 }
VALID_NUMBER_REGEX = /\A((\d{0,12}(\.\d{0,2})?)|(\.\d{0,2}))\z/
validates :salary, presence: true,
format: { with: VALID_NUMBER_REGEX },
numericality: {
greater_than: 0.00,
less_than: 999_999_999_999.99
}
# VALID_NUMBER_REGEX = /\A((\d{0,12}(\.\d{0,2})?)|(\.\d{0,2}))\z/
# validates :salary, presence: true,
# format: { with: VALID_NUMBER_REGEX },
# numericality: {
# greater_than: 0.00,
# less_than: 999_999_999_999.99
# }
validates :salary, presence: true
validates :expiry_date, presence: true
validates :description, presence: true, length: { maximum: 1000 }
validates :update_date, presence: true
......
<div class="card" style="width: 40rem;">
<div class="card-body">
<h5 class="card-title"><%= job.title %></h5>
<p class="card-text">some job description</p>
<p>Update date: <%= time_ago_in_words(job.created_at) %> ago. </p>
<!-- <a href="#" class="card-link">Show job</a> -->
<%= link_to 'Show job', job, class: 'card-link' %>
</div>
</div>
<br>
<div class='card' style='width: 40rem;'>
<span class='card-body'>
<h4 class='card-title'><%=link_to job.title, job %></h4>
<p class='card-text' ><strong>Description:</strong> <%= job.description.split('.').first %></p>
<span class='card-text col-md-4'><strong>Location:</strong> <%= job.cities.map(&:name).reject(&:blank?).join(', ') %> </span>
<span class='card-text col-md-4'><strong>Salary:</strong> <%= job.salary %></span><br>
<span class='card-link col-md-4'><%= link_to 'Show', job %></span>
</div>
<br>
<h3>show all <%= pluralize(@cities.count, 'city') %></h3>
<h3>Show all <%= pluralize(@cities.count, 'city') %></h3>
<ul class='list-group'>
<% @cities.each do |city| %>
......
<div class='container'>
<h3>Total: <%= pluralize(Job.count , 'job') %></h3><br>
<div class='container'>
<nav class='navbar navbar-light bg-light'>
<%= form_tag( jobs_path,
method: 'get',
class: 'form-inline') do %>
<%= text_field_tag :search, params[:search],
placeholder: 'Search Jobs',
<%= form_tag( jobs_path,
method: 'get',
class: 'form-inline') do %>
<%= text_field_tag :search, params[:search],
placeholder: 'search job',
class: 'form-control mr-sm-2'%>
<%= submit_tag 'Search', name: nil,
class: 'btn btn-outline-success my-2 my-sm-0' %>
<% end %>
</nav>
</div>
<%= submit_tag 'Search', name: nil,
class: 'btn btn-outline-success my-2 my-sm-0' %>
<% end %>
</div> <br>
<div class='jobs-list'>
<ul>
<%= render @jobs %>
<div class='container'>
<ul class='list-group'>
<% @jobs.each do |job| %>
<li class='list-group-item link'>
<%= link_to job.title, job %>
</li>
<% end %>
</ul>
</div>
</div><br>
<div class='container'>
<h4>City:</h4>
<h4> Cities list </h4>
<div class='cities-list'>
<ul>
<div class="container">
<div class="row">
<% @cities.each do |city| %>
<li>
<div class="col-6 col-md-4 list-group-item">
<%= city.name %>
<%= link_to pluralize(city.jobs.count, 'job'),
controller: 'jobs',
action: 'jobs_in_city',
slug: city.slug %>
</li>
</div>
<% 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>
<h3>Search result: <%= pluralize(@job_num , 'job') %></h3>
<nav class='navbar navbar-light bg-light'>
<div class='container'>
<div class='container'>
<%= form_tag(jobs_path, method: 'get',
class: 'form-inline') do %>
<%= text_field_tag :search, params[:search],
......@@ -9,7 +8,13 @@
<%= submit_tag 'Search', name: nil,
class: 'btn btn-outline-success my-2 my-sm-0' %>
<% end %>
</nav>
</div><br>
<div class='container'>
<h3>Search result: <%= pluralize(@job_num , 'job') %></h3><br>
<%= paginate @jobs%>
<%= render @jobs %>
\ No newline at end of file
<%= paginate @jobs%>
<%= render @jobs %>
<%= paginate @jobs%>
</div>
</div>
<div class="row">
<aside class="col-md-16">
<section class="user_info">
<h2>Job detail</h2>
<h4>
<%= @job.title %>
</h4>
<p>
<%= @job.description %>
</p>
<h4>
<%= @job.title %>
</h4>
<p>
<%= link_to "Apply", apply_path(job_id: @job.id),
class: "btn btn-secondary" %>
</p><br>
<%= link_to "Apply", apply_path(job_id: @job.id),
class: "btn btn-secondary" %>
<%= link_to 'Back', :back, class: "btn btn-secondary" %>
<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),
class: "btn btn-secondary" %>
<%= link_to 'Back', :back, class: "btn btn-secondary" %>
</section>
</aside>
</div>
......@@ -8,9 +8,6 @@
<li class="nav-item active">
<%= link_to 'Home', root_path, class: 'nav-link' %>
</li>
<li class="nav-item active">
<%= link_to 'City', city_jobs_path, class: 'nav-link' %>
</li>
<% if user_signed_in? %>
<li class="nav-item active">
<%= link_to 'Edit profile', edit_user_registration_path, class: 'nav-link' %>
......
......@@ -4,7 +4,8 @@ class CreateJobs < ActiveRecord::Migration[5.2]
t.string :title, index: true
t.references :company, foreign_key: true
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.text :description
t.datetime :update_date
......
# frozen_string_literal: true
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
......@@ -12,132 +10,133 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20_180_619_011_959) do
create_table 'cities', options: 'ENGINE=InnoDB DEFAULT CHARSET=utf8', force: :cascade do |t|
t.string 'name'
t.string 'city_type'
t.string 'slug'
t.string 'name_with_type'
t.string 'path'
t.integer 'code'
t.integer 'parent_code'
t.datetime 'created_at', null: false
t.datetime 'updated_at', null: false
t.index %w[name slug], name: 'index_cities_on_name_and_slug'
ActiveRecord::Schema.define(version: 2018_06_19_011959) do
create_table "cities", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.string "name"
t.string "city_type"
t.string "slug"
t.string "name_with_type"
t.string "path"
t.integer "code"
t.integer "parent_code"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["name", "slug"], name: "index_cities_on_name_and_slug"
end
create_table 'cities_jobs', options: 'ENGINE=InnoDB DEFAULT CHARSET=utf8', force: :cascade do |t|
t.bigint 'job_id'
t.bigint 'city_id'
t.datetime 'created_at', null: false
t.datetime 'updated_at', null: false
t.index ['city_id'], name: 'index_cities_jobs_on_city_id'
t.index %w[job_id city_id], name: 'index_cities_jobs_on_job_id_and_city_id', unique: true
t.index ['job_id'], name: 'index_cities_jobs_on_job_id'
create_table "cities_jobs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.bigint "job_id"
t.bigint "city_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["city_id"], name: "index_cities_jobs_on_city_id"
t.index ["job_id", "city_id"], name: "index_cities_jobs_on_job_id_and_city_id", unique: true
t.index ["job_id"], name: "index_cities_jobs_on_job_id"
end
create_table 'companies', options: 'ENGINE=InnoDB DEFAULT CHARSET=utf8', force: :cascade do |t|
t.string 'name'
t.text 'description'
t.string 'address'
t.string 'email'
t.string 'phone'
t.string 'fax'
t.string 'number_of_employees'
t.datetime 'created_at', null: false
t.datetime 'updated_at', null: false
create_table "companies", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.string "name"
t.text "description"
t.string "address"
t.string "email"
t.string "phone"
t.string "fax"
t.string "number_of_employees"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table 'entries', options: 'ENGINE=InnoDB DEFAULT CHARSET=utf8', force: :cascade do |t|
t.bigint 'user_id'
t.bigint 'job_id'
t.string 'entry_name'
t.string 'entry_email'
t.string 'entry_phone'
t.text 'entry_address'
t.datetime 'created_at', null: false
t.datetime 'updated_at', null: false
t.index ['job_id'], name: 'index_entries_on_job_id'
t.index %w[user_id job_id], name: 'index_entries_on_user_id_and_job_id', unique: true
t.index ['user_id'], name: 'index_entries_on_user_id'
create_table "entries", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.bigint "user_id"
t.bigint "job_id"
t.string "entry_name"
t.string "entry_email"
t.string "entry_phone"
t.text "entry_address"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["job_id"], name: "index_entries_on_job_id"
t.index ["user_id", "job_id"], name: "index_entries_on_user_id_and_job_id", unique: true
t.index ["user_id"], name: "index_entries_on_user_id"
end
create_table 'favorite_jobs', options: 'ENGINE=InnoDB DEFAULT CHARSET=utf8', force: :cascade do |t|
t.bigint 'user_id'
t.bigint 'job_id'
t.datetime 'created_at', null: false
t.datetime 'updated_at', null: false
t.index ['job_id'], name: 'index_favorite_jobs_on_job_id'
t.index ['user_id'], name: 'index_favorite_jobs_on_user_id'
create_table "favorite_jobs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.bigint "user_id"
t.bigint "job_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["job_id"], name: "index_favorite_jobs_on_job_id"
t.index ["user_id"], name: "index_favorite_jobs_on_user_id"
end
create_table 'industries', options: 'ENGINE=InnoDB DEFAULT CHARSET=utf8', force: :cascade do |t|
t.string 'code'
t.string 'name'
t.string 'slug'
t.datetime 'created_at', null: false
t.datetime 'updated_at', null: false
t.index ['name'], name: 'index_industries_on_name'
create_table "industries", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.string "code"
t.string "name"
t.string "slug"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["name"], name: "index_industries_on_name"
end
create_table 'industries_jobs', options: 'ENGINE=InnoDB DEFAULT CHARSET=utf8', force: :cascade do |t|
t.bigint 'job_id'
t.bigint 'industry_id'
t.datetime 'created_at', null: false
t.datetime 'updated_at', null: false
t.index ['industry_id'], name: 'index_industries_jobs_on_industry_id'
t.index %w[job_id industry_id], name: 'index_industries_jobs_on_job_id_and_industry_id', unique: true
t.index ['job_id'], name: 'index_industries_jobs_on_job_id'
create_table "industries_jobs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.bigint "job_id"
t.bigint "industry_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["industry_id"], name: "index_industries_jobs_on_industry_id"
t.index ["job_id", "industry_id"], name: "index_industries_jobs_on_job_id_and_industry_id", unique: true
t.index ["job_id"], name: "index_industries_jobs_on_job_id"
end
create_table 'jobs', options: 'ENGINE=InnoDB DEFAULT CHARSET=utf8', force: :cascade do |t|
t.string 'title'
t.bigint 'company_id'
t.string 'position'
t.decimal 'salary', precision: 12, scale: 2
t.datetime 'expiry_date'
t.text 'description'
t.datetime 'update_date'
t.boolean 'published'
t.text 'welfare'
t.text 'condition'
t.text 'link'
t.datetime 'created_at', null: false
t.datetime 'updated_at', null: false
t.index ['company_id'], name: 'index_jobs_on_company_id'
t.index %w[title update_date], name: 'index_jobs_on_title_and_update_date'
t.index ['title'], name: 'index_jobs_on_title'
create_table "jobs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.string "title"
t.bigint "company_id"
t.string "position"
t.string "salary"
t.datetime "expiry_date"
t.text "description"
t.datetime "update_date"
t.boolean "published"
t.text "welfare"
t.text "condition"
t.text "link"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["company_id"], name: "index_jobs_on_company_id"
t.index ["title", "update_date"], name: "index_jobs_on_title_and_update_date"
t.index ["title"], name: "index_jobs_on_title"
end
create_table 'users', options: 'ENGINE=InnoDB DEFAULT CHARSET=utf8', force: :cascade do |t|
t.string 'name', default: '', null: false
t.string 'prefix', default: ''
t.string 'phone', default: ''
t.boolean 'registration', default: false
t.text 'address'
t.string 'email', default: '', null: false
t.string 'encrypted_password', default: '', null: false
t.string 'reset_password_token'
t.datetime 'reset_password_sent_at'
t.datetime 'remember_created_at'
t.string 'confirmation_token'
t.datetime 'confirmed_at'
t.datetime 'confirmation_sent_at'
t.string 'unconfirmed_email'
t.datetime 'created_at', null: false
t.datetime 'updated_at', null: false
t.index ['confirmation_token'], name: 'index_users_on_confirmation_token', unique: true
t.index ['email'], name: 'index_users_on_email', unique: true
t.index ['reset_password_token'], name: 'index_users_on_reset_password_token', unique: true
create_table "users", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.string "name", default: "", null: false
t.string "prefix", default: ""
t.string "phone", default: ""
t.boolean "registration", default: false
t.text "address"
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.string "confirmation_token"
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
t.string "unconfirmed_email"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end
add_foreign_key 'cities_jobs', 'cities'
add_foreign_key 'cities_jobs', 'jobs'
add_foreign_key 'entries', 'jobs'
add_foreign_key 'entries', 'users'
add_foreign_key 'favorite_jobs', 'jobs'
add_foreign_key 'favorite_jobs', 'users'
add_foreign_key 'industries_jobs', 'industries'
add_foreign_key 'industries_jobs', 'jobs'
add_foreign_key 'jobs', 'companies'
add_foreign_key "cities_jobs", "cities"
add_foreign_key "cities_jobs", "jobs"
add_foreign_key "entries", "jobs"
add_foreign_key "entries", "users"
add_foreign_key "favorite_jobs", "jobs"
add_foreign_key "favorite_jobs", "users"
add_foreign_key "industries_jobs", "industries"
add_foreign_key "industries_jobs", "jobs"
add_foreign_key "jobs", "companies"
end
......@@ -22,15 +22,15 @@ namespace :importdb do
desc 'import data to companies table'
task companies: :environment do
Company.create!(
name: Faker::Company.name,
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'
)
# Company.create!(
# name: Faker::Company.name,
# 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
desc 'seed industries data'
......@@ -51,21 +51,38 @@ namespace :importdb do
jobs_redis = Redis.new
jobs_yaml_arr = jobs_redis.smembers 'crawled'
jobs_yaml_arr.each_with_index do |row,id|
# break if id == 3
# break if id == 100
job = YAML.safe_load(row)
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!(
title: job[1],
company_id: 1,
position: 'NA',
salary: '1_000',
expiry_date: Time.now,
description: 'NA',
update_date: Time.now,
published: true,
welfare: 'NA',
condition: 'NA',
link: job[14]
title: job[1],
company_id: company.id,
position: 'NA',
salary: job[7],
expiry_date: Time.now,
description: job[10],
update_date: Time.now,
published: true,
welfare: 'NA',
condition: 'NA',
link: job[14]
)
# import job industry
industry_arr = job[5].split('+').map { |ind| ind.strip }
......@@ -78,7 +95,7 @@ namespace :importdb do
job_new.industries_jobs.create!(industry_id: City.first.id)
end
# import job industry
# import job city
city_arr = job[3].split(',').map { |city| city.strip }
if city_arr.any?
city_arr.each do |city|
......
......@@ -8,8 +8,8 @@ namespace :update do
jobs = Job.all
if jobs.any?
jobs.each_with_index do |job, _id|
# break if id == 102
jobs.each_with_index do |job, id|
# break if id == 10
# check is job_id is exist and not update job to solr
response_solr = solr.get 'select', params: { q: "job_id: #{job['id']}" }
next if response_solr['response']['docs'].any?
......@@ -17,26 +17,31 @@ namespace :update do
# hash of job attribute array: city_name, ...
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_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_slug'] = job.industries.collect { |ind| ind['slug'] }
h['company_name'] = job.company.name.downcase
doc = {
job_id: job.id,
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_slug: h['city_slug'],
job_industry_id: h['industry_id'],
# job_industry_id: h['industry_id'],
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]
end
solr.commit
end
# solr.delete_by_query '*:*'
# solr.commit
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