mirror of
https://github.com/easydiffusion/easydiffusion.git
synced 2025-05-31 07:05:45 +02:00
Refactor the Use Settings code, and move that to the common restoreTask() function
This commit is contained in:
parent
ec294227bd
commit
a697bd935a
@ -335,9 +335,9 @@
|
|||||||
<script src="media/js/inpainting-editor.js?v=1"></script>
|
<script src="media/js/inpainting-editor.js?v=1"></script>
|
||||||
<script src="media/js/image-modifiers.js?v=7"></script>
|
<script src="media/js/image-modifiers.js?v=7"></script>
|
||||||
<script src="media/js/auto-save.js?v=8"></script>
|
<script src="media/js/auto-save.js?v=8"></script>
|
||||||
<script src="media/js/main.js?v=24"></script>
|
<script src="media/js/main.js?v=25"></script>
|
||||||
<script src="media/js/themes.js?v=4"></script>
|
<script src="media/js/themes.js?v=4"></script>
|
||||||
<script src="media/js/dnd.js?v=10"></script>
|
<script src="media/js/dnd.js?v=11"></script>
|
||||||
<script>
|
<script>
|
||||||
async function init() {
|
async function init() {
|
||||||
await initSettings()
|
await initSettings()
|
||||||
|
@ -243,7 +243,9 @@ const TASK_MAPPING = {
|
|||||||
parse: (val) => val
|
parse: (val) => val
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function restoreTaskToUI(task) {
|
function restoreTaskToUI(task, fieldsToSkip) {
|
||||||
|
fieldsToSkip = fieldsToSkip || []
|
||||||
|
|
||||||
if ('numOutputsTotal' in task) {
|
if ('numOutputsTotal' in task) {
|
||||||
numOutputsTotalField.value = task.numOutputsTotal
|
numOutputsTotalField.value = task.numOutputsTotal
|
||||||
}
|
}
|
||||||
@ -255,10 +257,47 @@ function restoreTaskToUI(task) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
for (const key in TASK_MAPPING) {
|
for (const key in TASK_MAPPING) {
|
||||||
if (key in task.reqBody) {
|
if (key in task.reqBody && !fieldsToSkip.includes(key)) {
|
||||||
TASK_MAPPING[key].setUI(task.reqBody[key])
|
TASK_MAPPING[key].setUI(task.reqBody[key])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// restore the original tag
|
||||||
|
promptField.value = task.reqBody.original_prompt || task.reqBody.prompt
|
||||||
|
|
||||||
|
// Restore modifiers
|
||||||
|
if (task.reqBody.active_tags) {
|
||||||
|
refreshModifiersState(task.reqBody.active_tags)
|
||||||
|
}
|
||||||
|
|
||||||
|
// properly reset checkboxes
|
||||||
|
if (!('use_face_correction' in task.reqBody)) {
|
||||||
|
useFaceCorrectionField.checked = false
|
||||||
|
}
|
||||||
|
if (!('use_upscale' in task.reqBody)) {
|
||||||
|
useUpscalingField.checked = false
|
||||||
|
}
|
||||||
|
if (!('mask' in task.reqBody)) {
|
||||||
|
maskSetting.checked = false
|
||||||
|
}
|
||||||
|
upscaleModelField.disabled = !useUpscalingField.checked
|
||||||
|
|
||||||
|
// Show the source picture if present
|
||||||
|
initImagePreview.src = (task.reqBody.init_image == undefined ? '' : task.reqBody.init_image)
|
||||||
|
if (IMAGE_REGEX.test(initImagePreview.src)) {
|
||||||
|
Boolean(task.reqBody.mask) ? inpaintingEditor.setImg(task.reqBody.mask) : inpaintingEditor.resetBackground()
|
||||||
|
initImagePreviewContainer.style.display = 'block'
|
||||||
|
inpaintingEditorContainer.style.display = 'none'
|
||||||
|
promptStrengthContainer.style.display = 'table-row'
|
||||||
|
//samplerSelectionContainer.style.display = 'none'
|
||||||
|
// maskSetting.checked = false
|
||||||
|
inpaintingEditorContainer.style.display = maskSetting.checked ? 'block' : 'none'
|
||||||
|
} else {
|
||||||
|
initImagePreviewContainer.style.display = 'none'
|
||||||
|
// inpaintingEditorContainer.style.display = 'none'
|
||||||
|
promptStrengthContainer.style.display = 'none'
|
||||||
|
// maskSetting.style.display = 'none'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
function readUI() {
|
function readUI() {
|
||||||
const reqBody = {}
|
const reqBody = {}
|
||||||
|
@ -898,44 +898,9 @@ function createTask(task) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
task['useSettings'] = taskEntry.querySelector('.useSettings')
|
task['useSettings'] = taskEntry.querySelector('.useSettings')
|
||||||
task['useSettings'].addEventListener('click', async function(e) {
|
task['useSettings'].addEventListener('click', function(e) {
|
||||||
TASK_REQ_NO_EXPORT.forEach((key) => delete task.reqBody[key]) // don't restore system settings when restoring tasks
|
e.stopPropagation()
|
||||||
restoreTaskToUI(task)
|
restoreTaskToUI(task, TASK_REQ_NO_EXPORT)
|
||||||
e.stopPropagation();
|
|
||||||
|
|
||||||
// restore the original tag
|
|
||||||
promptField.value = task.reqBody.original_prompt
|
|
||||||
|
|
||||||
// Restore modifiers
|
|
||||||
refreshModifiersState(task.reqBody.active_tags)
|
|
||||||
|
|
||||||
// properly reset checkboxes
|
|
||||||
if (!('use_face_correction' in task.reqBody)) {
|
|
||||||
useFaceCorrectionField.checked = false
|
|
||||||
}
|
|
||||||
if (!('use_upscale' in task.reqBody)) {
|
|
||||||
useUpscalingField.checked = false
|
|
||||||
}
|
|
||||||
if (!('mask' in task.reqBody)) {
|
|
||||||
maskSetting.checked = false
|
|
||||||
}
|
|
||||||
|
|
||||||
// Show the source picture if present
|
|
||||||
initImagePreview.src = (task.reqBody.init_image == undefined ? '' : task.reqBody.init_image)
|
|
||||||
if (IMAGE_REGEX.test(initImagePreview.src)) {
|
|
||||||
Boolean(task.reqBody.mask) ? inpaintingEditor.setImg(task.reqBody.mask) : inpaintingEditor.resetBackground()
|
|
||||||
initImagePreviewContainer.style.display = 'block'
|
|
||||||
inpaintingEditorContainer.style.display = 'none'
|
|
||||||
promptStrengthContainer.style.display = 'table-row'
|
|
||||||
//samplerSelectionContainer.style.display = 'none'
|
|
||||||
// maskSetting.checked = false
|
|
||||||
inpaintingEditorContainer.style.display = maskSetting.checked ? 'block' : 'none'
|
|
||||||
} else {
|
|
||||||
initImagePreviewContainer.style.display = 'none'
|
|
||||||
// inpaintingEditorContainer.style.display = 'none'
|
|
||||||
promptStrengthContainer.style.display = 'none'
|
|
||||||
// maskSetting.style.display = 'none'
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
imagePreview.insertBefore(taskEntry, previewTools.nextSibling)
|
imagePreview.insertBefore(taskEntry, previewTools.nextSibling)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user