Permalink
Browse files

V1.0.1 - added support for embedded docs. improved nav

  • Loading branch information...
derailed committed Jan 24, 2010
1 parent a182b70 commit 05ea8fa008c6a1377751a3043915187f14e4d75f
Showing with 3,485 additions and 183 deletions.
  1. +10 −1 HISTORY
  2. +2 −0 README.rdoc
  3. +2 −2 bin/mongo3
  4. +1 −1 lib/app.rb
  5. +2 −10 lib/controllers/collections.rb
  6. +13 −1 lib/controllers/databases.rb
  7. +19 −2 lib/controllers/explore.rb
  8. +32 −0 lib/helpers/collection_helper.rb
  9. +0 −5 lib/helpers/explore_helper.rb
  10. +5 −0 lib/helpers/main_helper.rb
  11. +15 −0 lib/helpers/paths_helper.rb
  12. +1 −1 lib/mongo3.rb
  13. +39 −24 lib/mongo3/connection.rb
  14. +10 −4 lib/mongo3/user.rb
  15. +24 −8 lib/mongo3/zone.rb
  16. BIN lib/public/images/favicon.png
  17. BIN lib/public/images/information.png
  18. BIN lib/public/images/tree/Thumbs.db
  19. BIN lib/public/images/tree/array.png
  20. BIN lib/public/images/tree/arrow_refresh.png
  21. BIN lib/public/images/tree/collapsable-last.gif
  22. BIN lib/public/images/tree/collapsable.gif
  23. BIN lib/public/images/tree/collection.png
  24. BIN lib/public/images/tree/cross.png
  25. BIN lib/public/images/tree/disk.png
  26. BIN lib/public/images/tree/expandable-last.gif
  27. BIN lib/public/images/tree/expandable-last.png
  28. BIN lib/public/images/tree/expandable.gif
  29. BIN lib/public/images/tree/expandable.png
  30. BIN lib/public/images/tree/folder_add.png
  31. BIN lib/public/images/tree/folder_delete.png
  32. BIN lib/public/images/tree/folder_edit.png
  33. BIN lib/public/images/tree/icons.png
  34. BIN lib/public/images/tree/leaf-last.gif
  35. BIN lib/public/images/tree/leaf-last.png
  36. BIN lib/public/images/tree/leaf.gif
  37. BIN lib/public/images/tree/leaf.png
  38. BIN lib/public/images/tree/line_bg.gif
  39. BIN lib/public/images/tree/line_bg_over.gif
  40. BIN lib/public/images/tree/line_bg_over_last.gif
  41. BIN lib/public/images/tree/minus.gif
  42. BIN lib/public/images/tree/page_add.png
  43. BIN lib/public/images/tree/page_delete.png
  44. BIN lib/public/images/tree/page_edit.png
  45. BIN lib/public/images/tree/plus.gif
  46. BIN lib/public/images/tree/root.gif
  47. BIN lib/public/images/tree/spacer.gif
  48. BIN lib/public/images/tree/spinner.gif
  49. BIN lib/public/images/tree/tree_line.gif
  50. +451 −0 lib/public/javascripts/jquery.simple.tree.js
  51. +6 −0 lib/public/javascripts/jquery.tiptip.min.js
  52. +1 −0 lib/public/javascripts/jquery.tree.min.js
  53. +2,058 −0 lib/public/javascripts/jstree/jquery.tree.js
  54. BIN lib/public/javascripts/themes/mongo3/bg.jpg
  55. BIN lib/public/javascripts/themes/mongo3/dot_for_ie.gif
  56. BIN lib/public/javascripts/themes/mongo3/icons.png
  57. +39 −0 lib/public/javascripts/themes/mongo3/style.css
  58. BIN lib/public/javascripts/themes/mongo3/throbber.gif
  59. +194 −61 lib/public/stylesheets/mongo3.css
  60. +1 −1 lib/views/collections/_fields_form.erb
  61. +1 −1 lib/views/collections/_index_form.erb
  62. +40 −15 lib/views/collections/_index_rows.erb
  63. 0 lib/views/collections/_nodes.erb
  64. +4 −4 lib/views/collections/_results.erb
  65. +2 −2 lib/views/collections/{_rows.erb → _rows_table.erb}
  66. +81 −0 lib/views/collections/_rows_tree.erb
  67. +1 −1 lib/views/collections/_search_form.erb
  68. +20 −0 lib/views/collections/blee.erb
  69. +1 −1 lib/views/collections/list.erb
  70. +1 −1 lib/views/collections/update.js.erb
  71. +9 −7 lib/views/databases/_results.erb
  72. +21 −4 lib/views/explore/_node_info.erb
  73. +11 −1 lib/views/explore/explore.erb
  74. +1 −0 lib/views/explore/load_collection.js.erb
  75. +1 −0 lib/views/explore/load_database.js.erb
  76. +13 −7 lib/views/layout.erb
  77. +2 −2 lib/views/users/_results.erb
  78. +20 −0 spec/configs/crap.yml
  79. +4 −0 spec/configs/hosed.yml
  80. +9 −0 spec/configs/landscape.yml
  81. +0 −3 spec/landscape.yml
  82. +105 −12 spec/mongo3/connection_spec.rb
  83. +38 −0 spec/mongo3/node_spec.rb
  84. +72 −0 spec/mongo3/user_spec.rb
  85. +69 −0 spec/mongo3/zone_spec.rb
  86. +20 −0 spec/mongo3_spec.rb
  87. +13 −0 spec/spec_helper.rb
  88. +1 −1 tasks/setup.rb
