mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Progress on move entry
* Fixed header alignment * Building HTML with browser api instead of string. * jqueryElement.data(key, value) usages converted to jqueryElement.attr(data-key, value) * Logs simplified * Removed success toastry message
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
<div id="WIEntryHeaderTitlesPC" class="flex-container wide100p spaceBetween justifyCenter textAlignCenter" style="padding:0 4.5em;">
|
<div id="WIEntryHeaderTitlesPC" class="flex-container wide100p spaceBetween justifyCenter textAlignCenter" style="padding:0 7.0em;">
|
||||||
<small class="flex1" data-i18n="Title/Memo">Title/Memo</small>
|
<small class="flex1" data-i18n="Title/Memo">Title/Memo</small>
|
||||||
<small style="width: calc(3.5em + 10px)" data-i18n="Strategy">Strategy</small>
|
<small style="width: calc(3.5em + 10px)" data-i18n="Strategy">Strategy</small>
|
||||||
<small style="width: calc(3.5em + 20px)" data-i18n="Position">Position</small>
|
<small style="width: calc(3.5em + 20px)" data-i18n="Position">Position</small>
|
||||||
|
@@ -2208,7 +2208,7 @@ function verifyWorldInfoSearchSortRule() {
|
|||||||
* Use `originalWIDataKeyMap` to find the correct value to be set.
|
* Use `originalWIDataKeyMap` to find the correct value to be set.
|
||||||
*
|
*
|
||||||
* @param {object} data - The data object containing the original data entries.
|
* @param {object} data - The data object containing the original data entries.
|
||||||
* @param {string} uid - The unique identifier of the data entry.
|
* @param {number} uid - The unique identifier of the data entry.
|
||||||
* @param {string} key - The key of the value to be set.
|
* @param {string} key - The key of the value to be set.
|
||||||
* @param {any} value - The value to be set.
|
* @param {any} value - The value to be set.
|
||||||
*/
|
*/
|
||||||
@@ -3141,21 +3141,38 @@ export async function getWorldEntry(name, data, entry) {
|
|||||||
|
|
||||||
// move button
|
// move button
|
||||||
const moveButton = template.find('.move_entry_button');
|
const moveButton = template.find('.move_entry_button');
|
||||||
moveButton.data('uid', entry.uid);
|
moveButton.attr('data-uid', entry.uid);
|
||||||
moveButton.data('current-world', name);
|
moveButton.attr('data-current-world', name);
|
||||||
moveButton.on('click', async function (e) {
|
moveButton.on('click', async function (e) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
const sourceUid = $(this).data('uid');
|
const sourceUid = $(this).data('uid');
|
||||||
const sourceWorld = $(this).data('current-world');
|
const sourceWorld = $(this).data('current-world');
|
||||||
// Loading world info is bad, do we have cache variable?
|
const sourceWorldInfo = await loadWorldInfo(sourceWorld);
|
||||||
const sourceName = (await loadWorldInfo(sourceWorld)).entries[sourceUid].comment;
|
if (!sourceWorldInfo) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const sourceName = sourceWorldInfo.entries[sourceUid]?.comment;
|
||||||
|
if (sourceName === undefined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const select = document.createElement('select');
|
||||||
|
select.id = 'move_entry_target_select';
|
||||||
|
select.classList.add('text_pole', 'wide100p', 'margin-top');
|
||||||
|
|
||||||
|
const defaultOption = document.createElement('option');
|
||||||
|
defaultOption.value = '';
|
||||||
|
defaultOption.textContent = `-- ${t`Select Target Lorebook`} --`;
|
||||||
|
select.appendChild(defaultOption);
|
||||||
|
|
||||||
let optionsHtml = `<option value="">-- ${t`Select Target Lorebook`} --</option>`;
|
|
||||||
let selectableWorldCount = 0;
|
let selectableWorldCount = 0;
|
||||||
world_names.forEach(worldName => {
|
world_names.forEach(worldName => {
|
||||||
if (worldName !== sourceWorld) { // Exclude the current world
|
if (worldName !== sourceWorld) { // Exclude current world
|
||||||
optionsHtml += `<option value="${world_names.indexOf(worldName)}">${worldName}</option>`;
|
const option = document.createElement('option');
|
||||||
selectableWorldCount += 1;
|
option.value = world_names.indexOf(worldName).toString();
|
||||||
|
option.textContent = worldName;
|
||||||
|
select.appendChild(option);
|
||||||
|
selectableWorldCount++;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -3164,27 +3181,24 @@ export async function getWorldEntry(name, data, entry) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const content = `
|
// Create wrapper div
|
||||||
<div>${t`Move ${sourceName} to:`}</div>
|
const wrapper = document.createElement('div');
|
||||||
<select id="move_entry_target_select" class="text_pole wide100p margin-top">
|
wrapper.textContent = t`Move ${sourceName} to:`;
|
||||||
${optionsHtml}
|
|
||||||
</select>
|
|
||||||
`;
|
|
||||||
|
|
||||||
const popupPromise = callGenericPopup(content, POPUP_TYPE.CONFIRM, '', {
|
// Create container and append elements
|
||||||
|
const container = document.createElement('div');
|
||||||
|
container.appendChild(wrapper);
|
||||||
|
container.appendChild(select);
|
||||||
|
|
||||||
|
let selectedWorldIndex = -1;
|
||||||
|
select.addEventListener('change', function() {
|
||||||
|
selectedWorldIndex = this.value === '' ? -1 : Number(this.value);
|
||||||
|
});
|
||||||
|
|
||||||
|
const popupConfirm = await callGenericPopup(container, POPUP_TYPE.CONFIRM, '', {
|
||||||
okButton: t`Move`,
|
okButton: t`Move`,
|
||||||
cancelButton: t`Cancel`,
|
cancelButton: t`Cancel`,
|
||||||
});
|
});
|
||||||
|
|
||||||
let selectedWorldIndex = -1;
|
|
||||||
$('#move_entry_target_select').on('change', function () {
|
|
||||||
/** @type {string} */
|
|
||||||
// @ts-ignore
|
|
||||||
const value = $(this).val();
|
|
||||||
selectedWorldIndex = value === '' ? -1 : Number(value);
|
|
||||||
});
|
|
||||||
|
|
||||||
const popupConfirm = await popupPromise;
|
|
||||||
if (!popupConfirm) {
|
if (!popupConfirm) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -5337,19 +5351,11 @@ jQuery(() => {
|
|||||||
*
|
*
|
||||||
* @param {string} sourceName - The name of the source lorebook file.
|
* @param {string} sourceName - The name of the source lorebook file.
|
||||||
* @param {string} targetName - The name of the target lorebook file.
|
* @param {string} targetName - The name of the target lorebook file.
|
||||||
* @param {number|string} uid - The UID of the entry to move from the source lorebook.
|
* @param {number} uid - The UID of the entry to move from the source lorebook.
|
||||||
* @returns {Promise<boolean>} True if the move was successful, false otherwise.
|
* @returns {Promise<boolean>} True if the move was successful, false otherwise.
|
||||||
*/
|
*/
|
||||||
export async function moveWorldInfoEntry(sourceName, targetName, uid) {
|
export async function moveWorldInfoEntry(sourceName, targetName, uid) {
|
||||||
console.log(`[WI] Attempting to move entry UID ${uid} from '${sourceName}' to '${targetName}'`);
|
|
||||||
|
|
||||||
if (!sourceName || !targetName || uid === undefined || uid === null) {
|
|
||||||
console.error('[WI Move] Missing required arguments.');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sourceName === targetName) {
|
if (sourceName === targetName) {
|
||||||
toastr.warning(t`Source and target lorebooks cannot be the same.`);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5407,20 +5413,19 @@ export async function moveWorldInfoEntry(sourceName, targetName, uid) {
|
|||||||
targetData.entries[newUid] = entryToMove;
|
targetData.entries[newUid] = entryToMove;
|
||||||
|
|
||||||
delete sourceData.entries[entryUidString];
|
delete sourceData.entries[entryUidString];
|
||||||
// Remove from originalData if it exists, using the original UID
|
// Remove from originalData if it exists
|
||||||
deleteWIOriginalDataValue(sourceData, entryUidString);
|
deleteWIOriginalDataValue(sourceData, entryUidString);
|
||||||
|
// TODO: setWIOriginalDataValue
|
||||||
console.debug(`[WI Move] Removed entry UID ${entryUidString} from source '${sourceName}'.`);
|
console.debug(`[WI Move] Removed entry UID ${entryUidString} from source '${sourceName}'.`);
|
||||||
|
|
||||||
|
|
||||||
// Save immediately to reduce chances of inconsistency if the browser is closed
|
await saveWorldInfo(targetName, targetData);
|
||||||
// Note: This is not truly atomic. If one save fails, state could be inconsistent.
|
|
||||||
await saveWorldInfo(targetName, targetData, true);
|
|
||||||
console.debug(`[WI Move] Saved target lorebook '${targetName}'.`);
|
console.debug(`[WI Move] Saved target lorebook '${targetName}'.`);
|
||||||
await saveWorldInfo(sourceName, sourceData, true);
|
await saveWorldInfo(sourceName, sourceData);
|
||||||
console.debug(`[WI Move] Saved source lorebook '${sourceName}'.`);
|
console.debug(`[WI Move] Saved source lorebook '${sourceName}'.`);
|
||||||
|
|
||||||
|
|
||||||
toastr.success(t`${entryToMove.comment} moved successfully!`);
|
console.log(`[WI Move] ${entryToMove.comment} moved successfully to '${targetName}'.`);
|
||||||
|
|
||||||
// Check if the currently viewed book in the editor is the source or target and reload it
|
// Check if the currently viewed book in the editor is the source or target and reload it
|
||||||
const currentEditorBookIndex = Number($('#world_editor_select').val());
|
const currentEditorBookIndex = Number($('#world_editor_select').val());
|
||||||
|
Reference in New Issue
Block a user