2025-04-11 17:35:06 +02:00
|
|
|
"use client";
|
|
|
|
|
|
2025-04-12 13:19:52 +02:00
|
|
|
import { AppSidebar } from "@/components/app-sidebar";
|
2025-04-11 14:53:00 +02:00
|
|
|
import {
|
|
|
|
|
Breadcrumb,
|
|
|
|
|
BreadcrumbItem,
|
|
|
|
|
BreadcrumbLink,
|
|
|
|
|
BreadcrumbList,
|
|
|
|
|
BreadcrumbPage,
|
|
|
|
|
BreadcrumbSeparator,
|
2025-04-12 13:19:52 +02:00
|
|
|
} from "@/components/ui/breadcrumb";
|
|
|
|
|
import { Separator } from "@/components/ui/separator";
|
2025-04-11 14:53:00 +02:00
|
|
|
import {
|
|
|
|
|
SidebarInset,
|
|
|
|
|
SidebarProvider,
|
|
|
|
|
SidebarTrigger,
|
2025-04-12 13:19:52 +02:00
|
|
|
} from "@/components/ui/sidebar";
|
|
|
|
|
import { Button } from "@/components/ui/button";
|
2025-04-14 13:59:36 +02:00
|
|
|
import {
|
|
|
|
|
Plus,
|
|
|
|
|
Link,
|
|
|
|
|
Home,
|
|
|
|
|
Trash2,
|
|
|
|
|
LayoutGrid,
|
|
|
|
|
List,
|
|
|
|
|
Pencil,
|
2025-04-14 15:46:28 +02:00
|
|
|
Zap,
|
2025-04-14 13:59:36 +02:00
|
|
|
} from "lucide-react";
|
2025-04-11 16:03:56 +02:00
|
|
|
import {
|
|
|
|
|
Card,
|
|
|
|
|
CardContent,
|
|
|
|
|
CardDescription,
|
|
|
|
|
CardFooter,
|
|
|
|
|
CardHeader,
|
|
|
|
|
CardTitle,
|
2025-04-12 13:19:52 +02:00
|
|
|
} from "@/components/ui/card";
|
2025-04-11 16:03:56 +02:00
|
|
|
import {
|
2025-04-11 22:55:17 +02:00
|
|
|
Pagination,
|
|
|
|
|
PaginationContent,
|
|
|
|
|
PaginationEllipsis,
|
|
|
|
|
PaginationItem,
|
|
|
|
|
PaginationLink,
|
|
|
|
|
PaginationNext,
|
|
|
|
|
PaginationPrevious,
|
2025-04-12 13:19:52 +02:00
|
|
|
} from "@/components/ui/pagination";
|
2025-04-11 16:19:02 +02:00
|
|
|
import {
|
2025-04-11 22:55:17 +02:00
|
|
|
AlertDialog,
|
|
|
|
|
AlertDialogAction,
|
|
|
|
|
AlertDialogCancel,
|
|
|
|
|
AlertDialogContent,
|
|
|
|
|
AlertDialogDescription,
|
|
|
|
|
AlertDialogFooter,
|
|
|
|
|
AlertDialogHeader,
|
|
|
|
|
AlertDialogTitle,
|
|
|
|
|
AlertDialogTrigger,
|
2025-04-12 13:19:52 +02:00
|
|
|
} from "@/components/ui/alert-dialog";
|
|
|
|
|
import { Input } from "@/components/ui/input";
|
|
|
|
|
import { Label } from "@/components/ui/label";
|
|
|
|
|
import { Textarea } from "@/components/ui/textarea";
|
|
|
|
|
import {
|
|
|
|
|
Select,
|
|
|
|
|
SelectContent,
|
|
|
|
|
SelectItem,
|
|
|
|
|
SelectTrigger,
|
|
|
|
|
SelectValue,
|
|
|
|
|
} from "@/components/ui/select";
|
2025-04-12 15:42:32 +02:00
|
|
|
import Cookies from "js-cookie";
|
2025-04-11 22:55:17 +02:00
|
|
|
import { useState, useEffect } from "react";
|
2025-04-13 21:10:17 +02:00
|
|
|
import axios from "axios";
|
2025-04-14 21:10:21 +02:00
|
|
|
import {
|
|
|
|
|
Tooltip,
|
|
|
|
|
TooltipContent,
|
|
|
|
|
TooltipProvider,
|
|
|
|
|
TooltipTrigger,
|
|
|
|
|
} from "@/components/ui/tooltip"
|
2025-04-21 12:40:55 +02:00
|
|
|
import { StatusIndicator } from "@/components/status-indicator";
|
2025-04-24 14:01:19 +02:00
|
|
|
import { Toaster } from "@/components/ui/sonner"
|
|
|
|
|
import { toast } from "sonner"
|
2025-04-13 21:10:17 +02:00
|
|
|
|
|
|
|
|
interface Application {
|
|
|
|
|
id: number;
|
|
|
|
|
name: string;
|
|
|
|
|
description?: string;
|
|
|
|
|
icon?: string;
|
|
|
|
|
publicURL: string;
|
|
|
|
|
localURL?: string;
|
|
|
|
|
server?: string;
|
|
|
|
|
online: boolean;
|
|
|
|
|
serverId: number;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface Server {
|
|
|
|
|
id: number;
|
|
|
|
|
name: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface ApplicationsResponse {
|
|
|
|
|
applications: Application[];
|
|
|
|
|
servers: Server[];
|
|
|
|
|
maxPage: number;
|
|
|
|
|
}
|
2025-04-11 17:35:06 +02:00
|
|
|
|
2025-04-11 14:53:00 +02:00
|
|
|
export default function Dashboard() {
|
2025-04-13 21:10:17 +02:00
|
|
|
const [name, setName] = useState<string>("");
|
|
|
|
|
const [description, setDescription] = useState<string>("");
|
|
|
|
|
const [icon, setIcon] = useState<string>("");
|
|
|
|
|
const [publicURL, setPublicURL] = useState<string>("");
|
|
|
|
|
const [localURL, setLocalURL] = useState<string>("");
|
2025-04-12 13:19:52 +02:00
|
|
|
const [serverId, setServerId] = useState<number | null>(null);
|
2025-04-14 13:59:36 +02:00
|
|
|
|
|
|
|
|
const [editName, setEditName] = useState<string>("");
|
|
|
|
|
const [editDescription, setEditDescription] = useState<string>("");
|
|
|
|
|
const [editIcon, setEditIcon] = useState<string>("");
|
|
|
|
|
const [editPublicURL, setEditPublicURL] = useState<string>("");
|
|
|
|
|
const [editLocalURL, setEditLocalURL] = useState<string>("");
|
|
|
|
|
const [editId, setEditId] = useState<number | null>(null);
|
|
|
|
|
const [editServerId, setEditServerId] = useState<number | null>(null);
|
|
|
|
|
|
2025-04-13 21:10:17 +02:00
|
|
|
const [currentPage, setCurrentPage] = useState<number>(1);
|
|
|
|
|
const [maxPage, setMaxPage] = useState<number>(1);
|
|
|
|
|
const [applications, setApplications] = useState<Application[]>([]);
|
|
|
|
|
const [servers, setServers] = useState<Server[]>([]);
|
|
|
|
|
const [loading, setLoading] = useState<boolean>(true);
|
2025-04-12 15:42:32 +02:00
|
|
|
|
2025-04-14 14:47:57 +02:00
|
|
|
const [searchTerm, setSearchTerm] = useState<string>("");
|
|
|
|
|
const [isSearching, setIsSearching] = useState<boolean>(false);
|
|
|
|
|
|
2025-04-21 12:56:32 +02:00
|
|
|
const savedLayout = Cookies.get("layoutPreference-app");
|
|
|
|
|
const initialIsGridLayout = savedLayout === "grid";
|
|
|
|
|
const initialItemsPerPage = initialIsGridLayout ? 15 : 5;
|
|
|
|
|
|
|
|
|
|
const [isGridLayout, setIsGridLayout] = useState<boolean>(initialIsGridLayout);
|
|
|
|
|
const [itemsPerPage, setItemsPerPage] = useState<number>(initialItemsPerPage);
|
2025-04-12 15:42:32 +02:00
|
|
|
|
|
|
|
|
const toggleLayout = () => {
|
|
|
|
|
const newLayout = !isGridLayout;
|
|
|
|
|
setIsGridLayout(newLayout);
|
2025-04-14 13:59:36 +02:00
|
|
|
Cookies.set("layoutPreference-app", newLayout ? "grid" : "standard", {
|
2025-04-12 15:42:32 +02:00
|
|
|
expires: 365,
|
2025-04-14 13:59:36 +02:00
|
|
|
path: "/",
|
|
|
|
|
sameSite: "strict",
|
2025-04-12 15:42:32 +02:00
|
|
|
});
|
2025-04-12 15:49:07 +02:00
|
|
|
setItemsPerPage(newLayout ? 15 : 5);
|
2025-04-12 15:42:32 +02:00
|
|
|
};
|
2025-04-11 22:55:17 +02:00
|
|
|
|
2025-04-11 17:35:06 +02:00
|
|
|
const add = async () => {
|
|
|
|
|
try {
|
2025-04-14 13:59:36 +02:00
|
|
|
await axios.post("/api/applications/add", {
|
|
|
|
|
name,
|
|
|
|
|
description,
|
|
|
|
|
icon,
|
|
|
|
|
publicURL,
|
2025-04-12 13:19:52 +02:00
|
|
|
localURL,
|
2025-04-14 13:59:36 +02:00
|
|
|
serverId,
|
2025-04-12 13:19:52 +02:00
|
|
|
});
|
2025-04-11 22:55:17 +02:00
|
|
|
getApplications();
|
2025-04-24 14:01:19 +02:00
|
|
|
toast.success("Application added successfully");
|
2025-04-11 22:55:17 +02:00
|
|
|
} catch (error: any) {
|
2025-04-14 13:59:36 +02:00
|
|
|
console.log(error.response?.data);
|
2025-04-24 14:01:19 +02:00
|
|
|
toast.error("Failed to add application");
|
2025-04-11 22:55:17 +02:00
|
|
|
}
|
2025-04-14 13:59:36 +02:00
|
|
|
};
|
2025-04-11 22:55:17 +02:00
|
|
|
|
|
|
|
|
const getApplications = async () => {
|
|
|
|
|
try {
|
2025-04-13 21:10:17 +02:00
|
|
|
setLoading(true);
|
|
|
|
|
const response = await axios.post<ApplicationsResponse>(
|
2025-04-14 13:59:36 +02:00
|
|
|
"/api/applications/get",
|
2025-04-13 21:10:17 +02:00
|
|
|
{ page: currentPage, ITEMS_PER_PAGE: itemsPerPage }
|
|
|
|
|
);
|
2025-04-11 22:55:17 +02:00
|
|
|
setApplications(response.data.applications);
|
2025-04-12 13:19:52 +02:00
|
|
|
setServers(response.data.servers);
|
2025-04-11 22:55:17 +02:00
|
|
|
setMaxPage(response.data.maxPage);
|
2025-04-13 21:10:17 +02:00
|
|
|
setLoading(false);
|
2025-04-11 22:55:17 +02:00
|
|
|
} catch (error: any) {
|
2025-04-13 21:10:17 +02:00
|
|
|
console.log(error.response?.data);
|
2025-04-24 14:01:19 +02:00
|
|
|
toast.error("Failed to get applications");
|
2025-04-11 22:55:17 +02:00
|
|
|
}
|
2025-04-14 13:59:36 +02:00
|
|
|
};
|
2025-04-11 22:55:17 +02:00
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
getApplications();
|
2025-04-12 15:49:07 +02:00
|
|
|
}, [currentPage, itemsPerPage]);
|
2025-04-11 22:55:17 +02:00
|
|
|
|
2025-04-14 13:59:36 +02:00
|
|
|
const handlePrevious = () => setCurrentPage((prev) => Math.max(1, prev - 1));
|
|
|
|
|
const handleNext = () =>
|
|
|
|
|
setCurrentPage((prev) => Math.min(maxPage, prev + 1));
|
2025-04-11 22:55:17 +02:00
|
|
|
|
|
|
|
|
const deleteApplication = async (id: number) => {
|
|
|
|
|
try {
|
2025-04-14 13:59:36 +02:00
|
|
|
await axios.post("/api/applications/delete", { id });
|
2025-04-11 22:55:17 +02:00
|
|
|
getApplications();
|
2025-04-24 14:01:19 +02:00
|
|
|
toast.success("Application deleted successfully");
|
2025-04-11 17:35:06 +02:00
|
|
|
} catch (error: any) {
|
2025-04-13 21:10:17 +02:00
|
|
|
console.log(error.response?.data);
|
2025-04-24 14:01:19 +02:00
|
|
|
toast.error("Failed to delete application");
|
2025-04-11 17:35:06 +02:00
|
|
|
}
|
2025-04-14 13:59:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const openEditDialog = (app: Application) => {
|
|
|
|
|
setEditId(app.id);
|
|
|
|
|
setEditServerId(app.serverId);
|
|
|
|
|
setEditName(app.name);
|
|
|
|
|
setEditDescription(app.description || "");
|
|
|
|
|
setEditIcon(app.icon || "");
|
|
|
|
|
setEditLocalURL(app.localURL || "");
|
|
|
|
|
setEditPublicURL(app.publicURL || "");
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const edit = async () => {
|
|
|
|
|
if (!editId) return;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
await axios.put("/api/applications/edit", {
|
|
|
|
|
id: editId,
|
|
|
|
|
serverId: editServerId,
|
|
|
|
|
name: editName,
|
|
|
|
|
description: editDescription,
|
|
|
|
|
icon: editIcon,
|
|
|
|
|
publicURL: editPublicURL,
|
|
|
|
|
localURL: editLocalURL,
|
|
|
|
|
});
|
|
|
|
|
getApplications();
|
|
|
|
|
setEditId(null);
|
2025-04-24 14:01:19 +02:00
|
|
|
toast.success("Application edited successfully");
|
2025-04-14 13:59:36 +02:00
|
|
|
} catch (error: any) {
|
|
|
|
|
console.log(error.response.data);
|
2025-04-24 14:01:19 +02:00
|
|
|
toast.error("Failed to edit application");
|
2025-04-14 13:59:36 +02:00
|
|
|
}
|
|
|
|
|
};
|
2025-04-14 14:50:48 +02:00
|
|
|
|
2025-04-14 14:47:57 +02:00
|
|
|
const searchApplications = async () => {
|
|
|
|
|
try {
|
|
|
|
|
setIsSearching(true);
|
|
|
|
|
const response = await axios.post<{ results: Application[] }>(
|
|
|
|
|
"/api/applications/search",
|
|
|
|
|
{ searchterm: searchTerm }
|
|
|
|
|
);
|
|
|
|
|
setApplications(response.data.results);
|
|
|
|
|
setIsSearching(false);
|
|
|
|
|
} catch (error: any) {
|
|
|
|
|
console.error("Search error:", error.response?.data);
|
|
|
|
|
setIsSearching(false);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const delayDebounce = setTimeout(() => {
|
|
|
|
|
if (searchTerm.trim() === "") {
|
|
|
|
|
getApplications();
|
|
|
|
|
} else {
|
|
|
|
|
searchApplications();
|
|
|
|
|
}
|
|
|
|
|
}, 300);
|
|
|
|
|
|
|
|
|
|
return () => clearTimeout(delayDebounce);
|
|
|
|
|
}, [searchTerm]);
|
|
|
|
|
|
2025-04-14 15:46:28 +02:00
|
|
|
const generateIconURL = async () => {
|
|
|
|
|
setIcon("https://cdn.jsdelivr.net/gh/selfhst/icons/png/" + name.toLowerCase() + ".png")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const generateEditIconURL = async () => {
|
|
|
|
|
setEditIcon("https://cdn.jsdelivr.net/gh/selfhst/icons/png/" + editName.toLowerCase() + ".png")
|
|
|
|
|
}
|
2025-04-11 17:35:06 +02:00
|
|
|
|
2025-04-11 14:53:00 +02:00
|
|
|
return (
|
|
|
|
|
<SidebarProvider>
|
|
|
|
|
<AppSidebar />
|
|
|
|
|
<SidebarInset>
|
2025-04-15 16:25:01 +02:00
|
|
|
<header className="flex h-16 shrink-0 items-center gap-2 border-b bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60">
|
2025-04-11 14:53:00 +02:00
|
|
|
<div className="flex items-center gap-2 px-4">
|
|
|
|
|
<SidebarTrigger className="-ml-1" />
|
|
|
|
|
<Separator orientation="vertical" className="mr-2 h-4" />
|
|
|
|
|
<Breadcrumb>
|
|
|
|
|
<BreadcrumbList>
|
|
|
|
|
<BreadcrumbItem className="hidden md:block">
|
2025-04-11 16:03:56 +02:00
|
|
|
<BreadcrumbPage>/</BreadcrumbPage>
|
2025-04-11 14:53:00 +02:00
|
|
|
</BreadcrumbItem>
|
|
|
|
|
<BreadcrumbSeparator className="hidden md:block" />
|
|
|
|
|
<BreadcrumbItem>
|
2025-04-12 13:21:03 +02:00
|
|
|
<BreadcrumbPage>My Infrastructure</BreadcrumbPage>
|
2025-04-11 14:53:00 +02:00
|
|
|
</BreadcrumbItem>
|
|
|
|
|
<BreadcrumbSeparator className="hidden md:block" />
|
|
|
|
|
<BreadcrumbItem>
|
|
|
|
|
<BreadcrumbPage>Applications</BreadcrumbPage>
|
|
|
|
|
</BreadcrumbItem>
|
|
|
|
|
</BreadcrumbList>
|
|
|
|
|
</Breadcrumb>
|
|
|
|
|
</div>
|
|
|
|
|
</header>
|
2025-04-24 14:01:19 +02:00
|
|
|
<Toaster />
|
2025-04-15 16:25:01 +02:00
|
|
|
<div className="p-6">
|
2025-04-12 13:19:52 +02:00
|
|
|
<div className="flex justify-between items-center">
|
2025-04-15 16:25:01 +02:00
|
|
|
<span className="text-3xl font-bold">Your Applications</span>
|
2025-04-12 15:42:32 +02:00
|
|
|
<div className="flex gap-2">
|
2025-04-14 13:59:36 +02:00
|
|
|
<Button
|
|
|
|
|
variant="outline"
|
2025-04-12 15:42:32 +02:00
|
|
|
size="icon"
|
|
|
|
|
onClick={toggleLayout}
|
2025-04-14 13:59:36 +02:00
|
|
|
title={
|
|
|
|
|
isGridLayout ? "Switch to list view" : "Switch to grid view"
|
|
|
|
|
}
|
2025-04-12 15:42:32 +02:00
|
|
|
>
|
2025-04-14 13:59:36 +02:00
|
|
|
{isGridLayout ? (
|
|
|
|
|
<List className="h-4 w-4" />
|
|
|
|
|
) : (
|
|
|
|
|
<LayoutGrid className="h-4 w-4" />
|
|
|
|
|
)}
|
2025-04-12 15:42:32 +02:00
|
|
|
</Button>
|
|
|
|
|
{servers.length === 0 ? (
|
2025-04-14 13:59:36 +02:00
|
|
|
<p className="text-muted-foreground">
|
|
|
|
|
You must first add a server.
|
|
|
|
|
</p>
|
2025-04-12 15:42:32 +02:00
|
|
|
) : (
|
|
|
|
|
<AlertDialog>
|
|
|
|
|
<AlertDialogTrigger asChild>
|
|
|
|
|
<Button variant="outline" size="icon">
|
|
|
|
|
<Plus />
|
|
|
|
|
</Button>
|
|
|
|
|
</AlertDialogTrigger>
|
|
|
|
|
<AlertDialogContent>
|
|
|
|
|
<AlertDialogHeader>
|
|
|
|
|
<AlertDialogTitle>Add an application</AlertDialogTitle>
|
|
|
|
|
<AlertDialogDescription>
|
|
|
|
|
<div className="space-y-4 pt-4">
|
2025-04-14 13:59:36 +02:00
|
|
|
<div className="grid w-full items-center gap-1.5">
|
|
|
|
|
<Label>Name</Label>
|
|
|
|
|
<Input
|
|
|
|
|
placeholder="e.g. Portainer"
|
|
|
|
|
onChange={(e) => setName(e.target.value)}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="grid w-full items-center gap-1.5">
|
|
|
|
|
<Label>Server</Label>
|
|
|
|
|
<Select
|
|
|
|
|
onValueChange={(v) => setServerId(Number(v))}
|
|
|
|
|
required
|
|
|
|
|
>
|
|
|
|
|
<SelectTrigger className="w-full">
|
|
|
|
|
<SelectValue placeholder="Select server" />
|
|
|
|
|
</SelectTrigger>
|
|
|
|
|
<SelectContent>
|
|
|
|
|
{servers.map((server) => (
|
|
|
|
|
<SelectItem
|
|
|
|
|
key={server.id}
|
|
|
|
|
value={String(server.id)}
|
|
|
|
|
>
|
|
|
|
|
{server.name}
|
|
|
|
|
</SelectItem>
|
|
|
|
|
))}
|
|
|
|
|
</SelectContent>
|
|
|
|
|
</Select>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="grid w-full items-center gap-1.5">
|
|
|
|
|
<Label>
|
|
|
|
|
Description{" "}
|
|
|
|
|
<span className="text-stone-600">(optional)</span>
|
|
|
|
|
</Label>
|
|
|
|
|
<Textarea
|
|
|
|
|
placeholder="Application description"
|
|
|
|
|
onChange={(e) => setDescription(e.target.value)}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="grid w-full items-center gap-1.5">
|
|
|
|
|
<Label>
|
|
|
|
|
Icon URL{" "}
|
|
|
|
|
<span className="text-stone-600">(optional)</span>
|
|
|
|
|
</Label>
|
2025-04-14 15:46:28 +02:00
|
|
|
<div className="flex gap-2">
|
|
|
|
|
<Input
|
|
|
|
|
value={icon}
|
|
|
|
|
placeholder="https://example.com/icon.png"
|
|
|
|
|
onChange={(e) => setIcon(e.target.value)}
|
|
|
|
|
/>
|
2025-04-14 21:10:21 +02:00
|
|
|
<TooltipProvider>
|
|
|
|
|
<Tooltip>
|
|
|
|
|
<TooltipTrigger>
|
|
|
|
|
<Button variant="outline" size="icon" onClick={generateIconURL}>
|
|
|
|
|
<Zap />
|
|
|
|
|
</Button>
|
|
|
|
|
</TooltipTrigger>
|
|
|
|
|
<TooltipContent>
|
|
|
|
|
Generate Icon URL
|
|
|
|
|
</TooltipContent>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
</TooltipProvider>
|
2025-04-14 15:46:28 +02:00
|
|
|
</div>
|
2025-04-14 13:59:36 +02:00
|
|
|
</div>
|
|
|
|
|
<div className="grid w-full items-center gap-1.5">
|
|
|
|
|
<Label>Public URL</Label>
|
|
|
|
|
<Input
|
|
|
|
|
placeholder="https://example.com"
|
|
|
|
|
onChange={(e) => setPublicURL(e.target.value)}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="grid w-full items-center gap-1.5">
|
|
|
|
|
<Label>
|
|
|
|
|
Local URL{" "}
|
|
|
|
|
<span className="text-stone-600">(optional)</span>
|
|
|
|
|
</Label>
|
|
|
|
|
<Input
|
|
|
|
|
placeholder="http://localhost:3000"
|
|
|
|
|
onChange={(e) => setLocalURL(e.target.value)}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2025-04-12 15:42:32 +02:00
|
|
|
</div>
|
|
|
|
|
</AlertDialogDescription>
|
|
|
|
|
</AlertDialogHeader>
|
|
|
|
|
<AlertDialogFooter>
|
|
|
|
|
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
2025-04-14 13:59:36 +02:00
|
|
|
<AlertDialogAction
|
|
|
|
|
onClick={add}
|
|
|
|
|
disabled={!name || !publicURL || !serverId}
|
|
|
|
|
>
|
2025-04-12 15:42:32 +02:00
|
|
|
Add
|
2025-04-12 20:20:17 +02:00
|
|
|
</AlertDialogAction>
|
2025-04-12 15:42:32 +02:00
|
|
|
</AlertDialogFooter>
|
|
|
|
|
</AlertDialogContent>
|
|
|
|
|
</AlertDialog>
|
|
|
|
|
)}
|
2025-04-14 13:59:36 +02:00
|
|
|
</div>
|
2025-04-11 16:03:56 +02:00
|
|
|
</div>
|
2025-04-14 14:47:57 +02:00
|
|
|
<div className="flex flex-col gap-2 mb-4 pt-2">
|
|
|
|
|
<Input
|
|
|
|
|
id="application-search"
|
|
|
|
|
placeholder="Type to search..."
|
|
|
|
|
value={searchTerm}
|
|
|
|
|
onChange={(e) => setSearchTerm(e.target.value)}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2025-04-11 16:03:56 +02:00
|
|
|
<br />
|
2025-04-14 13:59:36 +02:00
|
|
|
{!loading ? (
|
|
|
|
|
<div
|
|
|
|
|
className={
|
|
|
|
|
isGridLayout
|
|
|
|
|
? "grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4"
|
|
|
|
|
: "space-y-4"
|
|
|
|
|
}
|
|
|
|
|
>
|
2025-04-12 17:40:37 +02:00
|
|
|
{applications.map((app) => (
|
2025-04-14 13:59:36 +02:00
|
|
|
<Card
|
|
|
|
|
key={app.id}
|
|
|
|
|
className={
|
|
|
|
|
isGridLayout
|
|
|
|
|
? "h-full flex flex-col justify-between relative"
|
|
|
|
|
: "w-full mb-4 relative"
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
<CardHeader>
|
|
|
|
|
<div className="absolute top-2 right-2">
|
2025-04-21 12:40:55 +02:00
|
|
|
<StatusIndicator isOnline={app.online} />
|
2025-04-12 17:40:37 +02:00
|
|
|
</div>
|
2025-04-21 12:40:55 +02:00
|
|
|
<div className="flex items-center justify-between w-full mt-4 mb-4">
|
2025-04-14 13:59:36 +02:00
|
|
|
<div className="flex items-center">
|
|
|
|
|
<div className="w-16 h-16 flex-shrink-0 flex items-center justify-center rounded-md">
|
|
|
|
|
{app.icon ? (
|
|
|
|
|
<img
|
|
|
|
|
src={app.icon}
|
|
|
|
|
alt={app.name}
|
|
|
|
|
className="w-full h-full object-contain rounded-md"
|
|
|
|
|
/>
|
|
|
|
|
) : (
|
|
|
|
|
<span className="text-gray-500 text-xs">Image</span>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="ml-4">
|
|
|
|
|
<CardTitle className="text-2xl font-bold">
|
|
|
|
|
{app.name}
|
|
|
|
|
</CardTitle>
|
|
|
|
|
<CardDescription className="text-md">
|
|
|
|
|
{app.description}
|
2025-04-14 21:12:12 +02:00
|
|
|
{app.description && (
|
|
|
|
|
<br className="hidden md:block" />
|
|
|
|
|
)}
|
2025-04-14 13:59:36 +02:00
|
|
|
Server: {app.server || "No server"}
|
|
|
|
|
</CardDescription>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2025-04-19 16:15:56 +02:00
|
|
|
<div className="flex flex-col items-end justify-start space-y-2 w-[190px]">
|
2025-04-14 13:59:36 +02:00
|
|
|
<div className="flex items-center gap-2 w-full">
|
|
|
|
|
<div className="flex flex-col space-y-2 flex-grow">
|
|
|
|
|
<Button
|
|
|
|
|
variant="outline"
|
2025-04-12 17:40:37 +02:00
|
|
|
className="gap-2 w-full"
|
2025-04-14 13:59:36 +02:00
|
|
|
onClick={() =>
|
|
|
|
|
window.open(app.publicURL, "_blank")
|
|
|
|
|
}
|
2025-04-12 17:40:37 +02:00
|
|
|
>
|
2025-04-14 13:59:36 +02:00
|
|
|
<Link className="h-4 w-4" />
|
2025-04-19 16:15:56 +02:00
|
|
|
Public URL
|
2025-04-12 17:40:37 +02:00
|
|
|
</Button>
|
2025-04-14 13:59:36 +02:00
|
|
|
{app.localURL && (
|
|
|
|
|
<Button
|
|
|
|
|
variant="outline"
|
|
|
|
|
className="gap-2 w-full"
|
|
|
|
|
onClick={() =>
|
|
|
|
|
window.open(app.localURL, "_blank")
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
<Home className="h-4 w-4" />
|
2025-04-19 16:15:56 +02:00
|
|
|
Local URL
|
2025-04-14 13:59:36 +02:00
|
|
|
</Button>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
2025-04-14 15:35:32 +02:00
|
|
|
<div className="flex flex-col gap-2">
|
|
|
|
|
<Button
|
|
|
|
|
variant="destructive"
|
|
|
|
|
size="icon"
|
|
|
|
|
className="h-9 w-9"
|
|
|
|
|
onClick={() => deleteApplication(app.id)}
|
|
|
|
|
>
|
|
|
|
|
<Trash2 className="h-4 w-4" />
|
|
|
|
|
</Button>
|
|
|
|
|
<AlertDialog>
|
|
|
|
|
<AlertDialogTrigger asChild>
|
|
|
|
|
<Button
|
|
|
|
|
size="icon"
|
|
|
|
|
className="h-9 w-9"
|
|
|
|
|
onClick={() => openEditDialog(app)}
|
2025-04-14 13:59:36 +02:00
|
|
|
>
|
2025-04-14 15:35:32 +02:00
|
|
|
<Pencil className="h-4 w-4" />
|
|
|
|
|
</Button>
|
|
|
|
|
</AlertDialogTrigger>
|
|
|
|
|
<AlertDialogContent>
|
|
|
|
|
<AlertDialogHeader>
|
|
|
|
|
<AlertDialogTitle>
|
|
|
|
|
Edit Application
|
|
|
|
|
</AlertDialogTitle>
|
|
|
|
|
<AlertDialogDescription>
|
|
|
|
|
<div className="space-y-4 pt-4">
|
|
|
|
|
<div className="grid w-full items-center gap-1.5">
|
|
|
|
|
<Label>Name</Label>
|
|
|
|
|
<Input
|
|
|
|
|
placeholder="e.g. Portainer"
|
|
|
|
|
value={editName}
|
|
|
|
|
onChange={(e) =>
|
|
|
|
|
setEditName(e.target.value)
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="grid w-full items-center gap-1.5">
|
|
|
|
|
<Label>Server</Label>
|
|
|
|
|
<Select
|
|
|
|
|
value={
|
|
|
|
|
editServerId !== null
|
|
|
|
|
? String(editServerId)
|
|
|
|
|
: undefined
|
|
|
|
|
}
|
|
|
|
|
onValueChange={(v) =>
|
|
|
|
|
setEditServerId(Number(v))
|
|
|
|
|
}
|
|
|
|
|
required
|
|
|
|
|
>
|
|
|
|
|
<SelectTrigger className="w-full">
|
|
|
|
|
<SelectValue placeholder="Select server" />
|
|
|
|
|
</SelectTrigger>
|
|
|
|
|
<SelectContent>
|
|
|
|
|
{servers.map((server) => (
|
|
|
|
|
<SelectItem
|
|
|
|
|
key={server.id}
|
|
|
|
|
value={String(server.id)}
|
|
|
|
|
>
|
|
|
|
|
{server.name}
|
|
|
|
|
</SelectItem>
|
|
|
|
|
))}
|
|
|
|
|
</SelectContent>
|
|
|
|
|
</Select>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="grid w-full items-center gap-1.5">
|
|
|
|
|
<Label>
|
|
|
|
|
Description{" "}
|
|
|
|
|
<span className="text-stone-600">
|
|
|
|
|
(optional)
|
|
|
|
|
</span>
|
|
|
|
|
</Label>
|
|
|
|
|
<Textarea
|
|
|
|
|
placeholder="Application description"
|
|
|
|
|
value={editDescription}
|
|
|
|
|
onChange={(e) =>
|
|
|
|
|
setEditDescription(e.target.value)
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="grid w-full items-center gap-1.5">
|
|
|
|
|
<Label>
|
|
|
|
|
Icon URL{" "}
|
|
|
|
|
<span className="text-stone-600">
|
|
|
|
|
(optional)
|
|
|
|
|
</span>
|
|
|
|
|
</Label>
|
2025-04-14 15:46:28 +02:00
|
|
|
<div className="flex gap-2">
|
|
|
|
|
<Input
|
|
|
|
|
placeholder="https://example.com/icon.png"
|
|
|
|
|
value={editIcon}
|
|
|
|
|
onChange={(e) =>
|
|
|
|
|
setEditIcon(e.target.value)
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
<Button variant="outline" size="icon" onClick={generateEditIconURL}>
|
|
|
|
|
<Zap />
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
2025-04-14 15:35:32 +02:00
|
|
|
</div>
|
|
|
|
|
<div className="grid w-full items-center gap-1.5">
|
|
|
|
|
<Label>Public URL</Label>
|
|
|
|
|
<Input
|
|
|
|
|
placeholder="https://example.com"
|
|
|
|
|
value={editPublicURL}
|
|
|
|
|
onChange={(e) =>
|
|
|
|
|
setEditPublicURL(e.target.value)
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="grid w-full items-center gap-1.5">
|
|
|
|
|
<Label>
|
|
|
|
|
Local URL{" "}
|
|
|
|
|
<span className="text-stone-600">
|
|
|
|
|
(optional)
|
|
|
|
|
</span>
|
|
|
|
|
</Label>
|
|
|
|
|
<Input
|
|
|
|
|
placeholder="http://localhost:3000"
|
|
|
|
|
value={editLocalURL}
|
|
|
|
|
onChange={(e) =>
|
|
|
|
|
setEditLocalURL(e.target.value)
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</AlertDialogDescription>
|
|
|
|
|
</AlertDialogHeader>
|
|
|
|
|
<AlertDialogFooter>
|
|
|
|
|
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
|
|
|
|
<AlertDialogAction
|
|
|
|
|
onClick={edit}
|
|
|
|
|
disabled={
|
|
|
|
|
!editName || !editPublicURL || !editServerId
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
Save Changes
|
|
|
|
|
</AlertDialogAction>
|
|
|
|
|
</AlertDialogFooter>
|
|
|
|
|
</AlertDialogContent>
|
|
|
|
|
</AlertDialog>
|
|
|
|
|
</div>
|
2025-04-12 17:40:37 +02:00
|
|
|
</div>
|
2025-04-11 22:55:17 +02:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2025-04-14 13:59:36 +02:00
|
|
|
</CardHeader>
|
|
|
|
|
</Card>
|
|
|
|
|
))}
|
2025-04-12 17:40:37 +02:00
|
|
|
</div>
|
2025-04-14 13:59:36 +02:00
|
|
|
) : (
|
|
|
|
|
<div className="flex items-center justify-center">
|
|
|
|
|
<div className="inline-block" role="status" aria-label="loading">
|
|
|
|
|
<svg
|
|
|
|
|
className="w-6 h-6 stroke-white animate-spin "
|
|
|
|
|
viewBox="0 0 24 24"
|
|
|
|
|
fill="none"
|
|
|
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
|
|
|
>
|
|
|
|
|
<g clip-path="url(#clip0_9023_61563)">
|
|
|
|
|
<path
|
|
|
|
|
d="M14.6437 2.05426C11.9803 1.2966 9.01686 1.64245 6.50315 3.25548C1.85499 6.23817 0.504864 12.4242 3.48756 17.0724C6.47025 21.7205 12.6563 23.0706 17.3044 20.088C20.4971 18.0393 22.1338 14.4793 21.8792 10.9444"
|
|
|
|
|
stroke="stroke-current"
|
|
|
|
|
stroke-width="1.4"
|
|
|
|
|
stroke-linecap="round"
|
|
|
|
|
className="my-path"
|
|
|
|
|
></path>
|
|
|
|
|
</g>
|
|
|
|
|
<defs>
|
|
|
|
|
<clipPath id="clip0_9023_61563">
|
|
|
|
|
<rect width="24" height="24" fill="white"></rect>
|
2025-04-12 17:40:37 +02:00
|
|
|
</clipPath>
|
2025-04-14 13:59:36 +02:00
|
|
|
</defs>
|
2025-04-12 17:40:37 +02:00
|
|
|
</svg>
|
2025-04-14 13:59:36 +02:00
|
|
|
<span className="sr-only">Loading...</span>
|
|
|
|
|
</div>
|
2025-04-12 17:40:37 +02:00
|
|
|
</div>
|
2025-04-14 13:59:36 +02:00
|
|
|
)}
|
2025-04-14 21:28:09 +02:00
|
|
|
<div className="pt-4 pb-4">
|
2025-04-12 13:19:52 +02:00
|
|
|
<Pagination>
|
|
|
|
|
<PaginationContent>
|
|
|
|
|
<PaginationItem>
|
2025-04-14 13:59:36 +02:00
|
|
|
<PaginationPrevious
|
2025-04-12 13:19:52 +02:00
|
|
|
onClick={handlePrevious}
|
|
|
|
|
isActive={currentPage > 1}
|
2025-04-14 21:36:15 +02:00
|
|
|
style={{ cursor: currentPage === 1 ? 'not-allowed' : 'pointer' }}
|
2025-04-12 13:19:52 +02:00
|
|
|
/>
|
|
|
|
|
</PaginationItem>
|
|
|
|
|
<PaginationItem>
|
|
|
|
|
<PaginationLink isActive>{currentPage}</PaginationLink>
|
|
|
|
|
</PaginationItem>
|
|
|
|
|
<PaginationItem>
|
2025-04-14 13:59:36 +02:00
|
|
|
<PaginationNext
|
2025-04-12 13:19:52 +02:00
|
|
|
onClick={handleNext}
|
|
|
|
|
isActive={currentPage < maxPage}
|
2025-04-14 21:36:15 +02:00
|
|
|
style={{ cursor: currentPage === maxPage ? 'not-allowed' : 'pointer' }}
|
2025-04-12 13:19:52 +02:00
|
|
|
/>
|
|
|
|
|
</PaginationItem>
|
|
|
|
|
</PaginationContent>
|
|
|
|
|
</Pagination>
|
|
|
|
|
</div>
|
2025-04-11 14:53:00 +02:00
|
|
|
</div>
|
|
|
|
|
</SidebarInset>
|
|
|
|
|
</SidebarProvider>
|
2025-04-14 13:59:36 +02:00
|
|
|
);
|
|
|
|
|
}
|