@@ -216,12 +216,6 @@ else
216216 private bool _isSavingInheritance ;
217217
218218 // Dialog state
219- private GlossaryTermDto ? _editingTerm ;
220- private string _formSourceTerm = " " ;
221- private string _formSourceLanguage = " en" ;
222- private string _formDescription = " " ;
223- private bool _formCaseSensitive ;
224- private Dictionary <string , string > _formTranslations = new ();
225219 private List <string > _availableLanguages = new () { " en" , " fr" , " de" , " es" , " it" , " el" , " pt" , " nl" , " pl" , " ru" , " ja" , " zh" , " ko" };
226220
227221 private string _projectName = " " ;
@@ -329,135 +323,38 @@ else
329323
330324 private async Task OpenAddDialog ()
331325 {
332- _editingTerm = null ;
333- _formSourceTerm = " " ;
334- _formSourceLanguage = " en" ;
335- _formDescription = " " ;
336- _formCaseSensitive = false ;
337- _formTranslations = new Dictionary <string , string >();
338- foreach (var lang in _availableLanguages .Where (l => l != " en" ))
339- {
340- _formTranslations [lang ] = " " ;
341- }
342-
343- await ShowTermDialog (" Add Glossary Term" );
344- }
345-
346- private async Task OpenEditDialog (GlossaryTermDto term )
347- {
348- _editingTerm = term ;
349- _formSourceTerm = term .SourceTerm ;
350- _formSourceLanguage = term .SourceLanguage ;
351- _formDescription = term .Description ?? " " ;
352- _formCaseSensitive = term .CaseSensitive ;
353- _formTranslations = new Dictionary <string , string >(term .Translations );
354-
355- foreach (var lang in _availableLanguages .Where (l => l != term .SourceLanguage ))
356- {
357- if (! _formTranslations .ContainsKey (lang ))
358- _formTranslations [lang ] = " " ;
359- }
360-
361- await ShowTermDialog (" Edit Glossary Term" );
362- }
363-
364- private async Task ShowTermDialog (string title )
365- {
366- var result = await DialogService .OpenAsync (title , ds =>
367- @< RadzenStack Gap = " 1rem" >
368- < RadzenFormField Text = " Source Term" Variant = " Radzen.Variant.Outlined" Style = " width: 100%;" >
369- < RadzenTextBox @bind - Value = " _formSourceTerm" Placeholder = " e.g., Dashboard" Style = " width: 100%;" / >
370- < / RadzenFormField >
371-
372- < RadzenFormField Text = " Source Language" Variant = " Radzen.Variant.Outlined" Style = " width: 100%;" >
373- < RadzenDropDown @bind - Value = " _formSourceLanguage" Data = " @_availableLanguages" Style = " width: 100%;" >
374- < Template Context = " lang" > @lang .ToUpperInvariant ()< / Template >
375- < / RadzenDropDown >
376- < / RadzenFormField >
377-
378- < RadzenFormField Text = " Description (optional)" Variant = " Radzen.Variant.Outlined" Style = " width: 100%;" >
379- < RadzenTextArea @bind - Value = " _formDescription" Rows = " 2" Placeholder = " Context or usage notes" Style = " width: 100%;" / >
380- < / RadzenFormField >
381-
382- < RadzenCheckBox @bind - Value = " _formCaseSensitive" TValue = " bool" >
383- < Template > Case - sensitive matching < / Template >
384- < / RadzenCheckBox >
385-
386- < hr / >
387-
388- < RadzenText TextStyle = " TextStyle.Subtitle1" > Translations < / RadzenText >
389- @foreach (var lang in _availableLanguages .Where (l => l != _formSourceLanguage ))
390- {
391- < RadzenFormField Text = " @($" Translation ({lang .ToUpperInvariant ()})" )" Variant = " Radzen.Variant.Outlined" Style = " width: 100%;" >
392- < RadzenTextBox Value = " @GetTranslation(lang)" ValueChanged = " @(v => SetTranslation(lang, v))" Placeholder = " @($" Enter translation in {lang .ToUpperInvariant ()}" )" Style = " width: 100%;" / >
393- < / RadzenFormField >
394- }
395-
396- < RadzenStack Orientation = " Radzen.Orientation.Horizontal" JustifyContent = " JustifyContent.End" Gap = " 0.5rem" class = " rz-mt-4" >
397- < RadzenButton Variant = " Radzen.Variant.Text" Text = " Cancel" Click = " @(() => ds.Close(false))" / >
398- < RadzenButton Variant = " Radzen.Variant.Filled" ButtonStyle = " ButtonStyle.Primary"
399- Text = " @(_editingTerm == null ? " Add " : " Save " )"
400- Click = " @(() => ds.Close(true))"
401- Disabled = " @(string.IsNullOrWhiteSpace(_formSourceTerm) || string.IsNullOrWhiteSpace(_formSourceLanguage))" / >
402- < / RadzenStack >
403- < / RadzenStack > ,
326+ var result = await DialogService .OpenAsync <GlossaryTermDialog >(
327+ " Add Glossary Term" ,
328+ new Dictionary <string , object >
329+ {
330+ { " ProjectId" , ProjectId },
331+ { " AvailableLanguages" , _availableLanguages },
332+ { " ShowCaseSensitive" , true }
333+ },
404334 new Radzen .DialogOptions { Width = " 500px" });
405335
406336 if (result == true )
407337 {
408- await SaveTerm ();
338+ await LoadGlossaryAsync ();
409339 }
410340 }
411341
412- private string GetTranslation (string lang ) => _formTranslations .TryGetValue (lang , out var val ) ? val : " " ;
413-
414- private void SetTranslation (string lang , string value ) => _formTranslations [lang ] = value ;
415-
416- private async Task SaveTerm ()
342+ private async Task OpenEditDialog (GlossaryTermDto term )
417343 {
418- if (string .IsNullOrWhiteSpace (_formSourceTerm ) || string .IsNullOrWhiteSpace (_formSourceLanguage ))
419- return ;
420-
421- try
422- {
423- var translations = _formTranslations
424- .Where (kv => ! string .IsNullOrWhiteSpace (kv .Value ))
425- .ToDictionary (kv => kv .Key , kv => kv .Value );
426-
427- if (_editingTerm == null )
344+ var result = await DialogService .OpenAsync <GlossaryTermDialog >(
345+ " Edit Glossary Term" ,
346+ new Dictionary <string , object >
428347 {
429- var request = new CreateGlossaryTermRequest
430- {
431- SourceTerm = _formSourceTerm ,
432- SourceLanguage = _formSourceLanguage ,
433- Description = string .IsNullOrWhiteSpace (_formDescription ) ? null : _formDescription ,
434- CaseSensitive = _formCaseSensitive ,
435- Translations = translations
436- };
437-
438- await GlossaryService .CreateProjectTermAsync (ProjectId , request );
439- NotificationService .Notify (NotificationSeverity .Success , " Success" , " Term added successfully" );
440- }
441- else
442- {
443- var request = new UpdateGlossaryTermRequest
444- {
445- SourceTerm = _formSourceTerm ,
446- SourceLanguage = _formSourceLanguage ,
447- Description = string .IsNullOrWhiteSpace (_formDescription ) ? null : _formDescription ,
448- CaseSensitive = _formCaseSensitive ,
449- Translations = translations
450- };
451-
452- await GlossaryService .UpdateProjectTermAsync (ProjectId , _editingTerm .Id , request );
453- NotificationService .Notify (NotificationSeverity .Success , " Success" , " Term updated successfully" );
454- }
348+ { " ProjectId" , ProjectId },
349+ { " AvailableLanguages" , _availableLanguages },
350+ { " EditingTerm" , term },
351+ { " ShowCaseSensitive" , true }
352+ },
353+ new Radzen .DialogOptions { Width = " 500px" });
455354
456- await LoadGlossaryAsync ();
457- }
458- catch (Exception ex )
355+ if (result == true )
459356 {
460- NotificationService . Notify ( NotificationSeverity . Error , " Error " , ex . Message );
357+ await LoadGlossaryAsync ( );
461358 }
462359 }
463360
0 commit comments