mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-29 17:23:25 -05:00
Migrating other deployment wizards to the generic ResourceTypeWizard (#13132)
* SQL VM wizard migration to ResourceType Wizard * Revert "SQL VM wizard migration to ResourceType Wizard" This reverts commit e58cd47707a7e2812be20d915f1fe638b96b035f. * migrated notebook wizard * SQL VM wizard migration to ResourceType Wizard * Fixed some imports on SQL VM wizard * migrated sqldb wizard to generic ResourceTypeWizard * Added missing import Solving errors from the merge * Moved some common functionality into ResourceTypeWizard * Changed logic of start deployment * fixed some import after changing files.
This commit is contained in:
@@ -5,9 +5,22 @@
|
||||
|
||||
import { EOL } from 'os';
|
||||
import * as azdata from 'azdata';
|
||||
import { Model } from '../model';
|
||||
import * as vscode from 'vscode';
|
||||
import * as constants from './constants';
|
||||
import axios, { AxiosRequestConfig } from 'axios';
|
||||
import { ResourceTypeModel } from '../resourceTypeModel';
|
||||
import { INotebookService } from '../../services/notebookService';
|
||||
import { IToolsService } from '../../services/toolsService';
|
||||
import { AzureSQLDBDeploymentProvider } from '../../interfaces';
|
||||
import { ResourceTypeWizard } from '../resourceTypeWizard';
|
||||
import { ResourceTypePage } from '../resourceTypePage';
|
||||
import { DatabaseSettingsPage } from './pages/databaseSettingsPage';
|
||||
import { AzureSQLDBSummaryPage } from './pages/summaryPage';
|
||||
import { AzureSettingsPage } from './pages/azureSettingsPage';
|
||||
|
||||
export class DeployAzureSQLDBWizardModel extends ResourceTypeModel {
|
||||
private cache: Map<string, any> = new Map();
|
||||
|
||||
export class DeployAzureSQLDBWizardModel extends Model {
|
||||
public azureAccount!: azdata.Account;
|
||||
public securityToken!: any;
|
||||
public azureSubscription!: string;
|
||||
@@ -29,9 +42,142 @@ export class DeployAzureSQLDBWizardModel extends Model {
|
||||
public databaseCollation!: string;
|
||||
public newFirewallRule!: boolean;
|
||||
|
||||
public get notebookService(): INotebookService {
|
||||
return this.wizard.notebookService;
|
||||
}
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
public get toolService(): IToolsService {
|
||||
return this.wizard.toolsService;
|
||||
}
|
||||
|
||||
constructor(public sqldbProvider: AzureSQLDBDeploymentProvider, wizard: ResourceTypeWizard) {
|
||||
super(sqldbProvider, wizard);
|
||||
this.wizard.wizardObject.title = constants.WizardTitle;
|
||||
}
|
||||
|
||||
initialize(): void {
|
||||
this.wizard.setPages(this.getPages());
|
||||
this.wizard.wizardObject.generateScriptButton.hidden = true;
|
||||
this.wizard.wizardObject.doneButton.label = constants.WizardDoneButtonLabel;
|
||||
}
|
||||
|
||||
async onOk(): Promise<void> {
|
||||
await this.scriptToNotebook();
|
||||
}
|
||||
|
||||
onCancel(): void {
|
||||
}
|
||||
|
||||
private getPages(): ResourceTypePage[] {
|
||||
const pages: ResourceTypePage[] = [];
|
||||
pages.push(new AzureSettingsPage(this));
|
||||
pages.push(new DatabaseSettingsPage(this));
|
||||
pages.push(new AzureSQLDBSummaryPage(this));
|
||||
return pages;
|
||||
}
|
||||
|
||||
public async getRequest(url: string, useCache = false): Promise<any> {
|
||||
if (useCache) {
|
||||
if (this.cache.has(url)) {
|
||||
return this.cache.get(url);
|
||||
}
|
||||
}
|
||||
let token = this.securityToken.token;
|
||||
const config: AxiosRequestConfig = {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${token}`
|
||||
},
|
||||
validateStatus: () => true // Never throw
|
||||
};
|
||||
const response = await axios.get(url, config);
|
||||
if (response.status !== 200) {
|
||||
let errorMessage: string[] = [];
|
||||
errorMessage.push(response.status.toString());
|
||||
errorMessage.push(response.statusText);
|
||||
if (response.data && response.data.error) {
|
||||
errorMessage.push(`${response.data.error.code} : ${response.data.error.message}`);
|
||||
}
|
||||
vscode.window.showErrorMessage(errorMessage.join(EOL));
|
||||
}
|
||||
if (useCache) {
|
||||
this.cache.set(url, response);
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
public createFormRowComponent(view: azdata.ModelView, title: string, description: string, component: azdata.Component, required: boolean): azdata.FlexContainer {
|
||||
|
||||
component.updateProperties({
|
||||
required: required,
|
||||
width: '480px'
|
||||
});
|
||||
|
||||
const labelText = view.modelBuilder.text()
|
||||
.withProperties<azdata.TextComponentProperties>(
|
||||
{
|
||||
value: title,
|
||||
width: '250px',
|
||||
description: description,
|
||||
requiredIndicator: required,
|
||||
})
|
||||
.component();
|
||||
|
||||
labelText.updateCssStyles({
|
||||
'font-weight': '400',
|
||||
'font-size': '13px',
|
||||
});
|
||||
|
||||
const flexContainer = view.modelBuilder.flexContainer()
|
||||
.withLayout(
|
||||
{
|
||||
flexFlow: 'row',
|
||||
alignItems: 'center',
|
||||
})
|
||||
.withItems(
|
||||
[labelText, component],
|
||||
{
|
||||
CSSStyles: { 'margin-right': '5px' }
|
||||
})
|
||||
.component();
|
||||
return flexContainer;
|
||||
}
|
||||
|
||||
public changeComponentDisplay(component: azdata.Component, display: ('none' | 'block')) {
|
||||
component.updateProperties({
|
||||
required: display === 'block'
|
||||
});
|
||||
component.updateCssStyles({
|
||||
display: display
|
||||
});
|
||||
}
|
||||
|
||||
public changeRowDisplay(container: azdata.FlexContainer, display: ('none' | 'block')) {
|
||||
container.items.map((component) => {
|
||||
component.updateProperties({
|
||||
required: (display === 'block'),
|
||||
});
|
||||
component.updateCssStyles({
|
||||
display: display,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public addDropdownValues(component: azdata.DropDownComponent, values: azdata.CategoryValue[], width?: number) {
|
||||
component.updateProperties({
|
||||
values: values,
|
||||
width: '480px'
|
||||
});
|
||||
}
|
||||
|
||||
private async scriptToNotebook(): Promise<void> {
|
||||
const variableValueStatements = this.getCodeCellContentForNotebook();
|
||||
const insertionPosition = 2; // Cell number 2 is the position where the python variable setting statements need to be inserted in this.wizardInfo.notebook.
|
||||
try {
|
||||
await this.notebookService.openNotebookWithEdits(this.sqldbProvider.azureSQLDBWizard.notebook, variableValueStatements, insertionPosition);
|
||||
} catch (error) {
|
||||
vscode.window.showErrorMessage(error);
|
||||
}
|
||||
}
|
||||
|
||||
public getCodeCellContentForNotebook(): string[] {
|
||||
|
||||
Reference in New Issue
Block a user