feat: IconGridSelect, CrossLink, SearchPalette components + entity crosslinks
New components: - IconGridSelect: Visual grid selector replacing <select> dropdowns, with icon + label cells, fixed-position popup, smart placement - CrossLink: Inline clickable badge for cross-entity navigation, hover highlights primary, used on entity cards - SearchPalette: Ctrl+K global command palette, searches all entity types via cached data, grouped results, keyboard navigation Integration: - Targets: type selector uses IconGridSelect (4-column grid with icons) - Targets: bot crosslink on telegram/email/matrix target cards - Command Trackers: provider and config badges → CrossLinks - Command Trackers: listener bot name → CrossLink - Command Configs: template config shown as CrossLink on card - Notification Trackers: provider CrossLink added to card - Layout: SearchPalette mounted globally Infrastructure: - Added CommandConfig, CommandTemplateConfig, CommandTracker types - Added notificationTrackersCache, commandTrackersCache to caches - Added allCaches map and fetchAllCaches() for search palette - Added searchPalette i18n keys (EN/RU)
This commit is contained in:
@@ -0,0 +1,50 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { goto } from '$app/navigation';
|
||||||
|
import MdiIcon from './MdiIcon.svelte';
|
||||||
|
|
||||||
|
let {
|
||||||
|
href,
|
||||||
|
icon = 'mdiLink',
|
||||||
|
label,
|
||||||
|
title = '',
|
||||||
|
}: {
|
||||||
|
href: string;
|
||||||
|
icon?: string;
|
||||||
|
label: string;
|
||||||
|
title?: string;
|
||||||
|
} = $props();
|
||||||
|
|
||||||
|
function navigate(e: MouseEvent) {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
goto(href);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<a {href} class="crosslink" title={title || label} onclick={navigate}>
|
||||||
|
<MdiIcon name={icon} size={12} />
|
||||||
|
<span>{label}</span>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.crosslink {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.25rem;
|
||||||
|
font-size: 0.65rem;
|
||||||
|
font-weight: 500;
|
||||||
|
padding: 0.1rem 0.4rem;
|
||||||
|
border-radius: 9999px;
|
||||||
|
background: var(--color-muted);
|
||||||
|
color: var(--color-muted-foreground);
|
||||||
|
text-decoration: none;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.15s;
|
||||||
|
white-space: nowrap;
|
||||||
|
font-family: var(--font-mono);
|
||||||
|
}
|
||||||
|
.crosslink:hover {
|
||||||
|
background: var(--color-primary);
|
||||||
|
color: var(--color-primary-foreground);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,183 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import MdiIcon from './MdiIcon.svelte';
|
||||||
|
|
||||||
|
export interface GridItem {
|
||||||
|
value: string | number;
|
||||||
|
icon: string;
|
||||||
|
label: string;
|
||||||
|
desc?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
let {
|
||||||
|
items = [],
|
||||||
|
value = $bindable(),
|
||||||
|
placeholder = 'Select...',
|
||||||
|
columns = 2,
|
||||||
|
disabled = false,
|
||||||
|
}: {
|
||||||
|
items: GridItem[];
|
||||||
|
value: string | number | null;
|
||||||
|
placeholder?: string;
|
||||||
|
columns?: number;
|
||||||
|
disabled?: boolean;
|
||||||
|
} = $props();
|
||||||
|
|
||||||
|
let open = $state(false);
|
||||||
|
let triggerEl: HTMLButtonElement;
|
||||||
|
let popupStyle = $state('');
|
||||||
|
|
||||||
|
const selected = $derived(items.find(i => String(i.value) === String(value)));
|
||||||
|
|
||||||
|
function toggle() {
|
||||||
|
if (disabled) return;
|
||||||
|
if (!open && triggerEl) {
|
||||||
|
const rect = triggerEl.getBoundingClientRect();
|
||||||
|
const spaceBelow = window.innerHeight - rect.bottom;
|
||||||
|
const popupHeight = Math.min(items.length * 60 + 16, 320);
|
||||||
|
const top = spaceBelow > popupHeight + 8
|
||||||
|
? rect.bottom + 4
|
||||||
|
: rect.top - popupHeight - 4;
|
||||||
|
const left = Math.min(rect.left, window.innerWidth - columns * 160 - 24);
|
||||||
|
popupStyle = `position:fixed; z-index:9999; top:${top}px; left:${Math.max(4, left)}px;`;
|
||||||
|
}
|
||||||
|
open = !open;
|
||||||
|
}
|
||||||
|
|
||||||
|
function select(item: GridItem) {
|
||||||
|
value = item.value;
|
||||||
|
open = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleKeydown(e: KeyboardEvent) {
|
||||||
|
if (e.key === 'Escape' && open) {
|
||||||
|
open = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<svelte:window onkeydown={open ? handleKeydown : undefined} />
|
||||||
|
|
||||||
|
<button type="button" bind:this={triggerEl} onclick={toggle}
|
||||||
|
class="icon-grid-trigger"
|
||||||
|
class:disabled
|
||||||
|
style="opacity: {disabled ? 0.5 : 1}; cursor: {disabled ? 'default' : 'pointer'};">
|
||||||
|
{#if selected}
|
||||||
|
<span class="icon-grid-trigger-icon"><MdiIcon name={selected.icon} size={18} /></span>
|
||||||
|
<span class="icon-grid-trigger-label">{selected.label}</span>
|
||||||
|
{:else}
|
||||||
|
<span class="icon-grid-trigger-label" style="color: var(--color-muted-foreground);">{placeholder}</span>
|
||||||
|
{/if}
|
||||||
|
<span class="icon-grid-trigger-arrow"><MdiIcon name="mdiChevronDown" size={14} /></span>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
{#if open}
|
||||||
|
<!-- Backdrop -->
|
||||||
|
<div style="position:fixed; top:0; left:0; right:0; bottom:0; z-index:9998;"
|
||||||
|
role="presentation" onclick={() => open = false}></div>
|
||||||
|
|
||||||
|
<!-- Popup grid -->
|
||||||
|
<div style="{popupStyle} width: {columns * 160 + 16}px;"
|
||||||
|
class="icon-grid-popup">
|
||||||
|
<div class="icon-grid" style="grid-template-columns: repeat({columns}, 1fr);">
|
||||||
|
{#each items as item}
|
||||||
|
<button type="button"
|
||||||
|
class="icon-grid-cell"
|
||||||
|
class:active={String(item.value) === String(value)}
|
||||||
|
onclick={() => select(item)}>
|
||||||
|
<span class="icon-grid-cell-icon"><MdiIcon name={item.icon} size={22} /></span>
|
||||||
|
<span class="icon-grid-cell-label">{item.label}</span>
|
||||||
|
{#if item.desc}
|
||||||
|
<span class="icon-grid-cell-desc">{item.desc}</span>
|
||||||
|
{/if}
|
||||||
|
</button>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.icon-grid-trigger {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.5rem;
|
||||||
|
width: 100%;
|
||||||
|
padding: 0.5rem 0.75rem;
|
||||||
|
border: 1px solid var(--color-border);
|
||||||
|
border-radius: 0.375rem;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
background: var(--color-background);
|
||||||
|
color: var(--color-foreground);
|
||||||
|
transition: border-color 0.15s, box-shadow 0.15s;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
.icon-grid-trigger:hover:not(.disabled) {
|
||||||
|
border-color: var(--color-primary);
|
||||||
|
}
|
||||||
|
.icon-grid-trigger-icon {
|
||||||
|
flex-shrink: 0;
|
||||||
|
color: var(--color-primary);
|
||||||
|
}
|
||||||
|
.icon-grid-trigger-label {
|
||||||
|
flex: 1;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
.icon-grid-trigger-arrow {
|
||||||
|
flex-shrink: 0;
|
||||||
|
color: var(--color-muted-foreground);
|
||||||
|
transition: transform 0.15s;
|
||||||
|
}
|
||||||
|
.icon-grid-popup {
|
||||||
|
background: var(--color-card);
|
||||||
|
border: 1px solid var(--color-border);
|
||||||
|
border-radius: 0.5rem;
|
||||||
|
box-shadow: 0 10px 30px rgba(0,0,0,0.3);
|
||||||
|
padding: 0.5rem;
|
||||||
|
max-height: 320px;
|
||||||
|
overflow-y: auto;
|
||||||
|
scrollbar-width: thin;
|
||||||
|
}
|
||||||
|
.icon-grid {
|
||||||
|
display: grid;
|
||||||
|
gap: 0.375rem;
|
||||||
|
}
|
||||||
|
.icon-grid-cell {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.25rem;
|
||||||
|
padding: 0.625rem 0.375rem;
|
||||||
|
border-radius: 0.375rem;
|
||||||
|
border: 2px solid transparent;
|
||||||
|
background: transparent;
|
||||||
|
color: var(--color-foreground);
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.15s;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.icon-grid-cell:hover {
|
||||||
|
background: var(--color-muted);
|
||||||
|
transform: scale(1.03);
|
||||||
|
}
|
||||||
|
.icon-grid-cell.active {
|
||||||
|
border-color: var(--color-primary);
|
||||||
|
background: color-mix(in srgb, var(--color-primary) 10%, transparent);
|
||||||
|
}
|
||||||
|
.icon-grid-cell-icon {
|
||||||
|
color: var(--color-muted-foreground);
|
||||||
|
}
|
||||||
|
.icon-grid-cell.active .icon-grid-cell-icon {
|
||||||
|
color: var(--color-primary);
|
||||||
|
}
|
||||||
|
.icon-grid-cell-label {
|
||||||
|
font-size: 0.7rem;
|
||||||
|
font-weight: 500;
|
||||||
|
line-height: 1.2;
|
||||||
|
}
|
||||||
|
.icon-grid-cell-desc {
|
||||||
|
font-size: 0.6rem;
|
||||||
|
color: var(--color-muted-foreground);
|
||||||
|
line-height: 1.2;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,377 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { goto } from '$app/navigation';
|
||||||
|
import { t } from '$lib/i18n';
|
||||||
|
import MdiIcon from './MdiIcon.svelte';
|
||||||
|
import {
|
||||||
|
fetchAllCaches,
|
||||||
|
providersCache,
|
||||||
|
targetsCache,
|
||||||
|
notificationTrackersCache,
|
||||||
|
trackingConfigsCache,
|
||||||
|
templateConfigsCache,
|
||||||
|
telegramBotsCache,
|
||||||
|
emailBotsCache,
|
||||||
|
matrixBotsCache,
|
||||||
|
commandConfigsCache,
|
||||||
|
commandTemplateConfigsCache,
|
||||||
|
commandTrackersCache,
|
||||||
|
} from '$lib/stores/caches.svelte';
|
||||||
|
|
||||||
|
let open = $state(false);
|
||||||
|
let query = $state('');
|
||||||
|
let activeIndex = $state(0);
|
||||||
|
let loading = $state(false);
|
||||||
|
let inputEl: HTMLInputElement;
|
||||||
|
|
||||||
|
interface SearchResult {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
icon: string;
|
||||||
|
detail: string;
|
||||||
|
href: string;
|
||||||
|
group: string;
|
||||||
|
groupIcon: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** All searchable entity groups. */
|
||||||
|
const GROUPS = [
|
||||||
|
{ key: 'providers', label: 'nav.providers', icon: 'mdiServer', href: '/providers',
|
||||||
|
mapFn: (e: any) => ({ detail: e.type, icon: e.icon || 'mdiServer' }) },
|
||||||
|
{ key: 'notification_trackers', label: 'nav.notification', icon: 'mdiRadar', href: '/notification-trackers',
|
||||||
|
mapFn: (e: any) => ({ detail: e.enabled ? 'enabled' : 'disabled', icon: e.icon || 'mdiRadar' }) },
|
||||||
|
{ key: 'tracking_configs', label: 'nav.trackingConfigs', icon: 'mdiCog', href: '/tracking-configs',
|
||||||
|
mapFn: (e: any) => ({ detail: e.provider_type, icon: e.icon || 'mdiCog' }) },
|
||||||
|
{ key: 'template_configs', label: 'nav.templateConfigs', icon: 'mdiFileDocumentEdit', href: '/template-configs',
|
||||||
|
mapFn: (e: any) => ({ detail: e.provider_type, icon: e.icon || 'mdiFileDocumentEdit' }) },
|
||||||
|
{ key: 'targets', label: 'nav.targets', icon: 'mdiTarget', href: '/targets',
|
||||||
|
mapFn: (e: any) => ({ detail: e.type, icon: e.icon || 'mdiTarget' }) },
|
||||||
|
{ key: 'telegram_bots', label: 'nav.telegram', icon: 'mdiSendCircle', href: '/telegram-bots',
|
||||||
|
mapFn: (e: any) => ({ detail: `@${e.bot_username || ''}`, icon: e.icon || 'mdiRobot' }) },
|
||||||
|
{ key: 'email_bots', label: 'nav.email', icon: 'mdiEmailOutline', href: '/telegram-bots?tab=email',
|
||||||
|
mapFn: (e: any) => ({ detail: e.email || '', icon: e.icon || 'mdiEmailOutline' }) },
|
||||||
|
{ key: 'matrix_bots', label: 'nav.matrix', icon: 'mdiMatrix', href: '/telegram-bots?tab=matrix',
|
||||||
|
mapFn: (e: any) => ({ detail: e.display_name || '', icon: e.icon || 'mdiMatrix' }) },
|
||||||
|
{ key: 'command_trackers', label: 'nav.commandTrackers', icon: 'mdiConsoleLine', href: '/command-trackers',
|
||||||
|
mapFn: (e: any) => ({ detail: e.enabled ? 'enabled' : 'disabled', icon: e.icon || 'mdiConsoleLine' }) },
|
||||||
|
{ key: 'command_configs', label: 'nav.commandConfigs', icon: 'mdiCog', href: '/command-configs',
|
||||||
|
mapFn: (e: any) => ({ detail: e.provider_type, icon: e.icon || 'mdiCog' }) },
|
||||||
|
{ key: 'command_template_configs', label: 'nav.cmdTemplateConfigs', icon: 'mdiCodeBracesBox', href: '/command-template-configs',
|
||||||
|
mapFn: (e: any) => ({ detail: e.provider_type, icon: e.icon || 'mdiCodeBracesBox' }) },
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
const cacheMap: Record<string, { items: any[] }> = {
|
||||||
|
providers: providersCache,
|
||||||
|
notification_trackers: notificationTrackersCache,
|
||||||
|
tracking_configs: trackingConfigsCache,
|
||||||
|
template_configs: templateConfigsCache,
|
||||||
|
targets: targetsCache,
|
||||||
|
telegram_bots: telegramBotsCache,
|
||||||
|
email_bots: emailBotsCache,
|
||||||
|
matrix_bots: matrixBotsCache,
|
||||||
|
command_trackers: commandTrackersCache,
|
||||||
|
command_configs: commandConfigsCache,
|
||||||
|
command_template_configs: commandTemplateConfigsCache,
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Build flat results from all caches, filtered by query. */
|
||||||
|
const results = $derived.by(() => {
|
||||||
|
if (!open) return [];
|
||||||
|
const terms = query.toLowerCase().split(/\s+/).filter(Boolean);
|
||||||
|
const all: SearchResult[] = [];
|
||||||
|
|
||||||
|
for (const group of GROUPS) {
|
||||||
|
const cache = cacheMap[group.key];
|
||||||
|
if (!cache) continue;
|
||||||
|
for (const entity of cache.items) {
|
||||||
|
const mapped = group.mapFn(entity);
|
||||||
|
const name = entity.name || '';
|
||||||
|
const searchable = `${name} ${mapped.detail} ${t(group.label)}`.toLowerCase();
|
||||||
|
if (terms.length > 0 && !terms.every(term => searchable.includes(term))) continue;
|
||||||
|
all.push({
|
||||||
|
id: entity.id,
|
||||||
|
name,
|
||||||
|
icon: mapped.icon,
|
||||||
|
detail: mapped.detail,
|
||||||
|
href: group.href,
|
||||||
|
group: t(group.label),
|
||||||
|
groupIcon: group.icon,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return all;
|
||||||
|
});
|
||||||
|
|
||||||
|
/** Group results by entity type for display. */
|
||||||
|
const groupedResults = $derived.by(() => {
|
||||||
|
const groups: { label: string; icon: string; items: SearchResult[] }[] = [];
|
||||||
|
const seen = new Set<string>();
|
||||||
|
for (const r of results) {
|
||||||
|
if (!seen.has(r.group)) {
|
||||||
|
seen.add(r.group);
|
||||||
|
groups.push({ label: r.group, icon: r.groupIcon, items: [] });
|
||||||
|
}
|
||||||
|
groups.find(g => g.label === r.group)!.items.push(r);
|
||||||
|
}
|
||||||
|
return groups;
|
||||||
|
});
|
||||||
|
|
||||||
|
const flatResults = $derived(results);
|
||||||
|
|
||||||
|
async function openPalette() {
|
||||||
|
open = true;
|
||||||
|
query = '';
|
||||||
|
activeIndex = 0;
|
||||||
|
loading = true;
|
||||||
|
await fetchAllCaches();
|
||||||
|
loading = false;
|
||||||
|
// Focus input after mount
|
||||||
|
requestAnimationFrame(() => inputEl?.focus());
|
||||||
|
}
|
||||||
|
|
||||||
|
function closePalette() {
|
||||||
|
open = false;
|
||||||
|
query = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
function navigateTo(result: SearchResult) {
|
||||||
|
closePalette();
|
||||||
|
goto(result.href);
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleKeydown(e: KeyboardEvent) {
|
||||||
|
if (!open) {
|
||||||
|
// Global shortcut: Ctrl+K / Cmd+K
|
||||||
|
if ((e.ctrlKey || e.metaKey) && e.key === 'k') {
|
||||||
|
e.preventDefault();
|
||||||
|
openPalette();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (e.key === 'Escape') {
|
||||||
|
closePalette();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (e.key === 'ArrowDown') {
|
||||||
|
e.preventDefault();
|
||||||
|
activeIndex = Math.min(activeIndex + 1, flatResults.length - 1);
|
||||||
|
scrollToActive();
|
||||||
|
} else if (e.key === 'ArrowUp') {
|
||||||
|
e.preventDefault();
|
||||||
|
activeIndex = Math.max(activeIndex - 1, 0);
|
||||||
|
scrollToActive();
|
||||||
|
} else if (e.key === 'Enter' && flatResults[activeIndex]) {
|
||||||
|
e.preventDefault();
|
||||||
|
navigateTo(flatResults[activeIndex]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function scrollToActive() {
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
const el = document.querySelector('.sp-item.sp-active');
|
||||||
|
el?.scrollIntoView({ block: 'nearest' });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset active index when query changes
|
||||||
|
$effect(() => {
|
||||||
|
query; // track
|
||||||
|
activeIndex = 0;
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<svelte:window onkeydown={handleKeydown} />
|
||||||
|
|
||||||
|
{#if open}
|
||||||
|
<!-- Backdrop -->
|
||||||
|
<div class="sp-backdrop" onclick={closePalette} role="presentation"></div>
|
||||||
|
|
||||||
|
<!-- Palette -->
|
||||||
|
<div class="sp-container">
|
||||||
|
<div class="sp-input-row">
|
||||||
|
<MdiIcon name="mdiMagnify" size={20} />
|
||||||
|
<input
|
||||||
|
bind:this={inputEl}
|
||||||
|
bind:value={query}
|
||||||
|
placeholder={t('searchPalette.placeholder')}
|
||||||
|
class="sp-input"
|
||||||
|
type="text"
|
||||||
|
/>
|
||||||
|
<kbd class="sp-kbd">ESC</kbd>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="sp-results">
|
||||||
|
{#if loading}
|
||||||
|
<div class="sp-empty">
|
||||||
|
<div class="w-4 h-4 rounded-full border-2 border-[var(--color-primary)] border-t-transparent animate-spin"></div>
|
||||||
|
<span>{t('common.loading')}</span>
|
||||||
|
</div>
|
||||||
|
{:else if flatResults.length === 0}
|
||||||
|
<div class="sp-empty">
|
||||||
|
<MdiIcon name="mdiMagnifyClose" size={24} />
|
||||||
|
<span>{query ? t('searchPalette.noResults') : t('searchPalette.typeToSearch')}</span>
|
||||||
|
</div>
|
||||||
|
{:else}
|
||||||
|
{#each groupedResults as group}
|
||||||
|
<div class="sp-group-header">
|
||||||
|
<MdiIcon name={group.icon} size={14} />
|
||||||
|
{group.label}
|
||||||
|
</div>
|
||||||
|
{#each group.items as item, i}
|
||||||
|
{@const flatIdx = flatResults.indexOf(item)}
|
||||||
|
<button
|
||||||
|
class="sp-item"
|
||||||
|
class:sp-active={flatIdx === activeIndex}
|
||||||
|
onclick={() => navigateTo(item)}
|
||||||
|
onmouseenter={() => activeIndex = flatIdx}
|
||||||
|
>
|
||||||
|
<span class="sp-item-icon"><MdiIcon name={item.icon} size={18} /></span>
|
||||||
|
<span class="sp-item-name">{item.name}</span>
|
||||||
|
{#if item.detail}
|
||||||
|
<span class="sp-item-detail">{item.detail}</span>
|
||||||
|
{/if}
|
||||||
|
</button>
|
||||||
|
{/each}
|
||||||
|
{/each}
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="sp-footer">
|
||||||
|
<span><kbd>↑↓</kbd> {t('searchPalette.navigate')}</span>
|
||||||
|
<span><kbd>↵</kbd> {t('searchPalette.open')}</span>
|
||||||
|
<span><kbd>esc</kbd> {t('searchPalette.close')}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.sp-backdrop {
|
||||||
|
position: fixed;
|
||||||
|
top: 0; left: 0; right: 0; bottom: 0;
|
||||||
|
z-index: 9998;
|
||||||
|
background: rgba(0, 0, 0, 0.5);
|
||||||
|
backdrop-filter: blur(4px);
|
||||||
|
}
|
||||||
|
.sp-container {
|
||||||
|
position: fixed;
|
||||||
|
top: 20vh;
|
||||||
|
left: 50%;
|
||||||
|
transform: translateX(-50%);
|
||||||
|
z-index: 9999;
|
||||||
|
width: min(500px, 90vw);
|
||||||
|
background: var(--color-card);
|
||||||
|
border: 1px solid var(--color-border);
|
||||||
|
border-radius: 0.75rem;
|
||||||
|
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
.sp-input-row {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.5rem;
|
||||||
|
padding: 0.75rem 1rem;
|
||||||
|
border-bottom: 1px solid var(--color-border);
|
||||||
|
color: var(--color-muted-foreground);
|
||||||
|
}
|
||||||
|
.sp-input {
|
||||||
|
flex: 1;
|
||||||
|
border: none;
|
||||||
|
outline: none;
|
||||||
|
background: transparent;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
color: var(--color-foreground);
|
||||||
|
}
|
||||||
|
.sp-kbd {
|
||||||
|
font-size: 0.6rem;
|
||||||
|
font-family: var(--font-mono);
|
||||||
|
padding: 0.15rem 0.35rem;
|
||||||
|
border-radius: 0.25rem;
|
||||||
|
background: var(--color-muted);
|
||||||
|
color: var(--color-muted-foreground);
|
||||||
|
border: 1px solid var(--color-border);
|
||||||
|
}
|
||||||
|
.sp-results {
|
||||||
|
max-height: 50vh;
|
||||||
|
overflow-y: auto;
|
||||||
|
scrollbar-width: thin;
|
||||||
|
padding: 0.25rem;
|
||||||
|
}
|
||||||
|
.sp-empty {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 0.5rem;
|
||||||
|
padding: 2rem;
|
||||||
|
color: var(--color-muted-foreground);
|
||||||
|
font-size: 0.85rem;
|
||||||
|
}
|
||||||
|
.sp-group-header {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.375rem;
|
||||||
|
padding: 0.375rem 0.75rem;
|
||||||
|
font-size: 0.65rem;
|
||||||
|
font-weight: 600;
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 0.04em;
|
||||||
|
color: var(--color-muted-foreground);
|
||||||
|
font-family: var(--font-mono);
|
||||||
|
margin-top: 0.25rem;
|
||||||
|
}
|
||||||
|
.sp-item {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.5rem;
|
||||||
|
width: 100%;
|
||||||
|
padding: 0.5rem 0.75rem;
|
||||||
|
border-radius: 0.375rem;
|
||||||
|
border: none;
|
||||||
|
background: transparent;
|
||||||
|
color: var(--color-foreground);
|
||||||
|
font-size: 0.85rem;
|
||||||
|
cursor: pointer;
|
||||||
|
text-align: left;
|
||||||
|
transition: background 0.1s;
|
||||||
|
}
|
||||||
|
.sp-item:hover, .sp-item.sp-active {
|
||||||
|
background: var(--color-muted);
|
||||||
|
}
|
||||||
|
.sp-item-icon {
|
||||||
|
flex-shrink: 0;
|
||||||
|
color: var(--color-muted-foreground);
|
||||||
|
}
|
||||||
|
.sp-item.sp-active .sp-item-icon {
|
||||||
|
color: var(--color-primary);
|
||||||
|
}
|
||||||
|
.sp-item-name {
|
||||||
|
flex: 1;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
.sp-item-detail {
|
||||||
|
font-size: 0.7rem;
|
||||||
|
font-family: var(--font-mono);
|
||||||
|
color: var(--color-muted-foreground);
|
||||||
|
padding: 0.1rem 0.35rem;
|
||||||
|
border-radius: 9999px;
|
||||||
|
background: var(--color-muted);
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
.sp-footer {
|
||||||
|
display: flex;
|
||||||
|
gap: 1rem;
|
||||||
|
padding: 0.5rem 1rem;
|
||||||
|
border-top: 1px solid var(--color-border);
|
||||||
|
font-size: 0.65rem;
|
||||||
|
color: var(--color-muted-foreground);
|
||||||
|
}
|
||||||
|
.sp-footer kbd {
|
||||||
|
font-family: var(--font-mono);
|
||||||
|
padding: 0.05rem 0.25rem;
|
||||||
|
border-radius: 0.2rem;
|
||||||
|
background: var(--color-muted);
|
||||||
|
border: 1px solid var(--color-border);
|
||||||
|
font-size: 0.6rem;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -699,5 +699,13 @@
|
|||||||
"undefinedVar": "Unknown variable",
|
"undefinedVar": "Unknown variable",
|
||||||
"line": "line",
|
"line": "line",
|
||||||
"add": "Add"
|
"add": "Add"
|
||||||
|
},
|
||||||
|
"searchPalette": {
|
||||||
|
"placeholder": "Search entities...",
|
||||||
|
"noResults": "No results found",
|
||||||
|
"typeToSearch": "Start typing to search",
|
||||||
|
"navigate": "navigate",
|
||||||
|
"open": "open",
|
||||||
|
"close": "close"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -699,5 +699,13 @@
|
|||||||
"undefinedVar": "Неизвестная переменная",
|
"undefinedVar": "Неизвестная переменная",
|
||||||
"line": "строка",
|
"line": "строка",
|
||||||
"add": "Добавить"
|
"add": "Добавить"
|
||||||
|
},
|
||||||
|
"searchPalette": {
|
||||||
|
"placeholder": "Поиск объектов...",
|
||||||
|
"noResults": "Ничего не найдено",
|
||||||
|
"typeToSearch": "Начните вводить для поиска",
|
||||||
|
"navigate": "навигация",
|
||||||
|
"open": "открыть",
|
||||||
|
"close": "закрыть"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,11 +9,15 @@ import { createEntityCache } from './entity-cache.svelte';
|
|||||||
import type {
|
import type {
|
||||||
ServiceProvider,
|
ServiceProvider,
|
||||||
NotificationTarget,
|
NotificationTarget,
|
||||||
|
Tracker,
|
||||||
TrackingConfig,
|
TrackingConfig,
|
||||||
TemplateConfig,
|
TemplateConfig,
|
||||||
TelegramBot,
|
TelegramBot,
|
||||||
EmailBot,
|
EmailBot,
|
||||||
MatrixBot,
|
MatrixBot,
|
||||||
|
CommandConfig,
|
||||||
|
CommandTemplateConfig,
|
||||||
|
CommandTracker,
|
||||||
} from '$lib/types';
|
} from '$lib/types';
|
||||||
|
|
||||||
/** Service providers — used by Dashboard, Trackers, Command Trackers, Providers page. */
|
/** Service providers — used by Dashboard, Trackers, Command Trackers, Providers page. */
|
||||||
@@ -22,6 +26,9 @@ export const providersCache = createEntityCache<ServiceProvider>('/providers');
|
|||||||
/** Notification targets — used by Trackers, Targets page. */
|
/** Notification targets — used by Trackers, Targets page. */
|
||||||
export const targetsCache = createEntityCache<NotificationTarget>('/targets');
|
export const targetsCache = createEntityCache<NotificationTarget>('/targets');
|
||||||
|
|
||||||
|
/** Notification trackers — used by Dashboard, Trackers page. */
|
||||||
|
export const notificationTrackersCache = createEntityCache<Tracker>('/notification-trackers');
|
||||||
|
|
||||||
/** Tracking configs — used by Trackers, Tracking Configs page. */
|
/** Tracking configs — used by Trackers, Tracking Configs page. */
|
||||||
export const trackingConfigsCache = createEntityCache<TrackingConfig>('/tracking-configs');
|
export const trackingConfigsCache = createEntityCache<TrackingConfig>('/tracking-configs');
|
||||||
|
|
||||||
@@ -37,23 +44,42 @@ export const emailBotsCache = createEntityCache<EmailBot>('/email-bots');
|
|||||||
/** Matrix bots — used by Targets, Bots page. */
|
/** Matrix bots — used by Targets, Bots page. */
|
||||||
export const matrixBotsCache = createEntityCache<MatrixBot>('/matrix-bots');
|
export const matrixBotsCache = createEntityCache<MatrixBot>('/matrix-bots');
|
||||||
|
|
||||||
// Command-specific caches (less shared but still benefit from caching)
|
/** Command configs — used by Command Trackers, Command Configs page. */
|
||||||
|
export const commandConfigsCache = createEntityCache<CommandConfig>('/command-configs');
|
||||||
|
|
||||||
export const commandConfigsCache = createEntityCache<any>('/command-configs');
|
/** Command template configs — used by Command Configs, Command Template Configs page. */
|
||||||
|
export const commandTemplateConfigsCache = createEntityCache<CommandTemplateConfig>('/command-template-configs');
|
||||||
|
|
||||||
export const commandTemplateConfigsCache = createEntityCache<any>('/command-template-configs');
|
/** Command trackers — used by Command Trackers page. */
|
||||||
|
export const commandTrackersCache = createEntityCache<CommandTracker>('/command-trackers');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* All caches keyed by entity type — for search palette and crosslink resolution.
|
||||||
|
*/
|
||||||
|
export const allCaches = {
|
||||||
|
providers: providersCache,
|
||||||
|
targets: targetsCache,
|
||||||
|
notification_trackers: notificationTrackersCache,
|
||||||
|
tracking_configs: trackingConfigsCache,
|
||||||
|
template_configs: templateConfigsCache,
|
||||||
|
telegram_bots: telegramBotsCache,
|
||||||
|
email_bots: emailBotsCache,
|
||||||
|
matrix_bots: matrixBotsCache,
|
||||||
|
command_configs: commandConfigsCache,
|
||||||
|
command_template_configs: commandTemplateConfigsCache,
|
||||||
|
command_trackers: commandTrackersCache,
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch all caches in parallel. Used by search palette.
|
||||||
|
*/
|
||||||
|
export async function fetchAllCaches(): Promise<void> {
|
||||||
|
await Promise.all(Object.values(allCaches).map(c => c.fetch()));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invalidate all entity caches. Useful on logout.
|
* Invalidate all entity caches. Useful on logout.
|
||||||
*/
|
*/
|
||||||
export function clearAllCaches(): void {
|
export function clearAllCaches(): void {
|
||||||
providersCache.clear();
|
Object.values(allCaches).forEach(c => c.clear());
|
||||||
targetsCache.clear();
|
|
||||||
trackingConfigsCache.clear();
|
|
||||||
templateConfigsCache.clear();
|
|
||||||
telegramBotsCache.clear();
|
|
||||||
emailBotsCache.clear();
|
|
||||||
matrixBotsCache.clear();
|
|
||||||
commandConfigsCache.clear();
|
|
||||||
commandTemplateConfigsCache.clear();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -166,6 +166,43 @@ export interface User {
|
|||||||
created_at: string;
|
created_at: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface CommandConfig {
|
||||||
|
id: number;
|
||||||
|
user_id: number;
|
||||||
|
provider_type: string;
|
||||||
|
name: string;
|
||||||
|
icon: string;
|
||||||
|
enabled_commands: string[];
|
||||||
|
locale: string;
|
||||||
|
response_mode: string;
|
||||||
|
default_count: number;
|
||||||
|
rate_limits: Record<string, number>;
|
||||||
|
command_template_config_id: number | null;
|
||||||
|
created_at: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CommandTemplateConfig {
|
||||||
|
id: number;
|
||||||
|
user_id: number;
|
||||||
|
provider_type: string;
|
||||||
|
name: string;
|
||||||
|
description: string;
|
||||||
|
icon: string;
|
||||||
|
slots: Record<string, string>;
|
||||||
|
created_at: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CommandTracker {
|
||||||
|
id: number;
|
||||||
|
user_id: number;
|
||||||
|
name: string;
|
||||||
|
icon: string;
|
||||||
|
provider_id: number;
|
||||||
|
command_config_id: number;
|
||||||
|
enabled: boolean;
|
||||||
|
created_at: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface DashboardStatus {
|
export interface DashboardStatus {
|
||||||
providers: number;
|
providers: number;
|
||||||
trackers: { total: number; active: number };
|
trackers: { total: number; active: number };
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
import Modal from '$lib/components/Modal.svelte';
|
import Modal from '$lib/components/Modal.svelte';
|
||||||
import MdiIcon from '$lib/components/MdiIcon.svelte';
|
import MdiIcon from '$lib/components/MdiIcon.svelte';
|
||||||
import Snackbar from '$lib/components/Snackbar.svelte';
|
import Snackbar from '$lib/components/Snackbar.svelte';
|
||||||
|
import SearchPalette from '$lib/components/SearchPalette.svelte';
|
||||||
import { snackSuccess, snackError } from '$lib/stores/snackbar.svelte';
|
import { snackSuccess, snackError } from '$lib/stores/snackbar.svelte';
|
||||||
|
|
||||||
let { children } = $props();
|
let { children } = $props();
|
||||||
@@ -440,6 +441,7 @@
|
|||||||
</Modal>
|
</Modal>
|
||||||
|
|
||||||
<Snackbar />
|
<Snackbar />
|
||||||
|
<SearchPalette />
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
@media (max-width: 767px) {
|
@media (max-width: 767px) {
|
||||||
|
|||||||
@@ -11,8 +11,15 @@
|
|||||||
import EmptyState from '$lib/components/EmptyState.svelte';
|
import EmptyState from '$lib/components/EmptyState.svelte';
|
||||||
import ConfirmModal from '$lib/components/ConfirmModal.svelte';
|
import ConfirmModal from '$lib/components/ConfirmModal.svelte';
|
||||||
import IconButton from '$lib/components/IconButton.svelte';
|
import IconButton from '$lib/components/IconButton.svelte';
|
||||||
|
import CrossLink from '$lib/components/CrossLink.svelte';
|
||||||
import { snackSuccess, snackError } from '$lib/stores/snackbar.svelte';
|
import { snackSuccess, snackError } from '$lib/stores/snackbar.svelte';
|
||||||
|
|
||||||
|
function templateName(id: number | null): string {
|
||||||
|
if (!id) return '';
|
||||||
|
const tpl = cmdTemplateConfigs.find((c: any) => c.id === id);
|
||||||
|
return tpl?.name || `#${id}`;
|
||||||
|
}
|
||||||
|
|
||||||
let configs = $derived(commandConfigsCache.items);
|
let configs = $derived(commandConfigsCache.items);
|
||||||
let cmdTemplateConfigs = $derived(commandTemplateConfigsCache.items);
|
let cmdTemplateConfigs = $derived(commandTemplateConfigsCache.items);
|
||||||
let loaded = $state(false);
|
let loaded = $state(false);
|
||||||
@@ -243,10 +250,15 @@
|
|||||||
</span>
|
</span>
|
||||||
<span class="text-xs text-[var(--color-muted-foreground)]">{cfg.locale?.toUpperCase()}</span>
|
<span class="text-xs text-[var(--color-muted-foreground)]">{cfg.locale?.toUpperCase()}</span>
|
||||||
</div>
|
</div>
|
||||||
<p class="text-xs text-[var(--color-muted-foreground)] mt-0.5">
|
<div class="flex items-center gap-2 mt-0.5">
|
||||||
{t('commandConfig.responseMode')}: {cfg.response_mode === 'media' ? t('commandConfig.modeMedia') : t('commandConfig.modeText')}
|
<span class="text-xs text-[var(--color-muted-foreground)]">
|
||||||
· {t('commandConfig.defaultCount')}: {cfg.default_count}
|
{t('commandConfig.responseMode')}: {cfg.response_mode === 'media' ? t('commandConfig.modeMedia') : t('commandConfig.modeText')}
|
||||||
</p>
|
· {t('commandConfig.defaultCount')}: {cfg.default_count}
|
||||||
|
</span>
|
||||||
|
{#if cfg.command_template_config_id}
|
||||||
|
<CrossLink href="/command-template-configs" icon="mdiCodeBracesBox" label={templateName(cfg.command_template_config_id)} />
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex items-center gap-1">
|
<div class="flex items-center gap-1">
|
||||||
<IconButton icon="mdiPencil" title={t('common.edit')} onclick={() => editConfig(cfg)} />
|
<IconButton icon="mdiPencil" title={t('common.edit')} onclick={() => editConfig(cfg)} />
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
import EmptyState from '$lib/components/EmptyState.svelte';
|
import EmptyState from '$lib/components/EmptyState.svelte';
|
||||||
import ConfirmModal from '$lib/components/ConfirmModal.svelte';
|
import ConfirmModal from '$lib/components/ConfirmModal.svelte';
|
||||||
import IconButton from '$lib/components/IconButton.svelte';
|
import IconButton from '$lib/components/IconButton.svelte';
|
||||||
|
import CrossLink from '$lib/components/CrossLink.svelte';
|
||||||
import { snackSuccess, snackError } from '$lib/stores/snackbar.svelte';
|
import { snackSuccess, snackError } from '$lib/stores/snackbar.svelte';
|
||||||
import type { ServiceProvider, TelegramBot } from '$lib/types';
|
import type { ServiceProvider, TelegramBot } from '$lib/types';
|
||||||
|
|
||||||
@@ -231,8 +232,8 @@
|
|||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
<span style="color: var(--color-primary);"><MdiIcon name={trk.icon || 'mdiConsoleLine'} size={20} /></span>
|
<span style="color: var(--color-primary);"><MdiIcon name={trk.icon || 'mdiConsoleLine'} size={20} /></span>
|
||||||
<p class="font-medium">{trk.name}</p>
|
<p class="font-medium">{trk.name}</p>
|
||||||
<span class="text-xs px-1.5 py-0.5 rounded bg-[var(--color-muted)] text-[var(--color-muted-foreground)]">{providerName(trk.provider_id)}</span>
|
<CrossLink href="/providers" icon="mdiServer" label={providerName(trk.provider_id)} />
|
||||||
<span class="text-xs px-1.5 py-0.5 rounded bg-[var(--color-muted)] text-[var(--color-muted-foreground)]">{configName(trk.command_config_id)}</span>
|
<CrossLink href="/command-configs" icon="mdiCog" label={configName(trk.command_config_id)} />
|
||||||
<span class="text-xs px-1.5 py-0.5 rounded font-mono {trk.enabled
|
<span class="text-xs px-1.5 py-0.5 rounded font-mono {trk.enabled
|
||||||
? 'bg-emerald-500/10 text-emerald-500'
|
? 'bg-emerald-500/10 text-emerald-500'
|
||||||
: 'bg-red-500/10 text-red-500'}">
|
: 'bg-red-500/10 text-red-500'}">
|
||||||
@@ -269,7 +270,7 @@
|
|||||||
<div class="flex items-center justify-between text-sm px-2 py-1 rounded hover:bg-[var(--color-muted)]">
|
<div class="flex items-center justify-between text-sm px-2 py-1 rounded hover:bg-[var(--color-muted)]">
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
<MdiIcon name="mdiRobot" size={14} />
|
<MdiIcon name="mdiRobot" size={14} />
|
||||||
<span class="font-medium">{listener.name || listener.listener_type}</span>
|
<CrossLink href="/telegram-bots" icon="mdiRobot" label={listener.name || listener.listener_type} />
|
||||||
<span class="text-xs px-1.5 py-0.5 rounded bg-blue-500/10 text-blue-500 font-mono">{listener.listener_type}</span>
|
<span class="text-xs px-1.5 py-0.5 rounded bg-blue-500/10 text-blue-500 font-mono">{listener.listener_type}</span>
|
||||||
</div>
|
</div>
|
||||||
<IconButton icon="mdiClose" title={t('commandTracker.removeListener')} size={14}
|
<IconButton icon="mdiClose" title={t('commandTracker.removeListener')} size={14}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
import ConfirmModal from '$lib/components/ConfirmModal.svelte';
|
import ConfirmModal from '$lib/components/ConfirmModal.svelte';
|
||||||
import Hint from '$lib/components/Hint.svelte';
|
import Hint from '$lib/components/Hint.svelte';
|
||||||
import IconButton from '$lib/components/IconButton.svelte';
|
import IconButton from '$lib/components/IconButton.svelte';
|
||||||
|
import CrossLink from '$lib/components/CrossLink.svelte';
|
||||||
import { snackSuccess, snackError } from '$lib/stores/snackbar.svelte';
|
import { snackSuccess, snackError } from '$lib/stores/snackbar.svelte';
|
||||||
import type { Tracker, ServiceProvider, NotificationTarget, TrackingConfig, TemplateConfig } from '$lib/types';
|
import type { Tracker, ServiceProvider, NotificationTarget, TrackingConfig, TemplateConfig } from '$lib/types';
|
||||||
|
|
||||||
@@ -234,6 +235,11 @@
|
|||||||
return p?.type || '';
|
return p?.type || '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getProviderName(id: number): string {
|
||||||
|
const p = providers.find(p => p.id === id);
|
||||||
|
return p?.name || `#${id}`;
|
||||||
|
}
|
||||||
|
|
||||||
function configsForTracker(tracker: any, configs: (TrackingConfig | TemplateConfig)[]): any[] {
|
function configsForTracker(tracker: any, configs: (TrackingConfig | TemplateConfig)[]): any[] {
|
||||||
const pt = getProviderType(tracker);
|
const pt = getProviderType(tracker);
|
||||||
return pt ? configs.filter((c: any) => c.provider_type === pt) : configs;
|
return pt ? configs.filter((c: any) => c.provider_type === pt) : configs;
|
||||||
@@ -373,6 +379,7 @@
|
|||||||
<span class="text-xs px-1.5 py-0.5 rounded {tracker.enabled ? 'bg-[var(--color-success-bg)] text-[var(--color-success-fg)]' : 'bg-[var(--color-muted)] text-[var(--color-muted-foreground)]'}">
|
<span class="text-xs px-1.5 py-0.5 rounded {tracker.enabled ? 'bg-[var(--color-success-bg)] text-[var(--color-success-fg)]' : 'bg-[var(--color-muted)] text-[var(--color-muted-foreground)]'}">
|
||||||
{tracker.enabled ? t('notificationTracker.active') : t('notificationTracker.paused')}
|
{tracker.enabled ? t('notificationTracker.active') : t('notificationTracker.paused')}
|
||||||
</span>
|
</span>
|
||||||
|
t <CrossLink href="/providers" icon="mdiServer" label={getProviderName(tracker.provider_id)} />
|
||||||
</div>
|
</div>
|
||||||
<p class="text-sm text-[var(--color-muted-foreground)]">
|
<p class="text-sm text-[var(--color-muted-foreground)]">
|
||||||
{(tracker.collection_ids || []).length} {t('notificationTracker.albums_count')} · {t('notificationTracker.every')} {tracker.scan_interval}s · {(tracker.tracker_targets || []).length} {t('notificationTracker.linkedTargets')}
|
{(tracker.collection_ids || []).length} {t('notificationTracker.albums_count')} · {t('notificationTracker.every')} {tracker.scan_interval}s · {(tracker.tracker_targets || []).length} {t('notificationTracker.linkedTargets')}
|
||||||
|
|||||||
@@ -14,9 +14,34 @@
|
|||||||
import ConfirmModal from '$lib/components/ConfirmModal.svelte';
|
import ConfirmModal from '$lib/components/ConfirmModal.svelte';
|
||||||
import Hint from '$lib/components/Hint.svelte';
|
import Hint from '$lib/components/Hint.svelte';
|
||||||
import IconButton from '$lib/components/IconButton.svelte';
|
import IconButton from '$lib/components/IconButton.svelte';
|
||||||
|
import CrossLink from '$lib/components/CrossLink.svelte';
|
||||||
|
import IconGridSelect from '$lib/components/IconGridSelect.svelte';
|
||||||
import { snackSuccess, snackError } from '$lib/stores/snackbar.svelte';
|
import { snackSuccess, snackError } from '$lib/stores/snackbar.svelte';
|
||||||
import type { NotificationTarget, TelegramBot, TelegramChat, EmailBot, MatrixBot } from '$lib/types';
|
import type { NotificationTarget, TelegramBot, TelegramChat, EmailBot, MatrixBot } from '$lib/types';
|
||||||
|
|
||||||
|
function getBotName(target: any): string | null {
|
||||||
|
if (target.type === 'telegram' && target.config?.bot_id) {
|
||||||
|
const bot = telegramBots.find(b => b.id === target.config.bot_id);
|
||||||
|
return bot?.name || null;
|
||||||
|
}
|
||||||
|
if (target.type === 'email' && target.config?.email_bot_id) {
|
||||||
|
const bot = emailBots.find(b => b.id === target.config.email_bot_id);
|
||||||
|
return bot?.name || null;
|
||||||
|
}
|
||||||
|
if (target.type === 'matrix' && target.config?.matrix_bot_id) {
|
||||||
|
const bot = matrixBots.find(b => b.id === target.config.matrix_bot_id);
|
||||||
|
return bot?.name || null;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getBotHref(target: any): string {
|
||||||
|
if (target.type === 'telegram') return '/telegram-bots';
|
||||||
|
if (target.type === 'email') return '/telegram-bots?tab=email';
|
||||||
|
if (target.type === 'matrix') return '/telegram-bots?tab=matrix';
|
||||||
|
return '/telegram-bots';
|
||||||
|
}
|
||||||
|
|
||||||
const ALL_TYPES = ['telegram', 'webhook', 'email', 'discord', 'slack', 'ntfy', 'matrix'] as const;
|
const ALL_TYPES = ['telegram', 'webhook', 'email', 'discord', 'slack', 'ntfy', 'matrix'] as const;
|
||||||
type TargetType = typeof ALL_TYPES[number];
|
type TargetType = typeof ALL_TYPES[number];
|
||||||
const TYPE_ICONS: Record<string, string> = {
|
const TYPE_ICONS: Record<string, string> = {
|
||||||
@@ -28,6 +53,12 @@
|
|||||||
discord: 'targets.descDiscord', slack: 'targets.descSlack', ntfy: 'targets.descNtfy', matrix: 'targets.descMatrix',
|
discord: 'targets.descDiscord', slack: 'targets.descSlack', ntfy: 'targets.descNtfy', matrix: 'targets.descMatrix',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const typeGridItems = $derived(ALL_TYPES.map(tt => ({
|
||||||
|
value: tt,
|
||||||
|
icon: TYPE_ICONS[tt] || 'mdiTarget',
|
||||||
|
label: tt.charAt(0).toUpperCase() + tt.slice(1),
|
||||||
|
})));
|
||||||
|
|
||||||
let allTargets = $derived(targetsCache.items);
|
let allTargets = $derived(targetsCache.items);
|
||||||
let activeType = $derived(page.url.searchParams.get('type') as TargetType | null);
|
let activeType = $derived(page.url.searchParams.get('type') as TargetType | null);
|
||||||
let targets = $derived(activeType ? allTargets.filter(t => t.type === activeType) : allTargets);
|
let targets = $derived(activeType ? allTargets.filter(t => t.type === activeType) : allTargets);
|
||||||
@@ -189,13 +220,8 @@
|
|||||||
<form onsubmit={save} class="space-y-4">
|
<form onsubmit={save} class="space-y-4">
|
||||||
{#if !activeType}
|
{#if !activeType}
|
||||||
<div>
|
<div>
|
||||||
<label for="tgt-type" class="block text-sm font-medium mb-1">{t('targets.type')}</label>
|
<label class="block text-sm font-medium mb-1">{t('targets.type')}</label>
|
||||||
<select id="tgt-type" bind:value={formType}
|
<IconGridSelect items={typeGridItems} bind:value={formType} columns={4} />
|
||||||
class="w-full px-3 py-2 border border-[var(--color-border)] rounded-md text-sm bg-[var(--color-background)]">
|
|
||||||
{#each ALL_TYPES as tt}
|
|
||||||
<option value={tt}>{tt.charAt(0).toUpperCase() + tt.slice(1)}</option>
|
|
||||||
{/each}
|
|
||||||
</select>
|
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
<div>
|
<div>
|
||||||
@@ -380,6 +406,7 @@
|
|||||||
<p class="font-medium">{target.name}</p>
|
<p class="font-medium">{target.name}</p>
|
||||||
{#if !activeType}<span class="text-xs px-1.5 py-0.5 rounded bg-[var(--color-muted)] text-[var(--color-muted-foreground)]">{target.type}</span>{/if}
|
{#if !activeType}<span class="text-xs px-1.5 py-0.5 rounded bg-[var(--color-muted)] text-[var(--color-muted-foreground)]">{target.type}</span>{/if}
|
||||||
{#if target.receiver_count}<span class="text-xs px-1.5 py-0.5 rounded bg-[var(--color-muted)] text-[var(--color-muted-foreground)]">{target.receiver_count} receiver(s)</span>{/if}
|
{#if target.receiver_count}<span class="text-xs px-1.5 py-0.5 rounded bg-[var(--color-muted)] text-[var(--color-muted-foreground)]">{target.receiver_count} receiver(s)</span>{/if}
|
||||||
|
{#if getBotName(target)}<CrossLink href={getBotHref(target)} icon="mdiRobot" label={getBotName(target)} />{/if}
|
||||||
</div>
|
</div>
|
||||||
<p class="text-sm text-[var(--color-muted-foreground)]">
|
<p class="text-sm text-[var(--color-muted-foreground)]">
|
||||||
{#if target.type === 'telegram'}
|
{#if target.type === 'telegram'}
|
||||||
|
|||||||
Reference in New Issue
Block a user