This script manages and updates the "Progress" section of a note in an application. It processes tasks within the note, calculates task progress, and updates the note with a progress bar and categorized task list. This guide explains the functionality of each section of the script and how it reflects in the final output.
Input:
app: The application object containing methods to interact with notes and tasks.
noteUUID: The unique identifier for the note to be processed.
Purpose:
This function is designed to handle note content, particularly focusing on tasks and their progress.
Input:
Uses the application's getNoteSections method to retrieve all sections of the note specified by app.context.noteUUID.
Purpose:
Finds the section with the heading "Progress". If this section is missing, the user is prompted to create it.
Output:
If the "Progress" section is not found, an alert is displayed with instructions to create one.
Input:
app.getNoteTasks: Retrieves tasks for the specified note. The first call fetches only pending tasks, while the second includes completed and dismissed tasks.
Purpose:
To process and categorize tasks into pending, completed, and dismissed.
Output:
taskPending: List of tasks that are still pending.
taskAll: List of all tasks, including those that are completed or dismissed.
Input:
unixTimestamp: A UNIX timestamp representing a date and time.
Purpose:
Converts the UNIX timestamp to a human-readable date format (YYYY-MM-DD HH:MM:SS).
Output:
A formatted date string.
Input:
a, b: Task objects to be compared.
key: The key in the task object that holds the timestamp.
Purpose:
Sorts tasks based on a specific timestamp field.
Output:
Numeric comparison result for sorting.
Input:
task: A task object with properties like content, important, urgent, and startAt.
Purpose:
Formats a pending task into a string with content, start date, and labels (if applicable).
Output:
A string representing the formatted pending task.
Input:
taskAll: List of all tasks.
Purpose:
Filters tasks that are completed, sorts them by completion date, and formats them into strings.
Output:
An array of formatted strings for completed tasks.
Input:
taskAll: List of all tasks.
Purpose:
Filters tasks that are dismissed, sorts them by dismissal date, and formats them into strings.
Output:
An array of formatted strings for dismissed tasks.
Input:
taskAll: List of all tasks.
Purpose:
Filters tasks that are neither completed nor dismissed, sorts them by start date, and formats them.
Output:
An array of formatted strings for pending tasks.
Input:
taskAllN: Total number of tasks.
taskPendingN: Number of pending tasks.
Purpose:
Calculates the progress of tasks as a percentage based on the ratio of completed to total tasks.
Output:
taskCompletedPercent: Percentage of tasks completed.
Input:
taskCompletedPercent: Percentage of tasks completed.
app.settings["Emoji"]: User-selected emoji set for the progress bar.
Purpose:
Generates a progress bar string based on the completion percentage and selected emoji set.
Output:
A string representing the progress bar, which includes the completion percentage and selected emojis.
Input:
allTaskCategorized: A string containing categorized tasks.
Purpose:
Prepares the categorized task list for insertion into the note.
Output:
A formatted string that includes a placeholder for the categorized task list.
Input:
app.replaceNoteContent: Method to update note content.
taskProgress: The progress bar string.
allTaskCategorizedz: The categorized task list string.
section: The section of the note to be updated.
Purpose:
Replaces the content of the "Progress" section with the progress bar and categorized task list.
Output:
Updates the note in the application with the new progress and task details.
This script performs a series of steps to manage and update the "Progress" section of a note, including fetching tasks, categorizing them, calculating progress, and generating a visual representation of progress with a customizable emoji-based progress bar. It ensures that users are alerted if the required "Progress" section is missing and provides detailed information about the tasks and their statuses.