fix: API compatibility with latest TaskNotes plugin (fixes #2)#3
Open
diegomarzaa wants to merge 1 commit intocallumalpass:mainfrom
Open
fix: API compatibility with latest TaskNotes plugin (fixes #2)#3diegomarzaa wants to merge 1 commit intocallumalpass:mainfrom
diegomarzaa wants to merge 1 commit intocallumalpass:mainfrom
Conversation
…ss#2) The current TaskNotes plugin API has different behavior than expected: - GET /api/tasks with query params returns HTTP 400 - POST /api/tasks/query exists but returns 0 tasks This fix implements client-side filtering as a workaround: Changes to lib/api.js: - listTasks(): Now uses GET /api/tasks without params and filters client-side - queryTasks(): Handles FilterParser AST format for advanced filtering - searchTasks(): Implements client-side title search - Added helper methods: getAllTasks(), evaluateGroup(), evaluateNode(), evaluateCondition() Changes to commands/projects.js: - Fixed project filtering to handle [[wikilink]] format in project names - showProject() and showProjectStats() now properly match tasks to projects Tested with TaskNotes plugin v4.2.1. All CLI commands now work correctly: - tn list (with all filter options) - tn search - tn projects list/show/stats - All other commands that depend on task listing
|
Great work! This resolves the issue I had opened. |
|
Alternative approach: Use POST I hit the same issue and found that Instead of fetching all tasks and filtering client-side, you could build a proper FilterQuery object and use the query endpoint: async listTasks(filters = {}) {
const conditions = [];
const timestamp = Date.now();
let condIndex = 0;
const makeCondition = (property, operator, value) => ({
type: 'condition',
id: `cond_${timestamp}_${condIndex++}`,
property,
operator,
value
});
// Note: TaskNotes default completed status is 'done'
if (filters.completed === 'true') {
conditions.push(makeCondition('status', 'is', 'done'));
} else if (filters.completed === 'false') {
conditions.push(makeCondition('status', 'is-not', 'done'));
}
if (filters.scheduled_after) {
conditions.push(makeCondition('scheduled', 'is-on-or-after', filters.scheduled_after));
}
if (filters.scheduled_before) {
conditions.push(makeCondition('scheduled', 'is-on-or-before', filters.scheduled_before));
}
if (filters.due_before) {
conditions.push(makeCondition('due', 'is-before', filters.due_before));
}
const filterQuery = {
type: 'group',
id: `root_${timestamp}`,
conjunction: 'and',
children: conditions
};
return this.queryTasks(filterQuery);
}Pros of server-side filtering:
Pros of your client-side approach:
Tested with TaskNotes v4.2.1 and the query endpoint works. Up to you which approach you prefer! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #2 - HTTP 400 error when using CLI commands with the latest TaskNotes plugin.
Problem
The current TaskNotes plugin API has different behavior than expected by the CLI:
GET /api/taskswith query parameters returns HTTP 400POST /api/tasks/queryexists but returns 0 tasks regardless of filtersSolution
Implemented client-side filtering as a workaround:
Changes to
lib/api.js:listTasks(): Now usesGET /api/taskswithout params and filters client-sidequeryTasks(): Handles FilterParser AST format for advanced filtering client-sidesearchTasks(): Implements client-side title searchgetAllTasks(),evaluateGroup(),evaluateNode(),evaluateCondition()Changes to
commands/projects.js:[[wikilink]]format in project namesshowProject()andshowProjectStats()now properly match tasks to projectsTesting
Tested with TaskNotes plugin v4.2.1. All CLI commands now work correctly:
tn list(with all filter options:--today,--completed,--overdue,--filter)tn searchtn projects list/show/stats