Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .claude/settings.local.json
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be checked in

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"permissions": {
"allow": [
"Bash(dotnet publish:*)",
"WebFetch(domain:github.com)",
"WebFetch(domain:raw.githubusercontent.com)",
"mcp__ide__getDiagnostics"
]
}
}
10 changes: 10 additions & 0 deletions Clockify/AvailableOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Collections.Generic;

namespace Clockify;

public class AvailableOptions
{
public List<string> WorkspaceNames { get; set; } = [];
public List<string> ProjectNames { get; set; } = [];
public List<string> TaskNames { get; set; } = [];
}
28 changes: 25 additions & 3 deletions Clockify/ClockifyService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,17 @@ public class ClockifyService(Logger logger)
private List<string> _tags = [];
private TaskDtoV1 _task = new();

private List<string> _allWorkspaceNames = [];
private List<string> _allProjectNames = [];
private List<string> _allTaskNames = [];

public bool IsValid => _clockifyClient is not null
&& !string.IsNullOrWhiteSpace(_settings.WorkspaceName)
&& _workspace is not null;

public AvailableOptions GetAvailableOptions() =>
new() { WorkspaceNames = _allWorkspaceNames, ProjectNames = _allProjectNames, TaskNames = _allTaskNames };

public async Task<bool> ToggleTimerAsync()
{
logger.LogInfo("Toggling timer...");
Expand Down Expand Up @@ -211,24 +218,39 @@ private async Task ReloadCacheAsync()
_project = null;
_tags = [];
_task = null;

_allWorkspaceNames = [];
_allProjectNames = [];
_allTaskNames = [];

try
{
var workspaces = await _clockifyClient.V1.Workspaces.GetAsync();
_allWorkspaceNames = workspaces?.Select(w => w.Name).ToList() ?? [];
_workspace = workspaces?.SingleOrDefault(w => w.Name == _settings.WorkspaceName);

if (_workspace is not null)
{
var allProjects = await _clockifyClient.V1.Workspaces[_workspace.Id].Projects
.GetAsync(q => q.QueryParameters.PageSize = MaxPageSize);
_allProjectNames = allProjects?.Select(p => p.Name).ToList() ?? [];

var client = await FindMatchingClientAsync(_workspace.Id, _settings.ClientName);
_project = await FindMatchingProjectAsync(_workspace.Id, _settings.ProjectName, client?.Id);
_tags = await FindMatchingTagsAsync(_workspace.Id, _settings.Tags);

if (_project is not null)
{
_task = await FindMatchingTaskAsync(_workspace.Id, _project.Id, _settings.TaskName);
var allTasks = await _clockifyClient.V1.Workspaces[_workspace.Id].Projects[_project.Id].Tasks
.GetAsync(q =>
{
q.QueryParameters.PageSize = MaxPageSize;
q.QueryParameters.IsActive = true;
});
_allTaskNames = allTasks?.Select(t => t.Name).ToList() ?? [];
_task = allTasks?.FirstOrDefault(t => t.Name == _settings.TaskName);
}
}

logger.LogInfo("Reloading cache successful");
}
catch (Exception exception) when (exception is ApiException or HttpRequestException)
Expand Down
13 changes: 13 additions & 0 deletions Clockify/ToggleAction.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Threading.Tasks;
using BarRaider.SdTools;
using Newtonsoft.Json.Linq;

// ReSharper disable AsyncVoidMethod - Async overridse for SdTools
namespace Clockify;
Expand Down Expand Up @@ -100,13 +101,25 @@
Tools.AutoPopulateSettings(_settings, payload.Settings);
_logger.LogInfo($"Settings Received: {_settings}");
await _clockifyService.UpdateSettingsAsync(_settings);
await SendOptionsToPropertyInspectorAsync();
}

public override async void PropertyInspectorDidAppear()

Check failure on line 107 in Clockify/ToggleAction.cs

View workflow job for this annotation

GitHub Actions / Windows .NET 8

'ToggleAction.PropertyInspectorDidAppear()': no suitable method found to override

