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
37cb0f75
Commit
37cb0f75
authored
Aug 24, 2020
by
Tô Ngọc Ánh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
split job_body partial,show history
parent
f5e77b66
Pipeline
#1003
canceled with stages
in 0 seconds
Changes
17
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
72 additions
and
66 deletions
+72
-66
app/controllers/favorites_controller.rb
+2
-1
app/controllers/histories_controller.rb
+2
-2
app/controllers/jobs_controller.rb
+8
-1
app/models/history.rb
+2
-0
app/views/applied_jobs/index.html.erb
+2
-0
app/views/favorites/_job.html.erb
+3
-21
app/views/favorites/create.js.erb
+1
-0
app/views/favorites/destroy.js.erb
+1
-0
app/views/favorites/index.html.erb
+10
-1
app/views/histories/_job.html.erb
+3
-21
app/views/histories/index.html.erb
+6
-1
app/views/jobs/_job.html.erb
+1
-12
app/views/jobs/index.html.erb
+5
-3
app/views/jobs/show.html.erb
+2
-2
app/views/shared/_header.html.erb
+1
-1
app/views/shared/_job_body.html.erb
+12
-0
lib/tasks/delete_record.rake
+11
-0
No files found.
app/controllers/favorites_controller.rb
View file @
37cb0f75
...
@@ -9,7 +9,8 @@ class FavoritesController < ApplicationController
...
@@ -9,7 +9,8 @@ class FavoritesController < ApplicationController
def
create
def
create
@job
=
Job
.
find_by
(
id:
params
[
:job_id
])
@job
=
Job
.
find_by
(
id:
params
[
:job_id
])
@favorite
=
@job
.
favorites
.
new
(
user_id:
current_user
.
id
)
@favorite
=
@job
.
favorites
.
new
(
user_id:
current_user
.
id
)
respond_to
:js
if
@favorite
.
save
@favorite
.
save
respond_to
:js
end
end
def
destroy
def
destroy
...
...
app/controllers/histories_controller.rb
View file @
37cb0f75
...
@@ -2,7 +2,7 @@ class HistoriesController < ApplicationController
...
@@ -2,7 +2,7 @@ class HistoriesController < ApplicationController
before_action
:authenticate_user!
before_action
:authenticate_user!
def
index
def
index
histories
=
current_user
.
histories
.
order
(
created_at: :asc
).
take
(
20
).
pluck
(
:job_id
)
histories
=
current_user
.
histories
.
order
(
updated_at: :desc
).
take
(
History
::
NUMBER_STORED_HISTORIES
).
pluck
(
:job_id
)
@jobs
=
Job
.
where
(
id:
histories
).
includes
(
:company
,
:locations
)
@jobs
=
Job
.
where
(
id:
histories
).
includes
(
:company
,
:locations
)
.
sort_by
{
|
job
|
histories
.
index
(
job
.
id
)
}
end
end
end
end
app/controllers/jobs_controller.rb
View file @
37cb0f75
...
@@ -13,6 +13,13 @@ class JobsController < ApplicationController
...
@@ -13,6 +13,13 @@ class JobsController < ApplicationController
return
@is_not_applied
=
true
unless
user_signed_in?
return
@is_not_applied
=
true
unless
user_signed_in?
@is_not_applied
=
current_user
.
applied_jobs
.
find_by
(
job_id:
@job
.
id
).
blank?
@is_not_applied
=
current_user
.
applied_jobs
.
find_by
(
job_id:
@job
.
id
).
blank?
current_user
.
histories
.
find_or_create_by
(
job_id:
@job
.
id
)
save_history
(
@job
.
id
)
end
private
def
save_history
(
job_id
)
history
=
current_user
.
histories
.
find_or_create_by
(
job_id:
job_id
)
history
.
update_attributes
(
updated_at:
Time
.
now
)
end
end
end
end
app/models/history.rb
View file @
37cb0f75
class
History
<
ApplicationRecord
class
History
<
ApplicationRecord
NUMBER_STORED_HISTORIES
=
20
belongs_to
:user
belongs_to
:user
belongs_to
:job
belongs_to
:job
end
end
app/views/applied_jobs/index.html.erb
View file @
37cb0f75
...
@@ -2,8 +2,10 @@
...
@@ -2,8 +2,10 @@
<h3
class=
'text-center'
>
Applied Jobs
</h3>
<h3
class=
'text-center'
>
Applied Jobs
</h3>
<hr
class=
"divider"
>
<hr
class=
"divider"
>
<div
class=
'content'
>
<div
class=
'content'
>
<%
if
@applied_jobs
.
any?
%>
<%=
paginate
@applied_jobs
%>
<%=
paginate
@applied_jobs
%>
<%=
render
partial:
'applied_jobs/applied_job'
,
collection:
@applied_jobs
,
as: :job
%>
<%=
render
partial:
'applied_jobs/applied_job'
,
collection:
@applied_jobs
,
as: :job
%>
<%=
paginate
@applied_jobs
%>
<%=
paginate
@applied_jobs
%>
<%
end
%>
</div>
</div>
</div>
</div>
app/views/favorites/_job.html.erb
View file @
37cb0f75
<%=
form_tag
new_applied_job_path
,
method: :get
,
enforce_utf8:
false
do
%>
<div
id=
"favorited-
<%=
job
.
id
%>
"
>
<%
jobs
.
each
do
|
job
|
%>
<div
id=
"favorited-
<%=
job
.
id
%>
"
>
<div
class=
'card flex-md-row align-items-center my-2 p-2'
>
<div
class=
'card flex-md-row align-items-center my-2 p-2'
>
<%=
radio_button_tag
:job_id
,
job
.
id
%>
<%=
radio_button_tag
:job_id
,
job
.
id
%>
<div
class=
'card-body'
>
<%=
render
'shared/job_body'
,
job:
job
%>
<%=
link_to
job
.
title
,
job_path
(
job
),
class:
'card-title font-weight-bold text-decoration-none'
%>
<p
class=
'card-text'
>
<%=
job
.
company
.
name
%>
</p>
<p
class=
'mb-0'
>
<strong>
Work place:
</strong>
<%
job
.
locations
.
each
do
|
location
|
%>
<%=
location
.
city
%>
<%
end
%>
</p>
<p><strong>
Salary:
</strong>
<%=
job
.
salary
%>
</p>
<p
class=
'card-text'
>
<%=
strip_tags
(
job
.
description
).
truncate
(
Job
::
WORDS_SHORT_DESCRIPTION
)
%>
</p>
</div>
<%=
link_to
'Remove'
,
job_favorite_path
(
job
.
id
),
<%=
link_to
'Remove'
,
job_favorite_path
(
job
.
id
),
method: :delete
,
class:
'btn btn-danger btn-lg'
,
remote:
true
,
method: :delete
,
class:
'btn btn-danger btn-lg'
,
remote:
true
,
data:
{
disable_with:
'<i class="fa fa-spinner fa-spin"></i>'
.
html_safe
}
%>
data:
{
disable_with:
'<i class="fa fa-spinner fa-spin"></i>'
.
html_safe
}
%>
</div>
</div>
</div>
</div>
<%
end
%>
<div
class=
"actions text-center"
>
<%=
submit_tag
'Apply Now'
,
name:
nil
,
class:
'btn btn-outline-success btn-lg'
%>
</div>
<%
end
%>
app/views/favorites/create.js.erb
View file @
37cb0f75
$('#favorite-
<%=
@job
.
id
%>
')
$('#favorite-
<%=
@job
.
id
%>
')
.html("
<%=
j
render
'favorites/link_favorite'
,
job_id:
@job
.
id
%>
")
.html("
<%=
j
render
'favorites/link_favorite'
,
job_id:
@job
.
id
%>
")
$('#sum-favorited').html("
<%=
current_user
.
favorites
.
size
%>
")
app/views/favorites/destroy.js.erb
View file @
37cb0f75
$('#favorite-
<%=
@favorite
.
job_id
%>
')
$('#favorite-
<%=
@favorite
.
job_id
%>
')
.html("
<%=
j
render
'favorites/link_favorite'
,
job_id:
@favorite
.
job_id
%>
")
.html("
<%=
j
render
'favorites/link_favorite'
,
job_id:
@favorite
.
job_id
%>
")
$('#sum-favorited').html("
<%=
current_user
.
favorites
.
size
%>
")
$('#favorited-
<%=
@favorite
.
job_id
%>
').remove()
$('#favorited-
<%=
@favorite
.
job_id
%>
').remove()
app/views/favorites/index.html.erb
View file @
37cb0f75
...
@@ -2,8 +2,17 @@
...
@@ -2,8 +2,17 @@
<h3
class=
'text-center'
>
Favorited Jobs
</h3>
<h3
class=
'text-center'
>
Favorited Jobs
</h3>
<hr
class=
"divider"
>
<hr
class=
"divider"
>
<div
class=
'content'
>
<div
class=
'content'
>
<%
if
@jobs
.
any?
%>
<%=
paginate
@jobs
%>
<%=
paginate
@jobs
%>
<%=
render
'favorites/job'
,
jobs:
@jobs
if
@jobs
.
any?
%>
<%=
form_tag
new_applied_job_path
,
method: :get
,
enforce_utf8:
false
do
%>
<%=
render
partial:
'favorites/job'
,
collection:
@jobs
%>
<div
class=
"actions text-center"
>
<%=
submit_tag
'Apply Now'
,
name:
nil
,
class:
'btn btn-outline-success btn-lg'
%>
</div>
<%
end
%>
<%=
paginate
@jobs
%>
<%=
paginate
@jobs
%>
<%
else
%>
<h4
class=
"text-center"
>
Sorry! We can't found what you want!
</h4>
<%
end
%>
</div>
</div>
</div>
</div>
app/views/histories/_job.html.erb
View file @
37cb0f75
<%=
form_tag
new_applied_job_path
,
method: :get
,
enforce_utf8:
false
do
%>
<div
class=
'card flex-md-row align-items-center my-2 p-2'
>
<%
jobs
.
each
do
|
job
|
%>
<div
class=
'card flex-md-row align-items-center my-2 p-2'
>
<%=
radio_button_tag
:job_id
,
job
.
id
%>
<%=
radio_button_tag
:job_id
,
job
.
id
%>
<div
class=
'card-body'
>
<%=
render
'shared/job_body'
,
job:
job
%>
<%=
link_to
job
.
title
,
job_path
(
job
),
class:
'card-title font-weight-bold text-decoration-none'
%>
</div>
<p
class=
'card-text'
>
<%=
job
.
company
.
name
%>
</p>
<p
class=
'mb-0'
>
<strong>
Work place:
</strong>
<%
job
.
locations
.
each
do
|
location
|
%>
<%=
location
.
city
%>
<%
end
%>
</p>
<p><strong>
Salary:
</strong>
<%=
job
.
salary
%>
</p>
<p
class=
'card-text'
>
<%=
strip_tags
(
job
.
description
).
truncate
(
Job
::
WORDS_SHORT_DESCRIPTION
)
%>
</p>
</div>
</div>
<%
end
%>
<div
class=
"actions text-center"
>
<%=
submit_tag
'Apply Now'
,
name:
nil
,
class:
'btn btn-outline-success btn-lg'
%>
</div>
<%
end
%>
app/views/histories/index.html.erb
View file @
37cb0f75
...
@@ -2,6 +2,11 @@
...
@@ -2,6 +2,11 @@
<h3
class=
'text-center'
>
History Jobs
</h3>
<h3
class=
'text-center'
>
History Jobs
</h3>
<hr
class=
"divider"
>
<hr
class=
"divider"
>
<div
class=
'content'
>
<div
class=
'content'
>
<%=
render
'histories/job'
,
jobs:
@jobs
if
@jobs
.
any?
%>
<%=
form_tag
new_applied_job_path
,
method: :get
,
enforce_utf8:
false
do
%>
<%=
render
partial:
'histories/job'
,
collection:
@jobs
%>
<div
class=
"actions text-center"
>
<%=
submit_tag
'Apply Now'
,
name:
nil
,
class:
'btn btn-outline-success btn-lg'
if
@jobs
.
any?
%>
</div>
<%
end
%>
</div>
</div>
</div>
</div>
app/views/jobs/_job.html.erb
View file @
37cb0f75
<div
class=
'card flex-md-row align-items-center my-2'
>
<div
class=
'card flex-md-row align-items-center my-2'
>
<div
class=
'card-body'
>
<%=
render
'shared/job_body'
,
job:
job
%>
<%=
link_to
job
.
title
,
job_path
(
job
),
class:
'card-title font-weight-bold text-decoration-none'
%>
<p
class=
'card-text'
>
<%=
job
.
company
.
name
%>
</p>
<p
class=
'mb-0'
>
<strong>
Work place:
</strong>
<%
job
.
locations
.
each
do
|
location
|
%>
<%=
location
.
city
%>
<%
end
%>
</p>
<p><strong>
Salary:
</strong>
<%=
job
.
salary
%>
</p>
<p
class=
'card-text'
>
<%=
strip_tags
(
job
.
description
).
truncate
(
Job
::
WORDS_SHORT_DESCRIPTION
)
%>
</p>
</div>
<div
id=
"favorite-
<%=
job
.
id
%>
"
class=
'p-2'
>
<div
id=
"favorite-
<%=
job
.
id
%>
"
class=
'p-2'
>
<%=
render
'favorites/link_favorite'
,
job_id:
job
.
id
%>
<%=
render
'favorites/link_favorite'
,
job_id:
job
.
id
%>
</div>
</div>
...
...
app/views/jobs/index.html.erb
View file @
37cb0f75
<div
class=
'px-5'
>
<div
class=
'px-5'
>
<%=
render
'shared/searchbar'
,
my_class:
'd-flex flex-column flex-md-row'
%>
<%=
render
'shared/searchbar'
,
my_class:
'd-flex flex-column flex-md-row'
%>
</div>
</div>
<div>
<div
class=
'content'
>
<%
if
@jobs
.
any?
%>
<div
class=
'message text-center'
>
<div
class=
'message text-center'
>
<h3>
We found
<%=
pluralize
(
@jobs
.
total_count
,
'result'
)
%>
for "
<%=
@keyword
%>
"
</h3>
<h3>
We found
<%=
pluralize
(
@jobs
.
total_count
,
'result'
)
%>
for "
<%=
@keyword
%>
"
</h3>
</div>
</div>
<hr>
<hr>
<div
class=
'content'
>
<%=
paginate
@jobs
%>
<%=
paginate
@jobs
%>
<%=
render
partial:
'jobs/job'
,
collection:
@jobs
%>
<%=
render
partial:
'jobs/job'
,
collection:
@jobs
%>
<%=
paginate
@jobs
%>
<%=
paginate
@jobs
%>
</div>
<%
else
%>
<h4
class=
"text-center"
>
Sorry! We can't found what you want!
</h4>
<%
end
%>
</div>
</div>
app/views/jobs/show.html.erb
View file @
37cb0f75
...
@@ -32,14 +32,14 @@
...
@@ -32,14 +32,14 @@
</div>
</div>
<div
class=
"col-2"
>
<div
class=
"col-2"
>
<%=
link_to_if
@is_not_applied
,
'Apply Now'
,
new_applied_job_path
(
job_id:
@job
.
id
),
class:
'btn btn-outline-success btn-lg'
do
%>
<%=
link_to_if
@is_not_applied
,
'Apply Now'
,
new_applied_job_path
(
job_id:
@job
.
id
),
class:
'btn btn-outline-success btn-lg'
do
%>
<%=
link_to
'Appl
y Now
'
,
'#'
,
class:
'btn btn-outline-secondary btn-lg disabled'
%>
<%=
link_to
'Appl
ied
'
,
'#'
,
class:
'btn btn-outline-secondary btn-lg disabled'
%>
<%
end
%>
<%
end
%>
</div>
</div>
</div>
</div>
<div
class=
"row my-3"
>
<div
class=
"row my-3"
>
<div
class=
"col-6 text-right"
>
<div
class=
"col-6 text-right"
>
<%=
link_to_if
@is_not_applied
,
'Apply Now'
,
new_applied_job_path
(
job_id:
@job
.
id
),
class:
'btn btn-outline-success btn-lg'
do
%>
<%=
link_to_if
@is_not_applied
,
'Apply Now'
,
new_applied_job_path
(
job_id:
@job
.
id
),
class:
'btn btn-outline-success btn-lg'
do
%>
<%=
link_to
'Appl
y Now
'
,
'#'
,
class:
'btn btn-outline-secondary btn-lg disabled'
%>
<%=
link_to
'Appl
ied
'
,
'#'
,
class:
'btn btn-outline-secondary btn-lg disabled'
%>
<%
end
%>
<%
end
%>
</div>
</div>
<div
id=
"favorite-
<%=
@job
.
id
%>
"
class=
"col-6 text-left"
>
<div
id=
"favorite-
<%=
@job
.
id
%>
"
class=
"col-6 text-left"
>
...
...
app/views/shared/_header.html.erb
View file @
37cb0f75
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
<%
if
user_signed_in?
%>
<%
if
user_signed_in?
%>
<li
class=
"nav-item"
>
<li
class=
"nav-item"
>
<%=
link_to
favorites_path
,
class:
'nav-link text-white'
,
title:
'Favorite'
do
%>
<%=
link_to
favorites_path
,
class:
'nav-link text-white'
,
title:
'Favorite'
do
%>
<small>
<%=
current_user
.
favorites
.
size
%>
</small>
<small
id=
"sum-favorited"
>
<%=
current_user
.
favorites
.
size
%>
</small>
<i
class=
"fas fa-heart"
></i>
<i
class=
"fas fa-heart"
></i>
<%
end
%>
<%
end
%>
</li>
</li>
...
...
app/views/shared/_job_body.html.erb
0 → 100644
View file @
37cb0f75
<div
class=
'card-body'
>
<%=
link_to
job
.
title
,
job_path
(
job
),
class:
'card-title font-weight-bold text-decoration-none'
%>
<p
class=
'card-text'
>
<%=
job
.
company
.
name
%>
</p>
<p
class=
'mb-0'
>
<strong>
Work place:
</strong>
<%
job
.
locations
.
each
do
|
location
|
%>
<%=
location
.
city
%>
<%
end
%>
</p>
<p><strong>
Salary:
</strong>
<%=
job
.
salary
%>
</p>
<p
class=
'card-text'
>
<%=
strip_tags
(
job
.
description
).
truncate
(
Job
::
WORDS_SHORT_DESCRIPTION
)
%>
</p>
</div>
lib/tasks/delete_record.rake
0 → 100644
View file @
37cb0f75
namespace
:delete_record
do
desc
'Delete history when total greater than default limit'
task
history: :environment
do
users
=
User
.
includes
(
:histories
).
all
users
.
each
do
|
user
|
break
if
user
.
histories
.
size
<=
History
::
NUMBER_STORED_HISTORIES
lasted
=
user
.
histories
.
last
(
History
::
NUMBER_STORED_HISTORIES
).
pluck
(
:id
)
user
.
histories
.
where
.
not
(
id:
lasted
).
delete_all
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