Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show connected db in the tree view #277

Merged
merged 2 commits into from
Dec 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,21 @@ export function activate(context: vscode.ExtensionContext) {
initCommand(context, 'cosmosDB.openInPortal', (node: IAzureNode) => node.openInPortal());
initAsyncCommand(context, 'cosmosDB.copyConnectionString', (node: IAzureNode<MongoAccountTreeItem | DocDBAccountTreeItemBase>) => copyConnectionString(node));

vscode.window.setStatusBarMessage('Mongo: Not connected');
initAsyncCommand(context, 'cosmosDB.connectMongoDB', async (node: IAzureParentNode<MongoDatabaseTreeItem>) => {
if (connectedDb) {
connectedDb.treeItem.isConnected = false;
connectedDb.refresh();
}
connectedDb = node;
await languageClient.connect(connectedDb.treeItem.connectionString);
vscode.window.setStatusBarMessage('Mongo: ' + node.parent.treeItem.label + '/' + connectedDb.treeItem.label);
connectedDb.treeItem.isConnected = true;
node.refresh();
});
initAsyncCommand(context, 'cosmosDB.deleteMongoDB', async (node: IAzureNode<MongoDatabaseTreeItem>) => {
await node.deleteNode();
if (connectedDb && connectedDb.treeItem.id === node.treeItem.id) {
connectedDb = null;
languageClient.disconnect();
vscode.window.setStatusBarMessage('Mongo: Not connected');
}
});
initAsyncCommand(context, 'cosmosDB.deleteMongoCollection', (node: IAzureNode) => node.deleteNode());
Expand Down
4 changes: 4 additions & 0 deletions src/mongo/tree/MongoDatabaseTreeItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class MongoDatabaseTreeItem implements IAzureParentTreeItem {
private readonly _databaseName: string;
private readonly _accountConnectionString: string;
private readonly _parentId: string;
public isConnected: boolean = false;

constructor(databaseName: string, accountConnectionString: string, parentId: string) {
this._databaseName = databaseName;
Expand All @@ -31,6 +32,9 @@ export class MongoDatabaseTreeItem implements IAzureParentTreeItem {
}

public get label(): string {
if (this.isConnected) {
return this._databaseName + " (Connected)";
}
return this._databaseName;
}

Expand Down