mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-03-05 20:29:22 +01:00
Refactor tag import setting override
This commit is contained in:
parent
2d476d4461
commit
0f606642ce
@ -10738,7 +10738,7 @@ jQuery(async function () {
|
||||
}
|
||||
} break;
|
||||
case 'import_tags': {
|
||||
await importTags(characters[this_chid], { forceShow: true });
|
||||
await importTags(characters[this_chid], { importSetting: tag_import_setting.ASK });
|
||||
} break;
|
||||
/*case 'delete_button':
|
||||
popup_type = "del_ch";
|
||||
|
@ -18,7 +18,7 @@ import {
|
||||
import { favsToHotswap } from './RossAscends-mods.js';
|
||||
import { hideLoader, showLoader } from './loader.js';
|
||||
import { convertCharacterToPersona } from './personas.js';
|
||||
import { createTagInput, getTagKeyForEntity, getTagsList, printTagList, tag_map, compareTagsForSort, removeTagFromMap, importTags } from './tags.js';
|
||||
import { createTagInput, getTagKeyForEntity, getTagsList, printTagList, tag_map, compareTagsForSort, removeTagFromMap, importTags, tag_import_setting } from './tags.js';
|
||||
|
||||
/**
|
||||
* Static object representing the actions of the
|
||||
@ -269,7 +269,7 @@ class BulkTagPopupHandler {
|
||||
*/
|
||||
async importExistingTags() {
|
||||
for (const characterId of this.characterIds) {
|
||||
await importTags(characters[characterId], { importExisting: true });
|
||||
await importTags(characters[characterId], { importSetting: tag_import_setting.ONLY_EXISTING });
|
||||
}
|
||||
|
||||
$('#bulkTagList').empty();
|
||||
@ -280,7 +280,7 @@ class BulkTagPopupHandler {
|
||||
*/
|
||||
async importAllTags() {
|
||||
for (const characterId of this.characterIds) {
|
||||
await importTags(characters[characterId], { importAll: true });
|
||||
await importTags(characters[characterId], { importSetting: tag_import_setting.ALL });
|
||||
}
|
||||
|
||||
$('#bulkTagList').empty();
|
||||
|
@ -708,14 +708,12 @@ const ANTI_TROLL_MAX_TAGS = 15;
|
||||
*
|
||||
* @param {Character} character - The character
|
||||
* @param {object} [options] - Options
|
||||
* @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 {tag_import_setting} [options.importSetting=null] - Force a tag import setting
|
||||
* @returns {Promise<boolean>} Boolean indicating whether any tag was imported
|
||||
*/
|
||||
async function importTags(character, { importAll = false, importExisting = false, forceShow = false } = {}) {
|
||||
async function importTags(character, { importSetting = null } = {}) {
|
||||
// Gather the tags to import based on the selected setting
|
||||
const tagNamesToImport = await handleTagImport(character, { importAll, importExisting, forceShow });
|
||||
const tagNamesToImport = await handleTagImport(character, { importSetting });
|
||||
if (!tagNamesToImport?.length) {
|
||||
console.debug('No tags to import');
|
||||
return;
|
||||
@ -734,12 +732,10 @@ async function importTags(character, { importAll = false, importExisting = false
|
||||
*
|
||||
* @param {Character} character - The character
|
||||
* @param {object} [options] - Options
|
||||
* @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 {tag_import_setting} [options.importSetting=null] - Force a tag import setting
|
||||
* @returns {Promise<string[]>} Array of strings representing the tags to import
|
||||
*/
|
||||
async function handleTagImport(character, { importAll = false, importExisting = false, forceShow = false } = {}) {
|
||||
async function handleTagImport(character, { importSetting = null } = {}) {
|
||||
/** @type {string[]} */
|
||||
const importTags = character.tags.map(t => t.trim()).filter(t => t)
|
||||
.filter(t => !IMPORT_EXLCUDED_TAGS.includes(t))
|
||||
@ -749,17 +745,9 @@ async function handleTagImport(character, { importAll = false, importExisting =
|
||||
.map(newTag);
|
||||
const folderTags = getOpenBogusFolders();
|
||||
|
||||
// Choose the setting for this dialog. If from settings, verify the setting really exists, otherwise take "ASK".
|
||||
let setting;
|
||||
if (forceShow) {
|
||||
setting = tag_import_setting.ASK;
|
||||
} else if (importAll) {
|
||||
setting = tag_import_setting.ALL;
|
||||
} else if (importExisting) {
|
||||
setting = tag_import_setting.ONLY_EXISTING;
|
||||
} else {
|
||||
setting = Object.values(tag_import_setting).find(setting => setting === power_user.tag_import_setting) ?? tag_import_setting.ASK;
|
||||
}
|
||||
// Choose the setting for this dialog. First check override, then saved setting or finally use "ASK".
|
||||
const setting = importSetting ? importSetting :
|
||||
Object.values(tag_import_setting).find(setting => setting === power_user.tag_import_setting) ?? tag_import_setting.ASK;
|
||||
|
||||
switch (setting) {
|
||||
case tag_import_setting.ALL:
|
||||
|
Loading…
x
Reference in New Issue
Block a user