mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Add button to bulk import existing tags
This commit is contained in:
@ -200,7 +200,7 @@ class BulkTagPopupHandler {
|
|||||||
<div id="bulk_tag_popup">
|
<div id="bulk_tag_popup">
|
||||||
<div id="bulk_tag_popup_holder">
|
<div id="bulk_tag_popup_holder">
|
||||||
<h3 class="marginBot5">Modify tags of ${this.characterIds.length} characters</h3>
|
<h3 class="marginBot5">Modify tags of ${this.characterIds.length} characters</h3>
|
||||||
<small class="bulk_tags_desc m-b-1">Add or remove the mutual tags of all selected characters.</small>
|
<small class="bulk_tags_desc m-b-1">Add or remove the mutual tags of all selected characters. Import all or existing tags for all selected characters.</small>
|
||||||
<div id="bulk_tags_avatars_block" class="avatars_inline avatars_inline_small tags tags_inline"></div>
|
<div id="bulk_tags_avatars_block" class="avatars_inline avatars_inline_small tags tags_inline"></div>
|
||||||
<br>
|
<br>
|
||||||
<div id="bulk_tags_div" class="marginBot5" data-characters='${characterData}'>
|
<div id="bulk_tags_div" class="marginBot5" data-characters='${characterData}'>
|
||||||
@ -222,6 +222,9 @@ class BulkTagPopupHandler {
|
|||||||
<div id="bulk_tag_popup_import_all_tags" class="menu_button" title="Import all tags from selected characters" data-i18n="[title]Import all tags from selected characters">
|
<div id="bulk_tag_popup_import_all_tags" class="menu_button" title="Import all tags from selected characters" data-i18n="[title]Import all tags from selected characters">
|
||||||
Import All
|
Import All
|
||||||
</div>
|
</div>
|
||||||
|
<div id="bulk_tag_popup_import_existing_tags" class="menu_button" title="Import existing tags from selected characters" data-i18n="[title]Import existing tags from selected characters">
|
||||||
|
Import Existing
|
||||||
|
</div>
|
||||||
<div id="bulk_tag_popup_cancel" class="menu_button" data-i18n="Cancel">Close</div>
|
<div id="bulk_tag_popup_cancel" class="menu_button" data-i18n="Cancel">Close</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -258,6 +261,18 @@ class BulkTagPopupHandler {
|
|||||||
document.querySelector('#bulk_tag_popup_remove_mutual').addEventListener('click', this.removeMutual.bind(this));
|
document.querySelector('#bulk_tag_popup_remove_mutual').addEventListener('click', this.removeMutual.bind(this));
|
||||||
document.querySelector('#bulk_tag_popup_cancel').addEventListener('click', this.hide.bind(this));
|
document.querySelector('#bulk_tag_popup_cancel').addEventListener('click', this.hide.bind(this));
|
||||||
document.querySelector('#bulk_tag_popup_import_all_tags').addEventListener('click', this.importAllTags.bind(this));
|
document.querySelector('#bulk_tag_popup_import_all_tags').addEventListener('click', this.importAllTags.bind(this));
|
||||||
|
document.querySelector('#bulk_tag_popup_import_existing_tags').addEventListener('click', this.importExistingTags.bind(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Import existing tags for all selected characters
|
||||||
|
*/
|
||||||
|
async importExistingTags() {
|
||||||
|
for (const characterId of this.characterIds) {
|
||||||
|
await importTags(characters[characterId], { importExisting: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
$('#bulkTagList').empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -709,12 +709,13 @@ const ANTI_TROLL_MAX_TAGS = 15;
|
|||||||
* @param {Character} character - The character
|
* @param {Character} character - The character
|
||||||
* @param {object} [options] - Options
|
* @param {object} [options] - Options
|
||||||
* @param {boolean} [options.importAll=false] - Whether to import all tags without dialog
|
* @param {boolean} [options.importAll=false] - Whether to import all tags without dialog
|
||||||
|
* @param {boolean} [options.importExisting=false] - Whether to import existing tags without dialog
|
||||||
* @param {boolean} [options.forceShow=false] - Whether to force showing the import dialog
|
* @param {boolean} [options.forceShow=false] - Whether to force showing the import dialog
|
||||||
* @returns {Promise<boolean>} Boolean indicating whether any tag was imported
|
* @returns {Promise<boolean>} Boolean indicating whether any tag was imported
|
||||||
*/
|
*/
|
||||||
async function importTags(character, { importAll = false, forceShow = false } = {}) {
|
async function importTags(character, { importAll = false, importExisting = false, forceShow = false } = {}) {
|
||||||
// Gather the tags to import based on the selected setting
|
// Gather the tags to import based on the selected setting
|
||||||
const tagNamesToImport = await handleTagImport(character, { importAll, forceShow });
|
const tagNamesToImport = await handleTagImport(character, { importAll, importExisting, forceShow });
|
||||||
if (!tagNamesToImport?.length) {
|
if (!tagNamesToImport?.length) {
|
||||||
console.debug('No tags to import');
|
console.debug('No tags to import');
|
||||||
return;
|
return;
|
||||||
@ -734,10 +735,11 @@ async function importTags(character, { importAll = false, forceShow = false } =
|
|||||||
* @param {Character} character - The character
|
* @param {Character} character - The character
|
||||||
* @param {object} [options] - Options
|
* @param {object} [options] - Options
|
||||||
* @param {boolean} [options.importAll=false] - Whether to import all tags without dialog
|
* @param {boolean} [options.importAll=false] - Whether to import all tags without dialog
|
||||||
|
* @param {boolean} [options.importExisting=false] - Whether to import existing tags without dialog
|
||||||
* @param {boolean} [options.forceShow=false] - Whether to force showing the import dialog
|
* @param {boolean} [options.forceShow=false] - Whether to force showing the import dialog
|
||||||
* @returns {Promise<string[]>} Array of strings representing the tags to import
|
* @returns {Promise<string[]>} Array of strings representing the tags to import
|
||||||
*/
|
*/
|
||||||
async function handleTagImport(character, { importAll = false, forceShow = false } = {}) {
|
async function handleTagImport(character, { importAll = false, importExisting = false, forceShow = false } = {}) {
|
||||||
/** @type {string[]} */
|
/** @type {string[]} */
|
||||||
const importTags = character.tags.map(t => t.trim()).filter(t => t)
|
const importTags = character.tags.map(t => t.trim()).filter(t => t)
|
||||||
.filter(t => !IMPORT_EXLCUDED_TAGS.includes(t))
|
.filter(t => !IMPORT_EXLCUDED_TAGS.includes(t))
|
||||||
@ -750,7 +752,8 @@ async function handleTagImport(character, { importAll = false, forceShow = false
|
|||||||
// Choose the setting for this dialog. If from settings, verify the setting really exists, otherwise take "ASK".
|
// Choose the setting for this dialog. If from settings, verify the setting really exists, otherwise take "ASK".
|
||||||
const setting = forceShow ? tag_import_setting.ASK
|
const setting = forceShow ? tag_import_setting.ASK
|
||||||
: importAll ? tag_import_setting.ALL
|
: importAll ? tag_import_setting.ALL
|
||||||
: Object.values(tag_import_setting).find(setting => setting === power_user.tag_import_setting) ?? tag_import_setting.ASK;
|
: importExisting ? tag_import_setting.ONLY_EXISTING
|
||||||
|
: Object.values(tag_import_setting).find(setting => setting === power_user.tag_import_setting) ?? tag_import_setting.ASK;
|
||||||
|
|
||||||
switch (setting) {
|
switch (setting) {
|
||||||
case tag_import_setting.ALL:
|
case tag_import_setting.ALL:
|
||||||
|
Reference in New Issue
Block a user