Skip to content

Commit 4e14f47

Browse files
committed
Feature: Profile filter
1 parent bc90eee commit 4e14f47

File tree

5 files changed

+35
-36
lines changed

5 files changed

+35
-36
lines changed

Source/NETworkManager.Profiles/ProfileFilterInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ public class ProfileFilterInfo
2020
/// <summary>
2121
/// Indicates whether to match any or all tags in the filter.
2222
/// </summary>
23-
public ProfileTagsFilterMatch TagsFilterMatch { get; set; } = ProfileTagsFilterMatch.Any;
23+
public ProfileFilterTagsMatch TagsFilterMatch { get; set; } = ProfileFilterTagsMatch.Any;
2424
}

Source/NETworkManager.Profiles/ProfileTagsFilterInfo.cs renamed to Source/NETworkManager.Profiles/ProfileFilterTagsInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace NETworkManager.Profiles;
55
/// <summary>
66
/// Class used to represent a tag filter in the UI (Popup).
77
/// </summary>
8-
public class ProfileTagsFilterInfo : PropertyChangedBase
8+
public class ProfileFilterTagsInfo : PropertyChangedBase
99
{
1010
/// <summary>
1111
/// Private field for <see cref="IsSelected"/>.
@@ -34,11 +34,11 @@ public bool IsSelected
3434
public string Name { get; set; }
3535

3636
/// <summary>
37-
/// Creates a new instance of <see cref="ProfileTagsFilterInfo"/> with parameters.
37+
/// Creates a new instance of <see cref="ProfileFilterTagsInfo"/> with parameters.
3838
/// </summary>
3939
/// <param name="isSelected">Indicates whether the tag is selected for filtering.</param>
4040
/// <param name="name">Tag name.</param>
41-
public ProfileTagsFilterInfo(bool isSelected, string name)
41+
public ProfileFilterTagsInfo(bool isSelected, string name)
4242
{
4343
IsSelected = isSelected;
4444
Name = name;

Source/NETworkManager.Profiles/ProfileTagsFilterMatch.cs renamed to Source/NETworkManager.Profiles/ProfileFilterTagsMatch.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/// <summary>
44
/// Enumeration for tag filtering options.
55
/// </summary>
6-
public enum ProfileTagsFilterMatch
6+
public enum ProfileFilterTagsMatch
77
{
88
/// <summary>
99
/// Any of the tags can match.

Source/NETworkManager/ViewModels/PingMonitorHostViewModel.cs

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -227,36 +227,36 @@ public bool ProfileFilterIsOpen
227227
}
228228
}
229229

230-
public ICollectionView ProfileTagsFilterView { get; set; }
230+
public ICollectionView ProfileFilterTagsView { get; set; }
231231

232-
public ObservableCollection<ProfileTagsFilterInfo> ProfileTagsFilter { get; set; } = [];
232+
public ObservableCollection<ProfileFilterTagsInfo> ProfileFilterTags { get; set; } = [];
233233

234-
private bool _profileTagsMatchAny = GlobalStaticConfiguration.Profile_TagsMatchAny;
234+
private bool _profileFilterTagsMatchAny = GlobalStaticConfiguration.Profile_TagsMatchAny;
235235

236-
public bool ProfileTagsMatchAny
236+
public bool ProfileFilterTagsMatchAny
237237
{
238-
get => _profileTagsMatchAny;
238+
get => _profileFilterTagsMatchAny;
239239
set
240240
{
241-
if (value == _profileTagsMatchAny)
241+
if (value == _profileFilterTagsMatchAny)
242242
return;
243243

244-
_profileTagsMatchAny = value;
244+
_profileFilterTagsMatchAny = value;
245245
OnPropertyChanged();
246246
}
247247
}
248248

249-
private bool _profileTagsMatchAll;
249+
private bool _profileFilterTagsMatchAll;
250250

251-
public bool ProfileTagsMatchAll
251+
public bool ProfileFilterTagsMatchAll
252252
{
253-
get => _profileTagsMatchAll;
253+
get => _profileFilterTagsMatchAll;
254254
set
255255
{
256-
if (value == _profileTagsMatchAll)
256+
if (value == _profileFilterTagsMatchAll)
257257
return;
258258

259-
_profileTagsMatchAll = value;
259+
_profileFilterTagsMatchAll = value;
260260
OnPropertyChanged();
261261
}
262262
}
@@ -323,7 +323,6 @@ public GridLength ProfileWidth
323323
OnPropertyChanged();
324324
}
325325
}
326-
327326
#endregion
328327

