Skip to content
This repository was archived by the owner on Mar 1, 2026. It is now read-only.

Commit ecaec45

Browse files
committed
fix getting the data from the javascript side and changing the naming convention of table
1 parent 9fa1ab5 commit ecaec45

4 files changed

Lines changed: 146 additions & 45 deletions

File tree

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

Lines changed: 127 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,52 +4,149 @@
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'],
10-
columns: [
11-
{ orderable: true, data: 'first_name', visible: false },
12-
{ orderable: true, data: 'last_name', visible: false },
13-
{ orderable: false, data: 'about' },
14-
{ orderable: true, data: 'checked_in' },
15-
{ orderable: false, data: 'actions' },
10+
columns: [{
11+
orderable: true,
12+
data: 'first_name',
13+
visible: false
14+
},
15+
{
16+
orderable: true,
17+
data: 'last_name',
18+
visible: false
19+
},
20+
{
21+
orderable: false,
22+
data: 'about'
23+
},
24+
{
25+
orderable: true,
26+
data: 'checked_in'
27+
},
28+
{
29+
orderable: false,
30+
data: 'actions'
31+
},
1632
],
1733
});
1834

1935
$('.datatable.users').DataTable({
2036
order: [1, 'asc'],
21-
columns: [
22-
{ orderable: true, data: 'id', visible: false },
23-
{ orderable: true, data: 'email' },
24-
{ orderable: true, data: 'role' },
25-
{ orderable: true, data: 'active' },
26-
{ orderable: true, data: 'receive_weekly_report' },
27-
{ orderable: true, data: 'created_at' },
37+
columns: [{
38+
orderable: true,
39+
data: 'id',
40+
visible: false
41+
},
42+
{
43+
orderable: true,
44+
data: 'email'
45+
},
46+
{
47+
orderable: true,
48+
data: 'role'
49+
},
50+
{
51+
orderable: true,
52+
data: 'active'
53+
},
54+
{
55+
orderable: true,
56+
data: 'receive_weekly_report'
57+
},
58+
{
59+
orderable: true,
60+
data: 'created_at'
61+
},
62+
{
63+
orderable: true,
64+
data: 'current_sign_in_at'
65+
},
66+
{
67+
orderable: true,
68+
data: 'last_sign_in_at'
69+
},
70+
{
71+
orderable: true,
72+
data: 'current_sign_in_ip'
73+
},
74+
{
75+
orderable: true,
76+
data: 'last_sign_in_ip'
77+
},
78+
{
79+
orderable: true,
80+
data: 'sign_in_count'
81+
},
2882
],
2983
});
3084

3185
$('.datatable.bulk-messages').DataTable({
3286
order: [4, 'desc'],
33-
columns: [
34-
{ orderable: true, data: 'id', visible: false },
35-
{ orderable: true, data: 'name' },
36-
{ orderable: true, data: 'subject' },
37-
{ orderable: false, data: 'status' },
38-
{ orderable: true, data: 'created_at' },
39-
{ orderable: true, data: 'updated_at', visible: false },
40-
{ orderable: true, data: 'delivered_at' },
87+
columns: [{
88+
orderable: true,
89+
data: 'id',
90+
visible: false
91+
},
92+
{
93+
orderable: true,
94+
data: 'name'
95+
},
96+
{
97+
orderable: true,
98+
data: 'subject'
99+
},
100+
{
101+
orderable: false,
102+
data: 'status'
103+
},
104+
{
105+
orderable: true,
106+
data: 'created_at'
107+
},
108+
{
109+
orderable: true,
110+
data: 'updated_at',
111+
visible: false
112+
},
113+
{
114+
orderable: true,
115+
data: 'delivered_at'
116+
},
41117
],
42118
});
43119

44120
$('.datatable.schools').DataTable({
45-
order: [[5, 'desc'], [4, 'desc']],
46-
columns: [
47-
{ orderable: true, data: 'id', visible: false },
48-
{ orderable: true, data: 'name' },
49-
{ orderable: true, data: 'city' },
50-
{ orderable: true, data: 'state' },
51-
{ orderable: true, data: 'questionnaire_count' },
52-
{ orderable: true, data: 'home_school' },
121+
order: [
122+
[5, 'desc'],
123+
[4, 'desc']
124+
],
125+
columns: [{
126+
orderable: true,
127+
data: 'id',
128+
visible: false
129+
},
130+
{
131+
orderable: true,
132+
data: 'name'
133+
},
134+
{
135+
orderable: true,
136+
data: 'city'
137+
},
138+
{
139+
orderable: true,
140+
data: 'state'
141+
},
142+
{
143+
orderable: true,
144+
data: 'questionnaire_count'
145+
},
146+
{
147+
orderable: true,
148+
data: 'home_school'
149+
},
53150
],
54151
});
55152

app/datatables/admin_datatable.rb

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,20 @@ 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", searchable: false },
15-
last_sign_in_ip: { source: "User.last_sign_in_ip", searchable: false },
16-
sign_in_count: { source: "User.sign_in_count", searchable: false },
12+
current_sign_in_at: { source: "User.current_sign_in_at" },
13+
last_sign_in_at: { source: "User.last_sign_in_at" },
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" },
1717
}
1818
end
1919

2020
private
2121

22+
def ip(record)
23+
return ( record == "::1" ) ? "127.0.0.1" : record
24+
end
25+
2226
def data
2327
records.map do |record|
2428
{
@@ -30,8 +34,8 @@ def data
3034
created_at: display_datetime(record.created_at),
3135
current_sign_in_at: display_datetime(record.current_sign_in_at),
3236
last_sign_in_at: display_datetime(record.last_sign_in_at),
33-
current_sign_in_ip: record.current_sign_in_ip,
34-
last_sign_in_ip: record.last_sign_in_ip,
37+
current_sign_in_ip: ip(record.current_sign_in_ip),
38+
last_sign_in_ip: ip(record.last_sign_in_ip),
3539
sign_in_count: record.sign_in_count,
3640
}
3741
end

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
%th Login access
1212
%th Weekly report
1313
%th Registered on
14-
%th Signed-in Time
15-
%th Last Signed-in Time
14+
%th Signed-in
15+
%th Previous Signed-in
1616
%th IP
1717
%th Last IP
18-
%th Sign In Count
18+
%th Sign-in Count
1919
%tbody

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,23 @@
3737
= display_datetime(@user.created_at)
3838

3939
%p
40-
%b Current Signed-in Time:
40+
%b Signed-in:
4141
= display_datetime(@user.current_sign_in_at)
4242

4343
%p
44-
%b Last Signed-in Time:
44+
%b Previous Signed-in:
4545
= display_datetime(@user.last_sign_in_at)
4646

4747
%p
48-
%b Current Signed-in IP:
48+
%b IP:
4949
= @user.current_sign_in_ip
5050

5151
%p
52-
%b Last Signed-in IP:
52+
%b Last IP:
5353
= @user.last_sign_in_ip
5454

5555
%p
56-
%b Sign in Count:
56+
%b Sign-in Count:
5757
= @user.sign_in_count
5858

5959
.col-lg-6

0 commit comments

Comments
 (0)