Check failure on line 107 in Clockify/ToggleAction.cs

View workflow job for this annotation

GitHub Actions / Windows .NET 8

'ToggleAction.PropertyInspectorDidAppear()': no suitable method found to override

Check failure on line 107 in Clockify/ToggleAction.cs

View workflow job for this annotation

GitHub Actions / MacOS .NET 8

'ToggleAction.PropertyInspectorDidAppear()': no suitable method found to override

Check failure on line 107 in Clockify/ToggleAction.cs

View workflow job for this annotation

GitHub Actions / MacOS .NET 8

'ToggleAction.PropertyInspectorDidAppear()': no suitable method found to override
{
await SendOptionsToPropertyInspectorAsync();
}

public override void ReceivedGlobalSettings(ReceivedGlobalSettingsPayload payload)
{
_logger.LogInfo("Global Settings Received");
}

private async Task SendOptionsToPropertyInspectorAsync()
{
var options = _clockifyService.GetAvailableOptions();
await Connection.SendToPropertyInspectorAsync(JObject.FromObject(options));
}

private async Task<bool> TryInitializingClockifyContext()
{
if (_clockifyService.IsValid)
Expand Down
30 changes: 21 additions & 9 deletions PropertyInspector/PluginActionPI.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
Expand All @@ -11,21 +11,32 @@
</head>
<body>
<div class="sdpi-wrapper">
<!-- Hidden inputs store workspace/project/task names for sdtools.common.js -->
<input type="hidden" class="sdProperty" id="workspaceName">
<input type="hidden" class="sdProperty" id="projectName">
<input type="hidden" class="sdProperty" id="taskName">

<div class="sdpi-item">
<div class="sdpi-item-label">API Key</div>
<input class="sdpi-item-value sdProperty" id="apiKey" value="" pattern="[A-Za-z0-9]+" placeholder="Enter your Private API Key" oninput="setSettings()" required>
<input class="sdpi-item-value sdProperty" id="apiKey" value="" pattern="[A-Za-z0-9]+" placeholder="Enter your Private API Key" oninput="setSettings();" required>
</div>
<div class="sdpi-item">
<div class="sdpi-item-label">Workspace Name</div>
<input class="sdpi-item-value sdProperty" id="workspaceName" value="" placeholder="Enter the name of the Workspace" oninput="setSettings()" required>
<div class="sdpi-item-label">Workspace</div>
<select class="sdpi-item-value" id="workspaceSelect" onchange="onWorkspaceChange()">
<option value="">-- Select Workspace --</option>
</select>
</div>
<div class="sdpi-item">
<div class="sdpi-item-label">Project Name</div>
<input class="sdpi-item-value sdProperty" id="projectName" value="" placeholder="Enter the name of the Project" oninput="setSettings()">
<div class="sdpi-item-label">Project</div>
<select class="sdpi-item-value" id="projectSelect" onchange="onProjectChange()">
<option value="">-- No Project --</option>
</select>
</div>
<div class="sdpi-item">
<div class="sdpi-item-label">Task Name</div>
<input class="sdpi-item-value sdProperty" id="taskName" value="" placeholder="Enter the name of the Project Task" oninput="setSettings()">
<div class="sdpi-item-label">Task</div>
<select class="sdpi-item-value" id="taskSelect" onchange="onTaskChange()">
<option value="">-- No Task --</option>
</select>
</div>
<div class="sdpi-item">
<div class="sdpi-item-label">Timer Name</div>
Expand Down Expand Up @@ -69,10 +80,11 @@
</div>
<div class="sdpi-item">
<div class="sdpi-item-label">Server Url</div>
<input class="sdpi-item-value sdProperty" id="serverUrl" value="https://api.clockify.me/api/v1" placeholder="Enter the ULR of the Server" oninput="setSettings()" required>
<input class="sdpi-item-value sdProperty" id="serverUrl" value="https://api.clockify.me/api/v1" placeholder="Enter the URL of the Server" oninput="setSettings();" required>
</div>
</div>
</div>
</div>

</body>
</html>
Loading