mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-08 09:38:26 -05:00
* saving wip to merge main * temp fixes for textValidation* removal * save wip to switch tasks * save wip to switch tasks * save wip to switch tasks * code complete - with known bugs * missed test file * fix extHostModelView changes * validation module * missed test changes * missed change * pr feedback * pr feedback * revert inadvertent change * remove unneeded change * merge from bug/12082-2 * pr feedback * pr feedback * bdd -> tdd for validation tests * bdd -> tdd for validation tests * pr feedback * remove unneeded file * pr feedback * EOL instead of '\n' * pr feedback * pr feedback * minor fixes. * pr feedback * fix comment * comments and var renames * test fixes * working version after validation simplification * working version after validation simplification * remove inadvertent change * simplified validations * undo uneeded change * cleanup * working version after latest merge * comments and whitespace fixes * remove is_integer checks * sentence case field validation messages * Use generic strings in sample fields * minor fixes to sample extension strings * spaces to tabs for indentation * request fields before limit fields * reaarange request/limit fields * is_integer checks for PG Server Group number fields * Thenable to Promise * InputBoxInfo * pr feedback * pr feedback * isUndefinedOrEmpty to utils * include asde package.json * use ValidationValueType * ValidationValueType -> InputValueType * Add support for dynamic enablement of resource deployment components * use instanceof function * getValue returns InputValueType Co-authored-by: Arvind Ranasaria <ranasaria@outlook.com>
121 lines
4.3 KiB
TypeScript
121 lines
4.3 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 * as azdata from 'azdata';
|
|
import { EOL } from 'os';
|
|
import * as vscode from 'vscode';
|
|
import * as nls from 'vscode-nls';
|
|
import { DialogInfo, instanceOfNotebookBasedDialogInfo, NotebookBasedDialogInfo, FieldType, NotebookPathInfo } from '../interfaces';
|
|
import { INotebookService } from '../services/notebookService';
|
|
import { IPlatformService } from '../services/platformService';
|
|
import { DialogBase } from './dialogBase';
|
|
import { Model } from './model';
|
|
import { initializeDialog, InputComponent, InputComponentInfo, InputComponents, setModelValues, Validator } from './modelViewUtils';
|
|
import { IToolsService } from '../services/toolsService';
|
|
|
|
const localize = nls.loadMessageBundle();
|
|
|
|
const NotebookTypeVariableName: string = 'SYS_NotebookType';
|
|
|
|
export class DeploymentInputDialog extends DialogBase {
|
|
|
|
private inputComponents: InputComponents = {};
|
|
|
|
constructor(private notebookService: INotebookService,
|
|
private platformService: IPlatformService,
|
|
private toolsService: IToolsService,
|
|
private dialogInfo: DialogInfo) {
|
|
super(dialogInfo.title, dialogInfo.name, false);
|
|
let okButtonText: string;
|
|
if (dialogInfo.actionText) {
|
|
okButtonText = dialogInfo.actionText;
|
|
} else if (instanceOfNotebookBasedDialogInfo(dialogInfo) && !dialogInfo.runNotebook) {
|
|
okButtonText = localize('deploymentDialog.OpenNotebook', "Open Notebook");
|
|
} else {
|
|
okButtonText = localize('deploymentDialog.OkButtonText', "OK");
|
|
}
|
|
|
|
this._dialogObject.okButton.label = okButtonText;
|
|
}
|
|
|
|
protected initialize() {
|
|
const self = this;
|
|
const validators: Validator[] = [];
|
|
|
|
if (this.dialogInfo.tabs.length > 0
|
|
&& instanceOfNotebookBasedDialogInfo(this.dialogInfo)
|
|
&& Array.isArray(this.dialogInfo.notebook)) {
|
|
// Add the notebook type field to the dialog
|
|
this.dialogInfo.tabs[0].sections.push(
|
|
{
|
|
fields: [
|
|
{
|
|
type: FieldType.Options,
|
|
label: localize('notebookType', 'Notebook type'),
|
|
options: this.dialogInfo.notebook.map(nb => nb.type),
|
|
variableName: NotebookTypeVariableName
|
|
}
|
|
]
|
|
}
|
|
);
|
|
}
|
|
|
|
initializeDialog({
|
|
dialogInfo: this.dialogInfo,
|
|
container: this._dialogObject,
|
|
inputComponents: this.inputComponents,
|
|
onNewDisposableCreated: (disposable: vscode.Disposable): void => {
|
|
this._toDispose.push(disposable);
|
|
},
|
|
onNewInputComponentCreated: (name: string, inputComponentInfo: InputComponentInfo<InputComponent>): void => {
|
|
this.inputComponents[name] = inputComponentInfo;
|
|
},
|
|
onNewValidatorCreated: (validator: Validator): void => {
|
|
validators.push(validator);
|
|
},
|
|
toolsService: this.toolsService
|
|
});
|
|
this._dialogObject.registerCloseValidator(() => {
|
|
const messages: string[] = [];
|
|
validators.forEach(validator => {
|
|
const result = validator();
|
|
if (!result.valid) {
|
|
messages.push(result.message);
|
|
}
|
|
});
|
|
if (messages.length > 0) {
|
|
self._dialogObject.message = { level: azdata.window.MessageLevel.Error, text: messages.join(EOL) };
|
|
} else {
|
|
self._dialogObject.message = { text: '' };
|
|
}
|
|
return messages.length === 0;
|
|
});
|
|
}
|
|
|
|
protected async onComplete(): Promise<void> {
|
|
const model: Model = new Model();
|
|
await setModelValues(this.inputComponents, model);
|
|
if (instanceOfNotebookBasedDialogInfo(this.dialogInfo)) {
|
|
model.setEnvironmentVariables();
|
|
if (this.dialogInfo.runNotebook) {
|
|
this.executeNotebook(this.dialogInfo);
|
|
} else {
|
|
const notebook = Array.isArray(this.dialogInfo.notebook) ?
|
|
this.dialogInfo.notebook.find(nb => nb.type === model.getStringValue(NotebookTypeVariableName))?.path :
|
|
this.dialogInfo.notebook;
|
|
this.notebookService.openNotebook(notebook!).catch(error => {
|
|
vscode.window.showErrorMessage(error);
|
|
});
|
|
}
|
|
} else {
|
|
await vscode.commands.executeCommand(this.dialogInfo.command, model);
|
|
}
|
|
}
|
|
|
|
private executeNotebook(notebookDialogInfo: NotebookBasedDialogInfo): void {
|
|
this.notebookService.backgroundExecuteNotebook(notebookDialogInfo.taskName, notebookDialogInfo.notebook as string | NotebookPathInfo, 'deploy', this.platformService);
|
|
}
|
|
}
|