-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #210 from sebadob/ui-events-section
UI: Events section to fetch and view historic events from the database
- Loading branch information
Showing
15 changed files
with
263 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
150 changes: 150 additions & 0 deletions
150
frontend/src/components/admin/events/EventsArchive.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
<script> | ||
import {onMount} from "svelte"; | ||
import {postEvents} from "../../../utils/dataFetchingAdmin.js"; | ||
import {formatDateToDateInput, formatUtcTsFromDateInput} from "../../../utils/helpers.js"; | ||
import OrderSearchBar from "$lib/search/OrderSearchBar.svelte"; | ||
import Input from "$lib/inputs/Input.svelte"; | ||
import {EVENT_LEVELS, EVENT_TYPES} from "../../../utils/constants.js"; | ||
import OptionSelect from "$lib/OptionSelect.svelte"; | ||
import Event from "./Event.svelte"; | ||
import Switch from "$lib/Switch.svelte"; | ||
let err = ''; | ||
let events = []; | ||
let resEvents = []; | ||
let from = formatDateToDateInput(new Date(new Date().getTime() - 3600 * 1000)); | ||
/** @type {string | undefined} */ | ||
let until = undefined; | ||
let level = 'Info'; | ||
let filter = false; | ||
let typ = EVENT_TYPES[0]; | ||
$: if (from || until || level || filter || typ) { | ||
fetchData(); | ||
} | ||
let searchOptions = [ | ||
{ | ||
label: 'IP', | ||
callback: (item, search) => item.ip?.includes(search), | ||
}, | ||
// { | ||
// label: 'Content', | ||
// callback: (item, search) => item.data?.includes(search) | ||
// || item.text?.toLowerCase()?.contains(search.toLowerCase()), | ||
// }, | ||
{ | ||
label: 'Content', | ||
callback: (item, search) => item.text?.toLowerCase()?.includes(search.toLowerCase()), | ||
}, | ||
]; | ||
let orderOptions = [ | ||
{label: 'Timestamp', callback: (a, b) => a.timestamp - b.timestamp}, | ||
{label: 'Level', callback: (a, b) => a.level.localeCompare(b.level)}, | ||
{label: 'Type', callback: (a, b) => a.typ.localeCompare(b.typ)}, | ||
]; | ||
onMount(() => { | ||
fetchData(); | ||
}); | ||
async function fetchData() { | ||
let data = { | ||
from: formatUtcTsFromDateInput(from), | ||
level: level.toLowerCase(), | ||
}; | ||
if (until) { | ||
data.until = formatUtcTsFromDateInput(until); | ||
} | ||
if (filter) { | ||
data.typ = typ; | ||
} | ||
let res = await postEvents(data); | ||
let body = await res.json(); | ||
if (res.ok) { | ||
events = body; | ||
} else { | ||
err = body.message; | ||
} | ||
} | ||
function onSave() { | ||
fetchData(); | ||
} | ||
</script> | ||
<div class="content"> | ||
<div class="row"> | ||
<OrderSearchBar | ||
items={events} | ||
bind:resItems={resEvents} | ||
searchOptions={searchOptions} | ||
orderOptions={orderOptions} | ||
firstDirReverse | ||
/> | ||
</div> | ||
<div class="row filter"> | ||
<Input | ||
type="datetime-local" | ||
step="60" | ||
width="17.5rem" | ||
bind:value={from} | ||
max="2099-01-01T00:00" | ||
> | ||
FROM | ||
</Input> | ||
<Input | ||
type="datetime-local" | ||
step="60" | ||
width="17rem" | ||
bind:value={until} | ||
max="2099-01-01T00:00" | ||
> | ||
UNTIL | ||
</Input> | ||
</div> | ||
<div class="row filterOpts"> | ||
<div style:margin="0 5.5rem 0 .25rem"> | ||
<OptionSelect | ||
bind:value={level} | ||
options={EVENT_LEVELS} | ||
/> | ||
</div> | ||
Filter | ||
<Switch bind:selected={filter} /> | ||
{#if filter} | ||
<OptionSelect | ||
bind:value={typ} | ||
options={EVENT_TYPES} | ||
/> | ||
{/if} | ||
</div> | ||
{#if resEvents.length === 0} | ||
<div class="row"> | ||
No events found | ||
</div> | ||
{:else} | ||
{#each resEvents as event (event.id)} | ||
<Event bind:event collapsed={false} wide /> | ||
{/each} | ||
{/if} | ||
</div> | ||
<style> | ||
.filter, .filterOpts { | ||
margin: -.5rem 0 1rem -.5rem; | ||
} | ||
.filterOpts { | ||
gap: 1rem; | ||
} | ||
.row { | ||
display: flex; | ||
flex-wrap: wrap; | ||
align-items: center; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<script> | ||
export let opacity = 0.9; | ||
export let width = 24; | ||
</script> | ||
|
||
<svg | ||
fill="none" | ||
viewBox="0 0 24 24" | ||
stroke="currentColor" | ||
stroke-width={2} | ||
width={width} | ||
opacity={opacity} | ||
> | ||
<path | ||
stroke-linecap="round" | ||
stroke-linejoin="round" | ||
d="M14.857 17.082a23.848 23.848 0 0 0 5.454-1.31A8.967 8.967 0 0 1 18 9.75V9A6 6 0 0 0 6 9v.75a8.967 8.967 0 0 1-2.312 6.022c1.733.64 3.56 1.085 5.455 1.31m5.714 0a24.255 24.255 0 0 1-5.714 0m5.714 0a3 3 0 1 1-5.714 0M3.124 7.5A8.969 8.969 0 0 1 5.292 3m13.416 0a8.969 8.969 0 0 1 2.168 4.5" | ||
/> | ||
</svg> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<script> | ||
import AdminMainPre from "../../../components/admin/AdminMainPre.svelte"; | ||
</script> | ||
|
||
<AdminMainPre selected="Events"/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.