Skip to content

Commit 05ea8fa

Browse files
committed
V1.0.1 - added support for embedded docs. improved nav
1 parent a182b70 commit 05ea8fa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+3485
-183
lines changed

Diff for: HISTORY

+10-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,13 @@
2626
o Added user administration - should be able to crub users on zone now
2727
o Added mongo based session store using mongo_rack. (Per Kyle's suggestion! ). This is now the default session store.
2828
You can alternatively still use memcache ( see README for instructions )
29-
o Bug fixes and some cleanup
29+
o Bug fixes and some cleanup
30+
31+
0.0.8 - Bug fixes and clean up
32+
33+
0.0.9 - Bug fixes and clean up
34+
35+
0.1.0 - Big improvements!
36+
o Added better support for docs and embedded docs.
37+
o Change navigation to make it easier to drilldown.
38+
o More tests

Diff for: README.rdoc

+2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@
3434
* CRUD on dbs, collections, indexes [done]
3535
* Administer users [done]
3636
* Collection rename
37+
* Database creation
3738
* Manage logs
3839
* Support for shards and replication
40+
* Add support for drilling down array and embedded documents [done]
3941

4042
== DEPENDENCIES
4143

Diff for: bin/mongo3

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Main {
4444
end
4545

4646
# default port
47-
def default_port() 6666; end
47+
def default_port() 6663; end
4848

4949
# sleepy time...
5050
def sleep_time() 3; end
@@ -74,4 +74,4 @@ Main {
7474
end
7575
opts
7676
end
77-
}
77+
}

Diff for: lib/app.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# Configurations
1515

1616
configure :production do
17-
set :logging, false
17+
set :logging, true
1818
end
1919

2020
configure do

Diff for: lib/controllers/collections.rb

+2-10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
module Collections
44

55
# ---------------------------------------------------------------------------
6+
# BOZO - Move to indexes ctrl
67
post "/collections/create_index/" do
78
json = params[:index].gsub( /'/, "\"" )
89
tokens = json.split( "|" )
@@ -34,7 +35,7 @@ module Collections
3435
# ---------------------------------------------------------------------------
3536
# Paginate on a collection
3637
get "/collections/:page" do
37-
@back_url = "/explore/back"
38+
@back_url = "/databases/1"
3839
@page = params[:page].to_i || 1
3940

4041
@indexes = options.connection.indexes_for( session[:path_names] )
@@ -46,9 +47,6 @@ module Collections
4647

4748
# ---------------------------------------------------------------------------
4849
post "/collections/refresh/:page/" do
49-
selected_cols = params[:cols].keys.sort
50-
session[:selected_cols] = selected_cols
51-
5250
load_cltn( params[:page].to_i )
5351

5452
erb :'collections/update.js', :layout => false
@@ -119,12 +117,6 @@ def load_cltn( page=1 )
119117
path_names = session[:path_names]
120118

121119
@cltn = options.connection.paginate_cltn( path_names, query_params, @page, 15 )
122-
@cols = []
123-
@selected_cols = []
124-
unless @cltn.empty?
125-
@cols = @cltn.first.keys.sort
126-
@selected_cols = session[:selected_cols] || @cols[0...5]
127-
end
128120
end
129121
end
130122
end

Diff for: lib/controllers/databases.rb

+13-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,19 @@ module Databases
44
get "/databases/:page" do
55
page = params[:page].to_i || 1
66
path_names = session[:path_names]
7-
7+
tokens = path_names.split( "|" )
8+
9+
# Could be we have a cltn path. if so adjust for it
10+
if tokens.size > 3
11+
tokens.pop
12+
session[:path_names] = tokens.join( "|")
13+
path_names = session[:path_names]
14+
path_ids = session[:path_ids].split( "|" )
15+
path_ids.pop
16+
session[:path_ids] = path_ids.join( "|" )
17+
end
18+
19+
puts "DB PATH #{path_names.inspect}"
820
@cltns = options.connection.paginate_db( path_names, page, 10 )
921
@back_url = "/explore/back"
1022

Diff for: lib/controllers/explore.rb

+19-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module Explore
77
@node_id = params[:db_id]
88
db_name = params[:db_name].gsub( /\(\d+\)/, '' )
99

10-
options.connection.drop_database( session[:path_names], db_name )
10+
options.connection.drop_db( "#{session[:path_names]}|#{db_name}" )
1111

1212
flash_it!( :info, "Database `#{db_name} was dropped successfully!" )
1313

@@ -43,14 +43,16 @@ module Explore
4343

4444
crumbs_from_path( path_ids, path_names )
4545

46+
puts "PATHS #{path_names} -- #{@node_id}"
4647
@root = options.connection.build_partial_tree( path_names )
48+
Mongo3::Node.dump( @root )
4749
@nodes = @root.find( @node_id ).children
4850

4951
erb :'explore/explore'
5052
end
5153

5254
# -----------------------------------------------------------------------------
53-
get '/explore/show/:path_ids/:path_names' do
55+
get '/explore/info/:path_ids/:path_names' do
5456
path_ids = params[:path_ids]
5557
path_names = params[:path_names]
5658

@@ -78,6 +80,21 @@ module Explore
7880
erb :'explore/more_data_js', :layout => false
7981
end
8082

83+
# ---------------------------------------------------------------------------
84+
get "/explore/show/:path_ids/:path_names" do
85+
path_ids = params[:path_ids]
86+
path_names = params[:path_names]
87+
88+
# crumbs_from_path( path_ids, path_names )
89+
update_paths!( path_ids, path_names )
90+
91+
if cltn_path?( path_ids )
92+
erb :'explore/load_collection.js', :layout => false
93+
else
94+
erb :'explore/load_database.js', :layout => false
95+
end
96+
end
97+
8198
# -----------------------------------------------------------------------------
8299
get '/explore/update_crumb/:path_ids/:path_names' do
83100
path_ids = params[:path_ids]

Diff for: lib/helpers/collection_helper.rb

+32
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,38 @@ module CollectionHelper
1515
helpers do
1616
include WillPaginate::ViewHelpers::Base
1717

18+
def format_nodes( item, col )
19+
buff = []
20+
_format_nodes( buff, item, col )
21+
buff.join( "\n" )
22+
end
23+
24+
def _format_nodes( buff, item, col=nil )
25+
if item.is_a?( Array )
26+
buff << "<li><ins style=\"background-position:-48px -16px\"></ins><span>#{col} <span class=\"meta\" style=\"color:#c1c1c1\">(#{item.size})</span></span>"
27+
return buff if item.empty?
28+
buff << "<ul>"
29+
count = 0
30+
item.each do |element|
31+
_format_nodes( buff, element )
32+
count += 1
33+
end
34+
buff << "</ul>"
35+
buff << "</li>"
36+
elsif item.is_a?( Hash )
37+
buff << "<li><ins style=\"background-position:-48px -16px\"></ins><span>#{col} (#{item.size})</span>"
38+
return buff if item.empty?
39+
buff << "<ul>"
40+
item.each_pair do |key,val|
41+
_format_nodes( buff, val, key )
42+
end
43+
buff << "</ul>"
44+
buff << "</li>"
45+
else
46+
buff << "<li><ins></ins><span title=\"#{item.to_s}\">#{truncate(item.to_s,90)} <span class=\"meta\" style=\"color:#c1c1c1\">#{col ? "[#{col} - #{item.class}]" : "[#{item.class}]"}</span></span></li>"
47+
end
48+
end
49+
1850
# Attempts to format an attribute to some human readable format
1951
def format_value( value )
2052
if value.is_a?( Fixnum)

Diff for: lib/helpers/explore_helper.rb

-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
module ExploreHelper
22

33
helpers do
4-
5-
# looking at zone path?
6-
def zone_path?( path )
7-
path.split( "|" ).size == 1
8-
end
94

105
# compute legend title
116
def legend_title( path )

Diff for: lib/helpers/main_helper.rb

+5
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ def display_info( info )
6161
end
6262

6363
def partial( page, options={} )
64+
if object = options.delete(:object)
65+
template = page.to_s.split("/").last
66+
options.merge!( :locals => { template.to_sym => object } )
67+
end
68+
6469
if page.to_s.index( /\// )
6570
page = page.to_s.gsub( /\//, '/_' )
6671
else

Diff for: lib/helpers/paths_helper.rb

+15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
module PathHelper
22
helpers do
33

4+
# looking at zone path?
5+
def zone_path?( path )
6+
path.split( "|" ).size == 1
7+
end
8+
9+
# looking at db path?
10+
def db_path?( path )
11+
path.split( "|" ).size == 3
12+
end
13+
14+
# looking at cltn path?
15+
def cltn_path?( path )
16+
path.split( "|" ).size == 4
17+
end
18+
419
def reset_paths!
520
session[:path_ids] = "home"
621
session[:path_names] = "home"

Diff for: lib/mongo3.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Mongo3
22

33
# :stopdoc:
4-
VERSION = '0.0.9' unless defined? Mongo3::VERSION
4+
VERSION = '0.1.0' unless defined? Mongo3::VERSION
55
LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR unless defined? Mongo3::LIBPATH
66
PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR unless defined? Mongo3::PATH
77
# :startdoc:

Diff for: lib/mongo3/connection.rb

+39-24
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
11
require 'yaml'
22

33
# BOZO !! Time to refact no?
4+
# TODO !! Arg check and errors
5+
# TODO !! Add logging
46
module Mongo3
57
class Connection
68

79
def initialize( config_file )
810
@config_file = config_file
911
end
1012

11-
# drop a database using context and db name
12-
def drop_database( path_names, db_name )
13-
path_name_tokens = path_names.split( "|" )
14-
zone = path_name_tokens[1]
15-
connect_for( zone ) do |con|
16-
con.drop_database( db_name )
17-
end
18-
end
19-
13+
# drop a db using a db path
2014
def drop_db( path_names )
2115
path_name_tokens = path_names.split( "|" )
2216
zone = path_name_tokens[1]
@@ -42,12 +36,12 @@ def indexes_for( path_names )
4236

4337
def drop_index( path_names, index )
4438
path_name_tokens = path_names.split( "|" )
45-
zone = path_name_tokens[1]
39+
zone = path_name_tokens[1]
4640
connect_for( zone ) do |con|
4741
cltn_name = path_name_tokens.pop
4842
db_name = path_name_tokens.pop
4943
db = con.db( db_name )
50-
cltn = db[cltn_name]
44+
cltn = db[cltn_name]
5145
cltn.drop_index( index )
5246
end
5347
end
@@ -84,7 +78,7 @@ def clear_cltn( path_names )
8478
db_name = path_name_tokens.pop
8579
db = con.db( db_name )
8680
cltn = db[cltn_name]
87-
cltn.remove
81+
cltn.remove( {} )
8882
end
8983
end
9084

@@ -96,7 +90,7 @@ def delete_row( path_names, id )
9690
db_name = path_name_tokens.pop
9791
db = con.db( db_name )
9892
cltn = db[cltn_name]
99-
cltn.remove( {:_id => Mongo::ObjectID.from_string(id) } )
93+
res = cltn.remove( {:_id => Mongo::ObjectID.from_string(id) } )
10094
end
10195
end
10296

@@ -150,7 +144,7 @@ def show( path_names )
150144
end
151145

152146
def paginate_db( path_names, page=1, per_page=10 )
153-
path_name_tokens = path_names.split( "|" )
147+
path_name_tokens = path_names.split( "|" )
154148
zone = path_name_tokens[1]
155149
list = nil
156150
connect_for( zone ) do |con|
@@ -189,7 +183,15 @@ def paginate_cltn( path_names, query_params=[{},[]], page=1, per_page=10 )
189183
list = WillPaginate::Collection.create( page, per_page, count ) do |pager|
190184
offset = (page-1)*per_page
191185
sort = query_params.last.empty? ? [ ['_id', Mongo::DESCENDING] ] : query_params.last
192-
results = cltn.find( query_params.first,
186+
query = query_params.first
187+
188+
# Scan for regexes...
189+
query.each_pair do |k,v|
190+
if v.is_a?( String ) and v.index( /^\// )
191+
query[k] = Regexp.new( v.gsub( "/", '' ) )
192+
end
193+
end
194+
results = cltn.find( query,
193195
:sort => sort,
194196
:skip => offset,
195197
:limit => per_page ).to_a
@@ -398,14 +400,23 @@ def database_names( con )
398400
# Connects to mongo given an zone
399401
def connect_for( zone, &block )
400402
info = landscape[zone]
401-
# puts ">>> Connecting for #{zone} -- #{info['host']}-#{info['port']}"
402-
con = Mongo::Connection.new( info['host'], info['port'], { :slave_ok => true } )
403+
raise "Unable to find zone info in config file for zone `#{zone}" unless info
404+
raise "Check your config. Unable to find `host information" unless info['host']
405+
raise "Check your config. Unable to find `port information" unless info['port']
406+
407+
begin
408+
con = Mongo::Connection.new( info['host'], info['port'], { :slave_ok => true } )
403409

404-
if info['user'] and info['password']
405-
con.db( 'admin' ).authenticate( info['user'], info['password'] )
410+
if info['user'] and info['password']
411+
con.db( 'admin' ).authenticate( info['user'], info['password'] )
412+
end
413+
yield con
414+
con.close()
415+
rescue => boom
416+
# puts boom
417+
# puts boom.backtrace.each {|l| puts l }
418+
raise "MongoDB connection failed for `#{info['host'].inspect}:#{info['port'].inspect}"
406419
end
407-
yield con
408-
con.close()
409420
end
410421

411422
# db request occurs within dist 2
@@ -461,10 +472,14 @@ def slave_zone?( tokens )
461472
# Initialize the mongo installation landscape
462473
def config
463474
unless @config
464-
@config = YAML.load_file( @config_file )
475+
begin
476+
@config = YAML.load_file( @config_file )
477+
rescue => boom
478+
@config = nil
479+
raise "Unable to grok yaml landscape file. #{boom}"
480+
end
465481
end
466482
@config
467-
end
468-
483+
end
469484
end
470485
end

0 commit comments

Comments
 (0)