mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Merge pull request #602 from bdashore3/dev
Add persistence to tag exclusions
This commit is contained in:
@@ -280,7 +280,7 @@ function createNewTag(tagName) {
|
|||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
function appendTagToList(listElement, tag, { removable, selectable, action }) {
|
function appendTagToList(listElement, tag, { removable, selectable, action, isGeneralList }) {
|
||||||
if (!listElement) {
|
if (!listElement) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -305,6 +305,10 @@ function appendTagToList(listElement, tag, { removable, selectable, action }) {
|
|||||||
tagElement.find('.tag_name').text('').attr('title', tag.name).addClass(tag.icon);
|
tagElement.find('.tag_name').text('').attr('title', tag.name).addClass(tag.icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tag.excluded) {
|
||||||
|
isGeneralList ? $(tagElement).addClass('excluded') : $(listElement).parent().parent().addClass('hiddenByTag');
|
||||||
|
}
|
||||||
|
|
||||||
if (selectable) {
|
if (selectable) {
|
||||||
tagElement.on('click', () => onTagFilterClick.bind(tagElement)(listElement, characterSelector));
|
tagElement.on('click', () => onTagFilterClick.bind(tagElement)(listElement, characterSelector));
|
||||||
}
|
}
|
||||||
@@ -321,17 +325,32 @@ function appendTagToList(listElement, tag, { removable, selectable, action }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onTagFilterClick(listElement, characterSelector) {
|
function onTagFilterClick(listElement, characterSelector) {
|
||||||
|
let excludeTag;
|
||||||
if ($(this).hasClass('selected')) {
|
if ($(this).hasClass('selected')) {
|
||||||
$(this).removeClass('selected');
|
$(this).removeClass('selected');
|
||||||
$(this).addClass('excluded');
|
$(this).addClass('excluded');
|
||||||
|
excludeTag = true
|
||||||
}
|
}
|
||||||
else if ($(this).hasClass('excluded')) {
|
else if ($(this).hasClass('excluded')) {
|
||||||
$(this).removeClass('excluded');
|
$(this).removeClass('excluded');
|
||||||
|
excludeTag = false;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$(this).addClass('selected');
|
$(this).addClass('selected');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Manual undefined check required for three-state boolean
|
||||||
|
if (excludeTag !== undefined) {
|
||||||
|
const tagId = $(this).attr('id');
|
||||||
|
const existingTag = tags.find((tag) => tag.id === tagId);
|
||||||
|
if (existingTag) {
|
||||||
|
existingTag.excluded = excludeTag;
|
||||||
|
|
||||||
|
saveSettingsDebounced();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Overhaul this somehow to use settings tag IDs instead
|
||||||
const tagIds = [...($(listElement).find(".tag.selected:not(.actionable)").map((_, el) => $(el).attr("id")))];
|
const tagIds = [...($(listElement).find(".tag.selected:not(.actionable)").map((_, el) => $(el).attr("id")))];
|
||||||
const excludedTagIds = [...($(listElement).find(".tag.excluded:not(.actionable)").map((_, el) => $(el).attr("id")))];
|
const excludedTagIds = [...($(listElement).find(".tag.excluded:not(.actionable)").map((_, el) => $(el).attr("id")))];
|
||||||
$(characterSelector).each((_, element) => applyFilterToElement(tagIds, excludedTagIds, element));
|
$(characterSelector).each((_, element) => applyFilterToElement(tagIds, excludedTagIds, element));
|
||||||
@@ -380,16 +399,16 @@ function printTagFilters(type = tag_filter_types.character) {
|
|||||||
.sort((a, b) => a.name.localeCompare(b.name));
|
.sort((a, b) => a.name.localeCompare(b.name));
|
||||||
|
|
||||||
for (const tag of Object.values(ACTIONABLE_TAGS)) {
|
for (const tag of Object.values(ACTIONABLE_TAGS)) {
|
||||||
appendTagToList(FILTER_SELECTOR, tag, { removable: false, selectable: false, action: tag.action });
|
appendTagToList(FILTER_SELECTOR, tag, { removable: false, selectable: false, action: tag.action, isGeneralList: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
$(FILTER_SELECTOR).find('.actionable').last().addClass('margin-right-10px');
|
$(FILTER_SELECTOR).find('.actionable').last().addClass('margin-right-10px');
|
||||||
|
|
||||||
for (const tag of Object.values(InListActionable)) {
|
for (const tag of Object.values(InListActionable)) {
|
||||||
appendTagToList(FILTER_SELECTOR, tag, { removable: false, selectable: false, action: tag.action });
|
appendTagToList(FILTER_SELECTOR, tag, { removable: false, selectable: false, action: tag.action, isGeneralList: true });
|
||||||
}
|
}
|
||||||
for (const tag of tagsToDisplay) {
|
for (const tag of tagsToDisplay) {
|
||||||
appendTagToList(FILTER_SELECTOR, tag, { removable: false, selectable: true, });
|
appendTagToList(FILTER_SELECTOR, tag, { removable: false, selectable: true, isGeneralList: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const tagId of selectedTagIds) {
|
for (const tagId of selectedTagIds) {
|
||||||
|
Reference in New Issue
Block a user