Commit 56be2f14 by Hoang Nam Nguyen

'Fix Top,industry,city_pages'

parent c4db0830
...@@ -11,6 +11,8 @@ gem 'rubyzip', '>= 1.0.0' # will load new rubyzip version ...@@ -11,6 +11,8 @@ gem 'rubyzip', '>= 1.0.0' # will load new rubyzip version
gem 'zip-zip' # will load compatibility for old rubyzip API. gem 'zip-zip' # will load compatibility for old rubyzip API.
gem 'nokogiri' gem 'nokogiri'
gem 'whenever', :require => false gem 'whenever', :require => false
gem "figaro"
gem 'counter_culture', '~> 0.1.33'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.1.3' gem 'rails', '~> 5.1.3'
# Use mysql as the database for Active Record # Use mysql as the database for Active Record
......
...@@ -40,6 +40,9 @@ GEM ...@@ -40,6 +40,9 @@ GEM
tzinfo (~> 1.1) tzinfo (~> 1.1)
addressable (2.5.2) addressable (2.5.2)
public_suffix (>= 2.0.2, < 4.0) public_suffix (>= 2.0.2, < 4.0)
after_commit_action (1.0.1)
activerecord (>= 3.0.0)
activesupport (>= 3.0.0)
arel (8.0.0) arel (8.0.0)
bindex (0.5.0) bindex (0.5.0)
bootstrap-will_paginate (1.0.0) bootstrap-will_paginate (1.0.0)
...@@ -65,9 +68,15 @@ GEM ...@@ -65,9 +68,15 @@ GEM
execjs execjs
coffee-script-source (1.12.2) coffee-script-source (1.12.2)
concurrent-ruby (1.0.5) concurrent-ruby (1.0.5)
counter_culture (0.1.34)
activerecord (>= 3.0.0)
activesupport (>= 3.0.0)
after_commit_action (~> 1.0.0)
erubi (1.6.1) erubi (1.6.1)
execjs (2.7.0) execjs (2.7.0)
ffi (1.9.18) ffi (1.9.18)
figaro (1.1.1)
thor (~> 0.14)
globalid (0.4.0) globalid (0.4.0)
activesupport (>= 4.2.0) activesupport (>= 4.2.0)
i18n (0.8.6) i18n (0.8.6)
...@@ -196,6 +205,8 @@ DEPENDENCIES ...@@ -196,6 +205,8 @@ DEPENDENCIES
byebug byebug
capybara (~> 2.13) capybara (~> 2.13)
coffee-rails (~> 4.2) coffee-rails (~> 4.2)
counter_culture (~> 0.1.33)
figaro
jbuilder (~> 2.5) jbuilder (~> 2.5)
listen (>= 3.0.5, < 3.2) listen (>= 3.0.5, < 3.2)
mysql2 (>= 0.3.18, < 0.5) mysql2 (>= 0.3.18, < 0.5)
......
...@@ -4,18 +4,17 @@ ...@@ -4,18 +4,17 @@
} }
#distance { #distance {
border-width: 3px; margin-top: 10%;
margin-top: 5px; width: 130%;
width: 120px;
border-radius: 25px; border-radius: 25px;
} }
#slidebar { #slidebar {
padding-right: 100px; padding-right: 5%;
} }
#slide { #slide {
padding-left: 600px; padding-left: 32%;
} }
.container-fluid { .container-fluid {
...@@ -35,58 +34,53 @@ input[type=text]:focus { ...@@ -35,58 +34,53 @@ input[type=text]:focus {
} }
#image_height { #image_height {
padding-left: 5px;
width: 99.5%; width: 99.5%;
} }
#fontwords { #fontwords {
margin-top: 30px; margin-top: 5%;
padding-left: 341px; padding-left: 34%
} }
#search_button { #search_button {
margin-top: 30px; margin-top: 30px;
margin-left: 50px; margin-left: 3%;
} }
#search_box { #search_box {
width: 1000px; width: 88%;
margin-top: 30px; margin-top: 30px;
} }
.line_job { .line_job {
margin-left: -190px; margin-left: -17%;
margin-top: 30px; margin-top: 5%;
font-size: 35px; font-size: 220%;
} }
.jobs { .jobs {
margin-top: 20px; width: 125%;
width: 10000px; margin-left: 2.5%;
margin-left: 11px;
} }
.detail_description { .detail_description {
font-size: 13px; font-size: 80%;
} }
.cities { .cities {
margin-top: 10px; margin-left: 2%;
margin-left: 10px;
width: 1126px;
border: 1px solid rgba(0, 0, 0, 0.125); border: 1px solid rgba(0, 0, 0, 0.125);
} }
.titlejob{ .titlejob{
width: 1116px; width: 50%;
margin-left: -2px; margin-left: -3%;
height: 550px;
} }
.total_jobs { .total_jobs {
margin-top: -10px; font-size: 80%;
margin-bottom: 5px; margin-left: 30%;
font-size: 14px; margin-top: -5%;
} }
.column_set { .column_set {
...@@ -94,14 +88,24 @@ input[type=text]:focus { ...@@ -94,14 +88,24 @@ input[type=text]:focus {
} }
#cities_button { #cities_button {
margin-left: 955px; margin-left: 83%;
margin-bottom: 37px; margin-bottom: 3%;
margin-top: 30px; margin-top: 3%;
} }
#industries_button{
margin-bottom: 3%;
margin-top: 3%;
margin-left: 89.7%;
}
.content_job { .content_job {
margin-top: -1.5%; margin-top: -1.5%;
} }
.name_list_top {
margin-left: 30%;
margin-top: 5%;
}
/* city list */ /* city list */
#international_city { #international_city {
......
class TopPagesController < ApplicationController class TopPagesController < ApplicationController
def cities def cities
@vn_cities = City.where(location: City::VN_CITIES) @vn_cities = City.where(is_vietnam: true)
@international_cities = City.where('location NOT IN (?)', City::VN_CITIES) @international_cities = City.where(is_vietnam: false)
end end
def industries def industries
@industries_page = Industry.order(industry_name: :desc).all @industries_page = Industry.order(industry_name: :desc).all
end end
def jobs
end
def top_page def top_page
@jobs = Job.order(short_description: :desc, job_title: :desc,salary: :desc).limit(5) @jobs = Job.order(short_description: :desc, job_title: :desc,salary: :desc).limit(ENV["Number_top_page_jobs"])
@total_job = Job.count @total_job = Job.count
@industries = Industry.limit(9) @industries = Industry.limit(ENV["Number_top_page"])
@cities = City.limit(9) @cities = City.limit(ENV["Number_top_page"])
end end
def show def show
......
class City < ApplicationRecord class City < ApplicationRecord
has_many :job_cities has_many :job_cities
has_many :jobs, through: :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 end
class JobCity < ApplicationRecord class JobCity < ApplicationRecord
belongs_to :job belongs_to :job
belongs_to :city belongs_to :city, counter_cache: true
end end
class JobIndustry < ApplicationRecord class JobIndustry < ApplicationRecord
belongs_to :job belongs_to :job
belongs_to :industry belongs_to :industry, counter_cache: true
end end
<nav class="navbar navbar-light bg-faded"> <nav class="navbar navbar-light bg-faded">
<div class="container-fluid"> <div class="container-fluid">
<div class="navbar-header"> <div class="navbar-header">
<img src="/assets/logo-de7018dbfd264fe7911d4f13f8ae89a4697a4624ae01a49de6e8df3f8e507041.png"" class="navbar-brand" id="logo" href="zigexn.vn"> <a href="http://zigexn.vn">
<img src="/assets/logo-de7018dbfd264fe7911d4f13f8ae89a4697a4624ae01a49de6e8df3f8e507041.png"" class="navbar-brand" id="logo">
</a>
</div> </div>
<ul class="nav navbar-nav" id="slide"> <ul class="nav navbar-nav" id="slide">
<li><button type="button" class="btn btn-info" id="distance">Login</button></li> <li><button type="button" class="btn btn-info" id="distance">Login</button></li>
......
<% @cities.each do |city| %> <div class="container">
<div class="col-md-4 column_set"> <div class=" row align-items-start">
<%= render partial: "city",locals: {city: city} unless city.jobs.count.zero? %> <%= render partial: "city",collection: @cities, as: :city %>
</div> </div>
<% end %> </div>
<div> <div>
<%= link_to '<button type="button" class="btn btn-success" id="cities_button" >All Cities</button>'.html_safe, cities_path %> <%= link_to '<button type="button" class="btn btn-success" id="cities_button" >All Cities</button>'.html_safe, cities_path %>
</div> </div>
\ No newline at end of file
<a href="#" class="titlejob"> <div class="col-4">
<p> <a href="#">
<%= city.location %> <p class="name_list_top">
</p> <%= city.location %>
</a> </p>
<li class="total_jobs"> </a>
<%= city.jobs.count %> Jobs <li class="total_jobs">
</li> <%= city.job_cities_count %> Jobs
\ No newline at end of file </li>
</div>
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<ul> <ul>
<li> <li>
<a href=""><%= city.location %></a> <a href=""><%= city.location %></a>
(<%= city.jobs.count %>) (<%= city.job_cities_count %>)
</li> </li>
</ul> </ul>
</div> </div>
\ No newline at end of file
<div class="jobs list-group-item"> <div class="jobs list-group-item">
<% @jobs.each do |job| %> <%= render partial: "job",collection: @jobs, as: :job %>
<%= render partial: "job",locals: {job: job} %>
<% end %>
</div> </div>
\ No newline at end of file
<% @industries.each do |industry| %> <%= render partial: "industry",collection: @industries, as: :industry %>
<%= render partial: "industr",locals: {industr: industry} %>
<% end %>
<div> <div>
<%= link_to'<button type="button" class="btn btn-success" id="cities_button">All Industry</button>'.html_safe, industries_path %> <%= link_to'<button type="button" class="btn btn-success" id="industries_button">All Industry</button>'.html_safe, industries_path %>
</div> </div>
\ No newline at end of file
<div class="col-md-4 column_set"> <div class="col-md-4 column_set">
<a href="#" class="titlejob"> <a href="#" class="titlejob">
<p> <p>
<%= industr.industry_name %> <%= industry.industry_name %>
</a> </a>
(<%= industr.jobs.count %>) (<%= industry.jobs.count unless industry.jobs.count.zero? %>)
</p> </p>
</div> </div>
\ No newline at end of file
<% provide(:title, "Job List") %>
\ No newline at end of file
<p class="text-success line_job">Industry List</p> <p class="text-success line_job">Industry List</p>
<div class="row"> <div class="row">
<% @industries_page.each do |industr| %> <% @industries_page.each do |industry| %>
<%= render partial: "industry_list", locals: {industry: industr} unless industr.jobs.count.zero?%> <%= render partial: "industry_list", locals: {industry: industry} unless industry.jobs.count.zero?%>
<% end %> <% end %>
</div> </div>
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
</div> </div>
<p class="text-success line_job">Top Cities</p> <p class="text-success line_job">Top Cities</p>
<div class="row cities"> <div class="cities">
<%= render 'cities' %> <%= render 'cities' %>
</div> </div>
......
Rails.application.routes.draw do Rails.application.routes.draw do
get '/cities', to: 'top_pages#cities' get '/cities', to: 'top_pages#cities'
get '/industries', to: 'top_pages#industries' get '/industries', to: 'top_pages#industries'
# get '/job', to: '#' get '/jobs', to: 'top_pages#jobs'
get 'top_pages/cities' get 'top_pages/cities'
get 'top_pages/industries' get 'top_pages/industries'
get 'top_pages/top_page' get 'top_pages/top_page'
get 'top_pages/job' get 'top_pages/jobs'
root 'top_pages#top_page' root 'top_pages#top_page'
end end
class AddBooleanToCities < ActiveRecord::Migration[5.1]
def change
add_column :cities, :is_vietnam, :boolean
end
end
class AddJobsCount < ActiveRecord::Migration[5.1]
def change
add_column :industries, :job_industries_count, :integer, default: 0
end
end
class AddJobsCountCity < ActiveRecord::Migration[5.1]
def change
add_column :cities, :job_cities_count, :integer, default: 0
end
end
...@@ -10,12 +10,14 @@ ...@@ -10,12 +10,14 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20170913062114) do ActiveRecord::Schema.define(version: 20170914072404) do
create_table "cities", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t| create_table "cities", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
t.string "location" t.string "location"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.boolean "is_vietnam"
t.integer "job_cities_count", default: 0
end end
create_table "companies", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t| create_table "companies", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
...@@ -30,6 +32,7 @@ ActiveRecord::Schema.define(version: 20170913062114) do ...@@ -30,6 +32,7 @@ ActiveRecord::Schema.define(version: 20170913062114) do
t.string "industry_name" t.string "industry_name"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.integer "job_industries_count", default: 0
end end
create_table "job_cities", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t| create_table "job_cities", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
......
namespace :count do
task jobs_counter: :environment do
Industry.reset_column_information
Industry.find_each do |project|
Industry.reset_counters project.id, :jobs
end
end
end
\ No newline at end of file
namespace :count do
task jobs_counter_from_city: :environment do
City.reset_column_information
City.find_each do |project|
City.reset_counters project.id, :jobs
end
end
end
\ No newline at end of file
...@@ -12,9 +12,11 @@ namespace :crawl do ...@@ -12,9 +12,11 @@ namespace :crawl do
url_cities = "http://careerbuilder.vn/viec-lam/tat-ca-viec-lam-vi.html" url_cities = "http://careerbuilder.vn/viec-lam/tat-ca-viec-lam-vi.html"
home_page = Nokogiri::HTML(open(url_cities)) home_page = Nokogiri::HTML(open(url_cities))
cities = home_page.css('div.box_multiSelect_location select option') cities = home_page.css('div.box_multiSelect_location select option')
is_vietnam = true
cities.each do |city| cities.each do |city|
next if city.text == 'Tất cả địa điểm' next if city.text == 'Tất cả địa điểm'
City.find_or_create_by!(location: city.text) is_vietnam = false if city.text == 'Angola'
City.find_or_create_by!(location: city.text, is_vietnam: is_vietnam)
end end
#get industry and save database #get industry and save database
......
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