Skip to content

Commit

Permalink
Added GUI element for display currently displayed items count
Browse files Browse the repository at this point in the history
Added GUI element for display currently displayed items count
  • Loading branch information
HotCakeX committed Aug 28, 2024
1 parent 636ad83 commit 23eddc3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
30 changes: 24 additions & 6 deletions Harden-Windows-Security Module/Main files/C#/GUI/Confirm/View.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ private void Confirm(object obj)
// Find the SecOpsDataGrid
HardenWindowsSecurity.GUIConfirmSystemCompliance.SecOpsDataGrid = (System.Windows.Controls.DataGrid)confirmView.FindName("SecOpsDataGrid");

System.Windows.Controls.TextBlock TotalCurrentlyDisplayedSecOpsTextBlock = (System.Windows.Controls.TextBlock)confirmView.FindName("TotalCurrentlyDisplayedSecOps");

#region ToggleButtons
System.Windows.Controls.Primitives.ToggleButton CompliantItemsToggleButton = (System.Windows.Controls.Primitives.ToggleButton)confirmView.FindName("CompliantItemsToggleButton");
System.Windows.Controls.Primitives.ToggleButton NonCompliantItemsToggleButton = (System.Windows.Controls.Primitives.ToggleButton)confirmView.FindName("NonCompliantItemsToggleButton");
Expand All @@ -79,6 +81,15 @@ private void Confirm(object obj)
NonCompliantItemsToggleButton.IsChecked = true;
#endregion

// Method to update the text block showing the total count of currently displayed items in the GUI
void UpdateCurrentVisibleItemsTextBlock()
{
// Get the count of all of the current items in the CollectionView
string totalDisplayedItemsCount = _SecOpsCollectionView.Cast<SecOp>().Count().ToString(CultureInfo.InvariantCulture);
// Display the count in a text box in the GUI
TotalCurrentlyDisplayedSecOpsTextBlock.Text = $"Showing {totalDisplayedItemsCount} Items";
}

// A Method to apply filters on the DataGrid based on the filter text and toggle buttons
void ApplyFilters(string filterText, bool includeCompliant, bool includeNonCompliant)
{
Expand Down Expand Up @@ -109,6 +120,8 @@ void ApplyFilters(string filterText, bool includeCompliant, bool includeNonCompl
};

_SecOpsCollectionView.Refresh(); // Refresh the collection view to apply the filter

UpdateCurrentVisibleItemsTextBlock();
}
}

Expand Down Expand Up @@ -184,6 +197,10 @@ void ApplyFilters(string filterText, bool includeCompliant, bool includeNonCompl
// mark as activity started
HardenWindowsSecurity.ActivityTracker.IsActive = true;
// Clear the current security options before starting data generation
__SecOpses.Clear();
_SecOpsCollectionView.Refresh(); // Refresh the collection view to clear the DataGrid
// Disable the Refresh button while processing
// Set text blocks to empty while new data is being generated
System.Windows.Application.Current.Dispatcher.Invoke(() =>
Expand All @@ -204,12 +221,9 @@ void ApplyFilters(string filterText, bool includeCompliant, bool includeNonCompl
TotalCountTextBlock.Text = "Loading...";
}
UpdateCurrentVisibleItemsTextBlock();
});
// Clear the current security options before starting data generation
__SecOpses.Clear();
_SecOpsCollectionView.Refresh(); // Refresh the collection view to clear the DataGrid
// Run the method asynchronously in a different thread
await System.Threading.Tasks.Task.Run(() =>
{
Expand All @@ -225,6 +239,8 @@ await System.Windows.Application.Current.Dispatcher.InvokeAsync(() =>
{
LoadMembers(); // Load updated security options
RefreshButton.IsChecked = false; // Uncheck the Refresh button
UpdateCurrentVisibleItemsTextBlock();
});
// mark as activity completed
Expand Down Expand Up @@ -304,8 +320,10 @@ private System.Windows.Media.Brush GetCategoryColor(string category)
/// <param name="ShowNotification">If set to true, this method will display end of confirmation toast notification</param>
private void UpdateTotalCount(bool ShowNotification)
{
// Get the total count of security options
int totalCount = _SecOpsCollectionView.Cast<SecOp>().Count();

// calculates the total number of all security options across all lists, so all the items in each category that exist in the values of the main dictionary object
int totalCount = HardenWindowsSecurity.GlobalVars.FinalMegaObject?.Values.Sum(list => list.Count) ?? 0;

if (CurrentView is System.Windows.Controls.UserControl confirmView)
{
// Find the TextBlock used to display the total count
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,10 @@
<TextBox Name="textBoxFilter" Style="{StaticResource filterTextBox}" />
</Grid>

<!--Toggle buttons and textblocks rows-->
<StackPanel Orientation="Horizontal" Grid.Row="2" Margin="0,0,0,20">

<StackPanel Orientation="Horizontal" Margin="0,0,50,0">
<StackPanel Orientation="Horizontal" Margin="0,0,40,0">

<TextBlock x:Name="CompliantItemsTextBlock" Text="Compliant Items"
FontSize="15" FontWeight="SemiBold" Foreground="#121518"
Expand All @@ -333,7 +334,7 @@
</StackPanel>


<StackPanel Orientation="Horizontal">
<StackPanel Orientation="Horizontal" Margin="0,0,30,0">

<!-- Add some margin to the right -->
<TextBlock x:Name="NonCompliantItemsTextBlock" Text="Non-Compliant Items"
Expand All @@ -347,6 +348,10 @@

</StackPanel>


<TextBlock x:Name="TotalCurrentlyDisplayedSecOps" FontSize="15" FontWeight="SemiBold" Foreground="#121518"
HorizontalAlignment="Right" VerticalAlignment="Center"/>

</StackPanel>

<!--SecOps Data Grid-->
Expand Down

0 comments on commit 23eddc3

Please sign in to comment.