From cd8a24a7127f73477e7814f78b14b692b0d93676 Mon Sep 17 00:00:00 2001 From: Cohee Date: Fri, 4 Aug 2023 14:41:00 +0300 Subject: [PATCH] Fix bulk edit --- public/script.js | 7 ++++--- public/scripts/extensions/bulk-edit/index.js | 15 ++++++++++++--- public/scripts/extensions/bulk-edit/manifest.json | 2 +- public/scripts/extensions/bulk-edit/style.css | 7 +++++++ server.js | 4 ++-- 5 files changed, 26 insertions(+), 9 deletions(-) create mode 100644 public/scripts/extensions/bulk-edit/style.css diff --git a/public/script.js b/public/script.js index ff8b45380..390554939 100644 --- a/public/script.js +++ b/public/script.js @@ -7032,13 +7032,13 @@ function doCloseChat() { * * @param {string} popup_type - The type of popup currently active. * @param {string} this_chid - The character ID to be deleted. + * @param {boolean} delete_chats - Whether to delete chats or not. */ -export async function handleDeleteCharacter(popup_type, this_chid) { +export async function handleDeleteCharacter(popup_type, this_chid, delete_chats) { if (popup_type !== "del_ch") { return; } - const delete_chats = !!$("#del_char_checkbox").prop("checked"); const avatar = characters[this_chid].avatar; const name = characters[this_chid].name; @@ -7476,7 +7476,8 @@ $(document).ready(function () { }, 200); } if (popup_type == "del_ch") { - handleDeleteCharacter(popup_type, this_chid, characters); + const deleteChats = !!$("#del_char_checkbox").prop("checked"); + await handleDeleteCharacter(popup_type, this_chid, deleteChats); } if (popup_type == "alternate_greeting" && menu_type !== "create") { createOrEditCharacter(); diff --git a/public/scripts/extensions/bulk-edit/index.js b/public/scripts/extensions/bulk-edit/index.js index b72b662a1..ace288c94 100644 --- a/public/scripts/extensions/bulk-edit/index.js +++ b/public/scripts/extensions/bulk-edit/index.js @@ -1,4 +1,4 @@ -import { characters, getCharacters, saveSettingsDebounced, handleDeleteCharacter } from "../../../script.js"; +import { characters, getCharacters, handleDeleteCharacter, callPopup } from "../../../script.js"; let is_bulk_edit = false; @@ -27,7 +27,7 @@ function onEditButtonClick() { * @param {string} this_chid - The chid of the character to delete. */ async function deleteCharacter(this_chid) { - await handleDeleteCharacter("del_ch", this_chid); + await handleDeleteCharacter("del_ch", this_chid, false); } /** @@ -45,6 +45,13 @@ async function onDeleteButtonClick() { toDelete.push(avatar); }); + const confirm = await callPopup('

Are you sure you want to delete these characters?

You would need to delete the chat files manually.
', 'confirm'); + + if (!confirm) { + console.log('User cancelled delete'); + return; + } + // Delete the characters for (const avatar of toDelete) { console.log(`Deleting character with avatar ${avatar}`); @@ -78,7 +85,7 @@ function addButtons() { * Enables bulk selection by adding a checkbox next to each character. */ function enableBulkSelect() { - $(".character_select").each((i, el) => { + $("#rm_print_characters_block .character_select").each((i, el) => { const character = $(el).text(); const checkbox = $(""); checkbox.on("change", () => { @@ -86,6 +93,7 @@ function enableBulkSelect() { }); $(el).prepend(checkbox); }); + $("#rm_print_characters_block").addClass("bulk_select"); // We also need to disable the default click event for the character_select divs $(document).on("click", ".bulk_select_checkbox", function (event) { event.stopImmediatePropagation(); @@ -97,6 +105,7 @@ function enableBulkSelect() { */ function disableBulkSelect() { $(".bulk_select_checkbox").remove(); + $("#rm_print_characters_block").removeClass("bulk_select"); } /** diff --git a/public/scripts/extensions/bulk-edit/manifest.json b/public/scripts/extensions/bulk-edit/manifest.json index 3f2d177e7..b86a2c82b 100644 --- a/public/scripts/extensions/bulk-edit/manifest.json +++ b/public/scripts/extensions/bulk-edit/manifest.json @@ -4,7 +4,7 @@ "requires": [], "optional": [], "js": "index.js", - "css": "", + "css": "style.css", "author": "city-unit", "version": "1.0.0", "homePage": "https://github.com/city-unit" diff --git a/public/scripts/extensions/bulk-edit/style.css b/public/scripts/extensions/bulk-edit/style.css new file mode 100644 index 000000000..7a9377ef6 --- /dev/null +++ b/public/scripts/extensions/bulk-edit/style.css @@ -0,0 +1,7 @@ +.bulk_select_checkbox { + align-self: center; +} + +#rm_print_characters_block .wide100pLess70px { + width: calc(100% - 85px); +} diff --git a/server.js b/server.js index 11146e29b..d841a3d41 100644 --- a/server.js +++ b/server.js @@ -1169,7 +1169,7 @@ app.post("/deletecharacter", jsonParser, async function (request, response) { return response.sendStatus(403); } - if (request.body.delete_chats == 'true') { + if (request.body.delete_chats == true) { try { await fs.promises.rm(path.join(chatsPath, sanitize(dir_name)), { recursive: true, force: true }) } catch (err) { @@ -3475,7 +3475,7 @@ app.post("/tokenize_via_api", jsonParser, async function (request, response) { body: JSON.stringify({ "prompt": text }), headers: { "Content-Type": "application/json" } }; - + if (main_api == 'textgenerationwebui' && request.body.use_mancer) { args.headers = Object.assign(args.headers, get_mancer_headers()); }