Skip to content

Commit

Permalink
Issue 279
Browse files Browse the repository at this point in the history
Implementation completed except for option to turn on/off
  • Loading branch information
sckaushal committed Aug 1, 2016
1 parent c2ab271 commit 672d7fb
Show file tree
Hide file tree
Showing 10 changed files with 513 additions and 157 deletions.
3 changes: 3 additions & 0 deletions Client/Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@
<Compile Include="Controls\SetDueDateDialog.xaml.cs">
<DependentUpon>SetDueDateDialog.xaml</DependentUpon>
</Compile>
<Compile Include="Converters\ActiveFilterToStatusConvertor.cs" />
<Compile Include="Converters\SortTypeToDescriptionConvertor.cs" />
<Compile Include="ExceptionExtensions.cs" />
<Compile Include="GroupConverter.cs" />
<Compile Include="PortableSettingsProvider.cs" />
Expand Down Expand Up @@ -127,6 +129,7 @@
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<DependentUpon>User.settings</DependentUpon>
</Compile>
<Compile Include="Utilities\EnumExtensions.cs" />
<Compile Include="WindowLocation.cs" />
<Page Include="Controls\DeleteConfirmationDialog.xaml">
<SubType>Designer</SubType>
Expand Down
24 changes: 21 additions & 3 deletions Client/Controls/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Client"
xmlns:convertors="clr-namespace:Client.Converters"
Loaded="Window_Loaded"
Title="todotxt.net"
mc:Ignorable="d"
Expand Down Expand Up @@ -100,6 +101,8 @@
</DataTrigger>
</Style.Triggers>
</Style>
<convertors:ActiveFilterToStatusConvertor x:Key="filterToStatusConv"></convertors:ActiveFilterToStatusConvertor>
<convertors:SortTypeToDescriptionConvertor x:Key="sortTypeToDescConv"></convertors:SortTypeToDescriptionConvertor>
</Window.Resources>
<Window.CommandBindings>
<!-- File menu commands -->
Expand Down Expand Up @@ -378,11 +381,26 @@
<WebBrowser Grid.Row="2" Height="Auto" HorizontalAlignment="Stretch" Margin="0,0,0,0" Name="webBrowser1" VerticalAlignment="Stretch" Width="Auto" Visibility="Hidden" Grid.ColumnSpan="2" />
<Button Grid.Row="0" Grid.RowSpan="2" Content="Print" Height="23" HorizontalAlignment="Left" Margin="0,23,207,0" Name="btnPrint" VerticalAlignment="Top" Width="92" Visibility="Hidden" Click="btnPrint_Click" />
<Button Grid.Row="0" Grid.RowSpan="2" Content="Cancel" Height="23" HorizontalAlignment="Left" Margin="97,23,0,0" Name="btnCancelPrint" VerticalAlignment="Top" Width="92" Visibility="Hidden" Click="btnCancelPrint_Click" />
<StatusBar Grid.Row="3">
<TextBlock Name="lblFilterStatus" Text="{Binding FilterDescription, Mode=OneWay}" VerticalAlignment="Bottom" ></TextBlock>
<StatusBar Grid.Row="3" Name="sbTaskSummary">
<TextBlock Name="lblFilterStatus" Text="{Binding ActiveFilterNumber, Mode=OneWay, Converter= {StaticResource filterToStatusConv}}" VerticalAlignment="Bottom"></TextBlock>
<Separator></Separator>
<TextBlock Text="Sort:"/>
<TextBlock Text="{Binding SortType, Mode=OneWay}"/>
<TextBlock Text="{Binding SortType, Mode=OneWay, Converter={StaticResource sortTypeToDescConv}}"/>
<Separator></Separator>
<TextBlock Text="Tasks:"/>
<TextBlock Text="{Binding FilteredTasks, Mode=OneWay}"/>
<TextBlock Text="of"/>
<TextBlock Text="{Binding TotalTasks, Mode=OneWay}"/>
<Separator></Separator>
<TextBlock Text="Incomplete:"/>
<TextBlock Text="{Binding IncompleteTasks, Mode=OneWay}"/>
<Separator></Separator>
<TextBlock Text="Due Today:"/>
<TextBlock Text="{Binding TasksDueToday, Mode=OneWay}"/>
<Separator></Separator>
<TextBlock Text="Overdue:"/>
<TextBlock Text="{Binding TasksOverdue, Mode=OneWay}"/>

</StatusBar>

</Grid>
Expand Down
23 changes: 23 additions & 0 deletions Client/Converters/ActiveFilterToStatusConvertor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows.Data;

namespace Client.Converters
{
public class ActiveFilterToStatusConvertor : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return ((int)value > 0) ? String.Format("Filter #:{0}", value) : "Filter: None";

}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
23 changes: 23 additions & 0 deletions Client/Converters/SortTypeToDescriptionConvertor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows.Data;
using static Client.Utilities.EnumExtensions;

namespace Client.Converters
{
class SortTypeToDescriptionConvertor : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return ((SortType)value).GetDescription();
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
164 changes: 155 additions & 9 deletions Client/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class MainWindowViewModel : INotifyPropertyChanged
private List<CollectionViewGroup> _viewGroups;
private int _nextGroupAtTaskNumber;
private List<Task> _selectedTasks;

public TaskList TaskList { get; set; }
public Help HelpPage { get; private set; }
public SortType SortType
Expand All @@ -57,23 +57,118 @@ public SortType SortType
}
}

