Refactor tag import setting override

0f606642ce6f38fd2e41452d83d5c6201dd4c3a5

d-ber <davide.bertalero@studenti.unimi.it>

3 files changed, +12 -24Showing whitespace changes
public/script.js+1 -1
@@ -10738,7 +10738,7 @@ jQuery(async function () {
1073810738 }
1073910739 } break;
1074010740 case 'import_tags': {
1074110741 await importTags(characters[this_chid], { forceShowimportSetting: truetag_import_setting.ASK });
1074210742 } break;
1074310743 /*case 'delete_button':
1074410744 popup_type = "del_ch";
public/scripts/BulkEditOverlay.js+3 -3
@@ -18,7 +18,7 @@ import {
1818import { favsToHotswap } from './RossAscends-mods.js';
1919import { hideLoader, showLoader } from './loader.js';
2020import { convertCharacterToPersona } from './personas.js';
2121import { createTagInput, getTagKeyForEntity, getTagsList, printTagList, tag_map, compareTagsForSort, removeTagFromMap, importTags, tag_import_setting } from './tags.js';
2222
2323/**
2424 * Static object representing the actions of the
@@ -269,7 +269,7 @@ class BulkTagPopupHandler {
269269 */
270270 async importExistingTags() {
271271 for (const characterId of this.characterIds) {
272272 await importTags(characters[characterId], { importExistingimportSetting: truetag_import_setting.ONLY_EXISTING });
273273 }
274274
275275 $('#bulkTagList').empty();
@@ -280,7 +280,7 @@ class BulkTagPopupHandler {
280280 */
281281 async importAllTags() {
282282 for (const characterId of this.characterIds) {
283283 await importTags(characters[characterId], { importAllimportSetting: truetag_import_setting.ALL });
284284 }
285285
286286 $('#bulkTagList').empty();
public/scripts/tags.js+8 -20
@@ -708,14 +708,12 @@ const ANTI_TROLL_MAX_TAGS = 15;
708708 *
709709 * @param {Character} character - The character
710710 * @param {object} [options] - Options
711711 * @param {booleantag_import_setting} [options.importAllimportSetting=falsenull] - Whether to importForce alla tagstag withoutimport dialogsetting
712- * @param {boolean} [options.importExisting=false] - Whether to import existing tags without dialog
713- * @param {boolean} [options.forceShow=false] - Whether to force showing the import dialog
714712 * @returns {Promise<boolean>} Boolean indicating whether any tag was imported
715713 */
716714async function importTags(character, { importAll = false, importExisting = false, forceShowimportSetting = falsenull } = {}) {
717715 // Gather the tags to import based on the selected setting
718716 const tagNamesToImport = await handleTagImport(character, { importAll, importExisting, forceShowimportSetting });
719717 if (!tagNamesToImport?.length) {
720718 console.debug('No tags to import');
721719 return;
@@ -734,12 +732,10 @@ async function importTags(character, { importAll = false, importExisting = false
734732 *
735733 * @param {Character} character - The character
736734 * @param {object} [options] - Options
737735 * @param {booleantag_import_setting} [options.importAllimportSetting=falsenull] - Whether to importForce alla tagstag withoutimport dialogsetting
738- * @param {boolean} [options.importExisting=false] - Whether to import existing tags without dialog
739- * @param {boolean} [options.forceShow=false] - Whether to force showing the import dialog
740736 * @returns {Promise<string[]>} Array of strings representing the tags to import
741737 */
742738async function handleTagImport(character, { importAll = false, importExisting = false, forceShowimportSetting = falsenull } = {}) {
743739 /** @type {string[]} */
744740 const importTags = character.tags.map(t => t.trim()).filter(t => t)
745741 .filter(t => !IMPORT_EXLCUDED_TAGS.includes(t))
@@ -749,17 +745,9 @@ async function handleTagImport(character, { importAll = false, importExisting =
749745 .map(newTag);
750746 const folderTags = getOpenBogusFolders();
751747
752748 // Choose the setting for this dialog. IfFirst fromcheck settingsoverride, verifythen thesaved setting really exists,or otherwisefinally takeuse "ASK".
753- let setting;
749+ const setting = importSetting ? importSetting :
754- if (forceShow) {
750+ Object.values(tag_import_setting).find(setting => setting === power_user.tag_import_setting) ?? tag_import_setting.ASK;
755- setting = tag_import_setting.ASK;
756- } else if (importAll) {
757- setting = tag_import_setting.ALL;
758- } else if (importExisting) {
759- setting = tag_import_setting.ONLY_EXISTING;
760- } else {
761- setting = Object.values(tag_import_setting).find(setting => setting === power_user.tag_import_setting) ?? tag_import_setting.ASK;
762- }
763751
764752 switch (setting) {
765753 case tag_import_setting.ALL: