Skip to content

Commit d8635e8

Browse files
committed
feat: support raw SQL input
1 parent fdd65eb commit d8635e8

File tree

2 files changed

+38
-10
lines changed

2 files changed

+38
-10
lines changed

examples/gauge/Components/Input.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import { ComponentProps, DisplayComponent, FSComponent, Subscribable, UUID, VNode } from "@microsoft/msfs-sdk"
22

33
interface InputProps extends ComponentProps {
4-
type: HTMLInputElement["type"]
5-
name?: string
64
value?: string
75
class?: string | Subscribable<string>
6+
textarea?: boolean
87
}
98

109
export class Input extends DisplayComponent<InputProps> {
@@ -23,7 +22,7 @@ export class Input extends DisplayComponent<InputProps> {
2322
}
2423

2524
private getInputProps() {
26-
return { name: this.props.name, value: this.props.value, class: this.props.class }
25+
return { value: this.props.value, class: this.props.class }
2726
}
2827

2928
/**
@@ -46,6 +45,12 @@ export class Input extends DisplayComponent<InputProps> {
4645
}
4746

4847
render() {
48+
if (this.props.textarea)
49+
return (
50+
<textarea style="width:350px;height:180px;" ref={this.inputRef} {...this.getInputProps()}>
51+
{this.props.value}
52+
</textarea>
53+
)
4954
return <input ref={this.inputRef} {...this.getInputProps()} />
5055
}
5156
}

examples/gauge/Components/InterfaceSample.tsx

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ export class InterfaceSample extends DisplayComponent<InterfaceSampleProps> {
2222
private readonly qrCodeRef = FSComponent.createRef<HTMLImageElement>()
2323
private readonly dropdownRef = FSComponent.createRef<Dropdown>()
2424
private readonly downloadButtonRef = FSComponent.createRef<HTMLButtonElement>()
25-
private readonly executeButtonRef = FSComponent.createRef<HTMLButtonElement>()
26-
private readonly inputRef = FSComponent.createRef<Input>()
25+
private readonly icaoInputRef = FSComponent.createRef<Input>()
26+
private readonly executeIcaoButtonRef = FSComponent.createRef<HTMLButtonElement>()
27+
private readonly sqlInputRef = FSComponent.createRef<Input>()
28+
private readonly executeSqlButtonRef = FSComponent.createRef<HTMLButtonElement>()
2729
private readonly outputRef = FSComponent.createRef<HTMLPreElement>()
2830

2931
private cancelSource = CancelToken.source()
@@ -78,10 +80,20 @@ export class InterfaceSample extends DisplayComponent<InterfaceSampleProps> {
7880
<h4 style="text-align: center;">Step 3 - Query the database</h4>
7981
<div class="horizontal">
8082
<div class="vertical">
81-
<Input ref={this.inputRef} type="text" value="ESSA" class="text-field" />
82-
<div ref={this.executeButtonRef} class="button">
83+
<Input ref={this.icaoInputRef} value="ESSA" class="text-field" />
84+
<div ref={this.executeIcaoButtonRef} class="button">
8385
Fetch Airport
8486
</div>
87+
<div style="height:30px;"></div>
88+
<Input
89+
ref={this.sqlInputRef}
90+
textarea
91+
value="SELECT airport_name FROM tbl_airports WHERE airport_identifier = 'ESSA'"
92+
class="text-field"
93+
/>
94+
<div ref={this.executeSqlButtonRef} class="button">
95+
Execute SQL
96+
</div>
8597
</div>
8698
<pre ref={this.outputRef} id="output">
8799
The output of the query will show up here
@@ -97,19 +109,30 @@ export class InterfaceSample extends DisplayComponent<InterfaceSampleProps> {
97109
this.loginButtonRef.instance.addEventListener("click", () => this.handleClick())
98110
this.downloadButtonRef.instance.addEventListener("click", () => this.handleDownloadClick())
99111

100-
this.executeButtonRef.instance.addEventListener("click", () => {
112+
this.executeIcaoButtonRef.instance.addEventListener("click", () => {
101113
console.time("query")
102114
this.navigationDataInterface
103-
.get_airport(this.inputRef.instance.value)
115+
.get_airport(this.icaoInputRef.instance.value)
104116
.then(airport => {
105117
console.info(airport)
106-
107118
this.outputRef.instance.textContent = JSON.stringify(airport, null, 2)
108119
})
109120
.catch(e => console.error(e))
110121
.finally(() => console.timeEnd("query"))
111122
})
112123

124+
this.executeSqlButtonRef.instance.addEventListener("click", () => {
125+
console.time("query")
126+
this.navigationDataInterface
127+
.execute_sql(this.sqlInputRef.instance.value, [])
128+
.then(result => {
129+
console.info(result)
130+
this.outputRef.instance.textContent = JSON.stringify(result, null, 2)
131+
})
132+
.catch(e => console.error(e))
133+
.finally(() => console.timeEnd("query"))
134+
})
135+
113136
AuthService.user.sub(user => {
114137
if (user) {
115138
this.qrCodeRef.instance.src = ""

0 commit comments

Comments
 (0)