Skip to content

Commit

Permalink
Merge pull request #26 from DSaladinCH/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
DominicSaladin authored Jan 7, 2024
2 parents 978f55b + 5f85b0d commit be9669b
Show file tree
Hide file tree
Showing 11 changed files with 129 additions and 16 deletions.
9 changes: 3 additions & 6 deletions speed-time/Converter/DateConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,11 @@ public object ConvertBack(object value, Type targetType, object parameter, Cultu
return SourceValue;
}

if (parsedDate.Year == 1)
parsedDate = parsedDate.AddYears(currentDate.Year - 1);

if (parsedDate.Month == 1 && !formats[1].Equals(dateString) && !formats[2].Equals(dateString))
parsedDate = parsedDate.AddMonths(currentDate.Month - 1);
// Only day was provided
if (dateString.Length <= 2)
parsedDate = new(parsedDate.Year, currentDate.Month, parsedDate.Day);

return parsedDate;

}
}
}
2 changes: 2 additions & 0 deletions speed-time/Dialogs/UserSettings.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@
Value="{Binding Source={x:Static potato:ColorManagement.Instance}, Path=CurrAccent}" />
<settings:CheckBoxSetting Category="Behavior" OptionName="{x:Static language:SpeedTime.settings_auto_break}"
Value="{Binding Source={x:Static models:SettingsModel.Instance}, Path=AutoAddBreak}"/>
<settings:CheckBoxSetting Category="Behavior" OptionName="{x:Static language:SpeedTime.settings_show_gaps}"
Value="{Binding Source={x:Static models:SettingsModel.Instance}, Path=ShowGapsBetweenTimes}"/>
<settings:ActionSetting Category="Behavior" OptionName="{x:Static language:SpeedTime.settings_workdays}"
ActionText="{x:Static language:SpeedTime.open}"
ActionCommand="{Binding RelativeSource={RelativeSource AncestorType={x:Type local:UserSettings}}, Path=WorkdaysCommand}" />
Expand Down
18 changes: 18 additions & 0 deletions speed-time/Language/SpeedTime.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions speed-time/Language/SpeedTime.de-CH.resx
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@
<data name="Cancel" xml:space="preserve">
<value>Abbrechen</value>
</data>
<data name="gap-text" xml:space="preserve">
<value>Lücke von {0} Std.</value>
</data>
<data name="hotkey.press-key" xml:space="preserve">
<value>Taste drücken...</value>
</data>
Expand Down Expand Up @@ -159,6 +162,9 @@
<data name="settings.integrations.title" xml:space="preserve">
<value>Integrationen</value>
</data>
<data name="settings.show-gaps" xml:space="preserve">
<value>Zeige Lücken</value>
</data>
<data name="settings.task-linking" xml:space="preserve">
<value>Task Verbindungen</value>
</data>
Expand Down
6 changes: 6 additions & 0 deletions speed-time/Language/SpeedTime.es-ES.resx
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@
<data name="Cancel" xml:space="preserve">
<value>Cancelar</value>
</data>
<data name="gap-text" xml:space="preserve">
<value>Hueco de {0} hora</value>
</data>
<data name="hotkey.press-key" xml:space="preserve">
<value>Presiona la Tecla...</value>
</data>
Expand Down Expand Up @@ -159,6 +162,9 @@
<data name="settings.integrations.title" xml:space="preserve">
<value>Integraciones</value>
</data>
<data name="settings.show-gaps" xml:space="preserve">
<value>Mostrar Huecos</value>
</data>
<data name="settings.task-linking" xml:space="preserve">
<value>Conexión de tareas</value>
</data>
Expand Down
6 changes: 6 additions & 0 deletions speed-time/Language/SpeedTime.resx
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@
<data name="Cancel" xml:space="preserve">
<value>Cancel</value>
</data>
<data name="gap-text" xml:space="preserve">
<value>Gap of {0}h</value>
</data>
<data name="hotkey.press-key" xml:space="preserve">
<value>Press Key...</value>
</data>
Expand Down Expand Up @@ -159,6 +162,9 @@
<data name="settings.integrations.title" xml:space="preserve">
<value>Integrations</value>
</data>
<data name="settings.show-gaps" xml:space="preserve">
<value>Show Gaps</value>
</data>
<data name="settings.task-linking" xml:space="preserve">
<value>Task Links</value>
</data>
Expand Down
38 changes: 32 additions & 6 deletions speed-time/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@
<potato:DSWindow.Resources>
<converter:DateTimeConverter x:Key="DateTimeConverter" />
<potato:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />

