Skip to content

Commit

Permalink
feat(view): 🚧 implement report grouping selection
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesNZL committed May 15, 2023
1 parent 742e59d commit d8e2ca2
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 14 deletions.
26 changes: 22 additions & 4 deletions src/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,40 @@ public class Settings
new CommandArgument
{
Argument = "day",
Interpolation = "today's",
Interpolation = "today",
},
new CommandArgument
{
Argument = "week",
Interpolation = "this week's",
Interpolation = "this week",
},
new CommandArgument
{
Argument = "month",
Interpolation = "this month's",
Interpolation = "this month",
},
new CommandArgument
{
Argument = "year",
Interpolation = "this year's",
Interpolation = "this year",
},
};
internal static readonly List<CommandArgument> ViewGroupingArguments = new List<CommandArgument>
{
new CommandArgument
{
Argument = "entries",
Interpolation = "View tracked time entries",
},
new CommandArgument
{
Argument = "projects",
Interpolation = "View tracked time grouped by project",
},
new CommandArgument
{
Argument = "clients",
Interpolation = "View tracked time grouped by client",
},
};

Expand Down
44 changes: 34 additions & 10 deletions src/TogglTrack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1341,12 +1341,12 @@ internal async ValueTask<List<Result>> RequestViewReports(CancellationToken toke
*/
if (query.SearchTerms.Length == 1 || !Settings.ViewDurationArguments.Exists(duration => duration.Argument == query.SearchTerms[1]))
{
var results = Settings.ViewDurationArguments.ConvertAll(duration =>
var durations = Settings.ViewDurationArguments.ConvertAll(duration =>
{
return new Result
{
Title = duration.Argument,
SubTitle = $"View {duration.Interpolation} tracked time report",
SubTitle = $"View tracked time report for {duration.Interpolation}",
IcoPath = "view.png",
AutoCompleteText = $"{query.ActionKeyword} {Settings.ViewCommand} {duration.Argument} ",
Score = Settings.ViewDurationArguments.Count - Settings.ViewDurationArguments.IndexOf(duration),
Expand All @@ -1359,21 +1359,45 @@ internal async ValueTask<List<Result>> RequestViewReports(CancellationToken toke
});

return (string.IsNullOrWhiteSpace(query.SecondToEndSearch))
? results
: results.FindAll(result =>
? durations
: durations.FindAll(result =>
{
return this._context.API.FuzzySearch(query.SecondToEndSearch, result.Title).Score > 0;
});
}

var reports = new List<Result>();

return (string.IsNullOrWhiteSpace(query.SecondToEndSearch))
? reports
: reports.FindAll(result =>
/*
* Report groupinging selection --- tgl view [duration] [entries | projects | clients]
"View tracked time report by Project"
*/
if (query.SearchTerms.Length == 2 || !Settings.ViewGroupingArguments.Exists(grouping => grouping.Argument == query.SearchTerms[2]))
{
var groupings = Settings.ViewGroupingArguments.ConvertAll(grouping =>
{
return this._context.API.FuzzySearch(query.SecondToEndSearch, result.Title).Score > 0;
return new Result
{
Title = grouping.Argument,
SubTitle = grouping.Interpolation,
IcoPath = "view.png",
AutoCompleteText = $"{query.ActionKeyword} {Settings.ViewCommand} {query.SearchTerms[1]} {grouping.Argument} ",
Score = Settings.ViewGroupingArguments.Count - Settings.ViewGroupingArguments.IndexOf(grouping),
Action = c =>
{
this._context.API.ChangeQuery($"{query.ActionKeyword} {Settings.ViewCommand} {query.SearchTerms[1]} {grouping.Argument} ", true);
return false;
},
};
});

return (string.IsNullOrWhiteSpace(string.Join(" ", query.SearchTerms.Skip(2))))
? groupings
: groupings.FindAll(result =>
{
return this._context.API.FuzzySearch(string.Join(" ", query.SearchTerms.Skip(2)), result.Title).Score > 0;
});
}

return new List<Result>();
}
}
}

0 comments on commit d8e2ca2

Please sign in to comment.