Skip to content

Commit

Permalink
Merge pull request #77 from BeloMaximka/experimental-settings
Browse files Browse the repository at this point in the history
add experimental settings
  • Loading branch information
BeloMaximka authored Jan 22, 2024
2 parents 3c81d7b + c7dadee commit 6bfe28d
Show file tree
Hide file tree
Showing 15 changed files with 203 additions and 17 deletions.
1 change: 1 addition & 0 deletions MystatDesktopWpf/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

<!-- Converters -->
<converters:ZeroToVisibilityConverter x:Key="ZeroToVisibilityConverter"/>
<converters:StringToResource x:Key="StringToResource" />

<!-- Custom styles -->
<Style x:Key="PopupToolButton" TargetType="Button" BasedOn="{StaticResource MaterialDesignToolButton}">
Expand Down
22 changes: 22 additions & 0 deletions MystatDesktopWpf/Converters/StringToResource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace MystatDesktopWpf.Converters
{
public class StringToResource : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return App.Current.FindResource(value as string);
}

public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
7 changes: 7 additions & 0 deletions MystatDesktopWpf/Languages/lang.en-US.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
<v:String x:Key="m_FolderOpenError">Failed to open the folder.</v:String>
<v:String x:Key="m_ErrorWhileLoadingHomework" xml:space="preserve">¯\_(ツ)_/¯&#13;&#13;An error occurred while loading homework, please try again later.</v:String>
<v:String x:Key="m_AllSubjects">All subjects</v:String>
<v:String x:Key="m_HomeworkTypeHomework">Homework</v:String>
<v:String x:Key="m_HomeworkTypeLab">Lab</v:String>

<!-- Homework tooltips -->
<v:String x:Key="m_TeacherComment">Teacher's comment</v:String>
Expand Down Expand Up @@ -198,4 +200,9 @@
<v:String x:Key="size-kb">KB</v:String>
<v:String x:Key="size-mb">MB</v:String>
<v:String x:Key="size-gb">GB</v:String>

<!-- Experimental settings -->
<v:String x:Key="m_ExperimentalSettings">Experimental</v:String>
<v:String x:Key="m_BypassUploadRestrictions">Bypass upload restrictions for certain file types (for example .txt and .csv)</v:String>
<v:String x:Key="m_BypassUploadRestrictionsHelpText">May fix uploading of individual files, especially code files</v:String>
</ResourceDictionary>
7 changes: 7 additions & 0 deletions MystatDesktopWpf/Languages/lang.ru-RU.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
<v:String x:Key="m_FolderOpenError">Не удалось открыть папку.</v:String>
<v:String x:Key="m_ErrorWhileLoadingHomework" xml:space="preserve">¯\_(ツ)_/¯&#13;&#13;При загрузке домашнего задания произошла ошибка, повторите попытку позже.</v:String>
<v:String x:Key="m_AllSubjects">Все предметы</v:String>
<v:String x:Key="m_HomeworkTypeHomework">Домашние задания</v:String>
<v:String x:Key="m_HomeworkTypeLab">Лабораторные задания</v:String>

<!-- Homework tooltips -->
<v:String x:Key="m_TeacherComment">Комментарий преподавателя</v:String>
Expand Down Expand Up @@ -197,4 +199,9 @@
<v:String x:Key="size-kb">КБ</v:String>
<v:String x:Key="size-mb">МБ</v:String>
<v:String x:Key="size-gb">ГБ</v:String>

<!-- Experimental settings -->
<v:String x:Key="m_ExperimentalSettings">Эксперименты</v:String>
<v:String x:Key="m_BypassUploadRestrictions">Обход запрета на загрузку определенных типов файлов (например .txt и .csv)</v:String>
<v:String x:Key="m_BypassUploadRestrictionsHelpText">Может решить проблемы с загрузкой отдельных файлов, особенной файлов с кодом</v:String>
</ResourceDictionary>
9 changes: 8 additions & 1 deletion MystatDesktopWpf/Languages/lang.uk-UA.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<v:String x:Key="m_ColorSelection">Кориговані кольори</v:String>

