Refactor tag import setting override
| @@ -10738,7 +10738,7 @@ jQuery(async function () { | ||
| 10738 | 10738 | } |
| 10739 | 10739 | } break; |
| 10740 | 10740 | case 'import_tags': { |
| 10741 | 10741 | await importTags(characters[this_chid], { forceShowimportSetting: truetag_import_setting.ASK }); |
| 10742 | 10742 | } break; |
| 10743 | 10743 | /*case 'delete_button': |
| 10744 | 10744 | popup_type = "del_ch"; |
| @@ -18,7 +18,7 @@ import { | ||
| 18 | 18 | import { favsToHotswap } from './RossAscends-mods.js'; |
| 19 | 19 | import { hideLoader, showLoader } from './loader.js'; |
| 20 | 20 | import { convertCharacterToPersona } from './personas.js'; |
| 21 | 21 | import { createTagInput, getTagKeyForEntity, getTagsList, printTagList, tag_map, compareTagsForSort, removeTagFromMap, importTags, tag_import_setting } from './tags.js'; |
| 22 | 22 | |
| 23 | 23 | /** |
| 24 | 24 | * Static object representing the actions of the |
| @@ -269,7 +269,7 @@ class BulkTagPopupHandler { | ||
| 269 | 269 | */ |
| 270 | 270 | async importExistingTags() { |
| 271 | 271 | for (const characterId of this.characterIds) { |
| 272 | 272 | await importTags(characters[characterId], { importExistingimportSetting: truetag_import_setting.ONLY_EXISTING }); |
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | $('#bulkTagList').empty(); |
| @@ -280,7 +280,7 @@ class BulkTagPopupHandler { | ||
| 280 | 280 | */ |
| 281 | 281 | async importAllTags() { |
| 282 | 282 | for (const characterId of this.characterIds) { |
| 283 | 283 | await importTags(characters[characterId], { importAllimportSetting: truetag_import_setting.ALL }); |
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | $('#bulkTagList').empty(); |
| @@ -708,14 +708,12 @@ const ANTI_TROLL_MAX_TAGS = 15; | ||
| 708 | 708 | * |
| 709 | 709 | * @param {Character} character - The character |
| 710 | 710 | * @param {object} [options] - Options |
| 711 | 711 | * @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 | |
| 714 | 712 | * @returns {Promise<boolean>} Boolean indicating whether any tag was imported |
| 715 | 713 | */ |
| 716 | 714 | async function importTags(character, { importAll = false, importExisting = false, forceShowimportSetting = falsenull } = {}) { |
| 717 | 715 | // Gather the tags to import based on the selected setting |
| 718 | 716 | const tagNamesToImport = await handleTagImport(character, { importAll, importExisting, forceShowimportSetting }); |
| 719 | 717 | if (!tagNamesToImport?.length) { |
| 720 | 718 | console.debug('No tags to import'); |
| 721 | 719 | return; |
| @@ -734,12 +732,10 @@ async function importTags(character, { importAll = false, importExisting = false | ||
| 734 | 732 | * |
| 735 | 733 | * @param {Character} character - The character |
| 736 | 734 | * @param {object} [options] - Options |
| 737 | 735 | * @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 | |
| 740 | 736 | * @returns {Promise<string[]>} Array of strings representing the tags to import |
| 741 | 737 | */ |
| 742 | 738 | async function handleTagImport(character, { importAll = false, importExisting = false, forceShowimportSetting = falsenull } = {}) { |
| 743 | 739 | /** @type {string[]} */ |
| 744 | 740 | const importTags = character.tags.map(t => t.trim()).filter(t => t) |
| 745 | 741 | .filter(t => !IMPORT_EXLCUDED_TAGS.includes(t)) |
| @@ -749,17 +745,9 @@ async function handleTagImport(character, { importAll = false, importExisting = | ||
| 749 | 745 | .map(newTag); |
| 750 | 746 | const folderTags = getOpenBogusFolders(); |
| 751 | 747 | |
| 752 | 748 | // 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 | - } | |
| 763 | 751 | |
| 764 | 752 | switch (setting) { |
| 765 | 753 | case tag_import_setting.ALL: |