saw 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b24e7857a6b04db861aa6a2d7619eb49aa32f650
4
- data.tar.gz: f1eb037fbf8a252336b49a19fe6f370f95400893
3
+ metadata.gz: 10a19585b68bf2d75c22c686e95b183acb11aee0
4
+ data.tar.gz: 7666fb2b7ace755a9b36f967e2e74c889b7baa1a
5
5
  SHA512:
6
- metadata.gz: b0f15a0c4da218986cf43bd8c94f61c461ce765d654f43b9f22785d30e16a4774fb9c806481e6a0225a47122a7c2961c38eefa3a29eee861505da7b0f828a492
7
- data.tar.gz: 1a219ea218250fdc53349bcbad50ef99c8b88dbe35b5bb29600bd9e8ee035a92e1db86fb3317326ae7381905006c3e50c9d3545d387471f03b5854bc8fae0a33
6
+ metadata.gz: 5599f1ab6c78d157b133c96ed549db80fd9486714ff05abf868840198480108db0cabfba076650f02f86520d996f3bc342c1c1ffed7ff642bda8eaacc448d395
7
+ data.tar.gz: 6782a3b90894b9b34b9db20c65d6bd4a46ccc672a8e51236923f482efac44922979514436e91fec48f5f369d4d7011e1b9d8fec47bd991179cafa88f4d9d0203
@@ -1,7 +1,6 @@
1
1
  ActiveAdmin.register Visit do
2
2
  menu :parent => "Users"
3
3
  belongs_to :user, :optional => true
4
-
5
4
  actions :index, :show, :destroy
6
5
 
7
6
  index do
@@ -37,20 +36,20 @@ end
37
36
 
38
37
  ActiveAdmin.register Hit do
39
38
  menu false
40
-
41
39
  belongs_to :visit, :optional => true
42
-
43
- actions :index, :show, :destroy
40
+ actions :index, :show
44
41
 
45
42
  index do
46
43
  selectable_column
47
- column "Time", :sortable => :created_at do |resource|
48
- resource.created_at.strftime('%T %Z')
49
- end
44
+ column :after
50
45
  column :note do |resource|
51
46
  resource.note.html_safe
52
47
  end
53
-
54
48
  default_actions
55
49
  end
50
+
51
+ filter :note
52
+ filter :visit, :as => :select, :collection => proc { params[:visit_id] ? Visit.find(params[:visit_id]).user.visits : Visit.scoped }
53
+ filter :url
54
+ filter :created_at
56
55
  end
data/lib/saw.rb CHANGED
@@ -1,13 +1,14 @@
1
1
  require "saw/version"
2
+ require "saw/util.rb"
2
3
  require "saw/visit.rb"
3
4
  require "saw/hit.rb"
4
- require "saw/controller.rb"
5
5
 
6
6
  module Saw
7
7
  class Railtie < ::Rails::Railtie
8
8
  config.after_initialize do
9
- require "saw/visits_controller"
10
9
  require "saw/user_addition"
10
+ require "saw/controller.rb"
11
+ require "saw/visits_controller"
11
12
  end
12
13
  end
13
14
  end
@@ -3,4 +3,20 @@ class Hit < ActiveRecord::Base
3
3
  serialize :json_data, JSON
4
4
  attr_accessible :url, :http_method, :action, :params
5
5
  belongs_to :visit
6
+
7
+ def last_hit
8
+ visit.hits.where(' hits.id < ? ', id).last
9
+ end
10
+
11
+ def next_hit
12
+ visit.hits.where(' hits.id > ? ', id).first
13
+ end
14
+
15
+ def after
16
+ Saw::Util.time_diff visit.starts_with.created_at, created_at
17
+ end
18
+
19
+ def user_visits
20
+ visit.user.visits
21
+ end
6
22
  end
@@ -0,0 +1,40 @@
1
+ module Saw
2
+ module Util
3
+ def self.time_diff dt1, dt2
4
+ diff = nil
5
+ #diff = 1 unless dt1 or dt1.kind_of? DateTime
6
+ #diff ||= 1 unless dt2 or dt2.kind_of? DateTime
7
+ diff ||= dt2 - dt1
8
+
9
+ return '00:00:00' if diff==1
10
+
11
+ str = ''
12
+
13
+ hours_diff = (diff/1.hour).round
14
+ if hours_diff > 0
15
+ str << "#{format('%02d', hours_diff)}"
16
+ diff = diff - hours_diff.hours
17
+ else
18
+ str << "00"
19
+ end
20
+
21
+ minutes_diff = (diff/1.minute).round
22
+ if minutes_diff > 0
23
+ str << ":#{format('%02d', minutes_diff)}"
24
+ diff = diff - minutes_diff.minutes
25
+ else
26
+ str << ":00"
27
+ end
28
+
29
+ seconds_diff = (diff/1.second).round
30
+ if seconds_diff > 0
31
+ str << ":#{format('%02d', seconds_diff)}"
32
+ #diff = diff - seconds_diff.seconds
33
+ else
34
+ str << ":00"
35
+ end
36
+
37
+ str
38
+ end
39
+ end
40
+ end
@@ -1,3 +1,3 @@
1
1
  module Saw
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -1,45 +1,33 @@
1
1
  class Visit < ActiveRecord::Base
