diff --git a/src/lib/api/getAll.ts b/src/lib/api/getAll.ts new file mode 100644 index 0000000..8c098a0 --- /dev/null +++ b/src/lib/api/getAll.ts @@ -0,0 +1,24 @@ +export async function getAllUsers(token: string) { + try { + const response = await fetch( + 'https://sucu-backend-2024-689509857491.asia-southeast1.run.app/api/v1/users', + { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + Authorization: `Bearer ${token}` + } + } + ); + + if (!response.ok) { + const errorData = await response.json(); + throw new Error(`Error: ${errorData.message}`); + } + + const data = await response.json(); + return data; + } catch (error) { + console.error('Failed to fetch users:', error); + } +} diff --git a/src/lib/components/Pagination/Pagination.svelte b/src/lib/components/Pagination/Pagination.svelte index 263838e..ff87a5f 100644 --- a/src/lib/components/Pagination/Pagination.svelte +++ b/src/lib/components/Pagination/Pagination.svelte @@ -1,4 +1,5 @@ -
- - -
+{#if isAdminPage} +
+ + +
+{:else if isAuthLoginPage} +
+ +
+{:else} +
+ + +
+{/if} diff --git a/src/routes/admin/stats/+page.svelte b/src/routes/admin/stats/+page.svelte new file mode 100644 index 0000000..dd90c72 --- /dev/null +++ b/src/routes/admin/stats/+page.svelte @@ -0,0 +1,255 @@ + + + + +
+
+

สถิติ และ งบประมาณ

+

สถิติ และ งบประมาณ ทั้งหมดของฝ่าย - อบจ.

+
+ +
+
+ +
+ +
+ +
+
+
+ +
+
เลือกทั้งหมด
+ +
+ + {#each paginatedDocuments as doc} +
+
+ toggleSelectItem(doc.id)} + class="h-4 w-4 rounded border-gray-300" + /> +
+
+
{doc.title}
+
+ {new Date(doc.created_at).toLocaleDateString('th-TH')} โดย {doc.author.name} +
+
+
+ + {#if activePopoverId === doc.id} +
+
+ + +
+
+ {/if} +
+
+ {/each} + +
+
+ แสดง {(currentPage - 1) * itemsPerPage + 1} ถึง {Math.min( + currentPage * itemsPerPage, + filteredDocuments.length + )} จาก {filteredDocuments.length} รายการ +
+
+ + {#each Array(pageCount) as _, i} + + {/each} + +
+
+
+
diff --git a/src/routes/admin/users/+page.svelte b/src/routes/admin/users/+page.svelte new file mode 100644 index 0000000..3f6af9c --- /dev/null +++ b/src/routes/admin/users/+page.svelte @@ -0,0 +1,194 @@ + + + + +
+
+

{title}

+

{subtitle}

+
+ +
+ +
+ +
+ +
+
+ +
+
เลือกทั้งหมด
+
+
+
+ + +
+ + + {#each filteredUsers as user} +
+
+ toggleSelectItem(user.id)} + class="h-4 w-4 rounded border-gray-300" + /> +
+
{user.title}
+
{user.id}
+
สร้างเมื่อ {user.date}
+
+ + {user.role} + +
+
+ + {#if activePopoverId === user.id} +
+
+ + +
+
+ {/if} +
+
+ {/each} + + +
+ user.id)} on:pageChange={handlePageChange} /> +
+
+