Применение к сессии, USE заменён на checkbox
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Sms.TaskTwo.Core.Models;
|
||||
using Sms.TaskTwo.Core.Services;
|
||||
|
||||
@@ -8,14 +7,19 @@ namespace Sms.TaskTwo.ViewModels;
|
||||
public sealed partial class EnvironmentVariableRowViewModel : ObservableObject
|
||||
{
|
||||
private readonly EnvironmentVariablesService _service;
|
||||
private readonly Action? _onCustomRemoved;
|
||||
private bool _isLoading;
|
||||
|
||||
public EnvironmentVariableRowViewModel(EnvironmentVariableRow row, EnvironmentVariablesService service)
|
||||
public EnvironmentVariableRowViewModel(
|
||||
EnvironmentVariableRow row,
|
||||
EnvironmentVariablesService service,
|
||||
Action? onCustomRemoved = null)
|
||||
{
|
||||
Field = row.Field;
|
||||
IsFromAppSettings = row.IsFromAppSettings;
|
||||
IsCustom = row.IsCustom;
|
||||
_service = service;
|
||||
_onCustomRemoved = onCustomRemoved;
|
||||
ApplySnapshot(row, suppressSave: true);
|
||||
RefreshActualValue(_service.GetProcessValue(Field));
|
||||
}
|
||||
@@ -26,8 +30,10 @@ public sealed partial class EnvironmentVariableRowViewModel : ObservableObject
|
||||
|
||||
public bool IsCustom { get; }
|
||||
|
||||
public bool CanChangeUserStore => !IsFromAppSettings;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _isPersistedInUserStore;
|
||||
private bool _useUserStore;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _actualValue = string.Empty;
|
||||
@@ -35,36 +41,60 @@ public sealed partial class EnvironmentVariableRowViewModel : ObservableObject
|
||||
public string ActualValueDisplay =>
|
||||
string.IsNullOrEmpty(ActualValue) ? "<нет>" : ActualValue;
|
||||
|
||||
public string UserStoreBadge => IsPersistedInUserStore ? "USER" : string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _requiredValue = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _comment = string.Empty;
|
||||
|
||||
partial void OnIsPersistedInUserStoreChanged(bool value)
|
||||
partial void OnUseUserStoreChanged(bool value)
|
||||
{
|
||||
OnPropertyChanged(nameof(UserStoreBadge));
|
||||
DeleteFromUserStoreCommand.NotifyCanExecuteChanged();
|
||||
RowAppearanceChanged?.Invoke(this, EventArgs.Empty);
|
||||
|
||||
if (_isLoading)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsFromAppSettings && !value)
|
||||
{
|
||||
BeginLoad();
|
||||
UseUserStore = true;
|
||||
EndLoad();
|
||||
return;
|
||||
}
|
||||
|
||||
if (value)
|
||||
{
|
||||
_service.SaveValue(Field, RequiredValue);
|
||||
RefreshActualValue(_service.GetProcessValue(Field));
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsCustom)
|
||||
{
|
||||
_service.RemoveVariable(Field);
|
||||
_onCustomRemoved?.Invoke();
|
||||
return;
|
||||
}
|
||||
|
||||
_service.DeleteFromUserStore(Field);
|
||||
BeginLoad();
|
||||
RequiredValue = _service.GetDisplayValue(Field);
|
||||
EndLoad();
|
||||
RefreshActualValue(_service.GetProcessValue(Field));
|
||||
}
|
||||
|
||||
partial void OnActualValueChanged(string value) => OnPropertyChanged(nameof(ActualValueDisplay));
|
||||
|
||||
partial void OnRequiredValueChanged(string value)
|
||||
{
|
||||
if (_isLoading)
|
||||
if (_isLoading || !UseUserStore)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_service.SaveValue(Field, value);
|
||||
if (!IsPersistedInUserStore)
|
||||
{
|
||||
IsPersistedInUserStore = true;
|
||||
}
|
||||
|
||||
RefreshActualValue(_service.GetProcessValue(Field));
|
||||
}
|
||||
|
||||
@@ -79,7 +109,7 @@ public sealed partial class EnvironmentVariableRowViewModel : ObservableObject
|
||||
|
||||
RequiredValue = row.Value;
|
||||
Comment = row.Comment;
|
||||
IsPersistedInUserStore = row.IsPersistedInUserStore;
|
||||
UseUserStore = row.IsFromAppSettings || row.IsPersistedInUserStore;
|
||||
|
||||
if (suppressSave)
|
||||
{
|
||||
@@ -105,26 +135,4 @@ public sealed partial class EnvironmentVariableRowViewModel : ObservableObject
|
||||
|
||||
_service.SaveComment(Field, value);
|
||||
}
|
||||
|
||||
[RelayCommand(CanExecute = nameof(CanDeleteFromUserStore))]
|
||||
private void DeleteFromUserStore()
|
||||
{
|
||||
if (IsCustom)
|
||||
{
|
||||
_service.RemoveVariable(Field);
|
||||
Removed?.Invoke(this, EventArgs.Empty);
|
||||
return;
|
||||
}
|
||||
|
||||
_service.DeleteFromUserStore(Field);
|
||||
BeginLoad();
|
||||
IsPersistedInUserStore = false;
|
||||
RequiredValue = _service.GetDisplayValue(Field);
|
||||
EndLoad();
|
||||
RefreshActualValue(_service.GetProcessValue(Field));
|
||||
}
|
||||
|
||||
public event EventHandler? Removed;
|
||||
|
||||
private bool CanDeleteFromUserStore() => IsPersistedInUserStore || IsCustom;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user