-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
138 additions
and
2 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
packages/backend/src/notifications/notification-targets.controller.ts
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,33 @@ | ||
import { | ||
Body, | ||
Controller, | ||
Delete, | ||
Get, | ||
Inject, | ||
Param, | ||
Post, | ||
} from "@nestjs/common" | ||
import { NotificationsService } from "./notifications.service" | ||
|
||
@Controller("notification-targets") | ||
export class NotificationTargetsController { | ||
constructor( | ||
@Inject(NotificationsService) | ||
private readonly notificationsService: NotificationsService, | ||
) {} | ||
|
||
@Get() | ||
list() { | ||
return this.notificationsService.listTargets() | ||
} | ||
|
||
@Post() | ||
create(@Body("appriseUrl") appriseUrl: string) { | ||
return this.notificationsService.createTarget(appriseUrl) | ||
} | ||
|
||
@Delete(":id") | ||
delete(@Param("id") id: number) { | ||
return this.notificationsService.deleteTarget(id) | ||
} | ||
} |
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
81 changes: 81 additions & 0 deletions
81
...ages/frontend/src/lib/components/NotificationTargetConfig/NotificationTargetConfig.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,81 @@ | ||
<script lang="ts"> | ||
import * as Table from "$lib/components/ui/table" | ||
import { faPlus, faTrash } from "@fortawesome/free-solid-svg-icons" | ||
import { FontAwesomeIcon } from "@fortawesome/svelte-fontawesome" | ||
import { onMount } from "svelte" | ||
import { Button } from "../ui/button" | ||
import { Input } from "../ui/input" | ||
interface NotificationTarget { | ||
id: number | ||
appriseUrl: string | ||
} | ||
let targets: NotificationTarget[] = [] | ||
let newTargetUrl: string = "" | ||
async function loadTargets() { | ||
targets = await getTargets() | ||
} | ||
async function createTarget() { | ||
await fetch("/api/notification-targets", { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify({ appriseUrl: newTargetUrl }), | ||
}) | ||
newTargetUrl = "" | ||
loadTargets() | ||
} | ||
async function getTargets() { | ||
const response = await fetch("/api/notification-targets") | ||
return await response.json() | ||
} | ||
async function deleteTarget(id: number) { | ||
await fetch(`/api/notification-targets/${id}`, { method: "DELETE" }) | ||
loadTargets() | ||
} | ||
onMount(() => { | ||
loadTargets() | ||
}) | ||
</script> | ||
|
||
<Table.Root> | ||
<Table.Header> | ||
<Table.Row> | ||
<Table.Head class="w-full">Apprise URL</Table.Head> | ||
<Table.Head class="text-right"></Table.Head> | ||
</Table.Row> | ||
</Table.Header> | ||
<Table.Body> | ||
{#each targets as target} | ||
<Table.Row> | ||
<Table.Cell class="font-mono">{target.appriseUrl}</Table.Cell> | ||
<Table.Cell class="text-right"> | ||
<Button on:click={() => deleteTarget(target.id)} variant="destructive" size="sm" title="Delete"> | ||
<FontAwesomeIcon icon={faTrash} /> | ||
</Button> | ||
</Table.Cell> | ||
</Table.Row> | ||
{/each} | ||
<Table.Row class="hover:bg-inherit"> | ||
<Table.Cell> | ||
<Input | ||
class="font-mono" | ||
bind:value={newTargetUrl} | ||
placeholder="tgram://bottoken/ChatID" | ||
/> | ||
</Table.Cell> | ||
<Table.Cell class="text-right"> | ||
<Button on:click={() => createTarget()} size="sm" title="Add"> | ||
<FontAwesomeIcon icon={faPlus} /> | ||
</Button> | ||
</Table.Cell> | ||
</Table.Row> | ||
</Table.Body> | ||
</Table.Root> |
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