Skip to content

Commit f0be0e3

Browse files
authored
Merge pull request #181 from codeRIT/issue_128
feat: Display sign-in info on the admin detail & admin table list
2 parents b2021b3 + 93dde55 commit f0be0e3

File tree

5 files changed

+44
-1
lines changed

5 files changed

+44
-1
lines changed

app/assets/javascripts/manage/lib/setupDataTables.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* See app/views/manage/application/_questionnaire_datatable.html.haml for an example.
55
*/
66

7-
var setupDataTables = function() {
7+
var setupDataTables = function () {
88
$('.datatable.checkins').DataTable({
99
order: [1, 'asc'],
1010
columns: [
@@ -25,6 +25,11 @@ var setupDataTables = function() {
2525
{ orderable: true, data: 'active' },
2626
{ orderable: true, data: 'receive_weekly_report' },
2727
{ orderable: true, data: 'created_at' },
28+
{ orderable: true, data: 'current_sign_in_at' },
29+
{ orderable: true, data: 'last_sign_in_at', visible: false },
30+
{ orderable: true, data: 'current_sign_in_ip', visible: false },
31+
{ orderable: true, data: 'last_sign_in_ip', visible: false },
32+
{ orderable: true, data: 'sign_in_count', visible: false },
2833
],
2934
});
3035

app/datatables/admin_datatable.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ def view_columns
99
active: { source: "User.is_active", searchable: false },
1010
receive_weekly_report: { source: "User.receive_weekly_report", searchable: false },
1111
created_at: { source: "User.created_at", searchable: false },
12+
current_sign_in_at: { source: "User.current_sign_in_at", searchable: false },
13+
last_sign_in_at: { source: "User.last_sign_in_at", searchable: false },
14+
current_sign_in_ip: { source: "User.current_sign_in_ip" },
15+
last_sign_in_ip: { source: "User.last_sign_in_ip" },
16+
sign_in_count: { source: "User.sign_in_count", searchable: false },
1217
}
1318
end
1419

@@ -23,6 +28,11 @@ def data
2328
active: record.is_active ? '<span class="badge badge-secondary">Active</span>'.html_safe : '<span class="badge badge-danger">Inactive<span>'.html_safe,
2429
receive_weekly_report: yes_no_display(record.receive_weekly_report),
2530
created_at: display_datetime(record.created_at),
31+
current_sign_in_at: display_datetime(record.current_sign_in_at),
32+
last_sign_in_at: display_datetime(record.last_sign_in_at),
33+
current_sign_in_ip: record.current_sign_in_ip == "::1" ? "127.0.0.1" : record.current_sign_in_ip,
34+
last_sign_in_ip: record.last_sign_in_ip == "::1" ? "127.0.0.1" : record.last_sign_in_ip,
35+
sign_in_count: record.sign_in_count,
2636
}
2737
end
2838
end

app/helpers/hackathon_manager_helper.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ def acc_status_class(acc_status)
9292
end
9393

9494
def display_datetime(datetime, opts = {})
95+
if datetime.blank?
96+
return ""
97+
end
9598
opts[:relative] = true if opts[:relative].nil?
9699

97100
formatted = ""

app/views/manage/admins/index.html.haml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,9 @@
1111
%th Login access
1212
%th Weekly report
1313
%th Registered on
14+
%th Signed-in on
15+
%th Previous signed-in on
16+
%th Signed-in IP
17+
%th Previous signed-in IP
18+
%th Sign-in count
1419
%tbody

app/views/manage/admins/show.html.haml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,26 @@
3636
%b Registered:
3737
= display_datetime(@user.created_at)
3838

39+
%p
40+
%b Signed-in on:
41+
= display_datetime(@user.current_sign_in_at)
42+
43+
%p
44+
%b Previous signed-in on:
45+
= display_datetime(@user.last_sign_in_at)
46+
47+
%p
48+
%b Signed-in IP:
49+
= @user.current_sign_in_ip == "::1" ? "127.0.0.1" : @user.current_sign_in_ip
50+
51+
%p
52+
%b Previous signed-in IP:
53+
= @user.last_sign_in_ip == "::1" ? "127.0.0.1" : @user.last_sign_in_ip
54+
55+
%p
56+
%b Sign-in count:
57+
= @user.sign_in_count
58+
3959
.col-lg-6
4060
%h4.border-bottom.pb-2.mb-3 Change History
4161
= render "model_history", model: @user

0 commit comments

Comments
 (0)