329328
#endregion
@@ -346,8 +345,8 @@ public PingMonitorHostViewModel(IDialogCoordinator instance)
346345
// Profiles
347346
CreateTags();
348347

349-
ProfileTagsFilterView = CollectionViewSource.GetDefaultView(ProfileTagsFilter);
350-
ProfileTagsFilterView.SortDescriptions.Add(new SortDescription(nameof(ProfileTagsFilterInfo.Name), ListSortDirection.Ascending));
348+
ProfileFilterTagsView = CollectionViewSource.GetDefaultView(ProfileFilterTags);
349+
ProfileFilterTagsView.SortDescriptions.Add(new SortDescription(nameof(ProfileFilterTagsInfo.Name), ListSortDirection.Ascending));
351350

352351
SetProfilesView(new ProfileFilterInfo());
353352

@@ -493,7 +492,7 @@ private void ApplyProfileFilterAction()
493492

494493
private void ClearProfileFilterAction()
495494
{
496-
foreach (var tag in ProfileTagsFilter)
495+
foreach (var tag in ProfileFilterTags)
497496
tag.IsSelected = false;
498497

499498
RefreshProfiles();
@@ -686,18 +685,18 @@ private void CreateTags()
686685

687686
var tagSet = new HashSet<string>(tags);
688687

689-
for (var i = ProfileTagsFilter.Count - 1; i >= 0; i--)
688+
for (var i = ProfileFilterTags.Count - 1; i >= 0; i--)
690689
{
691-
if (!tagSet.Contains(ProfileTagsFilter[i].Name))
692-
ProfileTagsFilter.RemoveAt(i);
690+
if (!tagSet.Contains(ProfileFilterTags[i].Name))
691+
ProfileFilterTags.RemoveAt(i);
693692
}
694693

695-
var existingTagNames = new HashSet<string>(ProfileTagsFilter.Select(ft => ft.Name));
694+
var existingTagNames = new HashSet<string>(ProfileFilterTags.Select(ft => ft.Name));
696695

697696
foreach (var tag in tags)
698697
{
699698
if (!existingTagNames.Contains(tag))
700-
ProfileTagsFilter.Add(new ProfileTagsFilterInfo(false, tag));
699+
ProfileFilterTags.Add(new ProfileFilterTagsInfo(false, tag));
701700
}
702701
}
703702

@@ -710,9 +709,9 @@ private void SetProfilesView(ProfileFilterInfo filter, ProfileInfo profile = nul
710709
// If no tags are selected, show all profiles
711710
(!filter.Tags.Any()) ||
712711
// Any tag can match
713-
(filter.TagsFilterMatch == ProfileTagsFilterMatch.Any && filter.Tags.Any(tag => x.TagsCollection.Contains(tag))) ||
712+
(filter.TagsFilterMatch == ProfileFilterTagsMatch.Any && filter.Tags.Any(tag => x.TagsCollection.Contains(tag))) ||
714713
// All tags must match
715-
(filter.TagsFilterMatch == ProfileTagsFilterMatch.All && filter.Tags.All(tag => x.TagsCollection.Contains(tag))))
714+
(filter.TagsFilterMatch == ProfileFilterTagsMatch.All && filter.Tags.All(tag => x.TagsCollection.Contains(tag))))
716715
).OrderBy(x => x.Group).ThenBy(x => x.Name)
717716
}.View;
718717

