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
b0c6f32d
Commit
b0c6f32d
authored
Sep 11, 2020
by
Huỳnh Thiên Phước
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
created admin page
parent
d3fd0a39
Pipeline
#1098
failed with stages
in 0 seconds
Changes
11
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
139 additions
and
82 deletions
+139
-82
app/assets/stylesheets/form_login.scss
+3
-3
app/controllers/admins_controller.rb
+60
-13
app/models/admin.rb
+1
-1
app/models/job_applied.rb
+9
-13
app/services/export_csv_service.rb
+23
-0
app/views/admins/_datetime.html.erb
+9
-33
app/views/admins/_information.html.erb
+1
-1
app/views/admins/_search_condition.html.erb
+17
-17
app/views/admins/index.html.erb
+1
-1
app/views/admins/search.html.erb
+13
-0
config/routes.rb
+2
-0
No files found.
app/assets/stylesheets/form_login.scss
View file @
b0c6f32d
...
@@ -25,9 +25,9 @@
...
@@ -25,9 +25,9 @@
font-size
:
16px
;
font-size
:
16px
;
}
}
.tilde
{
.tilde
{
margin
:
0
0
0
40px
;
color
:
black
;
color
:
black
;
}
}
.datetime
{
.city-options
,
.industry-options
,
.datetime
{
margin
:
20px
;
margin
:
20px
0
20px
0
;
padding
:
10px
;
}
}
app/controllers/admins_controller.rb
View file @
b0c6f32d
class
AdminsController
<
ApplicationController
class
AdminsController
<
ApplicationController
before_action
:sign_out_current_user
before_action
:sign_out_current_user
before_action
:sign_in_validation_admin
,
only:
[
:index
,
:destroy
]
before_action
:remove_session
,
only
:[
:index
]
before_action
:sign_in_validation_admin
,
only:
[
:index
,
:destroy
,
:search
]
def
index
def
index
@cities
=
City
.
all
@cities
=
City
.
all
@industries
=
Industry
.
all
@industries
=
Industry
.
all
@count_apply_job
=
JobApplied
.
count
@apply_job
=
JobApplied
.
includes
(
job: :cities
).
includes
(
job: :industries
)
@user_apply_job
=
JobApplied
.
all
.
order
(
updated_at: :desc
).
page
(
params
[
:page
]).
per
(
Job
::
LIMIT_PAGE
)
@days
=
[
'None'
]
@user_apply_job
=
@apply_job
.
order
(
updated_at: :desc
).
page
(
params
[
:page
]).
per
(
Job
::
LIMIT_PAGE
)
@days
=
[]
(
Admin
::
FIRST_DAY
..
Admin
::
LAST_DAY
).
each
{
|
d
|
@days
<<
d
}
(
Admin
::
FIRST_DAY
..
Admin
::
LAST_DAY
).
each
{
|
d
|
@days
<<
d
}
@months
=
[
'None'
]
@months
=
[]
(
Admin
::
FIRST_MONTH
..
Admin
::
LAST_MONTH
).
each
{
|
m
|
@months
<<
m
}
(
Admin
::
FIRST_MONTH
..
Admin
::
LAST_MONTH
).
each
{
|
m
|
@months
<<
m
}
@years
=
[
'None'
]
@years
=
[]
(
Admin
::
FIRST_YEAR
..
Admin
::
LAST_YEAR
).
each
{
|
y
|
@years
<<
y
}
(
Admin
::
FIRST_YEAR
..
Admin
::
LAST_YEAR
).
each
{
|
y
|
@years
<<
y
}
end
def
search
@cities
=
City
.
all
@industries
=
Industry
.
all
if
params
[
:commit
]
==
'Search'
session
[
:input_email
]
=
params
[
:admin
][
:email
]
session
[
:input_city
]
=
params
[
:admin
][
:city_opt
]
session
[
:input_industry
]
=
params
[
:admin
][
:industry_opt
]
from_day
=
params
[
:admin
][
:from_day
]
from_month
=
params
[
:admin
][
:from_month
]
from_year
=
params
[
:admin
][
:from_year
]
session
[
:from_datetime
]
=
"
#{
from_year
}
/
#{
from_month
}
/
#{
from_day
}
"
params
[
:admin
][
:to_day
].
blank?
?
to_day
=
Admin
::
LAST_DAY
:
to_day
=
params
[
:admin
][
:to_day
]
params
[
:admin
][
:to_month
].
blank?
?
to_month
=
Admin
::
LAST_MONTH
:
to_month
=
params
[
:admin
][
:to_month
]
params
[
:admin
][
:to_year
].
blank?
?
to_year
=
Admin
::
LAST_YEAR
:
to_year
=
params
[
:admin
][
:to_year
]
session
[
:to_datetime
]
=
"
#{
to_year
}
/
#{
to_month
}
/
#{
to_day
}
"
end
@apply_job
=
JobApplied
.
includes
(
job: :cities
).
includes
(
job: :industries
).
email
(
session
[
:input_email
]).
city
(
session
[
:input_city
]).
industry
(
session
[
:input_industry
]).
datetime
(
session
[
:from_datetime
],
session
[
:to_datetime
])
@user_apply_job
=
@apply_job
.
order
(
updated_at: :desc
).
page
(
params
[
:page
]).
per
(
Job
::
LIMIT_PAGE
)
@days
=
[]
(
Admin
::
FIRST_DAY
..
Admin
::
LAST_DAY
).
each
{
|
d
|
@days
<<
d
}
@months
=
[]
(
Admin
::
FIRST_MONTH
..
Admin
::
LAST_MONTH
).
each
{
|
m
|
@months
<<
m
}
@years
=
[]
(
Admin
::
FIRST_YEAR
..
Admin
::
LAST_YEAR
).
each
{
|
y
|
@years
<<
y
}
end
def
download_csv
input_email
=
session
[
:input_email
]
input_city
=
session
[
:input_city
]
input_industry
=
session
[
:input_industry
]
from_datetime
=
session
[
:from_datetime
]
to_datetime
=
session
[
:to_datetime
]
@apply_job
=
JobApplied
.
includes
(
job: :cities
).
includes
(
job: :industries
).
email
(
input_email
).
city
(
input_city
).
industry
(
input_industry
).
datetime
(
from_datetime
,
to_datetime
)
@apply_job
=
JobApplied
.
includes
(
job: :cities
).
includes
(
job: :industries
)
if
@apply_job
.
blank?
@user_apply_job
=
@apply_job
.
order
(
updated_at: :desc
)
csv
=
ExportCsvService
.
new
(
@user_apply_job
,
JobApplied
::
CSV_ATTRIBUTES
)
respond_to
do
|
format
|
format
.
csv
{
send_data
csv
.
perform
,
filename:
"applied-jobs-
#{
Date
.
today
}
.csv"
}
end
end
end
def
new
def
new
...
@@ -37,15 +87,12 @@ class AdminsController < ApplicationController
...
@@ -37,15 +87,12 @@ class AdminsController < ApplicationController
redirect_to
root_path
redirect_to
root_path
end
end
def
download_csv
@user_apply_job
=
JobApplied
.
all
.
order
(
updated_at: :desc
)
respond_to
do
|
format
|
format
.
csv
{
send_data
@user_apply_job
.
to_csv
,
filename:
"test-
#{
Date
.
today
}
.csv"
}
end
end
private
private
def
remove_session
reset_session
end
def
sign_out_current_user
def
sign_out_current_user
sign_out
if
signed_in?
&&
current_user
.
admin
.
nil?
sign_out
if
signed_in?
&&
current_user
.
admin
.
nil?
end
end
...
...
app/models/admin.rb
View file @
b0c6f32d
...
@@ -6,5 +6,5 @@ class Admin < ApplicationRecord
...
@@ -6,5 +6,5 @@ class Admin < ApplicationRecord
LAST_MONTH
=
12
LAST_MONTH
=
12
FIRST_YEAR
=
2015
FIRST_YEAR
=
2015
LAST_YEAR
=
2020
LAST_YEAR
=
Time
.
current
.
year
end
end
app/models/job_applied.rb
View file @
b0c6f32d
require
'csv'
class
JobApplied
<
ApplicationRecord
class
JobApplied
<
ApplicationRecord
before_save
{
self
.
email
=
email
.
downcase
}
before_save
{
self
.
email
=
email
.
downcase
}
mount_uploader
:cv_user
,
UserCvUploader
mount_uploader
:cv_user
,
UserCvUploader
...
@@ -6,22 +5,19 @@ class JobApplied < ApplicationRecord
...
@@ -6,22 +5,19 @@ class JobApplied < ApplicationRecord
belongs_to
:user
belongs_to
:user
belongs_to
:job
belongs_to
:job
scope
:email
,
->
(
email
)
{
where
(
email:
email
)
if
email
.
present?
}
scope
:city
,
->
(
city_id
)
{
where
(
cities:
{
id:
city_id
})
if
city_id
.
present?
}
scope
:industry
,
->
(
industry_id
)
{
where
(
industries:
{
id:
industry_id
})
if
industry_id
.
present?
}
scope
:datetime
,
->
(
from_datetime
,
to_datetime
)
{
where
(
"job_applieds.updated_at BETWEEN ? AND ?"
,
from_datetime
,
to_datetime
)
}
LIMIT_PAGE
=
20
LIMIT_PAGE
=
20
CSV_ATTRIBUTES
=
%w(title name cv_user email updated_at)
.
freeze
validates
:name
,
presence:
true
,
length:
{
maximum:
200
}
validates
:name
,
presence:
true
,
length:
{
maximum:
200
}
VALID_EMAIL_REGEX
=
/\A[\w+\-.]+@[a-z\d\-]+(?:\.[a-z\d\-]+)*\.[a-z]+\z/i
VALID_EMAIL_REGEX
=
/\A[\w+\-.]+@[a-z\d\-]+(?:\.[a-z\d\-]+)*\.[a-z]+\z/i
validates
:email
,
presence:
true
,
length:
{
maximum:
200
},
format:
{
with:
VALID_EMAIL_REGEX
}
validates
:email
,
presence:
true
,
length:
{
maximum:
200
},
format:
{
with:
VALID_EMAIL_REGEX
}
validates
:cv_user
,
presence:
true
validates
:cv_user
,
presence:
true
def
self
.
to_csv
attributes
=
%w{title name cv_user email updated_at}
CSV
.
generate
(
headers:
true
)
do
|
csv
|
csv
<<
attributes
all
.
each
do
|
info_application
|
info_applied
=
info_application
.
attributes
.
values_at
(
*
attributes
)
info_applied
[
0
]
=
info_application
.
job
.
title
csv
<<
info_applied
end
end
end
end
end
app/services/export_csv_service.rb
0 → 100644
View file @
b0c6f32d
require
'csv'
class
ExportCsvService
def
initialize
(
objects
,
attributes
)
@attributes
=
attributes
@objects
=
objects
end
def
perform
CSV
.
generate
do
|
csv
|
csv
<<
attributes
objects
.
each
do
|
object
|
info_applied
=
object
.
attributes
.
values_at
(
*
attributes
)
info_applied
[
0
]
=
object
.
job
.
title
csv
<<
info_applied
end
end
end
private
attr_reader
:objects
,
:attributes
end
app/views/admins/_datetime.html.erb
View file @
b0c6f32d
<div
class=
"row justify-content-lg-center"
>
<div
class=
"row"
>
<div
class=
"text col-1"
>
Date:
</div>
<div
class=
"text col-2"
>
Date:
</div>
<select
class=
"form-control col-1"
>
<div
class=
"col-1"
>
<%=
f
.
select
:from_year
,
options_for_select
(
@years
.
collect
{
|
year
|
year
})
%>
</div>
<%=
@years
.
each
do
|
year
|
%>
<div
class=
"col-1"
>
<%=
f
.
select
:from_month
,
options_for_select
(
@months
.
collect
{
|
month
|
month
})
%>
</div>
<option>
<%=
year
%>
</option>
<div
class=
"col-1"
>
<%=
f
.
select
:from_day
,
options_for_select
(
@days
.
collect
{
|
day
|
day
})
%>
</div>
<%
end
%>
<h4
class=
"col-1 tilde"
>
~
</h4>
</select>
<div
class=
"col-1"
>
<%=
f
.
select
:to_year
,
options_for_select
(
@years
.
collect
{
|
year
|
year
}),
include_blank:
'None'
%>
</div>
<select
class=
"form-control col-1"
>
<div
class=
"col-1"
>
<%=
f
.
select
:to_month
,
options_for_select
(
@months
.
collect
{
|
month
|
month
}),
include_blank:
'None'
%>
</div>
<%=
@months
.
each
do
|
month
|
%>
<div
class=
"col-1"
>
<%=
f
.
select
:to_day
,
options_for_select
(
@days
.
collect
{
|
day
|
day
}),
include_blank:
'None'
%>
</div>
<option>
<%=
month
%>
</option>
<%
end
%>
</select>
<select
class=
"form-control col-1"
>
<%=
@days
.
each
do
|
day
|
%>
<option>
<%=
day
%>
</option>
<%
end
%>
</select>
<h2
class=
"col-1 tilde"
>
~
</h2>
<select
class=
"form-control col-1"
>
<%=
@years
.
each
do
|
year
|
%>
<option>
<%=
year
%>
</option>
<%
end
%>
</select>
<select
class=
"form-control col-1"
>
<%=
@months
.
each
do
|
month
|
%>
<option>
<%=
month
%>
</option>
<%
end
%>
</select>
<select
class=
"form-control col-1"
>
<%=
@days
.
each
do
|
day
|
%>
<option>
<%=
day
%>
</option>
<%
end
%>
</select>
</div>
</div>
app/views/admins/_information.html.erb
View file @
b0c6f32d
<div
class=
"border border-dark rounded"
>
<div
class=
"border border-dark rounded"
>
<div
class=
"job-details"
>
<div
class=
"job-details"
>
<div
class=
"title"
>
Job title:
<div
class=
"title"
>
Job title:
<%=
link_to
job_detail_path
(
info_application
.
id
)
do
%>
<%=
link_to
job_detail_path
(
info_application
.
job
.
id
)
do
%>
<strong>
<%=
info_application
.
job
.
title
%>
</strong>
<strong>
<%=
info_application
.
job
.
title
%>
</strong>
<%
end
%>
<%
end
%>
</div>
</div>
...
...
app/views/admins/_search_condition.html.erb
View file @
b0c6f32d
<div
class=
"search-bar"
>
<div
class=
"search-bar"
>
<%=
form_for
(
:admin
,
url:
admin_search_path
)
do
|
f
|
%>
<div
class=
"search"
>
<div
class=
"search"
>
Email:
<input
class=
"form-control mr-sm-2"
type=
"search"
placeholder=
"Search"
aria-label=
"Search"
>
Email:
<%=
f
.
text_field
:email
,
placeholder:
'Input Email...'
,
class:
'form-control mr-sm-2'
%
>
</div>
</div>
<div
class=
"city-options"
>
<div
class=
"city-options"
>
City:
<div
class=
"row"
>
<select
class=
"form-control"
id=
"exampleFormControlSelect1"
>
<div
class=
"col-2"
>
City:
</div>
<option>
All
</option>
<div
class=
"col-6"
>
<%=
f
.
select
:city_opt
,
options_for_select
(
@cities
.
collect
{
|
city
|
[
city
.
name
,
city
.
id
]
}),
include_blank:
'All'
%>
</div>
<%=
@cities
.
each
do
|
city
|
%>
</div>
<option>
<%=
city
.
name
%>
</option>
<%
end
%>
</select>
</div>
</div>
<div
class=
"industry-options"
>
<div
class=
"industry-options"
>
Industry:
<div
class=
"row"
>
<select
class=
"form-control"
id=
"exampleFormControlSelect1"
>
<div
class=
"col-2"
>
Industry:
</div>
<option>
All
</option>
<div
class=
"col-6"
>
<%=
f
.
select
:industry_opt
,
options_for_select
(
@industries
.
collect
{
|
industry
|
[
industry
.
name
,
industry
.
id
]
}),
include_blank:
'All'
%>
</div>
<%=
@industries
.
each
do
|
industry
|
%>
</div>
<option>
<%=
industry
.
name
%>
</option>
<%
end
%>
</select>
</div>
</div>
<div
class=
"datetime"
>
<div
class=
"datetime"
>
<%=
render
"datetime"
%>
<%=
render
"datetime"
,
f:
f
%>
</div>
</div>
<div
class=
"row"
>
<div
class=
"row"
>
<div
class=
"col-3"
></div>
<div
class=
"col-3"
></div>
<div
class=
"search-btn col-4"
>
<div
class=
"search-btn col-4"
>
<button
class=
"btn btn-primary"
type=
"submit"
>
Search
</button
>
<%=
f
.
submit
'Search'
,
class:
'btn btn-primary'
%
>
</div>
</div>
<div
class=
"download-csv-btn col-4"
>
<div
class=
"download-csv-btn col-4"
>
<%
if
@apply_job
.
count
>
0
%>
<%=
link_to
(
'Download CSV'
,
download_csv_path
(
format: :csv
),
class:
'btn btn-info'
)
%>
<%=
link_to
(
'Download CSV'
,
download_csv_path
(
format: :csv
),
class:
'btn btn-info'
)
%>
<%
else
%>
<strong><i>
Can't download CSV because can't find applications
</i></strong>
<%
end
%>
</div>
</div>
</div>
</div>
<%
end
%>
</div>
</div>
app/views/admins/index.html.erb
View file @
b0c6f32d
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
<div><h1>
Applied Jobs
</h1></div>
<div><h1>
Applied Jobs
</h1></div>
<%=
render
"search_condition"
%>
<%=
render
"search_condition"
%>
<div
class=
"row total-apply-jobs"
>
<div
class=
"row total-apply-jobs"
>
<div
class=
"col-4"
><strong>
Total:
<%=
@
count_apply_job
%>
applications
</strong></div>
<div
class=
"col-4"
><strong>
Total:
<%=
@
apply_job
.
count
%>
applications
</strong></div>
</div>
</div>
<%=
render
"pagination"
%>
<%=
render
"pagination"
%>
<div
class=
"apply-job-list"
>
<div
class=
"apply-job-list"
>
...
...
app/views/admins/search.html.erb
0 → 100644
View file @
b0c6f32d
<%
provide
(
:title
,
'Search Page'
)
%>
<div
class=
"container"
>
<div><h1>
Applied Jobs
</h1></div>
<%=
render
"search_condition"
%>
<div
class=
"row total-apply-jobs"
>
<div
class=
"col-4"
><strong>
Total:
<%=
@apply_job
.
count
%>
applications
</strong></div>
</div>
<%=
render
"pagination"
%>
<div
class=
"apply-job-list"
>
<%=
render
partial:
"information"
,
collection:
@user_apply_job
,
as: :info_application
%>
</div>
<%=
render
"pagination"
%>
</div>
config/routes.rb
View file @
b0c6f32d
...
@@ -37,6 +37,8 @@ Rails.application.routes.draw do
...
@@ -37,6 +37,8 @@ Rails.application.routes.draw do
get
'admin/login'
,
to:
'admins#new'
,
as: :admin_login
get
'admin/login'
,
to:
'admins#new'
,
as: :admin_login
delete
'admin/logout'
,
to:
'admins#destroy'
,
as: :admin_logout
delete
'admin/logout'
,
to:
'admins#destroy'
,
as: :admin_logout
get
'admin/applies'
,
to:
'admins#index'
,
as: :admin_page
get
'admin/applies'
,
to:
'admins#index'
,
as: :admin_page
match
'admin/search'
,
to:
'admins#search'
,
via:
[
:get
,
:post
],
as: :admin_search
get
'download-csv'
,
to:
'admins#download_csv'
,
as: :download_csv
get
'download-csv'
,
to:
'admins#download_csv'
,
as: :download_csv
resources
:applied_jobs
,
only:
[
:new
,
:create
]
resources
:applied_jobs
,
only:
[
:new
,
:create
]
...
...
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