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