Change default folder in dacpac and schema compare extensions (#5215)

* change default folder in dacpac and schema compare extensions

* move getting rootpath to a method

* change method name
This commit is contained in:
kisantia
2019-04-27 04:27:03 +12:00
committed by GitHub
parent 23f4931a1d
commit 64377000c6
8 changed files with 23 additions and 14 deletions

View File

@@ -6,6 +6,7 @@
import * as azdata from 'azdata';
import * as nls from 'vscode-nls';
import * as vscode from 'vscode';
import * as os from 'os';
import * as path from 'path';
import { DataTierApplicationWizard } from '../dataTierApplicationWizard';
@@ -101,7 +102,7 @@ export abstract class DacFxConfigPage extends BasePage {
// Handle database changes
this.databaseDropdown.onValueChanged(async () => {
this.model.database = (<azdata.CategoryValue>this.databaseDropdown.value).name;
this.fileTextBox.value = this.generateFilePath();
this.fileTextBox.value = this.generateFilePathFromDatabaseAndTimestamp();
this.model.filePath = this.fileTextBox.value;
});
@@ -124,7 +125,7 @@ export abstract class DacFxConfigPage extends BasePage {
let values = await this.getDatabaseValues();
this.model.database = values[0].name;
this.model.filePath = this.generateFilePath();
this.model.filePath = this.generateFilePathFromDatabaseAndTimestamp();
this.fileTextBox.value = this.model.filePath;
this.databaseDropdown.updateProperties({
@@ -145,10 +146,18 @@ export abstract class DacFxConfigPage extends BasePage {
}).component();
}
protected generateFilePath(): string {
protected generateFilePathFromDatabaseAndTimestamp(): string {
return path.join(this.getRootPath(), this.model.database + '-' + this.getDateTime() + this.fileExtension);
}
protected getDateTime(): string {
let now = new Date();
let datetime = now.getFullYear() + '-' + (now.getMonth() + 1) + '-' + now.getDate() + '-' + now.getHours() + '-' + now.getMinutes();
return path.join(os.homedir(), this.model.database + '-' + datetime + this.fileExtension);
return now.getFullYear() + '-' + (now.getMonth() + 1) + '-' + now.getDate() + '-' + now.getHours() + '-' + now.getMinutes();
}
protected getRootPath(): string {
// return rootpath of opened folder in file explorer if one is open, otherwise default to user home directory
return vscode.workspace.rootPath ? vscode.workspace.rootPath : os.homedir();
}
}

View File

@@ -167,9 +167,7 @@ export class DeployActionPage extends DacFxConfigPage {
}
private setDefaultScriptFilePath(): void {
let now = new Date();
let datetime = now.getFullYear() + '-' + (now.getMonth() + 1) + '-' + now.getDate() + '-' + now.getHours() + '-' + now.getMinutes();
this.fileTextBox.value = path.join(os.homedir(), this.model.database + '_UpgradeDACScript_' + datetime + '.sql');
this.fileTextBox.value = path.join(this.getRootPath(), this.model.database + '_UpgradeDACScript_' + this.getDateTime() + '.sql');
this.model.scriptFilePath = this.fileTextBox.value;
}

View File

@@ -72,7 +72,7 @@ export class DeployConfigPage extends DacFxConfigPage {
canSelectFiles: true,
canSelectFolders: false,
canSelectMany: false,
defaultUri: vscode.Uri.file(os.homedir()),
defaultUri: vscode.Uri.file(this.getRootPath()),
openLabel: localize('dacFxDeploy.openFile', 'Open'),
filters: {
'dacpac Files': ['dacpac'],

View File

@@ -65,7 +65,7 @@ export class ExportConfigPage extends DacFxConfigPage {
this.createFileBrowserParts();
// default filepath
this.fileTextBox.value = this.generateFilePath();
this.fileTextBox.value = this.generateFilePathFromDatabaseAndTimestamp();
this.model.filePath = this.fileTextBox.value;
this.fileButton.onDidClick(async (click) => {

View File

@@ -68,7 +68,7 @@ export class ExtractConfigPage extends DacFxConfigPage {
this.createFileBrowserParts();
// default filepath
this.fileTextBox.value = this.generateFilePath();
this.fileTextBox.value = this.generateFilePathFromDatabaseAndTimestamp();
this.model.filePath = this.fileTextBox.value;
this.fileButton.onDidClick(async (click) => {

View File

@@ -62,7 +62,7 @@ export class ImportConfigPage extends DacFxConfigPage {
canSelectFiles: true,
canSelectFolders: false,
canSelectMany: false,
defaultUri: vscode.Uri.file(os.homedir()),
defaultUri: vscode.Uri.file(this.getRootPath()),
openLabel: localize('dacFxImport.openFile', 'Open'),
filters: {
'bacpac Files': ['bacpac'],

View File

@@ -208,12 +208,13 @@ export class SchemaCompareDialog {
let currentButton = isTarget ? this.targetFileButton : this.sourceFileButton;
currentButton.onDidClick(async (click) => {
let rootPath = vscode.workspace.rootPath ? vscode.workspace.rootPath : os.homedir();
let fileUris = await vscode.window.showOpenDialog(
{
canSelectFiles: true,
canSelectFolders: false,
canSelectMany: false,
defaultUri: vscode.Uri.file(os.homedir()),
defaultUri: vscode.Uri.file(rootPath),
openLabel: localize('schemaCompare.openFile', 'Open'),
filters: {
'dacpac Files': ['dacpac'],

View File

@@ -291,7 +291,8 @@ export class SchemaCompareResult {
// get file path
let now = new Date();
let datetime = now.getFullYear() + '-' + (now.getMonth() + 1) + '-' + now.getDate() + '-' + now.getHours() + '-' + now.getMinutes() + '-' + now.getSeconds();
let defaultFilePath = path.join(os.homedir(), this.targetName + '_Update_' + datetime + '.sql');
let rootPath = vscode.workspace.rootPath ? vscode.workspace.rootPath : os.homedir();
let defaultFilePath = path.join(rootPath, this.targetName + '_Update_' + datetime + '.sql');
let fileUri = await vscode.window.showSaveDialog(
{
defaultUri: vscode.Uri.file(defaultFilePath),