ciyidogan commited on
Commit
cf4f53c
·
verified ·
1 Parent(s): f3e5f4f

Update flare-ui/src/app/dialogs/api-edit-dialog/api-edit-dialog.component.html

Browse files
flare-ui/src/app/dialogs/api-edit-dialog/api-edit-dialog.component.html CHANGED
@@ -0,0 +1,316 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <h2 mat-dialog-title>
2
+ {{ data.mode === 'create' ? 'Create New API' : data.mode === 'duplicate' ? 'Duplicate API' : 'Edit API' }}
3
+ </h2>
4
+
5
+ <mat-dialog-content>
6
+ <form [formGroup]="form">
7
+ <mat-tab-group>
8
+ <!-- General Tab -->
9
+ <mat-tab label="General">
10
+ <div class="tab-content">
11
+ <mat-form-field appearance="outline" class="full-width">
12
+ <mat-label>Name*</mat-label>
13
+ <input matInput formControlName="name"
14
+ placeholder="e.g., book_flight_api"
15
+ [readonly]="data.mode === 'edit'">
16
+ <mat-hint>Use only letters, numbers, and underscores</mat-hint>
17
+ <mat-error *ngIf="form.get('name')?.hasError('required')">Name is required</mat-error>
18
+ <mat-error *ngIf="form.get('name')?.hasError('pattern')">Invalid characters in name</mat-error>
19
+ </mat-form-field>
20
+
21
+ <mat-form-field appearance="outline" class="full-width">
22
+ <mat-label>URL*</mat-label>
23
+ <input matInput formControlName="url"
24
+ placeholder="https://api.example.com/endpoint">
25
+ <mat-error *ngIf="form.get('url')?.hasError('required')">URL is required</mat-error>
26
+ <mat-error *ngIf="form.get('url')?.hasError('pattern')">Invalid URL format</mat-error>
27
+ </mat-form-field>
28
+
29
+ <mat-form-field appearance="outline">
30
+ <mat-label>Method*</mat-label>
31
+ <mat-select formControlName="method">
32
+ <mat-option *ngFor="let method of httpMethods" [value]="method">
33
+ {{ method }}
34
+ </mat-option>
35
+ </mat-select>
36
+ </mat-form-field>
37
+
38
+ <div class="form-section">
39
+ <label class="section-label">Body Template:</label>
40
+ <div class="json-editor">
41
+ <textarea formControlName="body_template"
42
+ placeholder='{"key": "{{variables.value}}"}'
43
+ rows="8"
44
+ class="json-textarea"></textarea>
45
+ <div class="template-helpers">
46
+ <mat-expansion-panel>
47
+ <mat-expansion-panel-header>
48
+ <mat-panel-title>
49
+ <mat-icon>help_outline</mat-icon>
50
+ Template Variables
51
+ </mat-panel-title>
52
+ </mat-expansion-panel-header>
53
+ <div class="template-list">
54
+ <mat-chip *ngFor="let var of templateVariables"
55
+ (click)="insertTemplateVariable('body_template', var.key)">
56
+ {{ var.key }}
57
+ </mat-chip>
58
+ </div>
59
+ </mat-expansion-panel>
60
+ </div>
61
+ <button mat-button type="button"
62
+ (click)="validateJSON('body_template')"
63
+ [color]="validateJSON('body_template') ? 'primary' : 'warn'">
64
+ <mat-icon>check_circle</mat-icon>
65
+ Validate JSON
66
+ </button>
67
+ </div>
68
+ </div>
69
+
70
+ <mat-form-field appearance="outline">
71
+ <mat-label>Timeout (seconds)*</mat-label>
72
+ <input matInput type="number" formControlName="timeout_seconds">
73
+ <mat-error *ngIf="form.get('timeout_seconds')?.hasError('required')">Timeout is required</mat-error>
74
+ <mat-error *ngIf="form.get('timeout_seconds')?.hasError('min')">Minimum 1 second</mat-error>
75
+ <mat-error *ngIf="form.get('timeout_seconds')?.hasError('max')">Maximum 300 seconds</mat-error>
76
+ </mat-form-field>
77
+
78
+ <div class="form-section">
79
+ <h4>Retry Settings</h4>
80
+ <div formGroupName="retry" class="retry-settings">
81
+ <mat-form-field appearance="outline">
82
+ <mat-label>Retry Count*</mat-label>
83
+ <input matInput type="number" formControlName="retry_count">
84
+ </mat-form-field>
85
+
86
+ <mat-form-field appearance="outline">
87
+ <mat-label>Backoff (seconds)*</mat-label>
88
+ <input matInput type="number" formControlName="backoff_seconds">
89
+ </mat-form-field>
90
+
91
+ <mat-form-field appearance="outline">
92
+ <mat-label>Strategy*</mat-label>
93
+ <mat-select formControlName="strategy">
94
+ <mat-option value="static">Static</mat-option>
95
+ <mat-option value="exponential">Exponential</mat-option>
96
+ </mat-select>
97
+ </mat-form-field>
98
+ </div>
99
+ </div>
100
+
101
+ <mat-form-field appearance="outline" class="full-width">
102
+ <mat-label>Response Prompt</mat-label>
103
+ <textarea matInput formControlName="response_prompt"
104
+ rows="4"
105
+ placeholder="Convert the API response to human-friendly text..."></textarea>
106
+ <mat-hint>Use {{api_response}} to reference the API response</mat-hint>
107
+ </mat-form-field>
108
+
109
+ <mat-form-field appearance="outline" class="full-width">
110
+ <mat-label>Proxy URL (Optional)</mat-label>
111
+ <input matInput formControlName="proxy"
112
+ placeholder="http://proxy.example.com:8080">
113
+ </mat-form-field>
114
+ </div>
115
+ </mat-tab>
116
+
117
+ <!-- Headers Tab -->
118
+ <mat-tab label="Headers">
119
+ <div class="tab-content">
120
+ <div class="headers-section">
121
+ <div class="section-header">
122
+ <h4>Request Headers</h4>
123
+ <button mat-raised-button color="primary" type="button" (click)="addHeader()">
124
+ <mat-icon>add</mat-icon>
125
+ Add Header
126
+ </button>
127
+ </div>
128
+
129
+ <div formArrayName="headers" class="headers-list">
130
+ <div *ngFor="let header of headers.controls; let i = index"
131
+ [formGroupName]="i"
132
+ class="header-row">
133
+ <mat-form-field appearance="outline">
134
+ <mat-label>Key</mat-label>
135
+ <input matInput formControlName="key" placeholder="Content-Type">
136
+ </mat-form-field>
137
+
138
+ <mat-form-field appearance="outline" class="header-value">
139
+ <mat-label>Value</mat-label>
140
+ <input matInput formControlName="value" placeholder="application/json">
141
+ </mat-form-field>
142
+
143
+ <button mat-icon-button color="warn" type="button" (click)="removeHeader(i)">
144
+ <mat-icon>delete</mat-icon>
145
+ </button>
146
+ </div>
147
+ </div>
148
+
149
+ <div *ngIf="headers.length === 0" class="empty-state">
150
+ <mat-icon>info</mat-icon>
151
+ <p>No headers defined. Click "Add Header" to create one.</p>
152
+ </div>
153
+
154
+ <div class="template-helpers">
155
+ <mat-expansion-panel>
156
+ <mat-expansion-panel-header>
157
+ <mat-panel-title>
158
+ <mat-icon>help_outline</mat-icon>
159
+ Common Headers
160
+ </mat-panel-title>
161
+ </mat-expansion-panel-header>
162
+ <div class="common-headers">
163
+ <p><strong>Content-Type:</strong> application/json</p>
164
+ <p><strong>Authorization:</strong> Bearer {{auth_tokens.api_name.token}}</p>
165
+ <p><strong>Accept:</strong> application/json</p>
166
+ </div>
167
+ </mat-expansion-panel>
168
+ </div>
169
+ </div>
170
+ </div>
171
+ </mat-tab>
172
+
173
+ <!-- Auth Tab -->
174
+ <mat-tab label="Auth">
175
+ <div class="tab-content">
176
+ <div formGroupName="auth">
177
+ <mat-checkbox formControlName="enabled">
178
+ Enable Authentication
179
+ </mat-checkbox>
180
+
181
+ <div *ngIf="form.get('auth.enabled')?.value" class="auth-settings">
182
+ <mat-form-field appearance="outline" class="full-width">
183
+ <mat-label>Token Endpoint*</mat-label>
184
+ <input matInput formControlName="token_endpoint"
185
+ placeholder="https://api.example.com/auth">
186
+ <mat-error *ngIf="form.get('auth.token_endpoint')?.hasError('required')">
187
+ Token endpoint is required when auth is enabled
188
+ </mat-error>
189
+ </mat-form-field>
190
+
191
+ <mat-form-field appearance="outline" class="full-width">
192
+ <mat-label>Response Token Path*</mat-label>
193
+ <input matInput formControlName="response_token_path"
194
+ placeholder="access_token or data.token">
195
+ <mat-hint>JSON path to extract token from response (e.g., data.token)</mat-hint>
196
+ <mat-error *ngIf="form.get('auth.response_token_path')?.hasError('required')">
197
+ Token path is required when auth is enabled
198
+ </mat-error>
199
+ </mat-form-field>
200
+
201
+ <div class="form-section">
202
+ <label class="section-label">Token Request Body:</label>
203
+ <div class="json-editor">
204
+ <textarea formControlName="token_request_body"
205
+ placeholder='{"grant_type": "client_credentials"}'
206
+ rows="4"
207
+ class="json-textarea"></textarea>
208
+ <button mat-button type="button"
209
+ (click)="validateJSON('auth.token_request_body')"
210
+ [color]="validateJSON('auth.token_request_body') ? 'primary' : 'warn'">
211
+ <mat-icon>check_circle</mat-icon>
212
+ Validate JSON
213
+ </button>
214
+ </div>
215
+ </div>
216
+
217
+ <mat-divider></mat-divider>
218
+
219
+ <h4>Token Refresh (Optional)</h4>
220
+
221
+ <mat-form-field appearance="outline" class="full-width">
222
+ <mat-label>Token Refresh Endpoint</mat-label>
223
+ <input matInput formControlName="token_refresh_endpoint"
224
+ placeholder="https://api.example.com/refresh">
225
+ </mat-form-field>
226
+
227
+ <div class="form-section" *ngIf="form.get('auth.token_refresh_endpoint')?.value">
228
+ <label class="section-label">Token Refresh Body:</label>
229
+ <div class="json-editor">
230
+ <textarea formControlName="token_refresh_body"
231
+ placeholder='{"refresh_token": "{{auth_tokens.api_name.refresh_token}}"}'
232
+ rows="4"
233
+ class="json-textarea"></textarea>
234
+ <button mat-button type="button"
235
+ (click)="validateJSON('auth.token_refresh_body')"
236
+ [color]="validateJSON('auth.token_refresh_body') ? 'primary' : 'warn'">
237
+ <mat-icon>check_circle</mat-icon>
238
+ Validate JSON
239
+ </button>
240
+ </div>
241
+ </div>
242
+ </div>
243
+ </div>
244
+ </div>
245
+ </mat-tab>
246
+
247
+ <!-- Test Tab -->
248
+ <mat-tab label="Test">
249
+ <div class="tab-content">
250
+ <div class="test-section">
251
+ <h4>Test API Configuration</h4>
252
+ <p>Test your API with sample data before saving.</p>
253
+
254
+ <div class="test-info">
255
+ <mat-chip-listbox>
256
+ <mat-chip-option selected>{{ form.get('method')?.value || 'POST' }}</mat-chip-option>
257
+ <mat-chip-option>{{ form.get('url')?.value || 'No URL set' }}</mat-chip-option>
258
+ </mat-chip-listbox>
259
+ </div>
260
+
261
+ <button mat-raised-button color="accent"
262
+ (click)="testAPI()"
263
+ [disabled]="testing || !form.get('url')?.valid">
264
+ <mat-icon>play_arrow</mat-icon>
265
+ {{ testing ? 'Testing...' : 'Send Test Request' }}
266
+ </button>
267
+
268
+ <div *ngIf="testResult" class="test-result">
269
+ <h4>Test Result:</h4>
270
+
271
+ <div class="result-status" [class.success]="testResult.success" [class.error]="!testResult.success">
272
+ <mat-icon>{{ testResult.success ? 'check_circle' : 'error' }}</mat-icon>
273
+ <span>{{ testResult.success ? 'Success' : 'Failed' }}</span>
274
+ <span *ngIf="testResult.status_code" class="status-code">
275
+ Status: {{ testResult.status_code }}
276
+ </span>
277
+ <span *ngIf="testResult.response_time_ms" class="response-time">
278
+ Time: {{ testResult.response_time_ms }}ms
279
+ </span>
280
+ </div>
281
+
282
+ <div *ngIf="testResult.error" class="error-message">
283
+ <mat-icon>error_outline</mat-icon>
284
+ {{ testResult.error }}
285
+ </div>
286
+
287
+ <div *ngIf="testResult.headers" class="response-section">
288
+ <h5>Response Headers:</h5>
289
+ <pre>{{ testResult.headers | json }}</pre>
290
+ </div>
291
+
292
+ <div *ngIf="testResult.body" class="response-section">
293
+ <h5>Response Body:</h5>
294
+ <pre>{{ testResult.body }}</pre>
295
+ </div>
296
+ </div>
297
+
298
+ <div class="test-note">
299
+ <mat-icon>info</mat-icon>
300
+ <p>Note: Test requests use placeholder values for template variables.</p>
301
+ </div>
302
+ </div>
303
+ </div>
304
+ </mat-tab>
305
+ </mat-tab-group>
306
+ </form>
307
+ </mat-dialog-content>
308
+
309
+ <mat-dialog-actions align="end">
310
+ <button mat-button (click)="cancel()">Cancel</button>
311
+ <button mat-raised-button color="primary"
312
+ (click)="save()"
313
+ [disabled]="form.invalid || saving">
314
+ {{ saving ? 'Saving...' : 'Save' }}
315
+ </button>
316
+ </mat-dialog-actions>