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
1
Merge Requests
1
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
Tô Ngọc Ánh
VeNJob
Commits
127448dd
Commit
127448dd
authored
Sep 07, 2020
by
Tô Ngọc Ánh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
admin login
parent
1b7a0aa8
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
50 additions
and
25 deletions
+50
-25
app/controllers/users/sessions_controller.rb
+3
-1
app/controllers/users_controller.rb
+7
-1
app/views/users/applied_jobs.html.erb
+2
-0
config/routes.rb
+5
-0
db/migrate/20200907013824_change_admin_default_in_users.rb
+5
-0
db/schema.rb
+2
-2
db/seeds.rb
+4
-0
lib/import/crawler/crawler.rb
+18
-18
lib/solr/solr_server.rb
+3
-3
lib/tasks/delete_record.rake
+1
-0
No files found.
app/controllers/users/sessions_controller.rb
View file @
127448dd
...
@@ -26,6 +26,8 @@ class Users::SessionsController < Devise::SessionsController
...
@@ -26,6 +26,8 @@ class Users::SessionsController < Devise::SessionsController
# end
# end
def
after_sign_in_path_for
(
resource
)
def
after_sign_in_path_for
(
resource
)
stored_location_for
(
resource
)
||
my_page_path
default_path
=
resource
.
admin
?
admin_applied_jobs_path
:
my_page_path
stored_location
=
stored_location_for
(
resource
)
stored_location
==
root_path
?
default_path
:
stored_location
end
end
end
end
app/controllers/users_controller.rb
View file @
127448dd
class
UsersController
<
ApplicationController
class
UsersController
<
ApplicationController
before_action
:authenticate_user!
,
only:
:my_page
before_action
:authenticate_user!
,
only:
%i[my_page applied_job]
def
show
def
show
@user
=
User
.
find_by
(
id:
params
[
:id
])
@user
=
User
.
find_by
(
id:
params
[
:id
])
end
end
def
my_page
;
end
def
my_page
;
end
def
applied_jobs
return
unless
current_user
.
admin
@applied_jobs
=
AppliedJob
.
includes
(
:jobs
).
order
(
created_at: :desc
).
page
(
params
[
:page
])
end
end
end
app/views/users/applied_jobs.html.erb
0 → 100644
View file @
127448dd
day la admin applied job
\ No newline at end of file
config/routes.rb
View file @
127448dd
Rails
.
application
.
routes
.
draw
do
Rails
.
application
.
routes
.
draw
do
root
to:
'home#index'
root
to:
'home#index'
devise_for
:users
,
controllers:
{
sessions:
'users/sessions'
,
registrations:
'users/registrations'
}
devise_for
:users
,
controllers:
{
sessions:
'users/sessions'
,
registrations:
'users/registrations'
}
devise_scope
:user
do
get
'admin/login'
,
to:
'users/sessions#new'
,
as: :admin_login
end
get
'admin/applies'
,
to:
'users#applied_jobs'
,
as: :admin_applied_jobs
get
'cities'
,
to:
'locations#index'
get
'cities'
,
to:
'locations#index'
get
'industries'
,
to:
'industries#index'
get
'industries'
,
to:
'industries#index'
...
...
db/migrate/20200907013824_change_admin_default_in_users.rb
0 → 100644
View file @
127448dd
class
ChangeAdminDefaultInUsers
<
ActiveRecord
::
Migration
[
5.2
]
def
change
change_column_default
:users
,
:admin
,
from:
nil
,
to:
false
end
end
db/schema.rb
View file @
127448dd
...
@@ -10,7 +10,7 @@
...
@@ -10,7 +10,7 @@
#
#
# 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:
2020_0
8_07_062519
)
do
ActiveRecord
::
Schema
.
define
(
version:
2020_0
9_07_013824
)
do
create_table
"applied_jobs"
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8mb4"
,
force: :cascade
do
|
t
|
create_table
"applied_jobs"
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8mb4"
,
force: :cascade
do
|
t
|
t
.
bigint
"user_id"
t
.
bigint
"user_id"
...
@@ -103,7 +103,7 @@ ActiveRecord::Schema.define(version: 2020_08_07_062519) do
...
@@ -103,7 +103,7 @@ ActiveRecord::Schema.define(version: 2020_08_07_062519) do
t
.
string
"email"
t
.
string
"email"
t
.
string
"full_name"
t
.
string
"full_name"
t
.
string
"curriculum_vitae"
t
.
string
"curriculum_vitae"
t
.
boolean
"admin"
t
.
boolean
"admin"
,
default:
false
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
.
string
"encrypted_password"
,
default:
""
,
null:
false
t
.
string
"encrypted_password"
,
default:
""
,
null:
false
...
...
db/seeds.rb
View file @
127448dd
...
@@ -5,3 +5,7 @@
...
@@ -5,3 +5,7 @@
#
#
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# Character.create(name: 'Luke', movie: movies.first)
# Character.create(name: 'Luke', movie: movies.first)
admin
=
User
.
new
(
email:
'admin@venjob.com'
,
full_name:
'admin'
,
password:
'123456789'
,
admin:
true
)
admin
.
skip_confirmation!
admin
.
save
lib/import/crawler/crawler.rb
View file @
127448dd
...
@@ -5,17 +5,17 @@ module Crawler
...
@@ -5,17 +5,17 @@ module Crawler
def
initialize
(
logger
)
def
initialize
(
logger
)
@logger
=
logger
@logger
=
logger
end
end
def
crawl_data
(
page_number
,
base_link
)
def
crawl_data
(
page_number
,
base_link
)
crawl_industries_locations
crawl_industries_locations
job_links
=
get_job_links
(
page_number
,
base_link
)
job_links
=
get_job_links
(
page_number
,
base_link
)
job_links
.
each
do
|
link
|
job_links
.
each
do
|
link
|
next
if
link
.
empty?
next
if
link
.
empty?
crawl_job
(
link
)
crawl_job
(
link
)
end
end
end
end
def
get_job_links
(
page_number
,
link
)
def
get_job_links
(
page_number
,
link
)
job_links
=
[]
job_links
=
[]
page_number
.
times
do
page_number
.
times
do
...
@@ -24,21 +24,21 @@ module Crawler
...
@@ -24,21 +24,21 @@ module Crawler
jobs_xml
.
each
{
|
item
|
job_links
<<
item
.
value
}
jobs_xml
.
each
{
|
item
|
job_links
<<
item
.
value
}
next_page
=
document
.
at_css
(
'.next-page a'
)
next_page
=
document
.
at_css
(
'.next-page a'
)
break
if
next_page
.
nil?
break
if
next_page
.
nil?
link
=
next_page
[
:href
]
link
=
next_page
[
:href
]
end
end
job_links
job_links
end
end
def
crawl_company
(
company_link
)
def
crawl_company
(
company_link
)
uri
=
URI
.
parse
(
URI
.
escape
(
company_link
))
# fix error: uri must be ascii only
uri
=
URI
.
parse
(
URI
.
escape
(
company_link
))
# fix error: uri must be ascii only
document
=
Nokogiri
::
HTML
(
URI
.
open
(
uri
))
document
=
Nokogiri
::
HTML
(
URI
.
open
(
uri
))
company_name
=
document
.
css
(
'.content .name'
).
text
company_name
=
document
.
css
(
'.content .name'
).
text
return
if
company_name
.
empty?
return
if
company_name
.
empty?
company_address
=
document
.
css
(
'.content p'
)[
1
].
text
company_address
=
document
.
css
(
'.content p'
)[
1
].
text
company_description
=
document
.
css
(
'.main-about-us'
).
css
(
'.content'
).
text
company_description
=
document
.
css
(
'.main-about-us'
).
css
(
'.content'
).
text
Company
.
find_or_create_by
(
name:
company_name
)
do
|
company
|
Company
.
find_or_create_by
(
name:
company_name
)
do
|
company
|
company
.
address
=
company_address
company
.
address
=
company_address
company
.
description
=
company_description
company
.
description
=
company_description
...
@@ -46,30 +46,30 @@ module Crawler
...
@@ -46,30 +46,30 @@ module Crawler
rescue
StandardError
=>
e
rescue
StandardError
=>
e
@logger
.
error
"
#{
e
.
message
}
- Company link:
#{
uri
}
"
@logger
.
error
"
#{
e
.
message
}
- Company link:
#{
uri
}
"
end
end
def
crawl_job
(
job_link
)
def
crawl_job
(
job_link
)
uri
=
URI
.
parse
(
URI
.
escape
(
job_link
))
# fix error: uri must be ascii only
uri
=
URI
.
parse
(
URI
.
escape
(
job_link
))
# fix error: uri must be ascii only
document
=
Nokogiri
::
HTML
(
URI
.
open
(
uri
))
document
=
Nokogiri
::
HTML
(
URI
.
open
(
uri
))
job_title
=
document
.
at_css
(
'.job-desc p.title'
).
text
job_title
=
document
.
at_css
(
'.job-desc p.title'
).
text
return
if
job_title
.
empty?
return
if
job_title
.
empty?
job_company_link
=
document
.
at_css
(
'.job-desc a.job-company-name'
)[
:href
]
job_company_link
=
document
.
at_css
(
'.job-desc a.job-company-name'
)[
:href
]
job_company
=
crawl_company
(
job_company_link
)
job_company
=
crawl_company
(
job_company_link
)
return
if
job_company
.
nil?
return
if
job_company
.
nil?
job_location_name
=
document
.
css
(
'.map p a'
).
map
{
|
val
|
val
.
text
.
strip
}
job_location_name
=
document
.
css
(
'.map p a'
).
map
{
|
val
|
val
.
text
.
strip
}
job_locations
=
Location
.
where
(
city:
job_location_name
)
job_locations
=
Location
.
where
(
city:
job_location_name
)
job_industry_names
=
document
.
at_xpath
(
'//li[./strong/em[contains(@class, "mdi mdi-briefcase")]]'
).
css
(
'p a'
).
map
{
|
val
|
val
.
text
.
strip
}
job_industry_names
=
document
.
at_xpath
(
'//li[./strong/em[contains(@class, "mdi mdi-briefcase")]]'
).
css
(
'p a'
).
map
{
|
val
|
val
.
text
.
strip
}
job_industries
=
Industry
.
where
(
name:
job_industry_names
)
job_industries
=
Industry
.
where
(
name:
job_industry_names
)
job_salary
=
document
.
at_xpath
(
'//li[./strong/i[contains(@class, "fa fa-usd")]]/p'
).
try
(
:text
).
try
(
:strip
)
job_salary
=
document
.
at_xpath
(
'//li[./strong/i[contains(@class, "fa fa-usd")]]/p'
).
try
(
:text
).
try
(
:strip
)
job_level
=
document
.
at_xpath
(
'//li[./strong/i[contains(@class, "mdi mdi-account")]]/p'
).
try
(
:text
).
try
(
:strip
)
job_level
=
document
.
at_xpath
(
'//li[./strong/i[contains(@class, "mdi mdi-account")]]/p'
).
try
(
:text
).
try
(
:strip
)
job_experience
=
document
.
at_xpath
(
'//li[./strong/i[contains(@class, "fa fa-briefcase")]]/p'
).
try
(
:text
).
try
(
:strip
)
job_experience
=
document
.
at_xpath
(
'//li[./strong/i[contains(@class, "fa fa-briefcase")]]/p'
).
try
(
:text
).
try
(
:strip
)
job_exp_date
=
document
.
at_xpath
(
'//li[./strong/i[contains(@class, "mdi mdi-calendar-check")]]/p'
).
try
(
:text
).
try
(
:strip
)
job_exp_date
=
document
.
at_xpath
(
'//li[./strong/i[contains(@class, "mdi mdi-calendar-check")]]/p'
).
try
(
:text
).
try
(
:strip
)
job_description
=
document
.
css
(
'.job-detail-content .detail-row'
).
to_s
job_description
=
document
.
css
(
'.job-detail-content .detail-row'
).
to_s
Job
.
find_or_create_by
(
title:
job_title
,
Job
.
find_or_create_by
(
title:
job_title
,
company_id:
job_company
.
id
,
company_id:
job_company
.
id
,
level:
job_level
,
level:
job_level
,
...
@@ -83,22 +83,22 @@ module Crawler
...
@@ -83,22 +83,22 @@ module Crawler
rescue
StandardError
=>
e
rescue
StandardError
=>
e
@logger
.
error
"
#{
e
.
message
}
- Job link:
#{
uri
}
"
@logger
.
error
"
#{
e
.
message
}
- Job link:
#{
uri
}
"
end
end
def
crawl_industries_locations
def
crawl_industries_locations
document
=
Nokogiri
::
HTML
(
URI
.
open
(
'https://careerbuilder.vn/viec-lam/tat-ca-viec-lam-vi.html'
))
document
=
Nokogiri
::
HTML
(
URI
.
open
(
'https://careerbuilder.vn/viec-lam/tat-ca-viec-lam-vi.html'
))
industries
=
document
.
css
(
'#industry option'
).
map
(
&
:text
)
industries
=
document
.
css
(
'#industry option'
).
map
(
&
:text
)
locations
=
document
.
css
(
'#location option'
).
map
(
&
:text
)
locations
=
document
.
css
(
'#location option'
).
map
(
&
:text
)
industries
.
each
do
|
val
|
industries
.
each
do
|
val
|
Industry
.
find_or_create_by
(
name:
val
)
Industry
.
find_or_create_by
(
name:
val
)
end
end
locations
.
take
(
Location
::
CITY_VIETNAM_NUMBER
).
each
do
|
val
|
locations
.
take
(
Location
::
CITY_VIETNAM_NUMBER
).
each
do
|
val
|
Location
.
find_or_create_by
(
city:
val
)
do
|
location
|
Location
.
find_or_create_by
(
city:
val
)
do
|
location
|
location
.
oversea
=
false
location
.
oversea
=
false
end
end
end
end
locations
.
last
(
locations
.
count
-
Location
::
CITY_VIETNAM_NUMBER
).
each
do
|
val
|
locations
.
last
(
locations
.
count
-
Location
::
CITY_VIETNAM_NUMBER
).
each
do
|
val
|
Location
.
find_or_create_by
(
city:
val
)
do
|
location
|
Location
.
find_or_create_by
(
city:
val
)
do
|
location
|
location
.
oversea
=
true
location
.
oversea
=
true
...
...
lib/solr/solr_server.rb
View file @
127448dd
...
@@ -11,9 +11,9 @@ class SolrServer
...
@@ -11,9 +11,9 @@ class SolrServer
private
private
def
set_query_search
(
search_params
)
def
set_query_search
(
search_params
)
industry_id
=
search_params
[
:industry
].
blank?
?
"*"
:
RSolr
.
solr_escape
(
search_params
[
:industry
])
industry_id
=
search_params
[
:industry
].
blank?
?
'*'
:
RSolr
.
solr_escape
(
search_params
[
:industry
])
location_id
=
search_params
[
:location
].
blank?
?
"*"
:
RSolr
.
solr_escape
(
search_params
[
:location
])
location_id
=
search_params
[
:location
].
blank?
?
'*'
:
RSolr
.
solr_escape
(
search_params
[
:location
])
keyword
=
search_params
[
:search
].
blank?
?
"*"
:
RSolr
.
solr_escape
(
search_params
[
:search
])
keyword
=
search_params
[
:search
].
blank?
?
'*'
:
RSolr
.
solr_escape
(
search_params
[
:search
])
query
=
"title:(
#{
keyword
}
) OR company:(
#{
keyword
}
)"
query
=
"title:(
#{
keyword
}
) OR company:(
#{
keyword
}
)"
fq
=
[
"industry_ids:
#{
industry_id
}
"
,
"location_ids:
#{
location_id
}
"
]
fq
=
[
"industry_ids:
#{
industry_id
}
"
,
"location_ids:
#{
location_id
}
"
]
[
query
,
fq
]
[
query
,
fq
]
...
...
lib/tasks/delete_record.rake
View file @
127448dd
...
@@ -7,6 +7,7 @@ namespace :delete_record do
...
@@ -7,6 +7,7 @@ namespace :delete_record do
.
having
(
"count(histories.id) >
#{
History
::
NUMBER_STORED_HISTORIES
}
"
)
.
having
(
"count(histories.id) >
#{
History
::
NUMBER_STORED_HISTORIES
}
"
)
users
.
each
do
|
user
|
users
.
each
do
|
user
|
break
if
user
.
histories
.
size
<=
History
::
NUMBER_STORED_HISTORIES
break
if
user
.
histories
.
size
<=
History
::
NUMBER_STORED_HISTORIES
lastest
=
user
.
histories
.
order
(
updated_at: :desc
).
take
(
History
::
NUMBER_STORED_HISTORIES
).
pluck
(
:id
)
lastest
=
user
.
histories
.
order
(
updated_at: :desc
).
take
(
History
::
NUMBER_STORED_HISTORIES
).
pluck
(
:id
)
user
.
histories
.
where
.
not
(
id:
lastest
).
delete_all
user
.
histories
.
where
.
not
(
id:
lastest
).
delete_all
end
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