Spaces:
Building
Building
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
@@ -79,16 +79,16 @@ export interface ProjectDialogData {
|
|
79 |
<textarea matInput formControlName="description" rows="3"></textarea>
|
80 |
</mat-form-field>
|
81 |
|
82 |
-
<!-- Default
|
83 |
<mat-form-field appearance="outline" class="full-width">
|
84 |
-
<mat-label>Default
|
85 |
<mat-select
|
86 |
-
formControlName="
|
87 |
-
(selectionChange)="
|
88 |
@if (loadingLocales) {
|
89 |
<mat-option disabled>
|
90 |
<mat-spinner diameter="20"></mat-spinner>
|
91 |
-
Loading
|
92 |
</mat-option>
|
93 |
}
|
94 |
@for (locale of availableLocales; track locale.code) {
|
@@ -99,19 +99,19 @@ export interface ProjectDialogData {
|
|
99 |
}
|
100 |
</mat-select>
|
101 |
<mat-icon matPrefix>translate</mat-icon>
|
102 |
-
<mat-hint>Primary
|
103 |
</mat-form-field>
|
104 |
|
105 |
-
<!-- Supported
|
106 |
<mat-form-field appearance="outline" class="full-width">
|
107 |
-
<mat-label>Supported
|
108 |
<mat-select
|
109 |
-
formControlName="
|
110 |
-
(selectionChange)="
|
111 |
multiple>
|
112 |
<mat-select-trigger>
|
113 |
-
<div class="selected-
|
114 |
-
@for (lang of form.get('
|
115 |
<span>{{ getLocaleName(lang) }}@if (!last) {, }</span>
|
116 |
}
|
117 |
</div>
|
@@ -123,8 +123,8 @@ export interface ProjectDialogData {
|
|
123 |
</mat-option>
|
124 |
}
|
125 |
</mat-select>
|
126 |
-
<mat-icon matPrefix>
|
127 |
-
<mat-hint>
|
128 |
</mat-form-field>
|
129 |
|
130 |
<mat-form-field appearance="outline" class="full-width">
|
@@ -199,8 +199,8 @@ export default class ProjectEditDialogComponent implements OnInit, OnDestroy {
|
|
199 |
caption: this.data.project.caption || '',
|
200 |
icon: this.data.project.icon || 'folder',
|
201 |
description: this.data.project.description || '',
|
202 |
-
|
203 |
-
|
204 |
timezone: this.data.project.timezone || 'Europe/Istanbul',
|
205 |
region: this.data.project.region || 'tr-TR'
|
206 |
} : {
|
@@ -208,8 +208,8 @@ export default class ProjectEditDialogComponent implements OnInit, OnDestroy {
|
|
208 |
caption: '',
|
209 |
icon: 'folder',
|
210 |
description: '',
|
211 |
-
|
212 |
-
|
213 |
timezone: 'Europe/Istanbul',
|
214 |
region: 'tr-TR'
|
215 |
};
|
@@ -219,8 +219,8 @@ export default class ProjectEditDialogComponent implements OnInit, OnDestroy {
|
|
219 |
caption: [defaultValues.caption, Validators.required],
|
220 |
icon: [defaultValues.icon],
|
221 |
description: [defaultValues.description],
|
222 |
-
|
223 |
-
|
224 |
timezone: [defaultValues.timezone],
|
225 |
region: [defaultValues.region]
|
226 |
});
|
@@ -239,58 +239,58 @@ export default class ProjectEditDialogComponent implements OnInit, OnDestroy {
|
|
239 |
next: (locales) => {
|
240 |
this.availableLocales = locales;
|
241 |
this.loadingLocales = false;
|
242 |
-
this.
|
243 |
},
|
244 |
error: (err) => {
|
245 |
-
this.showMessage('Failed to load available
|
246 |
this.loadingLocales = false;
|
247 |
// Use fallback locales
|
248 |
this.availableLocales = [
|
249 |
-
{ code: 'tr
|
250 |
-
{ code: 'en
|
251 |
];
|
252 |
}
|
253 |
});
|
254 |
}
|
255 |
|
256 |
-
|
257 |
const availableCodes = this.availableLocales.map(l => l.code);
|
258 |
-
const currentSupported = this.form.get('
|
259 |
-
const currentDefault = this.form.get('
|
260 |
|
261 |
-
// Filter out any unsupported
|
262 |
const validSupported = currentSupported.filter((lang: string) =>
|
263 |
availableCodes.includes(lang)
|
264 |
);
|
265 |
|
266 |
-
// Update form if any
|
267 |
if (validSupported.length !== currentSupported.length) {
|
268 |
-
this.form.patchValue({
|
269 |
}
|
270 |
|
271 |
-
// Ensure default
|
272 |
if (!availableCodes.includes(currentDefault)) {
|
273 |
const newDefault = availableCodes[0] || 'tr-TR';
|
274 |
this.form.patchValue({
|
275 |
-
|
276 |
-
|
277 |
});
|
278 |
}
|
279 |
}
|
280 |
|
281 |
-
|
282 |
-
// Default
|
283 |
-
// Çünkü
|
284 |
}
|
285 |
|
286 |
-
|
287 |
-
// Supported
|
288 |
// En az bir dil seçili olduğu sürece sorun yok
|
289 |
-
const
|
290 |
-
if (
|
291 |
// En az bir dil seçilmeli
|
292 |
this.form.patchValue({
|
293 |
-
|
294 |
});
|
295 |
}
|
296 |
}
|
@@ -321,8 +321,8 @@ export default class ProjectEditDialogComponent implements OnInit, OnDestroy {
|
|
321 |
'name': 'Project Name',
|
322 |
'caption': 'Caption',
|
323 |
'description': 'Description',
|
324 |
-
'
|
325 |
-
'
|
326 |
'timezone': 'Timezone',
|
327 |
'region': 'Region',
|
328 |
'icon': 'Icon'
|
@@ -377,8 +377,8 @@ export default class ProjectEditDialogComponent implements OnInit, OnDestroy {
|
|
377 |
caption: formValue.caption,
|
378 |
icon: formValue.icon,
|
379 |
description: formValue.description,
|
380 |
-
default_locale: formValue.
|
381 |
-
supported_locales: formValue.
|
382 |
timezone: formValue.timezone,
|
383 |
region: formValue.region
|
384 |
};
|
|
|
79 |
<textarea matInput formControlName="description" rows="3"></textarea>
|
80 |
</mat-form-field>
|
81 |
|
82 |
+
<!-- Default Locale -->
|
83 |
<mat-form-field appearance="outline" class="full-width">
|
84 |
+
<mat-label>Default Locale</mat-label>
|
85 |
<mat-select
|
86 |
+
formControlName="defaultLocale"
|
87 |
+
(selectionChange)="onDefaultLocaleChange()">
|
88 |
@if (loadingLocales) {
|
89 |
<mat-option disabled>
|
90 |
<mat-spinner diameter="20"></mat-spinner>
|
91 |
+
Loading Locales...
|
92 |
</mat-option>
|
93 |
}
|
94 |
@for (locale of availableLocales; track locale.code) {
|
|
|
99 |
}
|
100 |
</mat-select>
|
101 |
<mat-icon matPrefix>translate</mat-icon>
|
102 |
+
<mat-hint>Primary Locale for this project</mat-hint>
|
103 |
</mat-form-field>
|
104 |
|
105 |
+
<!-- Supported Locales -->
|
106 |
<mat-form-field appearance="outline" class="full-width">
|
107 |
+
<mat-label>Supported Locales</mat-label>
|
108 |
<mat-select
|
109 |
+
formControlName="supportedLocales"
|
110 |
+
(selectionChange)="onSupportedLocalesChange()"
|
111 |
multiple>
|
112 |
<mat-select-trigger>
|
113 |
+
<div class="selected-locales">
|
114 |
+
@for (lang of form.get('supportedLocales')?.value || []; track lang; let last = $last) {
|
115 |
<span>{{ getLocaleName(lang) }}@if (!last) {, }</span>
|
116 |
}
|
117 |
</div>
|
|
|
123 |
</mat-option>
|
124 |
}
|
125 |
</mat-select>
|
126 |
+
<mat-icon matPrefix>locale</mat-icon>
|
127 |
+
<mat-hint>Locales available in this project</mat-hint>
|
128 |
</mat-form-field>
|
129 |
|
130 |
<mat-form-field appearance="outline" class="full-width">
|
|
|
199 |
caption: this.data.project.caption || '',
|
200 |
icon: this.data.project.icon || 'folder',
|
201 |
description: this.data.project.description || '',
|
202 |
+
defaultLocale: this.data.project.default_locale || 'tr',
|
203 |
+
supportedLolcales: this.data.project.supported_locales || ['tr'],
|
204 |
timezone: this.data.project.timezone || 'Europe/Istanbul',
|
205 |
region: this.data.project.region || 'tr-TR'
|
206 |
} : {
|
|
|
208 |
caption: '',
|
209 |
icon: 'folder',
|
210 |
description: '',
|
211 |
+
defaultLocale: 'tr',
|
212 |
+
supportedLocales: ['tr'],
|
213 |
timezone: 'Europe/Istanbul',
|
214 |
region: 'tr-TR'
|
215 |
};
|
|
|
219 |
caption: [defaultValues.caption, Validators.required],
|
220 |
icon: [defaultValues.icon],
|
221 |
description: [defaultValues.description],
|
222 |
+
defaultLocale: [defaultValues.defaultLocale],
|
223 |
+
supportedLocales: [defaultValues.supportedLocales],
|
224 |
timezone: [defaultValues.timezone],
|
225 |
region: [defaultValues.region]
|
226 |
});
|
|
|
239 |
next: (locales) => {
|
240 |
this.availableLocales = locales;
|
241 |
this.loadingLocales = false;
|
242 |
+
this.validateSelectedLocales();
|
243 |
},
|
244 |
error: (err) => {
|
245 |
+
this.showMessage('Failed to load available locales', 'error');
|
246 |
this.loadingLocales = false;
|
247 |
// Use fallback locales
|
248 |
this.availableLocales = [
|
249 |
+
{ code: 'tr', name: 'Türkçe', english_name: 'Turkish' },
|
250 |
+
{ code: 'en', name: 'English', english_name: 'English' }
|
251 |
];
|
252 |
}
|
253 |
});
|
254 |
}
|
255 |
|
256 |
+
validateSelectedLocales() {
|
257 |
const availableCodes = this.availableLocales.map(l => l.code);
|
258 |
+
const currentSupported = this.form.get('supportedLocales')?.value || [];
|
259 |
+
const currentDefault = this.form.get('defaultLocale')?.value;
|
260 |
|
261 |
+
// Filter out any unsupported Locales
|
262 |
const validSupported = currentSupported.filter((lang: string) =>
|
263 |
availableCodes.includes(lang)
|
264 |
);
|
265 |
|
266 |
+
// Update form if any Locales were removed
|
267 |
if (validSupported.length !== currentSupported.length) {
|
268 |
+
this.form.patchValue({ supportedLocales: validSupported });
|
269 |
}
|
270 |
|
271 |
+
// Ensure default Locale is valid
|
272 |
if (!availableCodes.includes(currentDefault)) {
|
273 |
const newDefault = availableCodes[0] || 'tr-TR';
|
274 |
this.form.patchValue({
|
275 |
+
defaultLocale: newDefault,
|
276 |
+
supportedLocales: [...validSupported, newDefault]
|
277 |
});
|
278 |
}
|
279 |
}
|
280 |
|
281 |
+
onDefaultLocaleChange() {
|
282 |
+
// Default Locale değiştiğinde bir şey yapmaya gerek yok
|
283 |
+
// Çünkü default_locale (Türkçe) ve supported_locales (tr-TR) farklı tipte
|
284 |
}
|
285 |
|
286 |
+
onSupportedLocalesChange() {
|
287 |
+
// Supported locales değiştiğinde de bir şey yapmaya gerek yok
|
288 |
// En az bir dil seçili olduğu sürece sorun yok
|
289 |
+
const supportedLocales = this.form.get('supportedLocales')?.value || [];
|
290 |
+
if (supportedLocales.length === 0) {
|
291 |
// En az bir dil seçilmeli
|
292 |
this.form.patchValue({
|
293 |
+
supportedLocales: ['tr-TR']
|
294 |
});
|
295 |
}
|
296 |
}
|
|
|
321 |
'name': 'Project Name',
|
322 |
'caption': 'Caption',
|
323 |
'description': 'Description',
|
324 |
+
'defaultLocale': 'Default Locale',
|
325 |
+
'supportedLocales': 'Supported Locales',
|
326 |
'timezone': 'Timezone',
|
327 |
'region': 'Region',
|
328 |
'icon': 'Icon'
|
|
|
377 |
caption: formValue.caption,
|
378 |
icon: formValue.icon,
|
379 |
description: formValue.description,
|
380 |
+
default_locale: formValue.defaultLocale,
|
381 |
+
supported_locales: formValue.supportedLocales,
|
382 |
timezone: formValue.timezone,
|
383 |
region: formValue.region
|
384 |
};
|