ciyidogan commited on
Commit
1b0bb82
·
verified ·
1 Parent(s): 8e5c46e

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 Language -->
83
  <mat-form-field appearance="outline" class="full-width">
84
- <mat-label>Default Language</mat-label>
85
  <mat-select
86
- formControlName="defaultLanguage"
87
- (selectionChange)="onDefaultLanguageChange()">
88
  @if (loadingLocales) {
89
  <mat-option disabled>
90
  <mat-spinner diameter="20"></mat-spinner>
91
- Loading languages...
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 language for this project</mat-hint>
103
  </mat-form-field>
104
 
105
- <!-- Supported Languages -->
106
  <mat-form-field appearance="outline" class="full-width">
107
- <mat-label>Supported Languages</mat-label>
108
  <mat-select
109
- formControlName="supportedLanguages"
110
- (selectionChange)="onSupportedLanguagesChange()"
111
  multiple>
112
  <mat-select-trigger>
113
- <div class="selected-languages">
114
- @for (lang of form.get('supportedLanguages')?.value || []; track lang; let last = $last) {
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>language</mat-icon>
127
- <mat-hint>Languages available in this project</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
- defaultLanguage: this.data.project.default_locale || 'tr', // default_language yerine default_locale
203
- supportedLanguages: this.data.project.supported_locales || ['tr'], // supported_languages yerine supported_locales
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
- defaultLanguage: 'tr',
212
- supportedLanguages: ['tr'],
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
- defaultLanguage: [defaultValues.defaultLanguage],
223
- supportedLanguages: [defaultValues.supportedLanguages],
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.validateSelectedLanguages();
243
  },
244
  error: (err) => {
245
- this.showMessage('Failed to load available languages', 'error');
246
  this.loadingLocales = false;
247
  // Use fallback locales
248
  this.availableLocales = [
249
- { code: 'tr-TR', name: 'Türkçe', english_name: 'Turkish' },
250
- { code: 'en-US', name: 'English', english_name: 'English (US)' }
251
  ];
252
  }
253
  });
254
  }
255
 
256
- validateSelectedLanguages() {
257
  const availableCodes = this.availableLocales.map(l => l.code);
258
- const currentSupported = this.form.get('supportedLanguages')?.value || [];
259
- const currentDefault = this.form.get('defaultLanguage')?.value;
260
 
261
- // Filter out any unsupported languages
262
  const validSupported = currentSupported.filter((lang: string) =>
263
  availableCodes.includes(lang)
264
  );
265
 
266
- // Update form if any languages were removed
267
  if (validSupported.length !== currentSupported.length) {
268
- this.form.patchValue({ supportedLanguages: validSupported });
269
  }
270
 
271
- // Ensure default language is valid
272
  if (!availableCodes.includes(currentDefault)) {
273
  const newDefault = availableCodes[0] || 'tr-TR';
274
  this.form.patchValue({
275
- defaultLanguage: newDefault,
276
- supportedLanguages: [...validSupported, newDefault]
277
  });
278
  }
279
  }
280
 
281
- onDefaultLanguageChange() {
282
- // Default language değiştiğinde bir şey yapmaya gerek yok
283
- // Çünkü default_language (Türkçe) ve supported_languages (tr-TR) farklı tipte
284
  }
285
 
286
- onSupportedLanguagesChange() {
287
- // Supported languages 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 supportedLangs = this.form.get('supportedLanguages')?.value || [];
290
- if (supportedLangs.length === 0) {
291
  // En az bir dil seçilmeli
292
  this.form.patchValue({
293
- supportedLanguages: ['tr-TR']
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
- 'defaultLanguage': 'Default Language',
325
- 'supportedLanguages': 'Supported Languages',
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.defaultLanguage, // default_language yerine default_locale
381
- supported_locales: formValue.supportedLanguages, // supported_languages yerine supported_locales
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
  };