diff --git a/assets/view.png b/assets/reports.png similarity index 100% rename from assets/view.png rename to assets/reports.png diff --git a/assets/svg/view.svg b/assets/svg/reports.svg similarity index 100% rename from assets/svg/view.svg rename to assets/svg/reports.svg diff --git a/src/Main.cs b/src/Main.cs index 10b4c38..670e582 100644 --- a/src/Main.cs +++ b/src/Main.cs @@ -88,7 +88,7 @@ public async Task> QueryAsync(Query query, CancellationToken token) Settings.StopCommand => await this._togglTrack.RequestStopEntry(token, query), Settings.DeleteCommand => await this._togglTrack.RequestDeleteEntry(token), Settings.ContinueCommand => await this._togglTrack.RequestContinueEntry(token, query), - Settings.ViewCommand => await this._togglTrack.RequestViewReports(token, query), + Settings.ReportsCommand => await this._togglTrack.RequestViewReports(token, query), _ => (await this._togglTrack.GetDefaultHotKeys()) .FindAll(result => { diff --git a/src/Settings.cs b/src/Settings.cs index 0bc8061..0539b28 100644 --- a/src/Settings.cs +++ b/src/Settings.cs @@ -13,23 +13,23 @@ public class Settings internal const string StopCommand = "stop"; internal const string DeleteCommand = "delete"; internal const string ContinueCommand = "continue"; - internal const string ViewCommand = "view"; + internal const string ReportsCommand = "reports"; internal const string BrowserCommand = "browser"; internal const string RefreshCommand = "refresh"; internal const string EditProjectFlag = "-p"; internal const string TimeSpanFlag = "-t"; - internal enum ViewSpanKeys + internal enum ReportsSpanKeys { Day, Week, Month, Year, } - internal static readonly List ViewSpanArguments = new List + internal static readonly List ReportsSpanArguments = new List { - new ViewSpanCommandArgument + new ReportsSpanCommandArgument { Argument = "day", Interpolation = "today", @@ -38,7 +38,7 @@ internal enum ViewSpanKeys Start = now => now, End = now => now, }, - new ViewSpanCommandArgument + new ReportsSpanCommandArgument { Argument = "week", Interpolation = "this week", @@ -48,7 +48,7 @@ internal enum ViewSpanKeys // Sunday of the current week End = now => now.AddDays(-(int)now.DayOfWeek + 7), }, - new ViewSpanCommandArgument + new ReportsSpanCommandArgument { Argument = "month", Interpolation = "this month", @@ -58,7 +58,7 @@ internal enum ViewSpanKeys // Last day of the current month End = now => new DateTimeOffset(now.Year, now.Month, DateTime.DaysInMonth(now.Year, now.Month), 0, 0, 0, now.Offset), }, - new ViewSpanCommandArgument + new ReportsSpanCommandArgument { Argument = "year", Interpolation = "this year", @@ -70,39 +70,39 @@ internal enum ViewSpanKeys }, }; - public enum ViewGroupingKeys + public enum ReportsGroupingKeys { Projects, Clients, Entries, } - private const string ViewGroupingProjectsArgument = "projects"; - private const string ViewGroupingClientsArgument = "clients"; - private const string ViewGroupingEntriesArgument = "entries"; - internal static readonly List ViewGroupingArguments = new List + private const string ReportsGroupingProjectsArgument = "projects"; + private const string ReportsGroupingClientsArgument = "clients"; + private const string ReportsGroupingEntriesArgument = "entries"; + internal static readonly List ReportsGroupingArguments = new List { - new ViewGroupingCommandArgument + new ReportsGroupingCommandArgument { - Argument = Settings.ViewGroupingProjectsArgument, + Argument = Settings.ReportsGroupingProjectsArgument, Interpolation = "View tracked time grouped by project", Score = 300, - Grouping = Settings.ViewGroupingKeys.Projects, + Grouping = Settings.ReportsGroupingKeys.Projects, SubArgument = null, }, - new ViewGroupingCommandArgument + new ReportsGroupingCommandArgument { - Argument = Settings.ViewGroupingClientsArgument, + Argument = Settings.ReportsGroupingClientsArgument, Interpolation = "View tracked time grouped by client", Score = 200, - Grouping = Settings.ViewGroupingKeys.Clients, - SubArgument = Settings.ViewGroupingProjectsArgument, + Grouping = Settings.ReportsGroupingKeys.Clients, + SubArgument = Settings.ReportsGroupingProjectsArgument, }, - new ViewGroupingCommandArgument + new ReportsGroupingCommandArgument { - Argument = Settings.ViewGroupingEntriesArgument, + Argument = Settings.ReportsGroupingEntriesArgument, Interpolation = "View tracked time entries", Score = 100, - Grouping = Settings.ViewGroupingKeys.Entries, + Grouping = Settings.ReportsGroupingKeys.Entries, SubArgument = null, }, }; @@ -122,7 +122,7 @@ public class CommandArgument #nullable enable } - public class ViewSpanCommandArgument : CommandArgument + public class ReportsSpanCommandArgument : CommandArgument { #nullable disable public Func Start { get; init; } @@ -130,10 +130,10 @@ public class ViewSpanCommandArgument : CommandArgument #nullable enable } - public class ViewGroupingCommandArgument : CommandArgument + public class ReportsGroupingCommandArgument : CommandArgument { #nullable disable - public Settings.ViewGroupingKeys Grouping { get; init; } + public Settings.ReportsGroupingKeys Grouping { get; init; } public string SubArgument { get; init; } #nullable enable } diff --git a/src/Toggl/Client.cs b/src/Toggl/Client.cs index 126a3ca..98b27e7 100644 --- a/src/Toggl/Client.cs +++ b/src/Toggl/Client.cs @@ -122,13 +122,13 @@ public void UpdateToken(string token) * Reports API */ - public async Task GetSummaryTimeEntries(long workspaceId, long userId, Settings.ViewGroupingKeys reportGrouping, DateTimeOffset start, DateTimeOffset? end) + public async Task GetSummaryTimeEntries(long workspaceId, long userId, Settings.ReportsGroupingKeys reportGrouping, DateTimeOffset start, DateTimeOffset? end) { (string grouping, string sub_grouping) = (reportGrouping) switch { - Settings.ViewGroupingKeys.Projects => ("projects", "time_entries"), - Settings.ViewGroupingKeys.Clients => ("clients", "projects"), - Settings.ViewGroupingKeys.Entries => ("projects", "time_entries"), + Settings.ReportsGroupingKeys.Projects => ("projects", "time_entries"), + Settings.ReportsGroupingKeys.Clients => ("clients", "projects"), + Settings.ReportsGroupingKeys.Entries => ("projects", "time_entries"), _ => ("projects", "time_entries"), }; diff --git a/src/TogglTrack.cs b/src/TogglTrack.cs index 60bf5ab..82e052a 100644 --- a/src/TogglTrack.cs +++ b/src/TogglTrack.cs @@ -145,7 +145,7 @@ internal TogglTrack(PluginInitContext context, Settings settings) } } - private async ValueTask _GetSummaryTimeEntries(long workspaceId, long userId, Settings.ViewGroupingKeys reportGrouping, DateTimeOffset start, DateTimeOffset? end, bool force = false) + private async ValueTask _GetSummaryTimeEntries(long workspaceId, long userId, Settings.ReportsGroupingKeys reportGrouping, DateTimeOffset start, DateTimeOffset? end, bool force = false) { string cacheKey = $"SummaryTimeEntries{workspaceId}{userId}{(int)reportGrouping}{start.ToString("yyyy-MM-dd")}{end?.ToString("yyyy-MM-dd")}"; @@ -336,14 +336,14 @@ internal async ValueTask> GetDefaultHotKeys() }, new Result { - Title = Settings.ViewCommand, + Title = Settings.ReportsCommand, SubTitle = "View tracked time reports", - IcoPath = "view.png", - AutoCompleteText = $"{this._context.CurrentPluginMetadata.ActionKeyword} {Settings.ViewCommand} ", + IcoPath = "reports.png", + AutoCompleteText = $"{this._context.CurrentPluginMetadata.ActionKeyword} {Settings.ReportsCommand} ", Score = 5, Action = c => { - this._context.API.ChangeQuery($"{this._context.CurrentPluginMetadata.ActionKeyword} {Settings.ViewCommand} "); + this._context.API.ChangeQuery($"{this._context.CurrentPluginMetadata.ActionKeyword} {Settings.ReportsCommand} "); return false; }, }, @@ -1446,20 +1446,20 @@ internal async ValueTask> RequestViewReports(CancellationToken toke * Report span selection --- tgl view [day | week | month | year] */ - if (query.SearchTerms.Length == ArgumentIndices.Span || !Settings.ViewSpanArguments.Exists(span => span.Argument == query.SearchTerms[ArgumentIndices.Span])) + if (query.SearchTerms.Length == ArgumentIndices.Span || !Settings.ReportsSpanArguments.Exists(span => span.Argument == query.SearchTerms[ArgumentIndices.Span])) { - var spans = Settings.ViewSpanArguments.ConvertAll(span => + var spans = Settings.ReportsSpanArguments.ConvertAll(span => { return new Result { Title = span.Argument, SubTitle = $"View tracked time report for {span.Interpolation}", - IcoPath = "view.png", - AutoCompleteText = $"{query.ActionKeyword} {Settings.ViewCommand} {span.Argument} ", + IcoPath = "reports.png", + AutoCompleteText = $"{query.ActionKeyword} {Settings.ReportsCommand} {span.Argument} ", Score = span.Score, Action = c => { - this._context.API.ChangeQuery($"{query.ActionKeyword} {Settings.ViewCommand} {span.Argument} ", true); + this._context.API.ChangeQuery($"{query.ActionKeyword} {Settings.ReportsCommand} {span.Argument} ", true); return false; }, }; @@ -1477,20 +1477,20 @@ internal async ValueTask> RequestViewReports(CancellationToken toke /* * Report groupinging selection --- tgl view [duration] [projects | clients | entries] */ - if (query.SearchTerms.Length == ArgumentIndices.Grouping || !Settings.ViewGroupingArguments.Exists(grouping => grouping.Argument == query.SearchTerms[ArgumentIndices.Grouping])) + if (query.SearchTerms.Length == ArgumentIndices.Grouping || !Settings.ReportsGroupingArguments.Exists(grouping => grouping.Argument == query.SearchTerms[ArgumentIndices.Grouping])) { - var groupings = Settings.ViewGroupingArguments.ConvertAll(grouping => + var groupings = Settings.ReportsGroupingArguments.ConvertAll(grouping => { return new Result { Title = grouping.Argument, SubTitle = grouping.Interpolation, - IcoPath = "view.png", - AutoCompleteText = $"{query.ActionKeyword} {Settings.ViewCommand} {query.SearchTerms[1]} {grouping.Argument} ", + IcoPath = "reports.png", + AutoCompleteText = $"{query.ActionKeyword} {Settings.ReportsCommand} {query.SearchTerms[1]} {grouping.Argument} ", Score = grouping.Score, Action = c => { - this._context.API.ChangeQuery($"{query.ActionKeyword} {Settings.ViewCommand} {query.SearchTerms[1]} {grouping.Argument} ", true); + this._context.API.ChangeQuery($"{query.ActionKeyword} {Settings.ReportsCommand} {query.SearchTerms[1]} {grouping.Argument} ", true); return false; }, }; @@ -1508,8 +1508,8 @@ internal async ValueTask> RequestViewReports(CancellationToken toke string spanArgument = query.SearchTerms[ArgumentIndices.Span]; string groupingArgument = query.SearchTerms[ArgumentIndices.Grouping]; - var spanConfiguration = Settings.ViewSpanArguments.Find(span => span.Argument == spanArgument); - var groupingConfiguration = Settings.ViewGroupingArguments.Find(grouping => grouping.Argument == groupingArgument); + var spanConfiguration = Settings.ReportsSpanArguments.Find(span => span.Argument == spanArgument); + var groupingConfiguration = Settings.ReportsGroupingArguments.Find(grouping => grouping.Argument == groupingArgument); if ((spanConfiguration is null) || (groupingConfiguration is null)) { @@ -1536,7 +1536,7 @@ internal async ValueTask> RequestViewReports(CancellationToken toke new Result { Title = $"{total.Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Hour)} tracked {spanConfiguration.Interpolation} ({(int)total.TotalHours}:{total.ToString(@"mm\:ss")})", - IcoPath = "view.png", + IcoPath = "reports.png", AutoCompleteText = $"{query.ActionKeyword} {query.Search} ", Score = (int)total.TotalSeconds + 1000, }, @@ -1549,7 +1549,7 @@ internal async ValueTask> RequestViewReports(CancellationToken toke switch (groupingConfiguration.Grouping) { - case (Settings.ViewGroupingKeys.Projects): + case (Settings.ReportsGroupingKeys.Projects): { if (runningTimeEntry is not null) { @@ -1617,14 +1617,14 @@ internal async ValueTask> RequestViewReports(CancellationToken toke Title = project?.name ?? "No Project", SubTitle = $"{((project?.client_id is not null) ? $"{me.clients?.Find(client => client.id == project.client_id)?.name} | " : string.Empty)}{elapsed.Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Hour)} ({(int)elapsed.TotalHours}:{elapsed.ToString(@"mm\:ss")})", IcoPath = (project?.color is not null) - ? new ColourIcon(this._context, project.color, "view.png").GetColourIcon() - : "view.png", - AutoCompleteText = $"{query.ActionKeyword} {Settings.ViewCommand} {spanConfiguration.Argument} {groupingConfiguration.Argument} ", + ? new ColourIcon(this._context, project.color, "reports.png").GetColourIcon() + : "reports.png", + AutoCompleteText = $"{query.ActionKeyword} {Settings.ReportsCommand} {spanConfiguration.Argument} {groupingConfiguration.Argument} ", Score = (int)group.seconds, Action = c => { this._selectedProjectId = project?.id; - this._context.API.ChangeQuery($"{query.ActionKeyword} {Settings.ViewCommand} {spanConfiguration.Argument} {groupingConfiguration.Argument} {project?.name?.Kebaberize() ?? "No Project"} ", true); + this._context.API.ChangeQuery($"{query.ActionKeyword} {Settings.ReportsCommand} {spanConfiguration.Argument} {groupingConfiguration.Argument} {project?.name?.Kebaberize() ?? "No Project"} ", true); return false; } }; @@ -1659,9 +1659,9 @@ internal async ValueTask> RequestViewReports(CancellationToken toke Title = (string.IsNullOrEmpty(subGroup.title)) ? "(no description)" : subGroup.title, SubTitle = $"{elapsed.Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Hour)} ({(int)elapsed.TotalHours}:{elapsed.ToString(@"mm\:ss")})", IcoPath = (project?.color is not null) - ? new ColourIcon(this._context, project.color, "view.png").GetColourIcon() - : "view.png", - AutoCompleteText = $"{query.ActionKeyword} {Settings.ViewCommand} {spanConfiguration.Argument} {groupingConfiguration.Argument} {project?.name?.Kebaberize() ?? "no-project"} {((string.IsNullOrEmpty(subGroup.title)) ? "(no description)" : subGroup.title)}", + ? new ColourIcon(this._context, project.color, "reports.png").GetColourIcon() + : "reports.png", + AutoCompleteText = $"{query.ActionKeyword} {Settings.ReportsCommand} {spanConfiguration.Argument} {groupingConfiguration.Argument} {project?.name?.Kebaberize() ?? "no-project"} {((string.IsNullOrEmpty(subGroup.title)) ? "(no description)" : subGroup.title)}", Score = (int)elapsed.TotalSeconds, Action = c => { @@ -1677,7 +1677,7 @@ internal async ValueTask> RequestViewReports(CancellationToken toke { Title = $"{subTotal.Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Hour)} tracked {spanConfiguration.Interpolation} ({(int)subTotal.TotalHours}:{subTotal.ToString(@"mm\:ss")})", SubTitle = projectName, - IcoPath = "view.png", + IcoPath = "reports.png", AutoCompleteText = $"{query.ActionKeyword} {query.Search} ", Score = (int)subTotal.TotalSeconds + 1000, }); @@ -1690,7 +1690,7 @@ internal async ValueTask> RequestViewReports(CancellationToken toke return this._context.API.FuzzySearch(subNameQuery, result.Title).Score > 0; }); } - case (Settings.ViewGroupingKeys.Clients): + case (Settings.ReportsGroupingKeys.Clients): { if (runningTimeEntry is not null) { @@ -1766,14 +1766,14 @@ internal async ValueTask> RequestViewReports(CancellationToken toke Title = client?.name ?? "No Client", SubTitle = $"{elapsed.Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Hour)} ({(int)elapsed.TotalHours}:{elapsed.ToString(@"mm\:ss")})", IcoPath = (highestProject?.color is not null) - ? new ColourIcon(this._context, highestProject.color, "view.png").GetColourIcon() - : "view.png", - AutoCompleteText = $"{query.ActionKeyword} {Settings.ViewCommand} {spanConfiguration.Argument} {groupingConfiguration.Argument} ", + ? new ColourIcon(this._context, highestProject.color, "reports.png").GetColourIcon() + : "reports.png", + AutoCompleteText = $"{query.ActionKeyword} {Settings.ReportsCommand} {spanConfiguration.Argument} {groupingConfiguration.Argument} ", Score = (int)group.seconds, Action = c => { this._selectedClientId = client?.id; - this._context.API.ChangeQuery($"{query.ActionKeyword} {Settings.ViewCommand} {spanConfiguration.Argument} {groupingConfiguration.Argument} {client?.name?.Kebaberize() ?? "No Client"} ", true); + this._context.API.ChangeQuery($"{query.ActionKeyword} {Settings.ReportsCommand} {spanConfiguration.Argument} {groupingConfiguration.Argument} {client?.name?.Kebaberize() ?? "No Client"} ", true); return false; } }; @@ -1801,9 +1801,9 @@ internal async ValueTask> RequestViewReports(CancellationToken toke Title = project?.name ?? "No Project", SubTitle = $"{((client?.id is not null) ? $"{client?.name} | " : string.Empty)}{elapsed.Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Hour)} ({(int)elapsed.TotalHours}:{elapsed.ToString(@"mm\:ss")})", IcoPath = (project?.color is not null) - ? new ColourIcon(this._context, project.color, "view.png").GetColourIcon() - : "view.png", - AutoCompleteText = $"{query.ActionKeyword} {Settings.ViewCommand} {spanConfiguration.Argument} {groupingConfiguration.Argument} {client?.name?.Kebaberize() ?? "No Client"} ", + ? new ColourIcon(this._context, project.color, "reports.png").GetColourIcon() + : "reports.png", + AutoCompleteText = $"{query.ActionKeyword} {Settings.ReportsCommand} {spanConfiguration.Argument} {groupingConfiguration.Argument} {client?.name?.Kebaberize() ?? "No Client"} ", Score = (int)subGroup.seconds, Action = c => { @@ -1815,7 +1815,7 @@ internal async ValueTask> RequestViewReports(CancellationToken toke throw new Exception("Invalid ViewGroupingCommandArgument configuration: Missing 'SubArgument' field."); } - this._context.API.ChangeQuery($"{query.ActionKeyword} {Settings.ViewCommand} {spanConfiguration.Argument} {groupingConfiguration.SubArgument} {project?.name?.Kebaberize() ?? "No Project"} ", true); + this._context.API.ChangeQuery($"{query.ActionKeyword} {Settings.ReportsCommand} {spanConfiguration.Argument} {groupingConfiguration.SubArgument} {project?.name?.Kebaberize() ?? "No Project"} ", true); return false; } }; @@ -1826,7 +1826,7 @@ internal async ValueTask> RequestViewReports(CancellationToken toke { Title = $"{subTotal.Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Hour)} tracked {spanConfiguration.Interpolation} ({(int)subTotal.TotalHours}:{subTotal.ToString(@"mm\:ss")})", SubTitle = client?.name ?? "No Client", - IcoPath = "view.png", + IcoPath = "reports.png", AutoCompleteText = $"{query.ActionKeyword} {query.Search} ", Score = (int)subTotal.TotalSeconds + 1000, }); @@ -1839,7 +1839,7 @@ internal async ValueTask> RequestViewReports(CancellationToken toke return this._context.API.FuzzySearch(subNameQuery, result.Title).Score > 0; }); } - case (Settings.ViewGroupingKeys.Entries): + case (Settings.ReportsGroupingKeys.Entries): { if (runningTimeEntry is not null) { @@ -1921,9 +1921,9 @@ internal async ValueTask> RequestViewReports(CancellationToken toke Title = (string.IsNullOrEmpty(subGroup.title)) ? "(no description)" : subGroup.title, SubTitle = $"{projectName} | {elapsed.Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Hour)} ({(int)elapsed.TotalHours}:{elapsed.ToString(@"mm\:ss")})", IcoPath = (project?.color is not null) - ? new ColourIcon(this._context, project.color, "view.png").GetColourIcon() - : "view.png", - AutoCompleteText = $"{query.ActionKeyword} {Settings.ViewCommand} {spanConfiguration.Argument} {groupingConfiguration.Argument} {((string.IsNullOrEmpty(subGroup.title)) ? "(no description)" : subGroup.title)}", + ? new ColourIcon(this._context, project.color, "reports.png").GetColourIcon() + : "reports.png", + AutoCompleteText = $"{query.ActionKeyword} {Settings.ReportsCommand} {spanConfiguration.Argument} {groupingConfiguration.Argument} {((string.IsNullOrEmpty(subGroup.title)) ? "(no description)" : subGroup.title)}", Score = (int)elapsed.TotalSeconds, Action = c => {