mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Merge branch 'staging' of https://github.com/Cohee1207/SillyTavern into staging
This commit is contained in:
131
public/script.js
131
public/script.js
@ -989,8 +989,15 @@ export async function selectCharacterById(id) {
|
||||
}
|
||||
}
|
||||
|
||||
function getTagBlock(item) {
|
||||
const count = Object.values(tag_map).flat().filter(x => x == item.id).length;
|
||||
function getTagBlock(item, entities) {
|
||||
let count = 0;
|
||||
|
||||
for (const entity of entities) {
|
||||
if (entitiesFilter.isElementTagged(entity, item.id)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
const template = $('#bogus_folder_template .bogus_folder_select').clone();
|
||||
template.attr({ 'tagid': item.id, 'id': `BogusFolder${item.id}` });
|
||||
template.find('.avatar').css({ 'background-color': item.color, 'color': item.color2 });
|
||||
@ -999,6 +1006,11 @@ function getTagBlock(item) {
|
||||
return template;
|
||||
}
|
||||
|
||||
function getBackBlock() {
|
||||
const template = $('#bogus_folder_back_template .bogus_folder_select').clone();
|
||||
return template;
|
||||
}
|
||||
|
||||
function getEmptyBlock() {
|
||||
const icons = ['fa-dragon', 'fa-otter', 'fa-kiwi-bird', 'fa-crow', 'fa-frog'];
|
||||
const texts = ['Here be dragons', 'Otterly empty', 'Kiwibunga', 'Pump-a-Rum', 'Croak it'];
|
||||
@ -1038,9 +1050,10 @@ function getCharacterBlock(item, id) {
|
||||
template.find('.ch_description').hide();
|
||||
}
|
||||
|
||||
const version = item.data?.character_version || '';
|
||||
if (version) {
|
||||
template.find('.character_version').text(version);
|
||||
const auxFieldName = power_user.aux_field || 'character_version';
|
||||
const auxFieldValue = (item.data && item.data[auxFieldName]) || '';
|
||||
if (auxFieldValue) {
|
||||
template.find('.character_version').text(auxFieldValue);
|
||||
}
|
||||
else {
|
||||
template.find('.character_version').hide();
|
||||
@ -1060,10 +1073,9 @@ async function printCharacters(fullRefresh = false) {
|
||||
saveCharactersPage = 0;
|
||||
printTagFilters(tag_filter_types.character);
|
||||
printTagFilters(tag_filter_types.group_member);
|
||||
const isBogusFolderOpen = !!entitiesFilter.getFilterData(FILTER_TYPES.TAG)?.bogus;
|
||||
|
||||
// Return to main list
|
||||
if (isBogusFolderOpen) {
|
||||
if (isBogusFolderOpen()) {
|
||||
entitiesFilter.setFilterData(FILTER_TYPES.TAG, { excluded: [], selected: [] });
|
||||
}
|
||||
|
||||
@ -1072,8 +1084,11 @@ async function printCharacters(fullRefresh = false) {
|
||||
}
|
||||
|
||||
const storageKey = 'Characters_PerPage';
|
||||
const listId = '#rm_print_characters_block';
|
||||
const entities = getEntitiesList({ doFilter: true });
|
||||
|
||||
$("#rm_print_characters_pagination").pagination({
|
||||
dataSource: getEntitiesList({ doFilter: true }),
|
||||
dataSource: entities,
|
||||
pageSize: Number(localStorage.getItem(storageKey)) || per_page_default,
|
||||
sizeChangerOptions: [10, 25, 50, 100, 250, 500, 1000],
|
||||
pageRange: 1,
|
||||
@ -1086,20 +1101,25 @@ async function printCharacters(fullRefresh = false) {
|
||||
formatNavigator: PAGINATION_TEMPLATE,
|
||||
showNavigator: true,
|
||||
callback: function (data) {
|
||||
$("#rm_print_characters_block").empty();
|
||||
for (const i of data) {
|
||||
if (i.type === 'character') {
|
||||
$("#rm_print_characters_block").append(getCharacterBlock(i.item, i.id));
|
||||
}
|
||||
if (i.type === 'group') {
|
||||
$("#rm_print_characters_block").append(getGroupBlock(i.item));
|
||||
}
|
||||
if (i.type === 'tag') {
|
||||
$("#rm_print_characters_block").append(getTagBlock(i.item));
|
||||
}
|
||||
$(listId).empty();
|
||||
if (isBogusFolderOpen()) {
|
||||
$(listId).append(getBackBlock());
|
||||
}
|
||||
if (!data.length) {
|
||||
$("#rm_print_characters_block").append(getEmptyBlock());
|
||||
$(listId).append(getEmptyBlock());
|
||||
}
|
||||
for (const i of data) {
|
||||
switch (i.type) {
|
||||
case 'character':
|
||||
$(listId).append(getCharacterBlock(i.item, i.id));
|
||||
break;
|
||||
case 'group':
|
||||
$(listId).append(getGroupBlock(i.item));
|
||||
break;
|
||||
case 'tag':
|
||||
$(listId).append(getTagBlock(i.item, entities));
|
||||
break;
|
||||
}
|
||||
}
|
||||
eventSource.emit(event_types.CHARACTER_PAGE_LOADED);
|
||||
},
|
||||
@ -1110,26 +1130,60 @@ async function printCharacters(fullRefresh = false) {
|
||||
saveCharactersPage = e;
|
||||
},
|
||||
afterRender: function () {
|
||||
$('#rm_print_characters_block').scrollTop(0);
|
||||
$(listId).scrollTop(0);
|
||||
},
|
||||
});
|
||||
|
||||
favsToHotswap();
|
||||
}
|
||||
|
||||
export function getEntitiesList({ doFilter } = {}) {
|
||||
let entities = [];
|
||||
entities.push(...characters.map((item, index) => ({ item, id: index, type: 'character' })));
|
||||
entities.push(...groups.map((item) => ({ item, id: item.id, type: 'group' })));
|
||||
/**
|
||||
* Indicates whether a user is currently in a bogus folder.
|
||||
* @returns {boolean} If currently viewing a folder
|
||||
*/
|
||||
function isBogusFolderOpen() {
|
||||
return !!entitiesFilter.getFilterData(FILTER_TYPES.TAG)?.bogus;
|
||||
}
|
||||
|
||||
if (power_user.bogus_folders) {
|
||||
entities.push(...tags.map((item) => ({ item, id: item.id, type: 'tag' })));
|
||||
export function getEntitiesList({ doFilter } = {}) {
|
||||
function characterToEntity(character, id) {
|
||||
return { item: character, id, type: 'character' };
|
||||
}
|
||||
|
||||
function groupToEntity(group) {
|
||||
return { item: group, id: group.id, type: 'group' };
|
||||
}
|
||||
|
||||
function tagToEntity(tag) {
|
||||
return { item: structuredClone(tag), id: tag.id, type: 'tag' };
|
||||
}
|
||||
|
||||
let entities = [
|
||||
...characters.map((item, index) => characterToEntity(item, index)),
|
||||
...groups.map(item => groupToEntity(item)),
|
||||
...(power_user.bogus_folders ? tags.map(item => tagToEntity(item)) : []),
|
||||
];
|
||||
|
||||
if (doFilter) {
|
||||
entities = entitiesFilter.applyFilters(entities);
|
||||
}
|
||||
|
||||
if (isBogusFolderOpen()) {
|
||||
// Get tags of entities within the bogus folder
|
||||
const filterData = structuredClone(entitiesFilter.getFilterData(FILTER_TYPES.TAG));
|
||||
entities = entities.filter(x => x.type !== 'tag');
|
||||
const otherTags = tags.filter(x => !filterData.selected.includes(x.id));
|
||||
const bogusTags = [];
|
||||
for (const entity of entities) {
|
||||
for (const tag of otherTags) {
|
||||
if (!bogusTags.includes(tag) && entitiesFilter.isElementTagged(entity, tag.id)) {
|
||||
bogusTags.push(tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
entities.push(...bogusTags.map(item => tagToEntity(item)));
|
||||
}
|
||||
|
||||
sortEntitiesList(entities);
|
||||
return entities;
|
||||
}
|
||||
@ -3355,7 +3409,7 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
|
||||
generate_data = getNovelGenerationData(finalPrompt, presetSettings, maxLength, isImpersonate, cfgValues);
|
||||
}
|
||||
else if (main_api == 'openai') {
|
||||
let [prompt, counts] = prepareOpenAIMessages({
|
||||
let [prompt, counts] = await prepareOpenAIMessages({
|
||||
name2: name2,
|
||||
charDescription: description,
|
||||
charPersonality: personality,
|
||||
@ -7523,8 +7577,25 @@ jQuery(async function () {
|
||||
$(document).on("click", ".bogus_folder_select", function () {
|
||||
const tagId = $(this).attr('tagid');
|
||||
console.log('Bogus folder clicked', tagId);
|
||||
entitiesFilter.setFilterData(FILTER_TYPES.TAG, { excluded: [], selected: [tagId], bogus: true, });
|
||||
})
|
||||
|
||||
const filterData = structuredClone(entitiesFilter.getFilterData(FILTER_TYPES.TAG));
|
||||
|
||||
if (!Array.isArray(filterData.selected)) {
|
||||
filterData.selected = [];
|
||||
filterData.excluded = [];
|
||||
filterData.bogus = false;
|
||||
}
|
||||
|
||||
if (tagId === 'back') {
|
||||
filterData.selected.pop();
|
||||
filterData.bogus = filterData.selected.length > 0;
|
||||
} else {
|
||||
filterData.selected.push(tagId);
|
||||
filterData.bogus = true;
|
||||
}
|
||||
|
||||
entitiesFilter.setFilterData(FILTER_TYPES.TAG, filterData);
|
||||
});
|
||||
|
||||
$(document).on("input", ".edit_textarea", function () {
|
||||
scroll_holder = $("#chat").scrollTop();
|
||||
|
Reference in New Issue
Block a user