mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-19 17:22:48 -05:00
* move handling generated files to the serilization classes * remove unneeded methods * add more folders to strictire compile, add more strict compile options * update ci * wip * add more layering and fix issues * add more strictness * remove unnecessary assertion * add missing checks * fix indentation * wip * remove jsdoc * fix layering * fix compile * fix compile errors * wip * wip * finish layering * fix css * more layering * rip * reworking results serializer * move some files around * move capabilities to platform wip * implement capabilities register provider * fix capabilities service * fix usage of the regist4ry * add contribution * wip * wip * wip * remove no longer good parts * fix strict-nulls * fix issues with startup * another try * fix startup * fix imports * fix tests * fix tests * fix more tests * fix tests * fix more tests * fix broken test * fix tabbing * fix naming * wip * finished layering * fix imports * fix valid layers * fix layers
109 lines
4.6 KiB
TypeScript
109 lines
4.6 KiB
TypeScript
/*---------------------------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
import Severity from 'vs/base/common/severity';
|
|
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
|
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
|
|
|
import { IErrorMessageService } from 'sql/platform/errorMessage/common/errorMessageService';
|
|
import { IServerGroupController, IServerGroupDialogCallbacks } from 'sql/platform/serverGroup/common/serverGroupController';
|
|
import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement';
|
|
import { ServerGroupDialog } from 'sql/workbench/services/serverGroup/browser/serverGroupDialog';
|
|
import { ServerGroupViewModel } from 'sql/workbench/services/serverGroup/common/serverGroupViewModel';
|
|
import { ConnectionProfileGroup, IConnectionProfileGroup } from 'sql/platform/connection/common/connectionProfileGroup';
|
|
import { SERVER_GROUP_CONFIG, SERVER_GROUP_COLORS_CONFIG } from 'sql/workbench/services/serverGroup/common/interfaces';
|
|
|
|
export class ServerGroupController implements IServerGroupController {
|
|
_serviceBrand: undefined;
|
|
|
|
private _serverGroupDialog: ServerGroupDialog;
|
|
private _callbacks: IServerGroupDialogCallbacks;
|
|
private _group: ConnectionProfileGroup;
|
|
private _viewModel: ServerGroupViewModel;
|
|
|
|
constructor(
|
|
@IErrorMessageService private _errorMessageService: IErrorMessageService,
|
|
@IInstantiationService private _instantiationService: IInstantiationService,
|
|
@IConfigurationService private _configurationService: IConfigurationService,
|
|
@IConnectionManagementService private readonly connectionManagementService: IConnectionManagementService
|
|
) {
|
|
}
|
|
|
|
private handleOnAddServerGroup(): void {
|
|
if (this._group) {
|
|
let tempGroup: ConnectionProfileGroup = this.copyConnectionProfileGroup(this._group);
|
|
this._group.name = this._viewModel.groupName;
|
|
this._group.color = this._viewModel.groupColor;
|
|
this._group.description = this._viewModel.groupDescription;
|
|
this.connectionManagementService.editGroup(this._group).then(() => {
|
|
this._serverGroupDialog.close();
|
|
}).catch(err => {
|
|
// rollback changes made
|
|
this._group = tempGroup;
|
|
this._errorMessageService.showDialog(Severity.Error, '', err);
|
|
});
|
|
|
|
} else {
|
|
let newGroup: IConnectionProfileGroup = {
|
|
name: this._viewModel.groupName,
|
|
id: undefined,
|
|
parentId: undefined,
|
|
color: this._viewModel.groupColor,
|
|
description: this._viewModel.groupDescription
|
|
};
|
|
this.connectionManagementService.saveProfileGroup(newGroup).then(groupId => {
|
|
if (this._callbacks) {
|
|
this._callbacks.onAddGroup(this._serverGroupDialog.groupName);
|
|
}
|
|
this._serverGroupDialog.close();
|
|
}).catch(err => {
|
|
this._errorMessageService.showDialog(Severity.Error, '', err);
|
|
});
|
|
}
|
|
}
|
|
|
|
private copyConnectionProfileGroup(group: ConnectionProfileGroup): ConnectionProfileGroup {
|
|
return new ConnectionProfileGroup(group.name, group.parent, group.id, group.color, group.description);
|
|
}
|
|
|
|
private handleOnClose(): void {
|
|
if (this._callbacks) {
|
|
this._callbacks.onClose();
|
|
}
|
|
}
|
|
|
|
|
|
public showCreateGroupDialog(callbacks?: IServerGroupDialogCallbacks): Promise<void> {
|
|
this._group = null;
|
|
this._viewModel = new ServerGroupViewModel(undefined, this._configurationService.getValue(SERVER_GROUP_CONFIG)[SERVER_GROUP_COLORS_CONFIG]);
|
|
this._callbacks = callbacks ? callbacks : undefined;
|
|
return this.openServerGroupDialog();
|
|
}
|
|
|
|
public showEditGroupDialog(group: ConnectionProfileGroup): Promise<void> {
|
|
this._group = group;
|
|
this._viewModel = new ServerGroupViewModel(group, this._configurationService.getValue(SERVER_GROUP_CONFIG)[SERVER_GROUP_COLORS_CONFIG]);
|
|
return this.openServerGroupDialog();
|
|
}
|
|
|
|
private openServerGroupDialog(): Promise<void> {
|
|
if (!this._serverGroupDialog) {
|
|
this._serverGroupDialog = this._instantiationService.createInstance(ServerGroupDialog);
|
|
this._serverGroupDialog.viewModel = this._viewModel;
|
|
this._serverGroupDialog.onCancel(() => { });
|
|
this._serverGroupDialog.onAddServerGroup(() => this.handleOnAddServerGroup());
|
|
this._serverGroupDialog.onCloseEvent(() => this.handleOnClose());
|
|
this._serverGroupDialog.render();
|
|
} else {
|
|
// reset the view model in the view
|
|
this._serverGroupDialog.viewModel = this._viewModel;
|
|
}
|
|
|
|
return new Promise<void>(() => {
|
|
this._serverGroupDialog.open();
|
|
});
|
|
}
|
|
}
|