Skip to content
Snippets Groups Projects
Commit b8efcd8b authored by Philipp Müller's avatar Philipp Müller
Browse files

delete button added. fix navigation bar

parent f75a2feb
No related branches found
No related tags found
1 merge request!63Delete option, Navbar fix
......@@ -72,7 +72,27 @@ namespace InnoLabProjektDektopApp
checkBox.Checked += CheckBox_CheckedChanged;
checkBox.Unchecked += CheckBox_CheckedChanged;
var deleteButtonBorder = new Border
{
Style = (Style)Application.Current.Resources["RoundedButtonBorder"],
Child = new TextBlock
{
Text = "Delete",
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
Foreground = (Brush)Application.Current.Resources["BACKGROUND_PRIMARY_BRUSH"],
FontWeight = FontWeights.Bold
},
Margin = new Thickness(5, 0, 10, 0),
Cursor = Cursors.Hand,
Width = 50,
Height = 30,
CornerRadius = new CornerRadius(10)
};
deleteButtonBorder.MouseDown += (s, e) => DeleteItemInList(item);
stackPanel.Children.Add(checkBox);
stackPanel.Children.Add(deleteButtonBorder);
// Add the filtered StackPanel to ItemsPanel
ItemsPanel.Children.Add(stackPanel);
......@@ -174,7 +194,27 @@ namespace InnoLabProjektDektopApp
checkBox.Checked += CheckBox_CheckedChanged;
checkBox.Unchecked += CheckBox_CheckedChanged;
var deleteButtonBorder = new Border
{
Style = (Style)Application.Current.Resources["RoundedButtonBorder"],
Child = new TextBlock
{
Text = "Delete",
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
Foreground = (Brush)Application.Current.Resources["BACKGROUND_PRIMARY_BRUSH"],
FontWeight = FontWeights.Bold
},
Margin = new Thickness(5, 0, 10, 0),
Cursor = Cursors.Hand,
Width = 50,
Height = 30,
CornerRadius = new CornerRadius(10)
};
deleteButtonBorder.MouseDown += (s, e) => DeleteItemInList(item);
stackPanel.Children.Add(checkBox);
stackPanel.Children.Add(deleteButtonBorder);
// Elemente zur Liste hinzufügen
ItemsPanel.Children.Add(stackPanel);
......@@ -206,6 +246,23 @@ namespace InnoLabProjektDektopApp
}
}
private void DeleteItemInList(WebsiteEntry websiteEntry)
{
if (MessageBox.Show($"Are you sure you want to delete '{websiteEntry.Url}'?", "Delete Item", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
{
// Remove the item from the list
_data[_category].Remove(websiteEntry);
// Save changes to the JSON
SaveData();
// Remove the item from the UI
var itemStackPanel = ItemsPanel.Children.OfType<StackPanel>().FirstOrDefault(sp => sp.Children.OfType<CheckBox>().Any(cb => cb.Tag == websiteEntry));
if (itemStackPanel != null)
{
ItemsPanel.Children.Remove(itemStackPanel);
}
}
}
private void SaveData()
{
try
......
......@@ -196,13 +196,13 @@ namespace InnoLabProjektDektopApp
// Add to UI dynamically
var newGrid = new Grid { Margin = new Thickness(5, 2, 5, 2) };
// Zwei Spalten: 1. für CheckBox + Text, 2. für den Button
// Three columns: 1. for CheckBox + Text, 2. for the Edit Button, 3. for the Delete Button
newGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
newGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
newGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
var newCheckBox = new CheckBox
{
Margin = new Thickness(5),
IsChecked = isDistracting,
ToolTip = $"{mainWindowTitle} ({processName})",
......@@ -216,7 +216,6 @@ namespace InnoLabProjektDektopApp
};
newCheckBox.Content = textBlock;
newCheckBox.Checked += CheckBox_CheckedChanged;
newCheckBox.Unchecked += CheckBox_CheckedChanged;
......@@ -239,14 +238,35 @@ namespace InnoLabProjektDektopApp
};
editButtonBorder.MouseDown += (s, e) => EditItemInList(processName, mainWindowTitle);
// Elemente ins Grid setzen
var deleteButtonBorder = new Border
{
Style = (Style)Application.Current.Resources["RoundedButtonBorder"],
Child = new TextBlock
{
Text = "Delete",
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
Foreground = (Brush)Application.Current.Resources["BACKGROUND_PRIMARY_BRUSH"],
FontWeight = FontWeights.Bold
},
Margin = new Thickness(5, 0, 10, 0),
Cursor = Cursors.Hand,
Width = 50,
Height = 30,
CornerRadius = new CornerRadius(10)
};
deleteButtonBorder.MouseDown += (s, e) => DeleteItemInList(processName);
// Set elements in the Grid
Grid.SetColumn(newCheckBox, 0);
Grid.SetColumn(editButtonBorder, 1);
Grid.SetColumn(deleteButtonBorder, 2);
newGrid.Children.Add(newCheckBox);
newGrid.Children.Add(editButtonBorder);
newGrid.Children.Add(deleteButtonBorder);
// Element zum UI-Stack hinzufügen
// Add element to the UI stack
ItemsPanel.Children.Add(newGrid);
}
......@@ -262,6 +282,13 @@ namespace InnoLabProjektDektopApp
RefreshProgramList();
}
private void DeleteItemInList(string processName)
{
_data["Programs"].RemoveAll(p => p.ProcessName.Equals(processName, StringComparison.CurrentCultureIgnoreCase));
SaveData();
RefreshProgramList();
}
public void RefreshProgramList()
{
ItemsPanel.Children.Clear();
......
......@@ -6,6 +6,7 @@
xmlns:local="clr-namespace:InnoLabProjektDektopApp"
xmlns:header="clr-namespace:InnoLabProjektDektopApp.Screens.Templates"
mc:Ignorable="d"
ShowsNavigationUI="True"
Background="{StaticResource BACKGROUND_PRIMARY_BRUSH}">
<ScrollViewer>
<Grid VerticalAlignment="Center">
......
......@@ -7,6 +7,7 @@
xmlns:header="clr-namespace:InnoLabProjektDektopApp.Screens.Templates"
mc:Ignorable="d"
Unloaded="Page_Unloaded"
ShowsNavigationUI="False"
Background="{StaticResource BACKGROUND_PRIMARY_BRUSH}">
<Grid>
......
......@@ -6,6 +6,6 @@
xmlns:local="clr-namespace:InnoLabProjektDektopApp"
xmlns:header="clr-namespace:InnoLabProjektDektopApp.Screens.Templates"
mc:Ignorable="d"
Height="550" Width="900" ShowsNavigationUI="False">
Height="550" Width="900">
</NavigationWindow>
......@@ -18,19 +18,8 @@ namespace InnoLabProjektDektopApp
/// </summary>
public partial class End : NavigationWindow
{
public End(String sessionInfoJsonPath)
public End()
{
// read the session info json file
string sessionInfoJson = File.ReadAllText(sessionInfoJsonPath);
dynamic sessionInfo = JsonNode.Parse(sessionInfoJson);
DateTime sessionEndTime = sessionInfo["SessionEndTime"].GetValue<DateTime>();
var cycleStartTimes = sessionInfo["cycleStartTimes"];
int finalDistractionStage = sessionInfo["finalDistractionStage"].GetValue<int>();
var processInfoList = sessionInfo["ProcessInfoList"].AsArray();
var breakInfoList = sessionInfo["BreakInfoList"].AsArray();
InitializeComponent();
GlobalSettings.setDefaults(this);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment