Permalink
Browse files

already helpful - adding compare view

  • Loading branch information...
1 parent a086121 commit 59944157a8b97872f8f63942ba297355a39d36d9 @schacon committed Apr 29, 2010
Showing with 155 additions and 4 deletions.
  1. +1 −0 .gitignore
  2. +61 −0 browser/browser.rb
  3. +7 −0 browser/public/style.css
  4. +19 −0 browser/views/compare.erb
  5. +16 −0 browser/views/groups.erb
  6. +19 −2 browser/views/index.erb
  7. +7 −2 server.rb
  8. +25 −0 snifter.rb
View
1 .gitignore
@@ -0,0 +1 @@
+*.swp
View
61 browser/browser.rb
@@ -63,6 +63,16 @@ def get_line(data)
'fu'
end
+def url_filter(url, id)
+ group = @groups[id]
+ base = @vars[group]['base']
+ act = @vars[group]['act']
+ ver = @vars[group]['ver']
+ url = url.gsub(base, '<span class="base">[base]</span>')
+ url = url.gsub(act, '<span class="act">[act]</span>')
+ url = url.gsub(ver, '<span class="ver">[ver]</span>')
+end
+
get '/' do
@snifter = Snifter.new
@sessions = []
@@ -86,4 +96,55 @@ def get_line(data)
erb :session
end
+post '/create/:name' do
+ name = params[:name]
+ data = params[:sessions]
+ @snifter = Snifter.new
+ @snifter.save_group(name, data)
+end
+
+get '/groups' do
+ @snifter = Snifter.new
+ @groups = @snifter.groups
+ erb :groups
+end
+
+get '/compare' do
+ pp params
+ @snifter = Snifter.new
+ @compare = []
+ @vars = {}
+ @groups = [params[:sessA], params[:sessB]]
+ @groups.each do |grp|
+ sessions = @snifter.get_group(grp)
+ group = []
+ sessions.each do |sess|
+ req, res, time = @snifter.session(sess)
+ req = get_line(req)
+ res = get_line(res)
+
+ # check for variables for better comparison
+ if m = /OPTIONS (.*)/.match(req)
+ @vars[grp] ||= {}
+ @vars[grp]['base'] = m[1].strip
+ end
+ if m = /MKACTIVITY (.*?)\/act\/(.*)/.match(req)
+ @vars[grp] ||= {}
+ @vars[grp]['act'] = m[2].strip
+ end
+ if m = /CHECKOUT (.*?)\/!svn\/bln\/(.*)/.match(req)
+ @vars[grp] ||= {}
+ @vars[grp]['ver'] = m[2].strip
+ end
+ group << [sess, req, res, time]
+ end
+ @compare << group
+ end
+ erb :compare
+end
+
+get '/clear_groups' do
+ Snifter.new.clear_groups
+ "cleared"
+end
View
7 browser/public/style.css
@@ -6,6 +6,9 @@ h1 {
#results { padding: 0 20px; }
.details { font-size: 80%; }
a.session { color: #363; }
+.base { color: #833; }
+.act { color: #383; }
+.ver { color: #338; }
table.headers {
font-family: monospace;
@@ -34,3 +37,7 @@ table.xmlbody tr th {
font-size: 90%;
color: #833;
}
+
+table.compare tr.bottom td {
+ border-bottom: 1px solid #aaa;
+}
View
19 browser/views/compare.erb
@@ -0,0 +1,19 @@
+<h1>Compare</h1>
+
+<!-- Base URL, Activity ID, Version -->
+
+<table class="compare">
+<% @compare[0].each_with_index do |data, i| %>
+ <% sess, req, res, time = data %>
+ <% sessB, reqB, resB, timeB = @compare[1][i] %>
+ <tr>
+ <td rowspan="2"><input type="radio" name="compare"></td>
+ <td><code><%= url_filter req, 0 %></code></td>
+ <td><%= res %></td>
+ </tr>
+ <tr class="bottom">
+ <td><code><%= url_filter reqB, 1 %></code></td>
+ <td><%= resB %></td>
+ </tr>
+<% end %>
+</table>
View
16 browser/views/groups.erb
@@ -0,0 +1,16 @@
+<h1>Groups</h1>
+
+<form action="compare">
+
+<table>
+<% @groups.each do |group| %>
+ <tr>
+ <td><input name="sessA" value="<%= group %>" type="checkbox"/></td>
+ <td><%= group %></td>
+ <td><input name="sessB" value="<%= group %>" type="checkbox"/></td>
+ </tr>
+<% end %>
+</table>
+<input type="submit">
+
+</form>
View
21 browser/views/index.erb
@@ -1,19 +1,24 @@
<table>
<tr><td valign="top">
- <h1>Sessions</h1>
+ <h1>Sessions</h1>
+ <form id="form">
+ <input type="textbox" id="session_name">
+ <input id="create_session" type="button" value="Save Session">
<table>
<% last_time = 0 %>
<% @sessions.each do |sess, req, res, time| %>
<% if (time - last_time) > 3 %>
- <tr><td colspan="2"><hr/></td></tr>
+ <tr><td colspan="3"><hr/></td></tr>
<% end %>
<% last_time = time %>
<tr>
+ <td nowrap><input class="check" value="<%= sess %>" type="checkbox"/></td>
<td nowrap><a class="session" href="#" rel="/sess/<%= sess %>"><%= req %></a></td>
<td nowrap><%= res %></td>
</tr>
<% end %>
</table>
+ </form>
</td><td valign="top">
<h1>Results</h1>
<div id="results"></div>
@@ -26,5 +31,17 @@
$(".session").click(function() {
$("#results").load($(this).attr('rel'))
})
+
+ $("#create_session").click(function() {
+ var sessions = [];
+ var rows = $(this).parents('form').contents().find('input:checked')
+ rows.each(function(i, dom) {
+ sessions.push($(dom).attr("value"))
+ })
+ sess_name = $("#session_name").val()
+ $.post("/create/" + sess_name, {"sessions": sessions}, function() {
+ alert('created')
+ })
+ })
})
</script>
View
9 server.rb
@@ -6,8 +6,13 @@
@snifter = Snifter.new
-listen_port = 5202
-host_to = ['127.0.0.1', 80]
+from_port = ARGV[0].to_i
+to_port = ARGV[1].to_i
+
+puts "Proxying from #{from_port} to #{to_port}"
+
+listen_port = from_port
+host_to = ['127.0.0.1', to_port]
@@sessions = {}
View
25 snifter.rb
@@ -7,6 +7,7 @@ def initialize
end
LIST_ID = 'snifter-conn-list'
+ GROUP_ID = 'snifter-conn-group'
def conn_id(conn)
'snifter-conn-' + conn.to_s
@@ -46,6 +47,30 @@ def current
@redis.lrange LIST_ID, 0, -1;
end
+ def groups
+ @redis.lrange GROUP_ID, 0, -1;
+ end
+
+ def get_group(group)
+ @redis.lrange group, 0, -1;
+ end
+
+ def clear_groups
+ @redis.ltrim GROUP_ID, -1, -1
+ end
+
+ def save_group(name, data)
+ time = rand(1000).to_s
+ name = 'snifter_group_' + name + '_' + time
+
+ @redis.rpush GROUP_ID, name
+
+ data.each do |sess|
+ puts "PUSH #{name} #{sess}"
+ @redis.rpush name, sess
+ end
+ end
+
def session(session)
req = @redis.get session + 'request'
res = @redis.get session + 'response'

0 comments on commit 5994415

Please sign in to comment.