mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
enabled button to import queries from sql files (#2042)
This commit is contained in:
@@ -143,13 +143,16 @@ export class JobStepDialog {
|
|||||||
width: '80px',
|
width: '80px',
|
||||||
isFile: true
|
isFile: true
|
||||||
}).component();
|
}).component();
|
||||||
this.openButton.enabled = false;
|
|
||||||
this.parseButton = view.modelBuilder.button()
|
this.parseButton = view.modelBuilder.button()
|
||||||
.withProperties({
|
.withProperties({
|
||||||
label: this.ParseCommandText,
|
label: this.ParseCommandText,
|
||||||
width: '80px',
|
width: '80px',
|
||||||
isFile: false
|
isFile: false
|
||||||
}).component();
|
}).component();
|
||||||
|
this.openButton.onDidClick(e => {
|
||||||
|
let queryContent = e;
|
||||||
|
this.commandTextBox.value = queryContent;
|
||||||
|
});
|
||||||
this.parseButton.onDidClick(e => {
|
this.parseButton.onDidClick(e => {
|
||||||
if (this.commandTextBox.value) {
|
if (this.commandTextBox.value) {
|
||||||
queryProvider.parseSyntax(this.ownerUri, this.commandTextBox.value).then(result => {
|
queryProvider.parseSyntax(this.ownerUri, this.commandTextBox.value).then(result => {
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ import { Color } from 'vs/base/common/color';
|
|||||||
<div>
|
<div>
|
||||||
<label for={{this.label}}>
|
<label for={{this.label}}>
|
||||||
<div #input style="width: 100%">
|
<div #input style="width: 100%">
|
||||||
<input *ngIf="this.isFile === true" id={{this.label}} type="file" style="display: none">
|
<input #fileInput *ngIf="this.isFile === true" id={{this.label}} type="file" accept=".sql" style="display: none">
|
||||||
</div>
|
</div>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
@@ -39,17 +39,16 @@ export default class ButtonComponent extends ComponentWithIconBase implements IC
|
|||||||
private _button: Button;
|
private _button: Button;
|
||||||
|
|
||||||
@ViewChild('input', { read: ElementRef }) private _inputContainer: ElementRef;
|
@ViewChild('input', { read: ElementRef }) private _inputContainer: ElementRef;
|
||||||
|
@ViewChild('fileInput', { read: ElementRef }) private _fileInputContainer: ElementRef;
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(forwardRef(() => ChangeDetectorRef)) changeRef: ChangeDetectorRef,
|
@Inject(forwardRef(() => ChangeDetectorRef)) changeRef: ChangeDetectorRef,
|
||||||
@Inject(IWorkbenchThemeService) private themeService: IWorkbenchThemeService
|
@Inject(IWorkbenchThemeService) private themeService: IWorkbenchThemeService
|
||||||
) {
|
) {
|
||||||
super(changeRef);
|
super(changeRef);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.baseInit();
|
this.baseInit();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ngAfterViewInit(): void {
|
ngAfterViewInit(): void {
|
||||||
@@ -61,10 +60,27 @@ export default class ButtonComponent extends ComponentWithIconBase implements IC
|
|||||||
buttonBackground: SIDE_BAR_BACKGROUND, buttonHoverBackground: SIDE_BAR_BACKGROUND, buttonForeground: SIDE_BAR_TITLE_FOREGROUND
|
buttonBackground: SIDE_BAR_BACKGROUND, buttonHoverBackground: SIDE_BAR_BACKGROUND, buttonForeground: SIDE_BAR_TITLE_FOREGROUND
|
||||||
}));
|
}));
|
||||||
this._register(this._button.onDidClick(e => {
|
this._register(this._button.onDidClick(e => {
|
||||||
this._onEventEmitter.fire({
|
if (this._fileInputContainer) {
|
||||||
eventType: ComponentEventType.onDidClick,
|
const self = this;
|
||||||
args: e
|
this._fileInputContainer.nativeElement.onchange = () => {
|
||||||
});
|
let file = self._fileInputContainer.nativeElement.files[0];
|
||||||
|
let reader = new FileReader();
|
||||||
|
reader.onload = (e) => {
|
||||||
|
let text = (<FileReader>e.target).result;
|
||||||
|
self.fileContent = text;
|
||||||
|
self._onEventEmitter.fire({
|
||||||
|
eventType: ComponentEventType.onDidClick,
|
||||||
|
args: self.fileContent
|
||||||
|
});
|
||||||
|
};
|
||||||
|
reader.readAsText(file);
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
this._onEventEmitter.fire({
|
||||||
|
eventType: ComponentEventType.onDidClick,
|
||||||
|
args: e
|
||||||
|
});
|
||||||
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -133,6 +149,18 @@ export default class ButtonComponent extends ComponentWithIconBase implements IC
|
|||||||
this.setPropertyFromUI<sqlops.ButtonProperties, boolean>(this.setFileProperties, newValue);
|
this.setPropertyFromUI<sqlops.ButtonProperties, boolean>(this.setFileProperties, newValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private get fileContent(): string {
|
||||||
|
return this.getPropertyOrDefault<sqlops.ButtonProperties, string>((props) => props.fileContent, '');
|
||||||
|
}
|
||||||
|
|
||||||
|
private set fileContent(newValue: string) {
|
||||||
|
this.setPropertyFromUI<sqlops.ButtonProperties, string>(this.setFileContentProperties, newValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
private setFileContentProperties(properties: sqlops.ButtonProperties, fileContent: string) : void {
|
||||||
|
properties.fileContent = fileContent;
|
||||||
|
}
|
||||||
|
|
||||||
private setValueProperties(properties: sqlops.ButtonProperties, label: string): void {
|
private setValueProperties(properties: sqlops.ButtonProperties, label: string): void {
|
||||||
properties.label = label;
|
properties.label = label;
|
||||||
}
|
}
|
||||||
|
|||||||
3
src/sql/sqlops.proposed.d.ts
vendored
3
src/sql/sqlops.proposed.d.ts
vendored
@@ -454,6 +454,7 @@ declare module 'sqlops' {
|
|||||||
export interface ButtonProperties extends ComponentProperties, ComponentWithIcon {
|
export interface ButtonProperties extends ComponentProperties, ComponentWithIcon {
|
||||||
label?: string;
|
label?: string;
|
||||||
isFile?: boolean;
|
isFile?: boolean;
|
||||||
|
fileContent?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface LoadingComponentProperties {
|
export interface LoadingComponentProperties {
|
||||||
@@ -533,7 +534,7 @@ declare module 'sqlops' {
|
|||||||
languageMode: string;
|
languageMode: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ButtonComponent extends Component {
|
export interface ButtonComponent extends Component, ButtonProperties {
|
||||||
label: string;
|
label: string;
|
||||||
iconPath: string | vscode.Uri | { light: string | vscode.Uri; dark: string | vscode.Uri };
|
iconPath: string | vscode.Uri | { light: string | vscode.Uri; dark: string | vscode.Uri };
|
||||||
onDidClick: vscode.Event<any>;
|
onDidClick: vscode.Event<any>;
|
||||||
|
|||||||
Reference in New Issue
Block a user