Add button to bulk import all tags

651072c61b29fa779f875081d11bb7e1aa338be4

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

2 files changed, +24 -6Ignore whitespace
public/scripts/BulkEditOverlay.js+17 -2
@@ -18,7 +18,7 @@ import {
18import { favsToHotswap } from './RossAscends-mods.js';18import { favsToHotswap } from './RossAscends-mods.js';
19import { hideLoader, showLoader } from './loader.js';19import { hideLoader, showLoader } from './loader.js';
20import { convertCharacterToPersona } from './personas.js';20import { convertCharacterToPersona } from './personas.js';
21import { createTagInput, getTagKeyForEntity, getTagsList, printTagList, tag_map, compareTagsForSort, removeTagFromMap } from './tags.js';21import { createTagInput, getTagKeyForEntity, getTagsList, printTagList, tag_map, compareTagsForSort, removeTagFromMap, importTags } from './tags.js';
2222
23/**23/**
24 * Static object representing the actions of the24 * 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 Mutual220 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 }
258273
259 /**274 /**
@@ -570,7 +585,7 @@ class BulkEditOverlay {
570 this.container.removeEventListener('mouseup', cancelHold);585 this.container.removeEventListener('mouseup', cancelHold);
571 this.container.removeEventListener('touchend', cancelHold);586 this.container.removeEventListener('touchend', cancelHold);
572 },587 },
573 BulkEditOverlay.longPressDelay);588 BulkEditOverlay.longPressDelay);
574 };589 };
575590
576 handleLongPressEnd = (event) => {591 handleLongPressEnd = (event) => {
public/scripts/tags.js+7 -4
@@ -708,12 +708,13 @@ const ANTI_TROLL_MAX_TAGS = 15;
708 *708 *
709 * @param {Character} character - The character709 * @param {Character} character - The character
710 * @param {object} [options] - Options710 * @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 dialog712 * @param {boolean} [options.forceShow=false] - Whether to force showing the import dialog
712 * @returns {Promise<boolean>} Boolean indicating whether any tag was imported713 * @returns {Promise<boolean>} Boolean indicating whether any tag was imported
713 */714 */
714async function importTags(character, { forceShow = false } = {}) {715async function importTags(character, { importAll = false, forceShow = false } = {}) {
715 // Gather the tags to import based on the selected setting716 // 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 character734 * @param {Character} character - The character
734 * @param {object} [options] - Options735 * @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 dialog737 * @param {boolean} [options.forceShow=false] - Whether to force showing the import dialog
736 * @returns {Promise<string[]>} Array of strings representing the tags to import738 * @returns {Promise<string[]>} Array of strings representing the tags to import
737 */739 */
738async function handleTagImport(character, { forceShow = false } = {}) {740async 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,7 +749,8 @@ async function handleTagImport(character, { forceShow = false } = {}) {
747749
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.ASK751 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;
751754
752 switch (setting) {755 switch (setting) {
753 case tag_import_setting.ALL:756 case tag_import_setting.ALL: