Description:
report ip
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r442:ce576ec8e8c3 - - 2 files changed: 10 inserted, 2 deleted
@@ -17,49 +17,53 | |||||
|
17 | date_and_time = '%Y-%m-%d %H:%M' |
|
17 | date_and_time = '%Y-%m-%d %H:%M' |
|
18 | begin |
|
18 | begin |
|
19 | @since_time = DateTime.strptime(params[:since_datetime],date_and_time) |
|
19 | @since_time = DateTime.strptime(params[:since_datetime],date_and_time) |
|
20 | rescue |
|
20 | rescue |
|
21 | @since_time = DateTime.new(1000,1,1) |
|
21 | @since_time = DateTime.new(1000,1,1) |
|
22 | end |
|
22 | end |
|
23 | begin |
|
23 | begin |
|
24 | @until_time = DateTime.strptime(params[:until_datetime],date_and_time) |
|
24 | @until_time = DateTime.strptime(params[:until_datetime],date_and_time) |
|
25 | rescue |
|
25 | rescue |
|
26 | @until_time = DateTime.new(3000,1,1) |
|
26 | @until_time = DateTime.new(3000,1,1) |
|
27 | end |
|
27 | end |
|
28 |
|
28 | ||
|
29 | User.all.each do |user| |
|
29 | User.all.each do |user| |
|
30 | @logins << { id: user.id, |
|
30 | @logins << { id: user.id, |
|
31 | login: user.login, |
|
31 | login: user.login, |
|
32 | full_name: user.full_name, |
|
32 | full_name: user.full_name, |
|
33 | count: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?", |
|
33 | count: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?", |
|
34 | user.id,@since_time,@until_time) |
|
34 | user.id,@since_time,@until_time) |
|
35 | .count(:id), |
|
35 | .count(:id), |
|
36 | min: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?", |
|
36 | min: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?", |
|
37 | user.id,@since_time,@until_time) |
|
37 | user.id,@since_time,@until_time) |
|
38 | .minimum(:created_at), |
|
38 | .minimum(:created_at), |
|
39 | max: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?", |
|
39 | max: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?", |
|
40 | user.id,@since_time,@until_time) |
|
40 | user.id,@since_time,@until_time) |
|
41 | - .maximum(:created_at) |
|
41 | + .maximum(:created_at), |
|
|
42 | + ip: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?", | ||
|
|
43 | + user.id,@since_time,@until_time) | ||
|
|
44 | + .select(:ip_address).uniq | ||
|
|
45 | + | ||
|
42 | } |
|
46 | } |
|
43 | end |
|
47 | end |
|
44 | end |
|
48 | end |
|
45 |
|
49 | ||
|
46 | def submission_stat |
|
50 | def submission_stat |
|
47 |
|
51 | ||
|
48 | date_and_time = '%Y-%m-%d %H:%M' |
|
52 | date_and_time = '%Y-%m-%d %H:%M' |
|
49 | begin |
|
53 | begin |
|
50 | @since_time = DateTime.strptime(params[:since_datetime],date_and_time) |
|
54 | @since_time = DateTime.strptime(params[:since_datetime],date_and_time) |
|
51 | rescue |
|
55 | rescue |
|
52 | @since_time = DateTime.new(1000,1,1) |
|
56 | @since_time = DateTime.new(1000,1,1) |
|
53 | end |
|
57 | end |
|
54 | begin |
|
58 | begin |
|
55 | @until_time = DateTime.strptime(params[:until_datetime],date_and_time) |
|
59 | @until_time = DateTime.strptime(params[:until_datetime],date_and_time) |
|
56 | rescue |
|
60 | rescue |
|
57 | @until_time = DateTime.new(3000,1,1) |
|
61 | @until_time = DateTime.new(3000,1,1) |
|
58 | end |
|
62 | end |
|
59 |
|
63 | ||
|
60 | @submissions = {} |
|
64 | @submissions = {} |
|
61 |
|
65 | ||
|
62 | User.find_each do |user| |
|
66 | User.find_each do |user| |
|
63 | @submissions[user.id] = { login: user.login, full_name: user.full_name, count: 0, sub: { } } |
|
67 | @submissions[user.id] = { login: user.login, full_name: user.full_name, count: 0, sub: { } } |
|
64 | end |
|
68 | end |
|
65 |
|
69 |
@@ -1,32 +1,36 | |||||
|
1 | - content_for :header do |
|
1 | - content_for :header do |
|
2 | = stylesheet_link_tag 'tablesorter-theme.cafe' |
|
2 | = stylesheet_link_tag 'tablesorter-theme.cafe' |
|
3 | = javascript_include_tag 'new' |
|
3 | = javascript_include_tag 'new' |
|
4 |
|
4 | ||
|
5 | %script{:type=>"text/javascript"} |
|
5 | %script{:type=>"text/javascript"} |
|
6 | $(function () { |
|
6 | $(function () { |
|
7 | $('#since_datetime').datetimepicker({ showButtonPanel: true, dateFormat: "yy-mm-dd", controlType: "slider"} ); |
|
7 | $('#since_datetime').datetimepicker({ showButtonPanel: true, dateFormat: "yy-mm-dd", controlType: "slider"} ); |
|
8 | $('#until_datetime').datetimepicker({ showButtonPanel: true, dateFormat: "yy-mm-dd", controlType: "slider"} ); |
|
8 | $('#until_datetime').datetimepicker({ showButtonPanel: true, dateFormat: "yy-mm-dd", controlType: "slider"} ); |
|
9 | $('#my_table').tablesorter({widthFixed: true, widgets: ['zebra']}); |
|
9 | $('#my_table').tablesorter({widthFixed: true, widgets: ['zebra']}); |
|
10 | }); |
|
10 | }); |
|
11 |
|
11 | ||
|
12 | %h1 Login status |
|
12 | %h1 Login status |
|
13 |
|
13 | ||
|
14 | =render partial: 'report_menu' |
|
14 | =render partial: 'report_menu' |
|
15 | =render partial: 'date_range', locals: {param_text: 'Login date range:', title: 'Query login stat in the range' } |
|
15 | =render partial: 'date_range', locals: {param_text: 'Login date range:', title: 'Query login stat in the range' } |
|
16 |
|
16 | ||
|
17 | %table.tablesorter-cafe#my_table |
|
17 | %table.tablesorter-cafe#my_table |
|
18 | %thead |
|
18 | %thead |
|
19 | %tr |
|
19 | %tr |
|
20 | %th login |
|
20 | %th login |
|
21 | %th full name |
|
21 | %th full name |
|
22 | %th login count |
|
22 | %th login count |
|
23 | %th earliest |
|
23 | %th earliest |
|
24 | %th latest |
|
24 | %th latest |
|
|
25 | + %th IP | ||
|
25 | %tbody |
|
26 | %tbody |
|
26 | - @logins.each do |l| |
|
27 | - @logins.each do |l| |
|
27 | %tr{class: cycle('info-even','info-odd')} |
|
28 | %tr{class: cycle('info-even','info-odd')} |
|
28 | %td= link_to l[:login], controller: 'users', action: 'profile', id: l[:id] |
|
29 | %td= link_to l[:login], controller: 'users', action: 'profile', id: l[:id] |
|
29 | %td= l[:full_name] |
|
30 | %td= l[:full_name] |
|
30 | %td= l[:count] |
|
31 | %td= l[:count] |
|
31 | %td= l[:min] ? l[:min].in_time_zone.strftime('%Y-%m-%d %H:%M') : '' |
|
32 | %td= l[:min] ? l[:min].in_time_zone.strftime('%Y-%m-%d %H:%M') : '' |
|
32 | - %td= l[:max] ? "#{l[:max].in_time_zone.strftime('%Y-%m-%d %H:%M')} (#{time_ago_in_words(l[:max].in_time_zone)} ago)" : '' |
|
33 | + %td= l[:max] ? "#{l[:max].in_time_zone.strftime('%Y-%m-%d %H:%M.%S')} (#{time_ago_in_words(l[:max].in_time_zone)} ago)" : '' |
|
|
34 | + %td | ||
|
|
35 | + - l[:ip].each do |ip| | ||
|
|
36 | + #{ip.ip_address} <br/> |
You need to be logged in to leave comments.
Login now