mongo3 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/HISTORY +6 -1
  2. data/README.rdoc +2 -0
  3. data/Rakefile +0 -1
  4. data/data/populate +4 -4
  5. data/lib/controllers/collections.rb +42 -8
  6. data/lib/controllers/databases.rb +11 -1
  7. data/lib/controllers/explore.rb +49 -12
  8. data/lib/helpers/collection_helper.rb +18 -0
  9. data/lib/helpers/crumb_helper.rb +4 -4
  10. data/lib/helpers/database_helper.rb +17 -0
  11. data/lib/helpers/explore_helper.rb +30 -0
  12. data/lib/helpers/flash_helper.rb +7 -0
  13. data/lib/helpers/main_helper.rb +12 -30
  14. data/lib/helpers/paths_helper.rb +40 -0
  15. data/lib/mongo3.rb +1 -1
  16. data/lib/mongo3/connection.rb +95 -34
  17. data/lib/mongo3/node.rb +43 -28
  18. data/lib/public/images/edit.png +0 -0
  19. data/lib/public/images/selected_bg.png +0 -0
  20. data/lib/public/stylesheets/mongo3.css +87 -76
  21. data/lib/views/collections/_index_form.erb +35 -0
  22. data/lib/views/collections/_index_rows.erb +54 -0
  23. data/lib/views/collections/_indexes.erb +3 -0
  24. data/lib/views/collections/_results.erb +1 -2
  25. data/lib/views/collections/_rows.erb +26 -22
  26. data/lib/views/collections/_search_form.erb +2 -3
  27. data/lib/views/collections/list.erb +18 -6
  28. data/lib/views/collections/update.js.erb +2 -0
  29. data/lib/views/collections/update_indexes.js.erb +3 -0
  30. data/lib/views/databases/_results.erb +30 -26
  31. data/lib/views/databases/list.erb +7 -3
  32. data/lib/views/explore/_node_info.erb +131 -0
  33. data/lib/views/explore/center_js.erb +1 -0
  34. data/lib/views/explore/explore.erb +11 -80
  35. data/lib/views/explore/more_data_js.erb +1 -0
  36. data/lib/views/explore/update.js.erb +5 -0
  37. data/lib/views/explore/update_crumb_js.erb +2 -1
  38. data/lib/views/layout.erb +2 -2
  39. data/lib/views/shared/flash.js.erb +9 -7
  40. data/spec/landscape.yml +3 -0
  41. data/spec/mongo3/connection_spec.rb +146 -0
  42. data/spec/mongo3/node_spec.rb +26 -8
  43. data/spec/spec_helper.rb +4 -1
  44. data/tasks/rdoc.rake +2 -2
  45. metadata +23 -2
data/HISTORY CHANGED
@@ -13,4 +13,9 @@
13
13
  o Fixed issue on over extending cookies. Ie mongo3 suffered amnesia. Switching to memcache
14
14
  o Using memcache for session store - will need a local memcache server on default port!
15
15
  o Added confirm dialog on clear and drop
16
- o Bug fixes and some refactor
16
+ o Bug fixes and some refactor
17
+
18
+ 0.0.5 - Lots of changes... Yeah!
19
+ o cleaned up ui
20
+ o added edit on main context window
21
+ o added index crud for collection
data/README.rdoc CHANGED
@@ -36,6 +36,8 @@
36
36
 
37
37
  == DEPENDENCIES
38
38
 
39
+ * At this time mongo3 only is supported on ruby 1.8 and sinatra 0.9.4
40
+
39
41
  * mongo + mongo_ext
40
42
  * agnostic-will_paginate
41
43
  * memcache-client
data/Rakefile CHANGED
@@ -1,7 +1,6 @@
1
1
  # Look in the tasks/setup.rb file for the various options that can be
2
2
  # configured in this Rakefile. The .rake files in the tasks directory
3
3
  # are where the options are used.
4
-
5
4
  begin
6
5
  require 'bones'
7
6
  Bones.setup
data/data/populate CHANGED
@@ -2,9 +2,9 @@
2
2
  require 'rubygems'
3
3
  require 'mongo'
