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
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
3
Merge Requests
3
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Xuan Trung Le
venjob
Commits
14fbc146
Commit
14fbc146
authored
Nov 17, 2017
by
Xuan Trung Le
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
paging with solr
parent
616cd333
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
43 additions
and
36 deletions
+43
-36
app/assets/javascripts/application.js
+8
-2
app/controllers/admins/applies_controller.rb
+20
-21
app/controllers/jobs_controller.rb
+10
-11
app/models/job.rb
+1
-1
app/views/admins/applies/index.html.erb
+4
-1
No files found.
app/assets/javascripts/application.js
View file @
14fbc146
...
@@ -25,13 +25,19 @@ $(document).ready(function(){
...
@@ -25,13 +25,19 @@ $(document).ready(function(){
});
});
$
(
'.form_date'
).
datetimepicker
({
$
(
'.form_date'
).
datetimepicker
({
language
:
'fr
'
,
language
:
'en
'
,
weekStart
:
1
,
weekStart
:
1
,
todayBtn
:
1
,
todayBtn
:
1
,
autoclose
:
1
,
autoclose
:
1
,
todayHighlight
:
1
,
todayHighlight
:
1
,
startView
:
2
,
startView
:
2
,
minView
:
2
,
minView
:
2
,
forceParse
:
0
forceParse
:
0
});
});
// set min-height css for content
windowHeight
=
$
(
document
).
height
();
menuHeight
=
$
(
'.navbar'
).
height
();
footHeight
=
$
(
'.footer'
).
height
();
$
(
'.content'
).
css
(
"min-height"
,
windowHeight
-
(
menuHeight
+
footHeight
))
});
});
app/controllers/admins/applies_controller.rb
View file @
14fbc146
require
'rsolr'
require
'rsolr'
require
"csv"
require
"csv"
require
'uri'
require
'./app/models/settings.rb'
class
Admins
::
AppliesController
<
ApplicationController
class
Admins
::
AppliesController
<
ApplicationController
before_action
:authenticate_admin!
before_action
:authenticate_admin!
def
index
def
index
if
params
[
:commit
]
if
params
[
:commit
]
# get condition here
condition
=
get_condition
condition
=
get_condition
# get applications from query
response
=
query
(
condition
)
response
=
query
(
condition
)
job_id
=
response
[
"response"
][
"docs"
].
pluck
(
"id"
)
job_id
s
=
response
[
"response"
][
"docs"
].
pluck
(
"id"
)
@applications
=
ApplyJob
.
where
(
job_id:
job_id
).
includes
(
:job
,
:user
)
application_count
=
response
[
"response"
][
"numFound"
]
applications
=
ApplyJob
.
where
(
job_id:
job_ids
).
includes
(
:job
,
:user
)
@applications
=
Kaminari
.
paginate_array
(
applications
,
total_count:
application_count
).
page
(
params
[
:page
])
if
params
[
:commit
].
eql?
'Down csv'
if
params
[
:commit
].
eql?
'Down csv'
down_csv
(
@applications
)
down_csv
(
@applications
)
return
return
end
end
else
else
# get applications
# get applications
@applications
=
ApplyJob
.
includes
(
:job
,
:user
)
@applications
=
ApplyJob
.
includes
(
:job
,
:user
)
.
page
(
params
[
:page
])
end
end
end
end
...
@@ -30,25 +29,23 @@ class Admins::AppliesController < ApplicationController
...
@@ -30,25 +29,23 @@ class Admins::AppliesController < ApplicationController
end
end
def
down_cv_candidate
def
down_cv_candidate
user
=
User
.
find
(
params
[
:user_id
])
user
=
User
.
find
(
params
[
:user_id
])
if
user
.
cv
.
file
.
exists?
if
user
.
cv
.
file
.
exists?
send_file
user
.
cv
.
path
send_file
user
.
cv
.
path
else
else
flash
[
:notice
]
=
'File not exist!'
flash
[
:notice
]
=
'File not exist!'
redirect_back
(
fallback_location:
root_path
)
redirect_back
(
fallback_location:
root_path
)
end
end
end
end
private
private
def
connect
def
solr_
connect
RSolr
.
connect
url:
Settings
.
rsolr
.
url
@solr
||=
RSolr
.
connect
url:
Settings
.
rsolr
.
url
end
end
def
query
(
condition
)
def
query
(
condition
)
# Direct connection
@solr
||=
connect
# use get method to query
# use get method to query
response
=
@solr
.
get
'select'
,
params:
condition
response
=
solr_connect
.
get
'select'
,
params:
condition
response
response
end
end
...
@@ -57,11 +54,13 @@ class Admins::AppliesController < ApplicationController
...
@@ -57,11 +54,13 @@ class Admins::AppliesController < ApplicationController
filter_query
=
[]
filter_query
=
[]
date_from
=
'*'
date_from
=
'*'
date_to
=
'NOW'
date_to
=
'NOW'
condition
[
:fl
]
=
"id"
start
=
params
[
:page
].
to_i
>
1
?
params
[:
page
].
to_i
-
1
:
0
# get condition
# get condition
condition
[
:q
]
=
"email:[* TO *]"
condition
[
:q
]
=
"email:[* TO *]"
condition
[
:start
]
=
0
condition
[
:start
]
=
Settings
.
top
.
job_per_history_page
*
start
condition
[
:rows
]
=
ApplyJob
.
count
condition
[
:rows
]
=
Settings
.
top
.
job_per_history_page
filter_query
<<
"email:
\"
#{
params
[
:email
]
}
\"
"
if
params
[
:email
]
filter_query
<<
"email:
\"
#{
params
[
:email
]
}
\"
"
if
params
[
:email
]
filter_query
<<
"city_name:
\"
#{
params
[
:city
]
}
\"
"
unless
params
[
:city
].
blank?
filter_query
<<
"city_name:
\"
#{
params
[
:city
]
}
\"
"
unless
params
[
:city
].
blank?
filter_query
<<
"industry:
\"
#{
params
[
:industry
]
}
\"
"
unless
params
[
:industry
].
blank?
filter_query
<<
"industry:
\"
#{
params
[
:industry
]
}
\"
"
unless
params
[
:industry
].
blank?
...
...
app/controllers/jobs_controller.rb
View file @
14fbc146
...
@@ -42,12 +42,12 @@ class JobsController < ApplicationController
...
@@ -42,12 +42,12 @@ class JobsController < ApplicationController
end
end
def
search
def
search
# byebug
condition
=
get_condition
condition
=
get_condition
response
=
query
(
condition
)
response
=
query
(
condition
)
job_ids
=
response
[
"response"
][
"docs"
].
pluck
(
"id"
)
job_ids
=
response
[
"response"
][
"docs"
].
pluck
(
"id"
)
@jobs
=
Job
.
where
(
id:
job_ids
).
check_expiration_date
.
includes
(
:company
).
page
(
params
[
:page
])
@jobs_count
=
response
[
"response"
][
"numFound"
]
@jobs_count
=
job_ids
.
count
jobs
=
Job
.
where
(
id:
job_ids
).
check_expiration_date
.
includes
(
:company
)
@jobs
=
Kaminari
.
paginate_array
(
jobs
,
total_count:
@jobs_count
).
page
(
params
[
:page
])
@result
=
params
[
:search
]
@result
=
params
[
:search
]
render
template:
"jobs/job_lists"
render
template:
"jobs/job_lists"
end
end
...
@@ -58,28 +58,27 @@ class JobsController < ApplicationController
...
@@ -58,28 +58,27 @@ class JobsController < ApplicationController
@job
=
Job
.
find
(
params
[
:id
])
@job
=
Job
.
find
(
params
[
:id
])
end
end
def
connect
def
solr_
connect
RSolr
.
connect
url:
Settings
.
rsolr
.
url
@solr
||=
RSolr
.
connect
url:
Settings
.
rsolr
.
url
end
end
def
query
(
condition
)
def
query
(
condition
)
# Direct connection
@solr
||=
connect
# use get method to query
# use get method to query
response
=
@solr
.
get
'select'
,
:params
=>
condition
response
=
solr_connect
.
get
'select'
,
params:
condition
response
response
end
end
def
get_condition
def
get_condition
condition
=
{}
condition
=
{}
filter_query
=
[]
filter_query
=
[]
start
=
params
[
:page
].
to_i
>
1
?
params
[:
page
].
to_i
-
1
:
0
# get condition
# get condition
condition
[
:q
]
=
"*:*"
condition
[
:q
]
=
"*:*"
condition
[
:fl
]
=
"id"
condition
[
:fl
]
=
"id"
condition
[
:start
]
=
0
condition
[
:start
]
=
Settings
.
top
.
job_per_history_page
*
start
condition
[
:rows
]
=
Job
.
count
condition
[
:rows
]
=
Settings
.
top
.
job_per_history_page
unless
params
[
:search
].
blank
?
if
params
[
:search
].
present
?
filter_query
<<
"name:
\"
#{
params
[
:search
]
}
\"
||
filter_query
<<
"name:
\"
#{
params
[
:search
]
}
\"
||
company_name:
\"
#{
params
[
:search
]
}
\"
||
company_name:
\"
#{
params
[
:search
]
}
\"
||
city_name:
\"
#{
params
[
:search
]
}
\"
||
city_name:
\"
#{
params
[
:search
]
}
\"
||
...
...
app/models/job.rb
View file @
14fbc146
...
@@ -12,7 +12,7 @@ class Job < ApplicationRecord
...
@@ -12,7 +12,7 @@ class Job < ApplicationRecord
has_many
:users_has_viewed
,
through: :view_jobs
,
class_name:
'User'
,
source: :user
has_many
:users_has_viewed
,
through: :view_jobs
,
class_name:
'User'
,
source: :user
scope
:top_list
,
->
{
order
(
updated_date: :desc
).
check_expiration_date
.
limit
(
Settings
.
top
.
job_per_page
)
}
scope
:top_list
,
->
{
order
(
updated_date: :desc
).
check_expiration_date
.
limit
(
Settings
.
top
.
job_per_page
)
}
scope
:check_expiration_date
,
->
{
where
(
'
NOW() >= expiry_date'
)
}
scope
:check_expiration_date
,
->
{
where
(
'
expiry_date > ?'
,
Time
.
current
+
1
.
day
)
}
def
self
.
create_new_jobs
(
arr_jobs
)
def
self
.
create_new_jobs
(
arr_jobs
)
arr_jobs
.
each
do
|
item
|
arr_jobs
.
each
do
|
item
|
...
...
app/views/admins/applies/index.html.erb
View file @
14fbc146
<div
class=
"row"
>
<div
class=
"row
content
"
>
<div
class=
"container"
>
<div
class=
"container"
>
<div
class=
"col-md-12 search mt-20"
>
<div
class=
"col-md-12 search mt-20"
>
<%=
form_tag
admins_applies_path
,
method: :get
,
class:
"search-form"
do
%>
<%=
form_tag
admins_applies_path
,
method: :get
,
class:
"search-form"
do
%>
...
@@ -39,5 +39,8 @@
...
@@ -39,5 +39,8 @@
<%=
render
"admins/applies/application"
,
applications:
@applications
%>
<%=
render
"admins/applies/application"
,
applications:
@applications
%>
</div>
</div>
</div>
</div>
<div
class=
"pagination navbar-right"
>
<%=
paginate
@applications
%>
</div>
</div>
</div>
</div>
</div>
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