Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
venjob
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Huỳnh Thiên Phước
venjob
Commits
529cabcb
Commit
529cabcb
authored
Aug 10, 2020
by
Huỳnh Thiên Phước
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create Job list and Job detail
parent
1ca2bdf3
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
60 additions
and
50 deletions
+60
-50
app/assets/stylesheets/top_pages.scss
+11
-1
app/common/convert.rb
+0
-4
app/controllers/cities_controller.rb
+2
-4
app/controllers/jobs_controller.rb
+4
-0
app/models/city.rb
+4
-5
app/models/company.rb
+1
-1
app/models/industry.rb
+1
-5
app/models/job.rb
+1
-1
app/views/cities/_vietnam.html.erb
+1
-1
app/views/cities/index.html.erb
+2
-2
app/views/jobs/_job.html.erb
+14
-10
app/views/jobs/access_jobs.html.erb
+3
-0
app/views/layouts/_show_job.html.erb
+5
-1
config/routes.rb
+1
-0
lib/src/crawler.rb
+10
-15
No files found.
app/assets/stylesheets/top_pages.scss
View file @
529cabcb
...
...
@@ -121,5 +121,15 @@
border
:
2px
solid
#006080
;
border-radius
:
12px
;
text-align
:
center
;
font-size
:
32px
;
font-size
:
20px
;
font-family
:
Bookman
,
URW
Bookman
L
,
serif
;
}
.job-details
.title
a
{
color
:
black
;
text-decoration
:
none
;
}
.job-details
.title
a
:hover
{
color
:
#e6b800
;
transition
:
1s
;
text-decoration
:
none
;
}
app/common/convert.rb
View file @
529cabcb
...
...
@@ -2,8 +2,4 @@ module Convert
def
self
.
to_convert
(
str
)
str
.
mb_chars
.
normalize
(
:kd
).
gsub
(
/[Đđ]/
,
'd'
).
gsub
(
/[^\x00-\x7F]/
,
''
).
gsub
(
/[\W+]/
,
' '
).
downcase
.
to_s
.
split
(
' '
).
join
(
'-'
)
end
def
self
.
to_convert_name
(
name
)
name
.
mb_chars
.
normalize
(
:kd
).
gsub
(
/[Đđ]/
,
'd'
).
gsub
(
/[^\x00-\x7F]/
,
''
).
gsub
(
/[\W+0-9]/
,
' '
).
downcase
.
to_s
.
split
(
' '
).
join
(
'-'
)
end
end
app/controllers/cities_controller.rb
View file @
529cabcb
class
CitiesController
<
ApplicationController
VIETNAM
=
1
FOREIGN
=
0
def
index
@
cities_vietnam
=
City
.
location
(
VIETNAM
)
@
cities_international
=
City
.
location
(
FOREIGN
)
@
vietnam
=
City
.
location
(
City
::
VIETNAM
)
@
international
=
City
.
location
(
City
::
FOREIGN
)
end
end
app/controllers/jobs_controller.rb
View file @
529cabcb
...
...
@@ -17,6 +17,10 @@ class JobsController < ApplicationController
@result_for_job
=
@industry
.
jobs
.
count
end
def
access_jobs
@job_details
=
Job
.
find
(
params
[
:id
])
end
def
use_variables
@cities
=
City
.
all
@industries
=
Industry
.
all
...
...
app/models/city.rb
View file @
529cabcb
...
...
@@ -3,14 +3,13 @@ class City < ApplicationRecord
has_many
:city_jobs
has_many
:jobs
,
through: :city_jobs
VIETNAM
=
1
FOREIGN
=
0
scope
:top_city
,
->
{
joins
(
:jobs
).
group
(
:city_id
).
order
(
'count(job_id) DESC'
).
limit
(
9
)
}
scope
:location
,
->
(
number
)
{
joins
(
:jobs
).
group
(
:city_id
).
order
(
'count(job_id) DESC'
).
where
(
location:
number
)
}
def
convert_city
converted_name
=
Convert
.
to_convert
(
"
#{
name
}
"
)
end
def
convert_name
converted_name
=
Convert
.
to_convert_name
(
"
#{
name
}
"
)
self
.
converted_name
=
Convert
.
to_convert
(
"
#{
name
}
#{
rand
(
10000
)
}
"
)
end
end
app/models/company.rb
View file @
529cabcb
...
...
@@ -3,6 +3,6 @@ class Company < ApplicationRecord
has_many
:jobs
def
convert_company
self
.
converted_name
=
Convert
.
to_convert
(
"
#{
name
}
"
)
self
.
converted_name
=
Convert
.
to_convert
(
"
#{
name
}
#{
rand
(
10000
)
}
"
)
end
end
app/models/industry.rb
View file @
529cabcb
...
...
@@ -7,10 +7,6 @@ class Industry < ApplicationRecord
scope
:all_industry
,
->
{
joins
(
:jobs
).
group
(
:industry_id
).
order
(
'count(job_id) DESC'
)
}
def
convert_industry
converted_name
=
Convert
.
to_convert
(
"
#{
name
}
"
)
end
def
convert_name
converted_name
=
Convert
.
to_convert_name
(
"
#{
name
}
"
)
self
.
converted_name
=
Convert
.
to_convert
(
"
#{
name
}
#{
rand
(
10000
)
}
"
)
end
end
app/models/job.rb
View file @
529cabcb
...
...
@@ -20,7 +20,7 @@ class Job < ApplicationRecord
scope
:all_job
,
->
{
all
.
order
(
created_at: :desc
)
}
def
convert_job
converted_name
=
Convert
.
to_convert
(
"
#{
title
}
"
)
converted_name
=
Convert
.
to_convert
(
"
#{
title
}
#{
rand
(
10000
)
}
"
)
end
def
company_name
...
...
app/views/cities/_vietnam.html.erb
View file @
529cabcb
<div
class=
"col-3 remove-decoration"
>
<%=
link_to
city_jobs_path
(
converted_name:
city
.
convert_name
)
do
%>
<%=
link_to
city_jobs_path
(
converted_name:
city
.
convert
ed
_name
)
do
%>
<div
class=
"border border-dark rounded international-name"
>
<div>
<strong>
<%=
city
.
name
%>
</strong>
...
...
app/views/cities/index.html.erb
View file @
529cabcb
...
...
@@ -14,13 +14,13 @@
<div
class=
"city-banner rounded vietnam-area"
>
Việt Nam
</div>
<div
class=
"city-vietnam"
>
<div
class=
"row"
>
<%=
render
partial:
"vietnam"
,
collection:
@
cities_
vietnam
,
as: :city
%>
<%=
render
partial:
"vietnam"
,
collection:
@vietnam
,
as: :city
%>
</div>
</div>
<div
class=
"city-banner rounded international-area"
>
International
</div>
<div
class=
"city-international"
>
<div
class=
"row"
>
<%=
render
partial:
"international"
,
collection:
@
cities_
international
,
as: :city
%>
<%=
render
partial:
"international"
,
collection:
@international
,
as: :city
%>
</div>
</div>
</div>
app/views/jobs/_job.html.erb
View file @
529cabcb
<%
if
job
.
cities
.
present?
%>
<div
class=
"border border-dark rounded"
>
<div
class=
"job-details"
>
<div
class=
"title"
><strong>
<%=
job
.
title
%>
</strong></div>
<div
class=
"row"
>
<div
class=
"col-5"
>
▼
<%=
job
.
cities
.
map
(
&
:name
).
join
(
' | '
)
%>
</div>
<div
class=
"col-5 salary"
>
💲 Salary:
<%=
job
.
salary
%>
</div>
<div
class=
"col-10 introduction"
>
<%=
job_description
(
job
.
description
)
%>
<br>
<%=
link_to
'Read more..'
,
'#'
%>
</div>
<div
class=
"title"
>
<%=
link_to
job_detail_path
(
job
.
id
)
do
%>
<strong>
<%=
job
.
title
%>
</strong>
<%
end
%>
</div>
<div
class=
"row"
>
<div
class=
"col-5"
>
▼
<%=
job
.
cities
.
map
(
&
:name
).
join
(
' | '
)
%>
</div>
<div
class=
"col-5 salary"
>
💲 Salary:
<%=
job
.
salary
%>
</div>
<div
class=
"col-10 introduction"
>
<%=
job_description
(
job
.
description
)
%>
<br>
<%=
link_to
'Read more..'
,
'#'
%>
</div>
</div>
<button
type=
"button"
class=
"btn btn-success"
id=
"button-follow"
>
♥ Favorite
</button>
</div>
</div>
...
...
app/views/jobs/access_jobs.html.erb
0 → 100644
View file @
529cabcb
<div
class=
"container"
>
<%=
@job_details
.
title
%>
</div>
app/views/layouts/_show_job.html.erb
View file @
529cabcb
<%
if
job
.
cities
.
present?
%>
<div
class=
"border border-dark rounded"
>
<div
class=
"job-details"
>
<div
class=
"title"
><strong>
<%=
job
.
title
%>
</strong></div>
<div
class=
"title"
>
<%=
link_to
job_detail_path
(
job
.
id
)
do
%>
<strong>
<%=
job
.
title
%>
</strong>
<%
end
%>
</div>
<div>
<%=
job
.
company_name
%>
</div>
<div
class=
"salary"
>
💲 Salary:
<%=
job
.
salary
%>
</div>
<div>
▼
...
...
config/routes.rb
View file @
529cabcb
...
...
@@ -3,6 +3,7 @@ Rails.application.routes.draw do
resources
:jobs
get
'jobs/city/:converted_name'
,
to:
'jobs#city_jobs'
,
as: :city_jobs
get
'jobs/industry/:converted_name'
,
to:
'jobs#industry_jobs'
,
as: :industry_jobs
get
'detail/:id'
,
to:
'jobs#access_jobs'
,
as: :job_detail
resources
:top_pages
resources
:industries
...
...
lib/src/crawler.rb
View file @
529cabcb
...
...
@@ -20,13 +20,11 @@ class Crawler
data_city
.
each
do
|
name_city
|
if
City
.
find_by
(
id:
70
)
city
=
City
.
find_or_create_by!
(
name:
name_city
)
do
|
city
|
city
.
location
=
0
end
city
=
City
.
create!
(
name:
name_city
,
location:
0
)
else
city
=
City
.
find_or_create_by!
(
name:
name_city
)
do
|
city
|
city
.
location
=
1
end
city
=
City
.
create!
(
name:
name_city
,
location:
1
)
end
end
end
...
...
@@ -47,9 +45,7 @@ class Crawler
cities_relationship
=
City
.
where
(
name:
location_relationship
)
city_job_relationship
=
CityJob
.
where
(
job_id:
job
.
id
,
city_id:
cities_relationship
.
ids
)
if
city_job_relationship
.
blank?
job
.
cities
<<
cities_relationship
end
job
.
cities
<<
cities_relationship
if
city_job_relationship
.
blank?
end
def
industry_relationship
(
row
,
job
)
...
...
@@ -57,9 +53,7 @@ class Crawler
industries_relationship
=
Industry
.
where
(
name:
industry_relationship
)
industry_job_relationship
=
IndustryJob
.
where
(
job_id:
job
.
id
,
industry_id:
industries_relationship
.
ids
)
if
industry_job_relationship
.
blank?
job
.
industries
<<
industries_relationship
end
job
.
industries
<<
industries_relationship
if
industry_job_relationship
.
blank?
end
def
create_job
(
title
,
link_page
,
row
,
company
)
...
...
@@ -76,6 +70,7 @@ class Crawler
expiration_date:
expiration_date
,
description:
description
,
company_id:
company
.
id
)
city_relationship
(
row
,
job
)
industry_relationship
(
row
,
job
)
end
...
...
@@ -88,14 +83,14 @@ class Crawler
begin
next
if
link
==
'javascript:void(0);'
page
=
Nokogiri
::
HTML
(
URI
.
open
(
URI
.
escape
(
link
)))
name
=
page
.
search
(
'p.name'
)
&
.
text
&
.
strip
name
=
page
.
search
(
'p.name'
)
&
.
text
next
if
name
.
blank?
address
=
page
.
css
(
'div.content p'
).
children
[
1
]
&
.
text
introduction
=
page
.
css
(
'div.main-about-us'
).
text
Company
.
find_or_create_by!
(
name:
name
,
address:
address
,
introduction:
introduction
)
address:
address
,
introduction:
introduction
)
rescue
StandardError
=>
e
@logger
.
error
e
.
message
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment