Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
venjobs_app
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
Quang Vinh Nguyen
venjobs_app
Commits
7f7df78b
Commit
7f7df78b
authored
Jun 27, 2018
by
Quang Vinh Nguyen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add some job detail
parent
77d9a1de
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
286 additions
and
215 deletions
+286
-215
app/controllers/jobs_controller.rb
+2
-1
app/models/company.rb
+10
-10
app/models/job.rb
+9
-7
app/views/jobs/_job.html.erb
+9
-10
app/views/jobs/city.html.erb
+1
-1
app/views/jobs/home.html.erb
+42
-22
app/views/jobs/index.html.erb
+11
-7
app/views/jobs/show.html.erb
+38
-12
app/views/layouts/_header.html.erb
+0
-3
db/migrate/20180607054848_create_jobs.rb
+2
-1
db/schema.rb
+111
-112
lib/tasks/importdb.rake
+39
-22
lib/tasks/update.rake
+12
-7
No files found.
app/controllers/jobs_controller.rb
View file @
7f7df78b
...
@@ -26,6 +26,7 @@ class JobsController < ApplicationController
...
@@ -26,6 +26,7 @@ class JobsController < ApplicationController
def
home
def
home
@jobs
=
Job
.
all
.
order
(
updated_at: :desc
).
take
(
5
)
@jobs
=
Job
.
all
.
order
(
updated_at: :desc
).
take
(
5
)
@cities
=
City
.
all
.
select
{
|
city
|
city
.
jobs
.
any?
}.
take
(
8
)
@cities
=
City
.
all
.
select
{
|
city
|
city
.
jobs
.
any?
}.
take
(
9
)
@industries
=
Industry
.
all
.
select
{
|
industry
|
industry
.
jobs
.
any?
}.
take
(
9
)
end
end
end
end
app/models/company.rb
View file @
7f7df78b
...
@@ -3,15 +3,15 @@ class Company < ApplicationRecord
...
@@ -3,15 +3,15 @@ class Company < ApplicationRecord
validates
:name
,
presence:
true
,
length:
{
maximum:
255
},
validates
:name
,
presence:
true
,
length:
{
maximum:
255
},
uniqueness:
{
case_sensitive:
false
}
uniqueness:
{
case_sensitive:
false
}
validates
:description
,
presence:
true
,
length:
{
maximum:
1000
}
#
validates :description, presence: true, length: { maximum: 1000 }
validates
:address
,
presence:
true
,
length:
{
maximum:
255
}
#
validates :address, presence: true, length: { maximum: 255 }
VALID_EMAIL_REGEX
=
/\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i
#
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i
validates
:email
,
length:
{
maximum:
255
},
#
validates :email, length: { maximum: 255 },
format:
{
with:
VALID_EMAIL_REGEX
}
#
format: { with: VALID_EMAIL_REGEX }
VALID_PHONE_REGEX
=
/\A^(\+\d{1,2}\s)?\(?\d{3}\)?[\s.-]\d{3}[\s.-]\d{4}\z/
#
VALID_PHONE_REGEX = /\A^(\+\d{1,2}\s)?\(?\d{3}\)?[\s.-]\d{3}[\s.-]\d{4}\z/
validates
:phone
,
length:
{
maximum:
50
},
#
validates :phone, length: { maximum: 50 },
format:
{
with:
VALID_PHONE_REGEX
}
#
format: { with: VALID_PHONE_REGEX }
validates
:fax
,
length:
{
maximum:
50
}
#
validates :fax, length: { maximum: 50 }
validates
:number_of_employees
,
length:
{
maximum:
255
}
#
validates :number_of_employees, length: { maximum: 255 }
end
end
app/models/job.rb
View file @
7f7df78b
...
@@ -18,13 +18,15 @@ class Job < ApplicationRecord
...
@@ -18,13 +18,15 @@ class Job < ApplicationRecord
uniqueness:
{
case_sensitive:
false
}
uniqueness:
{
case_sensitive:
false
}
validates
:position
,
presence:
true
,
length:
{
maximum:
255
}
validates
:position
,
presence:
true
,
length:
{
maximum:
255
}
VALID_NUMBER_REGEX
=
/\A((\d{0,12}(\.\d{0,2})?)|(\.\d{0,2}))\z/
# VALID_NUMBER_REGEX = /\A((\d{0,12}(\.\d{0,2})?)|(\.\d{0,2}))\z/
validates
:salary
,
presence:
true
,
# validates :salary, presence: true,
format:
{
with:
VALID_NUMBER_REGEX
},
# format: { with: VALID_NUMBER_REGEX },
numericality:
{
# numericality: {
greater_than:
0.00
,
# greater_than: 0.00,
less_than:
999_999_999_999
.
99
# less_than: 999_999_999_999.99
}
# }
validates
:salary
,
presence:
true
validates
:expiry_date
,
presence:
true
validates
:expiry_date
,
presence:
true
validates
:description
,
presence:
true
,
length:
{
maximum:
1000
}
validates
:description
,
presence:
true
,
length:
{
maximum:
1000
}
validates
:update_date
,
presence:
true
validates
:update_date
,
presence:
true
...
...
app/views/jobs/_job.html.erb
View file @
7f7df78b
<div
class=
"card"
style=
"width: 40rem;"
>
<div
class=
'card'
style=
'width: 40rem;'
>
<div
class=
"card-body"
>
<span
class=
'card-body'
>
<h5
class=
"card-title"
>
<%=
job
.
title
%>
</h5>
<h4
class=
'card-title'
>
<%=
link_to
job
.
title
,
job
%>
</h4>
<p
class=
"card-text"
>
some job description
</p>
<p
class=
'card-text'
><strong>
Description:
</strong>
<%=
job
.
description
.
split
(
'.'
).
first
%>
</p>
<p>
Update date:
<%=
time_ago_in_words
(
job
.
created_at
)
%>
ago.
</p>
<span
class=
'card-text col-md-4'
><strong>
Location:
</strong>
<%=
job
.
cities
.
map
(
&
:name
).
reject
(
&
:blank?
).
join
(
', '
)
%>
</span>
<!-- <a href="#" class="card-link">Show job</a> -->
<span
class=
'card-text col-md-4'
><strong>
Salary:
</strong>
<%=
job
.
salary
%>
</span><br>
<%=
link_to
'Show job'
,
job
,
class:
'card-link'
%>
<span
class=
'card-link col-md-4'
>
<%=
link_to
'Show'
,
job
%>
</span>
</div>
</div>
</div>
<br>
<br>
app/views/jobs/city.html.erb
View file @
7f7df78b
<h3>
s
how all
<%=
pluralize
(
@cities
.
count
,
'city'
)
%>
</h3>
<h3>
S
how all
<%=
pluralize
(
@cities
.
count
,
'city'
)
%>
</h3>
<ul
class=
'list-group'
>
<ul
class=
'list-group'
>
<%
@cities
.
each
do
|
city
|
%>
<%
@cities
.
each
do
|
city
|
%>
...
...
app/views/jobs/home.html.erb
View file @
7f7df78b
<div
class=
'container'
>
<div
class=
'container'
>
<h3>
Total:
<%=
pluralize
(
Job
.
count
,
'job'
)
%>
</h3><br>
<div
class=
'container'
>
<div
class=
'container'
>
<nav
class=
'navbar navbar-light bg-light'
>
<%=
form_tag
(
jobs_path
,
<%=
form_tag
(
jobs_path
,
method:
'get'
,
method:
'get'
,
class:
'form-inline'
)
do
%>
class:
'form-inline'
)
do
%>
<%=
text_field_tag
:search
,
params
[
:search
],
<%=
text_field_tag
:search
,
params
[
:search
],
placeholder:
'search job'
,
placeholder:
'Search Jobs'
,
class:
'form-control mr-sm-2'
%>
class:
'form-control mr-sm-2'
%>
<%=
submit_tag
'Search'
,
name:
nil
,
<%=
submit_tag
'Search'
,
name:
nil
,
class:
'btn btn-outline-success my-2 my-sm-0'
%>
class:
'btn btn-outline-success my-2 my-sm-0'
%>
<%
end
%>
<%
end
%>
</nav>
</div>
<br>
</div>
<div
class=
'jobs-list'
>
<div
class=
'container'
>
<ul>
<ul
class=
'list-group'
>
<%=
render
@jobs
%>
<%
@jobs
.
each
do
|
job
|
%>
<li
class=
'list-group-item link'
>
<%=
link_to
job
.
title
,
job
%>
</li>
<%
end
%>
</ul>
</ul>
</div>
</div><br>
<div
class=
'container'
>
<h4>
City:
</h4>
<h4>
Cities list
</h4>
<div
class=
"container"
>
<div
class=
'cities-list'
>
<div
class=
"row"
>
<ul>
<%
@cities
.
each
do
|
city
|
%>
<%
@cities
.
each
do
|
city
|
%>
<
li
>
<
div
class=
"col-6 col-md-4 list-group-item"
>
<%=
city
.
name
%>
<%=
city
.
name
%>
<%=
link_to
pluralize
(
city
.
jobs
.
count
,
'job'
),
<%=
link_to
pluralize
(
city
.
jobs
.
count
,
'job'
),
controller:
'jobs'
,
controller:
'jobs'
,
action:
'jobs_in_city'
,
action:
'jobs_in_city'
,
slug:
city
.
slug
%>
slug:
city
.
slug
%>
</
li
>
</
div
>
<%
end
%>
<%
end
%>
</ul>
</div>
</div
</div><br>
<h4>
Industry:
</h4>
<div
class=
"container"
>
<div
class=
"row"
>
<%
@industries
.
each
do
|
industry
|
%>
<div
class=
"col-6 col-md-4 list-group-item"
>
<%=
industry
.
name
%>
<%=
link_to
pluralize
(
industry
.
jobs
.
count
,
'job'
),
controller:
'jobs'
,
action:
'jobs_in_city'
,
slug:
industry
.
slug
%>
</div>
<%
end
%>
</div>
</div>
</div>
</div>
app/views/jobs/index.html.erb
View file @
7f7df78b
<h3>
Search result:
<%=
pluralize
(
@job_num
,
'job'
)
%>
</h3>
<div
class=
'container'
>
<div
class=
'container'
>
<nav
class=
'navbar navbar-light bg-light'
>
<%=
form_tag
(
jobs_path
,
method:
'get'
,
<%=
form_tag
(
jobs_path
,
method:
'get'
,
class:
'form-inline'
)
do
%>
class:
'form-inline'
)
do
%>
<%=
text_field_tag
:search
,
params
[
:search
],
<%=
text_field_tag
:search
,
params
[
:search
],
...
@@ -9,7 +8,13 @@
...
@@ -9,7 +8,13 @@
<%=
submit_tag
'Search'
,
name:
nil
,
<%=
submit_tag
'Search'
,
name:
nil
,
class:
'btn btn-outline-success my-2 my-sm-0'
%>
class:
'btn btn-outline-success my-2 my-sm-0'
%>
<%
end
%>
<%
end
%>
</nav>
</div><br>
<div
class=
'container'
>
<h3>
Search result:
<%=
pluralize
(
@job_num
,
'job'
)
%>
</h3><br>
<%=
paginate
@jobs
%>
<%=
paginate
@jobs
%>
<%=
render
@jobs
%>
<%=
render
@jobs
%>
\ No newline at end of file
<%=
paginate
@jobs
%>
</div>
</div>
app/views/jobs/show.html.erb
View file @
7f7df78b
<div
class=
"row"
>
<div
class=
"row"
>
<aside
class=
"col-md-16"
>
<aside
class=
"col-md-16"
>
<section
class=
"user_info"
>
<section
class=
"user_info"
>
<h2>
Job detail
</h2>
<h4>
<%=
@job
.
title
%>
</h4>
<p>
<%=
@job
.
description
%>
<h4>
</p>
<%=
@job
.
title
%>
</h4>
<p>
<%=
link_to
"Apply"
,
apply_path
(
job_id:
@job
.
id
),
class:
"btn btn-secondary"
%>
</p><br>
<%=
link_to
"Apply"
,
apply_path
(
job_id:
@job
.
id
),
<table
class=
"table table-hover"
>
class:
"btn btn-secondary"
%>
<tbody>
<%=
link_to
'Back'
,
:back
,
class:
"btn btn-secondary"
%>
<tr>
<th
scope=
"row col-8"
>
Job title
</th>
<td>
<%=
@job
.
title
%>
</td>
</tr>
<tr>
<th
scope=
"row"
>
Company
</th>
<td>
<%=
@job
.
company
.
name
%>
</td>
</tr>
<tr>
<th
scope=
"row"
>
Location
</th>
<td
colspan=
"2"
>
<%=
@job
.
cities
.
map
(
&
:name
).
reject
(
&
:blank?
).
join
(
', '
)
%>
</td>
</tr>
<tr>
<th
scope=
"row"
>
Salary
</th>
<td
colspan=
"2"
>
<%=
@job
.
salary
%>
</td>
</tr>
<tr>
<th
scope=
"row"
>
Description
</th>
<td
colspan=
"2"
>
<%=
@job
.
description
%>
</td>
</tr>
</tbody>
</table>
<%=
link_to
"Apply"
,
apply_path
(
job_id:
@job
.
id
),
class:
"btn btn-secondary"
%>
<%=
link_to
'Back'
,
:back
,
class:
"btn btn-secondary"
%>
</section>
</section>
</aside>
</aside>
</div>
</div>
app/views/layouts/_header.html.erb
View file @
7f7df78b
...
@@ -8,9 +8,6 @@
...
@@ -8,9 +8,6 @@
<li
class=
"nav-item active"
>
<li
class=
"nav-item active"
>
<%=
link_to
'Home'
,
root_path
,
class:
'nav-link'
%>
<%=
link_to
'Home'
,
root_path
,
class:
'nav-link'
%>
</li>
</li>
<li
class=
"nav-item active"
>
<%=
link_to
'City'
,
city_jobs_path
,
class:
'nav-link'
%>
</li>
<%
if
user_signed_in?
%>
<%
if
user_signed_in?
%>
<li
class=
"nav-item active"
>
<li
class=
"nav-item active"
>
<%=
link_to
'Edit profile'
,
edit_user_registration_path
,
class:
'nav-link'
%>
<%=
link_to
'Edit profile'
,
edit_user_registration_path
,
class:
'nav-link'
%>
...
...
db/migrate/20180607054848_create_jobs.rb
View file @
7f7df78b
...
@@ -4,7 +4,8 @@ class CreateJobs < ActiveRecord::Migration[5.2]
...
@@ -4,7 +4,8 @@ class CreateJobs < ActiveRecord::Migration[5.2]
t
.
string
:title
,
index:
true
t
.
string
:title
,
index:
true
t
.
references
:company
,
foreign_key:
true
t
.
references
:company
,
foreign_key:
true
t
.
string
:position
t
.
string
:position
t
.
decimal
:salary
,
precision:
12
,
scale:
2
# t.decimal :salary, precision: 12, scale: 2
t
.
string
:salary
t
.
datetime
:expiry_date
t
.
datetime
:expiry_date
t
.
text
:description
t
.
text
:description
t
.
datetime
:update_date
t
.
datetime
:update_date
...
...
db/schema.rb
View file @
7f7df78b
This diff is collapsed.
Click to expand it.
lib/tasks/importdb.rake
View file @
7f7df78b
...
@@ -22,15 +22,15 @@ namespace :importdb do
...
@@ -22,15 +22,15 @@ namespace :importdb do
desc
'import data to companies table'
desc
'import data to companies table'
task
companies: :environment
do
task
companies: :environment
do
Company
.
create!
(
#
Company.create!(
name:
Faker
::
Company
.
name
,
#
name: Faker::Company.name,
description:
Faker
::
Lorem
.
paragraph
,
#
description: Faker::Lorem.paragraph,
address:
Faker
::
Address
.
street_address
,
#
address: Faker::Address.street_address,
email:
Faker
::
Internet
.
email
,
#
email: Faker::Internet.email,
phone:
'123-456-7890'
,
#
phone: '123-456-7890',
fax:
'123-456-7890'
,
#
fax: '123-456-7890',
number_of_employees:
'1000 - 2000'
#
number_of_employees: '1000 - 2000'
)
#
)
end
end
desc
'seed industries data'
desc
'seed industries data'
...
@@ -51,21 +51,38 @@ namespace :importdb do
...
@@ -51,21 +51,38 @@ namespace :importdb do
jobs_redis
=
Redis
.
new
jobs_redis
=
Redis
.
new
jobs_yaml_arr
=
jobs_redis
.
smembers
'crawled'
jobs_yaml_arr
=
jobs_redis
.
smembers
'crawled'
jobs_yaml_arr
.
each_with_index
do
|
row
,
id
|
jobs_yaml_arr
.
each_with_index
do
|
row
,
id
|
# break if id ==
3
# break if id ==
100
job
=
YAML
.
safe_load
(
row
)
job
=
YAML
.
safe_load
(
row
)
next
if
job
[
1
].
blank?
||
!!
Job
.
find_by
(
title:
job
[
1
])
||
!!
Job
.
find_by
(
link:
job
[
14
])
next
if
job
[
1
].
blank?
||
!!
Job
.
find_by
(
title:
job
[
1
])
||
!!
Job
.
find_by
(
link:
job
[
14
])
# create job company
next
if
job
[
2
].
blank?
company
=
Company
.
find_by
(
name:
job
[
2
])
unless
company
company
=
Company
.
create
(
name:
job
[
2
],
description:
Faker
::
Lorem
.
paragraph
,
address:
Faker
::
Address
.
street_address
,
email:
Faker
::
Internet
.
email
,
phone:
'123-456-7890'
,
fax:
'123-456-7890'
,
number_of_employees:
'1000 - 2000'
)
end
next
unless
company
# create job
job_new
=
Job
.
create!
(
job_new
=
Job
.
create!
(
title:
job
[
1
],
title:
job
[
1
],
company_id:
1
,
company_id:
company
.
id
,
position:
'NA'
,
position:
'NA'
,
salary:
'1_000'
,
salary:
job
[
7
]
,
expiry_date:
Time
.
now
,
expiry_date:
Time
.
now
,
description:
'NA'
,
description:
job
[
10
]
,
update_date:
Time
.
now
,
update_date:
Time
.
now
,
published:
true
,
published:
true
,
welfare:
'NA'
,
welfare:
'NA'
,
condition:
'NA'
,
condition:
'NA'
,
link:
job
[
14
]
link:
job
[
14
]
)
)
# import job industry
# import job industry
industry_arr
=
job
[
5
].
split
(
'+'
).
map
{
|
ind
|
ind
.
strip
}
industry_arr
=
job
[
5
].
split
(
'+'
).
map
{
|
ind
|
ind
.
strip
}
...
@@ -78,7 +95,7 @@ namespace :importdb do
...
@@ -78,7 +95,7 @@ namespace :importdb do
job_new
.
industries_jobs
.
create!
(
industry_id:
City
.
first
.
id
)
job_new
.
industries_jobs
.
create!
(
industry_id:
City
.
first
.
id
)
end
end
# import job
industr
y
# import job
cit
y
city_arr
=
job
[
3
].
split
(
','
).
map
{
|
city
|
city
.
strip
}
city_arr
=
job
[
3
].
split
(
','
).
map
{
|
city
|
city
.
strip
}
if
city_arr
.
any?
if
city_arr
.
any?
city_arr
.
each
do
|
city
|
city_arr
.
each
do
|
city
|
...
...
lib/tasks/update.rake
View file @
7f7df78b
...
@@ -8,8 +8,8 @@ namespace :update do
...
@@ -8,8 +8,8 @@ namespace :update do
jobs
=
Job
.
all
jobs
=
Job
.
all
if
jobs
.
any?
if
jobs
.
any?
jobs
.
each_with_index
do
|
job
,
_
id
|
jobs
.
each_with_index
do
|
job
,
id
|
# break if id == 10
2
# break if id == 10
# check is job_id is exist and not update job to solr
# check is job_id is exist and not update job to solr
response_solr
=
solr
.
get
'select'
,
params:
{
q:
"job_id:
#{
job
[
'id'
]
}
"
}
response_solr
=
solr
.
get
'select'
,
params:
{
q:
"job_id:
#{
job
[
'id'
]
}
"
}
next
if
response_solr
[
'response'
][
'docs'
].
any?
next
if
response_solr
[
'response'
][
'docs'
].
any?
...
@@ -17,26 +17,31 @@ namespace :update do
...
@@ -17,26 +17,31 @@ namespace :update do
# hash of job attribute array: city_name, ...
# hash of job attribute array: city_name, ...
h
=
{}
h
=
{}
h
[
'city_id'
]
=
job
.
cities
.
collect
{
|
city
|
city
[
'id'
].
to_s
}
#
h['city_id'] = job.cities.collect { |city| city['id'].to_s }
h
[
'city_name'
]
=
job
.
cities
.
collect
{
|
city
|
city
[
'name'
].
downcase
}
h
[
'city_name'
]
=
job
.
cities
.
collect
{
|
city
|
city
[
'name'
].
downcase
}
h
[
'city_slug'
]
=
job
.
cities
.
collect
{
|
city
|
city
[
'slug'
]
}
h
[
'city_slug'
]
=
job
.
cities
.
collect
{
|
city
|
city
[
'slug'
]
}
h
[
'industry_id'
]
=
job
.
industries
.
collect
{
|
ind
|
ind
[
'id'
].
to_s
}
#
h['industry_id'] = job.industries.collect { |ind| ind['id'].to_s }
h
[
'industry_name'
]
=
job
.
industries
.
collect
{
|
ind
|
ind
[
'name'
].
downcase
}
h
[
'industry_name'
]
=
job
.
industries
.
collect
{
|
ind
|
ind
[
'name'
].
downcase
}
h
[
'industry_slug'
]
=
job
.
industries
.
collect
{
|
ind
|
ind
[
'slug'
]
}
h
[
'industry_slug'
]
=
job
.
industries
.
collect
{
|
ind
|
ind
[
'slug'
]
}
h
[
'company_name'
]
=
job
.
company
.
name
.
downcase
doc
=
{
doc
=
{
job_id:
job
.
id
,
job_id:
job
.
id
,
job_title:
job
.
title
.
downcase
,
job_title:
job
.
title
.
downcase
,
job_city_id:
h
[
'city_id'
],
#
job_city_id: h['city_id'],
job_city_name:
h
[
'city_name'
],
job_city_name:
h
[
'city_name'
],
job_city_slug:
h
[
'city_slug'
],
job_city_slug:
h
[
'city_slug'
],
job_industry_id:
h
[
'industry_id'
],
#
job_industry_id: h['industry_id'],
job_industry_name:
h
[
'industry_name'
],
job_industry_name:
h
[
'industry_name'
],
job_industry_slug:
h
[
'industry_slug'
]
job_industry_slug:
h
[
'industry_slug'
],
job_company_name:
h
[
'company_name'
]
}
}
solr
.
add
[
doc
]
solr
.
add
[
doc
]
end
end
solr
.
commit
solr
.
commit
end
end
# solr.delete_by_query '*:*'
# solr.commit
end
end
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