Add button to bulk import all tags

651072c61b29fa779f875081d11bb7e1aa338be4

d-ber <davide.bertalero@studenti.unimi.it>

2 files changed, +22 -4Showing whitespace changes
public/scripts/BulkEditOverlay.js+16 -1
@@ -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 } from './tags.js';
2222
2323/**
2424 * Static object representing the actions of the
@@ -219,6 +219,9 @@ 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>
222225 <div id="bulk_tag_popup_cancel" class="menu_button" data-i18n="Cancel">Close</div>
223226 </div>
224227 </div>
@@ -254,6 +257,18 @@ class BulkTagPopupHandler {
254257 document.querySelector('#bulk_tag_popup_reset').addEventListener('click', this.resetTags.bind(this));
255258 document.querySelector('#bulk_tag_popup_remove_mutual').addEventListener('click', this.removeMutual.bind(this));
256259 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();
257272 }
258273
259274 /**
public/scripts/tags.js+6 -3
@@ -708,12 +708,13 @@ const ANTI_TROLL_MAX_TAGS = 15;
708708 *
709709 * @param {Character} character - The character
710710 * @param {object} [options] - Options
711+ * @param {boolean} [options.importAll=false] - Whether to import all tags without dialog
711712 * @param {boolean} [options.forceShow=false] - Whether to force showing the import dialog
712713 * @returns {Promise<boolean>} Boolean indicating whether any tag was imported
713714 */
714715async function importTags(character, { importAll = false, forceShow = false } = {}) {
715716 // Gather the tags to import based on the selected setting
716717 const tagNamesToImport = await handleTagImport(character, { importAll, forceShow });
717718 if (!tagNamesToImport?.length) {
718719 console.debug('No tags to import');
719720 return;
@@ -732,10 +733,11 @@ async function importTags(character, { forceShow = false } = {}) {
732733 *
733734 * @param {Character} character - The character
734735 * @param {object} [options] - Options
736+ * @param {boolean} [options.importAll=false] - Whether to import all tags without dialog
735737 * @param {boolean} [options.forceShow=false] - Whether to force showing the import dialog
736738 * @returns {Promise<string[]>} Array of strings representing the tags to import
737739 */
738740async function handleTagImport(character, { importAll = false, forceShow = false } = {}) {
739741 /** @type {string[]} */
740742 const importTags = character.tags.map(t => t.trim()).filter(t => t)
741743 .filter(t => !IMPORT_EXLCUDED_TAGS.includes(t))
@@ -747,6 +749,7 @@ async function handleTagImport(character, { forceShow = false } = {}) {
747749
748750 // Choose the setting for this dialog. If from settings, verify the setting really exists, otherwise take "ASK".
749751 const setting = forceShow ? tag_import_setting.ASK
752+ : importAll ? tag_import_setting.ALL
750753 : Object.values(tag_import_setting).find(setting => setting === power_user.tag_import_setting) ?? tag_import_setting.ASK;
751754
752755 switch (setting) {