<v:String x:Key="m_ShowFromTray">Розгорнути</v:String>
<v:String x:Key="m_Exit">Закрити</v:String>
<v:String x:Key="m_Exit">Закрити</v:String>

<v:String x:Key="m_TraySettings">Налаштування трею</v:String>
<v:String x:Key="m_MoveToTray">Коли переміщати в трей:</v:String>
Expand All @@ -76,6 +76,8 @@
<v:String x:Key="m_FolderOpenError">Не вдалося відкрити папку.</v:String>
<v:String x:Key="m_ErrorWhileLoadingHomework" xml:space="preserve">¯\_(ツ)_/¯&#13;&#13;Під час завантаження домашнього завдання виникла помилка, повторіть спробу пізніше.</v:String>
<v:String x:Key="m_AllSubjects">Всі предмети</v:String>
<v:String x:Key="m_HomeworkTypeHomework">Домашні завдання</v:String>
<v:String x:Key="m_HomeworkTypeLab">Лабораторні завдання</v:String>

<!-- Homework tooltips -->
<v:String x:Key="m_TeacherComment">Коментар викладача</v:String>
Expand Down Expand Up @@ -197,4 +199,9 @@
<v:String x:Key="size-kb">КБ</v:String>
<v:String x:Key="size-mb">МБ</v:String>
<v:String x:Key="size-gb">ГБ</v:String>

<!-- Experimental settings -->
<v:String x:Key="m_ExperimentalSettings">Експерименти</v:String>
<v:String x:Key="m_BypassUploadRestrictions">Обхід заборони завантаження певних типів файлів (наприклад, .txt і .csv)</v:String>
<v:String x:Key="m_BypassUploadRestrictionsHelpText">Може вирішити проблеми із завантаженням окремих файлів, особливо файлів з кодом</v:String>
</ResourceDictionary>
2 changes: 2 additions & 0 deletions MystatDesktopWpf/Services/SettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ static SettingsService()
Settings.Theme.OnPropertyChanged += SettingsChanged;
Settings.Tray.OnPropertyChanged += SettingsChanged;
Settings.TimezoneConvertion.OnPropertyChanged += SettingsChanged;
Settings.Experimental.OnPropertyChanged += SettingsChanged;
}

public static Settings? Load()
Expand Down Expand Up @@ -172,6 +173,7 @@ то мы ставим анлийский*/
public ThemeSubSettings Theme { get; set; } = new();
public TraySubSettings Tray { get; set; } = new();
public TimezoneSubSettings TimezoneConvertion { get; set; } = new();
public ExperimentalFeaturesSubSettings Experimental { get; set; } = new();
public bool AutoLessonEvaluationEnabled { get; set; } = false;
public string Language { get; set; }

