Spaces:
Running
Running
Update flare-ui/src/app/dialogs/project-edit-dialog/project-edit-dialog.component.ts
Browse files
flare-ui/src/app/dialogs/project-edit-dialog/project-edit-dialog.component.ts
CHANGED
@@ -129,17 +129,30 @@ export default class ProjectEditDialogComponent implements OnInit {
|
|
129 |
) {}
|
130 |
|
131 |
ngOnInit() {
|
132 |
-
this.
|
133 |
-
|
134 |
-
{ value: '', disabled: this.data.mode === 'edit' },
|
135 |
-
[Validators.required, Validators.pattern(/^[a-zA-Z0-9_]+$/)]
|
136 |
-
],
|
137 |
-
caption: [''],
|
138 |
-
last_update_date: ['']
|
139 |
-
});
|
140 |
-
|
141 |
if (this.data.mode === 'edit' && this.data.project) {
|
142 |
-
this.form.patchValue(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
143 |
}
|
144 |
}
|
145 |
|
@@ -149,28 +162,65 @@ export default class ProjectEditDialogComponent implements OnInit {
|
|
149 |
}
|
150 |
|
151 |
async save() {
|
152 |
-
if (this.form.invalid)
|
153 |
-
|
|
|
|
|
|
|
154 |
this.saving = true;
|
155 |
try {
|
156 |
-
const
|
157 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
158 |
if (this.data.mode === 'create') {
|
159 |
-
await this.apiService.createProject(
|
160 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
161 |
} else {
|
162 |
-
|
163 |
-
this.
|
|
|
|
|
164 |
}
|
165 |
-
|
166 |
-
this.dialogRef.close(
|
167 |
} catch (error: any) {
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
});
|
174 |
} finally {
|
175 |
this.saving = false;
|
176 |
}
|
|
|
129 |
) {}
|
130 |
|
131 |
ngOnInit() {
|
132 |
+
this.initializeForm();
|
133 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
134 |
if (this.data.mode === 'edit' && this.data.project) {
|
135 |
+
this.form.patchValue({
|
136 |
+
name: this.data.project.name,
|
137 |
+
caption: this.data.project.caption || '',
|
138 |
+
icon: this.data.project.icon || 'folder',
|
139 |
+
description: this.data.project.description || '',
|
140 |
+
defaultLanguage: this.data.project.default_language || 'tr',
|
141 |
+
supportedLanguages: this.data.project.supported_languages || ['tr'],
|
142 |
+
timezone: this.data.project.timezone || 'Europe/Istanbul',
|
143 |
+
region: this.data.project.region || 'tr-TR',
|
144 |
+
testUsers: this.data.project.test_users || []
|
145 |
+
});
|
146 |
+
|
147 |
+
// Rebuild test users form array
|
148 |
+
const testUsersArray = this.form.get('testUsers') as FormArray;
|
149 |
+
testUsersArray.clear();
|
150 |
+
(this.data.project.test_users || []).forEach(phoneNumber => {
|
151 |
+
testUsersArray.push(this.fb.control(phoneNumber, Validators.required));
|
152 |
+
});
|
153 |
+
} else if (this.data.mode === 'create') {
|
154 |
+
// Yeni proje için boş bir versiyon otomatik ekle
|
155 |
+
this.data.autoCreateVersion = true;
|
156 |
}
|
157 |
}
|
158 |
|
|
|
162 |
}
|
163 |
|
164 |
async save() {
|
165 |
+
if (this.form.invalid) {
|
166 |
+
this.form.markAllAsTouched();
|
167 |
+
return;
|
168 |
+
}
|
169 |
+
|
170 |
this.saving = true;
|
171 |
try {
|
172 |
+
const formValue = this.form.value;
|
173 |
+
const projectData = {
|
174 |
+
...formValue,
|
175 |
+
test_users: formValue.testUsers || [],
|
176 |
+
default_language: formValue.defaultLanguage,
|
177 |
+
supported_languages: formValue.supportedLanguages
|
178 |
+
};
|
179 |
+
|
180 |
+
let result;
|
181 |
if (this.data.mode === 'create') {
|
182 |
+
result = await this.apiService.createProject(projectData).toPromise();
|
183 |
+
|
184 |
+
// Otomatik boş versiyon oluştur
|
185 |
+
if (this.data.autoCreateVersion && result) {
|
186 |
+
const defaultVersion = {
|
187 |
+
description: 'Initial version',
|
188 |
+
default_api: '',
|
189 |
+
published: false,
|
190 |
+
llm: {
|
191 |
+
repo_id: '',
|
192 |
+
generation_config: {
|
193 |
+
max_new_tokens: 512,
|
194 |
+
temperature: 0.7,
|
195 |
+
top_p: 0.95,
|
196 |
+
top_k: 50,
|
197 |
+
repetition_penalty: 1.1
|
198 |
+
},
|
199 |
+
use_fine_tune: false,
|
200 |
+
fine_tune_zip: ''
|
201 |
+
},
|
202 |
+
intents: [],
|
203 |
+
parameters: []
|
204 |
+
};
|
205 |
+
|
206 |
+
await this.apiService.createVersion(result.id, defaultVersion).toPromise();
|
207 |
+
}
|
208 |
+
|
209 |
+
this.showMessage('Project created successfully!', false);
|
210 |
} else {
|
211 |
+
projectData.id = this.data.project.id;
|
212 |
+
projectData.last_update_date = this.data.project.last_update_date;
|
213 |
+
result = await this.apiService.updateProject(projectData).toPromise();
|
214 |
+
this.showMessage('Project updated successfully!', false);
|
215 |
}
|
216 |
+
|
217 |
+
this.dialogRef.close(result);
|
218 |
} catch (error: any) {
|
219 |
+
if (error.status === 409) {
|
220 |
+
this.showMessage('This record was modified by another user. Please reload and try again.', true);
|
221 |
+
} else {
|
222 |
+
this.showMessage(error.error?.detail || 'Operation failed', true);
|
223 |
+
}
|
|
|
224 |
} finally {
|
225 |
this.saving = false;
|
226 |
}
|