Permalink
Browse files

fixing the next filter

  • Loading branch information...
1 parent a4430db commit 6590328f1d95b5a60fb7178102f4df9df550b5a4 @abdullin abdullin committed Feb 28, 2013
Showing with 54 additions and 9 deletions.
  1. +4 −3 Source/Gtd.Console/Filters/AvailableFilter.cs
  2. +50 −6 Source/Gtd.Console/Filters/NextActionFilter.cs
@@ -29,9 +29,10 @@ public IEnumerable<ActionView> FilterActions(ProjectView view)
}
else
{
- var filtered = view.Actions
- .Where(v => !v.Completed)
- .Where(v => !v.Archived)
+ var availableActions = view.Actions
+ .Where(v => !v.Completed)
+ .Where(v => !v.Archived);
+ var filtered = availableActions
.Where(v => v.StartDate <= DateTime.Now);
foreach (var action in filtered)
@@ -7,16 +7,60 @@ namespace Gtd.Shell.Filters
{
public sealed class NextActionFilter : IFilterCriteria
{
- readonly AvailableFilter _filter = new AvailableFilter();
+
public IEnumerable<ActionView> FilterActions(ProjectView view)
{
- var value = _filter.FilterActions(view).FirstOrDefault();
- if (value != null)
- yield return value;
+ if (view.Type == ProjectType.List)
+ {
+ // in list, every available action is next
+ foreach (var actionView in GetAllAvailableActions(view))
+ {
+ yield return actionView;
+ }
+ }
+ else if (view.Type == ProjectType.Parallel)
+ {
+ // in parallel, first available action is next
+ var filtered = GetAllAvailableActions(view).FirstOrDefault();
+
+ if (filtered != null)
+ {
+ yield return filtered;
+ }
+ }
+ else
+ {
+ // in sequential, first available action is next (unless it's blocked)
+ var filtered = view.Actions
+ .Where(v => !v.Completed)
+ .Where(v => !v.Archived)
+ .FirstOrDefault();
+
+ if (filtered != null && filtered.StartDate <= DateTime.UtcNow)
+ yield return filtered;
+
+ }
+
+ }
+
+ static IEnumerable<ActionView> GetAllAvailableActions(ProjectView view)
+ {
+ return view.Actions
+ .Where(v => !v.Completed)
+ .Where(v => !v.Archived)
+ .Where(v => v.StartDate <= DateTime.Now);
+ }
+
+ public string Title
+ {
+ get { return "Next"; }
+ }
+
+ public string Description
+ {
+ get { return "next thing to do in each eligible project"; }
}
- public string Title { get { return "Next"; } }
- public string Description { get { return "next thing to do in each eligible project"; } }
public string FormatActionCount(int actionCount)
{
switch (actionCount)

0 comments on commit 6590328

Please sign in to comment.