name

Work Blocks

description

Select the text of a task and generate multiple timeblocks for that task.

instructions


Best used in Calendar Mode. Select the entire text of a task, then from the floating toolbar that appears select the Work Blocks plugin. Use the prompt to type in how many instances of the task you want to generate.

Useful for timeblocking multiple work sessions on a single task/project.

icon

more_time


Change log:

August 3rd, 2023:

Tasks are now added automatically to the source note of the selected task

Option to schedule a task now only appears when text inside a task is selected

Replaced text input with select input

Renamed plugin and added icon

Todos:

Add duration to tasks

Addition of suffix or prefix to the task name
i.e.
[[Master Task]] - Work Block 1
[[Master Task]] - Work Block 2

A link back to the "master" task.



{
replaceText: {
// TODO: add checks
"Create timeblocks": {
async run(app, text) {
try {
const sourceTaskUUID = app.context.taskUUID;
console.log(sourceTaskUUID);
 
const sourceTask = await app.getTask(sourceTaskUUID);
console.log(JSON.stringify(sourceTask));
 
const destinationNote = await app.notes.find({uuid: sourceTask.noteUUID});
console.log(destinationNote.uuid);
// const taskCount = await app.prompt("How many work blocks would you like to generate?");
const taskCountOptions = Array.from({length: 10}, (_, i) => ({label: `${i+1}`, value: i+1}));
 
const result = await app.prompt("How many work blocks would you like to generate?", {
inputs: [
{ label: "Task count", type: "select", options: taskCountOptions },
]
});
console.log(result);
 
if (!this._isStringAnInteger(result)) {
app.alert("Not an integer number of work blocks.");
return null;
}
 
for (let i = 0; i < result; i++) {
destinationNote.insertTask({content: sourceTask.content, startAt: this._getNow()})
}
} catch (err) {
app.alert(err);
}
},
 
async check(app) {
try {
const sourceTaskUUID = app.context.taskUUID;
console.log(sourceTaskUUID);
 
if (!app.context.taskUUID || app.context.taskUUID === undefined) {
return false;
}
return true;
} catch (err) {
app.alert(err);
}
}
}
},
 
_getNow() {
const unixTimestamp = Math.floor(Date.now() / 1000);
return unixTimestamp;
},
 
_isStringAnInteger(str) {
const integerRegex = /^\d+$/;
return integerRegex.test(str);
},
}