Extract templates, replace pagination format

a08972759178c9704583c46a0820ce512c3ea32c

Cohee <18619528+Cohee1207@users.noreply.github.com>

5 files changed, +33 -46Ignore whitespace
public/script.js+16 -18
@@ -1426,30 +1426,26 @@ function getBackBlock() {
14261426 return template;
14271427}
14281428
14291429async function getEmptyBlock() {
14301430 const icons = ['fa-dragon', 'fa-otter', 'fa-kiwi-bird', 'fa-crow', 'fa-frog'];
14311431 const texts = [t`Here be dragons`, t`Otterly empty`, t`Kiwibunga`, t`Pump-a-Rum`, t`Croak it`];
14321432 const roll = new Date().getMinutes() % icons.length;
14331433 const emptyBlockparams = `{
1434- <div class="text_block empty_block">
1434+ text: texts[roll],
1435- <i class="fa-solid ${icons[roll]} fa-4x"></i>
1435+ icon: icons[roll],
1436- <h1>${texts[roll]}</h1>
1436+ };
1437- <p>` + t`There are no items to display.` + `</p>
1437+ const emptyBlock = await renderTemplateAsync('emptyBlock', params);
1438- </div>`;
14391438 return $(emptyBlock);
14401439}
14411440
14421441/**
14431442 * @param {number} hidden Number of hidden characters
14441443 */
14451444async function getHiddenBlock(hidden) {
14461445 const hiddenBlockparams = `{
1447- <div class="text_block hidden_block">
1446+ text: (hidden > 1 ? t`${hidden} characters hidden.` : t`${hidden} character hidden.`),
1448- <small>
1447+ };
1449- <p>` + (hidden > 1 ? t`${hidden} characters hidden.` : t`${hidden} character hidden.`) + `</p>
1448+ const hiddenBlock = await renderTemplateAsync('hiddenBlock', params);
1450- <div class="fa-solid fa-circle-info opacity50p" data-i18n="[title]Characters and groups hidden by filters or closed folders" title="Characters and groups hidden by filters or closed folders"></div>
1451- </small>
1452- </div>`;
14531449 return $(hiddenBlock);
14541450}
14551451
@@ -1542,13 +1538,14 @@ export async function printCharacters(fullRefresh = false) {
15421538 nextText: '>',
15431539 formatNavigator: PAGINATION_TEMPLATE,
15441540 showNavigator: true,
15451541 callback: async function (/** @type {Entity[]} */ data) {
15461542 $(listId).empty();
15471543 if (power_user.bogus_folders && isBogusFolderOpen()) {
15481544 $(listId).append(getBackBlock());
15491545 }
15501546 if (!data.length) {
1551- $(listId).append(getEmptyBlock());
1547+ const emptyBlock = await getEmptyBlock();
1548+ $(listId).append(emptyBlock);
15521549 }
15531550 let displayCount = 0;
15541551 for (const i of data) {
@@ -1569,7 +1566,8 @@ export async function printCharacters(fullRefresh = false) {
15691566
15701567 const hidden = (characters.length + groups.length) - displayCount;
15711568 if (hidden > 0 && entitiesFilter.hasAnyFilter()) {
1572- $(listId).append(getHiddenBlock(hidden));
1569+ const hiddenBlock = await getHiddenBlock(hidden);
1570+ $(listId).append(hiddenBlock);
15731571 }
15741572 localizePagination($('#rm_print_characters_pagination'));
15751573
public/scripts/templates/emptyBlock.html+7 -0
@@ -0,0 +1,7 @@
1+<div class="text_block empty_block">
2+ <i class="fa-solid {{icon}} fa-4x"></i>
3+ <h1>{{text}}</h1>
4+ <p data-i18n="There are no items to display.">
5+ There are no items to display.
6+ </p>
7+</div>
public/scripts/templates/hiddenBlock.html+6 -0
@@ -0,0 +1,6 @@
1+<div class="text_block hidden_block">
2+ <small>
3+ <p>{{text}}</p>
4+ <div class="fa-solid fa-circle-info opacity50p" data-i18n="[title]Characters and groups hidden by filters or closed folders" title="Characters and groups hidden by filters or closed folders"></div>
5+ </small>
6+</div>
public/scripts/textgen-models.js+3 -14
@@ -5,9 +5,9 @@ import { textgenerationwebui_settings as textgen_settings, textgen_types } from
55import { tokenizers } from './tokenizers.js';
66import { renderTemplateAsync } from './templates.js';
77import { POPUP_TYPE, callGenericPopup } from './popup.js';
88import { t, translate } from './i18n.js';
99import { accountStorage } from './util/AccountStorage.js';
1010import { localizePagination, PAGINATION_TEMPLATE } from './utils.js';
1111
1212let mancerModels = [];
1313let togetherModels = [];
@@ -362,18 +362,7 @@ export async function loadFeatherlessModels(data) {
362362 showSizeChanger: false,
363363 prevText: '<',
364364 nextText: '>',
365365 formatNavigator: function (currentPagePAGINATION_TEMPLATE, totalPage) {
366- let translated_of;
367- try {
368- translated_of = translate('pagination_of');
369- if (translated_of == 'pagination_of') {
370- translated_of = 'of';
371- }
372- } catch (e) {
373- translated_of = 'of';
374- }
375- return (currentPage - 1) * perPage + 1 + ' - ' + currentPage * perPage + ` ${translated_of} ` + totalPage * perPage;
376- },
377366 showNavigator: true,
378367 callback: function (modelsOnPage, pagination) {
379368 modelCardBlock.innerHTML = '';
public/scripts/utils.js+1 -14
@@ -18,21 +18,8 @@ import { getCurrentLocale, t, translate } from './i18n.js';
1818
1919/**
2020 * Function returning pagination status string template.
21- * @type {function}
2221 */
23-export const PAGINATION_TEMPLATE = function() {
22+export const PAGINATION_TEMPLATE = '<%= rangeStart %>-<%= rangeEnd %> .. <%= totalNumber %>';
24- let translated_of;
25- try {
26- translated_of = translate('pagination_of');
27- if (translated_of == 'pagination_of') {
28- translated_of = 'of';
29- }
30- } catch (e) {
31- console.error(e);
32- translated_of = 'of';
33- }
34- return `<%= rangeStart %>-<%= rangeEnd %> ${translated_of} <%= totalNumber %>`;
35-};
3623
3724export const localizePagination = function(container) {
3825 let options = container.find('option');