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
def
home
@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
app/models/company.rb
View file @
7f7df78b
...
...
@@ -3,15 +3,15 @@ class Company < ApplicationRecord
validates
:name
,
presence:
true
,
length:
{
maximum:
255
},
uniqueness:
{
case_sensitive:
false
}
validates
:description
,
presence:
true
,
length:
{
maximum:
1000
}
validates
:address
,
presence:
true
,
length:
{
maximum:
255
}
VALID_EMAIL_REGEX
=
/\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i
validates
:email
,
length:
{
maximum:
255
},
format:
{
with:
VALID_EMAIL_REGEX
}
#
validates :description, presence: true, length: { maximum: 1000 }
#
validates :address, presence: true, length: { maximum: 255 }
#
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i
#
validates :email, length: { maximum: 255 },
#
format: { with: VALID_EMAIL_REGEX }
VALID_PHONE_REGEX
=
/\A^(\+\d{1,2}\s)?\(?\d{3}\)?[\s.-]\d{3}[\s.-]\d{4}\z/
validates
:phone
,
length:
{
maximum:
50
},
format:
{
with:
VALID_PHONE_REGEX
}
validates
:fax
,
length:
{
maximum:
50
}
validates
:number_of_employees
,
length:
{
maximum:
255
}
#
VALID_PHONE_REGEX = /\A^(\+\d{1,2}\s)?\(?\d{3}\)?[\s.-]\d{3}[\s.-]\d{4}\z/
#
validates :phone, length: { maximum: 50 },
#
format: { with: VALID_PHONE_REGEX }
#
validates :fax, length: { maximum: 50 }
#
validates :number_of_employees, length: { maximum: 255 }
end
app/models/job.rb
View file @
7f7df78b
...
...
@@ -18,13 +18,15 @@ class Job < ApplicationRecord
uniqueness:
{
case_sensitive:
false
}
validates
:position
,
presence:
true
,
length:
{
maximum:
255
}
VALID_NUMBER_REGEX
=
/\A((\d{0,12}(\.\d{0,2})?)|(\.\d{0,2}))\z/
validates
:salary
,
presence:
true
,
format:
{
with:
VALID_NUMBER_REGEX
},
numericality:
{
greater_than:
0.00
,
less_than:
999_999_999_999
.
99
}
# VALID_NUMBER_REGEX = /\A((\d{0,12}(\.\d{0,2})?)|(\.\d{0,2}))\z/
# validates :salary, presence: true,
# format: { with: VALID_NUMBER_REGEX },
# numericality: {
# greater_than: 0.00,
# less_than: 999_999_999_999.99
# }
validates
:salary
,
presence:
true
validates
:expiry_date
,
presence:
true
validates
:description
,
presence:
true
,
length:
{
maximum:
1000
}
validates
:update_date
,
presence:
true
...
...
app/views/jobs/_job.html.erb
View file @
7f7df78b
<div
class=
"card"
style=
"width: 40rem;"
>
<div
class=
"card-body"
>
<h5
class=
"card-title"
>
<%=
job
.
title
%>
</h5>
<p
class=
"card-text"
>
some job description
</p>
<p>
Update date:
<%=
time_ago_in_words
(
job
.
created_at
)
%>
ago.
</p>
<!-- <a href="#" class="card-link">Show job</a> -->
<%=
link_to
'Show job'
,
job
,
class:
'card-link'
%>
</div>
</div>
<br>
<div
class=
'card'
style=
'width: 40rem;'
>
<span
class=
'card-body'
>
<h4
class=
'card-title'
>
<%=
link_to
job
.
title
,
job
%>
</h4>
<p
class=
'card-text'
><strong>
Description:
</strong>
<%=
job
.
description
.
split
(
'.'
).
first
%>
</p>
<span
class=
'card-text col-md-4'
><strong>
Location:
</strong>
<%=
job
.
cities
.
map
(
&
:name
).
reject
(
&
:blank?
).
join
(
', '
)
%>
</span>
<span
class=
'card-text col-md-4'
><strong>
Salary:
</strong>
<%=
job
.
salary
%>
</span><br>
<span
class=
'card-link col-md-4'
>
<%=
link_to
'Show'
,
job
%>
</span>
</div>
<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'
>
<%
@cities
.
each
do
|
city
|
%>
...
...
app/views/jobs/home.html.erb
View file @
7f7df78b
<div
class=
'container'
>
<h3>
Total:
<%=
pluralize
(
Job
.
count
,
'job'
)
%>
</h3><br>
<div
class=
'container'
>
<nav
class=
'navbar navbar-light bg-light'
>
<%=
form_tag
(
jobs_path
,
method:
'get'
,
class:
'form-inline'
)
do
%>
<%=
text_field_tag
:search
,
params
[
:search
],
placeholder:
'Search Jobs'
,
<%=
form_tag
(
jobs_path
,
method:
'get'
,
class:
'form-inline'
)
do
%>
<%=
text_field_tag
:search
,
params
[
:search
],
placeholder:
'search job'
,
class:
'form-control mr-sm-2'
%>
<%=
submit_tag
'Search'
,
name:
nil
,
class:
'btn btn-outline-success my-2 my-sm-0'
%>
<%
end
%>
</nav>
</div>
<%=
submit_tag
'Search'
,
name:
nil
,
class:
'btn btn-outline-success my-2 my-sm-0'
%>
<%
end
%>
</div>
<br>
<div
class=
'jobs-list'
>
<ul>
<%=
render
@jobs
%>
<div
class=
'container'
>
<ul
class=
'list-group'
>
<%
@jobs
.
each
do
|
job
|
%>
<li
class=
'list-group-item link'
>
<%=
link_to
job
.
title
,
job
%>
</li>
<%
end
%>
</ul>
</div>
</div><br>
<div
class=
'container'
>
<h4>
City:
</h4>
<h4>
Cities list
</h4>
<div
class=
'cities-list'
>
<ul>
<div
class=
"container"
>
<div
class=
"row"
>
<%
@cities
.
each
do
|
city
|
%>
<
li
>
<
div
class=
"col-6 col-md-4 list-group-item"
>
<%=
city
.
name
%>
<%=
link_to
pluralize
(
city
.
jobs
.
count
,
'job'
),
controller:
'jobs'
,
action:
'jobs_in_city'
,
slug:
city
.
slug
%>
</
li
>
</
div
>
<%
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>
app/views/jobs/index.html.erb
View file @
7f7df78b
<h3>
Search result:
<%=
pluralize
(
@job_num
,
'job'
)
%>
</h3>
<nav
class=
'navbar navbar-light bg-light'
>
<div
class=
'container'
>
<div
class=
'container'
>
<%=
form_tag
(
jobs_path
,
method:
'get'
,
class:
'form-inline'
)
do
%>
<%=
text_field_tag
:search
,
params
[
:search
],
...
...
@@ -9,7 +8,13 @@
<%=
submit_tag
'Search'
,
name:
nil
,
class:
'btn btn-outline-success my-2 my-sm-0'
%>
<%
end
%>
</nav>
</div><br>
<div
class=
'container'
>
<h3>
Search result:
<%=
pluralize
(
@job_num
,
'job'
)
%>
</h3><br>
<%=
paginate
@jobs
%>
<%=
render
@jobs
%>
\ No newline at end of file
<%=
paginate
@jobs
%>
<%=
render
@jobs
%>
<%=
paginate
@jobs
%>
</div>
</div>
app/views/jobs/show.html.erb
View file @
7f7df78b
<div
class=
"row"
>
<aside
class=
"col-md-16"
>
<section
class=
"user_info"
>
<h2>
Job detail
</h2>
<h4>
<%=
@job
.
title
%>
</h4>
<p>
<%=
@job
.
description
%>
</p>
<h4>
<%=
@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
),
class:
"btn btn-secondary"
%>
<%=
link_to
'Back'
,
:back
,
class:
"btn btn-secondary"
%>
<table
class=
"table table-hover"
>
<tbody>
<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>
</aside>
</div>
app/views/layouts/_header.html.erb
View file @
7f7df78b
...
...
@@ -8,9 +8,6 @@
<li
class=
"nav-item active"
>
<%=
link_to
'Home'
,
root_path
,
class:
'nav-link'
%>
</li>
<li
class=
"nav-item active"
>
<%=
link_to
'City'
,
city_jobs_path
,
class:
'nav-link'
%>
</li>
<%
if
user_signed_in?
%>
<li
class=
"nav-item active"
>
<%=
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]
t
.
string
:title
,
index:
true
t
.
references
:company
,
foreign_key:
true
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
.
text
:description
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
desc
'import data to companies table'
task
companies: :environment
do
Company
.
create!
(
name:
Faker
::
Company
.
name
,
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'
)
#
Company.create!(
#
name: Faker::Company.name,
#
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
desc
'seed industries data'
...
...
@@ -51,21 +51,38 @@ namespace :importdb do
jobs_redis
=
Redis
.
new
jobs_yaml_arr
=
jobs_redis
.
smembers
'crawled'
jobs_yaml_arr
.
each_with_index
do
|
row
,
id
|
# break if id ==
3
# break if id ==
100
job
=
YAML
.
safe_load
(
row
)
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!
(
title:
job
[
1
],
company_id:
1
,
position:
'NA'
,
salary:
'1_000'
,
expiry_date:
Time
.
now
,
description:
'NA'
,
update_date:
Time
.
now
,
published:
true
,
welfare:
'NA'
,
condition:
'NA'
,
link:
job
[
14
]
title:
job
[
1
],
company_id:
company
.
id
,
position:
'NA'
,
salary:
job
[
7
]
,
expiry_date:
Time
.
now
,
description:
job
[
10
]
,
update_date:
Time
.
now
,
published:
true
,
welfare:
'NA'
,
condition:
'NA'
,
link:
job
[
14
]
)
# import job industry
industry_arr
=
job
[
5
].
split
(
'+'
).
map
{
|
ind
|
ind
.
strip
}
...
...
@@ -78,7 +95,7 @@ namespace :importdb do
job_new
.
industries_jobs
.
create!
(
industry_id:
City
.
first
.
id
)
end
# import job
industr
y
# import job
cit
y
city_arr
=
job
[
3
].
split
(
','
).
map
{
|
city
|
city
.
strip
}
if
city_arr
.
any?
city_arr
.
each
do
|
city
|
...
...
lib/tasks/update.rake
View file @
7f7df78b
...
...
@@ -8,8 +8,8 @@ namespace :update do
jobs
=
Job
.
all
if
jobs
.
any?
jobs
.
each_with_index
do
|
job
,
_
id
|
# break if id == 10
2
jobs
.
each_with_index
do
|
job
,
id
|
# break if id == 10
# check is job_id is exist and not update job to solr
response_solr
=
solr
.
get
'select'
,
params:
{
q:
"job_id:
#{
job
[
'id'
]
}
"
}
next
if
response_solr
[
'response'
][
'docs'
].
any?
...
...
@@ -17,26 +17,31 @@ namespace :update do
# hash of job attribute array: city_name, ...
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_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_slug'
]
=
job
.
industries
.
collect
{
|
ind
|
ind
[
'slug'
]
}
h
[
'company_name'
]
=
job
.
company
.
name
.
downcase
doc
=
{
job_id:
job
.
id
,
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_slug:
h
[
'city_slug'
],
job_industry_id:
h
[
'industry_id'
],
#
job_industry_id: h['industry_id'],
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
]
end
solr
.
commit
end
# solr.delete_by_query '*:*'
# solr.commit
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