From 7023723a16e155fc218e858c7ab538c509da4b0c Mon Sep 17 00:00:00 2001 From: headlessdev Date: Mon, 14 Apr 2025 12:27:49 +0200 Subject: [PATCH 01/12] Fix for database deployment error --- compose.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compose.yml b/compose.yml index df9668f..a7a10df 100644 --- a/compose.yml +++ b/compose.yml @@ -8,7 +8,7 @@ services: LOGIN_PASSWORD: "SecretPassword" JWT_SECRET: RANDOM_SECRET ACCOUNT_SECRET: RANDOM_SECRET - DATABASE_URL: "postgresql://postgres:postgres@db:5432/postgres?sslmode=require&schema=public" + DATABASE_URL: "postgresql://postgres:postgres@db:5432/postgres" depends_on: - db - agent @@ -16,7 +16,7 @@ services: agent: image: haedlessdev/corecontrol-agent:latest environment: - DATABASE_URL: "postgresql://postgres:postgres@db:5432/postgres?sslmode=require&schema=public" + DATABASE_URL: "postgresql://postgres:postgres@db:5432/postgres" db: image: postgres:17 From 130e282cd6895a69e1b5a46e1801d09ccba6a848 Mon Sep 17 00:00:00 2001 From: headlessdev Date: Mon, 14 Apr 2025 12:46:05 +0200 Subject: [PATCH 02/12] Edit Application API Route --- app/api/applications/edit/route.ts | 38 ++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 app/api/applications/edit/route.ts diff --git a/app/api/applications/edit/route.ts b/app/api/applications/edit/route.ts new file mode 100644 index 0000000..3637fa3 --- /dev/null +++ b/app/api/applications/edit/route.ts @@ -0,0 +1,38 @@ +import { NextResponse, NextRequest } from "next/server"; +import { prisma } from "@/lib/prisma"; + +interface EditRequest { + id: number; + name: string; + description: string; + icon: string; + publicURL: string; + localURL: string; +} + +export async function PUT(request: NextRequest) { + try { + const body: EditRequest = await request.json(); + const { id, name, description, icon, publicURL, localURL } = body; + + const existingServer = await prisma.server.findUnique({ where: { id } }); + if (!existingServer) { + return NextResponse.json({ error: "Server not found" }, { status: 404 }); + } + + const updatedApplication = await prisma.application.update({ + where: { id }, + data: { + name, + description, + icon, + publicURL, + localURL + } + }); + + return NextResponse.json({ message: "Application updated", application: updatedApplication }); + } catch (error: any) { + return NextResponse.json({ error: error.message }, { status: 500 }); + } +} \ No newline at end of file From 3bdadab7c6a8a4b14430c79a9868755017c89c37 Mon Sep 17 00:00:00 2001 From: headlessdev Date: Mon, 14 Apr 2025 13:59:36 +0200 Subject: [PATCH 03/12] Edit APplications Function & Edit Application API Fixes --- app/api/applications/edit/route.ts | 8 +- app/dashboard/applications/Applications.tsx | 543 ++++++++++++++------ 2 files changed, 402 insertions(+), 149 deletions(-) diff --git a/app/api/applications/edit/route.ts b/app/api/applications/edit/route.ts index 3637fa3..8e6e514 100644 --- a/app/api/applications/edit/route.ts +++ b/app/api/applications/edit/route.ts @@ -5,6 +5,7 @@ interface EditRequest { id: number; name: string; description: string; + serverId: number; icon: string; publicURL: string; localURL: string; @@ -13,16 +14,17 @@ interface EditRequest { export async function PUT(request: NextRequest) { try { const body: EditRequest = await request.json(); - const { id, name, description, icon, publicURL, localURL } = body; + const { id, name, description, serverId, icon, publicURL, localURL } = body; - const existingServer = await prisma.server.findUnique({ where: { id } }); - if (!existingServer) { + const existingApp = await prisma.application.findUnique({ where: { id } }); + if (!existingApp) { return NextResponse.json({ error: "Server not found" }, { status: 404 }); } const updatedApplication = await prisma.application.update({ where: { id }, data: { + serverId, name, description, icon, diff --git a/app/dashboard/applications/Applications.tsx b/app/dashboard/applications/Applications.tsx index 5ec7b23..119198b 100644 --- a/app/dashboard/applications/Applications.tsx +++ b/app/dashboard/applications/Applications.tsx @@ -16,7 +16,15 @@ import { SidebarTrigger, } from "@/components/ui/sidebar"; import { Button } from "@/components/ui/button"; -import { Plus, Link, Home, Trash2, LayoutGrid, List } from "lucide-react"; +import { + Plus, + Link, + Home, + Trash2, + LayoutGrid, + List, + Pencil, +} from "lucide-react"; import { Card, CardContent, @@ -89,6 +97,15 @@ export default function Dashboard() { const [publicURL, setPublicURL] = useState(""); const [localURL, setLocalURL] = useState(""); const [serverId, setServerId] = useState(null); + + const [editName, setEditName] = useState(""); + const [editDescription, setEditDescription] = useState(""); + const [editIcon, setEditIcon] = useState(""); + const [editPublicURL, setEditPublicURL] = useState(""); + const [editLocalURL, setEditLocalURL] = useState(""); + const [editId, setEditId] = useState(null); + const [editServerId, setEditServerId] = useState(null); + const [currentPage, setCurrentPage] = useState(1); const [maxPage, setMaxPage] = useState(1); const [itemsPerPage, setItemsPerPage] = useState(5); @@ -98,8 +115,8 @@ export default function Dashboard() { const [loading, setLoading] = useState(true); useEffect(() => { - const savedLayout = Cookies.get('layoutPreference-app'); - const layout_bool = savedLayout === 'grid'; + const savedLayout = Cookies.get("layoutPreference-app"); + const layout_bool = savedLayout === "grid"; setIsGridLayout(layout_bool); setItemsPerPage(layout_bool ? 15 : 5); }, []); @@ -107,35 +124,35 @@ export default function Dashboard() { const toggleLayout = () => { const newLayout = !isGridLayout; setIsGridLayout(newLayout); - Cookies.set('layoutPreference-app', newLayout ? 'grid' : 'standard', { + Cookies.set("layoutPreference-app", newLayout ? "grid" : "standard", { expires: 365, - path: '/', - sameSite: 'strict' + path: "/", + sameSite: "strict", }); setItemsPerPage(newLayout ? 15 : 5); }; const add = async () => { try { - await axios.post('/api/applications/add', { - name, - description, - icon, - publicURL, + await axios.post("/api/applications/add", { + name, + description, + icon, + publicURL, localURL, - serverId + serverId, }); getApplications(); } catch (error: any) { - console.log(error.response?.data); + console.log(error.response?.data); } - } + }; const getApplications = async () => { try { setLoading(true); const response = await axios.post( - '/api/applications/get', + "/api/applications/get", { page: currentPage, ITEMS_PER_PAGE: itemsPerPage } ); setApplications(response.data.applications); @@ -145,23 +162,54 @@ export default function Dashboard() { } catch (error: any) { console.log(error.response?.data); } - } + }; useEffect(() => { getApplications(); }, [currentPage, itemsPerPage]); - const handlePrevious = () => setCurrentPage(prev => Math.max(1, prev - 1)); - const handleNext = () => setCurrentPage(prev => Math.min(maxPage, prev + 1)); + const handlePrevious = () => setCurrentPage((prev) => Math.max(1, prev - 1)); + const handleNext = () => + setCurrentPage((prev) => Math.min(maxPage, prev + 1)); const deleteApplication = async (id: number) => { try { - await axios.post('/api/applications/delete', { id }); + await axios.post("/api/applications/delete", { id }); getApplications(); } catch (error: any) { console.log(error.response?.data); } - } + }; + + 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); + } catch (error: any) { + console.log(error.response.data); + } + }; return ( @@ -192,16 +240,24 @@ export default function Dashboard() {
Your Applications
- {servers.length === 0 ? ( -

You must first add a server.

+

+ You must first add a server. +

) : ( @@ -214,151 +270,346 @@ export default function Dashboard() { Add an application
-
- - setName(e.target.value)}/> -
-
- - -
-
- -