diff --git a/src/Nexus.UI/Components/ResourceView.razor b/src/Nexus.UI/Components/ResourceView.razor index 9e50d296..af48d581 100644 --- a/src/Nexus.UI/Components/ResourceView.razor +++ b/src/Nexus.UI/Components/ResourceView.razor @@ -2,11 +2,10 @@ @inject AppState AppState
-
@if (AppState.CatalogItemsMap is not null) { - @foreach (var entry in AppState.CatalogItemsMap) + @foreach (var entry in AppState.CatalogItemsMap) //String = GruppenName, Val = Gruppe selbst { - @if (entry.Value == AppState.CatalogItemsGroup) + @if (entry.Value == AppState.CatalogItemsGroup) //AppState.CatalogItemsGroup aktuelle gewählte gruppe {
@entry.Key @@ -42,95 +41,31 @@
- @if (AppState.CatalogItemsGroup is not null) - { - @if (AppState.EditModeCatalogMap.ContainsKey(AppState.SelectedCatalog!.Id)) - { - -
- - @foreach (var catalogItem in catalogItemPair) - { -
- -
- - @catalogItem.Resource.Id - - - - - - - - @Utilities.ToUnitString(catalogItem.Representation.SamplePeriod) - -
- -
- -
- -
- } -
-
- } - else - { - -
- - @foreach (var catalogItem in catalogItemPair) - { -
- -
- - @catalogItem.Resource.Id - - @catalogItem.Unit - @if (catalogItem.Warning is not null) - { - - - - } - - @Utilities.ToUnitString(catalogItem.Representation.SamplePeriod) - -
- -
- - @if (string.IsNullOrWhiteSpace(@catalogItem.Description)) - { -   - } - else - { - @catalogItem.Description - } - -
- -
- } -
-
- } - } + + + + + + + + + + + +
-
@@ -164,10 +99,10 @@ { - @@ -178,7 +113,7 @@ argument.TryGetStringValue("default", out var defaultValue2)) { - - @@ -209,8 +144,6 @@ } @code { - - private Virtualize>? _virtualizeComponent; private PropertyChangedEventHandler _handler; private string _searchIcon = Icons.Material.Filled.Search; private bool _isPropertiesViewDialogOpen; @@ -224,26 +157,13 @@ public ResourceView() { - _handler = async (sender, e) => + _handler = async (sender, e) => { - if (e.PropertyName == nameof(AppState.CatalogItemsMap)) - { - if (_virtualizeComponent is not null) - { - await _virtualizeComponent.RefreshDataAsync(); - StateHasChanged(); - } - } - - else if (e.PropertyName == nameof(AppState.SearchString)) + if (e.PropertyName == nameof(AppState.SearchString)) { _searchIcon = string.IsNullOrWhiteSpace(AppState.SearchString) ? Icons.Material.Filled.Search - : Icons.Material.Filled.Close; - - if (_virtualizeComponent is not null) - await _virtualizeComponent.RefreshDataAsync(); - } + : Icons.Material.Filled.Close; } else if (e.PropertyName == nameof(AppState.Settings.SelectedCatalogItems)) { @@ -257,54 +177,10 @@ }; } - private async Task SelectCatalogItemsGroupAsync(List catalogItems) - { - AppState.CatalogItemsGroup = catalogItems; - - if (_virtualizeComponent is not null) - await _virtualizeComponent.RefreshDataAsync(); - } - - private ValueTask>> LoadItems(ItemsProviderRequest request) - { - var catalogItemsGroup = AppState.CatalogItemsGroup; - - if (catalogItemsGroup is null) - return ValueTask.FromResult(new ItemsProviderResult>(Enumerable.Empty>(), 0)); - - var groupSize = 4; - var total = (int)Math.Ceiling(catalogItemsGroup.Count / (double)groupSize); - - var source = catalogItemsGroup - .Skip(request.StartIndex * groupSize) - .Take(request.Count * groupSize); - - var index = 0; - - var groups = source - .GroupBy(item => - { - var result = index / groupSize; - index++; - return result; - }) - .Select(group => group.ToList()) - .ToList(); - - return ValueTask.FromResult(new ItemsProviderResult>(groups, total)); - } - - private void OpenPropertiesModal() - { - _isPropertiesViewDialogOpen = true; - } - - private void OpenContextMenu(MouseEventArgs args, CatalogItemViewModel catalogItem) + public void Dispose() { - _contextMenuLeft = args.PageX; - _contextMenuTop = args.PageY; - _contextMenuCatalogItem = catalogItem; - _isContextMenuOpen = true; + AppState.PropertyChanged -= _handler; + AppState.Settings.PropertyChanged -= _handler; } protected override void OnInitialized() @@ -313,28 +189,24 @@ AppState.Settings.PropertyChanged += _handler; } - private void SetMetadataOverridesValue(ChangeEventArgs e, string resourceId, string propertyKey) + + private async Task SelectCatalogItemsGroupAsync(List catalogItems) { - if (AppState.EditModeCatalogMap.TryGetValue(AppState.SelectedCatalog!.Id, out var map)) - { - var key = new EditModeItem(resourceId, propertyKey); - var value = e.Value?.ToString(); + AppState.CatalogItemsGroup = catalogItems; + } - map[key] = value; - } + private void OpenPropertiesModal() + { + _isPropertiesViewDialogOpen = true; } - private string? GetMetadataOverridesValue(string resourceId, string propertyKey) + private void SetNewMetaDataValue(string resourceId, string newValue, string propertyKey) { if (AppState.EditModeCatalogMap.TryGetValue(AppState.SelectedCatalog!.Id, out var map)) { var key = new EditModeItem(resourceId, propertyKey); - - if (map.TryGetValue(key, out var value)) - return value; + map[key] = newValue; } - - return default; } private void SelectParameterizedCatalogItem() @@ -359,9 +231,76 @@ } } - public void Dispose() + private void CommittedItemChanges(CatalogItemViewModel item) { - AppState.PropertyChanged -= _handler; - AppState.Settings.PropertyChanged -= _handler; + var id = item.Resource.Id; + if(item.DescriptionHasChanged) + { + SetNewMetaDataValue(id, item.Description, CatalogItemViewModel.DESCRIPTION_KEY); + } + else if(item.UnitHasChanged) + { + SetNewMetaDataValue(id, item.Unit, CatalogItemViewModel.UNIT_KEY); + } + else if(item.WarningHasChanged) + { + SetNewMetaDataValue(id, item.Warning, CatalogItemViewModel.WARNING_KEY); + } + item.ResetHasChangedState(); + } + + // quick filter - filter globally across multiple columns with the same input + private Func QuickFilter => x => + { + var searchString = AppState.SearchString != null ? AppState.SearchString : ""; + + if (string.IsNullOrWhiteSpace(searchString)) + return true; + + if (x.Resource.Id.Contains(searchString, StringComparison.OrdinalIgnoreCase)) + return true; + + if (Utilities.ToUnitString(x.Representation.SamplePeriod).Contains(searchString, StringComparison.OrdinalIgnoreCase)) + return true; + + var description = x.Description != null ? x.Description : ""; + if (description.Contains(searchString, StringComparison.OrdinalIgnoreCase)) + return true; + + var unit = x.Unit != null ? x.Unit : ""; + if (unit.Contains(searchString, StringComparison.OrdinalIgnoreCase)) + return true; + + var warning = x.Warning != null ? x.Warning : ""; + if (warning.Contains(searchString, StringComparison.OrdinalIgnoreCase)) + return true; + + return false; + }; + + private void RowClicked(DataGridRowClickEventArgs args) + { + if(!AppState.EditModeCatalogMap.ContainsKey(AppState.SelectedCatalog!.Id)) + { + ToggleCatalogItemSelection(args.Item); + } + } + + private void OpenGridContextMenu(DataGridRowClickEventArgs args) + { + _contextMenuLeft = args.MouseEventArgs.PageX; + _contextMenuTop = args.MouseEventArgs.PageY; + _contextMenuCatalogItem = args.Item; + _isContextMenuOpen = true; } + + + // style the rows where the Element.Position == 0 to have italic text. + private Func RowStyleFunc => (x, i) => + { + if (AppState.Settings.IsSelected(x)) + return "background-color:#EACE5D"; + + return ""; + }; } \ No newline at end of file diff --git a/src/Nexus.UI/ViewModels/CatalogItemViewModel.cs b/src/Nexus.UI/ViewModels/CatalogItemViewModel.cs index 2be4e5a0..64b66422 100644 --- a/src/Nexus.UI/ViewModels/CatalogItemViewModel.cs +++ b/src/Nexus.UI/ViewModels/CatalogItemViewModel.cs @@ -10,11 +10,21 @@ namespace Nexus.UI.ViewModels; public class CatalogItemViewModel { public const string README_KEY = "readme"; + public const string LICENSE_KEY = "license"; + public const string DESCRIPTION_KEY = "description"; + public const string WARNING_KEY = "warning"; + public const string UNIT_KEY = "unit"; + private string? _description; + + private string? _warning; + + private string? _unit; + public CatalogItemViewModel(ResourceCatalog resourceCatalog, Resource resource, Representation representation) { Catalog = resourceCatalog; @@ -23,9 +33,9 @@ public CatalogItemViewModel(ResourceCatalog resourceCatalog, Resource resource, if (resource.Properties is not null) { - Description = resource.Properties.GetStringValue(DESCRIPTION_KEY); - Warning = resource.Properties.GetStringValue(WARNING_KEY); - Unit = resource.Properties.GetStringValue(UNIT_KEY); + _description = Resource.Properties.GetStringValue(DESCRIPTION_KEY); + _warning = Resource.Properties.GetStringValue(WARNING_KEY); + _unit = Resource.Properties.GetStringValue(UNIT_KEY); } } @@ -35,7 +45,64 @@ public CatalogItemViewModel(ResourceCatalog resourceCatalog, Resource resource, public Representation Representation { get; } - public string? Description; - public string? Warning; - public string? Unit; + public string? Description + { + get + { + return _description; + } + set + { + if (value != _description) + { + _description = value; + DescriptionHasChanged = true; + } + } + } + + public string? Warning + { + get + { + return _warning; + } + set + { + if (value != _warning) + { + _warning = value; + WarningHasChanged = true; + } + } + } + + public string? Unit + { + get + { + return _unit; + } + set + { + if (value != _unit) + { + _unit = value; + UnitHasChanged = true; + } + } + } + + public bool DescriptionHasChanged { get; private set; } + + public bool WarningHasChanged { get; private set; } + + public bool UnitHasChanged { get; private set; } + + public void ResetHasChangedState() + { + DescriptionHasChanged = false; + WarningHasChanged = false; + UnitHasChanged = false; + } } \ No newline at end of file