<Style x:Key="DefaultTimeLabel" TargetType="{x:Type Label}" BasedOn="{StaticResource DefaultLabel}">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=IsBreak}" Value="True">
<Setter Property="FontStyle" Value="Italic" />
<Setter Property="Foreground" Value="{DynamicResource ForegroundA}" />
</DataTrigger>
<DataTrigger Binding="{Binding Path=IsGapItem}" Value="True">
<Setter Property="FontStyle" Value="Italic" />
<Setter Property="Foreground" Value="{DynamicResource ForegroundA}" />
</DataTrigger>
</Style.Triggers>
</Style>
</potato:DSWindow.Resources>
<behaviors:Interaction.Triggers>
<behaviors:KeyTrigger Modifiers="{Binding RegisteredHotKey.RegisteredModifierKeys}" Key="{Binding RegisteredHotKey.RegisteredKey}" FiredOn="KeyDown">
Expand Down Expand Up @@ -109,24 +122,31 @@
<Setter Property="FontStyle" Value="Italic" />
<Setter Property="Foreground" Value="{DynamicResource ForegroundA}" />
</DataTrigger>
<DataTrigger Binding="{Binding Path=IsGapItem}" Value="True">
<Setter Property="FontStyle" Value="Italic" />
<Setter Property="Foreground" Value="{DynamicResource ForegroundA}" />
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
</Border>
<Label Grid.Column="1">
<Label.Style>
<Style TargetType="Label" BasedOn="{StaticResource DefaultLabel}">
<Style TargetType="Label" BasedOn="{StaticResource DefaultTimeLabel}">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=IsBreak}" Value="True">
<Setter Property="fa:Content.Icon" Value="SolidMugHot" />
</DataTrigger>
<DataTrigger Binding="{Binding Path=IsGapItem}" Value="True">
<Setter Property="fa:Content.Icon" Value="SolidArrowsLeftRightToLine" />
</DataTrigger>
</Style.Triggers>
</Style>
</Label.Style>
</Label>
<Label Grid.Column="2" Content="{Binding TrackingTime}" />
<Label Grid.Column="3" Content="{Binding Hours}" ContentStringFormat=" {0:N2}h" HorizontalContentAlignment="Right" />
<Label Grid.Column="2" Content="{Binding TrackingTime}" Style="{DynamicResource DefaultTimeLabel}" />
<Label Grid.Column="3" Content="{Binding Hours}" ContentStringFormat=" {0:N2}h" HorizontalContentAlignment="Right" Style="{DynamicResource DefaultTimeLabel}" />
<potato:DSButton Grid.Column="4" fa:Content.Icon="SolidGlobe" Padding="5,0,5,0" Style="{DynamicResource TransparentAccentButton}" Visibility="Collapsed" x:Name="btnBrowser"
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type potato:DSWindow}}, Path=DataContext.OpenJiraIssueCommand}"
CommandParameter="{Binding RelativeSource={RelativeSource Self}, Path=DataContext}" />
Expand All @@ -135,9 +155,15 @@
CommandParameter="{Binding RelativeSource={RelativeSource Self}, Path=DataContext}" />
</Grid>
<DataTemplate.Triggers>
<Trigger SourceName="grdTime" Property="IsMouseOver" Value="True">
<Setter TargetName="btnDelete" Property="Visibility" Value="Visible"/>
</Trigger>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding ElementName=grdTime, Path=IsMouseOver}" Value="True" />
<Condition Binding="{Binding IsGapItem}" Value="False" />
</MultiDataTrigger.Conditions>
<MultiDataTrigger.Setters>
<Setter TargetName="btnDelete" Property="Visibility" Value="Visible"/>
</MultiDataTrigger.Setters>
</MultiDataTrigger>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding ElementName=grdTime, Path=IsMouseOver}" Value="True" />
Expand Down
15 changes: 15 additions & 0 deletions speed-time/Model/SettingsModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,21 @@ public bool? AutoAddBreak
}
}

