mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Add toastr click popup on tag restore warnings
This commit is contained in:
@@ -1436,13 +1436,13 @@ async function onTagRestoreFileSelect(e) {
|
|||||||
const data = await parseJsonFile(file);
|
const data = await parseJsonFile(file);
|
||||||
|
|
||||||
if (!data) {
|
if (!data) {
|
||||||
toastr.warning('Empty file data', 'Tag restore');
|
toastr.warning('Empty file data', 'Tag Restore');
|
||||||
console.log('Tag restore: File data empty.');
|
console.log('Tag restore: File data empty.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!data.tags || !data.tag_map || !Array.isArray(data.tags) || typeof data.tag_map !== 'object') {
|
if (!data.tags || !data.tag_map || !Array.isArray(data.tags) || typeof data.tag_map !== 'object') {
|
||||||
toastr.warning('Invalid file format', 'Tag restore');
|
toastr.warning('Invalid file format', 'Tag Restore');
|
||||||
console.log('Tag restore: Invalid file format.');
|
console.log('Tag restore: Invalid file format.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1450,7 +1450,8 @@ async function onTagRestoreFileSelect(e) {
|
|||||||
// Prompt user if they want to overwrite existing tags
|
// Prompt user if they want to overwrite existing tags
|
||||||
let overwrite = false;
|
let overwrite = false;
|
||||||
if (tags.length > 0) {
|
if (tags.length > 0) {
|
||||||
const result = await Popup.show.confirm('Tag Restore', 'You have existing tags. If the backup contains any of those tags, to you want the backup to overwrite your current tags?', { okButton: 'Overwrite', cancelButton: 'Keep' })
|
const result = await Popup.show.confirm('Tag Restore', 'You have existing tags. If the backup contains any of those tags, to you want the backup to overwrite your current tags?',
|
||||||
|
{ okButton: 'Overwrite', cancelButton: 'Keep' });
|
||||||
overwrite = result === POPUP_RESULT.AFFIRMATIVE;
|
overwrite = result === POPUP_RESULT.AFFIRMATIVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1463,13 +1464,14 @@ async function onTagRestoreFileSelect(e) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tags.find(x => x.id === tag.id)) {
|
const existingTag = tags.find(x => x.id === tag.id);
|
||||||
|
if (existingTag) {
|
||||||
if (!overwrite) {
|
if (!overwrite) {
|
||||||
warnings.push(`Tag with id ${tag.id} already exists.`);
|
warnings.push(`Tag with id ${tag.id} already exists.`);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// On overwrite, we remove and re-add the tag
|
// On overwrite, we remove and re-add the tag
|
||||||
removeFromArray(tags, tag);
|
removeFromArray(tags, existingTag);
|
||||||
}
|
}
|
||||||
|
|
||||||
tags.push(tag);
|
tags.push(tag);
|
||||||
@@ -1502,10 +1504,13 @@ async function onTagRestoreFileSelect(e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (warnings.length) {
|
if (warnings.length) {
|
||||||
toastr.success('Tags restored with warnings. Check console for details.', 'Tag restore');
|
toastr.warning('Tags restored with warnings. Check console or click on this message for details.', 'Tag Restore', {
|
||||||
|
timeOut: toastr.options.timeOut * 2, // Display double the time
|
||||||
|
onclick: () => Popup.show.text('Tag Restore Warnings', `<samp class="justifyLeft">${warnings.join('<br />')}<samp>`, { allowVerticalScrolling: true }),
|
||||||
|
});
|
||||||
console.warn(`TAG RESTORE REPORT\n====================\n${warnings.join('\n')}`);
|
console.warn(`TAG RESTORE REPORT\n====================\n${warnings.join('\n')}`);
|
||||||
} else {
|
} else {
|
||||||
toastr.success('Tags restored successfully.', 'Tag restore');
|
toastr.success('Tags restored successfully.', 'Tag Restore');
|
||||||
}
|
}
|
||||||
|
|
||||||
$('#tag_view_restore_input').val('');
|
$('#tag_view_restore_input').val('');
|
||||||
|
@@ -470,6 +470,13 @@ kbd {
|
|||||||
line-height: 1;
|
line-height: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
samp {
|
||||||
|
display: block;
|
||||||
|
font-family: var(--monoFontFamily);
|
||||||
|
white-space: pre-wrap;
|
||||||
|
text-align: start;
|
||||||
|
justify-content: left;
|
||||||
|
}
|
||||||
|
|
||||||
hr {
|
hr {
|
||||||
background-image: linear-gradient(90deg, var(--transparent), var(--SmartThemeBodyColor), var(--transparent));
|
background-image: linear-gradient(90deg, var(--transparent), var(--SmartThemeBodyColor), var(--transparent));
|
||||||
|
Reference in New Issue
Block a user