feat(configmanager): add LdapFormViewModel
Implement LdapFormViewModel for editing LDAP configuration section with properties for ServerUrlsText, GroupDn, SearchBase, ConnectionTimeoutSeconds, UseFakeAuth, and AdminBypassUsersText. Array properties use newline-separated text with StringSplitOptions.RemoveEmptyEntries | TrimEntries for splitting.
This commit is contained in:
@@ -0,0 +1,122 @@
|
||||
using JdeScoping.ConfigManager.Models;
|
||||
|
||||
namespace JdeScoping.ConfigManager.ViewModels.Forms;
|
||||
|
||||
/// <summary>
|
||||
/// ViewModel for editing LDAP configuration section.
|
||||
/// </summary>
|
||||
public class LdapFormViewModel : ViewModelBase
|
||||
{
|
||||
private readonly LdapSection _model;
|
||||
private readonly Action _onChanged;
|
||||
|
||||
public LdapFormViewModel(LdapSection model, Action onChanged)
|
||||
{
|
||||
_model = model ?? throw new ArgumentNullException(nameof(model));
|
||||
_onChanged = onChanged ?? throw new ArgumentNullException(nameof(onChanged));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the server URLs as newline-separated text.
|
||||
/// </summary>
|
||||
public string ServerUrlsText
|
||||
{
|
||||
get => string.Join("\n", _model.ServerUrls);
|
||||
set
|
||||
{
|
||||
var urls = value.Split('\n', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
|
||||
if (!_model.ServerUrls.SequenceEqual(urls))
|
||||
{
|
||||
_model.ServerUrls = urls;
|
||||
OnPropertyChanged();
|
||||
_onChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the group distinguished name.
|
||||
/// </summary>
|
||||
public string GroupDn
|
||||
{
|
||||
get => _model.GroupDn;
|
||||
set
|
||||
{
|
||||
if (_model.GroupDn != value)
|
||||
{
|
||||
_model.GroupDn = value;
|
||||
OnPropertyChanged();
|
||||
_onChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the search base distinguished name.
|
||||
/// </summary>
|
||||
public string SearchBase
|
||||
{
|
||||
get => _model.SearchBase;
|
||||
set
|
||||
{
|
||||
if (_model.SearchBase != value)
|
||||
{
|
||||
_model.SearchBase = value;
|
||||
OnPropertyChanged();
|
||||
_onChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the connection timeout in seconds.
|
||||
/// </summary>
|
||||
public int ConnectionTimeoutSeconds
|
||||
{
|
||||
get => _model.ConnectionTimeoutSeconds;
|
||||
set
|
||||
{
|
||||
if (_model.ConnectionTimeoutSeconds != value)
|
||||
{
|
||||
_model.ConnectionTimeoutSeconds = value;
|
||||
OnPropertyChanged();
|
||||
_onChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether to use fake authentication.
|
||||
/// </summary>
|
||||
public bool UseFakeAuth
|
||||
{
|
||||
get => _model.UseFakeAuth;
|
||||
set
|
||||
{
|
||||
if (_model.UseFakeAuth != value)
|
||||
{
|
||||
_model.UseFakeAuth = value;
|
||||
OnPropertyChanged();
|
||||
_onChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the admin bypass users as newline-separated text.
|
||||
/// </summary>
|
||||
public string AdminBypassUsersText
|
||||
{
|
||||
get => string.Join("\n", _model.AdminBypassUsers);
|
||||
set
|
||||
{
|
||||
var users = value.Split('\n', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
|
||||
if (!_model.AdminBypassUsers.SequenceEqual(users))
|
||||
{
|
||||
_model.AdminBypassUsers = users;
|
||||
OnPropertyChanged();
|
||||
_onChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user