mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-03-03 03:17:54 +01:00
Add button to bulk import all tags
This commit is contained in:
parent
3b46b5a46d
commit
651072c61b
@ -18,7 +18,7 @@ import {
|
|||||||
import { favsToHotswap } from './RossAscends-mods.js';
|
import { favsToHotswap } from './RossAscends-mods.js';
|
||||||
import { hideLoader, showLoader } from './loader.js';
|
import { hideLoader, showLoader } from './loader.js';
|
||||||
import { convertCharacterToPersona } from './personas.js';
|
import { convertCharacterToPersona } from './personas.js';
|
||||||
import { createTagInput, getTagKeyForEntity, getTagsList, printTagList, tag_map, compareTagsForSort, removeTagFromMap } from './tags.js';
|
import { createTagInput, getTagKeyForEntity, getTagsList, printTagList, tag_map, compareTagsForSort, removeTagFromMap, importTags } from './tags.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Static object representing the actions of the
|
* Static object representing the actions of the
|
||||||
@ -219,6 +219,9 @@ class BulkTagPopupHandler {
|
|||||||
<i class="fa-solid fa-trash-can margin-right-10px"></i>
|
<i class="fa-solid fa-trash-can margin-right-10px"></i>
|
||||||
Mutual
|
Mutual
|
||||||
</div>
|
</div>
|
||||||
|
<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">
|
||||||
|
Import All
|
||||||
|
</div>
|
||||||
<div id="bulk_tag_popup_cancel" class="menu_button" data-i18n="Cancel">Close</div>
|
<div id="bulk_tag_popup_cancel" class="menu_button" data-i18n="Cancel">Close</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -254,6 +257,18 @@ class BulkTagPopupHandler {
|
|||||||
document.querySelector('#bulk_tag_popup_reset').addEventListener('click', this.resetTags.bind(this));
|
document.querySelector('#bulk_tag_popup_reset').addEventListener('click', this.resetTags.bind(this));
|
||||||
document.querySelector('#bulk_tag_popup_remove_mutual').addEventListener('click', this.removeMutual.bind(this));
|
document.querySelector('#bulk_tag_popup_remove_mutual').addEventListener('click', this.removeMutual.bind(this));
|
||||||
document.querySelector('#bulk_tag_popup_cancel').addEventListener('click', this.hide.bind(this));
|
document.querySelector('#bulk_tag_popup_cancel').addEventListener('click', this.hide.bind(this));
|
||||||
|
document.querySelector('#bulk_tag_popup_import_all_tags').addEventListener('click', this.importAllTags.bind(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Import all tags for all selected characters
|
||||||
|
*/
|
||||||
|
async importAllTags() {
|
||||||
|
for (const characterId of this.characterIds) {
|
||||||
|
await importTags(characters[characterId], { importAll: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
$('#bulkTagList').empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -570,7 +585,7 @@ class BulkEditOverlay {
|
|||||||
this.container.removeEventListener('mouseup', cancelHold);
|
this.container.removeEventListener('mouseup', cancelHold);
|
||||||
this.container.removeEventListener('touchend', cancelHold);
|
this.container.removeEventListener('touchend', cancelHold);
|
||||||
},
|
},
|
||||||
BulkEditOverlay.longPressDelay);
|
BulkEditOverlay.longPressDelay);
|
||||||
};
|
};
|
||||||
|
|
||||||
handleLongPressEnd = (event) => {
|
handleLongPressEnd = (event) => {
|
||||||
|
@ -708,12 +708,13 @@ const ANTI_TROLL_MAX_TAGS = 15;
|
|||||||
*
|
*
|
||||||
* @param {Character} character - The character
|
* @param {Character} character - The character
|
||||||
* @param {object} [options] - Options
|
* @param {object} [options] - Options
|
||||||
|
* @param {boolean} [options.importAll=false] - Whether to import all tags without dialog
|
||||||
* @param {boolean} [options.forceShow=false] - Whether to force showing the import dialog
|
* @param {boolean} [options.forceShow=false] - Whether to force showing the import dialog
|
||||||
* @returns {Promise<boolean>} Boolean indicating whether any tag was imported
|
* @returns {Promise<boolean>} Boolean indicating whether any tag was imported
|
||||||
*/
|
*/
|
||||||
async function importTags(character, { forceShow = false } = {}) {
|
async function importTags(character, { importAll = false, forceShow = false } = {}) {
|
||||||
// Gather the tags to import based on the selected setting
|
// Gather the tags to import based on the selected setting
|
||||||
const tagNamesToImport = await handleTagImport(character, { forceShow });
|
const tagNamesToImport = await handleTagImport(character, { importAll, forceShow });
|
||||||
if (!tagNamesToImport?.length) {
|
if (!tagNamesToImport?.length) {
|
||||||
console.debug('No tags to import');
|
console.debug('No tags to import');
|
||||||
return;
|
return;
|
||||||
@ -732,10 +733,11 @@ async function importTags(character, { forceShow = false } = {}) {
|
|||||||
*
|
*
|
||||||
* @param {Character} character - The character
|
* @param {Character} character - The character
|
||||||
* @param {object} [options] - Options
|
* @param {object} [options] - Options
|
||||||
|
* @param {boolean} [options.importAll=false] - Whether to import all tags without dialog
|
||||||
* @param {boolean} [options.forceShow=false] - Whether to force showing the import dialog
|
* @param {boolean} [options.forceShow=false] - Whether to force showing the import dialog
|
||||||
* @returns {Promise<string[]>} Array of strings representing the tags to import
|
* @returns {Promise<string[]>} Array of strings representing the tags to import
|
||||||
*/
|
*/
|
||||||
async function handleTagImport(character, { forceShow = false } = {}) {
|
async function handleTagImport(character, { importAll = false, forceShow = false } = {}) {
|
||||||
/** @type {string[]} */
|
/** @type {string[]} */
|
||||||
const importTags = character.tags.map(t => t.trim()).filter(t => t)
|
const importTags = character.tags.map(t => t.trim()).filter(t => t)
|
||||||
.filter(t => !IMPORT_EXLCUDED_TAGS.includes(t))
|
.filter(t => !IMPORT_EXLCUDED_TAGS.includes(t))
|
||||||
@ -747,7 +749,8 @@ async function handleTagImport(character, { forceShow = false } = {}) {
|
|||||||
|
|
||||||
// Choose the setting for this dialog. If from settings, verify the setting really exists, otherwise take "ASK".
|
// Choose the setting for this dialog. If from settings, verify the setting really exists, otherwise take "ASK".
|
||||||
const setting = forceShow ? tag_import_setting.ASK
|
const setting = forceShow ? tag_import_setting.ASK
|
||||||
: Object.values(tag_import_setting).find(setting => setting === power_user.tag_import_setting) ?? tag_import_setting.ASK;
|
: importAll ? tag_import_setting.ALL
|
||||||
|
: Object.values(tag_import_setting).find(setting => setting === power_user.tag_import_setting) ?? tag_import_setting.ASK;
|
||||||
|
|
||||||
switch (setting) {
|
switch (setting) {
|
||||||
case tag_import_setting.ALL:
|
case tag_import_setting.ALL:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user