mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-03-06 04:38:21 +01:00
Refactor tag import setting override
This commit is contained in:
parent
2d476d4461
commit
0f606642ce
@ -10738,7 +10738,7 @@ jQuery(async function () {
|
|||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
case 'import_tags': {
|
case 'import_tags': {
|
||||||
await importTags(characters[this_chid], { forceShow: true });
|
await importTags(characters[this_chid], { importSetting: tag_import_setting.ASK });
|
||||||
} break;
|
} break;
|
||||||
/*case 'delete_button':
|
/*case 'delete_button':
|
||||||
popup_type = "del_ch";
|
popup_type = "del_ch";
|
||||||
|
@ -18,7 +18,7 @@ import {
|
|||||||
import { favsToHotswap } from './RossAscends-mods.js';
|
import { favsToHotswap } from './RossAscends-mods.js';
|
||||||
import { hideLoader, showLoader } from './loader.js';
|
import { hideLoader, showLoader } from './loader.js';
|
||||||
import { convertCharacterToPersona } from './personas.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
|
* Static object representing the actions of the
|
||||||
@ -269,7 +269,7 @@ class BulkTagPopupHandler {
|
|||||||
*/
|
*/
|
||||||
async importExistingTags() {
|
async importExistingTags() {
|
||||||
for (const characterId of this.characterIds) {
|
for (const characterId of this.characterIds) {
|
||||||
await importTags(characters[characterId], { importExisting: true });
|
await importTags(characters[characterId], { importSetting: tag_import_setting.ONLY_EXISTING });
|
||||||
}
|
}
|
||||||
|
|
||||||
$('#bulkTagList').empty();
|
$('#bulkTagList').empty();
|
||||||
@ -280,7 +280,7 @@ class BulkTagPopupHandler {
|
|||||||
*/
|
*/
|
||||||
async importAllTags() {
|
async importAllTags() {
|
||||||
for (const characterId of this.characterIds) {
|
for (const characterId of this.characterIds) {
|
||||||
await importTags(characters[characterId], { importAll: true });
|
await importTags(characters[characterId], { importSetting: tag_import_setting.ALL });
|
||||||
}
|
}
|
||||||
|
|
||||||
$('#bulkTagList').empty();
|
$('#bulkTagList').empty();
|
||||||
|
@ -708,14 +708,12 @@ 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 {tag_import_setting} [options.importSetting=null] - Force a tag import setting
|
||||||
* @param {boolean} [options.importExisting=false] - Whether to import existing tags without 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, importExisting = false, forceShow = false } = {}) {
|
async function importTags(character, { importSetting = null } = {}) {
|
||||||
// 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, importExisting, forceShow });
|
const tagNamesToImport = await handleTagImport(character, { importSetting });
|
||||||
if (!tagNamesToImport?.length) {
|
if (!tagNamesToImport?.length) {
|
||||||
console.debug('No tags to import');
|
console.debug('No tags to import');
|
||||||
return;
|
return;
|
||||||
@ -734,12 +732,10 @@ async function importTags(character, { importAll = false, importExisting = 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 {tag_import_setting} [options.importSetting=null] - Force a tag import setting
|
||||||
* @param {boolean} [options.importExisting=false] - Whether to import existing tags without 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, importExisting = false, forceShow = false } = {}) {
|
async function handleTagImport(character, { importSetting = null } = {}) {
|
||||||
/** @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))
|
||||||
@ -749,17 +745,9 @@ async function handleTagImport(character, { importAll = false, importExisting =
|
|||||||
.map(newTag);
|
.map(newTag);
|
||||||
const folderTags = getOpenBogusFolders();
|
const folderTags = getOpenBogusFolders();
|
||||||
|
|
||||||
// Choose the setting for this dialog. If from settings, verify the setting really exists, otherwise take "ASK".
|
// Choose the setting for this dialog. First check override, then saved setting or finally use "ASK".
|
||||||
let setting;
|
const setting = importSetting ? importSetting :
|
||||||
if (forceShow) {
|
Object.values(tag_import_setting).find(setting => setting === power_user.tag_import_setting) ?? tag_import_setting.ASK;
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (setting) {
|
switch (setting) {
|
||||||
case tag_import_setting.ALL:
|
case tag_import_setting.ALL:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user