Merge pull request #2406 from SillyTavern/gray-out-useless-folders

Gray out bogus folders if they don't drill down
This commit is contained in:
Cohee 2024-06-22 12:46:06 +03:00 committed by GitHub
commit 26eb5f0926
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 26 additions and 10 deletions

View File

@ -5465,7 +5465,7 @@
</div> </div>
</div> </div>
<div id="character_template" class="template_element"> <div id="character_template" class="template_element">
<div class="character_select flex-container wide100p alignitemsflexstart" chid="" id=""> <div class="character_select entity_block flex-container wide100p alignitemsflexstart" chid="" id="">
<div class="avatar" title=""> <div class="avatar" title="">
<img src=""> <img src="">
</div> </div>
@ -5766,7 +5766,7 @@
</div> </div>
</div> </div>
<div id="group_list_template" class="template_element"> <div id="group_list_template" class="template_element">
<div class="group_select flex-container wide100p alignitemsflexstart"> <div class="group_select entity_block flex-container wide100p alignitemsflexstart">
<div class="avatar"> <div class="avatar">
<img src=""> <img src="">
</div> </div>
@ -5784,7 +5784,7 @@
</div> </div>
</div> </div>
<div id="bogus_folder_template" class="template_element"> <div id="bogus_folder_template" class="template_element">
<div class="bogus_folder_select flex-container wide100p alignitemsflexstart"> <div class="bogus_folder_select entity_block flex-container wide100p alignitemsflexstart">
<div class="avatar flex alignitemscenter textAlignCenter"> <div class="avatar flex alignitemscenter textAlignCenter">
<i class="bogus_folder_icon fa-solid fa-xl"></i> <i class="bogus_folder_icon fa-solid fa-xl"></i>
</div> </div>

View File

@ -1368,7 +1368,7 @@ export async function printCharacters(fullRefresh = false) {
nextText: '>', nextText: '>',
formatNavigator: PAGINATION_TEMPLATE, formatNavigator: PAGINATION_TEMPLATE,
showNavigator: true, showNavigator: true,
callback: function (data) { callback: function (/** @type {Entity[]} */ data) {
$(listId).empty(); $(listId).empty();
if (power_user.bogus_folders && isBogusFolderOpen()) { if (power_user.bogus_folders && isBogusFolderOpen()) {
$(listId).append(getBackBlock()); $(listId).append(getBackBlock());
@ -1388,7 +1388,7 @@ export async function printCharacters(fullRefresh = false) {
displayCount++; displayCount++;
break; break;
case 'tag': case 'tag':
$(listId).append(getTagBlock(i.item, i.entities, i.hidden)); $(listId).append(getTagBlock(i.item, i.entities, i.hidden, i.isUseless));
break; break;
} }
} }
@ -1442,8 +1442,9 @@ function verifyCharactersSearchSortRule() {
* @property {Character|Group|import('./scripts/tags.js').Tag|*} item - The item * @property {Character|Group|import('./scripts/tags.js').Tag|*} item - The item
* @property {string|number} id - The id * @property {string|number} id - The id
* @property {'character'|'group'|'tag'} type - The type of this entity (character, group, tag) * @property {'character'|'group'|'tag'} type - The type of this entity (character, group, tag)
* @property {Entity[]} [entities] - An optional list of entities relevant for this item * @property {Entity[]?} [entities=null] - An optional list of entities relevant for this item
* @property {number} [hidden] - An optional number representing how many hidden entities this entity contains * @property {number?} [hidden=null] - An optional number representing how many hidden entities this entity contains
* @property {boolean?} [isUseless=null] - Specifies if the entity is useless (not relevant, but should still be displayed for consistency) and should be displayed greyed out
*/ */
/** /**
@ -1538,6 +1539,15 @@ export function getEntitiesList({ doFilter = false, doSort = true } = {}) {
} }
} }
// Final step, updating some properties after the last filter run
const nonTagEntitiesCount = entities.filter(entity => entity.type !== 'tag').length;
for (const entity of entities) {
if (entity.type === 'tag') {
if (entity.entities?.length == nonTagEntitiesCount) entity.isUseless = true;
}
}
// Sort before returning if requested
if (doSort) { if (doSort) {
sortEntitiesList(entities); sortEntitiesList(entities);
} }

View File

@ -283,11 +283,12 @@ function chooseBogusFolder(source, tagId, remove = false) {
* Builds the tag block for the specified item. * Builds the tag block for the specified item.
* *
* @param {Tag} tag The tag item * @param {Tag} tag The tag item
* @param {*} entities The list ob sub items for this tag * @param {any[]} entities The list ob sub items for this tag
* @param {*} hidden A count of how many sub items are hidden * @param {number} hidden A count of how many sub items are hidden
* @param {boolean} isUseless Whether the tag is useless (should be displayed greyed out)
* @returns The html for the tag block * @returns The html for the tag block
*/ */
function getTagBlock(tag, entities, hidden = 0) { function getTagBlock(tag, entities, hidden = 0, isUseless = false) {
let count = entities.length; let count = entities.length;
const tagFolder = TAG_FOLDER_TYPES[tag.folder_type]; const tagFolder = TAG_FOLDER_TYPES[tag.folder_type];
@ -300,6 +301,7 @@ function getTagBlock(tag, entities, hidden = 0) {
template.find('.bogus_folder_hidden_counter').text(hidden > 0 ? `${hidden} hidden` : ''); template.find('.bogus_folder_hidden_counter').text(hidden > 0 ? `${hidden} hidden` : '');
template.find('.bogus_folder_counter').text(`${count} ${count != 1 ? 'characters' : 'character'}`); template.find('.bogus_folder_counter').text(`${count} ${count != 1 ? 'characters' : 'character'}`);
template.find('.bogus_folder_icon').addClass(tagFolder.fa_icon); template.find('.bogus_folder_icon').addClass(tagFolder.fa_icon);
if (isUseless) template.addClass('useless');
// Fill inline character images // Fill inline character images
buildAvatarList(template.find('.bogus_folder_avatars_block'), entities); buildAvatarList(template.find('.bogus_folder_avatars_block'), entities);

View File

@ -2368,6 +2368,10 @@ input[type="file"] {
padding: 1px; padding: 1px;
} }
#rm_print_characters_block .entity_block.useless {
opacity: 0.25;
}
#rm_ch_create_block { #rm_ch_create_block {
display: none; display: none;
overflow-y: auto; overflow-y: auto;