Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
ven-job
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
Trịnh Hoàng Phúc
ven-job
Commits
b07006ff
Commit
b07006ff
authored
May 19, 2020
by
Trịnh Hoàng Phúc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add table History, fix review 19/05/2020
parent
475139e9
Pipeline
#632
failed with stages
in 0 seconds
Changes
12
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
79 additions
and
53 deletions
+79
-53
app/assets/stylesheets/js/custom.js
+3
-3
app/controllers/admins_controller.rb
+2
-0
app/controllers/history_controller.rb
+6
-2
app/controllers/jobs_controller.rb
+5
-7
app/controllers/users_controller.rb
+2
-19
app/models/history.rb
+8
-0
app/models/job.rb
+2
-1
app/models/user.rb
+2
-0
app/views/history/index.html.erb
+1
-21
app/views/shared/_history_item_has_not_user.html.erb
+20
-0
app/views/shared/_history_item_has_user.html.erb
+20
-0
db/migrate/20200519030913_create_histories.rb
+8
-0
No files found.
app/assets/stylesheets/js/custom.js
View file @
b07006ff
...
...
@@ -25,7 +25,7 @@
},
error
:
(
err
)
=>
{
if
(
err
.
status
===
401
){
if
(
confirm
(
err
.
response
JSON
.
message
)){
if
(
confirm
(
err
.
response
Text
)){
window
.
location
.
href
=
"/users/sign_in"
;
}
}
...
...
@@ -55,7 +55,7 @@
},
error
:
(
err
)
=>
{
if
(
err
.
status
===
401
){
if
(
confirm
(
err
.
response
JSON
.
message
)){
if
(
confirm
(
err
.
response
Text
)){
window
.
location
.
href
=
"/users/sign_in"
;
}
}
...
...
@@ -78,7 +78,7 @@
},
error
:
(
err
)
=>
{
if
(
err
.
status
===
401
){
if
(
confirm
(
err
.
response
JSON
.
message
)){
if
(
confirm
(
err
.
response
Text
)){
window
.
location
.
href
=
"/users/sign_in"
;
}
}
...
...
app/controllers/admins_controller.rb
View file @
b07006ff
class
AdminsController
<
ApplicationController
before_action
:authenticate_admin!
def
applies
@cities
=
City
.
order
(
"title ASC"
).
all
@industries
=
Industry
.
order
(
"title ASC"
).
all
...
...
app/controllers/history_controller.rb
View file @
b07006ff
class
HistoryController
<
ApplicationController
def
index
return
redirect_to
jobs_path
if
cookies
[
:job_ids_history
].
blank?
if
user_signed_in?
@jobs_history
=
History
.
includes
(
:job
,
:user
).
where
(
"user_id =
#{
current_user
.
id
}
"
)
else
arr_job_ids
=
cookies
[
:job_ids_history
].
split
(
","
)
job_ids
=
cookies
[
:job_ids_history
].
split
(
","
)
@jobs_history
=
Job
.
where
(
"id IN (?)"
,
job_ids
).
order
(
"id DESC"
)
end
end
end
\ No newline at end of file
app/controllers/jobs_controller.rb
View file @
b07006ff
...
...
@@ -17,17 +17,13 @@ class JobsController < ApplicationController
def
show
@job
=
Job
.
find_by
(
id:
params
[
:id
])
return
redirect_to
page_404_path
if
@job
.
blank?
if
user_signed_in?
@apply
=
Apply
.
find_by
(
job_id:
params
[
:id
],
user_id:
current_user
.
id
)
@favorite
=
Favorite
.
find_by
(
job_id:
params
[
:id
],
user_id:
current_user
.
id
)
end
@relate_jobs
=
Job
.
related_jobs
(
@job
.
company_id
,
@job
.
id
)
if
cookies
[
:job_ids_history
].
nil?
History
.
create_history
(
params
[
:id
],
current_user
.
id
)
else
if
cookies
[
:job_ids_history
].
blank?
cookies
[
:job_ids_history
]
=
{
value:
@job
.
id
,
expires:
Time
.
now
+
3600
}
else
arr_job_ids
=
cookies
[
:job_ids_history
].
split
(
","
)
...
...
@@ -38,6 +34,8 @@ class JobsController < ApplicationController
cookies
[
:job_ids_history
]
=
{
value:
arr_job_ids
.
join
(
","
),
expires:
Time
.
now
+
3600
}
end
end
@relate_jobs
=
Job
.
related_jobs
(
@job
.
company_id
,
@job
.
id
)
end
def
search
return
redirect_to
root_path
,
alert:
"Empty field!"
if
params
[
:keyword
].
blank?
...
...
app/controllers/users_controller.rb
View file @
b07006ff
class
UsersController
<
ApplicationController
before_action
:authenticate_user!
def
info
redirect_to
user_session_path
unless
user_signed_in?
end
def
apply_jobs
redirect_to
user_session_path
unless
user_signed_in?
@applied_jobs
=
Apply
.
where
(
"user_id =
#{
current_user
.
id
}
"
)
end
def
favorite_jobs
redirect_to
user_session_path
unless
user_signed_in?
@favorite_jobs
=
Favorite
.
where
(
"user_id =
#{
current_user
.
id
}
"
)
end
def
apply_or_favorite_jobs
unless
user_signed_in?
payload
=
{
message:
"You are not logged in, please login to operate the feature"
,
}
render
:json
=>
payload
,
:status
=>
:unauthorized
else
if
params
[
:job_ids
].
present?
params
[
:job_ids
].
each
do
|
id
|
if
params
[
:type
]
==
"apply"
...
...
@@ -36,15 +27,8 @@ class UsersController < ApplicationController
render
:json
=>
payload
,
:status
=>
:ok
end
end
end
def
remove_favorite_job
unless
user_signed_in?
payload
=
{
message:
"You are not logged in, please login to operate the feature"
,
}
render
:json
=>
payload
,
:status
=>
:unauthorized
else
if
params
[
:favorite_id
].
present?
Favorite
.
find_by
(
id:
params
[
:favorite_id
]).
destroy
payload
=
{
...
...
@@ -53,5 +37,4 @@ class UsersController < ApplicationController
render
:json
=>
payload
,
:status
=>
:ok
end
end
end
end
app/models/history.rb
0 → 100644
View file @
b07006ff
class
History
<
ApplicationRecord
belongs_to
:user
belongs_to
:job
def
self
.
create_history
(
job_id
,
user_id
)
return
History
.
find_or_create_by
({
job_id:
job_id
,
user_id:
user_id
})
end
end
app/models/job.rb
View file @
b07006ff
...
...
@@ -9,7 +9,8 @@ class Job < ApplicationRecord
has_many
:applies
has_many
:users
,
through: :applies
has_many
:histories
has_many
:users
,
through: :histories
has_many
:favorites
has_many
:users
,
through: :favorites
...
...
app/models/user.rb
View file @
b07006ff
...
...
@@ -8,6 +8,8 @@ class User < ApplicationRecord
has_many
:jobs
,
through: :applies
has_many
:favorites
has_many
:jobs
,
through: :favorites
has_many
:histories
has_many
:jobs
,
through: :histories
mount_uploader
:cv
,
CvUploader
...
...
app/views/history/index.html.erb
View file @
b07006ff
...
...
@@ -20,27 +20,7 @@
</tr>
</thead>
<tbody>
<%
@jobs_history
.
each_with_index
do
|
job
,
index
|
%>
<tr
class=
"woocommerce-cart-form__cart-item cart_item"
>
<td>
<%=
index
+
1
%>
</td>
<td
style=
"text-align: center;"
>
<input
type=
"checkbox"
class=
"checkbox-apply-job"
data-id=
"
<%=
job
.
id
%>
"
>
</td>
<td>
<%=
link_to
job
.
title
,
job
%>
</td>
<td>
<%
job
.
cities
.
each_with_index
do
|
city
,
index
|
%>
<%=
city
.
title
%><%=
", "
if
index
!=
job
.
cities
.
size
-
1
%>
<%
end
%>
</td>
<td
class=
"product-price"
>
<%=
job
.
salary
%>
</td>
</tr>
<%
end
%>
<%=
render
partial:
(
user_signed_in?
?
'/shared/history_item_has_user'
:
'/shared/history_item_has_not_user'
),
collection:
@jobs_history
,
as: :history_item
%>
<tr>
<td
colspan=
"6"
class=
"actions"
>
<a
class=
"button apply-all-job"
href=
"javascript:void(0)"
>
Apply all
</a>
...
...
app/views/shared/_history_item_has_not_user.html.erb
0 → 100644
View file @
b07006ff
<tr
class=
"woocommerce-cart-form__cart-item cart_item"
>
<td>
<%=
history_item_counter
+
1
%>
</td>
<td
style=
"text-align: center;"
>
<input
type=
"checkbox"
class=
"checkbox-apply-job"
data-id=
"
<%=
history_item
.
id
%>
"
>
</td>
<td>
<%=
link_to
history_item
.
title
,
history_item
%>
</td>
<td>
<%
history_item
.
cities
.
each_with_index
do
|
city
,
index
|
%>
<%=
city
.
title
%><%=
", "
if
index
!=
history_item
.
cities
.
size
-
1
%>
<%
end
%>
</td>
<td
class=
"product-price"
>
<%=
history_item
.
salary
%>
</td>
</tr>
\ No newline at end of file
app/views/shared/_history_item_has_user.html.erb
0 → 100644
View file @
b07006ff
<tr
class=
"woocommerce-cart-form__cart-item cart_item"
>
<td>
<%=
history_item_counter
+
1
%>
</td>
<td
style=
"text-align: center;"
>
<input
type=
"checkbox"
class=
"checkbox-apply-job"
data-id=
"
<%=
history_item
.
job_id
%>
"
>
</td>
<td>
<%=
link_to
history_item
.
job
.
title
,
history_item
.
job
%>
</td>
<td>
<%
history_item
.
job
.
cities
.
each_with_index
do
|
city
,
index
|
%>
<%=
city
.
title
%><%=
", "
if
index
!=
history_item
.
job
.
cities
.
size
-
1
%>
<%
end
%>
</td>
<td
class=
"product-price"
>
<%=
history_item
.
job
.
salary
%>
</td>
</tr>
\ No newline at end of file
db/migrate/20200519030913_create_histories.rb
0 → 100644
View file @
b07006ff
class
CreateHistories
<
ActiveRecord
::
Migration
[
6.0
]
def
change
create_table
:histories
do
|
t
|
t
.
references
:user
,
null:
false
,
foreign_key:
true
t
.
references
:job
,
null:
false
,
foreign_key:
true
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