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
89c5bd8e
Commit
89c5bd8e
authored
Sep 09, 2020
by
Huỳnh Thiên Phước
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
creating export csv
parent
4e5ed11c
Pipeline
#1081
failed with stages
in 0 seconds
Changes
8
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
98 additions
and
26 deletions
+98
-26
app/assets/stylesheets/form_login.scss
+7
-1
app/controllers/admins_controller.rb
+24
-3
app/controllers/users_controller.rb
+5
-0
app/models/admin.rb
+6
-13
app/models/job_applied.rb
+11
-0
app/views/admins/_datetime.html.erb
+34
-0
app/views/admins/_search_condition.html.erb
+10
-9
config/routes.rb
+1
-0
No files found.
app/assets/stylesheets/form_login.scss
View file @
89c5bd8e
...
...
@@ -24,4 +24,10 @@
font-style
:
italic
;
font-size
:
16px
;
}
.tilde
{
color
:
black
;
}
.datetime
{
margin
:
20px
;
padding
:
10px
;
}
app/controllers/admins_controller.rb
View file @
89c5bd8e
class
AdminsController
<
ApplicationController
before_action
:sign_out_current_user
before_action
:sign_in_validation_admin
,
only:
[
:index
,
:destroy
]
def
index
@cities
=
City
.
all
@industries
=
Industry
.
all
@count_apply_job
=
JobApplied
.
count
@user_apply_job
=
JobApplied
.
all
.
order
(
updated_at: :desc
).
page
(
params
[
:page
]).
per
(
Job
::
LIMIT_PAGE
)
@months
=
[[
'None'
,
''
]]
(
1
..
12
).
each
{
|
m
|
@months
<<
[
Date
::
MONTHNAMES
[
m
],
m
]}
binding
.
pry
@days
=
[
'None'
]
(
Admin
::
FIRST_DAY
..
Admin
::
LAST_DAY
).
each
{
|
d
|
@days
<<
d
}
@months
=
[
'None'
]
(
Admin
::
FIRST_MONTH
..
Admin
::
LAST_MONTH
).
each
{
|
m
|
@months
<<
m
}
@years
=
[
'None'
]
(
Admin
::
FIRST_YEAR
..
Admin
::
LAST_YEAR
).
each
{
|
y
|
@years
<<
y
}
end
def
new
...
...
@@ -30,9 +37,23 @@ class AdminsController < ApplicationController
redirect_to
root_path
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
def
sign_out_current_user
sign_out
if
signed_in?
&&
current_user
.
admin
.
nil?
end
def
sign_in_validation_admin
return
if
signed_in?
&&
current_user
.
admin?
store_location
flash
[
:warning
]
=
Settings
.
user
.
warning_signin
redirect_to
admin_login_path
end
end
app/controllers/users_controller.rb
View file @
89c5bd8e
class
UsersController
<
ApplicationController
before_action
:sign_out_admin
before_action
:sign_in_validation
,
only:
[
:update
,
:my_page
,
:my_info
]
def
my_page
...
...
@@ -38,6 +39,10 @@ class UsersController < ApplicationController
private
def
sign_out_admin
sign_out
if
signed_in?
&&
current_user
.
admin?
end
def
sign_in_validation
return
if
signed_in?
store_location
...
...
app/models/admin.rb
View file @
89c5bd8e
class
Admin
<
ApplicationRecord
before_create
:create_remember_token
FIRST_DAY
=
1
LAST_DAY
=
31
def
self
.
new_remember_token
SecureRandom
.
urlsafe_base64
end
FIRST_MONTH
=
1
LAST_MONTH
=
12
def
self
.
digest
(
token
)
Digest
::
SHA1
.
hexdigest
(
token
.
to_s
)
end
private
def
create_remember_token
self
.
remember_token
=
User
.
digest
(
User
.
new_remember_token
)
end
FIRST_YEAR
=
2015
LAST_YEAR
=
2020
end
app/models/job_applied.rb
View file @
89c5bd8e
require
'csv'
class
JobApplied
<
ApplicationRecord
before_save
{
self
.
email
=
email
.
downcase
}
mount_uploader
:cv_user
,
UserCvUploader
...
...
@@ -12,4 +13,14 @@ class JobApplied < ApplicationRecord
validates
:email
,
presence:
true
,
length:
{
maximum:
200
},
format:
{
with:
VALID_EMAIL_REGEX
}
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
|
csv
<<
info_application
.
job
.
attributes
.
values_at
(
attributes
[
0
])
csv
<<
attributes
[(
1
..
4
)].
map
{
|
attr
|
info_application
.
send
(
attr
)
}
end
end
end
end
app/views/admins/_datetime.html.erb
0 → 100644
View file @
89c5bd8e
<div
class=
"row justify-content-lg-center"
>
<div
class=
"text col-1"
>
Date:
</div>
<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>
<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>
app/views/admins/_search_condition.html.erb
View file @
89c5bd8e
...
...
@@ -20,15 +20,16 @@
<%
end
%>
</select>
</div>
<div
class=
"row"
>
<div
class=
"text col-2"
>
Date
</div>
<select
class=
"form-control"
id=
"exampleFormControlSelect1"
>
<%=
@months
.
each
do
|
month
|
%>
<option>
<%=
month
%>
</option>
<%
end
%>
</select>
<div
class=
"datetime"
>
<%=
render
"datetime"
%>
</div>
<div
class=
"search-btn"
>
<button
class=
"btn btn-primary"
type=
"submit"
>
Search
</button>
<div
class=
"row"
>
<div
class=
"col-3"
></div>
<div
class=
"search-btn col-4"
>
<button
class=
"btn btn-primary"
type=
"submit"
>
Search
</button>
</div>
<div
class=
"download-csv-btn col-4"
>
<%=
link_to
(
'Download CSV'
,
download_csv_path
(
format: :csv
),
class:
'btn btn-info'
)
%>
</div>
</div>
</div>
config/routes.rb
View file @
89c5bd8e
...
...
@@ -37,6 +37,7 @@ Rails.application.routes.draw do
get
'admin/login'
,
to:
'admins#new'
,
as: :admin_login
delete
'admin/logout'
,
to:
'admins#destroy'
,
as: :admin_logout
get
'admin/applies'
,
to:
'admins#index'
,
as: :admin_page
get
'download-csv'
,
to:
'admins#download_csv'
,
as: :download_csv
resources
:applied_jobs
,
only:
[
:new
,
:create
]
resources
:reset_passwords
,
only:
[
:edit
,
:update
]
...
...
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