Commit c4db0830 by Hoang Nam Nguyen

'Finish cities_page industries_page'

parent 1f28d7e7
......@@ -97,4 +97,27 @@ input[type=text]:focus {
margin-left: 955px;
margin-bottom: 37px;
margin-top: 30px;
}
.content_job {
margin-top: -1.5%;
}
/* city list */
#international_city {
}
.ct_local {
width: 100%;
border: 1px solid rgba(0, 0, 0, 0.125);
}
.ct_local_font {
font-size: 130%;
margin-left: 24%;
}
#viet_nam_city{
margin_left: 10%;
}
\ No newline at end of file
class TopPagesController < ApplicationController
def cities
@vn_cities = City.where(location: City::VN_CITIES)
@international_cities = City.where('location NOT IN (?)', City::VN_CITIES)
end
def industries
@industries_page = Industry.order(industry_name: :desc).all
end
def top_page
@jobs = Job.order(short_description: :desc, job_title: :desc,salary: :desc).limit(5)
@cities = City.limit(9)
@total_job = Job.count
@industries = Industry.limit(9)
@cities = City.limit(9)
end
def show
......
class City < ApplicationRecord
has_many :job_cities
has_many :jobs, through: :job_cities
VN_CITIES = ["Hà Nội",
"Hồ Chí Minh",
"An Giang",
"Bà Rịa - Vũng Tàu",
"Bạc Liêu",
"Bắc Cạn",
"Bắc Giang",
"Bắc Ninh",
"Bến Tre",
"Bình Dương",
"Bình Định",
"Bình Phước",
"Bình Thuận",
"Cà Mau",
"Cao Bằng",
"Cần Thơ",
"Dak Lak",
"Dak Nông",
"Đà Nẵng",
"Điện Biên",
"Đồng Bằng Sông Cửu Long",
"Đồng Nai",
"Đồng Tháp",
"Gia Lai",
"Hà Giang",
"Hà Nam",
"Hà Tây",
"Hà Tĩnh",
"Hải Dương",
"Hải Phòng",
"Hậu Giang",
"Hòa Bình",
"Hưng Yên",
"Khác",
"Khánh Hòa",
"Kiên Giang",
"Kon Tum",
"KV Bắc Trung Bộ",
"KV Đông Nam Bộ",
"KV Nam Trung Bộ",
"KV Tây Nguyên",
"Lai Châu",
"Lạng Sơn",
"Lào Cai",
"Lâm Đồng",
"Long An",
"Nam Định",
"Nghệ An",
"Ninh Bình",
"Ninh Thuận",
"Phú Thọ",
"Phú Yên",
"Quảng Bình",
"Quảng Nam",
"Quảng Ngãi",
"Quảng Ninh",
"Quảng Trị",
"Sóc Trăng",
"Sơn La",
"Tây Ninh",
"Thái Bình",
"Thái Nguyên",
"Thanh Hóa",
"Thừa Thiên- Huế",
"Tiền Giang",
"Toàn quốc",
"Trà Vinh",
"Tuyên Quang",
"Vĩnh Long",
"Vĩnh Phúc",
"Yên Bái",
"Đắk Nông",
"Xã Xuân Giao",
"Thừa Thiên Huế",
"Đắk Lắk"]
end
class Industry < ApplicationRecord
has_many :job_industries
has_many :jobs, through: :job_industries
end
class Job < ApplicationRecord
has_many :job_cities
has_many :cities, through: :job_cities
has_many :job_industries
has_many :industries, through: :job_industries
end
class JobCity < ApplicationRecord
belongs_to :job, index: true
belongs_to :city, index: true
belongs_to :job
belongs_to :city
end
class JobIndustry < ApplicationRecord
belongs_to :job
belongs_to :industry
end
......@@ -9,11 +9,10 @@
<body>
<%= render 'layouts/header' %>
<img src="/assets/home_page-92e377f3edbb7945c7f7dc0ff74c6eec72b0d154f7fe3e301043af8c6fc58312.jpg" id="image_height">
<div class="container">
<%= yield %>
<%= render 'layouts/footer' %>
</div>
</div>
</body>
</html>
......@@ -4,5 +4,5 @@
</div>
<% end %>
<div>
<button type="button" class="btn btn-success" id="cities_button">All Cities</button>
<%= link_to '<button type="button" class="btn btn-success" id="cities_button" >All Cities</button>'.html_safe, cities_path %>
</div>
\ No newline at end of file
<div class="col-md-4 list-group-item">
<ul>
<li>
<a href=""><%= city.location %></a>
(<%= city.jobs.count %>)
</li>
</ul>
</div>
\ No newline at end of file
......@@ -2,6 +2,7 @@
<a href="#" class="titlejob">
<p>
<%= industr.industry_name %>
</p>
</a>
(<%= industr.jobs.count %>)
</p>
</div>
\ No newline at end of file
......@@ -2,5 +2,5 @@
<%= render partial: "industr",locals: {industr: industry} %>
<% end %>
<div>
<button type="button" class="btn btn-success" id="cities_button">All Industry</button>
<%= link_to'<button type="button" class="btn btn-success" id="cities_button">All Industry</button>'.html_safe, industries_path %>
</div>
\ No newline at end of file
<div class="col-md-4 list-group-item">
<ul>
<li>
<a href=""><%= industry.industry_name %></a>
(<%= industry.jobs.count %>)
</li>
</ul>
</div>
\ No newline at end of file
......@@ -3,9 +3,11 @@
<%= job.job_title %>
</p>
</a>
<li class="detail_description"> <%= truncate job.short_description,length: 160%>
<%= link_to 'read more', '#' %> </li>
<li class="detail_description"> <%= job.salary %> </li>
<% job.cities.each do |city| %>
<li class="detail_description"> <%= city.location %> </li>
<% end %>
\ No newline at end of file
<div class="content_job">
<li class="detail_description"> <%= truncate job.short_description,length: 160%>
<%= link_to 'read more', '#' %> </li>
<li class="detail_description"> <%= job.salary %> </li>
<% job.cities.each do |city| %>
<li class="detail_description"> <%= city.location %> </li>
<% end %>
</div>
\ No newline at end of file
<% provide(:title, "Job List") %>
\ No newline at end of file
<h1>TopPages#cities</h1>
<p>Find me in app/views/top_pages/cities.html.erb</p>
<p class="text-success line_job">City List</p>
<div class="ct_local">
<%= link_to "Viet Nam", '#' , id: "viet_nam_city" , class: "ct_local_font" %>
<%= link_to "International", '#', id: "international_city", class: "ct_local_font" %>
</div>
<p class="text-success line_job">Viet Nam</p>
<div class="row">
<% @vn_cities.each do |vn_ct| %>
<%= render partial: "city_list",locals: {city: vn_ct} unless vn_ct.jobs.count.zero? %>
<% end %>
</div>
<p class="text-success line_job">International</p>
<div class="row">
<% @international_cities.each do |inter_ct| %>
<%= render partial: "city_list",locals: {city: inter_ct} unless inter_ct.jobs.count.zero? %>
<% end %>
</div>
\ No newline at end of file
<h1>TopPages#industries</h1>
<p>Find me in app/views/top_pages/industries.html.erb</p>
<p class="text-success line_job">Industry List</p>
<div class="row">
<% @industries_page.each do |industr| %>
<%= render partial: "industry_list", locals: {industry: industr} unless industr.jobs.count.zero?%>
<% end %>
</div>
<img src="/assets/home_page-92e377f3edbb7945c7f7dc0ff74c6eec72b0d154f7fe3e301043af8c6fc58312.jpg" id="image_height">
<div class="row">
<div class="col">
<h1 id="fontwords">Total jobs: <em> <%= @total_job %> </em>job</h1>
......
Rails.application.routes.draw do
get '/cities', to: 'top_pages#cities'
get '/industries', to: 'top_pages#industries'
# get '/job', to: '#'
get 'top_pages/cities'
get 'top_pages/industries'
get 'top_pages/top_page'
get 'top_pages/job'
root 'top_pages#top_page'# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
root 'top_pages#top_page'
end
......@@ -8,7 +8,6 @@ class CreateJobs < ActiveRecord::Migration[5.1]
t.string :level
t.string :expiry_date
t.integer :company_id
t.integer :industry_id
t.timestamps
end
......
......@@ -5,7 +5,6 @@ class CreateJobCities < ActiveRecord::Migration[5.1]
t.belongs_to :job, index: true
t.timestamps
add_index
end
end
end
class CreateJobIndustries < ActiveRecord::Migration[5.1]
def change
create_table :job_industries do |t|
t.integer :job_id
t.integer :industry_id
t.timestamps
end
end
end
......@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20170911032843) do
ActiveRecord::Schema.define(version: 20170913062114) do
create_table "cities", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
t.string "location"
......@@ -41,6 +41,13 @@ ActiveRecord::Schema.define(version: 20170911032843) do
t.index ["job_id"], name: "index_job_cities_on_job_id"
end
create_table "job_industries", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
t.integer "job_id"
t.integer "industry_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "jobs", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
t.string "job_title"
t.text "descripton"
......@@ -49,7 +56,6 @@ ActiveRecord::Schema.define(version: 20170911032843) do
t.string "level"
t.string "expiry_date"
t.integer "company_id"
t.integer "industry_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "experence"
......
......@@ -14,7 +14,16 @@ namespace :crawl do
cities = home_page.css('div.box_multiSelect_location select option')
cities.each do |city|
next if city.text == 'Tất cả địa điểm'
area = City.find_or_create_by(location: city.text)
City.find_or_create_by!(location: city.text)
end
#get industry and save database
url_industries = "http://careerbuilder.vn/viec-lam/tat-ca-viec-lam-vi.html"
home_page_indus = Nokogiri::HTML(open(url_industries))
industries = home_page_indus.css('div.box_multiSelect_industry select option')
industries.each do |indus|
next if indus.text == 'Tất cả ngành nghề'
Industry.find_or_create_by(industry_name: indus.text)
end
while i <= last_page do
......@@ -31,11 +40,8 @@ namespace :crawl do
detail_company = each_page.xpath("//*[@id='emp_collapse']").text.strip
company = Company.find_or_create_by!(company_name: name_company, company_address: title_address,company_descripton: detail_company)
#get industry name and save database
industry_name = each_page.css('.fl_left a[itemprop="industry"]').text
industryname = Industry.find_or_create_by(industry_name: industry_name)
#get jobtitle update level experence salary detail_work expiry_date and save datapase
industry_name = each_page.css('.fl_left a[itemprop="industry"]').text
location_works = each_page.css('p.fl_left b[itemprop="jobLocation"]').text
job_title = each_page.css('h1[itemprop="title"]').text
date_post = each_page.css('.datepost').text
......@@ -48,10 +54,15 @@ namespace :crawl do
short_des = each_page.css('.desc_company #emp_more').text
job_params = { job_title: job_title,
update_job: date_post, level: level, expiry_date: time_off,
company_id: company.id, industry_id: industryname.id,
descripton: detail_work,experence: experence, salary: salary, benefit: benefits,
short_description: short_des }
company_id: company.id, descripton: detail_work, experence: experence,
salary: salary, benefit: benefits, short_description: short_des }
job = Job.create!(job_params)
industry_name = industry_name.split(',')
industry_name.each do |string_indus|
industry = Industry.find_by(industry_name: string_indus).jobs << job
end
location_works = location_works.split(',').map(&:strip)
location_works.each do |string|
city = City.find_by(location: string).jobs << job
......@@ -60,7 +71,7 @@ namespace :crawl do
#show pages on console screen
puts "#{detail['href']} - Page #{i}/#{last_page}"
rescue => e
p "#{e} - Job URL: #{detail['href']} - Job ID: #{job.id} - Locations: #{location_works}"
p "#{e} - Job URL: #{detail['href']} - Job ID: #{job.id} - Locations: #{location_works} -Industry: #{industry_name}"
end
end
i+=1
......
......@@ -43,9 +43,9 @@ namespace :import do
#get details job
descripton_work = "#{row[7]} + #{row[10]} + #{row[12]}"
job = Job.find_or_create_by(benefit: row[0], descripton: descripton_work, level: row[8],
job_title: row[9], salary: row[11], industry_id: category.id,
company_id: company.id)
job_title: row[9], salary: row[11], company_id: company.id)
job.cities << city
job.industries << category
p "[Success] job ##{job.id}"
rescue => e
p e
......
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