Spaces:
Running
Running
Update flare-ui/src/app/components/environment/environment.component.ts
Browse files
flare-ui/src/app/components/environment/environment.component.ts
CHANGED
@@ -1,210 +1,269 @@
|
|
1 |
-
import { Component, inject, OnInit } from '@angular/core';
|
2 |
-
import { CommonModule } from '@angular/common';
|
3 |
-
import { FormsModule } from '@angular/forms';
|
4 |
-
import {
|
5 |
-
|
6 |
-
@
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
>
|
43 |
-
<
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
</
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
[disabled]="loading
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
>
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
}
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
}
|
180 |
-
}
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
}
|
199 |
-
|
200 |
-
|
201 |
-
this.
|
202 |
-
this.
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
210 |
}
|
|
|
1 |
+
import { Component, inject, OnInit } from '@angular/core';
|
2 |
+
import { CommonModule } from '@angular/common';
|
3 |
+
import { FormsModule } from '@angular/forms';
|
4 |
+
import { MatCardModule } from '@angular/material/card';
|
5 |
+
import { MatFormFieldModule } from '@angular/material/form-field';
|
6 |
+
import { MatInputModule } from '@angular/material/input';
|
7 |
+
import { MatSelectModule } from '@angular/material/select';
|
8 |
+
import { MatButtonModule } from '@angular/material/button';
|
9 |
+
import { MatIconModule } from '@angular/material/icon';
|
10 |
+
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
|
11 |
+
import { MatSnackBar, MatSnackBarModule } from '@angular/material/snack-bar';
|
12 |
+
import { ApiService, Environment } from '../../services/api.service';
|
13 |
+
|
14 |
+
@Component({
|
15 |
+
selector: 'app-environment',
|
16 |
+
standalone: true,
|
17 |
+
imports: [
|
18 |
+
CommonModule,
|
19 |
+
FormsModule,
|
20 |
+
MatCardModule,
|
21 |
+
MatFormFieldModule,
|
22 |
+
MatInputModule,
|
23 |
+
MatSelectModule,
|
24 |
+
MatButtonModule,
|
25 |
+
MatIconModule,
|
26 |
+
MatProgressSpinnerModule,
|
27 |
+
MatSnackBarModule
|
28 |
+
],
|
29 |
+
template: `
|
30 |
+
<div class="environment-container">
|
31 |
+
<mat-card>
|
32 |
+
<mat-card-header>
|
33 |
+
<mat-card-title>
|
34 |
+
<mat-icon>settings</mat-icon>
|
35 |
+
Environment Configuration
|
36 |
+
</mat-card-title>
|
37 |
+
</mat-card-header>
|
38 |
+
|
39 |
+
<mat-card-content>
|
40 |
+
<form (ngSubmit)="save()" #envForm="ngForm">
|
41 |
+
<mat-form-field appearance="outline" class="full-width">
|
42 |
+
<mat-label>Work Mode</mat-label>
|
43 |
+
<mat-select
|
44 |
+
name="workMode"
|
45 |
+
[(ngModel)]="environment.work_mode"
|
46 |
+
(selectionChange)="onWorkModeChange()"
|
47 |
+
required
|
48 |
+
[disabled]="loading"
|
49 |
+
>
|
50 |
+
<mat-option value="hfcloud">HF Cloud</mat-option>
|
51 |
+
<mat-option value="cloud">Cloud</mat-option>
|
52 |
+
<mat-option value="on-premise">On-Premise</mat-option>
|
53 |
+
</mat-select>
|
54 |
+
<mat-icon matPrefix>cloud</mat-icon>
|
55 |
+
</mat-form-field>
|
56 |
+
|
57 |
+
<mat-form-field appearance="outline" class="full-width">
|
58 |
+
<mat-label>Cloud Token</mat-label>
|
59 |
+
<input
|
60 |
+
matInput
|
61 |
+
type="password"
|
62 |
+
name="cloudToken"
|
63 |
+
[(ngModel)]="environment.cloud_token"
|
64 |
+
[disabled]="loading || environment.work_mode === 'on-premise'"
|
65 |
+
placeholder="Enter cloud token"
|
66 |
+
>
|
67 |
+
<mat-icon matPrefix>vpn_key</mat-icon>
|
68 |
+
<mat-hint>Required for HF Cloud and Cloud modes</mat-hint>
|
69 |
+
</mat-form-field>
|
70 |
+
|
71 |
+
<mat-form-field appearance="outline" class="full-width">
|
72 |
+
<mat-label>Spark Endpoint</mat-label>
|
73 |
+
<input
|
74 |
+
matInput
|
75 |
+
type="url"
|
76 |
+
name="sparkEndpoint"
|
77 |
+
[(ngModel)]="environment.spark_endpoint"
|
78 |
+
required
|
79 |
+
[disabled]="loading"
|
80 |
+
placeholder="https://spark-service.example.com"
|
81 |
+
>
|
82 |
+
<mat-icon matPrefix>link</mat-icon>
|
83 |
+
<button
|
84 |
+
mat-icon-button
|
85 |
+
matSuffix
|
86 |
+
type="button"
|
87 |
+
(click)="testConnection()"
|
88 |
+
[disabled]="loading || !environment.spark_endpoint"
|
89 |
+
matTooltip="Test Connection"
|
90 |
+
>
|
91 |
+
<mat-icon>wifi_tethering</mat-icon>
|
92 |
+
</button>
|
93 |
+
</mat-form-field>
|
94 |
+
|
95 |
+
<div class="form-actions">
|
96 |
+
<button
|
97 |
+
mat-raised-button
|
98 |
+
color="primary"
|
99 |
+
type="submit"
|
100 |
+
[disabled]="loading || !envForm.valid || saving"
|
101 |
+
>
|
102 |
+
@if (saving) {
|
103 |
+
<mat-spinner diameter="20"></mat-spinner>
|
104 |
+
Saving...
|
105 |
+
} @else {
|
106 |
+
<mat-icon>save</mat-icon>
|
107 |
+
Save
|
108 |
+
}
|
109 |
+
</button>
|
110 |
+
|
111 |
+
<button
|
112 |
+
mat-raised-button
|
113 |
+
type="button"
|
114 |
+
(click)="reloadFromSpark()"
|
115 |
+
[disabled]="loading"
|
116 |
+
>
|
117 |
+
<mat-icon>refresh</mat-icon>
|
118 |
+
Reload from Spark
|
119 |
+
</button>
|
120 |
+
</div>
|
121 |
+
</form>
|
122 |
+
</mat-card-content>
|
123 |
+
</mat-card>
|
124 |
+
</div>
|
125 |
+
`,
|
126 |
+
styles: [`
|
127 |
+
.environment-container {
|
128 |
+
max-width: 800px;
|
129 |
+
margin: 0 auto;
|
130 |
+
}
|
131 |
+
|
132 |
+
mat-card-header {
|
133 |
+
margin-bottom: 24px;
|
134 |
+
|
135 |
+
mat-card-title {
|
136 |
+
display: flex;
|
137 |
+
align-items: center;
|
138 |
+
gap: 8px;
|
139 |
+
font-size: 24px;
|
140 |
+
|
141 |
+
mat-icon {
|
142 |
+
font-size: 28px;
|
143 |
+
width: 28px;
|
144 |
+
height: 28px;
|
145 |
+
}
|
146 |
+
}
|
147 |
+
}
|
148 |
+
|
149 |
+
.full-width {
|
150 |
+
width: 100%;
|
151 |
+
margin-bottom: 20px;
|
152 |
+
}
|
153 |
+
|
154 |
+
.form-actions {
|
155 |
+
display: flex;
|
156 |
+
gap: 16px;
|
157 |
+
margin-top: 24px;
|
158 |
+
padding-top: 24px;
|
159 |
+
border-top: 1px solid #e0e0e0;
|
160 |
+
|
161 |
+
button {
|
162 |
+
display: flex;
|
163 |
+
align-items: center;
|
164 |
+
gap: 8px;
|
165 |
+
|
166 |
+
mat-spinner {
|
167 |
+
margin-right: 8px;
|
168 |
+
}
|
169 |
+
}
|
170 |
+
}
|
171 |
+
|
172 |
+
::ng-deep {
|
173 |
+
.mat-mdc-form-field-icon-prefix {
|
174 |
+
padding-right: 12px;
|
175 |
+
}
|
176 |
+
|
177 |
+
.mat-mdc-progress-spinner {
|
178 |
+
--mdc-circular-progress-active-indicator-color: white;
|
179 |
+
}
|
180 |
+
}
|
181 |
+
`]
|
182 |
+
})
|
183 |
+
export class EnvironmentComponent implements OnInit {
|
184 |
+
private apiService = inject(ApiService);
|
185 |
+
private snackBar = inject(MatSnackBar);
|
186 |
+
|
187 |
+
environment: Environment = {
|
188 |
+
work_mode: 'hfcloud',
|
189 |
+
cloud_token: '',
|
190 |
+
spark_endpoint: ''
|
191 |
+
};
|
192 |
+
|
193 |
+
loading = true;
|
194 |
+
saving = false;
|
195 |
+
|
196 |
+
ngOnInit() {
|
197 |
+
this.loadEnvironment();
|
198 |
+
}
|
199 |
+
|
200 |
+
loadEnvironment() {
|
201 |
+
this.loading = true;
|
202 |
+
this.apiService.getEnvironment().subscribe({
|
203 |
+
next: (env) => {
|
204 |
+
this.environment = env;
|
205 |
+
this.loading = false;
|
206 |
+
},
|
207 |
+
error: (err) => {
|
208 |
+
this.snackBar.open('Failed to load environment configuration', 'Close', {
|
209 |
+
duration: 5000,
|
210 |
+
panelClass: 'error-snackbar'
|
211 |
+
});
|
212 |
+
this.loading = false;
|
213 |
+
}
|
214 |
+
});
|
215 |
+
}
|
216 |
+
|
217 |
+
onWorkModeChange() {
|
218 |
+
if (this.environment.work_mode === 'on-premise') {
|
219 |
+
this.environment.cloud_token = '';
|
220 |
+
}
|
221 |
+
}
|
222 |
+
|
223 |
+
save() {
|
224 |
+
this.saving = true;
|
225 |
+
|
226 |
+
this.apiService.updateEnvironment(this.environment).subscribe({
|
227 |
+
next: () => {
|
228 |
+
this.snackBar.open('Environment configuration saved successfully', 'Close', {
|
229 |
+
duration: 3000
|
230 |
+
});
|
231 |
+
this.saving = false;
|
232 |
+
},
|
233 |
+
error: (err) => {
|
234 |
+
this.snackBar.open(
|
235 |
+
err.error?.detail || 'Failed to save configuration',
|
236 |
+
'Close',
|
237 |
+
{ duration: 5000, panelClass: 'error-snackbar' }
|
238 |
+
);
|
239 |
+
this.saving = false;
|
240 |
+
}
|
241 |
+
});
|
242 |
+
}
|
243 |
+
|
244 |
+
testConnection() {
|
245 |
+
this.snackBar.open('Testing connection to Spark endpoint...', undefined, {
|
246 |
+
duration: 2000
|
247 |
+
});
|
248 |
+
|
249 |
+
// TODO: Implement actual connection test
|
250 |
+
setTimeout(() => {
|
251 |
+
this.snackBar.open('Connection successful!', 'Close', {
|
252 |
+
duration: 3000
|
253 |
+
});
|
254 |
+
}, 2000);
|
255 |
+
}
|
256 |
+
|
257 |
+
reloadFromSpark() {
|
258 |
+
this.snackBar.open('Reloading configuration from Spark...', undefined, {
|
259 |
+
duration: 2000
|
260 |
+
});
|
261 |
+
|
262 |
+
setTimeout(() => {
|
263 |
+
this.loadEnvironment();
|
264 |
+
this.snackBar.open('Configuration reloaded', 'Close', {
|
265 |
+
duration: 3000
|
266 |
+
});
|
267 |
+
}, 1000);
|
268 |
+
}
|
269 |
}
|