mirror of
https://github.com/psforever/PSFPortal.git
synced 2026-07-16 08:55:14 +00:00
Fix case insensitive search and display
This commit is contained in:
parent
0e4123fe98
commit
817796e181
2 changed files with 14 additions and 2 deletions
11
api/db.js
11
api/db.js
|
|
@ -340,6 +340,13 @@ export async function get_account_logins(account_id, pagination) {
|
||||||
|
|
||||||
export async function search(term, pagination) {
|
export async function search(term, pagination) {
|
||||||
const start_id = (pagination.page-1)*pagination.items_per_page;
|
const start_id = (pagination.page-1)*pagination.items_per_page;
|
||||||
|
|
||||||
|
term = term.replace(/%/g, "");
|
||||||
|
|
||||||
|
if (term.length < 3) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
const values = ['%'+term.toUpperCase()+'%', start_id, pagination.items_per_page];
|
const values = ['%'+term.toUpperCase()+'%', start_id, pagination.items_per_page];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
@ -347,8 +354,8 @@ export async function search(term, pagination) {
|
||||||
'WHERE upper(username) LIKE $1 '+
|
'WHERE upper(username) LIKE $1 '+
|
||||||
` ORDER BY username OFFSET $2 LIMIT $3`, values);
|
` ORDER BY username OFFSET $2 LIMIT $3`, values);
|
||||||
const characters = await pool.query('SELECT id, name, account_id, faction_id FROM characters ' +
|
const characters = await pool.query('SELECT id, name, account_id, faction_id FROM characters ' +
|
||||||
'WHERE name LIKE $1 '+
|
'WHERE upper(name) LIKE $1 '+
|
||||||
` ORDER BY upper(name) OFFSET $2 LIMIT $3`, values);
|
` ORDER BY name OFFSET $2 LIMIT $3`, values);
|
||||||
|
|
||||||
pagination.item_count = 100;
|
pagination.item_count = 100;
|
||||||
pagination.page_count = Math.ceil(pagination.item_count / pagination.items_per_page);
|
pagination.page_count = Math.ceil(pagination.item_count / pagination.items_per_page);
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,11 @@
|
||||||
<button type="submit" class="btn btn-primary mb-2">Search</button>
|
<button type="submit" class="btn btn-primary mb-2">Search</button>
|
||||||
</form>
|
</form>
|
||||||
{#if results}
|
{#if results}
|
||||||
|
{#if results.length > 0}
|
||||||
|
<p>{results.length} results found.</p>
|
||||||
|
{:else}
|
||||||
|
<p>No results found.</p>
|
||||||
|
{/if}
|
||||||
<ol>
|
<ol>
|
||||||
{#each results as result, i}
|
{#each results as result, i}
|
||||||
{#if result.type == "account"}
|
{#if result.type == "account"}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue