Add button to bulk import all tags
| @@ -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 } from './tags.js'; | 21 | import { createTagInput, getTagKeyForEntity, getTagsList, printTagList, tag_map, compareTagsForSort, removeTagFromMap, importTags } from './tags.js'; |
| 22 | 22 | ||
| 23 | /** | 23 | /** |
| 24 | * Static object representing the actions of the | 24 | * Static object representing the actions of the |
| @@ -219,6 +219,9 @@ class BulkTagPopupHandler { | |||
| 219 | <i class="fa-solid fa-trash-can margin-right-10px"></i> | 219 | <i class="fa-solid fa-trash-can margin-right-10px"></i> |
| 220 | Mutual | 220 | Mutual |
| 221 | </div> | 221 | </div> |
| 222 | <div id="bulk_tag_popup_import_all_tags" class="menu_button" title="Import all tags from selected characters" data-i18n="[title]Import all tags from selected characters"> | ||
| 223 | Import All | ||
| 224 | </div> | ||
| 222 | <div id="bulk_tag_popup_cancel" class="menu_button" data-i18n="Cancel">Close</div> | 225 | <div id="bulk_tag_popup_cancel" class="menu_button" data-i18n="Cancel">Close</div> |
| 223 | </div> | 226 | </div> |
| 224 | </div> | 227 | </div> |
| @@ -254,6 +257,18 @@ class BulkTagPopupHandler { | |||
| 254 | document.querySelector('#bulk_tag_popup_reset').addEventListener('click', this.resetTags.bind(this)); | 257 | document.querySelector('#bulk_tag_popup_reset').addEventListener('click', this.resetTags.bind(this)); |
| 255 | document.querySelector('#bulk_tag_popup_remove_mutual').addEventListener('click', this.removeMutual.bind(this)); | 258 | document.querySelector('#bulk_tag_popup_remove_mutual').addEventListener('click', this.removeMutual.bind(this)); |
| 256 | document.querySelector('#bulk_tag_popup_cancel').addEventListener('click', this.hide.bind(this)); | 259 | document.querySelector('#bulk_tag_popup_cancel').addEventListener('click', this.hide.bind(this)); |
| 260 | document.querySelector('#bulk_tag_popup_import_all_tags').addEventListener('click', this.importAllTags.bind(this)); | ||
| 261 | } | ||
| 262 | |||
| 263 | /** | ||
| 264 | * Import all tags for all selected characters | ||
| 265 | */ | ||
| 266 | async importAllTags() { | ||
| 267 | for (const characterId of this.characterIds) { | ||
| 268 | await importTags(characters[characterId], { importAll: true }); | ||
| 269 | } | ||
| 270 | |||
| 271 | $('#bulkTagList').empty(); | ||
| 257 | } | 272 | } |
| 258 | 273 | ||
| 259 | /** | 274 | /** |
| @@ -708,12 +708,13 @@ 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 {boolean} [options.forceShow=false] - Whether to force showing the import dialog | 712 | * @param {boolean} [options.forceShow=false] - Whether to force showing the import dialog |
| 712 | * @returns {Promise<boolean>} Boolean indicating whether any tag was imported | 713 | * @returns {Promise<boolean>} Boolean indicating whether any tag was imported |
| 713 | */ | 714 | */ |
| 714 | async function importTags(character, { forceShow = false } = {}) { | 715 | async function importTags(character, { importAll = false, forceShow = false } = {}) { |
| 715 | // Gather the tags to import based on the selected setting | 716 | // Gather the tags to import based on the selected setting |
| 716 | const tagNamesToImport = await handleTagImport(character, { forceShow }); | 717 | const tagNamesToImport = await handleTagImport(character, { importAll, forceShow }); |
| 717 | if (!tagNamesToImport?.length) { | 718 | if (!tagNamesToImport?.length) { |
| 718 | console.debug('No tags to import'); | 719 | console.debug('No tags to import'); |
| 719 | return; | 720 | return; |
| @@ -732,10 +733,11 @@ async function importTags(character, { forceShow = false } = {}) { | |||
| 732 | * | 733 | * |
| 733 | * @param {Character} character - The character | 734 | * @param {Character} character - The character |
| 734 | * @param {object} [options] - Options | 735 | * @param {object} [options] - Options |
| 736 | * @param {boolean} [options.importAll=false] - Whether to import all tags without dialog | ||
| 735 | * @param {boolean} [options.forceShow=false] - Whether to force showing the import dialog | 737 | * @param {boolean} [options.forceShow=false] - Whether to force showing the import dialog |
| 736 | * @returns {Promise<string[]>} Array of strings representing the tags to import | 738 | * @returns {Promise<string[]>} Array of strings representing the tags to import |
| 737 | */ | 739 | */ |
| 738 | async function handleTagImport(character, { forceShow = false } = {}) { | 740 | async function handleTagImport(character, { importAll = false, forceShow = false } = {}) { |
| 739 | /** @type {string[]} */ | 741 | /** @type {string[]} */ |
| 740 | const importTags = character.tags.map(t => t.trim()).filter(t => t) | 742 | const importTags = character.tags.map(t => t.trim()).filter(t => t) |
| 741 | .filter(t => !IMPORT_EXLCUDED_TAGS.includes(t)) | 743 | .filter(t => !IMPORT_EXLCUDED_TAGS.includes(t)) |
| @@ -747,6 +749,7 @@ async function handleTagImport(character, { forceShow = false } = {}) { | |||
| 747 | 749 | ||
| 748 | // Choose the setting for this dialog. If from settings, verify the setting really exists, otherwise take "ASK". | 750 | // Choose the setting for this dialog. If from settings, verify the setting really exists, otherwise take "ASK". |
| 749 | const setting = forceShow ? tag_import_setting.ASK | 751 | const setting = forceShow ? tag_import_setting.ASK |
| 752 | : importAll ? tag_import_setting.ALL | ||
| 750 | : Object.values(tag_import_setting).find(setting => setting === power_user.tag_import_setting) ?? tag_import_setting.ASK; | 753 | : Object.values(tag_import_setting).find(setting => setting === power_user.tag_import_setting) ?? tag_import_setting.ASK; |
| 751 | 754 | ||
| 752 | switch (setting) { | 755 | switch (setting) { |