mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
Give saveAsExcel its own config options (#20647)
Co-authored-by: Ben Russell <russellben@microsoft.com>
This commit is contained in:
@@ -12,6 +12,9 @@ export interface IQueryEditorConfiguration {
|
|||||||
readonly textIdentifier: string,
|
readonly textIdentifier: string,
|
||||||
readonly encoding: string
|
readonly encoding: string
|
||||||
},
|
},
|
||||||
|
readonly saveAsExcel: {
|
||||||
|
readonly includeHeaders: boolean,
|
||||||
|
},
|
||||||
readonly saveAsXml: {
|
readonly saveAsXml: {
|
||||||
readonly formatted: boolean,
|
readonly formatted: boolean,
|
||||||
readonly encoding: string
|
readonly encoding: string
|
||||||
|
|||||||
@@ -438,7 +438,7 @@ export class DataResourceDataProvider implements IGridDataProvider {
|
|||||||
if (!this.canSerialize) {
|
if (!this.canSerialize) {
|
||||||
return Promise.resolve(undefined);
|
return Promise.resolve(undefined);
|
||||||
}
|
}
|
||||||
// TODO implement selection support
|
|
||||||
let columns = this._resultSet.columnInfo;
|
let columns = this._resultSet.columnInfo;
|
||||||
let rowLength = this._rows.length;
|
let rowLength = this._rows.length;
|
||||||
let minRow = 0;
|
let minRow = 0;
|
||||||
@@ -482,13 +482,21 @@ export class DataResourceDataProvider implements IGridDataProvider {
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
let serializeRequestParams: SerializeDataParams = <SerializeDataParams>Object.assign(serializer.getBasicSaveParameters(format), <Partial<SerializeDataParams>>{
|
// This code path uses the serialization service which uses a different request parameter
|
||||||
|
// interface than the query execution service's saveResults handlers. Here, we take the
|
||||||
|
// format-specific request params (eg, includeHeaders for CSV) and merge the format-agnostic
|
||||||
|
// request params for the serialization request (eg, saveFormat, filePath).
|
||||||
|
let formatSpecificParams = serializer.getBasicSaveParameters(format);
|
||||||
|
let formatAgnosticParams = <Partial<SerializeDataParams>>{
|
||||||
saveFormat: format,
|
saveFormat: format,
|
||||||
columns: columns,
|
|
||||||
filePath: filePath.fsPath,
|
filePath: filePath.fsPath,
|
||||||
getRowRange: (rowStart, includeHeaders, numberOfRows) => getRows(rowStart, includeHeaders, numberOfRows),
|
columns: columns,
|
||||||
rowCount: rowLength
|
rowCount: rowLength,
|
||||||
});
|
getRowRange: (rowStart: number, includeHeaders: boolean, numberOfRows?: number) =>
|
||||||
|
getRows(rowStart, includeHeaders, numberOfRows),
|
||||||
|
};
|
||||||
|
let serializeRequestParams = <SerializeDataParams>Object.assign(formatSpecificParams, formatAgnosticParams);
|
||||||
|
|
||||||
return this._serializationService.serializeResults(serializeRequestParams);
|
return this._serializationService.serializeResults(serializeRequestParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -374,6 +374,11 @@ const queryEditorConfiguration: IConfigurationNode = {
|
|||||||
'description': localize('queryEditor.results.saveAsCsv.textIdentifier', "Character used for enclosing text fields when saving results as CSV"),
|
'description': localize('queryEditor.results.saveAsCsv.textIdentifier', "Character used for enclosing text fields when saving results as CSV"),
|
||||||
'default': '\"'
|
'default': '\"'
|
||||||
},
|
},
|
||||||
|
'queryEditor.results.saveAsExcel.includeHeaders': {
|
||||||
|
'type': 'boolean',
|
||||||
|
'description': localize('queryEditor.results.saveAsExcel.includeHeaders', "When true, column headers are included when saving results as an Excel file"),
|
||||||
|
'default': true
|
||||||
|
},
|
||||||
'queryEditor.results.saveAsCsv.encoding': {
|
'queryEditor.results.saveAsCsv.encoding': {
|
||||||
'type': 'string',
|
'type': 'string',
|
||||||
'description': localize('queryEditor.results.saveAsCsv.encoding', "File encoding used when saving results as CSV"),
|
'description': localize('queryEditor.results.saveAsCsv.encoding', "File encoding used when saving results as CSV"),
|
||||||
|
|||||||
@@ -191,6 +191,7 @@ export class ResultSerializer {
|
|||||||
|
|
||||||
// get save results config from vscode config
|
// get save results config from vscode config
|
||||||
let saveConfig = this._configurationService.getValue<IQueryEditorConfiguration>('queryEditor').results.saveAsCsv;
|
let saveConfig = this._configurationService.getValue<IQueryEditorConfiguration>('queryEditor').results.saveAsCsv;
|
||||||
|
|
||||||
// if user entered config, set options
|
// if user entered config, set options
|
||||||
if (saveConfig) {
|
if (saveConfig) {
|
||||||
if (saveConfig.includeHeaders !== undefined) {
|
if (saveConfig.includeHeaders !== undefined) {
|
||||||
@@ -215,21 +216,23 @@ export class ResultSerializer {
|
|||||||
|
|
||||||
private getConfigForJson(): SaveResultsRequestParams {
|
private getConfigForJson(): SaveResultsRequestParams {
|
||||||
// JSON does not currently have special conditions
|
// JSON does not currently have special conditions
|
||||||
let saveResultsParams = <SaveResultsRequestParams>{ resultFormat: SaveFormat.JSON as string };
|
return <SaveResultsRequestParams>{ resultFormat: SaveFormat.JSON as string };
|
||||||
return saveResultsParams;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private getConfigForExcel(): SaveResultsRequestParams {
|
private getConfigForExcel(): SaveResultsRequestParams {
|
||||||
// get save results config from vscode config
|
let saveResultsParams = <SaveResultsRequestParams>{ resultFormat: SaveFormat.EXCEL as string };
|
||||||
// Note: we are currently using the configSaveAsCsv setting since it has the option mssql.saveAsCsv.includeHeaders
|
|
||||||
// and we want to have just 1 setting that lists this.
|
// Get save results config from vscode config
|
||||||
let config = this.getConfigForCsv();
|
let saveConfig = this._configurationService.getValue<IQueryEditorConfiguration>('queryEditor').results.saveAsExcel;
|
||||||
config.resultFormat = SaveFormat.EXCEL;
|
|
||||||
config.delimiter = undefined;
|
// If user entered config, set options
|
||||||
config.lineSeperator = undefined;
|
if (saveConfig) {
|
||||||
config.textIdentifier = undefined;
|
if (saveConfig.includeHeaders !== undefined) {
|
||||||
config.encoding = undefined;
|
saveResultsParams.includeHeaders = saveConfig.includeHeaders;
|
||||||
return config;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return saveResultsParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
private getConfigForXml(): SaveResultsRequestParams {
|
private getConfigForXml(): SaveResultsRequestParams {
|
||||||
@@ -237,6 +240,7 @@ export class ResultSerializer {
|
|||||||
|
|
||||||
// get save results config from vscode config
|
// get save results config from vscode config
|
||||||
let saveConfig = this._configurationService.getValue<IQueryEditorConfiguration>('queryEditor').results.saveAsXml;
|
let saveConfig = this._configurationService.getValue<IQueryEditorConfiguration>('queryEditor').results.saveAsXml;
|
||||||
|
|
||||||
// if user entered config, set options
|
// if user entered config, set options
|
||||||
if (saveConfig) {
|
if (saveConfig) {
|
||||||
if (saveConfig.formatted !== undefined) {
|
if (saveConfig.formatted !== undefined) {
|
||||||
@@ -251,7 +255,14 @@ export class ResultSerializer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private getParameters(uri: string, filePath: URI, batchIndex: number, resultSetNo: number, format: string, selection?: Slick.Range): SaveResultsRequestParams {
|
private getParameters(
|
||||||
|
uri: string,
|
||||||
|
filePath: URI,
|
||||||
|
batchIndex: number,
|
||||||
|
resultSetNo: number,
|
||||||
|
format: string,
|
||||||
|
selection?: Slick.Range
|
||||||
|
): SaveResultsRequestParams {
|
||||||
let saveResultsParams = this.getBasicSaveParameters(format);
|
let saveResultsParams = this.getBasicSaveParameters(format);
|
||||||
saveResultsParams.filePath = filePath.fsPath;
|
saveResultsParams.filePath = filePath.fsPath;
|
||||||
saveResultsParams.ownerUri = uri;
|
saveResultsParams.ownerUri = uri;
|
||||||
|
|||||||
Reference in New Issue
Block a user