109 lines
3.5 KiB
C#
109 lines
3.5 KiB
C#
using Blueberry.Redmine;
|
|
using Blueberry.Redmine.Dto;
|
|
using System.Timers;
|
|
using System.Windows.Input;
|
|
using Wpf.Ui.Controls;
|
|
|
|
namespace Blueberry
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for TimeTrackerWindow.xaml
|
|
/// </summary>
|
|
public partial class TimeTrackerWindow : FluentWindow
|
|
{
|
|
private readonly RedmineConfig _config;
|
|
private readonly RedmineManager _manager;
|
|
private readonly IssueList.Issue _issue;
|
|
public string CurrentIssue => _issue.Subject;
|
|
private readonly System.Timers.Timer _timer;
|
|
private TimeSpan _elapsedTime;
|
|
|
|
public TimeTrackerWindow(RedmineConfig config, RedmineManager manager, IssueList.Issue issue)
|
|
{
|
|
DataContext = this;
|
|
_config = config;
|
|
_manager = manager;
|
|
_issue = issue;
|
|
_timer = new System.Timers.Timer(new TimeSpan(0, 0, 1));
|
|
_timer.Elapsed += TimerElapsed;
|
|
_elapsedTime = new TimeSpan(0);
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void FluentWindow_Loaded(object sender, System.Windows.RoutedEventArgs e)
|
|
{
|
|
issueTextBlock.Text = "#" + _issue.Id;
|
|
}
|
|
|
|
private void TimerElapsed(object? sender, ElapsedEventArgs e)
|
|
{
|
|
_elapsedTime = _elapsedTime.Add(new(0, 0, 1));
|
|
Dispatcher.Invoke(new Action(() =>
|
|
{
|
|
timeTextBlock.Text = _elapsedTime.ToString(@"hh\:mm\:ss");
|
|
}));
|
|
}
|
|
|
|
private void playPauseButton_Click(object sender, System.Windows.RoutedEventArgs e)
|
|
{
|
|
if(_timer.Enabled)
|
|
{
|
|
_timer.Stop();
|
|
playPauseIcon.Symbol = SymbolRegular.Play24;
|
|
}
|
|
else
|
|
{
|
|
_timer.Start();
|
|
playPauseIcon.Symbol = SymbolRegular.Pause24;
|
|
}
|
|
}
|
|
|
|
private void doneButton_Click(object sender, System.Windows.RoutedEventArgs e)
|
|
{
|
|
_timer.Stop();
|
|
double hour = GetCurrentHours();
|
|
|
|
resultHourTextBlock.Text = $"{hour}";
|
|
resultFlyout.IsOpen = true;
|
|
}
|
|
|
|
private double GetCurrentHours()
|
|
{
|
|
var hour = (_elapsedTime.TotalMinutes + 10) / 15;
|
|
hour = Math.Ceiling(hour / 15.0) * 15.0;
|
|
hour /= 60.0;
|
|
return hour;
|
|
}
|
|
|
|
private void FluentWindow_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
|
{
|
|
DragMove();
|
|
}
|
|
|
|
private void cancelButton_Click(object sender, System.Windows.RoutedEventArgs e)
|
|
{
|
|
Close();
|
|
}
|
|
|
|
private async void resultSaveButton_Click(object sender, System.Windows.RoutedEventArgs e)
|
|
{
|
|
var hours = GetCurrentHours();
|
|
var result = await new MessageBox
|
|
{
|
|
Title = "Ellenőrzés",
|
|
Content = $"Jegy: {_issue.Id}\nÓra: {hours}\nÜzenet: {resultTextBox.Text}\n\nBiztos, hogy beküldöd?",
|
|
PrimaryButtonText = "Igen",
|
|
SecondaryButtonText = "Nem",
|
|
IsCloseButtonEnabled = false,
|
|
}.ShowDialogAsync();
|
|
|
|
if (result == MessageBoxResult.Primary)
|
|
{
|
|
await _manager.LogTimeAsync(_issue.Id, hours, resultTextBox.Text, DateTime.Today);
|
|
await new MessageBox { Title = "Sikeres beküldés", Content = $"A {_issue.Id} jegyre {hours} óra lett felírva." }.ShowDialogAsync();
|
|
Close();
|
|
}
|
|
}
|
|
}
|
|
}
|