mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
User Management - Support new object types: Server Role, Application Role and Database Role (#22889)
* server role dialogs * dialogs for other types * refactor * find object dialog * script button * refactoring * fix issues * fix title * vbump sts * remove language from links
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
import * as azdata from 'azdata';
|
||||
import { ObjectManagementDialogBase, ObjectManagementDialogOptions } from './objectManagementDialogBase';
|
||||
import { IObjectManagementService, ObjectManagement } from 'mssql';
|
||||
import * as localizedConstants from '../localizedConstants';
|
||||
import { AlterApplicationRoleDocUrl, CreateApplicationRoleDocUrl } from '../constants';
|
||||
import { isValidSQLPassword } from '../utils';
|
||||
import { DefaultMaxTableHeight } from './dialogBase';
|
||||
|
||||
export class ApplicationRoleDialog extends ObjectManagementDialogBase<ObjectManagement.ApplicationRoleInfo, ObjectManagement.ApplicationRoleViewInfo> {
|
||||
// Sections
|
||||
private generalSection: azdata.GroupContainer;
|
||||
private ownedSchemasSection: azdata.GroupContainer;
|
||||
|
||||
// General section content
|
||||
private nameInput: azdata.InputBoxComponent;
|
||||
private defaultSchemaDropdown: azdata.DropDownComponent;
|
||||
private passwordInput: azdata.InputBoxComponent;
|
||||
private confirmPasswordInput: azdata.InputBoxComponent;
|
||||
|
||||
// Owned Schemas section content
|
||||
private ownedSchemaTable: azdata.TableComponent;
|
||||
|
||||
constructor(objectManagementService: IObjectManagementService, options: ObjectManagementDialogOptions) {
|
||||
super(objectManagementService, options);
|
||||
}
|
||||
|
||||
protected override postInitializeData(): void {
|
||||
this.objectInfo.password = this.objectInfo.password ?? '';
|
||||
}
|
||||
|
||||
protected override get docUrl(): string {
|
||||
return this.options.isNewObject ? CreateApplicationRoleDocUrl : AlterApplicationRoleDocUrl;
|
||||
}
|
||||
|
||||
protected override async validateInput(): Promise<string[]> {
|
||||
const errors = await super.validateInput();
|
||||
if (!this.objectInfo.password) {
|
||||
errors.push(localizedConstants.PasswordCannotBeEmptyError);
|
||||
}
|
||||
if (this.objectInfo.password && !isValidSQLPassword(this.objectInfo.password, this.objectInfo.name)
|
||||
&& (this.options.isNewObject || this.objectInfo.password !== this.originalObjectInfo.password)) {
|
||||
errors.push(localizedConstants.InvalidPasswordError);
|
||||
}
|
||||
if (this.objectInfo.password !== this.confirmPasswordInput.value) {
|
||||
errors.push(localizedConstants.PasswordsNotMatchError);
|
||||
}
|
||||
return errors;
|
||||
}
|
||||
|
||||
protected async initializeUI(): Promise<void> {
|
||||
this.initializeGeneralSection();
|
||||
this.initializeOwnedSchemasSection();
|
||||
this.formContainer.addItems([this.generalSection, this.ownedSchemasSection]);
|
||||
}
|
||||
|
||||
private initializeGeneralSection(): void {
|
||||
this.nameInput = this.createInputBox(localizedConstants.NameText, async (newValue) => {
|
||||
this.objectInfo.name = newValue;
|
||||
}, this.objectInfo.name, this.options.isNewObject);
|
||||
const nameContainer = this.createLabelInputContainer(localizedConstants.NameText, this.nameInput);
|
||||
|
||||
this.defaultSchemaDropdown = this.createDropdown(localizedConstants.DefaultSchemaText, async (newValue) => {
|
||||
this.objectInfo.defaultSchema = newValue;
|
||||
}, this.viewInfo.schemas, this.objectInfo.defaultSchema!);
|
||||
const defaultSchemaContainer = this.createLabelInputContainer(localizedConstants.DefaultSchemaText, this.defaultSchemaDropdown);
|
||||
|
||||
this.passwordInput = this.createPasswordInputBox(localizedConstants.PasswordText, async (newValue) => {
|
||||
this.objectInfo.password = newValue;
|
||||
}, this.objectInfo.password ?? '');
|
||||
const passwordContainer = this.createLabelInputContainer(localizedConstants.PasswordText, this.passwordInput);
|
||||
|
||||
this.confirmPasswordInput = this.createPasswordInputBox(localizedConstants.ConfirmPasswordText, async () => { }, this.objectInfo.password ?? '');
|
||||
const confirmPasswordContainer = this.createLabelInputContainer(localizedConstants.ConfirmPasswordText, this.confirmPasswordInput);
|
||||
|
||||
this.generalSection = this.createGroup(localizedConstants.GeneralSectionHeader, [nameContainer, defaultSchemaContainer, passwordContainer, confirmPasswordContainer], false);
|
||||
}
|
||||
|
||||
private initializeOwnedSchemasSection(): void {
|
||||
this.ownedSchemaTable = this.createTableList<string>(localizedConstants.OwnedSchemaSectionHeader,
|
||||
[localizedConstants.SchemaText],
|
||||
this.viewInfo.schemas,
|
||||
this.objectInfo.ownedSchemas,
|
||||
DefaultMaxTableHeight,
|
||||
(item) => {
|
||||
// It is not allowed to have unassigned schema.
|
||||
return this.objectInfo.ownedSchemas.indexOf(item) === -1;
|
||||
});
|
||||
this.ownedSchemasSection = this.createGroup(localizedConstants.OwnedSchemaSectionHeader, [this.ownedSchemaTable]);
|
||||
}
|
||||
}
|
||||
130
extensions/mssql/src/objectManagement/ui/databaseRoleDialog.ts
Normal file
130
extensions/mssql/src/objectManagement/ui/databaseRoleDialog.ts
Normal file
@@ -0,0 +1,130 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
import * as azdata from 'azdata';
|
||||
import { ObjectManagementDialogBase, ObjectManagementDialogOptions } from './objectManagementDialogBase';
|
||||
import { IObjectManagementService, ObjectManagement } from 'mssql';
|
||||
import * as localizedConstants from '../localizedConstants';
|
||||
import { AlterDatabaseRoleDocUrl, CreateDatabaseRoleDocUrl } from '../constants';
|
||||
import { FindObjectDialog } from './findObjectDialog';
|
||||
import { DefaultMaxTableHeight } from './dialogBase';
|
||||
|
||||
export class DatabaseRoleDialog extends ObjectManagementDialogBase<ObjectManagement.DatabaseRoleInfo, ObjectManagement.DatabaseRoleViewInfo> {
|
||||
// Sections
|
||||
private generalSection: azdata.GroupContainer;
|
||||
private ownedSchemasSection: azdata.GroupContainer;
|
||||
private memberSection: azdata.GroupContainer;
|
||||
|
||||
// General section content
|
||||
private nameInput: azdata.InputBoxComponent;
|
||||
private ownerInput: azdata.InputBoxComponent;
|
||||
|
||||
// Owned Schemas section content
|
||||
private ownedSchemaTable: azdata.TableComponent;
|
||||
|
||||
// Member section content
|
||||
private memberTable: azdata.TableComponent;
|
||||
|
||||
constructor(objectManagementService: IObjectManagementService, options: ObjectManagementDialogOptions) {
|
||||
super(objectManagementService, options);
|
||||
}
|
||||
|
||||
protected override get docUrl(): string {
|
||||
return this.options.isNewObject ? CreateDatabaseRoleDocUrl : AlterDatabaseRoleDocUrl;
|
||||
}
|
||||
|
||||
protected async initializeUI(): Promise<void> {
|
||||
this.initializeGeneralSection();
|
||||
this.initializeOwnedSchemasSection();
|
||||
this.initializeMemberSection();
|
||||
this.formContainer.addItems([this.generalSection, this.ownedSchemasSection, this.memberSection]);
|
||||
}
|
||||
|
||||
private initializeGeneralSection(): void {
|
||||
this.nameInput = this.createInputBox(localizedConstants.NameText, async (newValue) => {
|
||||
this.objectInfo.name = newValue;
|
||||
}, this.objectInfo.name, this.options.isNewObject);
|
||||
const nameContainer = this.createLabelInputContainer(localizedConstants.NameText, this.nameInput);
|
||||
|
||||
this.ownerInput = this.createInputBox(localizedConstants.OwnerText, async (newValue) => {
|
||||
this.objectInfo.owner = newValue;
|
||||
}, this.objectInfo.owner, true, 'text', 210);
|
||||
const browseOwnerButton = this.createButton(localizedConstants.BrowseText, localizedConstants.BrowseOwnerButtonAriaLabel, async () => {
|
||||
const dialog = new FindObjectDialog(this.objectManagementService, {
|
||||
objectTypes: [ObjectManagement.NodeType.ApplicationRole, ObjectManagement.NodeType.DatabaseRole, ObjectManagement.NodeType.User],
|
||||
multiSelect: false,
|
||||
contextId: this.contextId,
|
||||
title: localizedConstants.SelectDatabaseRoleOwnerDialogTitle
|
||||
});
|
||||
await dialog.open();
|
||||
const result = await dialog.waitForClose();
|
||||
if (result.selectedObjects.length > 0) {
|
||||
this.ownerInput.value = result.selectedObjects[0].name;
|
||||
}
|
||||
});
|
||||
const ownerContainer = this.createLabelInputContainer(localizedConstants.OwnerText, this.ownerInput);
|
||||
ownerContainer.addItems([browseOwnerButton], { flex: '0 0 auto' });
|
||||
|
||||
this.generalSection = this.createGroup(localizedConstants.GeneralSectionHeader, [nameContainer, ownerContainer], false);
|
||||
}
|
||||
|
||||
private initializeMemberSection(): void {
|
||||
this.memberTable = this.createTable(localizedConstants.MemberSectionHeader, [
|
||||
{
|
||||
type: azdata.ColumnType.text,
|
||||
value: localizedConstants.NameText
|
||||
}
|
||||
], this.objectInfo.members.map(m => [m]));
|
||||
const buttonContainer = this.addButtonsForTable(this.memberTable, localizedConstants.AddMemberAriaLabel, localizedConstants.RemoveMemberAriaLabel,
|
||||
async () => {
|
||||
const dialog = new FindObjectDialog(this.objectManagementService, {
|
||||
objectTypes: [ObjectManagement.NodeType.DatabaseRole, ObjectManagement.NodeType.User],
|
||||
multiSelect: true,
|
||||
contextId: this.contextId,
|
||||
title: localizedConstants.SelectDatabaseRoleMemberDialogTitle
|
||||
});
|
||||
await dialog.open();
|
||||
const result = await dialog.waitForClose();
|
||||
this.addMembers(result.selectedObjects.map(r => r.name));
|
||||
},
|
||||
async () => {
|
||||
if (this.memberTable.selectedRows.length === 1) {
|
||||
this.removeMember(this.memberTable.selectedRows[0]);
|
||||
}
|
||||
});
|
||||
this.memberSection = this.createGroup(localizedConstants.MemberSectionHeader, [this.memberTable, buttonContainer]);
|
||||
}
|
||||
|
||||
private addMembers(names: string[]): void {
|
||||
names.forEach(n => {
|
||||
if (this.objectInfo.members.indexOf(n) === -1) {
|
||||
this.objectInfo.members.push(n);
|
||||
}
|
||||
});
|
||||
this.updateMembersTable();
|
||||
}
|
||||
|
||||
private removeMember(idx: number): void {
|
||||
this.objectInfo.members.splice(idx, 1);
|
||||
this.updateMembersTable();
|
||||
}
|
||||
|
||||
private updateMembersTable(): void {
|
||||
this.setTableData(this.memberTable, this.objectInfo.members.map(m => [m]));
|
||||
this.onFormFieldChange();
|
||||
}
|
||||
|
||||
private initializeOwnedSchemasSection(): void {
|
||||
this.ownedSchemaTable = this.createTableList<string>(localizedConstants.OwnedSchemaSectionHeader,
|
||||
[localizedConstants.SchemaText],
|
||||
this.viewInfo.schemas,
|
||||
this.objectInfo.ownedSchemas,
|
||||
DefaultMaxTableHeight,
|
||||
(item) => {
|
||||
// It is not allowed to have unassigned schema.
|
||||
return this.objectInfo.ownedSchemas.indexOf(item) === -1;
|
||||
});
|
||||
this.ownedSchemasSection = this.createGroup(localizedConstants.OwnedSchemaSectionHeader, [this.ownedSchemaTable]);
|
||||
}
|
||||
}
|
||||
332
extensions/mssql/src/objectManagement/ui/dialogBase.ts
Normal file
332
extensions/mssql/src/objectManagement/ui/dialogBase.ts
Normal file
@@ -0,0 +1,332 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as azdata from 'azdata';
|
||||
import * as vscode from 'vscode';
|
||||
import { EOL } from 'os';
|
||||
import * as localizedConstants from '../localizedConstants';
|
||||
|
||||
export const DefaultLabelWidth = 150;
|
||||
export const DefaultInputWidth = 300;
|
||||
export const DefaultTableWidth = DefaultInputWidth + DefaultLabelWidth;
|
||||
export const DefaultMaxTableHeight = 400;
|
||||
export const DefaultMinTableRowCount = 1;
|
||||
export const TableRowHeight = 25;
|
||||
export const TableColumnHeaderHeight = 30;
|
||||
|
||||
export function getTableHeight(rowCount: number, minRowCount: number = DefaultMinTableRowCount, maxHeight: number = DefaultMaxTableHeight): number {
|
||||
return Math.min(Math.max(rowCount, minRowCount) * TableRowHeight + TableColumnHeaderHeight, maxHeight);
|
||||
}
|
||||
|
||||
export type TableListItemEnabledStateGetter<T> = (item: T) => boolean;
|
||||
export type TableListItemValueGetter<T> = (item: T) => string[];
|
||||
export type TableListItemComparer<T> = (item1: T, item2: T) => boolean;
|
||||
export const DefaultTableListItemEnabledStateGetter: TableListItemEnabledStateGetter<any> = (item: any) => true;
|
||||
export const DefaultTableListItemValueGetter: TableListItemValueGetter<any> = (item: any) => [item?.toString() ?? ''];
|
||||
export const DefaultTableListItemComparer: TableListItemComparer<any> = (item1: any, item2: any) => item1 === item2;
|
||||
|
||||
|
||||
export abstract class DialogBase<DialogResult> {
|
||||
protected readonly disposables: vscode.Disposable[] = [];
|
||||
protected readonly dialogObject: azdata.window.Dialog;
|
||||
|
||||
private _modelView: azdata.ModelView;
|
||||
private _loadingComponent: azdata.LoadingComponent;
|
||||
private _formContainer: azdata.DivContainer;
|
||||
private _closePromise: Promise<DialogResult | undefined>;
|
||||
|
||||
constructor(title: string, name: string, width: azdata.window.DialogWidth = 'narrow', style: azdata.window.DialogStyle = 'flyout') {
|
||||
this.dialogObject = azdata.window.createModelViewDialog(title, name, width, style);
|
||||
this.dialogObject.okButton.label = localizedConstants.OkText;
|
||||
this.dialogObject.registerCloseValidator(async (): Promise<boolean> => {
|
||||
const confirmed = await this.onConfirmation();
|
||||
if (!confirmed) {
|
||||
return false;
|
||||
}
|
||||
return await this.runValidation();
|
||||
});
|
||||
this._closePromise = new Promise<DialogResult | undefined>(resolve => {
|
||||
this.disposables.push(this.dialogObject.onClosed(async (reason: azdata.window.CloseReason) => {
|
||||
await this.dispose(reason);
|
||||
const result = reason === 'ok' ? this.dialogResult : undefined;
|
||||
resolve(result);
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
public waitForClose(): Promise<DialogResult | undefined> {
|
||||
return this._closePromise;
|
||||
}
|
||||
|
||||
protected get dialogResult(): DialogResult | undefined { return undefined; }
|
||||
|
||||
protected async onConfirmation(): Promise<boolean> { return true; }
|
||||
|
||||
protected abstract initialize(): Promise<void>;
|
||||
|
||||
protected get formContainer(): azdata.DivContainer { return this._formContainer; }
|
||||
|
||||
protected get modelView(): azdata.ModelView { return this._modelView; }
|
||||
|
||||
protected onFormFieldChange(): void { }
|
||||
|
||||
protected validateInput(): Promise<string[]> { return Promise.resolve([]); }
|
||||
|
||||
public async open(): Promise<void> {
|
||||
try {
|
||||
this.onLoadingStatusChanged(true);
|
||||
const initializeDialogPromise = new Promise<void>((async resolve => {
|
||||
await this.dialogObject.registerContent(async view => {
|
||||
this._modelView = view;
|
||||
this._formContainer = this.createFormContainer([]);
|
||||
this._loadingComponent = view.modelBuilder.loadingComponent().withItem(this._formContainer).withProps({
|
||||
loading: true,
|
||||
loadingText: localizedConstants.LoadingDialogText,
|
||||
showText: true,
|
||||
CSSStyles: {
|
||||
width: "100%",
|
||||
height: "100%"
|
||||
}
|
||||
}).component();
|
||||
await view.initializeModel(this._loadingComponent);
|
||||
resolve();
|
||||
});
|
||||
}));
|
||||
azdata.window.openDialog(this.dialogObject);
|
||||
await initializeDialogPromise;
|
||||
await this.initialize();
|
||||
this.onLoadingStatusChanged(false);
|
||||
} catch (err) {
|
||||
azdata.window.closeDialog(this.dialogObject);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
protected async dispose(reason: azdata.window.CloseReason): Promise<void> {
|
||||
this.disposables.forEach(disposable => disposable.dispose());
|
||||
}
|
||||
|
||||
protected async runValidation(showErrorMessage: boolean = true): Promise<boolean> {
|
||||
const errors = await this.validateInput();
|
||||
if (errors.length > 0 && (this.dialogObject.message?.text || showErrorMessage)) {
|
||||
this.dialogObject.message = {
|
||||
text: errors.join(EOL),
|
||||
level: azdata.window.MessageLevel.Error
|
||||
};
|
||||
} else {
|
||||
this.dialogObject.message = undefined;
|
||||
}
|
||||
return errors.length === 0;
|
||||
}
|
||||
|
||||
protected createLabelInputContainer(label: string, input: azdata.InputBoxComponent | azdata.DropDownComponent): azdata.FlexContainer {
|
||||
const labelComponent = this.modelView.modelBuilder.text().withProps({ width: DefaultLabelWidth, value: label, requiredIndicator: input.required }).component();
|
||||
const container = this.modelView.modelBuilder.flexContainer().withLayout({ flexFlow: 'horizontal', flexWrap: 'nowrap', alignItems: 'center' }).withItems([labelComponent], { flex: '0 0 auto' }).component();
|
||||
container.addItem(input, { flex: '1 1 auto' });
|
||||
return container;
|
||||
}
|
||||
|
||||
protected createCheckbox(label: string, handler: (checked: boolean) => Promise<void>, checked: boolean = false, enabled: boolean = true): azdata.CheckBoxComponent {
|
||||
const checkbox = this.modelView.modelBuilder.checkBox().withProps({
|
||||
label: label,
|
||||
checked: checked,
|
||||
enabled: enabled
|
||||
}).component();
|
||||
this.disposables.push(checkbox.onChanged(async () => {
|
||||
await handler(checkbox.checked!);
|
||||
this.onFormFieldChange();
|
||||
await this.runValidation(false);
|
||||
}));
|
||||
return checkbox;
|
||||
}
|
||||
|
||||
protected createPasswordInputBox(ariaLabel: string, textChangeHandler: (newValue: string) => Promise<void>, value: string = '', enabled: boolean = true, width: number = DefaultInputWidth): azdata.InputBoxComponent {
|
||||
return this.createInputBox(ariaLabel, textChangeHandler, value, enabled, 'password', width);
|
||||
}
|
||||
|
||||
protected createInputBox(ariaLabel: string, textChangeHandler: (newValue: string) => Promise<void>, value: string = '', enabled: boolean = true, type: azdata.InputBoxInputType = 'text', width: number = DefaultInputWidth): azdata.InputBoxComponent {
|
||||
const inputbox = this.modelView.modelBuilder.inputBox().withProps({ inputType: type, enabled: enabled, ariaLabel: ariaLabel, value: value, width: width }).component();
|
||||
this.disposables.push(inputbox.onTextChanged(async () => {
|
||||
await textChangeHandler(inputbox.value!);
|
||||
this.onFormFieldChange();
|
||||
await this.runValidation(false);
|
||||
}));
|
||||
return inputbox;
|
||||
}
|
||||
|
||||
protected createGroup(header: string, items: azdata.Component[], collapsible: boolean = true, collapsed: boolean = false): azdata.GroupContainer {
|
||||
return this.modelView.modelBuilder.groupContainer().withLayout({
|
||||
header: header,
|
||||
collapsible: collapsible,
|
||||
collapsed: collapsed
|
||||
}).withItems(items).component();
|
||||
}
|
||||
|
||||
protected createTableList<T>(ariaLabel: string,
|
||||
columnNames: string[],
|
||||
allItems: T[],
|
||||
selectedItems: T[],
|
||||
maxHeight: number = DefaultMaxTableHeight,
|
||||
enabledStateGetter: TableListItemEnabledStateGetter<T> = DefaultTableListItemEnabledStateGetter,
|
||||
rowValueGetter: TableListItemValueGetter<T> = DefaultTableListItemValueGetter,
|
||||
itemComparer: TableListItemComparer<T> = DefaultTableListItemComparer): azdata.TableComponent {
|
||||
const data = this.getDataForTableList(allItems, selectedItems, enabledStateGetter, rowValueGetter, itemComparer);
|
||||
const table = this.modelView.modelBuilder.table().withProps(
|
||||
{
|
||||
ariaLabel: ariaLabel,
|
||||
data: data,
|
||||
columns: [
|
||||
{
|
||||
value: localizedConstants.SelectedText,
|
||||
type: azdata.ColumnType.checkBox,
|
||||
options: { actionOnCheckbox: azdata.ActionOnCellCheckboxCheck.customAction }
|
||||
}, ...columnNames.map(name => {
|
||||
return { value: name };
|
||||
})
|
||||
],
|
||||
width: DefaultTableWidth,
|
||||
height: getTableHeight(data.length, DefaultMinTableRowCount, maxHeight)
|
||||
}
|
||||
).component();
|
||||
this.disposables.push(table.onCellAction!((arg: azdata.ICheckboxCellActionEventArgs) => {
|
||||
const item = allItems[arg.row];
|
||||
const idx = selectedItems.findIndex(i => itemComparer(i, item));
|
||||
if (arg.checked && idx === -1) {
|
||||
selectedItems.push(item);
|
||||
} else if (!arg.checked && idx !== -1) {
|
||||
selectedItems.splice(idx, 1)
|
||||
}
|
||||
this.onFormFieldChange();
|
||||
}));
|
||||
return table;
|
||||
}
|
||||
|
||||
protected setTableData(table: azdata.TableComponent, data: any[][], maxHeight: number = DefaultMaxTableHeight) {
|
||||
table.data = data;
|
||||
table.height = getTableHeight(data.length, DefaultMinTableRowCount, maxHeight);
|
||||
}
|
||||
|
||||
protected getDataForTableList<T>(
|
||||
allItems: T[],
|
||||
selectedItems: T[],
|
||||
enabledStateGetter: TableListItemEnabledStateGetter<T> = DefaultTableListItemEnabledStateGetter,
|
||||
rowValueGetter: TableListItemValueGetter<T> = DefaultTableListItemValueGetter,
|
||||
itemComparer: TableListItemComparer<T> = DefaultTableListItemComparer): any[][] {
|
||||
return allItems.map(item => {
|
||||
const idx = selectedItems.findIndex(i => itemComparer(i, item));
|
||||
const stateColumnValue = { checked: idx !== -1, enabled: enabledStateGetter(item) };
|
||||
return [stateColumnValue, ...rowValueGetter(item)];
|
||||
});
|
||||
}
|
||||
|
||||
protected createTable(ariaLabel: string, columns: azdata.TableColumn[], data: any[][], maxHeight: number = DefaultMaxTableHeight): azdata.TableComponent {
|
||||
const table = this.modelView.modelBuilder.table().withProps(
|
||||
{
|
||||
ariaLabel: ariaLabel,
|
||||
data: data,
|
||||
columns: columns,
|
||||
width: DefaultTableWidth,
|
||||
height: getTableHeight(data.length, DefaultMinTableRowCount, maxHeight)
|
||||
}
|
||||
).component();
|
||||
return table;
|
||||
}
|
||||
|
||||
protected addButtonsForTable(table: azdata.TableComponent, addButtonAriaLabel: string, removeButtonAriaLabel: string, addHandler: () => Promise<void>, removeHandler: () => void): azdata.FlexContainer {
|
||||
let addButton: azdata.ButtonComponent;
|
||||
let removeButton: azdata.ButtonComponent;
|
||||
const updateButtons = () => {
|
||||
removeButton.enabled = table.selectedRows.length > 0;
|
||||
}
|
||||
addButton = this.createButton(localizedConstants.AddText, addButtonAriaLabel, async () => {
|
||||
await addHandler();
|
||||
updateButtons();
|
||||
});
|
||||
removeButton = this.createButton(localizedConstants.RemoveText, removeButtonAriaLabel, async () => {
|
||||
await removeHandler();
|
||||
updateButtons();
|
||||
}, false);
|
||||
this.disposables.push(table.onRowSelected(() => {
|
||||
updateButtons();
|
||||
}));
|
||||
return this.createButtonContainer([addButton, removeButton]);
|
||||
}
|
||||
|
||||
protected createDropdown(ariaLabel: string, handler: (newValue: string) => Promise<void>, values: string[], value: string | undefined, enabled: boolean = true, width: number = DefaultInputWidth): azdata.DropDownComponent {
|
||||
// Automatically add an empty item to the beginning of the list if the current value is not specified.
|
||||
// This is needed when no meaningful default value can be provided.
|
||||
// Create a new array so that the original array isn't modified.
|
||||
const dropdownValues = [];
|
||||
dropdownValues.push(...values);
|
||||
if (!value) {
|
||||
dropdownValues.unshift('');
|
||||
}
|
||||
const dropdown = this.modelView.modelBuilder.dropDown().withProps({
|
||||
ariaLabel: ariaLabel,
|
||||
values: dropdownValues,
|
||||
value: value,
|
||||
width: width,
|
||||
enabled: enabled
|
||||
}).component();
|
||||
this.disposables.push(dropdown.onValueChanged(async () => {
|
||||
await handler(<string>dropdown.value!);
|
||||
this.onFormFieldChange();
|
||||
await this.runValidation(false);
|
||||
}));
|
||||
return dropdown;
|
||||
}
|
||||
|
||||
protected createButton(label: string, ariaLabel: string, handler: () => Promise<void>, enabled: boolean = true): azdata.ButtonComponent {
|
||||
const button = this.modelView.modelBuilder.button().withProps({
|
||||
label: label,
|
||||
ariaLabel: ariaLabel,
|
||||
enabled: enabled,
|
||||
secondary: true,
|
||||
CSSStyles: { 'min-width': '70px', 'margin-left': '5px' }
|
||||
}).component();
|
||||
this.disposables.push(button.onDidClick(async () => {
|
||||
await handler();
|
||||
}));
|
||||
return button;
|
||||
}
|
||||
|
||||
protected createButtonContainer(items: azdata.ButtonComponent[], justifyContent: azdata.JustifyContentType = 'flex-end'): azdata.FlexContainer {
|
||||
return this.modelView.modelBuilder.flexContainer().withProps({
|
||||
CSSStyles: { 'margin': '5px 0' }
|
||||
}).withLayout({
|
||||
flexFlow: 'horizontal',
|
||||
flexWrap: 'nowrap',
|
||||
justifyContent: justifyContent
|
||||
}).withItems(items, { flex: '0 0 auto' }).component();
|
||||
}
|
||||
|
||||
protected removeItem(container: azdata.DivContainer | azdata.FlexContainer, item: azdata.Component): void {
|
||||
if (container.items.indexOf(item) !== -1) {
|
||||
container.removeItem(item);
|
||||
}
|
||||
}
|
||||
|
||||
protected addItem(container: azdata.DivContainer | azdata.FlexContainer, item: azdata.Component, index?: number): void {
|
||||
if (container.items.indexOf(item) === -1) {
|
||||
if (index === undefined) {
|
||||
container.addItem(item);
|
||||
} else {
|
||||
container.insertItem(item, index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected onLoadingStatusChanged(isLoading: boolean): void {
|
||||
if (this._loadingComponent) {
|
||||
this._loadingComponent.loading = isLoading;
|
||||
}
|
||||
}
|
||||
|
||||
private createFormContainer(items: azdata.Component[]): azdata.DivContainer {
|
||||
return this.modelView.modelBuilder.divContainer().withLayout({ width: 'calc(100% - 20px)', height: 'calc(100% - 20px)' }).withProps({
|
||||
CSSStyles: { 'padding': '10px' }
|
||||
}).withItems(items, { CSSStyles: { 'margin-block-end': '10px' } }).component();
|
||||
}
|
||||
}
|
||||
136
extensions/mssql/src/objectManagement/ui/findObjectDialog.ts
Normal file
136
extensions/mssql/src/objectManagement/ui/findObjectDialog.ts
Normal file
@@ -0,0 +1,136 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as azdata from 'azdata';
|
||||
import * as mssql from 'mssql';
|
||||
import { DefaultTableListItemEnabledStateGetter, DefaultMaxTableHeight, DialogBase, TableListItemComparer, TableListItemValueGetter } from './dialogBase';
|
||||
import * as localizedConstants from '../localizedConstants';
|
||||
import { getNodeTypeDisplayName } from '../utils';
|
||||
import { getErrorMessage } from '../../utils';
|
||||
|
||||
export interface FindObjectDialogOptions {
|
||||
objectTypes: mssql.ObjectManagement.NodeType[];
|
||||
multiSelect: boolean;
|
||||
contextId: string;
|
||||
title: string;
|
||||
}
|
||||
|
||||
export interface FindObjectDialogResult {
|
||||
selectedObjects: mssql.ObjectManagement.SearchResultItem[];
|
||||
}
|
||||
|
||||
const ObjectComparer: TableListItemComparer<mssql.ObjectManagement.SearchResultItem> =
|
||||
(item1, item2) => {
|
||||
return item1.name === item2.name && item1.type === item2.type;
|
||||
};
|
||||
|
||||
const ObjectRowValueGetter: TableListItemValueGetter<mssql.ObjectManagement.SearchResultItem> =
|
||||
(item) => {
|
||||
return [item.name, getNodeTypeDisplayName(item.type, true)];
|
||||
};
|
||||
|
||||
const ObjectsTableMaxHeight = 700;
|
||||
|
||||
export class FindObjectDialog extends DialogBase<FindObjectDialogResult> {
|
||||
private objectTypesTable: azdata.TableComponent;
|
||||
private findButton: azdata.ButtonComponent;
|
||||
private objectsTable: azdata.TableComponent;
|
||||
private objectsLoadingComponent: azdata.LoadingComponent;
|
||||
private result: FindObjectDialogResult;
|
||||
private selectedObjectTypes: string[] = [];
|
||||
private allObjects: mssql.ObjectManagement.SearchResultItem[] = [];
|
||||
|
||||
constructor(private readonly objectManagementService: mssql.IObjectManagementService, private readonly options: FindObjectDialogOptions) {
|
||||
super(options.title, 'FindObjectDialog');
|
||||
this.dialogObject.okButton.label = localizedConstants.SelectText;
|
||||
this.result = {
|
||||
selectedObjects: []
|
||||
};
|
||||
this.selectedObjectTypes = [...options.objectTypes];
|
||||
}
|
||||
|
||||
protected override async initialize(): Promise<void> {
|
||||
this.dialogObject.okButton.enabled = false;
|
||||
this.objectTypesTable = this.createTableList<string>(localizedConstants.ObjectTypeText,
|
||||
[localizedConstants.ObjectTypeText],
|
||||
this.options.objectTypes,
|
||||
this.selectedObjectTypes,
|
||||
DefaultMaxTableHeight,
|
||||
DefaultTableListItemEnabledStateGetter, (item) => {
|
||||
return [getNodeTypeDisplayName(item, true)];
|
||||
});
|
||||
this.findButton = this.createButton(localizedConstants.FindText, localizedConstants.FindText, async () => {
|
||||
await this.onFindObjectButtonClick();
|
||||
});
|
||||
const buttonContainer = this.createButtonContainer([this.findButton]);
|
||||
const objectTypeSection = this.createGroup(localizedConstants.ObjectTypeText, [this.objectTypesTable, buttonContainer]);
|
||||
|
||||
if (this.options.multiSelect) {
|
||||
this.objectsTable = this.createTableList<mssql.ObjectManagement.SearchResultItem>(localizedConstants.ObjectsText,
|
||||
[localizedConstants.NameText, localizedConstants.ObjectTypeText],
|
||||
this.allObjects,
|
||||
this.result.selectedObjects,
|
||||
ObjectsTableMaxHeight,
|
||||
DefaultTableListItemEnabledStateGetter,
|
||||
ObjectRowValueGetter,
|
||||
ObjectComparer);
|
||||
} else {
|
||||
this.objectsTable = this.createTable(localizedConstants.ObjectsText, [{
|
||||
value: localizedConstants.NameText,
|
||||
}, {
|
||||
value: localizedConstants.ObjectTypeText
|
||||
}], []);
|
||||
this.disposables.push(this.objectsTable.onRowSelected(async () => {
|
||||
if (this.objectsTable.selectedRows.length > 0) {
|
||||
this.result.selectedObjects = [this.allObjects[this.objectsTable.selectedRows[0]]];
|
||||
}
|
||||
await this.onFormFieldChange();
|
||||
}));
|
||||
}
|
||||
this.objectsLoadingComponent = this.modelView.modelBuilder.loadingComponent().withItem(this.objectsTable).withProps({
|
||||
loadingText: localizedConstants.LoadingObjectsText,
|
||||
showText: true,
|
||||
loading: false
|
||||
}).component();
|
||||
const objectsSection = this.createGroup(localizedConstants.ObjectsText, [this.objectsLoadingComponent]);
|
||||
|
||||
this.formContainer.addItems([objectTypeSection, objectsSection]);
|
||||
}
|
||||
|
||||
protected override get dialogResult(): FindObjectDialogResult | undefined {
|
||||
return this.result;
|
||||
}
|
||||
|
||||
private async onFindObjectButtonClick(): Promise<void> {
|
||||
this.dialogObject.okButton.enabled = false;
|
||||
this.objectsLoadingComponent.loading = true;
|
||||
this.findButton.enabled = false;
|
||||
try {
|
||||
const results = await this.objectManagementService.search(this.options.contextId, <mssql.ObjectManagement.NodeType[]>this.selectedObjectTypes);
|
||||
this.allObjects.splice(0, this.allObjects.length, ...results);
|
||||
let data;
|
||||
if (this.options.multiSelect) {
|
||||
data = this.getDataForTableList(this.allObjects, this.result.selectedObjects, DefaultTableListItemEnabledStateGetter, ObjectRowValueGetter, ObjectComparer);
|
||||
}
|
||||
else {
|
||||
data = this.allObjects.map(item => ObjectRowValueGetter(item));
|
||||
}
|
||||
this.setTableData(this.objectsTable, data, ObjectsTableMaxHeight);
|
||||
this.objectsLoadingComponent.loadingCompletedText = localizedConstants.LoadingObjectsCompletedText(results.length);
|
||||
} catch (err) {
|
||||
this.dialogObject.message = {
|
||||
text: getErrorMessage(err),
|
||||
level: azdata.window.MessageLevel.Error
|
||||
};
|
||||
}
|
||||
this.findButton.enabled = true;
|
||||
this.objectsLoadingComponent.loading = false;
|
||||
}
|
||||
|
||||
protected override async onFormFieldChange(): Promise<void> {
|
||||
this.findButton.enabled = this.selectedObjectTypes.length > 0;
|
||||
this.dialogObject.okButton.enabled = this.result.selectedObjects.length > 0;
|
||||
}
|
||||
}
|
||||
@@ -4,11 +4,12 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
import * as azdata from 'azdata';
|
||||
import * as vscode from 'vscode';
|
||||
import { DefaultInputWidth, ObjectManagementDialogBase, ObjectManagementDialogOptions } from './objectManagementDialogBase';
|
||||
import { ObjectManagementDialogBase, ObjectManagementDialogOptions } from './objectManagementDialogBase';
|
||||
import { IObjectManagementService, ObjectManagement } from 'mssql';
|
||||
import * as localizedConstants from '../localizedConstants';
|
||||
import { AlterLoginDocUrl, CreateLoginDocUrl, PublicServerRoleName } from '../constants';
|
||||
import { getAuthenticationTypeByDisplayName, getAuthenticationTypeDisplayName, isValidSQLPassword } from '../utils';
|
||||
import { DefaultMaxTableHeight } from './dialogBase';
|
||||
|
||||
export class LoginDialog extends ObjectManagementDialogBase<ObjectManagement.Login, ObjectManagement.LoginViewInfo> {
|
||||
private generalSection: azdata.GroupContainer;
|
||||
@@ -52,11 +53,8 @@ export class LoginDialog extends ObjectManagementDialogBase<ObjectManagement.Log
|
||||
return true;
|
||||
}
|
||||
|
||||
protected async validateInput(): Promise<string[]> {
|
||||
const errors: string[] = [];
|
||||
if (!this.objectInfo.name) {
|
||||
errors.push(localizedConstants.NameCannotBeEmptyError);
|
||||
}
|
||||
protected override async validateInput(): Promise<string[]> {
|
||||
const errors = await super.validateInput();
|
||||
if (this.objectInfo.authenticationType === ObjectManagement.AuthenticationType.Sql) {
|
||||
if (!this.objectInfo.password && !(this.viewInfo.supportAdvancedPasswordOptions && !this.objectInfo.enforcePasswordPolicy)) {
|
||||
errors.push(localizedConstants.PasswordCannotBeEmptyError);
|
||||
@@ -104,17 +102,9 @@ export class LoginDialog extends ObjectManagementDialogBase<ObjectManagement.Log
|
||||
}
|
||||
|
||||
private initializeGeneralSection(): void {
|
||||
this.nameInput = this.modelView.modelBuilder.inputBox().withProps({
|
||||
ariaLabel: localizedConstants.NameText,
|
||||
enabled: this.options.isNewObject,
|
||||
value: this.objectInfo.name,
|
||||
width: DefaultInputWidth
|
||||
}).component();
|
||||
this.disposables.push(this.nameInput.onTextChanged(async () => {
|
||||
this.objectInfo.name = this.nameInput.value!;
|
||||
this.onObjectValueChange();
|
||||
await this.runValidation(false);
|
||||
}));
|
||||
this.nameInput = this.createInputBox(localizedConstants.NameText, async (newValue) => {
|
||||
this.objectInfo.name = newValue;
|
||||
}, this.objectInfo.name, this.options.isNewObject);
|
||||
|
||||
const nameContainer = this.createLabelInputContainer(localizedConstants.NameText, this.nameInput);
|
||||
const authTypes = [];
|
||||
@@ -127,93 +117,72 @@ export class LoginDialog extends ObjectManagementDialogBase<ObjectManagement.Log
|
||||
if (this.viewInfo.supportAADAuthentication) {
|
||||
authTypes.push(localizedConstants.AADAuthenticationTypeDisplayText);
|
||||
}
|
||||
this.authTypeDropdown = this.createDropdown(localizedConstants.AuthTypeText, authTypes, getAuthenticationTypeDisplayName(this.objectInfo.authenticationType), this.options.isNewObject);
|
||||
this.disposables.push(this.authTypeDropdown.onValueChanged(async () => {
|
||||
this.objectInfo.authenticationType = getAuthenticationTypeByDisplayName(<string>this.authTypeDropdown.value);
|
||||
this.authTypeDropdown = this.createDropdown(localizedConstants.AuthTypeText, async (newValue) => {
|
||||
this.objectInfo.authenticationType = getAuthenticationTypeByDisplayName(newValue);
|
||||
this.setViewByAuthenticationType();
|
||||
this.onObjectValueChange();
|
||||
await this.runValidation(false);
|
||||
}));
|
||||
}, authTypes, getAuthenticationTypeDisplayName(this.objectInfo.authenticationType), this.options.isNewObject);
|
||||
|
||||
const authTypeContainer = this.createLabelInputContainer(localizedConstants.AuthTypeText, this.authTypeDropdown);
|
||||
|
||||
this.enabledCheckbox = this.createCheckbox(localizedConstants.EnabledText, this.objectInfo.isEnabled);
|
||||
this.disposables.push(this.enabledCheckbox.onChanged(() => {
|
||||
this.objectInfo.isEnabled = this.enabledCheckbox.checked!;
|
||||
this.onObjectValueChange();
|
||||
}));
|
||||
this.enabledCheckbox = this.createCheckbox(localizedConstants.EnabledText, async (checked) => {
|
||||
this.objectInfo.isEnabled = checked;
|
||||
}, this.objectInfo.isEnabled);
|
||||
this.generalSection = this.createGroup(localizedConstants.GeneralSectionHeader, [nameContainer, authTypeContainer, this.enabledCheckbox], false);
|
||||
}
|
||||
|
||||
private initializeSqlAuthSection(): void {
|
||||
const items: azdata.Component[] = [];
|
||||
this.passwordInput = this.createPasswordInputBox(localizedConstants.PasswordText, this.objectInfo.password ?? '');
|
||||
this.passwordInput = this.createPasswordInputBox(localizedConstants.PasswordText, async (newValue) => {
|
||||
this.objectInfo.password = newValue;
|
||||
}, this.objectInfo.password ?? '');
|
||||
const passwordRow = this.createLabelInputContainer(localizedConstants.PasswordText, this.passwordInput);
|
||||
this.confirmPasswordInput = this.createPasswordInputBox(localizedConstants.ConfirmPasswordText, this.objectInfo.password ?? '');
|
||||
this.disposables.push(this.passwordInput.onTextChanged(async () => {
|
||||
this.objectInfo.password = this.passwordInput.value;
|
||||
this.onObjectValueChange();
|
||||
await this.runValidation(false);
|
||||
}));
|
||||
this.disposables.push(this.confirmPasswordInput.onTextChanged(async () => {
|
||||
await this.runValidation(false);
|
||||
}));
|
||||
this.confirmPasswordInput = this.createPasswordInputBox(localizedConstants.ConfirmPasswordText, async () => { }, this.objectInfo.password ?? '');
|
||||
const confirmPasswordRow = this.createLabelInputContainer(localizedConstants.ConfirmPasswordText, this.confirmPasswordInput);
|
||||
items.push(passwordRow, confirmPasswordRow);
|
||||
|
||||
if (!this.options.isNewObject) {
|
||||
this.specifyOldPasswordCheckbox = this.createCheckbox(localizedConstants.SpecifyOldPasswordText);
|
||||
this.oldPasswordInput = this.createPasswordInputBox(localizedConstants.OldPasswordText, '', false);
|
||||
const oldPasswordRow = this.createLabelInputContainer(localizedConstants.OldPasswordText, this.oldPasswordInput);
|
||||
this.disposables.push(this.specifyOldPasswordCheckbox.onChanged(async () => {
|
||||
this.specifyOldPasswordCheckbox = this.createCheckbox(localizedConstants.SpecifyOldPasswordText, async (checked) => {
|
||||
this.oldPasswordInput.enabled = this.specifyOldPasswordCheckbox.checked;
|
||||
this.objectInfo.oldPassword = '';
|
||||
if (!this.specifyOldPasswordCheckbox.checked) {
|
||||
this.oldPasswordInput.value = '';
|
||||
}
|
||||
this.onObjectValueChange();
|
||||
await this.runValidation(false);
|
||||
}));
|
||||
this.disposables.push(this.oldPasswordInput.onTextChanged(async () => {
|
||||
this.objectInfo.oldPassword = this.oldPasswordInput.value;
|
||||
this.onObjectValueChange();
|
||||
await this.runValidation(false);
|
||||
}));
|
||||
});
|
||||
this.oldPasswordInput = this.createPasswordInputBox(localizedConstants.OldPasswordText, async (newValue) => {
|
||||
this.objectInfo.oldPassword = newValue;
|
||||
}, '', false);
|
||||
const oldPasswordRow = this.createLabelInputContainer(localizedConstants.OldPasswordText, this.oldPasswordInput);
|
||||
items.push(this.specifyOldPasswordCheckbox, oldPasswordRow);
|
||||
}
|
||||
|
||||
if (this.viewInfo.supportAdvancedPasswordOptions) {
|
||||
this.enforcePasswordPolicyCheckbox = this.createCheckbox(localizedConstants.EnforcePasswordPolicyText, this.objectInfo.enforcePasswordPolicy);
|
||||
this.enforcePasswordExpirationCheckbox = this.createCheckbox(localizedConstants.EnforcePasswordExpirationText, this.objectInfo.enforcePasswordPolicy);
|
||||
this.mustChangePasswordCheckbox = this.createCheckbox(localizedConstants.MustChangePasswordText, this.objectInfo.mustChangePassword);
|
||||
this.disposables.push(this.enforcePasswordPolicyCheckbox.onChanged(async () => {
|
||||
const enforcePolicy = this.enforcePasswordPolicyCheckbox.checked;
|
||||
this.enforcePasswordPolicyCheckbox = this.createCheckbox(localizedConstants.EnforcePasswordPolicyText, async (checked) => {
|
||||
const enforcePolicy = checked;
|
||||
this.objectInfo.enforcePasswordPolicy = enforcePolicy;
|
||||
this.enforcePasswordExpirationCheckbox.enabled = enforcePolicy;
|
||||
this.mustChangePasswordCheckbox.enabled = enforcePolicy;
|
||||
this.enforcePasswordExpirationCheckbox.checked = enforcePolicy;
|
||||
this.mustChangePasswordCheckbox.checked = enforcePolicy;
|
||||
this.onObjectValueChange();
|
||||
await this.runValidation(false);
|
||||
}));
|
||||
this.disposables.push(this.enforcePasswordExpirationCheckbox.onChanged(() => {
|
||||
const enforceExpiration = this.enforcePasswordExpirationCheckbox.checked;
|
||||
}, this.objectInfo.enforcePasswordPolicy);
|
||||
|
||||
this.enforcePasswordExpirationCheckbox = this.createCheckbox(localizedConstants.EnforcePasswordExpirationText, async (checked) => {
|
||||
const enforceExpiration = checked;
|
||||
this.objectInfo.enforcePasswordExpiration = enforceExpiration;
|
||||
this.mustChangePasswordCheckbox.enabled = enforceExpiration;
|
||||
this.mustChangePasswordCheckbox.checked = enforceExpiration;
|
||||
this.onObjectValueChange();
|
||||
}));
|
||||
this.disposables.push(this.mustChangePasswordCheckbox.onChanged(() => {
|
||||
this.objectInfo.mustChangePassword = this.mustChangePasswordCheckbox.checked;
|
||||
this.onObjectValueChange();
|
||||
}));
|
||||
}, this.objectInfo.enforcePasswordPolicy);
|
||||
|
||||
this.mustChangePasswordCheckbox = this.createCheckbox(localizedConstants.MustChangePasswordText, async (checked) => {
|
||||
this.objectInfo.mustChangePassword = checked;
|
||||
}, this.objectInfo.mustChangePassword);
|
||||
|
||||
items.push(this.enforcePasswordPolicyCheckbox, this.enforcePasswordExpirationCheckbox, this.mustChangePasswordCheckbox);
|
||||
|
||||
if (!this.options.isNewObject) {
|
||||
this.lockedOutCheckbox = this.createCheckbox(localizedConstants.LoginLockedOutText, this.objectInfo.isLockedOut, this.viewInfo.canEditLockedOutState);
|
||||
this.lockedOutCheckbox = this.createCheckbox(localizedConstants.LoginLockedOutText, async (checked) => {
|
||||
this.objectInfo.isLockedOut = checked;
|
||||
}, this.objectInfo.isLockedOut, this.viewInfo.canEditLockedOutState);
|
||||
items.push(this.lockedOutCheckbox);
|
||||
this.disposables.push(this.lockedOutCheckbox.onChanged(() => {
|
||||
this.objectInfo.isLockedOut = this.lockedOutCheckbox.checked!;
|
||||
this.onObjectValueChange();
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,25 +192,19 @@ export class LoginDialog extends ObjectManagementDialogBase<ObjectManagement.Log
|
||||
private initializeAdvancedSection(): void {
|
||||
const items: azdata.Component[] = [];
|
||||
if (this.viewInfo.supportAdvancedOptions) {
|
||||
this.defaultDatabaseDropdown = this.createDropdown(localizedConstants.DefaultDatabaseText, this.viewInfo.databases, this.objectInfo.defaultDatabase);
|
||||
this.defaultDatabaseDropdown = this.createDropdown(localizedConstants.DefaultDatabaseText, async (newValue) => {
|
||||
this.objectInfo.defaultDatabase = newValue;
|
||||
}, this.viewInfo.databases, this.objectInfo.defaultDatabase);
|
||||
const defaultDatabaseContainer = this.createLabelInputContainer(localizedConstants.DefaultDatabaseText, this.defaultDatabaseDropdown);
|
||||
this.disposables.push(this.defaultDatabaseDropdown.onValueChanged(() => {
|
||||
this.objectInfo.defaultDatabase = <string>this.defaultDatabaseDropdown.value;
|
||||
this.onObjectValueChange();
|
||||
}));
|
||||
|
||||
this.defaultLanguageDropdown = this.createDropdown(localizedConstants.DefaultLanguageText, this.viewInfo.languages, this.objectInfo.defaultLanguage);
|
||||
this.defaultLanguageDropdown = this.createDropdown(localizedConstants.DefaultLanguageText, async (newValue) => {
|
||||
this.objectInfo.defaultLanguage = newValue;
|
||||
}, this.viewInfo.languages, this.objectInfo.defaultLanguage);
|
||||
const defaultLanguageContainer = this.createLabelInputContainer(localizedConstants.DefaultLanguageText, this.defaultLanguageDropdown);
|
||||
this.disposables.push(this.defaultLanguageDropdown.onValueChanged(() => {
|
||||
this.objectInfo.defaultLanguage = <string>this.defaultLanguageDropdown.value;
|
||||
this.onObjectValueChange();
|
||||
}));
|
||||
|
||||
this.connectPermissionCheckbox = this.createCheckbox(localizedConstants.PermissionToConnectText, this.objectInfo.connectPermission);
|
||||
this.disposables.push(this.connectPermissionCheckbox.onChanged(() => {
|
||||
this.objectInfo.connectPermission = this.connectPermissionCheckbox.checked!;
|
||||
this.onObjectValueChange();
|
||||
}));
|
||||
this.connectPermissionCheckbox = this.createCheckbox(localizedConstants.PermissionToConnectText, async (checked) => {
|
||||
this.objectInfo.connectPermission = checked;
|
||||
}, this.objectInfo.connectPermission);
|
||||
items.push(defaultDatabaseContainer, defaultLanguageContainer, this.connectPermissionCheckbox);
|
||||
}
|
||||
|
||||
@@ -249,12 +212,14 @@ export class LoginDialog extends ObjectManagementDialogBase<ObjectManagement.Log
|
||||
}
|
||||
|
||||
private initializeServerRolesSection(): void {
|
||||
const serverRolesData = this.viewInfo.serverRoles.map(name => {
|
||||
const isRoleSelected = this.objectInfo.serverRoles.indexOf(name) !== -1;
|
||||
const isRoleSelectionEnabled = name !== PublicServerRoleName;
|
||||
return [{ enabled: isRoleSelectionEnabled, checked: isRoleSelected }, name];
|
||||
});
|
||||
this.serverRoleTable = this.createTableList(localizedConstants.ServerRoleSectionHeader, this.viewInfo.serverRoles, this.objectInfo.serverRoles, serverRolesData);
|
||||
this.serverRoleTable = this.createTableList(localizedConstants.ServerRoleSectionHeader,
|
||||
[localizedConstants.ServerRoleTypeDisplayNameInTitle],
|
||||
this.viewInfo.serverRoles,
|
||||
this.objectInfo.serverRoles,
|
||||
DefaultMaxTableHeight,
|
||||
(item) => {
|
||||
return item !== PublicServerRoleName
|
||||
});
|
||||
this.serverRoleSection = this.createGroup(localizedConstants.ServerRoleSectionHeader, [this.serverRoleTable]);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,36 +3,19 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
// TODO:
|
||||
// 1. include server properties and other properties in the telemetry.
|
||||
|
||||
import * as azdata from 'azdata';
|
||||
import { IObjectManagementService, ObjectManagement } from 'mssql';
|
||||
import * as vscode from 'vscode';
|
||||
import { EOL } from 'os';
|
||||
import { generateUuid } from 'vscode-languageclient/lib/utils/uuid';
|
||||
import { getErrorMessage } from '../../utils';
|
||||
import { TelemetryActions, ObjectManagementViewName } from '../constants';
|
||||
import {
|
||||
CreateObjectOperationDisplayName, HelpText, LoadingDialogText,
|
||||
NameText,
|
||||
NewObjectDialogTitle, NoActionScriptedMessage, ObjectPropertiesDialogTitle, OkText, ScriptError, ScriptGeneratedText, ScriptText, SelectedText, UpdateObjectOperationDisplayName
|
||||
} from '../localizedConstants';
|
||||
import { deepClone, getNodeTypeDisplayName, refreshNode } from '../utils';
|
||||
import * as localizedConstants from '../localizedConstants';
|
||||
import { deepClone, getNodeTypeDisplayName, refreshNode, refreshParentNode } from '../utils';
|
||||
import { DialogBase } from './dialogBase';
|
||||
import { ObjectManagementViewName, TelemetryActions } from '../constants';
|
||||
import { TelemetryReporter } from '../../telemetry';
|
||||
import { getErrorMessage } from '../../utils';
|
||||
import { providerId } from '../../constants';
|
||||
import { equals } from '../../util/objects';
|
||||
|
||||
export const DefaultLabelWidth = 150;
|
||||
export const DefaultInputWidth = 300;
|
||||
export const DefaultTableWidth = DefaultInputWidth + DefaultLabelWidth;
|
||||
export const DefaultTableMaxHeight = 400;
|
||||
export const DefaultTableMinRowCount = 2;
|
||||
export const TableRowHeight = 25;
|
||||
export const TableColumnHeaderHeight = 30;
|
||||
|
||||
export function getTableHeight(rowCount: number, minRowCount: number = DefaultTableMinRowCount, maxHeight: number = DefaultTableMaxHeight): number {
|
||||
return Math.min(Math.max(rowCount, minRowCount) * TableRowHeight + TableColumnHeaderHeight, maxHeight);
|
||||
}
|
||||
|
||||
function getDialogName(type: ObjectManagement.NodeType, isNewObject: boolean): string {
|
||||
return isNewObject ? `New${type}` : `${type}Properties`
|
||||
@@ -50,56 +33,90 @@ export interface ObjectManagementDialogOptions {
|
||||
objectName?: string;
|
||||
}
|
||||
|
||||
export abstract class ObjectManagementDialogBase<ObjectInfoType extends ObjectManagement.SqlObject, ViewInfoType extends ObjectManagement.ObjectViewInfo<ObjectInfoType>> {
|
||||
protected readonly disposables: vscode.Disposable[] = [];
|
||||
protected readonly dialogObject: azdata.window.Dialog;
|
||||
export abstract class ObjectManagementDialogBase<ObjectInfoType extends ObjectManagement.SqlObject, ViewInfoType extends ObjectManagement.ObjectViewInfo<ObjectInfoType>> extends DialogBase<void> {
|
||||
private _contextId: string;
|
||||
private _viewInfo: ViewInfoType;
|
||||
private _originalObjectInfo: ObjectInfoType;
|
||||
private _modelView: azdata.ModelView;
|
||||
private _loadingComponent: azdata.LoadingComponent;
|
||||
private _formContainer: azdata.DivContainer;
|
||||
private _helpButton: azdata.window.Button;
|
||||
private _scriptButton: azdata.window.Button;
|
||||
|
||||
constructor(protected readonly objectManagementService: IObjectManagementService, protected readonly options: ObjectManagementDialogOptions) {
|
||||
this.options.width = this.options.width || 'narrow';
|
||||
const objectTypeDisplayName = getNodeTypeDisplayName(options.objectType, true);
|
||||
const dialogTitle = options.isNewObject ? NewObjectDialogTitle(objectTypeDisplayName) : ObjectPropertiesDialogTitle(objectTypeDisplayName, options.objectName);
|
||||
this.dialogObject = azdata.window.createModelViewDialog(dialogTitle, getDialogName(options.objectType, options.isNewObject), options.width);
|
||||
this.dialogObject.okButton.label = OkText;
|
||||
this.disposables.push(this.dialogObject.onClosed(async (reason: azdata.window.CloseReason) => { await this.dispose(reason); }));
|
||||
this._helpButton = azdata.window.createButton(HelpText, 'left');
|
||||
super(options.isNewObject ? localizedConstants.NewObjectDialogTitle(getNodeTypeDisplayName(options.objectType, true)) :
|
||||
localizedConstants.ObjectPropertiesDialogTitle(getNodeTypeDisplayName(options.objectType, true), options.objectName),
|
||||
getDialogName(options.objectType, options.isNewObject),
|
||||
options.width || 'narrow', 'flyout'
|
||||
);
|
||||
this._helpButton = azdata.window.createButton(localizedConstants.HelpText, 'left');
|
||||
this.disposables.push(this._helpButton.onClick(async () => {
|
||||
await vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(this.docUrl));
|
||||
}));
|
||||
this._scriptButton = azdata.window.createButton(ScriptText, 'left');
|
||||
this._scriptButton = azdata.window.createButton(localizedConstants.ScriptText, 'left');
|
||||
this.disposables.push(this._scriptButton.onClick(async () => { await this.onScriptButtonClick(); }));
|
||||
this.dialogObject.customButtons = [this._helpButton, this._scriptButton];
|
||||
this.updateLoadingStatus(true);
|
||||
this._contextId = generateUuid();
|
||||
this.dialogObject.registerCloseValidator(async (): Promise<boolean> => {
|
||||
const confirmed = await this.onConfirmation();
|
||||
if (!confirmed) {
|
||||
return false;
|
||||
}
|
||||
return await this.runValidation();
|
||||
});
|
||||
}
|
||||
|
||||
protected abstract initializeUI(): Promise<void>;
|
||||
protected abstract validateInput(): Promise<string[]>;
|
||||
|
||||
protected abstract get docUrl(): string;
|
||||
|
||||
protected postInitializeData(): void {
|
||||
protected postInitializeData(): void { }
|
||||
|
||||
}
|
||||
protected onObjectValueChange(): void {
|
||||
protected override onFormFieldChange(): void {
|
||||
this._scriptButton.enabled = this.isDirty;
|
||||
this.dialogObject.okButton.enabled = this.isDirty;
|
||||
}
|
||||
|
||||
protected async onConfirmation(): Promise<boolean> {
|
||||
return true;
|
||||
protected override async validateInput(): Promise<string[]> {
|
||||
const errors: string[] = [];
|
||||
if (!this.objectInfo.name) {
|
||||
errors.push(localizedConstants.NameCannotBeEmptyError);
|
||||
}
|
||||
return errors;
|
||||
}
|
||||
|
||||
protected override async initialize(): Promise<void> {
|
||||
await this.initializeData();
|
||||
await this.initializeUI();
|
||||
const typeDisplayName = getNodeTypeDisplayName(this.options.objectType);
|
||||
this.dialogObject.registerOperation({
|
||||
displayName: this.options.isNewObject ? localizedConstants.CreateObjectOperationDisplayName(typeDisplayName)
|
||||
: localizedConstants.UpdateObjectOperationDisplayName(typeDisplayName, this.options.objectName),
|
||||
description: '',
|
||||
isCancelable: false,
|
||||
operation: async (operation: azdata.BackgroundOperation): Promise<void> => {
|
||||
const actionName = this.options.isNewObject ? TelemetryActions.CreateObject : TelemetryActions.UpdateObject;
|
||||
try {
|
||||
if (this.isDirty) {
|
||||
const startTime = Date.now();
|
||||
await this.objectManagementService.save(this._contextId, this.objectInfo);
|
||||
if (this.options.objectExplorerContext) {
|
||||
if (this.options.isNewObject) {
|
||||
await refreshNode(this.options.objectExplorerContext);
|
||||
} else {
|
||||
// For edit mode, the node context is the object itself, we need to refresh the parent node to reflect the changes.
|
||||
await refreshParentNode(this.options.objectExplorerContext);
|
||||
}
|
||||
}
|
||||
|
||||
TelemetryReporter.sendTelemetryEvent(actionName, {
|
||||
objectType: this.options.objectType
|
||||
}, {
|
||||
elapsedTimeMs: Date.now() - startTime
|
||||
});
|
||||
operation.updateStatus(azdata.TaskStatus.Succeeded);
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
operation.updateStatus(azdata.TaskStatus.Failed, getErrorMessage(err));
|
||||
TelemetryReporter.createErrorEvent2(ObjectManagementViewName, actionName, err).withAdditionalProperties({
|
||||
objectType: this.options.objectType
|
||||
}).send();
|
||||
} finally {
|
||||
await this.disposeView();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected get viewInfo(): ViewInfoType {
|
||||
@@ -114,85 +131,12 @@ export abstract class ObjectManagementDialogBase<ObjectInfoType extends ObjectMa
|
||||
return this._originalObjectInfo;
|
||||
}
|
||||
|
||||
protected get formContainer(): azdata.DivContainer {
|
||||
return this._formContainer;
|
||||
protected get contextId(): string {
|
||||
return this._contextId;
|
||||
}
|
||||
|
||||
protected get modelView(): azdata.ModelView {
|
||||
return this._modelView;
|
||||
}
|
||||
|
||||
public async open(): Promise<void> {
|
||||
try {
|
||||
const initializeViewPromise = new Promise<void>((async resolve => {
|
||||
await this.dialogObject.registerContent(async view => {
|
||||
this._modelView = view;
|
||||
resolve();
|
||||
this._formContainer = this.createFormContainer([]);
|
||||
this._loadingComponent = view.modelBuilder.loadingComponent().withItem(this._formContainer).withProps({
|
||||
loading: true,
|
||||
loadingText: LoadingDialogText,
|
||||
showText: true,
|
||||
CSSStyles: {
|
||||
width: "100%",
|
||||
height: "100%"
|
||||
}
|
||||
}).component();
|
||||
await view.initializeModel(this._loadingComponent);
|
||||
});
|
||||
}));
|
||||
azdata.window.openDialog(this.dialogObject);
|
||||
await this.initializeData();
|
||||
await initializeViewPromise;
|
||||
await this.initializeUI();
|
||||
this._originalObjectInfo = deepClone(this.objectInfo);
|
||||
const typeDisplayName = getNodeTypeDisplayName(this.options.objectType);
|
||||
this.dialogObject.registerOperation({
|
||||
displayName: this.options.isNewObject ? CreateObjectOperationDisplayName(typeDisplayName)
|
||||
: UpdateObjectOperationDisplayName(typeDisplayName, this.options.objectName),
|
||||
description: '',
|
||||
isCancelable: false,
|
||||
operation: async (operation: azdata.BackgroundOperation): Promise<void> => {
|
||||
const actionName = this.options.isNewObject ? TelemetryActions.CreateObject : TelemetryActions.UpdateObject;
|
||||
try {
|
||||
if (JSON.stringify(this.objectInfo) !== JSON.stringify(this._originalObjectInfo)) {
|
||||
const startTime = Date.now();
|
||||
await this.objectManagementService.save(this._contextId, this.objectInfo);
|
||||
if (this.options.isNewObject && this.options.objectExplorerContext) {
|
||||
await refreshNode(this.options.objectExplorerContext);
|
||||
}
|
||||
|
||||
TelemetryReporter.sendTelemetryEvent(actionName, {
|
||||
objectType: this.options.objectType
|
||||
}, {
|
||||
elapsedTimeMs: Date.now() - startTime
|
||||
});
|
||||
operation.updateStatus(azdata.TaskStatus.Succeeded);
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
operation.updateStatus(azdata.TaskStatus.Failed, getErrorMessage(err));
|
||||
TelemetryReporter.createErrorEvent2(ObjectManagementViewName, actionName, err).withAdditionalProperties({
|
||||
objectType: this.options.objectType
|
||||
}).send();
|
||||
} finally {
|
||||
await this.disposeView();
|
||||
}
|
||||
}
|
||||
});
|
||||
this.updateLoadingStatus(false);
|
||||
} catch (err) {
|
||||
const actionName = this.options.isNewObject ? TelemetryActions.OpenNewObjectDialog : TelemetryActions.OpenPropertiesDialog;
|
||||
TelemetryReporter.createErrorEvent2(ObjectManagementViewName, actionName, err).withAdditionalProperties({
|
||||
objectType: this.options.objectType
|
||||
}).send();
|
||||
void vscode.window.showErrorMessage(getErrorMessage(err));
|
||||
azdata.window.closeDialog(this.dialogObject);
|
||||
}
|
||||
}
|
||||
|
||||
private async dispose(reason: azdata.window.CloseReason): Promise<void> {
|
||||
this.disposables.forEach(disposable => disposable.dispose());
|
||||
protected override async dispose(reason: azdata.window.CloseReason): Promise<void> {
|
||||
await super.dispose(reason);
|
||||
if (reason !== 'ok') {
|
||||
await this.disposeView();
|
||||
}
|
||||
@@ -206,140 +150,17 @@ export abstract class ObjectManagementDialogBase<ObjectInfoType extends ObjectMa
|
||||
const viewInfo = await this.objectManagementService.initializeView(this._contextId, this.options.objectType, this.options.connectionUri, this.options.database, this.options.isNewObject, this.options.parentUrn, this.options.objectUrn);
|
||||
this._viewInfo = viewInfo as ViewInfoType;
|
||||
this.postInitializeData();
|
||||
this._originalObjectInfo = deepClone(this.objectInfo);
|
||||
}
|
||||
|
||||
protected async runValidation(showErrorMessage: boolean = true): Promise<boolean> {
|
||||
const errors = await this.validateInput();
|
||||
if (errors.length > 0 && (this.dialogObject.message?.text || showErrorMessage)) {
|
||||
this.dialogObject.message = {
|
||||
text: errors.join(EOL),
|
||||
level: azdata.window.MessageLevel.Error
|
||||
};
|
||||
} else {
|
||||
this.dialogObject.message = undefined;
|
||||
}
|
||||
return errors.length === 0;
|
||||
}
|
||||
|
||||
protected createLabelInputContainer(label: string, input: azdata.InputBoxComponent | azdata.DropDownComponent): azdata.FlexContainer {
|
||||
const labelComponent = this.modelView.modelBuilder.text().withProps({ width: DefaultLabelWidth, value: label, requiredIndicator: input.required }).component();
|
||||
const row = this.modelView.modelBuilder.flexContainer().withLayout({ flexFlow: 'horizontal', flexWrap: 'nowrap', alignItems: 'center' }).withItems([labelComponent, input]).component();
|
||||
return row;
|
||||
}
|
||||
|
||||
protected createCheckbox(label: string, checked: boolean = false, enabled: boolean = true): azdata.CheckBoxComponent {
|
||||
return this.modelView.modelBuilder.checkBox().withProps({
|
||||
label: label,
|
||||
checked: checked,
|
||||
enabled: enabled
|
||||
}).component();
|
||||
}
|
||||
|
||||
protected createPasswordInputBox(ariaLabel: string, value: string = '', enabled: boolean = true, width: number = DefaultInputWidth): azdata.InputBoxComponent {
|
||||
return this.createInputBox(ariaLabel, value, enabled, 'password', width);
|
||||
}
|
||||
|
||||
protected createInputBox(ariaLabel: string, value: string = '', enabled: boolean = true, type: azdata.InputBoxInputType = 'text', width: number = DefaultInputWidth): azdata.InputBoxComponent {
|
||||
return this.modelView.modelBuilder.inputBox().withProps({ inputType: type, enabled: enabled, ariaLabel: ariaLabel, value: value, width: width }).component();
|
||||
}
|
||||
|
||||
protected createGroup(header: string, items: azdata.Component[], collapsible: boolean = true, collapsed: boolean = false): azdata.GroupContainer {
|
||||
return this.modelView.modelBuilder.groupContainer().withLayout({
|
||||
header: header,
|
||||
collapsible: collapsible,
|
||||
collapsed: collapsed
|
||||
}).withItems(items).component();
|
||||
}
|
||||
|
||||
protected createFormContainer(items: azdata.Component[]): azdata.DivContainer {
|
||||
return this.modelView.modelBuilder.divContainer().withLayout({ width: 'calc(100% - 20px)', height: 'calc(100% - 20px)' }).withProps({
|
||||
CSSStyles: { 'padding': '10px' }
|
||||
}).withItems(items, { CSSStyles: { 'margin-block-end': '10px' } }).component();
|
||||
}
|
||||
|
||||
protected createTableList(ariaLabel: string, listValues: string[], selectedValues: string[], data?: any[][]): azdata.TableComponent {
|
||||
let tableData = data;
|
||||
if (tableData === undefined) {
|
||||
tableData = listValues.map(name => {
|
||||
const isSelected = selectedValues.indexOf(name) !== -1;
|
||||
return [isSelected, name];
|
||||
});
|
||||
}
|
||||
const table = this.modelView.modelBuilder.table().withProps(
|
||||
{
|
||||
ariaLabel: ariaLabel,
|
||||
data: tableData,
|
||||
columns: [
|
||||
{
|
||||
value: SelectedText,
|
||||
type: azdata.ColumnType.checkBox,
|
||||
options: { actionOnCheckbox: azdata.ActionOnCellCheckboxCheck.customAction }
|
||||
}, {
|
||||
value: NameText,
|
||||
}
|
||||
],
|
||||
width: DefaultTableWidth,
|
||||
height: getTableHeight(tableData.length)
|
||||
}
|
||||
).component();
|
||||
this.disposables.push(table.onCellAction!((arg: azdata.ICheckboxCellActionEventArgs) => {
|
||||
const name = listValues[arg.row];
|
||||
const idx = selectedValues.indexOf(name);
|
||||
if (arg.checked && idx === -1) {
|
||||
selectedValues.push(name);
|
||||
} else if (!arg.checked && idx !== -1) {
|
||||
selectedValues.splice(idx, 1)
|
||||
}
|
||||
this.onObjectValueChange();
|
||||
}));
|
||||
return table;
|
||||
}
|
||||
|
||||
protected createDropdown(ariaLabel: string, values: string[], value: string | undefined, enabled: boolean = true, width: number = DefaultInputWidth): azdata.DropDownComponent {
|
||||
// Automatically add an empty item to the beginning of the list if the current value is not specified.
|
||||
// This is needed when no meaningful default value can be provided.
|
||||
// Create a new array so that the original array isn't modified.
|
||||
const dropdownValues = [];
|
||||
dropdownValues.push(...values);
|
||||
if (!value) {
|
||||
dropdownValues.unshift('');
|
||||
}
|
||||
return this.modelView.modelBuilder.dropDown().withProps({
|
||||
ariaLabel: ariaLabel,
|
||||
values: dropdownValues,
|
||||
value: value,
|
||||
width: width,
|
||||
enabled: enabled
|
||||
}).component();
|
||||
}
|
||||
|
||||
protected removeItem(container: azdata.DivContainer | azdata.FlexContainer, item: azdata.Component): void {
|
||||
if (container.items.indexOf(item) !== -1) {
|
||||
container.removeItem(item);
|
||||
}
|
||||
}
|
||||
|
||||
protected addItem(container: azdata.DivContainer | azdata.FlexContainer, item: azdata.Component, index?: number): void {
|
||||
if (container.items.indexOf(item) === -1) {
|
||||
if (index === undefined) {
|
||||
container.addItem(item);
|
||||
} else {
|
||||
container.insertItem(item, index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private updateLoadingStatus(isLoading: boolean): void {
|
||||
this._scriptButton.enabled = !isLoading;
|
||||
protected override onLoadingStatusChanged(isLoading: boolean): void {
|
||||
super.onLoadingStatusChanged(isLoading);
|
||||
this._helpButton.enabled = !isLoading;
|
||||
this.dialogObject.okButton.enabled = isLoading ? false : this.isDirty;
|
||||
if (this._loadingComponent) {
|
||||
this._loadingComponent.loading = isLoading;
|
||||
}
|
||||
this.dialogObject.okButton.enabled = this._scriptButton.enabled = isLoading ? false : this.isDirty;
|
||||
}
|
||||
|
||||
private async onScriptButtonClick(): Promise<void> {
|
||||
this.updateLoadingStatus(true);
|
||||
this.onLoadingStatusChanged(true);
|
||||
try {
|
||||
const isValid = await this.runValidation();
|
||||
if (!isValid) {
|
||||
@@ -348,10 +169,10 @@ export abstract class ObjectManagementDialogBase<ObjectInfoType extends ObjectMa
|
||||
let message: string;
|
||||
const script = await this.objectManagementService.script(this._contextId, this.objectInfo);
|
||||
if (script) {
|
||||
message = ScriptGeneratedText;
|
||||
message = localizedConstants.ScriptGeneratedText;
|
||||
await azdata.queryeditor.openQueryDocument({ content: script }, providerId);
|
||||
} else {
|
||||
message = NoActionScriptedMessage;
|
||||
message = localizedConstants.NoActionScriptedMessage;
|
||||
}
|
||||
this.dialogObject.message = {
|
||||
text: message,
|
||||
@@ -359,15 +180,15 @@ export abstract class ObjectManagementDialogBase<ObjectInfoType extends ObjectMa
|
||||
};
|
||||
} catch (err) {
|
||||
this.dialogObject.message = {
|
||||
text: ScriptError(getErrorMessage(err)),
|
||||
text: localizedConstants.ScriptError(getErrorMessage(err)),
|
||||
level: azdata.window.MessageLevel.Error
|
||||
};
|
||||
} finally {
|
||||
this.updateLoadingStatus(false);
|
||||
this.onLoadingStatusChanged(false);
|
||||
}
|
||||
}
|
||||
|
||||
private get isDirty(): boolean {
|
||||
return JSON.stringify(this.objectInfo) !== JSON.stringify(this._originalObjectInfo);
|
||||
return !equals(this.objectInfo, this._originalObjectInfo, false);
|
||||
}
|
||||
}
|
||||
|
||||
128
extensions/mssql/src/objectManagement/ui/serverRoleDialog.ts
Normal file
128
extensions/mssql/src/objectManagement/ui/serverRoleDialog.ts
Normal file
@@ -0,0 +1,128 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
import * as azdata from 'azdata';
|
||||
import { ObjectManagementDialogBase, ObjectManagementDialogOptions } from './objectManagementDialogBase';
|
||||
import { IObjectManagementService, ObjectManagement } from 'mssql';
|
||||
import * as localizedConstants from '../localizedConstants';
|
||||
import { AlterServerRoleDocUrl, CreateServerRoleDocUrl } from '../constants';
|
||||
import { FindObjectDialog } from './findObjectDialog';
|
||||
|
||||
export class ServerRoleDialog extends ObjectManagementDialogBase<ObjectManagement.ServerRoleInfo, ObjectManagement.ServerRoleViewInfo> {
|
||||
// Sections
|
||||
private generalSection: azdata.GroupContainer;
|
||||
private membershipSection: azdata.GroupContainer;
|
||||
private memberSection: azdata.GroupContainer;
|
||||
|
||||
// General section content
|
||||
private nameInput: azdata.InputBoxComponent;
|
||||
private ownerInput: azdata.InputBoxComponent;
|
||||
|
||||
// Member section content
|
||||
private memberTable: azdata.TableComponent;
|
||||
|
||||
// Membership section content
|
||||
private membershipTable: azdata.TableComponent;
|
||||
|
||||
|
||||
constructor(objectManagementService: IObjectManagementService, options: ObjectManagementDialogOptions) {
|
||||
super(objectManagementService, options);
|
||||
}
|
||||
|
||||
protected override get docUrl(): string {
|
||||
return this.options.isNewObject ? CreateServerRoleDocUrl : AlterServerRoleDocUrl;
|
||||
}
|
||||
|
||||
protected async initializeUI(): Promise<void> {
|
||||
this.initializeGeneralSection();
|
||||
this.initializeMemberSection();
|
||||
const sections: azdata.Component[] = [this.generalSection, this.memberSection];
|
||||
if (!this.viewInfo.isFixedRole) {
|
||||
this.initializeMembershipSection();
|
||||
sections.push(this.membershipSection);
|
||||
}
|
||||
this.formContainer.addItems(sections);
|
||||
}
|
||||
|
||||
private initializeGeneralSection(): void {
|
||||
this.nameInput = this.createInputBox(localizedConstants.NameText, async (newValue) => {
|
||||
this.objectInfo.name = newValue;
|
||||
}, this.objectInfo.name, this.options.isNewObject);
|
||||
const nameContainer = this.createLabelInputContainer(localizedConstants.NameText, this.nameInput);
|
||||
|
||||
this.ownerInput = this.createInputBox(localizedConstants.OwnerText, async (newValue) => {
|
||||
this.objectInfo.owner = newValue;
|
||||
}, this.objectInfo.owner, !this.viewInfo.isFixedRole, 'text', 210);
|
||||
const browseOwnerButton = this.createButton(localizedConstants.BrowseText, localizedConstants.BrowseOwnerButtonAriaLabel, async () => {
|
||||
const dialog = new FindObjectDialog(this.objectManagementService, {
|
||||
objectTypes: [ObjectManagement.NodeType.ServerLevelLogin, ObjectManagement.NodeType.ServerLevelServerRole],
|
||||
multiSelect: false,
|
||||
contextId: this.contextId,
|
||||
title: localizedConstants.SelectServerRoleOwnerDialogTitle
|
||||
});
|
||||
await dialog.open();
|
||||
const result = await dialog.waitForClose();
|
||||
if (result.selectedObjects.length > 0) {
|
||||
this.ownerInput.value = result.selectedObjects[0].name;
|
||||
}
|
||||
}, !this.viewInfo.isFixedRole);
|
||||
const ownerContainer = this.createLabelInputContainer(localizedConstants.OwnerText, this.ownerInput);
|
||||
ownerContainer.addItems([browseOwnerButton], { flex: '0 0 auto' });
|
||||
this.generalSection = this.createGroup(localizedConstants.GeneralSectionHeader, [
|
||||
nameContainer,
|
||||
ownerContainer
|
||||
], false);
|
||||
}
|
||||
|
||||
private initializeMemberSection(): void {
|
||||
this.memberTable = this.createTable(localizedConstants.MemberSectionHeader, [
|
||||
{
|
||||
type: azdata.ColumnType.text,
|
||||
value: localizedConstants.NameText
|
||||
}
|
||||
], this.objectInfo.members.map(m => [m]));
|
||||
const buttonContainer = this.addButtonsForTable(this.memberTable, localizedConstants.AddMemberAriaLabel, localizedConstants.RemoveMemberAriaLabel,
|
||||
async () => {
|
||||
const dialog = new FindObjectDialog(this.objectManagementService, {
|
||||
objectTypes: [ObjectManagement.NodeType.ServerLevelLogin, ObjectManagement.NodeType.ServerLevelServerRole],
|
||||
multiSelect: true,
|
||||
contextId: this.contextId,
|
||||
title: localizedConstants.SelectServerRoleMemberDialogTitle
|
||||
});
|
||||
await dialog.open();
|
||||
const result = await dialog.waitForClose();
|
||||
this.addMembers(result.selectedObjects.map(r => r.name));
|
||||
},
|
||||
async () => {
|
||||
if (this.memberTable.selectedRows.length === 1) {
|
||||
this.removeMember(this.memberTable.selectedRows[0]);
|
||||
}
|
||||
});
|
||||
this.memberSection = this.createGroup(localizedConstants.MemberSectionHeader, [this.memberTable, buttonContainer]);
|
||||
}
|
||||
|
||||
private addMembers(names: string[]): void {
|
||||
names.forEach(n => {
|
||||
if (this.objectInfo.members.indexOf(n) === -1) {
|
||||
this.objectInfo.members.push(n);
|
||||
}
|
||||
});
|
||||
this.updateMembersTable();
|
||||
}
|
||||
|
||||
private removeMember(idx: number): void {
|
||||
this.objectInfo.members.splice(idx, 1);
|
||||
this.updateMembersTable();
|
||||
}
|
||||
|
||||
private updateMembersTable(): void {
|
||||
this.setTableData(this.memberTable, this.objectInfo.members.map(m => [m]));
|
||||
this.onFormFieldChange();
|
||||
}
|
||||
|
||||
private initializeMembershipSection(): void {
|
||||
this.membershipTable = this.createTableList<string>(localizedConstants.MembershipSectionHeader, [localizedConstants.ServerRoleTypeDisplayNameInTitle], this.viewInfo.serverRoles, this.objectInfo.memberships);
|
||||
this.membershipSection = this.createGroup(localizedConstants.MembershipSectionHeader, [this.membershipTable]);
|
||||
}
|
||||
}
|
||||
@@ -3,11 +3,12 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
import * as azdata from 'azdata';
|
||||
import { DefaultInputWidth, ObjectManagementDialogBase, ObjectManagementDialogOptions } from './objectManagementDialogBase';
|
||||
import { ObjectManagementDialogBase, ObjectManagementDialogOptions } from './objectManagementDialogBase';
|
||||
import { IObjectManagementService, ObjectManagement } from 'mssql';
|
||||
import * as localizedConstants from '../localizedConstants';
|
||||
import { AlterUserDocUrl, CreateUserDocUrl } from '../constants';
|
||||
import { getAuthenticationTypeByDisplayName, getAuthenticationTypeDisplayName, getUserTypeByDisplayName, getUserTypeDisplayName, isValidSQLPassword } from '../utils';
|
||||
import { DefaultMaxTableHeight } from './dialogBase';
|
||||
|
||||
export class UserDialog extends ObjectManagementDialogBase<ObjectManagement.User, ObjectManagement.UserViewInfo> {
|
||||
private generalSection: azdata.GroupContainer;
|
||||
@@ -43,11 +44,8 @@ export class UserDialog extends ObjectManagementDialogBase<ObjectManagement.User
|
||||
this.objectInfo.password = this.objectInfo.password ?? '';
|
||||
}
|
||||
|
||||
protected async validateInput(): Promise<string[]> {
|
||||
const errors: string[] = [];
|
||||
if (!this.objectInfo.name) {
|
||||
errors.push(localizedConstants.NameCannotBeEmptyError);
|
||||
}
|
||||
protected override async validateInput(): Promise<string[]> {
|
||||
const errors = await super.validateInput();
|
||||
if (this.objectInfo.type === ObjectManagement.UserType.Contained && this.objectInfo.authenticationType === ObjectManagement.AuthenticationType.Sql) {
|
||||
if (!this.objectInfo.password) {
|
||||
errors.push(localizedConstants.PasswordCannotBeEmptyError);
|
||||
@@ -79,41 +77,27 @@ export class UserDialog extends ObjectManagementDialogBase<ObjectManagement.User
|
||||
}
|
||||
|
||||
private initializeGeneralSection(): void {
|
||||
this.nameInput = this.modelView.modelBuilder.inputBox().withProps({
|
||||
ariaLabel: localizedConstants.NameText,
|
||||
enabled: this.options.isNewObject,
|
||||
value: this.objectInfo.name,
|
||||
width: DefaultInputWidth
|
||||
}).component();
|
||||
this.disposables.push(this.nameInput.onTextChanged(async () => {
|
||||
this.objectInfo.name = this.nameInput.value!;
|
||||
this.onObjectValueChange();
|
||||
await this.runValidation(false);
|
||||
}));
|
||||
this.nameInput = this.createInputBox(localizedConstants.NameText, async (newValue) => {
|
||||
this.objectInfo.name = newValue;
|
||||
}, this.objectInfo.name, this.options.isNewObject);
|
||||
const nameContainer = this.createLabelInputContainer(localizedConstants.NameText, this.nameInput);
|
||||
this.defaultSchemaDropdown = this.createDropdown(localizedConstants.DefaultSchemaText, this.viewInfo.schemas, this.objectInfo.defaultSchema!);
|
||||
|
||||
this.defaultSchemaDropdown = this.createDropdown(localizedConstants.DefaultSchemaText, async (newValue) => {
|
||||
this.objectInfo.defaultSchema = newValue;
|
||||
}, this.viewInfo.schemas, this.objectInfo.defaultSchema!);
|
||||
this.defaultSchemaContainer = this.createLabelInputContainer(localizedConstants.DefaultSchemaText, this.defaultSchemaDropdown);
|
||||
this.disposables.push(this.defaultSchemaDropdown.onValueChanged(() => {
|
||||
this.objectInfo.defaultSchema = <string>this.defaultSchemaDropdown.value;
|
||||
this.onObjectValueChange();
|
||||
}));
|
||||
|
||||
// only supporting user with login for initial preview
|
||||
const userTypes = [localizedConstants.UserWithLoginText, localizedConstants.UserWithWindowsGroupLoginText, localizedConstants.ContainedUserText, localizedConstants.UserWithNoConnectAccess];
|
||||
this.typeDropdown = this.createDropdown(localizedConstants.UserTypeText, userTypes, getUserTypeDisplayName(this.objectInfo.type), this.options.isNewObject);
|
||||
this.disposables.push(this.typeDropdown.onValueChanged(async () => {
|
||||
this.objectInfo.type = getUserTypeByDisplayName(<string>this.typeDropdown.value);
|
||||
this.onObjectValueChange();
|
||||
this.typeDropdown = this.createDropdown(localizedConstants.UserTypeText, async (newValue) => {
|
||||
this.objectInfo.type = getUserTypeByDisplayName(newValue);
|
||||
this.setViewByUserType();
|
||||
await this.runValidation(false);
|
||||
}));
|
||||
}, userTypes, getUserTypeDisplayName(this.objectInfo.type), this.options.isNewObject);
|
||||
this.typeContainer = this.createLabelInputContainer(localizedConstants.UserTypeText, this.typeDropdown);
|
||||
this.loginDropdown = this.createDropdown(localizedConstants.LoginText, this.viewInfo.logins, this.objectInfo.loginName, this.options.isNewObject);
|
||||
this.disposables.push(this.loginDropdown.onValueChanged(async () => {
|
||||
this.objectInfo.loginName = <string>this.loginDropdown.value;
|
||||
this.onObjectValueChange();
|
||||
await this.runValidation(false);
|
||||
}));
|
||||
|
||||
this.loginDropdown = this.createDropdown(localizedConstants.LoginText, async (newValue) => {
|
||||
this.objectInfo.loginName = newValue;
|
||||
}, this.viewInfo.logins, this.objectInfo.loginName, this.options.isNewObject);
|
||||
this.loginContainer = this.createLabelInputContainer(localizedConstants.LoginText, this.loginDropdown);
|
||||
|
||||
const authTypes = [];
|
||||
@@ -126,27 +110,18 @@ export class UserDialog extends ObjectManagementDialogBase<ObjectManagement.User
|
||||
if (this.viewInfo.supportAADAuthentication) {
|
||||
authTypes.push(localizedConstants.AADAuthenticationTypeDisplayText);
|
||||
}
|
||||
this.authTypeDropdown = this.createDropdown(localizedConstants.AuthTypeText, authTypes, getAuthenticationTypeDisplayName(this.objectInfo.authenticationType), this.options.isNewObject);
|
||||
this.authTypeContainer = this.createLabelInputContainer(localizedConstants.AuthTypeText, this.authTypeDropdown);
|
||||
this.disposables.push(this.authTypeDropdown.onValueChanged(async () => {
|
||||
this.objectInfo.authenticationType = getAuthenticationTypeByDisplayName(<string>this.authTypeDropdown.value);
|
||||
this.onObjectValueChange();
|
||||
this.authTypeDropdown = this.createDropdown(localizedConstants.AuthTypeText, async (newValue) => {
|
||||
this.objectInfo.authenticationType = getAuthenticationTypeByDisplayName(newValue);
|
||||
this.setViewByAuthenticationType();
|
||||
await this.runValidation(false);
|
||||
}));
|
||||
}, authTypes, getAuthenticationTypeDisplayName(this.objectInfo.authenticationType), this.options.isNewObject);
|
||||
this.authTypeContainer = this.createLabelInputContainer(localizedConstants.AuthTypeText, this.authTypeDropdown);
|
||||
|
||||
this.passwordInput = this.createPasswordInputBox(localizedConstants.PasswordText, this.objectInfo.password ?? '');
|
||||
this.passwordInput = this.createPasswordInputBox(localizedConstants.PasswordText, async (newValue) => {
|
||||
this.objectInfo.password = newValue;
|
||||
}, this.objectInfo.password ?? '');
|
||||
this.passwordContainer = this.createLabelInputContainer(localizedConstants.PasswordText, this.passwordInput);
|
||||
this.confirmPasswordInput = this.createPasswordInputBox(localizedConstants.ConfirmPasswordText, this.objectInfo.password ?? '');
|
||||
this.confirmPasswordInput = this.createPasswordInputBox(localizedConstants.ConfirmPasswordText, async () => { }, this.objectInfo.password ?? '');
|
||||
this.confirmPasswordContainer = this.createLabelInputContainer(localizedConstants.ConfirmPasswordText, this.confirmPasswordInput);
|
||||
this.disposables.push(this.passwordInput.onTextChanged(async () => {
|
||||
this.objectInfo.password = this.passwordInput.value;
|
||||
this.onObjectValueChange();
|
||||
await this.runValidation(false);
|
||||
}));
|
||||
this.disposables.push(this.confirmPasswordInput.onTextChanged(async () => {
|
||||
await this.runValidation(false);
|
||||
}));
|
||||
|
||||
this.generalSection = this.createGroup(localizedConstants.GeneralSectionHeader, [
|
||||
nameContainer,
|
||||
@@ -160,25 +135,27 @@ export class UserDialog extends ObjectManagementDialogBase<ObjectManagement.User
|
||||
}
|
||||
|
||||
private initializeOwnedSchemaSection(): void {
|
||||
const ownedSchemaData = this.viewInfo.schemas.map(name => {
|
||||
const isSelected = this.objectInfo.ownedSchemas.indexOf(name) !== -1;
|
||||
return [{ enabled: !isSelected, checked: isSelected }, name];
|
||||
});
|
||||
this.ownedSchemaTable = this.createTableList(localizedConstants.OwnedSchemaSectionHeader, this.viewInfo.schemas, this.objectInfo.ownedSchemas, ownedSchemaData);
|
||||
this.ownedSchemaTable = this.createTableList<string>(localizedConstants.OwnedSchemaSectionHeader,
|
||||
[localizedConstants.SchemaText],
|
||||
this.viewInfo.schemas,
|
||||
this.objectInfo.ownedSchemas,
|
||||
DefaultMaxTableHeight,
|
||||
(item) => {
|
||||
// It is not allowed to have unassigned schema.
|
||||
return this.objectInfo.ownedSchemas.indexOf(item) === -1;
|
||||
});
|
||||
this.ownedSchemaSection = this.createGroup(localizedConstants.OwnedSchemaSectionHeader, [this.ownedSchemaTable]);
|
||||
}
|
||||
|
||||
private initializeMembershipSection(): void {
|
||||
this.membershipTable = this.createTableList(localizedConstants.MembershipSectionHeader, this.viewInfo.databaseRoles, this.objectInfo.databaseRoles);
|
||||
this.membershipTable = this.createTableList<string>(localizedConstants.MembershipSectionHeader, [localizedConstants.DatabaseRoleTypeDisplayNameInTitle], this.viewInfo.databaseRoles, this.objectInfo.databaseRoles);
|
||||
this.membershipSection = this.createGroup(localizedConstants.MembershipSectionHeader, [this.membershipTable]);
|
||||
}
|
||||
|
||||
private initializeAdvancedSection(): void {
|
||||
this.defaultLanguageDropdown = this.createDropdown(localizedConstants.DefaultLanguageText, this.viewInfo.languages, this.objectInfo.defaultLanguage);
|
||||
this.disposables.push(this.defaultLanguageDropdown.onValueChanged(() => {
|
||||
this.objectInfo.defaultLanguage = <string>this.defaultLanguageDropdown.value;
|
||||
this.onObjectValueChange();
|
||||
}));
|
||||
this.defaultLanguageDropdown = this.createDropdown(localizedConstants.DefaultLanguageText, async (newValue) => {
|
||||
this.objectInfo.defaultLanguage = newValue;
|
||||
}, this.viewInfo.languages, this.objectInfo.defaultLanguage);
|
||||
const container = this.createLabelInputContainer(localizedConstants.DefaultLanguageText, this.defaultLanguageDropdown);
|
||||
this.advancedSection = this.createGroup(localizedConstants.AdvancedSectionHeader, [container]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user