Commit ed961adb by Mai Hoang Thai Ha

add view to cities list, industries list. change routes, add path to top page

parent 108f7e4e
...@@ -107,6 +107,7 @@ GEM ...@@ -107,6 +107,7 @@ GEM
mini_mime (1.1.0) mini_mime (1.1.0)
minitest (5.14.4) minitest (5.14.4)
msgpack (1.4.2) msgpack (1.4.2)
multi_xml (0.6.0)
mysql2 (0.5.3) mysql2 (0.5.3)
nio4r (2.5.7) nio4r (2.5.7)
nokogiri (1.11.7-x86_64-linux) nokogiri (1.11.7-x86_64-linux)
...@@ -252,6 +253,7 @@ DEPENDENCIES ...@@ -252,6 +253,7 @@ DEPENDENCIES
jbuilder (~> 2.7) jbuilder (~> 2.7)
listen (~> 3.3) listen (~> 3.3)
mysql2 (~> 0.5) mysql2 (~> 0.5)
nokogiri (~> 1.11, >= 1.11.7)
pry-nav (~> 0.3.0) pry-nav (~> 0.3.0)
pry-rails (~> 0.3.9) pry-rails (~> 0.3.9)
puma (~> 5.0) puma (~> 5.0)
......
...@@ -123,7 +123,7 @@ footer { ...@@ -123,7 +123,7 @@ footer {
text-overflow: ellipsis; text-overflow: ellipsis;
line-height: 18px; line-height: 18px;
-webkit-line-clamp: 2; -webkit-line-clamp: 2;
height: 36px; max-height: 36px;
display: -webkit-box; display: -webkit-box;
-webkit-box-orient: vertical; -webkit-box-orient: vertical;
} }
...@@ -198,4 +198,6 @@ footer { ...@@ -198,4 +198,6 @@ footer {
.all-industries-btn:hover { .all-industries-btn:hover {
text-decoration: underline; text-decoration: underline;
} }
} }
\ No newline at end of file
// cities list
\ No newline at end of file
class CitiesController < ApplicationController class CitiesController < ApplicationController
def index
@region_job_list = City.joins(:jobs).group(:region).count
end
def show
end
end end
class IndustriesController < ApplicationController class IndustriesController < ApplicationController
def index
@industries_job_list = Industry.joins(:jobs).group(:name).count.sort_by(&:first)
end
def show
end
end end
module CitiesHelper module CitiesHelper
def get_cities_list(region_name)
City.joins(:jobs).where(region: region_name).group(:name).count
end
end end
class City < ApplicationRecord class City < ApplicationRecord
has_and_belongs_to_many :jobs has_and_belongs_to_many :jobs
enum region: %i[Vietnam International]
end end
.cities-list
.container
- @region_job_list.each do |region, job_count|
.countries-job-list id=region
.container-fullwidth.py-5
h2.mt-0
= region.upcase
small.text-muted
| (#{pluralize(job_count, "job")})
hr.divider.my-4
.row
- list = get_cities_list(region)
- list.each do |city, count|
.col-lg-4.col-md-6.text-center
.mt-5
.city-item
h3.h4.mb-2.see-more-text= link_to city, '#', class:'text-decoration-none fw-normal text-reset'
p.text-muted.mb-0= pluralize(count, "job")
\ No newline at end of file
.countries-list
.container.py-5
h2.mt-0 REGION
hr.divider.my-4
.row
- @region_job_list.each do |region, job_count|
.col-lg-4.col-md-6.text-center
.mt-5
h3.h4.mb-2.text-white.see-more-text= link_to region, anchor: region
p.text-muted.mb-0= pluralize(job_count, "job")
= render 'regions_list'
= render 'cities_list'
\ No newline at end of file
.countries-list
.container.py-5
h2.mt-0 INDUSTRIES
hr.divider.my-4
#info-box.row
- @industries_job_list.each do |name, job_count|
.col-lg-6.col-md-6.text-center
.mt-5
h3.h4.mb-2.see-more-text= link_to name, '#', class:'text-decoration-none fw-normal text-reset'
p.text-muted.mb-0= pluralize(job_count, "job")
hr.divider.my-4
...@@ -9,4 +9,4 @@ ...@@ -9,4 +9,4 @@
| ( | (
= pluralize(city_jobs, "job") = pluralize(city_jobs, "job")
|) |)
= link_to 'See all cities', '#', class:'all-cities-btn' = link_to 'See all cities', cities_path, class:'all-cities-btn'
\ No newline at end of file \ No newline at end of file
...@@ -9,4 +9,4 @@ ...@@ -9,4 +9,4 @@
| ( | (
= pluralize(industry_jobs, "job") = pluralize(industry_jobs, "job")
|) |)
= link_to 'See all industries', '#', class:'all-industries-btn' = link_to 'See all industries', industries_path, class:'all-industries-btn'
\ No newline at end of file \ No newline at end of file
Rails.application.routes.draw do Rails.application.routes.draw do
root 'top#index' root 'top#index'
resources :cities, only: %i[index show]
resources :industries, only: %i[index show]
end end
class CreateIndustriesJobs < ActiveRecord::Migration[6.1]
def change
create_table :industries_jobs do |t|
t.references :job, null: false, foreign_key: true
t.references :industry, null: false, foreign_key: true
t.timestamps
end
end
end
class CreateCitiesJobs < ActiveRecord::Migration[6.1]
def change
create_table :cities_jobs do |t|
t.references :job, null: false, foreign_key: true
t.references :city, null: false, foreign_key: true
t.timestamps
end
end
end
...@@ -9,7 +9,7 @@ namespace :crawler do ...@@ -9,7 +9,7 @@ namespace :crawler do
total_pages = 0 total_pages = 0
if ARGV.length == 1 && ARGV[0] == 'TEST' if ARGV.length == 1 && ARGV[0] == 'TEST'
total_pages = 1 total_pages = 5
elsif ARGV.length == 1 && ARGV[0] == 'ALL' elsif ARGV.length == 1 && ARGV[0] == 'ALL'
first_page = Nokogiri::HTML(HTTParty.get('https://careerbuilder.vn/viec-lam/tat-ca-viec-lam-vi.html').body) first_page = Nokogiri::HTML(HTTParty.get('https://careerbuilder.vn/viec-lam/tat-ca-viec-lam-vi.html').body)
jobs_per_page = first_page.css('div.job-item').count jobs_per_page = first_page.css('div.job-item').count
......
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