Permalink
Browse files

add support for mongohq

  • Loading branch information...
1 parent 07d12f5 commit 724aa4a4c10aa7480c6c5a46ba2def466c31cac9 @bububa committed May 29, 2010
@@ -15,6 +15,7 @@
IBOutlet NSTextField *aliasTextField;
IBOutlet NSTextField *adminuserTextField;
IBOutlet NSSecureTextField *adminpassTextField;
+ IBOutlet NSTextField *defaultdbTextField;
IBOutlet NSButton *usesshCheckBox;
IBOutlet NSTextField *bindaddressTextField;
IBOutlet NSTextField *bindportTextField;
@@ -32,6 +33,7 @@
@property (nonatomic, retain) NSTextField *aliasTextField;
@property (nonatomic, retain) NSTextField *adminuserTextField;
@property (nonatomic, retain) NSSecureTextField *adminpassTextField;
+@property (nonatomic, retain) NSTextField *defaultdbTextField;
@property (nonatomic, retain) NSButton *usesshCheckBox;
@property (nonatomic, retain) NSTextField *bindaddressTextField;
@property (nonatomic, retain) NSTextField *bindportTextField;
View
@@ -17,6 +17,7 @@ @implementation AddConnectionController
@synthesize aliasTextField;
@synthesize adminuserTextField;
@synthesize adminpassTextField;
+@synthesize defaultdbTextField;
@synthesize usesshCheckBox;
@synthesize bindaddressTextField;
@synthesize bindportTextField;
@@ -39,6 +40,7 @@ - (void)dealloc {
[aliasTextField release];
[adminuserTextField release];
[adminpassTextField release];
+ [defaultdbTextField release];
[usesshCheckBox release];
[bindaddressTextField release];
[bindportTextField release];
@@ -72,6 +74,7 @@ - (IBAction)add:(id)sender {
NSString *alias;
NSString *adminuser = [adminuserTextField stringValue];
NSString *adminpass = [adminpassTextField stringValue];
+ NSString *defaultdb = [defaultdbTextField stringValue];
NSUInteger usessh = 0;
NSString *bindaddress;
NSUInteger bindport;
@@ -124,10 +127,10 @@ - (IBAction)add:(id)sender {
sshuser = @"";
sshpassword = @"";
}
- NSArray *keys = [[NSArray alloc] initWithObjects:@"host", @"hostport", @"alias", @"adminuser", @"adminpass", @"usessh", @"bindaddress", @"bindport", @"sshhost", @"sshport", @"sshuser", @"sshpassword", nil];
- NSArray *objs = [[NSArray alloc] initWithObjects:host, [NSNumber numberWithInt:hostport], alias, adminuser, adminpass, [NSNumber numberWithInt:usessh], bindaddress, [NSNumber numberWithInt:bindport], sshhost, [NSNumber numberWithInt:sshport], sshuser, sshpassword, nil];
+ NSArray *keys = [[NSArray alloc] initWithObjects:@"host", @"hostport", @"alias", @"adminuser", @"adminpass", @"defaultdb", @"usessh", @"bindaddress", @"bindport", @"sshhost", @"sshport", @"sshuser", @"sshpassword", nil];
+ NSArray *objs = [[NSArray alloc] initWithObjects:host, [NSNumber numberWithInt:hostport], alias, adminuser, adminpass, defaultdb, [NSNumber numberWithInt:usessh], bindaddress, [NSNumber numberWithInt:bindport], sshhost, [NSNumber numberWithInt:sshport], sshuser, sshpassword, nil];
if (!connectionInfo) {
- connectionInfo = [[NSMutableDictionary alloc] initWithCapacity:12];
+ connectionInfo = [[NSMutableDictionary alloc] initWithCapacity:13];
}
connectionInfo = [NSMutableDictionary dictionaryWithObjects:objs forKeys:keys];
[keys release];
@@ -152,6 +155,10 @@ - (BOOL)validateConnection
NSRunAlertPanel(@"Error", @"Connection host should not be empty", @"OK", nil, nil);
return NO;
}
+ if ([[connectionInfo objectForKey:@"host"] isEqualToString:@"flame.mongohq.com"] && [[connectionInfo objectForKey:@"defaultdb"] length] == 0) {
+ NSRunAlertPanel(@"Error", @"DB should not be empty if you are using mongohq", @"OK", nil, nil);
+ return NO;
+ }
if ([[connectionInfo objectForKey:@"alias"] length]<3) {
NSRunAlertPanel(@"Error", @"Connection name should not be less than 3 charaters", @"OK", nil, nil);
return NO;
View
@@ -14,6 +14,7 @@
NSString *alias;
NSString *adminuser;
NSString *adminpass;
+ NSString *defaultdb;
NSString *sshhost;
NSNumber *sshport;
NSString *sshuser;
@@ -29,6 +30,7 @@
@property (nonatomic, retain) NSString *alias;
@property (nonatomic, retain) NSString *adminuser;
@property (nonatomic, retain) NSString *adminpass;
+@property (nonatomic, retain) NSString *defaultdb;
@property (nonatomic, retain) NSSet *databases;
@property (nonatomic, retain) NSString *sshhost;
@property (nonatomic, retain) NSNumber *sshport;
View
@@ -16,6 +16,7 @@ @implementation Connection
@dynamic alias;
@dynamic adminuser;
@dynamic adminpass;
+@dynamic defaultdb;
@dynamic databases;
@dynamic usessh;
@@ -50,8 +50,7 @@ - (void)windowDidLoad {
NSString *appVersion = [[NSString alloc] initWithFormat:@"version(%@)", [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString*)kCFBundleVersionKey] ];
[bundleVersion setStringValue: appVersion];
[appVersion release];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(addDB:) name:kNewDBWindowWillClose object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(addCollection:) name:kNewCollectionWindowWillClose object:nil];
+
NSString *hostaddress;
if ([conn.usessh intValue]==1) {
sshTunnel = [SSHTunnel sshTunnelWithHostname:conn.sshhost
@@ -64,13 +63,22 @@ - (void)windowDidLoad {
hostPort:[conn.hostport intValue]];
[sshTunnel launch];
hostaddress = [NSString stringWithFormat:@"%@:%@", conn.bindaddress, conn.bindport];
+ }else if ([conn.host isEqualToString:@"flame.mongohq.com"]) {
+ hostaddress = [NSString stringWithFormat:@"%@:%@/%@", conn.host, conn.hostport, conn.defaultdb];
}else {
hostaddress = [NSString stringWithFormat:@"%@:%@", conn.host, conn.hostport];
}
mongoDB = [[MongoDB alloc] initWithConn:hostaddress];
if ([conn.adminuser isPresent]) {
- [mongoDB authUser:conn.adminuser pass:conn.adminpass];
+ [mongoDB authUser:conn.adminuser pass:conn.adminpass database:conn.defaultdb];
}
+
+ if (![conn.defaultdb isPresent]) {
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(addDB:) name:kNewDBWindowWillClose object:nil];
+ }
+
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(addCollection:) name:kNewCollectionWindowWillClose object:nil];
+
[self reloadSidebar];
[self showServerStatus:nil];
}
@@ -118,7 +126,12 @@ - (void)reloadDBList {
[collections release];
collections = [[NSMutableArray alloc] init];
[databases release];
- databases = [[NSMutableArray alloc ] initWithArray:[mongoDB listDatabases]];
+ if ([conn.defaultdb isPresent]) {
+ databases = [[NSMutableArray alloc] initWithObjects:conn.defaultdb, nil];
+ }else {
+ databases = [[NSMutableArray alloc ] initWithArray:[mongoDB listDatabases]];
+ }
+
[databaseArrayController clean:conn databases:databases];
[sidebar removeItem:@"2"];
unsigned int i=1;
@@ -259,6 +272,10 @@ - (void)createCollectionForDB:(NSString *)dbname
- (void)createDB
{
+ if ([conn.defaultdb isPresent]) {
+ NSRunAlertPanel(@"Error", @"Could not create database!", @"OK", nil, nil);
+ return;
+ }
if (!addDBController)
{
addDBController = [[AddDBController alloc] init];
@@ -347,6 +364,10 @@ - (void)dropCollection:(NSString *)collectionname ForDB:(NSString *)dbname
- (void)dropDB
{
+ if ([conn.defaultdb isPresent]) {
+ NSRunAlertPanel(@"Error", @"Could not drop database!", @"OK", nil, nil);
+ return;
+ }
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *user=nil;
NSString *password=nil;
@@ -381,6 +402,11 @@ - (IBAction)query:(id)sender
- (IBAction)showAuth:(id)sender
{
+ if ([conn.defaultdb isPresent]) {
+ NSRunAlertPanel(@"Error", @"Could not auth for database!", @"OK", nil, nil);
+ return;
+ }
+
if (!selectedDB)
{
NSRunAlertPanel(@"Error", @"Please choose a database!", @"OK", nil, nil);
Oops, something went wrong.

0 comments on commit 724aa4a

Please sign in to comment.