Browse Source

working on search

feature/brute_force_protection
Stephan Richter 3 months ago
parent
commit
91147d736d
  1. 11
      frontend/src/Components/Menu.svelte
  2. 62
      frontend/src/routes/search/Search.svelte
  3. 1
      settings.gradle.kts
  4. 3
      web/src/main/resources/web/css/default.css

11
frontend/src/Components/Menu.svelte

@ -5,6 +5,7 @@ import { useTinyRouter } from 'svelte-tiny-router'; @@ -5,6 +5,7 @@ import { useTinyRouter } from 'svelte-tiny-router';
import { logout, user } from '../user.svelte.js';
import { t } from '../translations.svelte.js';
let key = $state(null);
const router = useTinyRouter();
const modules = $state([]);
@ -27,6 +28,12 @@ function go(path){ @@ -27,6 +28,12 @@ function go(path){
return false;
}
async function search(e){
e.preventDefault();
router.navigate(`/search?key=${key}`);
return false;
}
onMount(fetchModules);
</script>
@ -37,6 +44,10 @@ onMount(fetchModules); @@ -37,6 +44,10 @@ onMount(fetchModules);
</style>
<nav>
<form onsubmit={search}>
<input type="text" bind:value={key} />
<button type="submit">{t('search')}</button>
</form>
<a href="#" onclick={() => go('/user')}>{t('users')}</a>
<a href="#" onclick={() => go('/company')}>{t('companies')}</a>
<a href="#" onclick={() => go('/project')}>{t('projects')}</a>

62
frontend/src/routes/search/Search.svelte

@ -1,40 +1,60 @@ @@ -1,40 +1,60 @@
<script>
import { onMount } from 'svelte';
import { t } from '../../translations.svelte.js';
import { onMount } from 'svelte';
import { useTinyRouter } from 'svelte-tiny-router';
import { api } from '../../urls.svelte.js';
import { t } from '../../translations.svelte.js';
const router = useTinyRouter();
console.log(router);
let fulltext = false;
let html = "";
let key = "";
let key = $state(router.getQueryParam('key'));
let input = $state(router.getQueryParam('key'));
let error = $state(null);
async function doSearch(ev){
async function setKey(ev){
if (ev) ev.preventDefault();
const url = `${location.protocol}//${location.host.replace('5173','8080')}/legacy/search`;
const resp = await fetch(url,{
credentials : 'include',
method : 'POST',
body : JSON.stringify({key:key,fulltext:fulltext?'on':'off'})
});
if (resp.ok){
html = await resp.text();
if (!html) html = t('nothing_found');
}
key = input;
}
onMount(() => {
let params = new URLSearchParams(location.search);
key = params.get('key');
if (key) doSearch();
});
function doSearch(ignored){
let url = window.location.origin + window.location.pathname;
if (key) url += '?key=' + encodeURI(key);
window.history.replaceState(history.state, '', url);
const data = { key : key, fulltext : fulltext };
fetch(api('bookmark/search'),{
credentials:'include',
method: 'POST',
body: JSON.stringify(data)
}).then(handleBookmarks);
}
async function handleBookmarks(resp){
if (resp.ok){
} else {
error = await resp.text();
}
}
$effect(() => doSearch(key))
</script>
<fieldset class="search">
<legend>{t('search')}</legend>
<form onsubmit={doSearch}>
{#if error}
<span class="error">{error}</span>
{/if}
<form onsubmit={setKey}>
<label>
{t('key')}
<input type="text" bind:value={key} />
<input type="text" bind:value={input} />
</label>
<label>
<input type="checkbox" bind:checked={fulltext} />
@ -43,11 +63,11 @@ @@ -43,11 +63,11 @@
<button type="submit">{t('go')}</button>
</form>
</fieldset>
{#if html}
{#if key}
<fieldset>
<legend>
{t('results')}
</legend>
{@html html}
{key}
</fieldset>
{/if}

1
settings.gradle.kts

@ -12,6 +12,7 @@ include("messages") @@ -12,6 +12,7 @@ include("messages")
include("markdown")
include("notes")
include("project")
include("search")
include("tags")
include("task")
include("time")

3
web/src/main/resources/web/css/default.css

@ -283,3 +283,6 @@ legend{ @@ -283,3 +283,6 @@ legend{
vertical-align: top;
}
nav > form{
display:inline;
}
Loading…
Cancel
Save