Connection Dialog: Dropdown for database name (#583)

* dropdown now lets databases

* show databases for SQL Login too

* localized strings

* removed unnecesssary logic

* fixed dropdown height, case-insensitive filter and alignement

* added cache for connections
This commit is contained in:
Aditya Bist
2018-02-07 06:21:03 +05:30
committed by GitHub
parent 579e6bf0cb
commit a8c7c69509
4 changed files with 85 additions and 18 deletions

View File

@@ -26,6 +26,8 @@ export class ConnectionController implements IConnectionComponentController {
private _model: IConnectionProfile;
private _providerOptions: data.ConnectionOption[];
private _providerName: string;
/* key: uri, value : list of databases */
private _databaseCache = new Map<string, string[]>();
constructor(container: HTMLElement,
connectionManagementService: IConnectionManagementService,
@@ -43,11 +45,50 @@ export class ConnectionController implements IConnectionComponentController {
onSetConnectButton: (enable: boolean) => this._callback.onSetConnectButton(enable),
onCreateNewServerGroup: () => this.onCreateNewServerGroup(),
onAdvancedProperties: () => this.handleOnAdvancedProperties(),
onSetAzureTimeOut: () => this.handleonSetAzureTimeOut()
onSetAzureTimeOut: () => this.handleonSetAzureTimeOut(),
onFetchDatabases: (serverName: string, authenticationType: string, userName?: string, password?: string) => this.onFetchDatabases(
serverName, authenticationType, userName, password).then(result => {
return result;
})
}, providerName);
this._providerName = providerName;
}
private onFetchDatabases(serverName: string, authenticationType: string, userName?: string, password?: string): Promise<string[]> {
let tempProfile = this._model;
tempProfile.serverName = serverName;
tempProfile.authenticationType = authenticationType;
tempProfile.userName = userName;
tempProfile.password = password;
let uri = this._connectionManagementService.getConnectionId(tempProfile);
return new Promise<string[]>((resolve, reject) => {
if (this._databaseCache.has(uri)) {
let cachedDatabases : string[] = this._databaseCache.get(uri);
if (cachedDatabases !== null) {
resolve(cachedDatabases);
} else {
reject();
}
} else {
this._connectionManagementService.connect(tempProfile, uri).then(connResult => {
if (connResult && connResult.connected) {
this._connectionManagementService.listDatabases(uri).then(result => {
if (result && result.databaseNames) {
this._databaseCache.set(uri, result.databaseNames);
resolve(result.databaseNames);
} else {
this._databaseCache.set(uri, null);
reject();
}
})
} else {
reject(connResult.errorMessage);
}
});
}
});
}
private onCreateNewServerGroup(): void {
this._connectionManagementService.showCreateServerGroupDialog({
onAddGroup: (groupName) => this._connectionWidget.updateServerGroup(this.getAllServerGroups(), groupName),