private String _filterDescription = String.Empty;
public String FilterDescription
private int _activeFilterNumber = -1;
public int ActiveFilterNumber
{
get
{
return _filterDescription;
return _activeFilterNumber;
}
private set
{
if (!_filterDescription.Equals(value))
if (_activeFilterNumber != value)
{
_activeFilterNumber = value;
RaiseProperyChanged(nameof(ActiveFilterNumber));
}
}
}

private int totalTasks = 0;
public int TotalTasks
{
get
{
return totalTasks;
}

set
{
if (totalTasks != value)
{
totalTasks = value;
RaiseProperyChanged(nameof(TotalTasks));
}
}
}

private int filteredTasks = 0;
public int FilteredTasks
{
get
{
return filteredTasks;
}

set
{
if (filteredTasks != value)
{
filteredTasks = value;
RaiseProperyChanged(nameof(FilteredTasks));
}
}
}

private int incompleteTasks = 0;
public int IncompleteTasks
{
get
{
return incompleteTasks;
}

set
{
if (incompleteTasks != value)
{
incompleteTasks = value;
RaiseProperyChanged(nameof(IncompleteTasks));
}
}
}

private int tasksDueToday = 0;

public int TasksDueToday
{
get
{
return tasksDueToday;
}

set
{
if (tasksDueToday != value)
{
tasksDueToday = value;
RaiseProperyChanged(nameof(TasksDueToday));
}
}
}

public int TasksOverdue
{
get
{
return tasksOverdue;
}

set
{
if (tasksOverdue != value)
{
_filterDescription = value;
RaiseProperyChanged(nameof(FilterDescription));
tasksOverdue = value;
RaiseProperyChanged(nameof(TasksOverdue));
}
}
}

private int tasksOverdue = 0;




public event PropertyChangedEventHandler PropertyChanged;

public MainWindowViewModel(MainWindow window)
Expand All @@ -87,7 +182,7 @@ public MainWindowViewModel(MainWindow window)

SortType = (SortType)User.Default.CurrentSort;

FilterDescription = "Filter: None";
ActiveFilterNumber=0;

if (!string.IsNullOrEmpty(User.Default.FilePath))
{
Expand Down Expand Up @@ -215,6 +310,13 @@ public void LoadTasks(string filePath)
try
{
TaskList = new TaskList(filePath, User.Default.PreserveWhiteSpace);
if (TaskList != null)
{
// The first time the task list has been modified before we got a chance to hook to the modified event
// so call the method and then hook to the Modified event
TaskList.Modified += TaskList_Modified;
TaskList_Modified(TaskList, EventArgs.Empty);
}
User.Default.FilePath = filePath;
User.Default.Save();
EnableFileChangeObserver();
Expand All @@ -226,6 +328,11 @@ public void LoadTasks(string filePath)
}
}

private void TaskList_Modified(object sender, EventArgs e)
{
this.TotalTasks = TaskList.Tasks.Count;
}

public void ReloadFile()
{
Log.Debug("Reloading file");
Expand Down Expand Up @@ -294,8 +401,12 @@ public void UpdateDisplayedTasks()
{
_myView.GroupDescriptions.Clear();
}

var selectedTasksList = sortedTaskList.ToList();
_window.lbTasks.ItemsSource = sortedTaskList;
_window.lbTasks.UpdateLayout();
//sortedTaskList.
UpdateSummary(selectedTasksList);
}
catch (Exception ex)
{
Expand All @@ -306,6 +417,41 @@ public void UpdateDisplayedTasks()
_window.filterMenu.FontWeight = User.Default.FilterText.Length == 0 ? FontWeights.Normal : FontWeights.Bold;
}

protected void UpdateSummary(List<Task> selectedTasksList)
{
FilteredTasks = selectedTasksList.Count;

int fTask = 0, incompTask = 0, dueTodayTask = 0, overdueTask = 0;
foreach (Task t in selectedTasksList)
{
if (!t.Completed)
{
incompTask++;


if (!String.IsNullOrEmpty(t.DueDate))
{
DateTime dueDt;

if (DateTime.TryParseExact(t.DueDate, "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out dueDt))
{
if (dueDt.Date == DateTime.Today.Date)
{
dueTodayTask++;
}
else if (dueDt.Date < DateTime.Today)
{
overdueTask++;
}
}
}
}
}
IncompleteTasks = incompTask;
TasksOverdue = overdueTask;
TasksDueToday = dueTodayTask;
}

/// <summary>
/// Returns true if a single task is selected in the task list.
/// </summary>
Expand Down Expand Up @@ -599,7 +745,7 @@ private void ApplyFilterPreset(int filterPresetNumber)

User.Default.Save();

FilterDescription = String.Format("Filter #{0}", filterPresetNumber);
ActiveFilterNumber = filterPresetNumber;
}
#endregion

Expand Down
11 changes: 9 additions & 2 deletions Client/SortType.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
namespace Client
using System.ComponentModel;

namespace Client
{
// @sckaushal: Issue 279: Added description attribute to display in status
public enum SortType
{

Alphabetical,
Completed,
Context,
[Description("Due Date")]
DueDate,
Priority,
Project,
[Description("Order in file")]
None,
Created
[Description("Creation Date")]
Created
}
}
Loading

0 comments on commit 672d7fb

Please sign in to comment.