4
4
 
5
- connection = Mongo::Connection.new( 'localhost', 27018 )
6
- db = connection.db( 'admin' )
7
- db.authenticate( 'admin', 'admin')
5
+ connection = Mongo::Connection.new( 'localhost', 27019 )
6
+ # db = connection.db( 'admin' )
7
+ # db.authenticate( 'admin', 'admin')
8
8
 
9
9
  db_name = "fernand_mdb"
10
10
  cltn_name = "blee"
@@ -15,7 +15,7 @@ db = connection.db( db_name )
15
15
  cltn = db.create_collection( cltn_name )
16
16
  cltn.remove
17
17
 
18
- 10.times do |i|
18
+ 20.times do |i|
19
19
  row = { :name => "fred_#{i}", :last_name => "Blee_#{i}" }
20
20
  puts "Inserting row #{row.inspect}"
21
21
  cltn.insert( row )
@@ -2,14 +2,46 @@ require 'json'
2
2
 
3
3
  module Collections
4
4
 
5
+ # [ ['last_name', -1], ['name', 1] ]
6
+ # ---------------------------------------------------------------------------
7
+ post "/collections/create_index/" do
8
+ json = params[:index].gsub( /'/, "\"" )
9
+ tokens = json.split( "|" )
10
+
11
+ begin
12
+ raise "You need to enter an index description" if tokens.empty?
13
+ index = JSON.parse( tokens.shift )
14
+ constraints = tokens.empty? ? nil : JSON.parse( tokens.first )
15
+
16
+ options.connection.create_index( session[:path_names], index, constraints )
17
+ flash_it!( :info, "Index was created successfully!" )
18
+ rescue => boom
19
+ flash_it!( :error, boom )
20
+ return erb(:'shared/flash.js', :layout => false)
21
+ end
22
+
23
+ @indexes = options.connection.indexes_for( session[:path_names] )
24
+
25
+ erb :'collections/update_indexes.js', :layout => false
26
+ end
27
+
28
+ # ---------------------------------------------------------------------------
29
+ post "/collections/drop_index/" do
30
+ options.connection.drop_index( session[:path_names], params[:id] )
31
+ flash_it!( :info, "Index was dropped successfully!" )
32
+ erb :'shared/flash.js', :layout => false
33
+ end
34
+
5
35
  # ---------------------------------------------------------------------------
6
36
  # Paginate on a collection
7
37
  get "/collections/:page" do
8
38
  @back_url = "/explore/back"
9
39
  @page = params[:page].to_i || 1
10
- @title = title_for( session[:path_names] )
40
+
41
+ @indexes = options.connection.indexes_for( session[:path_names] )
42
+
43
+ load_cltn( params[:page].to_i )
11
44
 
12
- load_cltn( params[:page].to_i )
13
45
  erb :'collections/list'
14
46
  end
15
47
 
@@ -35,14 +67,14 @@ module Collections
35
67
  begin
36
68
  @query = JSON.parse( tokens.shift )
37
69
  @sort = tokens.empty? ? [] : JSON.parse( tokens.first )
38
- rescue => boom
70
+ session[:query_params] = [@query, @sort]
71
+ load_cltn
72
+ rescue => boom
39
73
  flash_it!( :error, boom )
40
74
  return erb(:'shared/flash.js', :layout => false)
41
75
  end
42
76
  end
43
- session[:query_params] = [@query, @sort]
44
77
 
45
- load_cltn
46
78
  erb :'collections/update.js', :layout => false
47
79
  end
48
80
 
@@ -50,6 +82,9 @@ module Collections
50
82
  path_names = session[:path_names]
51
83
  options.connection.delete_row( path_names, params[:id] )
52
84
  load_cltn
85
+
86
+ flash_it!( :info, "Row was deleted successfully!" )
87
+
53
88
  erb :'collections/update.js', :layout => false
54
89
  end
55
90
 
@@ -70,9 +105,8 @@ module Collections
70
105
  # ===========================================================================
71
106
  helpers do
72
107
  def load_cltn( page=1 )
73
- query_params = session[:query_params] || [{},[]]
74
-
75
- if query_params.first.empty? and query_params.last.empty?
108
+ query_params = session[:query_params] || [{},[]]
109
+ if ( !query_params.first or query_params.first.empty?) and ( !query_params.last or query_params.last.empty? )
76
110
  @query = nil
77
111
  else
78
112
  @query = [query_params.first.to_json, query_params.last.to_json].join( " | " )
@@ -6,12 +6,22 @@ module Databases
6
6
  path_names = session[:path_names]
7
7
 
8
8
  @cltns = options.connection.paginate_db( path_names, page, 10 )
9
- @title = title_for( path_names )
10
9
  @back_url = "/explore/back"
11
10
 
12
11
  erb :'databases/list'
13
12
  end
14
13
 
14
+ # ---------------------------------------------------------------------------
15
+ get "/databases/collection/:name/" do
16
+ cltn_name = params[:name]
17
+ path_names = session[:path_names]
18
+ path_ids = session[:path_ids]
19
+
20
+ update_paths!( path_ids + "|" + cltn_name, path_names + "|" + cltn_name )
21
+
22
+ redirect "/collections/1"
23
+ end
24
+
15
25
  # ---------------------------------------------------------------------------
16
26
  get "/databases/drop/" do
17
27
  path_names = session[:path_names]
@@ -1,9 +1,27 @@
1
1
  module Explore
2
2
 
3
+ # -----------------------------------------------------------------------------
4
+ get "/explore/database/:db_id/:db_name/drop" do
5
+ path_ids = session[:path_ids]
6
+ path_names = session[:path_names]
7
+ @node_id = params[:db_id]
8
+ db_name = params[:db_name].gsub( /\(\d+\)/, '' )
9
+
10
+ options.connection.drop_database( session[:path_names], db_name )
11
+
12
+ flash_it!( :info, "Database `#{db_name} was dropped successfully!" )
13
+
14
+ erb :'explore/update.js', :layout => false
15
+ end
16
+
3
17
  # -----------------------------------------------------------------------------
4
18
  get '/explore' do
19
+ @root = options.connection.build_tree
20
+ @nodes = @root.children
21
+
5
22
  reset_crumbs!
6
- @root = options.connection.build_tree
23
+ reset_paths!
24
+
7
25
  erb :'explore/explore'
8
26
  end
9
27
 
@@ -17,13 +35,13 @@ module Explore
17
35
  reset_crumbs!
18
36
  path_names = session[:path_names]
19
37
  path_ids = session[:path_ids]
20
- crumbs_from_path( path_ids, path_names )
38
+ @node_id = path_ids.split('|').last
21
39
 
22
- @root = options.connection.build_partial_tree( path_names )
40
+ crumbs_from_path( path_ids, path_names )
23
41
 
24
- # need to adjust crumbs in case something got blown...
25
- @center = path_ids.split('|').last
26
-
42
+ @root = options.connection.build_partial_tree( path_names )
43
+ @nodes = @root.find( @node_id ).children
44
+
27
45
  erb :'explore/explore'
28
46
  end
29
47
 
@@ -48,22 +66,41 @@ module Explore
48
66
 
49
67
  crumbs_from_path( path_ids, path_names )
50
68
 
51
- @sub_tree = options.connection.build_sub_tree( parent_id, path_names )
69
+ root = options.connection.build_sub_tree( parent_id, path_names )
70
+ @sub_tree = root.to_adjacencies
52
71
  @node_id = @sub_tree.first[:id]
72
+ @nodes = root.children
53
73
 
54
74
  erb :'explore/more_data_js', :layout => false
55
75
  end
56
76
 
57
77
  # -----------------------------------------------------------------------------
58
- get '/explore/update_crumb/:path/:crumbs' do
59
- crumbs_from_path( params[:path], params[:crumbs] )
78
+ get '/explore/update_crumb/:path_ids/:path_names' do
79
+ path_ids = params[:path_ids]
80
+ path_names = params[:path_names]
81
+
82
+ crumbs_from_path( path_ids, path_names )
83
+ update_paths!( path_ids, path_names )
84
+
85
+ root = options.connection.build_partial_tree( path_names )
86
+ node_id = path_ids.split( "|" ).last
87
+ @nodes = root.find( node_id ).children
88
+
60
89
  erb :'explore/update_crumb_js', :layout => false
61
90
  end
62
91
 
63
92
  # -----------------------------------------------------------------------------
64
- get '/explore/center/:node_id' do
65
- @node_id = params[:node_id]
66
- pop_crumb!( @node_id )
93
+ get '/explore/center/:path_ids/:path_names' do
94
+ path_ids = params[:path_ids]
95
+ path_names = params[:path_names]
96
+ @node_id = path_ids.split( "|" ).last
97
+
98
+ update_paths!( path_ids, path_names )
99
+ pop_crumb!( path_names, path_ids )
100
+
101
+ root = options.connection.build_partial_tree( path_names )
102
+ @nodes = root.find( @node_id ).children
103
+
67
104
  erb :'explore/center_js', :layout => false
68
105
  end
69
106
 
@@ -14,6 +14,24 @@ module CollectionHelper
14
14
 
15
15
  helpers do
16
16
  include WillPaginate::ViewHelpers::Base
17
+
18
+ # format indexes to key:orientation
19
+ def format_index( pair )
20
+ buff = []
21
+ buff << pair.first
22
+ buff << orientation( pair.last )
23
+ buff.join( ":" )
17
24
  end
18
25
 
26
+ # converts orientation to human
27
+ def orientation( value )
28
+ return "id" if value.is_a?(Mongo::ObjectID)
29
+ case( value.to_i )
30
+ when Mongo::ASCENDING : "asc"
31
+ when Mongo::DESCENDING : "desc"
32
+ else "n/a"
33
+ end
34
+ end
35
+
36
+ end
19
37
  end
@@ -8,14 +8,14 @@ module CrumbHelper
8
8
  @crumbs = []
9
9
  count = 0
10
10
  path_name_tokens.each do |crumb|
11
- @crumbs << [crumb, "/explore/center/#{path_id_tokens[count]}"]
11
+ @crumbs << [crumb, "/explore/center/#{path_name_tokens[0..count].join( "|" )}/#{path_id_tokens[0..count].join( "|") }"]
12
12
  count += 1
13
13
  end
14
14
  session[:crumbs] = @crumbs
15
15
  end
16
16
 
17
- def pop_crumb!( node_id )
18
- path = "/explore/center/#{node_id}"
17
+ def pop_crumb!( path_ids, path_names )
18
+ path = "/explore/center/#{path_ids}/#{path_names}"
19
19
  level = 0
20
20
  range = nil
21
21
  @crumbs.each do |pair|
@@ -30,7 +30,7 @@ module CrumbHelper
30
30
  end
31
31
 
32
32
  def reset_crumbs!
33
- @crumbs = [ ["home", '/explore/center/home'] ]
33
+ @crumbs = [ ["home", '/explore/center/home/home'] ]
34
34
  session[:crumbs] = @crumbs
35
35
  end
36
36
 
@@ -0,0 +1,17 @@
1
+ module DatabaseHelper
2
+ helpers do
3
+
4
+ def db_title
5
+ paths = session[:path_names].split( "|" )
6
+ return context_for( paths ), paths.last
7
+ end
8
+
9
+ def context_for( paths )
10
+ case paths.size
11
+ when 2 : "zone"
12
+ when 3 : "database"
13
+ else "collection"
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,30 @@
1
+ module ExploreHelper
2
+
3
+ helpers do
4
+
5
+ # looking at zone path?
6
+ def zone_path?( path )
7
+ path.split( "|" ).size == 1
8
+ end
9
+
10
+ # compute legend title
11
+ def legend_title( path )
12
+ path.split( "|" ).last
13
+ end
14
+
15
+ def path_type( path )
16
+ tokens = path.split( "|" )
17
+ case tokens.length
18
+ when 1 : "zone"
19
+ when 2 : "database"
20
+ else "collection"
21
+ end
22
+ end
23
+
24
+ # compute legend from given path.
25
+ def legend_for( path, count )
26
+ "#{path_type(path)}s(<span id='count'>#{count}</span>)"
27
+ end
28
+ end
29
+
30
+ end
@@ -1,6 +1,13 @@
1
1
  module FlashHelper
2
2
  helpers do
3
3
 
4
+ # clear out flash object
5
+ def clear_it!
6
+ @flash = session[:flash] || OrderedHash.new
7
+ @flash.clear
8
+ end
9
+
10
+ # add flash message
4
11
  def flash_it!( type, msg )
5
12
  @flash = session[:flash] || OrderedHash.new
6
13
  @flash[type] = msg
@@ -1,12 +1,17 @@
1
1
  module MainHelper
2
2
  helpers do
3
-
4
- def update_paths!( path_ids, path_names )
5
- puts "UPDAING PATH #{path_ids} -- #{path_names}"
6
- session[:path_ids] = path_ids
7
- session[:path_names] = path_names
3
+
4
+ def zone_locator
5
+ locator = session[:path_names].split( "|" )[1]
6
+ "<p class=\"ctx\"><span>zone</span>#{locator}</p>"
8
7
  end
9
-
8
+
9
+ def truncate(text, length = 30, truncate_string = "...")
10
+ return "" if text.nil?
11
+ l = length - truncate_string.size
12
+ text.size > length ? (text[0...l] + truncate_string).to_s : text
13
+ end
14
+
10
15
  def align_for( value )
11
16
  return "right" if value.is_a?(Fixnum)
12
17
  "left"
@@ -17,30 +22,7 @@ puts "UPDAING PATH #{path_ids} -- #{path_names}"
17
22
  return value.to_s.gsub(/(\d)(?=\d{3}+(\.\d*)?$)/, '\1,') if value.instance_of?(Fixnum)
18
23
  value
19
24
  end
20
-
21
- def back_paths!
22
- path_ids = session[:path_ids]
23
- new_path_ids = path_ids.split( "|" )
24
- new_path_ids.pop
25
-
26
- path_names = session[:path_names]
27
- new_path_names = path_names.split( "|" )
28
- new_path_names.pop
29
-
30
- update_paths!( new_path_ids.join( "|" ), new_path_names.join( "|" ) )
31
- end
32
-
33
- def title_for( path_names )
34
- tokens = path_names.split( "|" )
35
- buff = case tokens.length
36
- when 2 : "Environment"
37
- when 3 : "Database"
38
- else "Collection"
39
- end
40
-
41
- buff += " <em>#{tokens.last}</em>"
42
- end
43
-
25
+
44
26
  def display_info( info )
45
27
  return info if info.is_a?( String )
46
28
  if info.is_a?( Hash )
@@ -0,0 +1,40 @@
1
+ module PathHelper
2
+ helpers do
3
+
4
+ def reset_paths!
5
+ session[:path_ids] = "home"
6
+ session[:path_names] = "home"
7
+ end
8
+
9
+ def update_paths!( path_ids, path_names )
10
+ session[:path_ids] = path_ids
11
+ session[:path_names] = path_names
12
+ end
13
+
14
+ # Pop paths 1 level
15
+ def back_paths!
16
+ path_ids = session[:path_ids]
17
+ new_path_ids = path_ids.split( "|" )
18
+ new_path_ids.pop
19
+
20
+ path_names = session[:path_names]
21
+ new_path_names = path_names.split( "|" )
22
+ new_path_names.pop
23
+
24
+ update_paths!( new_path_ids.join( "|" ), new_path_names.join( "|" ) )
25
+ end
26
+
27
+ # compute title from path
28
+ def title_for( path_names )
29
+ tokens = path_names.split( "|" )
30
+ buff = case tokens.size
31
+ when 2 : "zone"
32
+ when 3 : "database"
33
+ else "collection"
34
+ end
35
+ db = tokens.size > 3 ? "<span class=\"ctx\">#{tokens[2]}</span>." : ""
36
+ "<p class=\"ctx\" style=\"text-align:center;font-size:0.8em\">#{db}#{tokens.last}</p>"
37
+ end
38
+
39
+ end
40
+ end