private bool showGapsBetweenTimes;
public bool? ShowGapsBetweenTimes
{
get { return showGapsBetweenTimes; }
set
{
if (value is null)
showGapsBetweenTimes = false;
else
showGapsBetweenTimes = value.Value;

NotifyPropertyChanged();
}
}

public Workdays Workdays { get; set; } = new();

public static List<UiLanguage> AvailableLanguages { get; } = new()
Expand Down
3 changes: 3 additions & 0 deletions speed-time/Model/TrackTime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ private set
[NotMapped]
public bool IsTimeStopped { get => TrackingStopped != default; }

[NotMapped]
public bool IsGapItem { get; set; }

[NotMapped]
public double Hours
{
Expand Down
40 changes: 37 additions & 3 deletions speed-time/ViewModel/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public MainWindowViewModel()

TrackTimeDoubleClickCommand = new(async (sender) =>
{
if (IsTrackTimeEditorOpen || IsUserSettingsOpen)
if (IsTrackTimeEditorOpen || IsUserSettingsOpen || sender is null || ((TrackTime)sender).IsGapItem)
return;
IsTrackTimeEditorOpen = true;
Expand Down Expand Up @@ -244,6 +244,7 @@ public MainWindowViewModel()
IsUserSettingsOpen = false;
RegisteredHotKey = SettingsModel.Instance.GetRegisteredHotKey(RegisteredHotKey.HotKeyType.NewEntry);
UpdateView();
if (shouldRestart)
{
Expand Down Expand Up @@ -272,7 +273,6 @@ public override void WindowLoaded(object sender, RoutedEventArgs eventArgs)

// bind to the source
TrackedTimesViewSource = new();
TrackedTimesViewSource.SetCurrentValue(CollectionViewSource.SourceProperty, App.dbContext.TrackedTimes.Local.ToObservableCollection());
TrackedTimesViewSource.Filter += (s, e) => e.Accepted = (e.Item as TrackTime)!.TrackingStarted.Date == CurrentDateTime.Date;
TrackedTimesViewSource.SortDescriptions.Add(new("TrackingStarted", ListSortDirection.Descending));
TrackedTimesViewSource.SortDescriptions.Add(new("TrackingStopped", ListSortDirection.Descending));
Expand All @@ -286,7 +286,41 @@ private void UpdateView()
{
weekRange = GetWeekRange(CurrentDateTime);
NotifyPropertyChanged("");
TrackedTimesViewSource.View?.Refresh();
UpdateTrackedTimes();
}

private void UpdateTrackedTimes()
{
List<TrackTime> trackedTimes = [.. App.dbContext.TrackedTimes.Local.Where(tt => tt.TrackingStarted.Date == currentDateTime.Date).OrderBy(tt => tt.TrackingStarted)];
ObservableCollection<TrackTime>? displayItems = TrackedTimesViewSource.Source as ObservableCollection<TrackTime>;

if (displayItems is null)
{
displayItems = [];
TrackedTimesViewSource.SetCurrentValue(CollectionViewSource.SourceProperty, displayItems);
}

displayItems.Clear();

for (int i = 0; i < trackedTimes.Count; i++)
{
displayItems.Add(trackedTimes[i]);

if (SettingsModel.Instance.ShowGapsBetweenTimes == false || i >= trackedTimes.Count - 1)
continue;

TimeSpan gapTime = trackedTimes[i + 1].TrackingStarted - trackedTimes[i].TrackingStopped;
if (gapTime.TotalHours < 0)
continue;

TrackTime gap = new(trackedTimes[i].TrackingStopped, string.Format(Language.SpeedTime.gap_text, gapTime.TotalHours.ToString("N2")), false)
{
IsGapItem = true
};

gap.StopTime(trackedTimes[i + 1].TrackingStarted);
displayItems.Add(gap);
}
}

async Task UpdateCurrentTime()
Expand Down
2 changes: 1 addition & 1 deletion speed-time/speed-time.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<PackageReadmeFile>README.md</PackageReadmeFile>
<ApplicationIcon>Icon.ico</ApplicationIcon>
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
<Version>0.13.1</Version>
<Version>0.14</Version>
<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile></AssemblyOriginatorKeyFile>
</PropertyGroup>
Expand Down

0 comments on commit be9669b

Please sign in to comment.