Add button to bulk import all tags
| @@ -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 } from './tags.js'; |
| 22 | 22 | |
| 23 | 23 | /** |
| 24 | 24 | * Static object representing the actions of the |
| @@ -219,6 +219,9 @@ class BulkTagPopupHandler { | ||
| 219 | 219 | <i class="fa-solid fa-trash-can margin-right-10px"></i> |
| 220 | 220 | Mutual |
| 221 | 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 | 225 | <div id="bulk_tag_popup_cancel" class="menu_button" data-i18n="Cancel">Close</div> |
| 223 | 226 | </div> |
| 224 | 227 | </div> |
| @@ -254,6 +257,18 @@ class BulkTagPopupHandler { | ||
| 254 | 257 | document.querySelector('#bulk_tag_popup_reset').addEventListener('click', this.resetTags.bind(this)); |
| 255 | 258 | document.querySelector('#bulk_tag_popup_remove_mutual').addEventListener('click', this.removeMutual.bind(this)); |
| 256 | 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 | /** |
| @@ -570,7 +585,7 @@ class BulkEditOverlay { | ||
| 570 | 585 | this.container.removeEventListener('mouseup', cancelHold); |
| 571 | 586 | this.container.removeEventListener('touchend', cancelHold); |
| 572 | 587 | }, |
| 573 | 588 | BulkEditOverlay.longPressDelay); |
| 574 | 589 | }; |
| 575 | 590 | |
| 576 | 591 | handleLongPressEnd = (event) => { |
| @@ -708,12 +708,13 @@ const ANTI_TROLL_MAX_TAGS = 15; | ||
| 708 | 708 | * |
| 709 | 709 | * @param {Character} character - The character |
| 710 | 710 | * @param {object} [options] - Options |
| 711 | + * @param {boolean} [options.importAll=false] - Whether to import all tags without dialog | |
| 711 | 712 | * @param {boolean} [options.forceShow=false] - Whether to force showing the import dialog |
| 712 | 713 | * @returns {Promise<boolean>} Boolean indicating whether any tag was imported |
| 713 | 714 | */ |
| 714 | 715 | async function importTags(character, { importAll = false, forceShow = false } = {}) { |
| 715 | 716 | // Gather the tags to import based on the selected setting |
| 716 | 717 | const tagNamesToImport = await handleTagImport(character, { importAll, forceShow }); |
| 717 | 718 | if (!tagNamesToImport?.length) { |
| 718 | 719 | console.debug('No tags to import'); |
| 719 | 720 | return; |
| @@ -732,10 +733,11 @@ async function importTags(character, { forceShow = false } = {}) { | ||
| 732 | 733 | * |
| 733 | 734 | * @param {Character} character - The character |
| 734 | 735 | * @param {object} [options] - Options |
| 736 | + * @param {boolean} [options.importAll=false] - Whether to import all tags without dialog | |
| 735 | 737 | * @param {boolean} [options.forceShow=false] - Whether to force showing the import dialog |
| 736 | 738 | * @returns {Promise<string[]>} Array of strings representing the tags to import |
| 737 | 739 | */ |
| 738 | 740 | async function handleTagImport(character, { importAll = false, forceShow = false } = {}) { |
| 739 | 741 | /** @type {string[]} */ |
| 740 | 742 | const importTags = character.tags.map(t => t.trim()).filter(t => t) |
| 741 | 743 | .filter(t => !IMPORT_EXLCUDED_TAGS.includes(t)) |
| @@ -747,7 +749,8 @@ async function handleTagImport(character, { forceShow = false } = {}) { | ||
| 747 | 749 | |
| 748 | 750 | // Choose the setting for this dialog. If from settings, verify the setting really exists, otherwise take "ASK". |
| 749 | 751 | const setting = forceShow ? tag_import_setting.ASK |
| 750 | - : Object.values(tag_import_setting).find(setting => setting === power_user.tag_import_setting) ?? tag_import_setting.ASK; | |
| 752 | + : importAll ? tag_import_setting.ALL | |
| 753 | + : Object.values(tag_import_setting).find(setting => setting === power_user.tag_import_setting) ?? tag_import_setting.ASK; | |
| 751 | 754 | |
| 752 | 755 | switch (setting) { |
| 753 | 756 | case tag_import_setting.ALL: |