Fix controller, model of city and industry

parent c002193c
Pipeline #774 canceled with stages
in 0 seconds
......@@ -78,14 +78,35 @@
background-image: linear-gradient(160deg, black, #8c8686);
color: white;
}
.city-list:hover{
.city-list:hover, .industry-list:hover{
background-color: black;
.city-name, .count-job{
text-decoration: none;
.city-name, .count-job, .industry-name{
color: white;
}
}
.city-name, .count-job{
.city-list, .industry-list{
&:hover {
a {
text-decoration: none;
}
}
}
.city-name, .count-job, .industry-name{
text-decoration: none;
color: black;
}
.search-bar{
padding: 20px;
}
.all-city:hover, .all-industry:hover{
.all-cities, .all-industries{
color: blue;
}
}
.all-city, .all-industry{
&:hover{
a {
text-decoration: none;
}
}
}
......@@ -4,7 +4,7 @@ class TopPagesController < ApplicationController
@industries = Industry.all
@total_jobs = Job.count
@jobs = Job.limit(5).order(created_at: :desc)
@jobs_of_cities = CityJob.top_city
@jobs_of_industries = IndustryJob.limit(9).group('industry_id').order('Count(*) DESC').count
@jobs_of_cities = City.top_city
@jobs_of_industries = Industry.top_industry
end
end
......@@ -2,4 +2,7 @@ class City < ApplicationRecord
has_many :city_jobs
has_many :jobs, through: :city_jobs
def self.top_city
joins(:jobs).group(:city_id).order('count(job_id) DESC').limit(9)
end
end
......@@ -2,7 +2,4 @@ class CityJob < ApplicationRecord
belongs_to :city
belongs_to :job
def self.top_city
limit(9).group('city_id').order('Count(*) DESC').count
end
end
class Industry < ApplicationRecord
has_many :industry_jobs
has_many :jobs, through: :industry_jobs
def self.top_industry
joins(:jobs).group(:industry_id).order('count(job_id) DESC').limit(9)
end
end
......@@ -5,6 +5,7 @@
</div>
<div class="col-sm">
<select class="form-control" id="exampleFormControlSelect1">
<option>--None</option>
<%= @cities.each do |city| %>
<option><%= city.name %></option>
<% end %>
......@@ -12,6 +13,7 @@
</div>
<div class="col-sm">
<select class="form-control" id="exampleFormControlSelect1">
<option>--None</option>
<%= @industries.each do |industry| %>
<option><%= industry.name %></option>
<% end %>
......
<% @jobs_of_cities.each do |city, count_job| %>
<% @jobs_of_cities.each do |city| %>
<div class="col-4">
<div class="row-table border border-dark rounded city-list">
<%= link_to '#' do%>
<div class="city-name"><strong><%= City.find(city).name %></strong></div>
<div class="count-job"><%= count_job %></div>
<%= link_to '#' do %>
<div class="city-name"><strong><%= city.name %></strong></div>
<div class="count-job"><%= city.jobs.count %></div>
<% end %>
</div>
</div>
......
<% @jobs_of_industries.each do |industry, count_job| %>
<% @jobs_of_industries.each do |industry| %>
<div class="col-4">
<div class="row-table border border-dark rounded">
<div class="industry-name"><strong><%= Industry.find(industry).name %></strong></div>
<div class="count-job"><%= count_job %></div>
<div class="row-table border border-dark rounded industry-list">
<%= link_to '#' do %>
<div class="industry-name"><strong><%= industry.name %></strong></div>
<div class="count-job"><%= industry.jobs.count %></div>
<% end %>
</div>
</div>
<% end %>
......@@ -4,7 +4,7 @@
<div class="job-details">
<div class="title"><strong><%= job.title %></strong></div>
<div><%= job.company_name %></div>
<div class="salary">$ Lương: <%= job.salary %></div>
<div class="salary">Salary: <%= job.salary %></div>
<div>
<% job.cities.each do |city| %>
<%= city.name %>
......
......@@ -7,18 +7,21 @@
<div class="container">
<div class="search-bar"><%= render 'layouts/search_bar' %></div>
<br>
<div class="job-list"><%= render 'layouts/show_jobs' %></div>
<div class="city-banner rounded">City</div>
<div class="row"><%= render 'layouts/show_cities' %></div>
<div class="all-city">
<div class="row-table border border-dark rounded"><strong>All Cities</strong></div>
<%= link_to '#' do %>
<div class="row-table border border-dark rounded all-cities"><strong>All Cities</strong></div>
<% end %>
</div>
<div class="industry-banner rounded">Industry</div>
<div class="row"><%= render 'layouts/show_industries' %></div>
<div class="all-industry">
<div class="row-table border border-dark rounded"><strong>All Industries</strong></div>
<%= link_to '#' do %>
<div class="row-table border border-dark rounded all-industries"><strong>All Industries</strong></div>
<% end %>
</div>
</div>
......
......@@ -2,7 +2,7 @@ require 'net/ftp'
require 'csv'
require 'zip'
class CSVimporter
class CSVImporter
def initialize(logger)
@logger = logger
@NAME_DOMAIN = '192.168.1.156'
......@@ -59,22 +59,15 @@ class CSVimporter
industry_name = row["category"]
industries_relationship = Industry.where(name: industry_name)
if industries_relationship.blank?
industries_relationship = Industry.where(name: industry)
next if industries_relationship.blank?
job.industries << industries_relationship
else
job.industries << industries_relationship
end
location_data = row["work place"]
location = location_data.gsub('["', '').gsub('"]', '')
location_relationship = City.where(name: location)
if location_relationship.blank?
location_relationship = City.where(name: city)
job.cities << location_relationship
else
next if location_relationship.blank?
job.cities << location_relationship
end
rescue StandardError => e
@logger.error e.message
end
......
require 'src/crawler.rb'
require 'src/jobparser.rb'
require 'src/csvimporter.rb'
require 'src/job_parser.rb'
require 'src/csv_importer.rb'
namespace :import do
desc 'crawler data'
task crawler: :environment do
action = Crawler.new(logger, url)
action.crawl_city_industry
action = Crawler.new(logger, url).crawl_city_industry
end
desc 'Crontab'
task auto: :environment do
crontab = JobParser.new(logger, url)
csvimporter = CSVimporter.new(logger)
csv_importer = CSVImporter.new(logger)
crontab.crawl_all
csvimporter.import
csv_importer.import
end
def logger
Logger.new(Rails.root.join('log','my.log'))
Logger.new(Rails.root.join('log','crawling.log'))
end
def url
......
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