View
11 HISTORY
@@ -26,4 +26,13 @@
o Added user administration - should be able to crub users on zone now
o Added mongo based session store using mongo_rack. (Per Kyle's suggestion! ). This is now the default session store.
You can alternatively still use memcache ( see README for instructions )
- o Bug fixes and some cleanup
+ o Bug fixes and some cleanup
+
+0.0.8 - Bug fixes and clean up
+
+0.0.9 - Bug fixes and clean up
+
+0.1.0 - Big improvements!
+ o Added better support for docs and embedded docs.
+ o Change navigation to make it easier to drilldown.
+ o More tests
View
@@ -34,8 +34,10 @@
* CRUD on dbs, collections, indexes [done]
* Administer users [done]
* Collection rename
+* Database creation
* Manage logs
* Support for shards and replication
+* Add support for drilling down array and embedded documents [done]
== DEPENDENCIES
View
@@ -44,7 +44,7 @@ Main {
end
# default port
- def default_port() 6666; end
+ def default_port() 6663; end
# sleepy time...
def sleep_time() 3; end
@@ -74,4 +74,4 @@ Main {
end
opts
end
-}
+}
View
@@ -14,7 +14,7 @@
# Configurations
configure :production do
- set :logging, false
+ set :logging, true
end
configure do
@@ -3,6 +3,7 @@
module Collections
# ---------------------------------------------------------------------------
+ # BOZO - Move to indexes ctrl
post "/collections/create_index/" do
json = params[:index].gsub( /'/, "\"" )
tokens = json.split( "|" )
@@ -34,7 +35,7 @@ module Collections
# ---------------------------------------------------------------------------
# Paginate on a collection
get "/collections/:page" do
- @back_url = "/explore/back"
+ @back_url = "/databases/1"
@page = params[:page].to_i || 1
@indexes = options.connection.indexes_for( session[:path_names] )
@@ -46,9 +47,6 @@ module Collections
# ---------------------------------------------------------------------------
post "/collections/refresh/:page/" do
- selected_cols = params[:cols].keys.sort
- session[:selected_cols] = selected_cols
-
load_cltn( params[:page].to_i )
erb :'collections/update.js', :layout => false
@@ -119,12 +117,6 @@ def load_cltn( page=1 )
path_names = session[:path_names]
@cltn = options.connection.paginate_cltn( path_names, query_params, @page, 15 )
- @cols = []
- @selected_cols = []
- unless @cltn.empty?
- @cols = @cltn.first.keys.sort
- @selected_cols = session[:selected_cols] || @cols[0...5]
- end
end
end
end
@@ -4,7 +4,19 @@ module Databases
get "/databases/:page" do
page = params[:page].to_i || 1
path_names = session[:path_names]
-
+ tokens = path_names.split( "|" )
+
+ # Could be we have a cltn path. if so adjust for it
+ if tokens.size > 3
+ tokens.pop
+ session[:path_names] = tokens.join( "|")
+ path_names = session[:path_names]
+ path_ids = session[:path_ids].split( "|" )
+ path_ids.pop
+ session[:path_ids] = path_ids.join( "|" )
+ end
+
+puts "DB PATH #{path_names.inspect}"
@cltns = options.connection.paginate_db( path_names, page, 10 )
@back_url = "/explore/back"
View
@@ -7,7 +7,7 @@ module Explore
@node_id = params[:db_id]
db_name = params[:db_name].gsub( /\(\d+\)/, '' )
- options.connection.drop_database( session[:path_names], db_name )
+ options.connection.drop_db( "#{session[:path_names]}|#{db_name}" )
flash_it!( :info, "Database `#{db_name} was dropped successfully!" )
@@ -43,14 +43,16 @@ module Explore
crumbs_from_path( path_ids, path_names )
+puts "PATHS #{path_names} -- #{@node_id}"
@root = options.connection.build_partial_tree( path_names )
+Mongo3::Node.dump( @root )
@nodes = @root.find( @node_id ).children
erb :'explore/explore'
end
# -----------------------------------------------------------------------------
- get '/explore/show/:path_ids/:path_names' do
+ get '/explore/info/:path_ids/:path_names' do
path_ids = params[:path_ids]
path_names = params[:path_names]
@@ -78,6 +80,21 @@ module Explore
erb :'explore/more_data_js', :layout => false
end
+ # ---------------------------------------------------------------------------
+ get "/explore/show/:path_ids/:path_names" do
+ path_ids = params[:path_ids]
+ path_names = params[:path_names]
+
+ # crumbs_from_path( path_ids, path_names )
+ update_paths!( path_ids, path_names )
+
+ if cltn_path?( path_ids )
+ erb :'explore/load_collection.js', :layout => false
+ else
+ erb :'explore/load_database.js', :layout => false
+ end
+ end
+
# -----------------------------------------------------------------------------
get '/explore/update_crumb/:path_ids/:path_names' do
path_ids = params[:path_ids]
@@ -15,6 +15,38 @@ module CollectionHelper
helpers do
include WillPaginate::ViewHelpers::Base
+ def format_nodes( item, col )
+ buff = []
+ _format_nodes( buff, item, col )
+ buff.join( "\n" )
+ end
+
+ def _format_nodes( buff, item, col=nil )
+ if item.is_a?( Array )
+ buff << "<li><ins style=\"background-position:-48px -16px\"></ins><span>#{col} <span class=\"meta\" style=\"color:#c1c1c1\">(#{item.size})</span></span>"
+ return buff if item.empty?
+ buff << "<ul>"
+ count = 0
+ item.each do |element|
+ _format_nodes( buff, element )
+ count += 1
+ end
+ buff << "</ul>"
+ buff << "</li>"
+ elsif item.is_a?( Hash )
+ buff << "<li><ins style=\"background-position:-48px -16px\"></ins><span>#{col} (#{item.size})</span>"
+ return buff if item.empty?
+ buff << "<ul>"
+ item.each_pair do |key,val|
+ _format_nodes( buff, val, key )
+ end
+ buff << "</ul>"
+ buff << "</li>"
+ else
+ 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>"
+ end
+ end
+
# Attempts to format an attribute to some human readable format
def format_value( value )
if value.is_a?( Fixnum)
@@ -1,11 +1,6 @@
module ExploreHelper
helpers do
-
- # looking at zone path?
- def zone_path?( path )
- path.split( "|" ).size == 1
- end
# compute legend title
def legend_title( path )
@@ -61,6 +61,11 @@ def display_info( info )
end
def partial( page, options={} )
+ if object = options.delete(:object)
+ template = page.to_s.split("/").last
+ options.merge!( :locals => { template.to_sym => object } )
+ end
+
if page.to_s.index( /\// )
page = page.to_s.gsub( /\//, '/_' )
else
@@ -1,6 +1,21 @@
module PathHelper
helpers do
+ # looking at zone path?
+ def zone_path?( path )
+ path.split( "|" ).size == 1
+ end
+
+ # looking at db path?
+ def db_path?( path )
+ path.split( "|" ).size == 3
+ end
+
+ # looking at cltn path?
+ def cltn_path?( path )
+ path.split( "|" ).size == 4
+ end
+
def reset_paths!
session[:path_ids] = "home"
session[:path_names] = "home"
View
@@ -1,7 +1,7 @@
module Mongo3
# :stopdoc:
- VERSION = '0.0.9' unless defined? Mongo3::VERSION
+ VERSION = '0.1.0' 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::PATH
# :startdoc:
View
@@ -1,22 +1,16 @@
require 'yaml'
# BOZO !! Time to refact no?
+# TODO !! Arg check and errors
+# TODO !! Add logging
module Mongo3
class Connection
def initialize( config_file )
@config_file = config_file
end
- # drop a database using context and db name
- def drop_database( path_names, db_name )
- path_name_tokens = path_names.split( "|" )
- zone = path_name_tokens[1]
- connect_for( zone ) do |con|
- con.drop_database( db_name )
- end
- end
-
+ # drop a db using a db path
def drop_db( path_names )
path_name_tokens = path_names.split( "|" )
zone = path_name_tokens[1]
@@ -42,12 +36,12 @@ def indexes_for( path_names )
def drop_index( path_names, index )
path_name_tokens = path_names.split( "|" )
- zone = path_name_tokens[1]
+ zone = path_name_tokens[1]
connect_for( zone ) do |con|
cltn_name = path_name_tokens.pop
db_name = path_name_tokens.pop
db = con.db( db_name )
- cltn = db[cltn_name]
+ cltn = db[cltn_name]
cltn.drop_index( index )
end
end
@@ -84,7 +78,7 @@ def clear_cltn( path_names )
db_name = path_name_tokens.pop
db = con.db( db_name )
cltn = db[cltn_name]
- cltn.remove
+ cltn.remove( {} )
end
end
@@ -96,7 +90,7 @@ def delete_row( path_names, id )
db_name = path_name_tokens.pop
db = con.db( db_name )
cltn = db[cltn_name]
- cltn.remove( {:_id => Mongo::ObjectID.from_string(id) } )
+ res = cltn.remove( {:_id => Mongo::ObjectID.from_string(id) } )
end
end
@@ -150,7 +144,7 @@ def show( path_names )
end
def paginate_db( path_names, page=1, per_page=10 )
- path_name_tokens = path_names.split( "|" )
+ path_name_tokens = path_names.split( "|" )
zone = path_name_tokens[1]
list = nil
connect_for( zone ) do |con|
@@ -189,7 +183,15 @@ 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
- results = cltn.find( query_params.first,
+ query = query_params.first
+
+ # Scan for regexes...
+ query.each_pair do |k,v|
+ if v.is_a?( String ) and v.index( /^\// )
+ query[k] = Regexp.new( v.gsub( "/", '' ) )
+ end
+ end
+ results = cltn.find( query,
:sort => sort,
:skip => offset,
:limit => per_page ).to_a
@@ -398,14 +400,23 @@ def database_names( con )
# Connects to mongo given an zone
def connect_for( zone, &block )
info = landscape[zone]
- # puts ">>> Connecting for #{zone} -- #{info['host']}-#{info['port']}"
- con = Mongo::Connection.new( info['host'], info['port'], { :slave_ok => true } )
+ raise "Unable to find zone info in config file for zone `#{zone}" unless info
+ raise "Check your config. Unable to find `host information" unless info['host']
+ raise "Check your config. Unable to find `port information" unless info['port']
+
+ begin
+ con = Mongo::Connection.new( info['host'], info['port'], { :slave_ok => true } )
- if info['user'] and info['password']
- con.db( 'admin' ).authenticate( info['user'], info['password'] )
+ if info['user'] and info['password']
+ con.db( 'admin' ).authenticate( info['user'], info['password'] )
+ end
+ yield con
+ con.close()
+ rescue => boom
+ # puts boom
+ # puts boom.backtrace.each {|l| puts l }
+ raise "MongoDB connection failed for `#{info['host'].inspect}:#{info['port'].inspect}"
end
- yield con
- con.close()
end
# db request occurs within dist 2
@@ -461,10 +472,14 @@ def slave_zone?( tokens )
# Initialize the mongo installation landscape
def config
unless @config
- @config = YAML.load_file( @config_file )
+ begin
+ @config = YAML.load_file( @config_file )
+ rescue => boom
+ @config = nil
+ raise "Unable to grok yaml landscape file. #{boom}"
+ end
end
@config
- end
-
+ end
end
end
Oops, something went wrong.

0 comments on commit 05ea8fa

Please sign in to comment.