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
6ccea578
Commit
6ccea578
authored
Sep 03, 2020
by
Huỳnh Thiên Phước
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change logic code and fix mentor's comments
parent
d91084a9
Pipeline
#1066
canceled with stages
in 0 seconds
Changes
12
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
27 additions
and
33 deletions
+27
-33
app/controllers/favorite_jobs_controller.rb
+6
-13
app/controllers/history_jobs_controller.rb
+0
-8
app/controllers/jobs_controller.rb
+4
-4
app/helpers/sessions_helper.rb
+1
-0
app/models/job.rb
+4
-0
app/models/user.rb
+2
-2
app/views/favorite_jobs/create.js.erb
+1
-1
app/views/favorite_jobs/destroy.js.erb
+2
-2
app/views/favorite_jobs/index.html.erb
+1
-0
app/views/jobs/show.html.erb
+2
-2
app/views/users/_unfavorite.html.erb
+1
-1
config/settings/development.yml
+3
-0
No files found.
app/controllers/favorite_jobs_controller.rb
View file @
6ccea578
class
FavoriteJobsController
<
ApplicationController
before_action
:sign_in_favorite_validation
,
only:
%i[create destroy]
before_action
:sign_in_validation
,
only:
[
:index
]
before_action
:sign_in_validation
,
only:
%i[create destroy index]
def
index
if
params
[
:page
].
present?
||
params
[
:page
]
==
""
return
redirect_to
favorite_jobs_path
,
flash:
{
warning:
Settings
.
user
.
favorite_job
.
validate_page
}
if
params
[
:page
].
to_i
<=
0
||
params
[
:page
].
scan
(
/\D+/
).
present?
end
@count
=
current_user
.
favorite_jobs
.
count
@favorited_jobs
=
current_user
.
favorite_jobs
.
order_favorite
.
page
(
params
[
:page
]).
per
(
Job
::
LIMIT_PAGE
)
end
def
create
@job
=
Job
.
find_by_id
(
params
[
:job_id
])
return
if
current_user
.
favorite_jobs
.
exists?
(
job_id:
params
[
:job_id
])
@follow
=
current_user
.
favorite!
(
params
[
:job_id
])
respond_to
{
|
format
|
format
.
js
}
end
def
destroy
@job
=
Job
.
find_by_id
(
params
[
:job_id
])
@unfollow
=
current_user
.
unfavorite!
(
params
[
:job_id
])
respond_to
{
|
format
|
format
.
js
}
if
request
.
referer
.
include?
(
"favorite"
)
@count
=
current_user
.
favorite_jobs
.
count
...
...
@@ -31,17 +29,12 @@ class FavoriteJobsController < ApplicationController
return
redirect_to
request
.
referer
if
count_on_page
==
Job
::
DIVISIBLE
end
respond_to
{
|
format
|
format
.
js
}
end
private
def
sign_in_favorite_validation
return
if
signed_in?
session
[
:return_to
]
=
request
.
referer
flash
[
:warning
]
=
Settings
.
user
.
warning_signin
redirect_to
login_path
end
def
sign_in_validation
return
if
signed_in?
store_location
...
...
app/controllers/history_jobs_controller.rb
View file @
6ccea578
class
HistoryJobsController
<
ApplicationController
before_action
:sign_in_favorite_validation
,
only:
[
:destroy
]
before_action
:sign_in_validation
,
only:
[
:index
]
def
index
...
...
@@ -9,13 +8,6 @@ class HistoryJobsController < ApplicationController
private
def
sign_in_favorite_validation
return
if
signed_in?
session
[
:return_to
]
=
request
.
referer
flash
[
:warning
]
=
Settings
.
user
.
warning_signin
redirect_to
login_path
end
def
sign_in_validation
return
if
signed_in?
store_location
...
...
app/controllers/jobs_controller.rb
View file @
6ccea578
...
...
@@ -30,15 +30,15 @@ class JobsController < ApplicationController
session
.
delete
(
:job_applied
)
return
redirect_to
jobs_path
unless
@job
if
signed_in?
@user
=
JobApplied
.
where
(
user_id:
current_user
.
id
,
job_id:
params
[
:id
])
history_jobs
=
current_user
.
histories
.
order_history
history_jobs
.
last
.
destroy
if
history_jobs
.
count
>=
Job
::
LIMIT_HISTORY
@is_job_applied
=
current_user
.
job_applieds
.
pluck
(
:job_id
).
include?
@job
.
id
founded_history
=
current_user
.
histories
.
find_by
(
job_id:
params
[
:id
])
return
founded_history
.
update
(
updated_at:
Time
.
current
.
utc
)
if
founded_history
.
present?
history
=
current_user
.
histories
.
create!
(
job_id:
params
[
:id
])
history_jobs
=
current_user
.
histories
.
order_history
history_jobs
.
last
.
destroy
if
history_jobs
.
count
>=
Job
::
LIMIT_HISTORY
end
end
...
...
app/helpers/sessions_helper.rb
View file @
6ccea578
...
...
@@ -33,6 +33,7 @@ module SessionsHelper
end
def
store_location
return
session
[
:return_to
]
=
request
.
referer
if
request
.
url
.
include?
(
"favorite_job"
)
session
[
:return_to
]
=
request
.
url
if
request
.
get?
end
end
app/models/job.rb
View file @
6ccea578
...
...
@@ -27,6 +27,10 @@ class Job < ApplicationRecord
company
&
.
name
end
def
converted_company_name
company
&
.
converted_name
end
def
format_desc
description
.
truncate_words
(
250
)
end
...
...
app/models/user.rb
View file @
6ccea578
...
...
@@ -29,11 +29,11 @@ class User < ApplicationRecord
end
def
unfavorite!
(
job_id
)
favorite_jobs
.
find_by
(
job_id:
job_id
).
destroy
favorite_jobs
.
find_by
(
job_id:
job_id
)
&
.
destroy
end
def
remove_history!
(
job_id
)
histories
.
find_by
(
job_id:
job_id
).
destroy
histories
.
find_by
(
job_id:
job_id
)
&
.
destroy
end
def
self
.
new_remember_token
...
...
app/views/favorite_jobs/create.js.erb
View file @
6ccea578
$("#favorite-form-
<%=
@
job
.
id
%>
").html("
<%=
escape_javascript
render
'users/unfavorite'
,
job_id:
@job
.
id
%>
");
$("#favorite-form-
<%=
@
follow
.
job_id
%>
").html("
<%=
escape_javascript
render
'users/unfavorite'
,
job_id:
@follow
.
job_
id
%>
");
app/views/favorite_jobs/destroy.js.erb
View file @
6ccea578
$("#favorite-form-
<%=
@
job
.
id
%>
").html("
<%=
j
render
'users/favorite'
,
job_id:
@job
.
id
%>
");
$(".job-id-
<%=
@
job
.
id
%>
").remove();
$("#favorite-form-
<%=
@
unfollow
.
job_id
%>
").html("
<%=
j
render
'users/favorite'
,
job_id:
@unfollow
.
job_
id
%>
");
$(".job-id-
<%=
@
unfollow
.
job_
id
%>
").remove();
$(".count-favorite-jobs").html("
<%=
@count
%>
");
app/views/favorite_jobs/index.html.erb
View file @
6ccea578
<div
class=
"container"
>
<%=
render
'layouts/flash'
%>
<%
if
@favorited_jobs
.
count
>
0
%>
<h1
class=
"text-center my-job-label"
>
Favorite Job (
<span
class=
"count-favorite-jobs"
>
<%=
@count
%>
</span>
jobs)
</h1>
<%=
paginate
@favorited_jobs
,
outer_window:
2
,
window:
1
%>
...
...
app/views/jobs/show.html.erb
View file @
6ccea578
...
...
@@ -4,7 +4,7 @@
<div
class=
"job-info"
>
<div><strong>
<%=
@job
.
title
%>
</strong></div>
<div>
<%=
link_to
@job
.
company_name
,
company_jobs_path
(
converted_name:
@job
.
co
mpany
.
converted
_name
),
class:
'company'
%>
<%=
link_to
@job
.
company_name
,
company_jobs_path
(
converted_name:
@job
.
co
nverted_company
_name
),
class:
'company'
%>
</div>
<div
class=
"breadcrumb"
>
<%=
link_to
"TOP"
,
root_path
%>
 
/
 
...
...
@@ -18,7 +18,7 @@
<%
end
%>
/
 
<%=
@job
.
title
.
truncate_words
(
5
)
%>
</div>
<%
if
signed_in?
&&
@user
.
present?
%>
<%
if
@is_job_applied
%>
<div
class=
"apply-job"
>
<strong>
Applied
</strong>
</div>
...
...
app/views/users/_unfavorite.html.erb
View file @
6ccea578
<%=
form_for
(
:job_unfavorite
,
url:
unfavorite_job_path
(
job_id:
job_id
),
method: :delete
,
remote:
true
)
do
|
f
|
%>
<%=
form_for
(
:job_unfavorite
,
url:
unfavorite_job_path
(
job_id:
job_id
),
method: :delete
,
remote:
true
,
data:
{
disable_with:
false
}
)
do
|
f
|
%>
<%=
f
.
submit
"Unfavorite"
,
class:
"btn btn-outline-danger"
,
id:
"button-unfavorite"
%>
<%
end
%>
config/settings/development.yml
View file @
6ccea578
...
...
@@ -21,6 +21,9 @@ user:
applied_job
:
applied
:
'
You
applied
for
this
job'
favorite_job
:
validate_page
:
'
Params
Page
format
failed'
email
:
confirmation
:
'
Welcome
To
VeNJOB!
Confirm
Your
Email'
reset_password
:
'
VeNJOB
Password
Assistance'
...
...
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