Merge pull request #437 from ouoertheo/ouoertheo/objective2

This commit is contained in:
Cohee
2023-06-03 13:39:53 +03:00
committed by GitHub
2 changed files with 78 additions and 18 deletions

View File

@@ -61,7 +61,7 @@ async function generateQuietPrompt(quiet_prompt) {
// Accepts optional position. Defaults to adding to end of list. // Accepts optional position. Defaults to adding to end of list.
function addTask(description, position = null) { function addTask(description, position = null) {
position = position ? position != null : position = globalTasks.length position = position != null ? position: position = globalTasks.length
globalTasks.splice(position, 0, { globalTasks.splice(position, 0, {
"description": description, "description": description,
"completed": false "completed": false
@@ -78,19 +78,24 @@ function getTask(index = null, taskDescription = null) {
task = globalObjective[index] task = globalObjective[index]
} else if (taskDescription != null) { } else if (taskDescription != null) {
task = globalTasks.find(task => { task = globalTasks.find(task => {
return true ? task.description == description : false return task.description == description ? true: false
}) })
} }
return task return task
} }
function deleteTask(index){
globalTasks.splice(index, 1)
setCurrentTask()
updateUiTaskList()
}
// Complete the current task, setting next task to next incomplete task // Complete the current task, setting next task to next incomplete task
function completeTask(task) { function completeTask(task) {
task.completed = true task.completed = true
console.info(`Task successfully completed: ${JSON.stringify(task)}`) console.info(`Task successfully completed: ${JSON.stringify(task)}`)
setCurrentTask() setCurrentTask()
updateUiTaskList() updateUiTaskList()
saveState()
} }
// Call Quiet Generate to create task list using character context, then convert to tasks. Should not be called much. // Call Quiet Generate to create task list using character context, then convert to tasks. Should not be called much.
@@ -115,13 +120,8 @@ async function generateTasks() {
// Call Quiet Generate to check if a task is completed // Call Quiet Generate to check if a task is completed
async function checkTaskCompleted() { async function checkTaskCompleted() {
// Make sure there are tasks and check is enabled // Make sure there are tasks
if (Object.keys(currentTask).length == 0 || $('#objective-check-frequency').val() == 0) { if (Object.keys(currentTask).length == 0) {
return
}
// Check only at specified interval
if (checkCounter > 0) {
return return
} }
checkCounter = $('#objective-check-frequency').val() checkCounter = $('#objective-check-frequency').val()
@@ -227,9 +227,11 @@ function addUiTask(taskIndex, taskComplete, taskDescription) {
<span>${taskIndex}</span> <span>${taskIndex}</span>
<input id="objective-task-complete-${taskIndex}" type="checkbox"> <input id="objective-task-complete-${taskIndex}" type="checkbox">
<span class="text_pole" style="display: block" id="objective-task-description-${taskIndex}" contenteditable>${taskDescription}</span> <span class="text_pole" style="display: block" id="objective-task-description-${taskIndex}" contenteditable>${taskDescription}</span>
<div id="objective-task-delete-${taskIndex}" class="objective-task-button fa-solid fa-xmark fa-2x" title="Delete Task"></div>
<div id="objective-task-add-${taskIndex}" class="objective-task-button fa-solid fa-plus fa-2x" title="Add Task"></div>
</div><br> </div><br>
`; `;
// Add the filled out template // Add the filled out template
$('#objective-tasks').append(template); $('#objective-tasks').append(template);
@@ -244,20 +246,52 @@ function addUiTask(taskIndex, taskComplete, taskDescription) {
const index = Number(event.target.id.split('-').pop()); const index = Number(event.target.id.split('-').pop());
globalTasks[index].description = event.target.textContent; globalTasks[index].description = event.target.textContent;
}); });
$(`#objective-task-delete-${taskIndex}`).on('click', event => {
const index = Number(event.target.id.split('-').pop());
deleteTask(index)
});
$(`#objective-task-add-${taskIndex}`).on('click', event => {
const index = Number(event.target.id.split('-').pop()) + 1;
addTask("", index)
setCurrentTask()
updateUiTaskList()
});
} }
// Populate UI task list // Populate UI task list
function updateUiTaskList() { function updateUiTaskList() {
$('#objective-tasks').empty() $('#objective-tasks').empty()
for (const index in globalTasks) { // Show tasks if there are any
addUiTask( if (globalTasks.length > 0){
index, for (const index in globalTasks) {
globalTasks[index].completed, addUiTask(
globalTasks[index].description index,
) globalTasks[index].completed,
globalTasks[index].description
)
}
} else {
// Show button to add tasks if there are none
$('#objective-tasks').append(`
<input id="objective-task-add-first" type="button" class="menu_button" value="Add Task">
`)
$("#objective-task-add-first").on('click', () => {
addTask("")
setCurrentTask()
updateUiTaskList()
})
} }
} }
function addManualTaskCheck() {
$('#extensionsMenu').prepend(`
<div id="objective-task-manual-check-menu-item" class="list-group-item flex-container flexGap5">
<div id="objective-task-manual-check" class="extensionsMenuExtensionButton fa-regular fa-square-check"/></div>
Manual Task Check
</div>`)
$('#objective-task-manual-check-menu-item').attr('title', 'Trigger AI check of completed tasks').on('click', checkTaskCompleted)
}
// Trigger creation of new tasks with given objective. // Trigger creation of new tasks with given objective.
async function onGenerateObjectiveClick() { async function onGenerateObjectiveClick() {
globalObjective = $('#objective-text').val() globalObjective = $('#objective-text').val()
@@ -273,6 +307,8 @@ function onChatDepthInput() {
// Update how often we check for task completion // Update how often we check for task completion
function onCheckFrequencyInput() { function onCheckFrequencyInput() {
checkCounter = $("#objective-check-frequency").val()
$('#objective-counter').text(checkCounter)
saveState() saveState()
} }
@@ -350,6 +386,7 @@ jQuery(() => {
</div> </div>
</div>`; </div>`;
addManualTaskCheck()
$('#extensions_settings').append(settingsHtml); $('#extensions_settings').append(settingsHtml);
$('#objective-generate').on('click', onGenerateObjectiveClick) $('#objective-generate').on('click', onGenerateObjectiveClick)
$('#objective-chat-depth').on('input', onChatDepthInput) $('#objective-chat-depth').on('input', onChatDepthInput)
@@ -366,7 +403,10 @@ jQuery(() => {
return return
} }
if ($("#objective-check-frequency").val() > 0) { if ($("#objective-check-frequency").val() > 0) {
checkTaskCompleted(); // Check only at specified interval
if (checkCounter <= 0) {
checkTaskCompleted();
}
checkCounter -= 1 checkCounter -= 1
} }
setCurrentTask(); setCurrentTask();

View File

@@ -14,3 +14,23 @@
.objective_block_control label { .objective_block_control label {
width: max-content; width: max-content;
} }
.objective-task-button {
margin: 0;
outline: none;
border: none;
cursor: pointer;
transition: 0.3s;
opacity: 0.7;
align-items: center;
justify-content: center;
}
.objective-task-button:hover {
opacity: 1;
}
[id^=objective-task-delete-] {
color: #da3f3f;
}