Skip to content

Commit

Permalink
Improved issue display, fixed update bug and changed timestamp to be …
Browse files Browse the repository at this point in the history
…nullable #209
  • Loading branch information
Kittyfisto committed Jul 21, 2019
1 parent 35eea55 commit 2cb6370
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public sealed class LogFileIssue
/// <param name="severity">The severity of the issue - more severe issues are presented to the user with more urgency</param>
/// <param name="summary">A very short summary of the issue, should fit into one line.</param>
/// <param name="description">An optional (very detailed) description of the issue. May span multiple lines.</param>
public LogFileIssue(LogLineIndex line, DateTime timestamp, Severity severity, string summary, string description)
public LogFileIssue(LogLineIndex line, DateTime? timestamp, Severity severity, string summary, string description)
{
Line = line;
Timestamp = timestamp;
Expand All @@ -32,7 +32,7 @@ public LogFileIssue(LogLineIndex line, DateTime timestamp, Severity severity, st
/// <summary>
/// The timestamp of when the issue occured.
/// </summary>
public DateTime Timestamp { get; }
public DateTime? Timestamp { get; }

/// <summary>
/// The severity of the issue - more severe issues are presented to the user with more urgency
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ public override void Update()
_dataSources.Update();
_bookmarks.Update();
_outline.Update();
_issues.Update();
}

public QuickFilterViewModel AddQuickFilter()
Expand Down
9 changes: 6 additions & 3 deletions src/Tailviewer/Ui/Controls/SidePanel/Issues/IssueViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Windows.Input;
using System.Windows.Media;
using Metrolib;
using Tailviewer.BusinessLogic;
Expand All @@ -9,18 +10,20 @@ namespace Tailviewer.Ui.Controls.SidePanel.Issues
internal sealed class IssueViewModel
{
private readonly LogFileIssue _issue;
private readonly Action<LogLineIndex> _goto;

public IssueViewModel(LogFileIssue issue)
public IssueViewModel(LogFileIssue issue, Action<LogLineIndex> @goto)
{
_issue = issue;
_goto = @goto;
}

public ICommand GoToCommand => new DelegateCommand2(() => _goto(_issue.Line));
public Geometry Icon => Icons.Alert;
public LogLineIndex Line => _issue.Line;
public string Summary => _issue.Summary;
public DateTime Timestamp => _issue.Timestamp;
public DateTime? Timestamp => _issue.Timestamp;
public Severity Severity => _issue.Severity;

public LogFileIssue Issue => _issue;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
Margin="8,0,0,0" />
</Grid>

<controls:FlatScrollViewer Grid.Row="1">
<controls:FlatScrollViewer Grid.Row="1"
Margin="8">
<ItemsControl ItemsSource="{Binding CurrentIssues.Issues}"
Grid.IsSharedSizeScope="True">
<ItemsControl.ItemTemplate>
Expand All @@ -36,15 +37,23 @@
<ColumnDefinition SharedSizeGroup="Summary" />
</Grid.ColumnDefinitions>

<Viewbox Width="48" Height="48">
<Viewbox Width="20" Height="20">
<Canvas Width="24" Height="24">
<Path Data="{Binding Severity, Converter={StaticResource SeverityToIconConverter}}"
Fill="{Binding Severity, Converter={StaticResource SeverityToBrushConverter}}"/>
<Path
Data="{Binding Severity, Converter={StaticResource SeverityToIconConverter}}"
Fill="{Binding Severity, Converter={StaticResource SeverityToBrushConverter}}" />
</Canvas>
</Viewbox>
<TextBlock Text="{Binding Timestamp}"
Grid.Column="1" />
<TextBlock Margin="4"
VerticalAlignment="Center"
Grid.Column="1">
<Hyperlink Command="{Binding GoToCommand}">
<TextBlock Text="{Binding Timestamp, StringFormat=T}" />
</Hyperlink>
</TextBlock>
<TextBlock Text="{Binding Summary}"
Margin="0,4,4,4"
VerticalAlignment="Center"
Grid.Column="2" />
</Grid>
</DataTemplate>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ private IssuesViewModel CreateViewModel(IDataSource dataSource)
if (plugin == null)
return null;

return new IssuesViewModel(plugin.CreateAnalyser(_services, dataSource.UnfilteredLogFile));
return new IssuesViewModel(plugin.CreateAnalyser(_services, dataSource.UnfilteredLogFile),
_services.Retrieve<INavigationService>());
}

private ILogFileIssuesPlugin FindMatchingPlugin(IDataSource dataSource)
Expand Down
15 changes: 12 additions & 3 deletions src/Tailviewer/Ui/Controls/SidePanel/Issues/IssuesViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading;
using Tailviewer.BusinessLogic;
using Tailviewer.BusinessLogic.Plugins.Issues;

namespace Tailviewer.Ui.Controls.SidePanel.Issues
Expand All @@ -16,14 +17,17 @@ internal sealed class IssuesViewModel
private readonly ObservableCollection<IssueViewModel> _issues;
private readonly Dictionary<LogFileIssue, IssueViewModel> _viewModelsByIssue;
private readonly ILogFileIssueAnalyser _analyser;
private readonly INavigationService _navigationService;
private IReadOnlyList<LogFileIssue> _currentIssues;

public IssuesViewModel(ILogFileIssueAnalyser analyser)
public IssuesViewModel(ILogFileIssueAnalyser analyser,
INavigationService navigationService)
{
_issues = new ObservableCollection<IssueViewModel>();
_viewModelsByIssue = new Dictionary<LogFileIssue, IssueViewModel>();

_analyser = analyser;
_navigationService = navigationService;
_analyser.AddListener(this);
_analyser.Start();
}
Expand Down Expand Up @@ -57,14 +61,19 @@ public void Update()
private void AddNewIssues(IReadOnlyList<LogFileIssue> currentIssues)
{
foreach (var issue in currentIssues)
if (_viewModelsByIssue.ContainsKey(issue))
if (!_viewModelsByIssue.ContainsKey(issue))
{
var viewModel = new IssueViewModel(issue);
var viewModel = new IssueViewModel(issue, GoToIssue);
_viewModelsByIssue.Add(issue, viewModel);
_issues.Add(viewModel);
}
}

private void GoToIssue(LogLineIndex line)
{
_navigationService.NavigateTo(line);
}

private void RemoveOldIssues(IReadOnlyList<LogFileIssue> currentIssues)
{
for (var i = _issues.Count - 1; i >= 0; --i)
Expand Down

0 comments on commit 2cb6370

Please sign in to comment.