2
2
  default_scope order('id')
3
3
 
4
- attr_accessible :user_id, :session_id, :remote_host
4
+ attr_accessible :user_id, :session_id, :remote_host, :user_agent
5
5
 
6
6
  has_many :hits, :dependent => :destroy
7
7
  belongs_to :user
8
8
 
9
9
  def title
10
- "#{lasts} on #{created_at.strftime('%b %-d %Y, %l %P')}"
11
- end
12
-
13
- def lasts
14
- str = ''
10
+ user_name = ''
15
11
 
16
- last_hit = hits.last
17
- diff = last_hit ? last_hit.created_at - created_at : 1
18
-
19
- hours_diff = (diff/1.hour).round
20
- if hours_diff > 0
21
- str << "#{format('%02d', hours_diff)}"
22
- diff = diff - hours_diff.hours
23
- else
24
- str << "00"
12
+ %w(name first_name username email).each do |attr|
13
+ if user.respond_to? attr
14
+ user_name = user.send attr
15
+ break
16
+ end
25
17
  end
26
18
 
27
- minutes_diff = (diff/1.minute).round
28
- if minutes_diff > 0
29
- str << ":#{format('%02d', minutes_diff)}"
30
- diff = diff - minutes_diff.minutes
31
- else
32
- str << ":00"
33
- end
19
+ "#{user_name}(#{lasts}) on #{created_at.strftime('%b %-d %Y, %l %P')}"
20
+ end
34
21
 
35
- seconds_diff = (diff/1.second).round
36
- if seconds_diff > 0
37
- str << ":#{format('%02d', seconds_diff)}"
38
- #diff = diff - seconds_diff.seconds
39
- else
40
- str << ":00"
41
- end
22
+ def starts_with
23
+ hits.first
24
+ end
42
25
 
43
- str
26
+ def ends_with
27
+ hits.last
28
+ end
29
+
30
+ def lasts
31
+ Saw::Util.time_diff created_at, ends_with.created_at if ends_with
44
32
  end
45
33
  end
@@ -3,4 +3,20 @@ class Hit < ActiveRecord::Base
3
3
  serialize :json_data, JSON
4
4
  attr_accessible :url, :http_method, :action, :params
5
5
  belongs_to :visit
6
+
7
+ def last_hit
8
+ visit.hits.where(' hits.id < ? ', id).last
9
+ end
10
+
11
+ def next_hit
12
+ visit.hits.where(' hits.id > ? ', id).first
13
+ end
14
+
15
+ def after
16
+ Saw::Util.time_diff visit.starts_with.created_at, created_at
17
+ end
18
+
19
+ def user_visits
20
+ visit.user.visits
21
+ end
6
22
  end
@@ -1,45 +1,33 @@
1
1
  class Visit < ActiveRecord::Base
2
2
  default_scope order('id')
3
3
 
4
- attr_accessible :user_id, :session_id, :remote_host
4
+ attr_accessible :user_id, :session_id, :remote_host, :user_agent
5
5
 
6
6
  has_many :hits, :dependent => :destroy
7
7
  belongs_to :user
8
8
 
9
9
  def title
10
- "#{lasts} on #{created_at.strftime('%b %-d %Y, %l %P')}"
11
- end
12
-
13
- def lasts
14
- str = ''
10
+ user_name = ''
15
11
 
16
- last_hit = hits.last
17
- diff = last_hit ? last_hit.created_at - created_at : 1
18
-
19
- hours_diff = (diff/1.hour).round
20
- if hours_diff > 0
21
- str << "#{format('%02d', hours_diff)}"
22
- diff = diff - hours_diff.hours
23
- else
24
- str << "00"
12
+ %w(name first_name username email).each do |attr|
13
+ if user.respond_to? attr
14
+ user_name = user.send attr
15
+ break
16
+ end
25
17
  end
26
18
 
27
- minutes_diff = (diff/1.minute).round
28
- if minutes_diff > 0
29
- str << ":#{format('%02d', minutes_diff)}"
30
- diff = diff - minutes_diff.minutes
31
- else
32
- str << ":00"
33
- end
19
+ "#{user_name}(#{lasts}) on #{created_at.strftime('%b %-d %Y, %l %P')}"
20
+ end
34
21
 
35
- seconds_diff = (diff/1.second).round
36
- if seconds_diff > 0
37
- str << ":#{format('%02d', seconds_diff)}"
38
- #diff = diff - seconds_diff.seconds
39
- else
40
- str << ":00"
41
- end
22
+ def starts_with
23
+ hits.first
24
+ end
42
25
 
43
- str
26
+ def ends_with
27
+ hits.last
28
+ end
29
+
30
+ def lasts
31
+ Saw::Util.time_diff created_at, ends_with.created_at if ends_with
44
32
  end
45
33
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: saw
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Amol Pujari
@@ -44,6 +44,7 @@ files:
44
44
  - lib/saw/controller.rb
45
45
  - lib/saw/hit.rb
46
46
  - lib/saw/user_addition.rb
47
+ - lib/saw/util.rb
47
48
  - lib/saw/version.rb
48
49
  - lib/saw/visit.rb
49
50
  - lib/saw/visits_controller.rb