Merge pull request #2663 from d-ber/bulkTagImport Add bulk tag import

d57272c166c58ad5a83513cb32430d6920c9a8cd

Cohee <18619528+Cohee1207@users.noreply.github.com>

Signed
4 files changed, +44 -14Ignore whitespace
public/css/character-group-overlay.css+1 -1
@@ -99,6 +99,6 @@
9999}
100100
101101#bulk_tag_shadow_popup #bulk_tag_popup #dialogue_popup_controls .menu_button {
102102 width: 100pxunset;
103103 padding: 0.25em;
104104}
public/script.js+1 -1
@@ -10740,7 +10740,7 @@ jQuery(async function () {
1074010740 }
1074110741 } break;
1074210742 case 'import_tags': {
1074310743 await importTags(characters[this_chid], { forceShowimportSetting: truetag_import_setting.ASK });
1074410744 } break;
1074510745 /*case 'delete_button':
1074610746 popup_type = "del_ch";
public/scripts/BulkEditOverlay.js+34 -4
@@ -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
@@ -197,10 +197,10 @@ class BulkTagPopupHandler {
197197 #getHtml = () => {
198198 const characterData = JSON.stringify({ characterIds: this.characterIds });
199199 return `<div id="bulk_tag_shadow_popup">
200200 <div id="bulk_tag_popup" class="wider_dialogue_popup">
201201 <div id="bulk_tag_popup_holder">
202202 <h3 class="marginBot5">Modify tags of ${this.characterIds.length} characters</h3>
203203 <small class="bulk_tags_desc m-b-1">Add or remove the mutual tags of all selected characters. Import all or existing tags for all selected characters.</small>
204204 <div id="bulk_tags_avatars_block" class="avatars_inline avatars_inline_small tags tags_inline"></div>
205205 <br>
206206 <div id="bulk_tags_div" class="marginBot5" data-characters='${characterData}'>
@@ -219,6 +219,12 @@ class BulkTagPopupHandler {
219219 <i class="fa-solid fa-trash-can margin-right-10px"></i>
220220 Mutual
221221 </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>
225+ <div id="bulk_tag_popup_import_existing_tags" class="menu_button" title="Import existing tags from selected characters" data-i18n="[title]Import existing tags from selected characters">
226+ Import Existing
227+ </div>
222228 <div id="bulk_tag_popup_cancel" class="menu_button" data-i18n="Cancel">Close</div>
223229 </div>
224230 </div>
@@ -254,6 +260,30 @@ class BulkTagPopupHandler {
254260 document.querySelector('#bulk_tag_popup_reset').addEventListener('click', this.resetTags.bind(this));
255261 document.querySelector('#bulk_tag_popup_remove_mutual').addEventListener('click', this.removeMutual.bind(this));
256262 document.querySelector('#bulk_tag_popup_cancel').addEventListener('click', this.hide.bind(this));
263+ document.querySelector('#bulk_tag_popup_import_all_tags').addEventListener('click', this.importAllTags.bind(this));
264+ document.querySelector('#bulk_tag_popup_import_existing_tags').addEventListener('click', this.importExistingTags.bind(this));
265+ }
266+
267+ /**
268+ * Import existing tags for all selected characters
269+ */
270+ async importExistingTags() {
271+ for (const characterId of this.characterIds) {
272+ await importTags(characters[characterId], { importSetting: tag_import_setting.ONLY_EXISTING });
273+ }
274+
275+ $('#bulkTagList').empty();
276+ }
277+
278+ /**
279+ * Import all tags for all selected characters
280+ */
281+ async importAllTags() {
282+ for (const characterId of this.characterIds) {
283+ await importTags(characters[characterId], { importSetting: tag_import_setting.ALL });
284+ }
285+
286+ $('#bulkTagList').empty();
257287 }
258288
259289 /**
@@ -570,7 +600,7 @@ class BulkEditOverlay {
570600 this.container.removeEventListener('mouseup', cancelHold);
571601 this.container.removeEventListener('touchend', cancelHold);
572602 },
573603 BulkEditOverlay.longPressDelay);
574604 };
575605
576606 handleLongPressEnd = (event) => {
public/scripts/tags.js+8 -8
@@ -708,12 +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.forceShowimportSetting=falsenull] - Whether to forceForce showinga thetag import dialogsetting
712712 * @returns {Promise<boolean>} Boolean indicating whether any tag was imported
713713 */
714714async function importTags(character, { forceShowimportSetting = falsenull } = {}) {
715715 // Gather the tags to import based on the selected setting
716716 const tagNamesToImport = await handleTagImport(character, { forceShowimportSetting });
717717 if (!tagNamesToImport?.length) {
718718 console.debug('No tags to import');
719719 return;
@@ -732,10 +732,10 @@ async function importTags(character, { forceShow = false } = {}) {
732732 *
733733 * @param {Character} character - The character
734734 * @param {object} [options] - Options
735735 * @param {booleantag_import_setting} [options.forceShowimportSetting=falsenull] - Whether to forceForce showinga thetag import dialogsetting
736736 * @returns {Promise<string[]>} Array of strings representing the tags to import
737737 */
738738async function handleTagImport(character, { forceShowimportSetting = falsenull } = {}) {
739739 /** @type {string[]} */
740740 const importTags = character.tags.map(t => t.trim()).filter(t => t)
741741 .filter(t => !IMPORT_EXLCUDED_TAGS.includes(t))
@@ -745,9 +745,9 @@ async function handleTagImport(character, { forceShow = false } = {}) {
745745 .map(newTag);
746746 const folderTags = getOpenBogusFolders();
747747
748748 // Choose the setting for this dialog. IfFirst fromcheck settingsoverride, verifythen thesaved setting really exists,or otherwisefinally takeuse "ASK".
749749 const setting = forceShowimportSetting ? tag_import_setting.ASKimportSetting :
750750 : Object.values(tag_import_setting).find(setting => setting === power_user.tag_import_setting) ?? tag_import_setting.ASK;
751751
752752 switch (setting) {
753753 case tag_import_setting.ALL: