TaskManager API
TaskManager module deals with managing long running tasks in phcode. It handles the Tasks
dropdown in the status
bar where the user can see all running tasks, monitor its progress and close/pause the execution of the task if
supported by the task.
determines what the spinner icon to show(green-for success), red-fail, blue normal based on the active tasks in list and renders. IF the active tasks has already been notified, it wont notify again.
newTaskAdded
Type: Object
-
show
function (): void Shows the task popup in the ui. -
close
function (): void Closes the task and removes it from the UI. -
setTitle
function (string): void Sets the task's title. -
getTitle
function (): string Returns the task's title. -
setMessage
function (string): void Sets the task's message. -
getMessage
function (): string Returns the task's message. -
setProgressPercent
function (number): void Sets the task's progress percentage. -
getProgressPercent
function (): number Returns the task's current progress percentage. -
setFailed
function (): void Marks the task as failed. -
isFailed
function (): boolean Returns true if the task is marked as failed. -
setSucceded
function (): void Marks the task as succeeded. -
isSucceded
function (): boolean Returns true if the task is marked as succeeded. -
showStopIcon
function (string): void Shows the stop icon with an optional tooltip message. -
hideStopIcon
function (): void Hides the stop icon. -
showPlayIcon
function (string): void Shows the play icon with an optional tooltip message. -
hidePlayIcon
function (): void Hides the play icon. -
showPauseIcon
function (string): void Shows the pause icon with an optional tooltip message. -
hidePauseIcon
function (): void Hides the pause icon. -
showRestartIcon
function (string): void Shows the restart (retry) icon with an optional tooltip message. -
hideRestartIcon
function (): void Hides the restart (retry) icon.
The addNewTask is designed for adding new tasks to the task management system. This function is central to managing long-running tasks, providing a way to visually represent task progress, status, and control actions directly from the UI in the status bar.
-
taskTitle
string The title of the task. This is a mandatory parameter and is displayed in the UI. -
message
string A message or status associated with the task. Displayed as additional information in the UI. -
iconHTML
string? Optional HTML string for the task's icon. Used to visually represent the task in the UI. (optional, defaultnull
) -
options
Object? Optional settings and callbacks for the task. (optional, default{onPauseClick:null,onPlayClick:null,onStopClick:null,onRetryClick:null,onSelect:null,progressPercent:null}
)-
options.onPauseClick
Function? Callback function triggered when the pause button is clicked. -
options.onPlayClick
Function? Callback function triggered when the play button is clicked. -
options.onStopClick
Function? Callback function triggered when the stop button is clicked. -
options.onRetryClick
Function? Callback function triggered when the retry button is clicked. -
options.onSelect
Function? Callback function triggered when the task is selected from the dropdown. -
options.progressPercent
number? Initial progress percentage of the task.
-
// Example: Adding a new task with initial progress and attaching event handlers
const task = TaskManager.addNewTask(
'Data Processing',
'Processing data...',
'<i class="fa fa-spinner fa-spin"></i>',
{
onPauseClick: () => console.log('Task paused'),
onPlayClick: () => console.log('Task resumed'),
onStopClick: () => console.log('Task stopped'),
onRetryClick: () => console.log('Task retried'),
onSelect: () => console.log('Task selected'),
progressPercent: 20
}
);
// Updating task progress
task.setProgressPercent(60);
// Updating task message
task.setMessage('60% completed');
// Marking task as succeeded
task.setSucceeded();
Returns TaskObject Returns a task object with methods for updating the task's state and UI representation,
such as setProgressPercent
, setMessage
, setSucceeded
, setFailed
, and control visibility methods
like showStopIcon
, hideStopIcon
, etc.