@@ -736,8 +735,8 @@ private void RefreshProfiles()
736735
SetProfilesView(new ProfileFilterInfo
737736
{
738737
Search = Search,
739-
Tags = [.. ProfileTagsFilter.Where(x => x.IsSelected).Select(x => x.Name)],
740-
TagsFilterMatch = ProfileTagsMatchAny ? ProfileTagsFilterMatch.Any : ProfileTagsFilterMatch.All
738+
Tags = [.. ProfileFilterTags.Where(x => x.IsSelected).Select(x => x.Name)],
739+
TagsFilterMatch = ProfileFilterTagsMatchAny ? ProfileFilterTagsMatch.Any : ProfileFilterTagsMatch.All
741740
}, SelectedProfile);
742741
}
743742
#endregion

Source/NETworkManager/Views/PingMonitorHostView.xaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -404,16 +404,16 @@
404404
Style="{StaticResource InfoTextBlock}"/>
405405
<ScrollViewer Grid.Column="0" Grid.Row="2"
406406
VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Hidden"
407-
Visibility="{Binding Path=ProfileTagsFilterView.Count, Converter={StaticResource IntNotZeroToVisibilityCollapsedConverter}}">
408-
<ItemsControl ItemsSource="{Binding ProfileTagsFilterView}"
407+
Visibility="{Binding Path=ProfileFilterTagsView.Count, Converter={StaticResource IntNotZeroToVisibilityCollapsedConverter}}">
408+
<ItemsControl ItemsSource="{Binding ProfileFilterTagsView}"
409409
Width="200">
410410
<ItemsControl.ItemsPanel>
411411
<ItemsPanelTemplate>
412412
<WrapPanel />
413413
</ItemsPanelTemplate>
414414
</ItemsControl.ItemsPanel>
415415
<ItemsControl.ItemTemplate>
416-
<DataTemplate DataType="{x:Type profiles:ProfileTagsFilterInfo}">
416+
<DataTemplate DataType="{x:Type profiles:ProfileFilterTagsInfo}">
417417
<CheckBox Margin="0,5,10,5" Content="{Binding Name}"
418418
IsChecked="{Binding IsSelected}"
419419
Style="{StaticResource DefaultCheckBox}" />
@@ -423,7 +423,7 @@
423423
</ScrollViewer>
424424
<TextBlock Grid.Column="0" Grid.Row="2"
425425
Text="{x:Static localization:Strings.NoTagsFound}"
426-
Visibility="{Binding Path=ProfileTagsFilterView.Count, Converter={StaticResource IntZeroToVisibilityCollapsedConverter}}"
426+
Visibility="{Binding Path=ProfileFilterTagsView.Count, Converter={StaticResource IntZeroToVisibilityCollapsedConverter}}"
427427
Style="{StaticResource MessageTextBlock}" />
428428
<TextBlock Grid.Column="0" Grid.Row="4"
429429
Text="{x:Static localization:Strings.Match}"
@@ -432,9 +432,9 @@
432432
<StackPanel Grid.Column="0" Grid.Row="6"
433433
Orientation="Horizontal">
434434
<RadioButton Content="{x:Static localization:Strings.Any}"
435-
IsChecked="{Binding Path=ProfileTagsMatchAny}" />
435+
IsChecked="{Binding Path=ProfileFilterTagsMatchAny}" />
436436
<RadioButton Content="{x:Static localization:Strings.All}"
437-
IsChecked="{Binding Path=ProfileTagsMatchAll}"
437+
IsChecked="{Binding Path=ProfileFilterTagsMatchAll}"
438438
Margin="10,0,0,0"/>
439439
</StackPanel>
440440
<StackPanel Grid.Column="0" Grid.Row="8"

0 commit comments

Comments
 (0)