Expand Down
31 changes: 31 additions & 0 deletions MystatDesktopWpf/SubSettings/ExperimentalFeaturesSubSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using MystatDesktopWpf.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MystatDesktopWpf.SubSettings
{
public class ExperimentalFeaturesSubSettings : ISettingsProperty
{
public event Action? OnPropertyChanged;

private bool bypassUploadRestrictions = false;

public bool BypassUploadRestrictions
{
get => bypassUploadRestrictions;
set
{
bypassUploadRestrictions = value;
PropertyChanged();
}
}

public void PropertyChanged()
{
OnPropertyChanged?.Invoke();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using MaterialDesignThemes.Wpf;
using Microsoft.Win32;
using MystatAPI.Entity;
using MystatDesktopWpf.Services;
using System;
using System.Collections.Generic;
using System.IO;
Expand All @@ -17,6 +18,7 @@ namespace MystatDesktopWpf.UserControls.DialogContent
/// </summary>
public partial class UploadHomework : UserControl
{
public static string[] mystatForbiddenExtentions = new string[] { ".txt", ".csv", ".py" };
public static readonly DependencyProperty HeaderProperty =
DependencyProperty.Register("Header", typeof(string), typeof(UploadHomework));
public string Header
Expand Down Expand Up @@ -79,7 +81,10 @@ private void UpdateFileInfo()
fileLine.Visibility = Visibility.Visible;

string extension = Path.GetExtension(files[0]);
if (files?.Length != 1 || extension == ".txt" || extension == ".csv" || Directory.Exists(files[0]))
if (
files?.Length != 1
|| (mystatForbiddenExtentions.Contains(extension) && !SettingsService.Settings.Experimental.BypassUploadRestrictions)
|| Directory.Exists(files[0]))
{
Archive = true;
fileTextBox.Visibility = Visibility.Visible;
Expand Down
27 changes: 18 additions & 9 deletions MystatDesktopWpf/UserControls/Menus/Homeworks.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
<materialDesign:DialogHost x:Name="homeworkDialog" CloseOnClickAway="True" DialogTheme="Inherit">
<Grid>
<materialDesign:Transitioner x:Name="transitioner" SelectedIndex="0">

<materialDesign:TransitionerSlide>
<materialDesign:TransitionerSlide.ForwardWipe>
<materialDesign:FadeWipe/>
Expand All @@ -26,14 +25,24 @@
<materialDesign:TransitionerSlide BackwardWipe="{x:Null}">
<ScrollViewer>
<StackPanel x:Name="HomeworkStackPanel" Margin="16">
<ComboBox x:Name="SpecsComboBox" ItemsSource="{Binding Specs}" Margin="8 0" HorizontalAlignment="Left"
SelectedItem="{Binding SelectedSpec, Mode=OneWay}" Width="430" >
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<StackPanel Orientation="Horizontal">
<!--<ComboBox x:Name="TypeComboBox" Margin="8 0" HorizontalAlignment="Left" Width="200" ItemsSource="{Binding Types}"
SelectedItem="{Binding SelectedType, Mode=OneWay}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding TranslationKey, Converter={StaticResource StringToResource}}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>-->
<ComboBox x:Name="SpecsComboBox" ItemsSource="{Binding Specs}" Margin="8 0" HorizontalAlignment="Left"
SelectedItem="{Binding SelectedSpec, Mode=OneWay}" Width="430" >
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</StackPanel>
<controls:HomeworkList x:Name="OverdueList" Header="{DynamicResource m_Overdue}"
HomeworkManager="{Binding ElementName=Control}"/>

Expand Down
7 changes: 4 additions & 3 deletions MystatDesktopWpf/UserControls/Menus/LessonEvaluation.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
using MystatDesktopWpf.Domain;
using MystatDesktopWpf.Services;
using MystatDesktopWpf.ViewModels;
using System.Linq;
using System;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using MystatAPI.Entity;

namespace MystatDesktopWpf.UserControls.Menus
{
Expand All @@ -16,6 +15,8 @@ namespace MystatDesktopWpf.UserControls.Menus
public partial class LessonEvaluation : UserControl, IRefreshable
{
private LessonEvaluationViewModel viewModel;
private static bool autoRefreshCompleted = false;

public LessonEvaluation()
{
InitializeComponent();
Expand All @@ -38,7 +39,7 @@ private async void AutoRefresh()
return;
}
}

// If not - schedule for tomorrow
scheduleList = await MystatAPISingleton.Client.GetScheduleByDate(DateTime.Now.AddDays(1));
if (scheduleList.Length > 0)
Expand Down
1 change: 1 addition & 0 deletions MystatDesktopWpf/UserControls/Menus/Settings.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<controls:ThemeSettings Margin="8"/>
<controls:TraySettings Margin="8"/>
<controls:TimezoneSettings Margin="8"/>
<controls:ExperimentalSettings Margin="8"/>
<controls:CacheSettings x:Name="CacheSettings" Margin="8"/>
</StackPanel>
</ScrollViewer>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<UserControl x:Class="MystatDesktopWpf.UserControls.SettingsSections.ExperimentalSettings"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:MystatDesktopWpf.UserControls.SettingsSections"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<materialDesign:Card Padding="8">
<StackPanel Margin="8 0 0 0">
<TextBlock Text="{DynamicResource m_ExperimentalSettings}" HorizontalAlignment="Left" Style="{DynamicResource MaterialDesignBody1TextBlock}"/>
<StackPanel Orientation="Horizontal" Margin="0 8">
<ToggleButton x:Name="BypassUploadToggle" Unchecked="ToggleButton_Unchecked" Checked='ToggleButton_Checked' VerticalAlignment="Top" />
<StackPanel Orientation="Vertical" Margin="8 0 0 0">
<TextBlock Text="{DynamicResource m_BypassUploadRestrictions}"/>
<TextBlock Text="{DynamicResource m_BypassUploadRestrictionsHelpText}" FontSize="10" Margin="0 4 0 0"/>
</StackPanel>
</StackPanel>
</StackPanel>
</materialDesign:Card>
</UserControl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using MystatDesktopWpf.Domain;
using MystatDesktopWpf.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace MystatDesktopWpf.UserControls.SettingsSections
{
/// <summary>
/// Interaction logic for ExperimentalSettings.xaml
/// </summary>
public partial class ExperimentalSettings : UserControl
{
public ExperimentalSettings()
{
InitializeComponent();
BypassUploadToggle.IsChecked = SettingsService.Settings.Experimental.BypassUploadRestrictions;
}

private void ToggleButton_Checked(object sender, RoutedEventArgs e)
{
MystatAPISingleton.Client.BypassUploadRestrictions = true;
SettingsService.Settings.Experimental.BypassUploadRestrictions = true;
}

private void ToggleButton_Unchecked(object sender, RoutedEventArgs e)
{
MystatAPISingleton.Client.BypassUploadRestrictions = false;
SettingsService.Settings.Experimental.BypassUploadRestrictions = false;
}
}
}
31 changes: 29 additions & 2 deletions MystatDesktopWpf/ViewModels/HomeworksViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
using System.Threading.Tasks;
using System.ComponentModel;
using System.Linq;
using System.Xml.Linq;
using Microsoft.VisualBasic.FileIO;
using MystatDesktopWpf.UserControls.Menus;

namespace MystatDesktopWpf.ViewModels
Expand All @@ -19,6 +17,12 @@ internal class HomeworksViewModel : ViewModelBase, INotificationCount

private List<Spec> specs;
public List<Spec> Specs { get => specs; set => SetProperty(ref specs, value); }

private List<HomeworkTypeListEntry> types = new List<HomeworkTypeListEntry>() {
new HomeworkTypeListEntry(HomeworkType.Homework, "m_HomeworkTypeHomework"),
new HomeworkTypeListEntry(HomeworkType.Lab, "m_HomeworkTypeLab"),
};
public List<HomeworkTypeListEntry> Types { get => types; set => SetProperty(ref types, value); }

private readonly Spec allSpecsItem;
private Spec selectedSpec;
Expand All @@ -32,6 +36,16 @@ private set
}
}

private HomeworkTypeListEntry selectedHomeworkType;
public HomeworkTypeListEntry SelectedType
{
get => selectedHomeworkType;
private set
{
SetProperty(ref selectedHomeworkType, value);
}
}

public HomeworksViewModel()
{
Homework[HomeworkStatus.Active].PropertyChanged += HomeworksViewModel_PropertyChanged;
Expand All @@ -45,6 +59,7 @@ public HomeworksViewModel()
};
allSpecsItem.ShortName = allSpecsItem.Name;
selectedSpec = allSpecsItem;
selectedHomeworkType = types[0];
UpdateHomeworkCollectionSpecs();
App.LanguageChanged += App_LanguageChanged;
App.GroupChanged += (_, _) => {
Expand Down Expand Up @@ -231,4 +246,16 @@ public async Task<bool> LoadNextPage()
}
}
}

class HomeworkTypeListEntry
{
public HomeworkType HomeworkType { get; set; }
public string TranslationKey { get; set; }

public HomeworkTypeListEntry(HomeworkType homeworkType, string translationKey)
{
HomeworkType = homeworkType;
TranslationKey = translationKey;
}
}
}
2 changes: 1 addition & 1 deletion mystatapi-cs

0 comments on commit 6bfe28d

Please sign in to comment.