Skip to content

Commit

Permalink
bug fixes + added support for 1.9 ( Tx! Nick )
Browse files Browse the repository at this point in the history
  • Loading branch information
fernand galiana authored and fernand galiana committed Jan 6, 2010
1 parent aba384f commit 4f963bf
Show file tree
Hide file tree
Showing 16 changed files with 58 additions and 37 deletions.
2 changes: 1 addition & 1 deletion lib/app.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'rubygems'
require 'sinatra'
require 'forwardable'
require File.join( File.dirname(__FILE__), 'mongo3.rb' )
require File.expand_path( File.join( File.dirname(__FILE__), 'mongo3.rb' ) )
require 'mongo'
gem 'agnostic-will_paginate'
require 'will_paginate'
Expand Down
6 changes: 4 additions & 2 deletions lib/controllers/collections.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ module Collections
json = params[:search].gsub( /'/, "\"" )
if json.empty?
@query = {}
@sort = {}
@sort = []
session[:query_params] = [@query,@sort]
load_cltn
else
tokens = json.split( "|" )
begin
Expand Down Expand Up @@ -106,7 +108,7 @@ module Collections
# ===========================================================================
helpers do
def load_cltn( page=1 )
query_params = session[:query_params] || [{},[]]
query_params = session[:query_params] || [Hash.new,[]]
if ( !query_params.first or query_params.first.empty?) and ( !query_params.last or query_params.last.empty? )
@query = nil
else
Expand Down
6 changes: 5 additions & 1 deletion lib/controllers/explore.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ module Explore
erb :'explore/explore'
end

get "/fred/:duh" do
"Hello World #{params[:duh]}"
end

# -----------------------------------------------------------------------------
get '/explore/back' do
session[:selected_cols] = nil
Expand Down Expand Up @@ -58,7 +62,7 @@ module Explore
end

# -----------------------------------------------------------------------------
get '/explore/more_data/:path_ids/:path_names/*' do
get '/explore/more_data/:path_ids/:path_names/' do
path_ids = params[:path_ids]
parent_id = path_ids.split("|").last
path_names = params[:path_names]
Expand Down
9 changes: 6 additions & 3 deletions lib/helpers/collection_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ def format_index( pair )
def orientation( value )
return "id" if value.is_a?(Mongo::ObjectID)
case( value.to_i )
when Mongo::ASCENDING : "asc"
when Mongo::DESCENDING : "desc"
else "n/a"
when Mongo::ASCENDING
"asc"
when Mongo::DESCENDING
"desc"
else
"n/a"
end
end

Expand Down
6 changes: 3 additions & 3 deletions lib/helpers/crumb_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ def crumbs_from_path( path_ids, path_names )
@crumbs = []
count = 0
path_name_tokens.each do |crumb|
@crumbs << [crumb, "/explore/center/#{path_name_tokens[0..count].join( "|" )}/#{path_id_tokens[0..count].join( "|") }"]
@crumbs << [crumb, "/explore/center/#{CGI.escape(path_name_tokens[0..count].join( "|" ))}/#{CGI.escape(path_id_tokens[0..count].join( "|")) }"]
count += 1
end
session[:crumbs] = @crumbs
end

def pop_crumb!( path_ids, path_names )
path = "/explore/center/#{path_ids}/#{path_names}"
path = "/explore/center/#{CGI.escape(path_ids)}/#{CGI.escape(path_names)}"
level = 0
range = nil
@crumbs.each do |pair|
Expand All @@ -38,7 +38,7 @@ def add_crumb( title, url )
titles = @crumbs.map{ |p| p.first }
unless titles.include?( title )
@crumbs.pop if @crumbs.size == 3
@crumbs << [title, url]
@crumbs << [title, CGI.escape(url)]
session[:crumbs] = @crumbs
end
end
Expand Down
9 changes: 6 additions & 3 deletions lib/helpers/database_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ def db_title

def context_for( paths )
case paths.size
when 2 : "zone"
when 3 : "database"
else "collection"
when 2
"zone"
when 3
"database"
else
"collection"
end
end
end
Expand Down
9 changes: 6 additions & 3 deletions lib/helpers/explore_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ def legend_title( path )
def path_type( path )
tokens = path.split( "|" )
case tokens.length
when 1 : "zone"
when 2 : "database"
else "collection"
when 1
"zone"
when 2
"database"
else
"collection"
end
end

Expand Down
9 changes: 6 additions & 3 deletions lib/helpers/paths_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ def back_paths!
def title_for( path_names )
tokens = path_names.split( "|" )
buff = case tokens.size
when 2 : "zone"
when 3 : "database"
else "collection"
when 2
"zone"
when 3
"database"
else
"collection"
end
db = tokens.size > 3 ? "<span class=\"ctx\">#{tokens[2]}</span>." : ""
"<p class=\"ctx\" style=\"text-align:center;font-size:0.8em\">#{db}#{tokens.last}</p>"
Expand Down
2 changes: 1 addition & 1 deletion lib/mongo3.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Mongo3

# :stopdoc:
VERSION = '0.0.7' unless defined? Mongo3::VERSION
VERSION = '0.0.8' unless defined? Mongo3::VERSION
LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR unless defined? Mongo3::LIBPATH
PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR unless defined? Mongo3::LIBPATH
# :startdoc:
Expand Down
8 changes: 5 additions & 3 deletions lib/mongo3/connection.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'yaml'

# BOZO !! Time to refact no?
module Mongo3
class Connection
Expand Down Expand Up @@ -186,7 +188,7 @@ def paginate_cltn( path_names, query_params=[{},[]], page=1, per_page=10 )

list = WillPaginate::Collection.create( page, per_page, count ) do |pager|
offset = (page-1)*per_page
sort = query_params.last.empty? ? [ ['_id', Mongo::DESCENDING] ] : query_params.last
sort = query_params.last.empty? ? [ ['_id', Mongo::DESCENDING] ] : query_params.last
results = cltn.find( query_params.first,
:sort => sort,
:skip => offset,
Expand Down Expand Up @@ -224,7 +226,7 @@ def build_tree
host, port = master.split( ":" )
master_zone = zone_for( host, port )
next unless master_zone
master_node = root.find( "home|#{master_zone}")
master_node = root.find( master_zone )
if master_node
master_node.mark_master!
master_node << node
Expand Down Expand Up @@ -281,7 +283,7 @@ def build_partial_tree( path_names )
host, port = master.split( ":" )
master_zone = zone_for( host, port )
next unless master_zone
master_node = root.find( "home|#{master_zone}")
master_node = root.find( master_zone )
if master_node
master_node.mark_master!
master_node << node
Expand Down
2 changes: 1 addition & 1 deletion lib/views/explore/_node_info.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<% unless zone_path?( session[:path_names] ) %>
<img id="<%=count%>" rel="div#confirm_drop" class="drop" href="/explore/database/<%=node.oid%>/<%=node.name%>/drop" title="drop <%=legend%>..." src="/images/delete.png"/>
<% end %>
<p rel="div#details" href="/explore/show/<%=node.data[:path_ids]%>/<%=node.data[:path_names]%>" class="info">
<p rel="div#details" href="/explore/show/<%=CGI.escape(node.data[:path_ids])%>/<%=CGI.escape(node.data[:path_names])%>" class="info">
<%=truncate(node.name, 30)%>
</p>
</div>
Expand Down
4 changes: 2 additions & 2 deletions lib/views/explore/explore.erb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
{
Log.write( "fetching new data..." );
var url = "/explore/more_data/";
url += node.data.path_ids + "/" + node.data.path_names + "/";
url += escape(node.data.path_ids) + "/" + escape(node.data.path_names) + "/";
$.ajax( {
dataType: 'script',
type: 'GET',
Expand Down Expand Up @@ -137,7 +137,7 @@
onBeforePlotLine: function(adj) {
var nodeTo = adj.nodeTo;
var nodeFrom = adj.nodeFrom;
if( nodeFrom.data.slave && nodeTo.data.master )
if( (nodeFrom.data.slave && nodeTo.data.master) || (nodeFrom.data.master && nodeTo.data.slave) )
{
adj.data.$lineWidth = 3;
adj.data.$color = "#f00";
Expand Down
2 changes: 1 addition & 1 deletion spec/landscape.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
test:
host: localhost
port: 27017
port: 12345
17 changes: 9 additions & 8 deletions spec/mongo3/connection_spec.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
require File.join(File.dirname(__FILE__), %w[.. spec_helper])
require File.expand_path( File.join( File.dirname(__FILE__), %w[.. spec_helper] ) )
require 'ostruct'
require 'mongo'

describe Mongo3::Connection do

before( :all ) do
@con = Mongo::Connection.new( 'localhost', 27017 )
@db = @con.db( 'mongo3_test_db', :strict => true )
@con = Mongo::Connection.new( 'localhost', 12345 )
@db = @con.db( 'mongo3_test_db', :strict => true )
@mongo3 = Mongo3::Connection.new( File.join(File.dirname(__FILE__), %w[.. landscape.yml]) )
end

Expand Down Expand Up @@ -35,6 +35,7 @@
it "should clear out a cltn correctly" do
@mongo3.clear_cltn( "home|test|mongo3_test_db|test1_cltn" )
@db['test1_cltn'].count.should == 0
@db['test2_cltn'].count.should == 10
end

it "should delete a row correctly" do
Expand All @@ -60,7 +61,7 @@

test.should_not be_nil
test['host'].should == 'localhost'
test['port'].should == 27017
test['port'].should == 12345
end

it "should build a tree correctly" do
Expand All @@ -87,9 +88,9 @@

it "should pull db info correctly" do
info = @mongo3.show( "home|test|mongo3_test_db" )
info.size.should == 7
info[:collections].size.should == 4
info[:title].should == "mongo3_test_db"
info.size.should == 7
info[:collections].should == 2
info[:title].should == "mongo3_test_db"
end

it "should pull cltn info correctly" do
Expand Down Expand Up @@ -119,7 +120,7 @@

it "should build a partial tree correctly" do
root = @mongo3.build_partial_tree( "home|test|mongo3_test_db" )
root.find( "test_2" ).children.should have(0).items
root.find( "test_0" ).children.should have(2).items
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/mongo3/node_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require File.join(File.dirname(__FILE__), %w[.. spec_helper])
require File.expand_path( File.join( File.dirname(__FILE__), %w[.. spec_helper] ) )
require 'ostruct'

describe Mongo3::Node do
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
gem 'agnostic-will_paginate'
require 'will_paginate/collection'

require File.join(File.dirname(__FILE__), %w[.. lib mongo3])
require File.expand_path( File.join( File.dirname(__FILE__), %w[.. lib mongo3] ) )

Spec::Runner.configure do |config|
end

0 comments on commit 4f963bf

Please sign in to comment.