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
44262ce9
Commit
44262ce9
authored
Sep 07, 2020
by
Huỳnh Thiên Phước
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix mentor's comments
parent
18811449
Pipeline
#1072
failed with stages
in 0 seconds
Changes
4
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
15 additions
and
17 deletions
+15
-17
app/controllers/favorite_jobs_controller.rb
+11
-13
app/views/favorite_jobs/_favorite_job.html.erb
+1
-1
app/views/favorite_jobs/create.js.erb
+1
-1
app/views/favorite_jobs/destroy.js.erb
+2
-2
No files found.
app/controllers/favorite_jobs_controller.rb
View file @
44262ce9
...
...
@@ -2,32 +2,30 @@ class FavoriteJobsController < ApplicationController
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
page
=
Integer
(
params
[
:page
]
||
"1"
)
rescue
0
return
redirect_to
favorite_jobs_path
unless
page
.
positive?
@count
=
current_user
.
favorite_jobs
.
count
@favorited_jobs
=
current_user
.
favorite_jobs
.
order_favorite
.
page
(
pa
rams
[
:page
]
).
per
(
Job
::
LIMIT_PAGE
)
@favorited_jobs
=
current_user
.
favorite_jobs
.
order_favorite
.
page
(
pa
ge
).
per
(
Job
::
LIMIT_PAGE
)
end
def
create
return
if
current_user
.
favorite_jobs
.
exists?
(
job_id:
params
[
:job_id
])
@f
ollow
=
current_user
.
favorite!
(
params
[
:job_id
])
@f
avorite
=
current_user
.
favorite!
(
params
[
:job_id
])
respond_to
{
|
format
|
format
.
js
}
end
def
destroy
@unf
ollow
=
current_user
.
unfavorite!
(
params
[
:job_id
])
@unf
avorite
=
current_user
.
unfavorite!
(
params
[
:job_id
])
if
request
.
referer
.
include?
(
"favorite"
)
@count
=
current_user
.
favorite_jobs
.
count
current_page_count
=
@count
%
Job
::
LIMIT_PAGE
remain_page
=
@count
/
Job
::
LIMIT_PAGE
count_on_page
=
@count
%
Job
::
LIMIT_PAGE
page_number
=
@count
/
Job
::
LIMIT_PAGE
link_url
=
request
.
referer
.
to_s
.
split
(
"="
)
return
redirect_to
link_url
[
0
]
+
"="
+
page_number
.
to_s
if
count_on_page
==
Job
::
DIVISIBLE
&&
link_url
[
1
].
to_i
==
page_number
+
1
return
redirect_to
request
.
referer
if
count_on_page
==
Job
::
DIVISIBLE
return
redirect_to
favorite_jobs_path
(
page:
remain_page
)
if
current_page_count
==
Job
::
DIVISIBLE
&&
params
[
:page
]
==
remain_page
+
1
return
redirect_to
favorite_jobs_path
(
page:
remain_page
)
if
current_page_count
==
Job
::
DIVISIBLE
end
respond_to
{
|
format
|
format
.
js
}
...
...
app/views/favorite_jobs/_favorite_job.html.erb
View file @
44262ce9
...
...
@@ -21,7 +21,7 @@
<div
class=
"salary col-3"
>
Salary:
<%=
favorite_job
.
job
.
salary
%>
</div>
<%=
link_to
"Remove"
,
unfavorite_job_path
(
job_id:
favorite_job
.
job
.
id
),
method: :delete
,
remote:
true
,
class:
"btn btn-danger"
,
id:
"button-remove"
%>
<%=
link_to
"Remove"
,
unfavorite_job_path
(
job_id:
favorite_job
.
job
.
id
,
page:
params
[
:page
]
),
method: :delete
,
remote:
true
,
class:
"btn btn-danger"
,
id:
"button-remove"
%>
</div>
</div>
</div>
...
...
app/views/favorite_jobs/create.js.erb
View file @
44262ce9
$("#favorite-form-
<%=
@f
ollow
.
job_id
%>
").html("
<%=
escape_javascript
render
'users/unfavorite'
,
job_id:
@follow
.
job_id
%>
");
$("#favorite-form-
<%=
@f
avorite
.
job_id
%>
").html("
<%=
escape_javascript
render
'users/unfavorite'
,
job_id:
@favorite
.
job_id
%>
");
app/views/favorite_jobs/destroy.js.erb
View file @
44262ce9
$("#favorite-form-
<%=
@unf
ollow
.
job_id
%>
").html("
<%=
j
render
'users/favorite'
,
job_id:
@unfollow
.
job_id
%>
");
$(".job-id-
<%=
@unf
ollow
.
job_id
%>
").remove();
$("#favorite-form-
<%=
@unf
avorite
.
job_id
%>
").html("
<%=
j
render
'users/favorite'
,
job_id:
@unfavorite
.
job_id
%>
");
$(".job-id-
<%=
@unf
avorite
.
job_id
%>
").remove();
$(".count-favorite-jobs").html("
<%=
@count
%>
");
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