Skip to content
Snippets Groups Projects
Commit 2705f8c5 authored by Jessica Paul's avatar Jessica Paul
Browse files

added the basic functionality of profiles (projects)

parent e22f4871
No related branches found
No related tags found
1 merge request!71added the basic functionality of profiles (projects)
This commit is part of merge request !71. Comments created here will be created in the context of that merge request.
......@@ -1502,4 +1502,8 @@
<Resource Include="Styles\Styles.xaml" />
</ItemGroup>
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="echo {} &gt; &quot;$(TargetDir)settings.json&quot;" />
</Target>
</Project>
......@@ -9,12 +9,66 @@
Background="{StaticResource BACKGROUND_PRIMARY_BRUSH}">
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled">
<Grid VerticalAlignment="Center">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="105*"/>
<ColumnDefinition Width="475*"/>
<ColumnDefinition Width="132*"/>
</Grid.ColumnDefinitions>
<StackPanel Margin="20,20,20,3" Grid.ColumnSpan="3" Grid.Row="0">
<StackPanel Margin="20,20,20,20">
<!--Project Area-->
<TextBlock Style="{StaticResource Header1}"
Text="Your project with saved settings"
HorizontalAlignment="Left" />
<!--Box 1-->
<Border Background="{StaticResource BACKGROUND_SECONDARY_BRUSH}" CornerRadius="10" Padding="15" Margin="0,10,0,0">
<!-- Project Pic and Name -->
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" Margin="10" HorizontalAlignment="Left">
<StackPanel Orientation="Vertical" Margin="10,0,0,0" VerticalAlignment="Center" HorizontalAlignment="Left">
<Border Width="80" Height="80" Background="LightBlue" CornerRadius="40">
<Image Source="pack://application:,,,/Assets/profileicon.png" Stretch="Uniform" Margin="10"/>
</Border>
</StackPanel>
<StackPanel Orientation="Vertical" Margin="10,0,0,0" VerticalAlignment="Center" HorizontalAlignment="Left">
<TextBox x:Name="ProjectNameTextBox" Text="Project Name" Margin="10,0,0,0" BorderThickness="0" Background="Transparent" FontWeight="Bold" Foreground="White" FontSize="14" CaretBrush="White"/>
<Border Height="1" Width="300" Background="White" Margin="10,2,0,0"/>
</StackPanel>
</StackPanel>
</StackPanel>
</Border>
<!--Box 2-->
<Border Background="{StaticResource BACKGROUND_SECONDARY_BRUSH}" CornerRadius="10" Padding="15" Margin="0,10,0,20">
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" Margin="10" HorizontalAlignment="Left">
<StackPanel Orientation="Vertical" Margin="10,0,0,0" VerticalAlignment="Center" HorizontalAlignment="Left">
<TextBlock Text="To the distractions saved in your profile" VerticalAlignment="Center" Grid.Column="0" FontSize="14" FontWeight="SemiBold"/>
</StackPanel>
<StackPanel Orientation="Vertical" Margin="10,0,0,0" VerticalAlignment="Center" HorizontalAlignment="Left">
<Button Content="➡" Width="30" Height="30" Background="Transparent" BorderThickness="0"/>
</StackPanel>
</StackPanel>
</StackPanel>
</Border>
<!--Settings Area-->
<TextBlock Style="{StaticResource Header2}"
Text="Change the settings as you want"
FontWeight="Bold"
HorizontalAlignment="Left" />
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" Margin="0,10,0,0">
......@@ -299,7 +353,7 @@ Width="70" MouseDown="TogglePopup4">
<!-- Pagination -->
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,478,0,0" VerticalAlignment="Top">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="-186,0,0,10" VerticalAlignment="Top" Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="1">
<Border Style="{StaticResource RoundedButtonBorder}" MouseDown="PreviousPage_Click" Width="100" Margin="10">
<TextBlock Text="Previous" Style="{StaticResource ButtonTextStyle}" />
</Border>
......@@ -321,7 +375,7 @@ Width="70" MouseDown="TogglePopup4">
-->
<Border Style="{StaticResource RoundedButtonBorder}" MouseDown="NextPage_Click" Width="100" Margin="10">
<TextBlock Text="Next" Style="{StaticResource ButtonTextStyle}" />
<TextBlock Text="Save" Style="{StaticResource ButtonTextStyle}" />
</Border>
</StackPanel>
......
......
......@@ -56,65 +56,80 @@ namespace InnoLabProjektDektopApp
}
// --------------------------------------------------------------
private void SaveSettings()
private void SaveSettings(string? projectName = null)
{
// Sammle die Werte aus den ComboBoxen oder verwende Standardwerte
string focusPeriod = string.IsNullOrWhiteSpace(SelectedText2.Text) ? "45" : SelectedText2.Text;
string breakPeriod = string.IsNullOrWhiteSpace(SelectedText3.Text) ? "45" : SelectedText3.Text;
string cycles = string.IsNullOrWhiteSpace(SelectedText4.Text) ? "4" : SelectedText4.Text;
string distractionMode = DistractionModeFullBlocking.IsChecked == true
? "Full-blocking mode"
: DistractionModeMascotFeedback.IsChecked == true
? "Mascot feedback only"
: "seconds warning mode";
string warningSeconds = !string.IsNullOrWhiteSpace(SelectedText.Text)
? SelectedText.Text
: "10";
string mascotVisible = MascotVisibleYes.IsChecked == true ? "Yes" : "No";
string filePath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "settings.json");
Dictionary<string, Dictionary<string, string>> settings;
bool wordsOfAffirmation = WordsOfAffirmationCheckBox.IsChecked ?? false;
bool insultingWords = InsultingWordsCheckBox.IsChecked ?? false;
// load existig json file or create new one
if (File.Exists(filePath))
{
string jsonContent = File.ReadAllText(filePath);
settings = JsonSerializer.Deserialize<Dictionary<string, Dictionary<string, string>>>(jsonContent) ?? new();
}
else
{
settings = new();
}
// JSON-Datei erstellen
var settings = new Dictionary<string, Dictionary<string, string>>
// if no project name from overview, then new project
if (string.IsNullOrWhiteSpace(projectName))
{
for (int i = 1; i <= 8; i++)
{
"profile1",
new Dictionary<string, string>
string newProjectKey = $"project{i}";
if (!settings.ContainsKey(newProjectKey))
{
{ "focusPeriod", focusPeriod },
{ "breakPeriod", breakPeriod },
{ "cycles", cycles },
{ "distractionMode", distractionMode },
{ "warningSeconds", warningSeconds },
{ "mascotVisibility", mascotVisible },
{ "wordsOfAffirmation", wordsOfAffirmation.ToString() },
{ "insultingWords", insultingWords.ToString() }
projectName = newProjectKey;
break;
}
}
}
// if user tries to add one project more then one can
if (string.IsNullOrWhiteSpace(projectName))
{
MessageBox.Show("You have reached the maximum number of 8 projects. Please delete an existing project before adding a new one.", "Limit Reached", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
// get values of settings oder default values
var projectSettings = new Dictionary<string, string>
{
{ "displayName", string.IsNullOrWhiteSpace(ProjectNameTextBox.Text) ? projectName : ProjectNameTextBox.Text },
{ "focusPeriod", string.IsNullOrWhiteSpace(SelectedText2.Text) ? "45" : SelectedText2.Text },
{ "breakPeriod", string.IsNullOrWhiteSpace(SelectedText3.Text) ? "10" : SelectedText3.Text },
{ "cycles", string.IsNullOrWhiteSpace(SelectedText4.Text) ? "4" : SelectedText4.Text },
{ "distractionMode", DistractionModeFullBlocking.IsChecked == true ? "Full-blocking mode" :
DistractionModeMascotFeedback.IsChecked == true ? "Mascot feedback only" : "seconds warning mode" },
{ "warningSeconds", string.IsNullOrWhiteSpace(SelectedText.Text) ? "10" : SelectedText.Text },
{ "mascotVisibility", MascotVisibleYes.IsChecked == true ? "Yes" : "No" },
{ "wordsOfAffirmation", (WordsOfAffirmationCheckBox.IsChecked ?? false).ToString() },
{ "insultingWords", (InsultingWordsCheckBox.IsChecked ?? false).ToString() }
};
string filePath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "settings.json");
// save project or overwrite
settings[projectName] = projectSettings;
// JSON speichern
// save json
File.WriteAllText(filePath, JsonSerializer.Serialize(settings, new JsonSerializerOptions { WriteIndented = true }));
// Nach dem Speichern: JSON lesen und in der MessageBox anzeigen
if (File.Exists(filePath))
MessageBox.Show($"Settings saved for {projectName}.", "Success.", MessageBoxButton.OK, MessageBoxImage.Information);
// show massageBox
/*if (File.Exists(filePath))
{
string jsonContent = File.ReadAllText(filePath);
var savedSettings = JsonSerializer.Deserialize<Dictionary<string, Dictionary<string, string>>>(jsonContent);
if (savedSettings != null && savedSettings.ContainsKey("profile1"))
if (savedSettings != null && savedSettings.ContainsKey("project1"))
{
var profileSettings = savedSettings["profile1"];
var profileSettings = savedSettings["project1"];
string message = "Saved Settings for profile1:\n";
string message = "Saved Settings for this profile:\n";
message += $"Filepath: {filePath}\n";
foreach (var setting in profileSettings)
{
message += $"{setting.Key}: {setting.Value}\n";
......@@ -122,8 +137,10 @@ namespace InnoLabProjektDektopApp
MessageBox.Show(message, "Saved Settings", MessageBoxButton.OK, MessageBoxImage.Information);
}
}*/
}
}
// --------------------------------------------------------------
private void PreviousPage_Click(object sender, RoutedEventArgs e)
{
......
......
......@@ -10,18 +10,13 @@
Background="{StaticResource BACKGROUND_PRIMARY_BRUSH}">
<ScrollViewer>
<Grid VerticalAlignment="Center">
<StackPanel Margin="20,0,20,20">
<!-- Überschrift -->
<TextBlock Style="{StaticResource Header1}"
Text="Selection and editing of your saved profiles"
Text="Selection and editing of your saved projects"
HorizontalAlignment="Left"
Margin="50,10,0,10" />
Margin="40,10,0,10" />
......@@ -29,43 +24,46 @@
<Border Background="{StaticResource BACKGROUND_SECONDARY_BRUSH}" CornerRadius="10" Padding="15">
<StackPanel Orientation="Vertical">
<TextBlock Style="{StaticResource Header2}"
Text="Want to customize this profile?"
Text="Your chosen project - click to edit"
HorizontalAlignment="Left" />
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" Background="#333333" Margin="10" HorizontalAlignment="Left">
<!-- Profil 1 -->
<StackPanel Orientation="Vertical" Margin="10,0,0,0" VerticalAlignment="Center">
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled">
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" Margin="10" HorizontalAlignment="Left">
<!-- Dynamische Anzeige der Projekte -->
<ItemsControl x:Name="ProjectItemsControl" HorizontalAlignment="Left">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
<!-- Ändert die Anordnung auf horizontal -->
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical" Margin="0,0,30,0" VerticalAlignment="Center">
<Button Click="Profile_Click" Background="Transparent" BorderThickness="0" Padding="0" Tag="{Binding Key}">
<Border Width="80" Height="80" Background="LightBlue" CornerRadius="40">
<Image Source="pack://application:,,,/Assets/profileicon.png" Stretch="Uniform" Margin="10"/>
</Border>
<TextBlock FontWeight="Bold" Text="Profile 1" Foreground="White" FontSize="14" HorizontalAlignment="Center" Margin="0,5,0,0" />
<Button Width="20" Height="20" Background="Transparent" BorderThickness="0" Click="EditProfile_Click" HorizontalAlignment="Center" ToolTip="Edit Profile" Margin="0,-205,-80,0">
</Button>
<TextBlock FontWeight="Bold" Text="{Binding Value}" Foreground="White" FontSize="14" HorizontalAlignment="Center" Margin="0,5,0,0"/>
<Button Width="20" Height="20" Background="Transparent" BorderThickness="0" Click="EditProfile_Click" HorizontalAlignment="Center" ToolTip="Edit Profile" Margin="0,-195,-80,0">
<Image Source="pack://application:,,,/Assets/pencilicon.png" Stretch="Uniform" />
</Button>
</StackPanel>
<!-- Profil 2 -->
<StackPanel Orientation="Vertical" Margin="20,0,0,0" VerticalAlignment="Center">
<Border Width="80" Height="80" Background="Gray" CornerRadius="40">
<Image Source="pack://application:,,,/Assets/profileicon.png" Stretch="Uniform" Margin="10"/>
</Border>
<TextBlock Text="Profile 2" Foreground="White" FontSize="14" HorizontalAlignment="Center" Margin="0,5,0,0" />
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<!-- Plus Button -->
<Border Width="50" Height="50" Background="Gray" CornerRadius="25" Margin="20,-15,0,0">
<Border Width="50" Height="50" Background="Gray" CornerRadius="25" Margin="5,0,0,20">
<Button Width="50" Height="50" Background="Transparent" BorderThickness="0" Click="AddProfile_Click" HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock Text="+" FontSize="24" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Center" />
<TextBlock Text="+" FontSize="24" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Center" FontWeight="Bold" Margin="0,-5,0,0"/>
</Button>
</Border>
</StackPanel>
</ScrollViewer>
</StackPanel>
</Border>
<!-- Settings Section -->
......
......
using InnoLabProjektDektopApp.Screens.Regulaer;
using InnoLabProjektDektopApp.Services;
using System.Collections.ObjectModel;
using InnoLabProjektDektopApp.Services.WebSocketServer;
using System.IO;
using System.Net.Sockets;
......@@ -17,13 +18,16 @@ namespace InnoLabProjektDektopApp
public partial class Overview : Page
{
// Aktuelles Profil, für das Einstellungen geladen werden sollen
private string profile = "profile1";
private string project = "project1";
// Pfad zur JSON-Datei, in der die Einstellungen gespeichert sind
private string SettingsFilePath;
private static Session tmpSession = null;
// ObservableCollection, die die Projektnamen enthält
private ObservableCollection<KeyValuePair<string, string>> projectNames = new ObservableCollection<KeyValuePair<string, string>>();
public Overview()
{
InitializeComponent();
......@@ -32,13 +36,83 @@ namespace InnoLabProjektDektopApp
this.SettingsFilePath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "settings.json");
// Einstellungen für das aktuelle Profil laden
LoadProjectNames();
LoadSettings();
// Die ProjectNames im UI an ItemsControl binden
ProjectItemsControl.ItemsSource = projectNames;
}
public static Session getSession() {
public static Session getSession()
{
return tmpSession;
}
private List<string> projectNamesList = new List<string>(); // Liste der Projekt-Namen
private void LoadProjectNames()
{
try
{
// JSON-Datei lesen
if (File.Exists(SettingsFilePath))
{
string jsonContent = File.ReadAllText(SettingsFilePath);
var settings = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(jsonContent);
if (settings != null)
{
// Alle Projekte durchgehen und den projectKey und displayName zur Liste hinzufügen
foreach (var projectKey in settings.Keys)
{
var projectSettings = settings[projectKey];
if (projectSettings.TryGetProperty("displayName", out var displayNameElement))
{
string displayName = displayNameElement.GetString() ?? "Unbekannt";
projectNames.Add(new KeyValuePair<string, string>(projectKey, displayName)); // projectKey und displayName speichern
}
}
}
}
}
catch (Exception ex)
{
Console.WriteLine($"Fehler beim Laden der Projekt-Namen: {ex.Message}");
}
}
private void Profile_Click(object sender, RoutedEventArgs e)
{
if (sender is Button button && button.Tag is string clickedProjectKey)
{
try
{
if (File.Exists(SettingsFilePath))
{
string jsonContent = File.ReadAllText(SettingsFilePath);
var settings = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(jsonContent);
if (settings != null && settings.ContainsKey(clickedProjectKey))
{
project = clickedProjectKey; // Setze das aktive Projekt
LoadSettings(); // Lade die Einstellungen für das gewählte Projekt
MessageBox.Show($"Projekt gewechselt zu: {project}");
}
}
}
catch (Exception ex)
{
MessageBox.Show($"Fehler beim Laden des Projekts: {ex.Message}");
}
}
}
// Methode, um die Einstellungen für das aktuelle Profil aus der JSON-Datei zu laden
private void LoadSettings()
{
......@@ -51,9 +125,9 @@ namespace InnoLabProjektDektopApp
string jsonContent = File.ReadAllText(SettingsFilePath);
var settings = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(jsonContent);
if (settings != null && settings.ContainsKey(profile))
if (settings != null && settings.ContainsKey(project))
{
var profileSettings = settings[profile];
var profileSettings = settings[project];
// Focus Period
if (profileSettings.TryGetProperty("focusPeriod", out var focusPeriodElement))
......@@ -211,7 +285,7 @@ namespace InnoLabProjektDektopApp
}
else
{
MessageBox.Show($"No settings found for profile '{profile}'", "Info", MessageBoxButton.OK, MessageBoxImage.Information);
MessageBox.Show($"No settings found for profile '{project}'", "Info", MessageBoxButton.OK, MessageBoxImage.Information);
}
}
else
......@@ -242,14 +316,15 @@ namespace InnoLabProjektDektopApp
// Ereignis-Handler für den "Edit Profile"-Button
private void EditProfile_Click(object sender, RoutedEventArgs e)
{
var distractions = new Distractions();
this.NavigationService.Navigate(distractions);
//var distractions = new Distractions();
//this.NavigationService.Navigate(distractions);
}
// Ereignis-Handler für den "Add Profile"-Button
private void AddProfile_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("Add Profile clicked!");
var settingsPage = new Settings();
this.NavigationService.Navigate(settingsPage);
}
// Ereignis-Handler, um den Placeholder für das Textfeld anzuzeigen oder auszublenden
......@@ -435,7 +510,8 @@ namespace InnoLabProjektDektopApp
}
}
public static Session getSessionInstance() {
public static Session getSessionInstance()
{
return tmpSession;
}
......
......
......@@ -144,7 +144,7 @@ namespace InnoLabProjektDektopApp.Screens.Regulaer
private bool mascottVisible()
{
String profile = "profile1";
String profile = "project1";
String SettingsFilePath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "settings.json");
if (File.Exists(SettingsFilePath))
......
......
......@@ -230,7 +230,7 @@ namespace InnoLabProjektDektopApp.Utils
{
string jsonContent = File.ReadAllText(path);
var settings = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(jsonContent);
if (settings != null && settings.TryGetValue("profile1", out JsonElement profileSettings))
if (settings != null && settings.TryGetValue("project1", out JsonElement profileSettings))
{
_settings.focusPeriod = int.Parse(profileSettings.GetProperty("focusPeriod").GetString().Replace(" minutes", ""));
_settings.breakPeriod = int.Parse(profileSettings.GetProperty("breakPeriod").GetString().Replace(" minutes", ""));
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment