appflare 0.2.30 → 0.2.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Documentation.md +758 -758
- package/cli/commands/index.ts +238 -238
- package/cli/generate.ts +178 -178
- package/cli/index.ts +120 -120
- package/cli/load-config.ts +184 -184
- package/cli/schema-compiler.ts +1183 -1183
- package/cli/templates/auth/README.md +156 -156
- package/cli/templates/auth/config.ts +61 -61
- package/cli/templates/auth/route-config.ts +1 -1
- package/cli/templates/auth/route-handler.ts +1 -1
- package/cli/templates/auth/route-request-utils.ts +5 -5
- package/cli/templates/auth/route.config.ts +18 -18
- package/cli/templates/auth/route.handler.ts +18 -18
- package/cli/templates/auth/route.request-utils.ts +55 -55
- package/cli/templates/auth/route.ts +14 -14
- package/cli/templates/core/README.md +266 -266
- package/cli/templates/core/app-creation.ts +19 -19
- package/cli/templates/core/client/appflare.ts +112 -112
- package/cli/templates/core/client/handlers/index.ts +748 -748
- package/cli/templates/core/client/handlers.ts +1 -1
- package/cli/templates/core/client/index.ts +7 -7
- package/cli/templates/core/client/storage.ts +195 -195
- package/cli/templates/core/client/types.ts +186 -186
- package/cli/templates/core/client-modules/appflare.ts +1 -1
- package/cli/templates/core/client-modules/handlers.ts +1 -1
- package/cli/templates/core/client-modules/index.ts +1 -1
- package/cli/templates/core/client-modules/storage.ts +1 -1
- package/cli/templates/core/client-modules/types.ts +1 -1
- package/cli/templates/core/client.artifacts.ts +39 -39
- package/cli/templates/core/client.ts +4 -4
- package/cli/templates/core/drizzle.ts +15 -15
- package/cli/templates/core/export.ts +14 -14
- package/cli/templates/core/handlers.route.ts +24 -24
- package/cli/templates/core/handlers.ts +1 -1
- package/cli/templates/core/imports.ts +9 -9
- package/cli/templates/core/server.ts +38 -38
- package/cli/templates/core/types.ts +6 -6
- package/cli/templates/core/wrangler.ts +109 -109
- package/cli/templates/dashboard/builders/functions/index.ts +17 -17
- package/cli/templates/dashboard/builders/functions/render-page/header.ts +20 -20
- package/cli/templates/dashboard/builders/functions/render-page/index.ts +33 -33
- package/cli/templates/dashboard/builders/functions/render-page/request-panel.ts +171 -171
- package/cli/templates/dashboard/builders/functions/render-page/result-panel.ts +85 -85
- package/cli/templates/dashboard/builders/functions/render-page/scripts.ts +554 -554
- package/cli/templates/dashboard/builders/navigation.ts +122 -122
- package/cli/templates/dashboard/builders/storage/index.ts +13 -13
- package/cli/templates/dashboard/builders/storage/routes/create-directory-route.ts +29 -29
- package/cli/templates/dashboard/builders/storage/routes/delete-route.ts +18 -18
- package/cli/templates/dashboard/builders/storage/routes/download-route.ts +23 -23
- package/cli/templates/dashboard/builders/storage/routes/index.ts +22 -22
- package/cli/templates/dashboard/builders/storage/routes/list-route.ts +25 -25
- package/cli/templates/dashboard/builders/storage/routes/preview-route.ts +21 -21
- package/cli/templates/dashboard/builders/storage/routes/upload-route.ts +21 -21
- package/cli/templates/dashboard/builders/storage/runtime/helpers.ts +72 -72
- package/cli/templates/dashboard/builders/storage/runtime/storage-page.ts +130 -130
- package/cli/templates/dashboard/builders/table-routes/common/drawer-panel.ts +27 -27
- package/cli/templates/dashboard/builders/table-routes/common/pagination.ts +30 -30
- package/cli/templates/dashboard/builders/table-routes/common/search-bar.ts +23 -23
- package/cli/templates/dashboard/builders/table-routes/fragments.ts +217 -217
- package/cli/templates/dashboard/builders/table-routes/helpers.ts +45 -45
- package/cli/templates/dashboard/builders/table-routes/index.ts +8 -8
- package/cli/templates/dashboard/builders/table-routes/table/actions-cell.ts +71 -71
- package/cli/templates/dashboard/builders/table-routes/table/get-route.ts +291 -291
- package/cli/templates/dashboard/builders/table-routes/table/index.ts +80 -80
- package/cli/templates/dashboard/builders/table-routes/table/post-routes.ts +163 -163
- package/cli/templates/dashboard/builders/table-routes/table-route.ts +7 -7
- package/cli/templates/dashboard/builders/table-routes/users/get-route.ts +69 -69
- package/cli/templates/dashboard/builders/table-routes/users/html/modals.ts +57 -57
- package/cli/templates/dashboard/builders/table-routes/users/html/page.ts +27 -27
- package/cli/templates/dashboard/builders/table-routes/users/html/table.ts +128 -128
- package/cli/templates/dashboard/builders/table-routes/users/index.ts +32 -32
- package/cli/templates/dashboard/builders/table-routes/users/post-routes.ts +150 -150
- package/cli/templates/dashboard/builders/table-routes/users/redirect.ts +14 -14
- package/cli/templates/dashboard/builders/table-routes/users-route.ts +10 -10
- package/cli/templates/dashboard/components/dashboard-home.ts +23 -23
- package/cli/templates/dashboard/components/layout.ts +388 -388
- package/cli/templates/dashboard/components/login-page.ts +65 -65
- package/cli/templates/dashboard/index.ts +61 -61
- package/cli/templates/dashboard/types.ts +9 -9
- package/cli/templates/handlers/README.md +353 -353
- package/cli/templates/handlers/auth.ts +37 -37
- package/cli/templates/handlers/execution.ts +42 -42
- package/cli/templates/handlers/generators/context/context-creation.ts +101 -101
- package/cli/templates/handlers/generators/context/error-helpers.ts +11 -11
- package/cli/templates/handlers/generators/context/scheduler.ts +24 -24
- package/cli/templates/handlers/generators/context/storage-api.ts +82 -82
- package/cli/templates/handlers/generators/context/storage-helpers.ts +59 -59
- package/cli/templates/handlers/generators/context/types.ts +40 -40
- package/cli/templates/handlers/generators/context.ts +43 -43
- package/cli/templates/handlers/generators/execution.ts +15 -15
- package/cli/templates/handlers/generators/handlers.ts +13 -13
- package/cli/templates/handlers/generators/registration/modules/cron.ts +26 -26
- package/cli/templates/handlers/generators/registration/modules/realtime/auth.ts +75 -75
- package/cli/templates/handlers/generators/registration/modules/realtime/durable-object.ts +144 -144
- package/cli/templates/handlers/generators/registration/modules/realtime/index.ts +14 -14
- package/cli/templates/handlers/generators/registration/modules/realtime/publisher.ts +102 -102
- package/cli/templates/handlers/generators/registration/modules/realtime/routes.ts +164 -164
- package/cli/templates/handlers/generators/registration/modules/realtime/types.ts +30 -30
- package/cli/templates/handlers/generators/registration/modules/realtime/utils.ts +516 -516
- package/cli/templates/handlers/generators/registration/modules/scheduler.ts +56 -56
- package/cli/templates/handlers/generators/registration/modules/storage.ts +199 -199
- package/cli/templates/handlers/generators/registration/sections.ts +210 -210
- package/cli/templates/handlers/generators/types/context.ts +92 -92
- package/cli/templates/handlers/generators/types/core.ts +106 -106
- package/cli/templates/handlers/generators/types/operations.ts +135 -135
- package/cli/templates/handlers/generators/types/query-definitions/filter-and-where-types.ts +281 -259
- package/cli/templates/handlers/generators/types/query-definitions/query-api-types.ts +135 -135
- package/cli/templates/handlers/generators/types/query-definitions/query-helper-functions.ts +1103 -1031
- package/cli/templates/handlers/generators/types/query-definitions/schema-and-table-types.ts +278 -246
- package/cli/templates/handlers/generators/types/query-definitions.ts +13 -13
- package/cli/templates/handlers/generators/types/query-runtime/handled-error.ts +13 -13
- package/cli/templates/handlers/generators/types/query-runtime/runtime-aggregate-and-footer.ts +174 -174
- package/cli/templates/handlers/generators/types/query-runtime/runtime-read.ts +157 -121
- package/cli/templates/handlers/generators/types/query-runtime/runtime-setup.ts +45 -45
- package/cli/templates/handlers/generators/types/query-runtime/runtime-write.ts +697 -697
- package/cli/templates/handlers/generators/types/query-runtime.ts +15 -15
- package/cli/templates/handlers/index.ts +43 -43
- package/cli/templates/handlers/operations.ts +116 -116
- package/cli/templates/handlers/registration.ts +91 -91
- package/cli/templates/handlers/types.ts +15 -15
- package/cli/templates/handlers/utils.ts +48 -48
- package/cli/types.ts +110 -110
- package/cli/utils/handler-discovery.ts +466 -466
- package/cli/utils/json-utils.ts +24 -24
- package/cli/utils/path-utils.ts +19 -19
- package/cli/utils/schema-discovery.ts +399 -399
- package/dist/cli/index.d.mts +2 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +270 -108
- package/dist/cli/index.mjs +270 -108
- package/index.ts +18 -18
- package/package.json +58 -58
- package/react/index.ts +5 -5
- package/react/use-infinite-query.ts +252 -252
- package/react/use-mutation.ts +89 -89
- package/react/use-query.ts +207 -207
- package/schema.ts +415 -415
- package/test-better-auth-hash.ts +2 -2
- package/tsconfig.json +6 -6
- package/tsup.config.ts +82 -82
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Builds the ban/unban confirmation modal HTML for a users table row.
|
|
3
|
-
* Clean PocketBase-style modal.
|
|
4
|
-
*/
|
|
5
|
-
export function buildBanUserModal(): string {
|
|
6
|
-
return `
|
|
7
|
-
\t\t\t\t\t\t\t\${(row as any).id === currentUserId ? '' : html\`
|
|
8
|
-
\t\t\t\t\t\t\t\t<input type="checkbox" id="ban-user-modal-\${String((row as any).id)}" class="modal-toggle" />
|
|
9
|
-
\t\t\t\t\t\t\t\t<div class="modal">
|
|
10
|
-
\t\t\t\t\t\t\t\t\t<div class="modal-box max-w-sm">
|
|
11
|
-
\t\t\t\t\t\t\t\t\t\t<h3 class="font-semibold text-base">\${(row as any).banned ? 'Unban user' : 'Ban user'}</h3>
|
|
12
|
-
\t\t\t\t\t\t\t\t\t\t<p class="py-3 text-sm text-base-content/60">\${(row as any).banned ? 'Restore access for' : 'Disable access for'} <span class="font-semibold">\${String((row as any).email ?? '')}</span>?</p>
|
|
13
|
-
\t\t\t\t\t\t\t\t\t\t<form hx-post="/admin/users/\${(row as any).banned ? 'unban' : 'ban'}" hx-target="#main-content" hx-swap="outerHTML" class="space-y-3">
|
|
14
|
-
\t\t\t\t\t\t\t\t\t\t\t<input type="hidden" name="id" value="\${String((row as any).id)}" />
|
|
15
|
-
\t\t\t\t\t\t\t\t\t\t\t<input type="hidden" name="page" value="\${page}" />
|
|
16
|
-
\t\t\t\t\t\t\t\t\t\t\t<input type="hidden" name="search" value="\${search}" />
|
|
17
|
-
\t\t\t\t\t\t\t\t\t\t\t<input type="hidden" name="sort" value="\${sort}" />
|
|
18
|
-
\t\t\t\t\t\t\t\t\t\t\t<input type="hidden" name="order" value="\${order}" />
|
|
19
|
-
\t\t\t\t\t\t\t\t\t\t\t<div class="modal-action">
|
|
20
|
-
\t\t\t\t\t\t\t\t\t\t\t\t<label for="ban-user-modal-\${String((row as any).id)}" class="btn btn-ghost btn-sm">Cancel</label>
|
|
21
|
-
\t\t\t\t\t\t\t\t\t\t\t\t<button class="btn btn-sm \${(row as any).banned ? 'btn-info' : 'btn-warning'}" type="submit">\${(row as any).banned ? 'Unban' : 'Ban'}</button>
|
|
22
|
-
\t\t\t\t\t\t\t\t\t\t\t</div>
|
|
23
|
-
\t\t\t\t\t\t\t\t\t\t</form>
|
|
24
|
-
\t\t\t\t\t\t\t\t\t</div>
|
|
25
|
-
\t\t\t\t\t\t\t\t\t<label class="modal-backdrop" for="ban-user-modal-\${String((row as any).id)}">Close</label>
|
|
26
|
-
\t\t\t\t\t\t\t\t</div>
|
|
27
|
-
\t\t\t\t\t\t\t\`}`;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Builds the delete confirmation modal HTML for a users table row.
|
|
32
|
-
* Clean PocketBase-style modal.
|
|
33
|
-
*/
|
|
34
|
-
export function buildDeleteUserModal(): string {
|
|
35
|
-
return `
|
|
36
|
-
\t\t\t\t\t\t\t\${(row as any).id === currentUserId ? '' : html\`
|
|
37
|
-
\t\t\t\t\t\t\t\t<input type="checkbox" id="delete-user-modal-\${String((row as any).id)}" class="modal-toggle" />
|
|
38
|
-
\t\t\t\t\t\t\t\t<div class="modal">
|
|
39
|
-
\t\t\t\t\t\t\t\t\t<div class="modal-box max-w-sm">
|
|
40
|
-
\t\t\t\t\t\t\t\t\t\t<h3 class="font-semibold text-base text-error">Delete user</h3>
|
|
41
|
-
\t\t\t\t\t\t\t\t\t\t<p class="py-3 text-sm text-base-content/60">Delete user <span class="font-semibold">\${String((row as any).email ?? '')}</span>? This action cannot be undone.</p>
|
|
42
|
-
\t\t\t\t\t\t\t\t\t\t<form hx-post="/admin/users/delete" hx-target="#main-content" hx-swap="outerHTML">
|
|
43
|
-
\t\t\t\t\t\t\t\t\t\t\t<input type="hidden" name="id" value="\${String((row as any).id)}" />
|
|
44
|
-
\t\t\t\t\t\t\t\t\t\t\t<input type="hidden" name="page" value="\${page}" />
|
|
45
|
-
\t\t\t\t\t\t\t\t\t\t\t<input type="hidden" name="search" value="\${search}" />
|
|
46
|
-
\t\t\t\t\t\t\t\t\t\t\t<input type="hidden" name="sort" value="\${sort}" />
|
|
47
|
-
\t\t\t\t\t\t\t\t\t\t\t<input type="hidden" name="order" value="\${order}" />
|
|
48
|
-
\t\t\t\t\t\t\t\t\t\t\t<div class="modal-action">
|
|
49
|
-
\t\t\t\t\t\t\t\t\t\t\t\t<label for="delete-user-modal-\${String((row as any).id)}" class="btn btn-ghost btn-sm">Cancel</label>
|
|
50
|
-
\t\t\t\t\t\t\t\t\t\t\t\t<button class="btn btn-error btn-sm" type="submit">Delete</button>
|
|
51
|
-
\t\t\t\t\t\t\t\t\t\t\t</div>
|
|
52
|
-
\t\t\t\t\t\t\t\t\t\t</form>
|
|
53
|
-
\t\t\t\t\t\t\t\t\t</div>
|
|
54
|
-
\t\t\t\t\t\t\t\t\t<label class="modal-backdrop" for="delete-user-modal-\${String((row as any).id)}">Close</label>
|
|
55
|
-
\t\t\t\t\t\t\t\t</div>
|
|
56
|
-
\t\t\t\t\t\t\t\`}`;
|
|
57
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Builds the ban/unban confirmation modal HTML for a users table row.
|
|
3
|
+
* Clean PocketBase-style modal.
|
|
4
|
+
*/
|
|
5
|
+
export function buildBanUserModal(): string {
|
|
6
|
+
return `
|
|
7
|
+
\t\t\t\t\t\t\t\${(row as any).id === currentUserId ? '' : html\`
|
|
8
|
+
\t\t\t\t\t\t\t\t<input type="checkbox" id="ban-user-modal-\${String((row as any).id)}" class="modal-toggle" />
|
|
9
|
+
\t\t\t\t\t\t\t\t<div class="modal">
|
|
10
|
+
\t\t\t\t\t\t\t\t\t<div class="modal-box max-w-sm">
|
|
11
|
+
\t\t\t\t\t\t\t\t\t\t<h3 class="font-semibold text-base">\${(row as any).banned ? 'Unban user' : 'Ban user'}</h3>
|
|
12
|
+
\t\t\t\t\t\t\t\t\t\t<p class="py-3 text-sm text-base-content/60">\${(row as any).banned ? 'Restore access for' : 'Disable access for'} <span class="font-semibold">\${String((row as any).email ?? '')}</span>?</p>
|
|
13
|
+
\t\t\t\t\t\t\t\t\t\t<form hx-post="/admin/users/\${(row as any).banned ? 'unban' : 'ban'}" hx-target="#main-content" hx-swap="outerHTML" class="space-y-3">
|
|
14
|
+
\t\t\t\t\t\t\t\t\t\t\t<input type="hidden" name="id" value="\${String((row as any).id)}" />
|
|
15
|
+
\t\t\t\t\t\t\t\t\t\t\t<input type="hidden" name="page" value="\${page}" />
|
|
16
|
+
\t\t\t\t\t\t\t\t\t\t\t<input type="hidden" name="search" value="\${search}" />
|
|
17
|
+
\t\t\t\t\t\t\t\t\t\t\t<input type="hidden" name="sort" value="\${sort}" />
|
|
18
|
+
\t\t\t\t\t\t\t\t\t\t\t<input type="hidden" name="order" value="\${order}" />
|
|
19
|
+
\t\t\t\t\t\t\t\t\t\t\t<div class="modal-action">
|
|
20
|
+
\t\t\t\t\t\t\t\t\t\t\t\t<label for="ban-user-modal-\${String((row as any).id)}" class="btn btn-ghost btn-sm">Cancel</label>
|
|
21
|
+
\t\t\t\t\t\t\t\t\t\t\t\t<button class="btn btn-sm \${(row as any).banned ? 'btn-info' : 'btn-warning'}" type="submit">\${(row as any).banned ? 'Unban' : 'Ban'}</button>
|
|
22
|
+
\t\t\t\t\t\t\t\t\t\t\t</div>
|
|
23
|
+
\t\t\t\t\t\t\t\t\t\t</form>
|
|
24
|
+
\t\t\t\t\t\t\t\t\t</div>
|
|
25
|
+
\t\t\t\t\t\t\t\t\t<label class="modal-backdrop" for="ban-user-modal-\${String((row as any).id)}">Close</label>
|
|
26
|
+
\t\t\t\t\t\t\t\t</div>
|
|
27
|
+
\t\t\t\t\t\t\t\`}`;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Builds the delete confirmation modal HTML for a users table row.
|
|
32
|
+
* Clean PocketBase-style modal.
|
|
33
|
+
*/
|
|
34
|
+
export function buildDeleteUserModal(): string {
|
|
35
|
+
return `
|
|
36
|
+
\t\t\t\t\t\t\t\${(row as any).id === currentUserId ? '' : html\`
|
|
37
|
+
\t\t\t\t\t\t\t\t<input type="checkbox" id="delete-user-modal-\${String((row as any).id)}" class="modal-toggle" />
|
|
38
|
+
\t\t\t\t\t\t\t\t<div class="modal">
|
|
39
|
+
\t\t\t\t\t\t\t\t\t<div class="modal-box max-w-sm">
|
|
40
|
+
\t\t\t\t\t\t\t\t\t\t<h3 class="font-semibold text-base text-error">Delete user</h3>
|
|
41
|
+
\t\t\t\t\t\t\t\t\t\t<p class="py-3 text-sm text-base-content/60">Delete user <span class="font-semibold">\${String((row as any).email ?? '')}</span>? This action cannot be undone.</p>
|
|
42
|
+
\t\t\t\t\t\t\t\t\t\t<form hx-post="/admin/users/delete" hx-target="#main-content" hx-swap="outerHTML">
|
|
43
|
+
\t\t\t\t\t\t\t\t\t\t\t<input type="hidden" name="id" value="\${String((row as any).id)}" />
|
|
44
|
+
\t\t\t\t\t\t\t\t\t\t\t<input type="hidden" name="page" value="\${page}" />
|
|
45
|
+
\t\t\t\t\t\t\t\t\t\t\t<input type="hidden" name="search" value="\${search}" />
|
|
46
|
+
\t\t\t\t\t\t\t\t\t\t\t<input type="hidden" name="sort" value="\${sort}" />
|
|
47
|
+
\t\t\t\t\t\t\t\t\t\t\t<input type="hidden" name="order" value="\${order}" />
|
|
48
|
+
\t\t\t\t\t\t\t\t\t\t\t<div class="modal-action">
|
|
49
|
+
\t\t\t\t\t\t\t\t\t\t\t\t<label for="delete-user-modal-\${String((row as any).id)}" class="btn btn-ghost btn-sm">Cancel</label>
|
|
50
|
+
\t\t\t\t\t\t\t\t\t\t\t\t<button class="btn btn-error btn-sm" type="submit">Delete</button>
|
|
51
|
+
\t\t\t\t\t\t\t\t\t\t\t</div>
|
|
52
|
+
\t\t\t\t\t\t\t\t\t\t</form>
|
|
53
|
+
\t\t\t\t\t\t\t\t\t</div>
|
|
54
|
+
\t\t\t\t\t\t\t\t\t<label class="modal-backdrop" for="delete-user-modal-\${String((row as any).id)}">Close</label>
|
|
55
|
+
\t\t\t\t\t\t\t\t</div>
|
|
56
|
+
\t\t\t\t\t\t\t\`}`;
|
|
57
|
+
}
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import { buildSearchBarHtml } from "../../common/search-bar";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Builds the full page content HTML (runtime template string) for the users management page.
|
|
5
|
-
* PocketBase-style breadcrumb header with search filter.
|
|
6
|
-
*/
|
|
7
|
-
export function buildUsersPageHtml(): string {
|
|
8
|
-
const searchBarHtml = buildSearchBarHtml("/admin/users", "Search users...");
|
|
9
|
-
|
|
10
|
-
return `
|
|
11
|
-
\t\tconst content = html\`
|
|
12
|
-
\t\t\t<div id="main-content">
|
|
13
|
-
\t\t\t\t<div class="flex flex-col md:flex-row justify-between items-start md:items-center mb-5 gap-3">
|
|
14
|
-
\t\t\t\t\t<div class="flex items-center gap-2 text-sm">
|
|
15
|
-
\t\t\t\t\t\t<a href="/admin" class="text-base-content/40 hover:text-primary transition-colors">Collections</a>
|
|
16
|
-
\t\t\t\t\t\t<iconify-icon icon="mdi:chevron-right" width="14" height="14" class="opacity-30"></iconify-icon>
|
|
17
|
-
\t\t\t\t\t\t<span class="font-semibold">users</span>
|
|
18
|
-
\t\t\t\t\t\t<button class="btn btn-ghost btn-xs btn-square opacity-40 hover:opacity-100" onclick="window.location.reload()">
|
|
19
|
-
\t\t\t\t\t\t\t<iconify-icon icon="mdi:refresh" width="14" height="14"></iconify-icon>
|
|
20
|
-
\t\t\t\t\t\t</button>
|
|
21
|
-
\t\t\t\t\t</div>
|
|
22
|
-
\t\t\t\t\t${searchBarHtml}
|
|
23
|
-
\t\t\t\t</div>
|
|
24
|
-
\t\t\t\t\${tableHtml}
|
|
25
|
-
\t\t\t</div>
|
|
26
|
-
\t\t\`;`;
|
|
27
|
-
}
|
|
1
|
+
import { buildSearchBarHtml } from "../../common/search-bar";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Builds the full page content HTML (runtime template string) for the users management page.
|
|
5
|
+
* PocketBase-style breadcrumb header with search filter.
|
|
6
|
+
*/
|
|
7
|
+
export function buildUsersPageHtml(): string {
|
|
8
|
+
const searchBarHtml = buildSearchBarHtml("/admin/users", "Search users...");
|
|
9
|
+
|
|
10
|
+
return `
|
|
11
|
+
\t\tconst content = html\`
|
|
12
|
+
\t\t\t<div id="main-content">
|
|
13
|
+
\t\t\t\t<div class="flex flex-col md:flex-row justify-between items-start md:items-center mb-5 gap-3">
|
|
14
|
+
\t\t\t\t\t<div class="flex items-center gap-2 text-sm">
|
|
15
|
+
\t\t\t\t\t\t<a href="/admin" class="text-base-content/40 hover:text-primary transition-colors">Collections</a>
|
|
16
|
+
\t\t\t\t\t\t<iconify-icon icon="mdi:chevron-right" width="14" height="14" class="opacity-30"></iconify-icon>
|
|
17
|
+
\t\t\t\t\t\t<span class="font-semibold">users</span>
|
|
18
|
+
\t\t\t\t\t\t<button class="btn btn-ghost btn-xs btn-square opacity-40 hover:opacity-100" onclick="window.location.reload()">
|
|
19
|
+
\t\t\t\t\t\t\t<iconify-icon icon="mdi:refresh" width="14" height="14"></iconify-icon>
|
|
20
|
+
\t\t\t\t\t\t</button>
|
|
21
|
+
\t\t\t\t\t</div>
|
|
22
|
+
\t\t\t\t\t${searchBarHtml}
|
|
23
|
+
\t\t\t\t</div>
|
|
24
|
+
\t\t\t\t\${tableHtml}
|
|
25
|
+
\t\t\t</div>
|
|
26
|
+
\t\t\`;`;
|
|
27
|
+
}
|
|
@@ -1,128 +1,128 @@
|
|
|
1
|
-
import { buildBanUserModal, buildDeleteUserModal } from "./modals";
|
|
2
|
-
import { buildPaginationHtml } from "../../common/pagination";
|
|
3
|
-
|
|
4
|
-
const USER_SORT_COLUMNS = [
|
|
5
|
-
"id",
|
|
6
|
-
"name",
|
|
7
|
-
"email",
|
|
8
|
-
"role",
|
|
9
|
-
"createdAt",
|
|
10
|
-
"banned",
|
|
11
|
-
] as const;
|
|
12
|
-
type UserSortColumn = (typeof USER_SORT_COLUMNS)[number];
|
|
13
|
-
|
|
14
|
-
/** Column type icon mapping for users table */
|
|
15
|
-
const USER_COLUMN_ICONS: Record<UserSortColumn, string> = {
|
|
16
|
-
id: "mdi:pound",
|
|
17
|
-
name: "mdi:format-text",
|
|
18
|
-
email: "mdi:at",
|
|
19
|
-
role: "mdi:shield-account-outline",
|
|
20
|
-
createdAt: "mdi:calendar",
|
|
21
|
-
banned: "mdi:toggle-switch-outline",
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Builds the sortable column header anchor for a single user column.
|
|
26
|
-
*/
|
|
27
|
-
function buildUserColumnHeader(column: UserSortColumn): string {
|
|
28
|
-
const icon = USER_COLUMN_ICONS[column] || "mdi:format-text";
|
|
29
|
-
return `<th><a href="#" hx-get="/admin/users?page=\${page}&search=\${search}&sort=${column}&order=\${sort === '${column}' && order === 'asc' ? 'desc' : 'asc'}" hx-target="#main-content" hx-push-url="true" class="hover:text-primary flex items-center gap-1.5 transition-colors whitespace-nowrap"><iconify-icon icon="${icon}" width="14" height="14" class="opacity-40"></iconify-icon>${column} <span class="text-[10px] opacity-30">\${sort === '${column}' ? (order === 'asc' ? '▲' : '▼') : ''}</span></a></th>`;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Builds the complete users data table HTML block (runtime template string).
|
|
34
|
-
* PocketBase-style clean table with icon headers and subtle actions.
|
|
35
|
-
*/
|
|
36
|
-
export function buildUsersTableHtml(): string {
|
|
37
|
-
const headers = USER_SORT_COLUMNS.map(buildUserColumnHeader).join(
|
|
38
|
-
"\n\t\t\t\t\t\t\t",
|
|
39
|
-
);
|
|
40
|
-
const paginationHtml = buildPaginationHtml("/admin/users");
|
|
41
|
-
|
|
42
|
-
return `
|
|
43
|
-
\t\tconst tableHtml = html\`
|
|
44
|
-
\t\t\t<div class="bg-base-100 rounded-xl border border-base-200 overflow-hidden">
|
|
45
|
-
\t\t\t\t<div class="overflow-x-auto">
|
|
46
|
-
\t\t\t\t\t<table class="table table-sm md:table-md w-full">
|
|
47
|
-
\t\t\t\t\t\t<thead>
|
|
48
|
-
\t\t\t\t\t\t\t<tr class="border-b border-base-200">
|
|
49
|
-
\t\t\t\t\t\t\t\t${headers}
|
|
50
|
-
\t\t\t\t\t\t\t\t<th class="text-right">
|
|
51
|
-
\t\t\t\t\t\t\t\t\t<iconify-icon icon="mdi:dots-horizontal" width="16" height="16" class="opacity-30"></iconify-icon>
|
|
52
|
-
\t\t\t\t\t\t\t\t</th>
|
|
53
|
-
\t\t\t\t\t\t\t</tr>
|
|
54
|
-
\t\t\t\t\t\t</thead>
|
|
55
|
-
\t\t\t\t\t\t<tbody>
|
|
56
|
-
\t\t\t\t\t\t\t\${data.map((row) => html\`
|
|
57
|
-
\t\t\t\t\t\t\t\t<tr class="hover:bg-base-200/30 transition-colors">
|
|
58
|
-
\t\t\t\t\t\t\t\t\t<td><button type="button" class="truncate max-w-[220px] text-sm font-mono text-xs opacity-70 hover:opacity-100 cursor-copy text-left" title="Click to copy: \${String((row as any).id ?? '')}" data-copy-value="\${String((row as any).id ?? '')}" onclick="navigator.clipboard?.writeText(this.dataset.copyValue || '')">\${String((row as any).id ?? '')}</button></td>
|
|
59
|
-
\t\t\t\t\t\t\t\t\t<td><div class="truncate max-w-[220px] text-sm" title="\${String((row as any).name ?? '')}">\${String((row as any).name ?? '')}</div></td>
|
|
60
|
-
\t\t\t\t\t\t\t\t\t<td><div class="truncate max-w-[260px] text-sm" title="\${String((row as any).email ?? '')}">\${String((row as any).email ?? '')}</div></td>
|
|
61
|
-
\t\t\t\t\t\t\t\t\t<td><span class="badge badge-sm \${String((row as any).role ?? '') === 'admin' ? 'badge-primary' : 'badge-ghost'}">\${String((row as any).role ?? '')}</span></td>
|
|
62
|
-
\t\t\t\t\t\t\t\t\t<td><div class="truncate max-w-[180px] text-xs opacity-50" title="\${String((row as any).createdAt ?? '')}">\${String((row as any).createdAt ?? '')}</div></td>
|
|
63
|
-
\t\t\t\t\t\t\t\t\t<td>\${(row as any).banned ? html\`<span class="badge badge-sm badge-warning gap-1"><iconify-icon icon="mdi:block-helper" width="10" height="10"></iconify-icon>banned</span>\` : html\`<span class="text-xs opacity-30">—</span>\`}</td>
|
|
64
|
-
\t\t\t\t\t\t\t\t\t<td class="text-right">
|
|
65
|
-
\t\t\t\t\t\t\t\t\t\t<div class="drawer drawer-end">
|
|
66
|
-
\t\t\t\t\t\t\t\t\t\t\t<input id="edit-user-drawer-\${String((row as any).id)}" type="checkbox" class="drawer-toggle" />
|
|
67
|
-
\t\t\t\t\t\t\t\t\t\t\t<div class="drawer-content">
|
|
68
|
-
\t\t\t\t\t\t\t\t\t\t\t\t<div class="flex justify-end gap-1">
|
|
69
|
-
\t\t\t\t\t\t\t\t\t\t\t\t\t<label for="edit-user-drawer-\${String((row as any).id)}" class="btn btn-ghost btn-xs btn-square" title="Edit">
|
|
70
|
-
\t\t\t\t\t\t\t\t\t\t\t\t\t\t<iconify-icon icon="mdi:pencil-outline" width="15" height="15" class="opacity-50"></iconify-icon>
|
|
71
|
-
\t\t\t\t\t\t\t\t\t\t\t\t\t</label>
|
|
72
|
-
\t\t\t\t\t\t\t\t\t\t\t\t\t\${(row as any).id === currentUserId ? html\`<button class="btn btn-ghost btn-xs btn-square btn-disabled" title="Ban"><iconify-icon icon="mdi:block-helper" width="15" height="15" class="opacity-20"></iconify-icon></button>\` : html\`<label for="ban-user-modal-\${String((row as any).id)}" class="btn btn-ghost btn-xs btn-square" title="\${(row as any).banned ? 'Unban' : 'Ban'}"><iconify-icon icon="\${(row as any).banned ? 'mdi:lock-open-outline' : 'mdi:block-helper'}" width="15" height="15" class="opacity-50"></iconify-icon></label>\`}
|
|
73
|
-
\t\t\t\t\t\t\t\t\t\t\t\t\t\${(row as any).id === currentUserId ? html\`<button class="btn btn-ghost btn-xs btn-square btn-disabled" title="Delete"><iconify-icon icon="mdi:delete-outline" width="15" height="15" class="opacity-20"></iconify-icon></button>\` : html\`<label for="delete-user-modal-\${String((row as any).id)}" class="btn btn-ghost btn-xs btn-square" title="Delete"><iconify-icon icon="mdi:delete-outline" width="15" height="15" class="opacity-50 hover:text-error"></iconify-icon></label>\`}
|
|
74
|
-
\t\t\t\t\t\t\t\t\t\t\t\t</div>
|
|
75
|
-
\t\t\t\t\t\t\t\t\t\t\t</div>
|
|
76
|
-
\t\t\t\t\t\t\t\t\t\t\t<div class="drawer-side z-50">
|
|
77
|
-
\t\t\t\t\t\t\t\t\t\t\t\t<label for="edit-user-drawer-\${String((row as any).id)}" aria-label="close sidebar" class="drawer-overlay"></label>
|
|
78
|
-
\t\t\t\t\t\t\t\t\t\t\t\t<div class="w-full max-w-md min-h-full bg-base-100 p-6 border-l border-base-200 overflow-y-auto shadow-lg">
|
|
79
|
-
\t\t\t\t\t\t\t\t\t\t\t\t\t<div class="flex justify-between items-center mb-5">
|
|
80
|
-
\t\t\t\t\t\t\t\t\t\t\t\t\t\t<h3 class="text-base font-semibold">Edit user</h3>
|
|
81
|
-
\t\t\t\t\t\t\t\t\t\t\t\t\t\t<label for="edit-user-drawer-\${String((row as any).id)}" class="btn btn-sm btn-ghost btn-square">
|
|
82
|
-
\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<iconify-icon icon="mdi:close" width="18" height="18"></iconify-icon>
|
|
83
|
-
\t\t\t\t\t\t\t\t\t\t\t\t\t\t</label>
|
|
84
|
-
\t\t\t\t\t\t\t\t\t\t\t\t\t</div>
|
|
85
|
-
\t\t\t\t\t\t\t\t\t\t\t\t\t<form hx-post="/admin/users/edit" hx-target="#main-content" hx-swap="outerHTML" class="flex flex-col gap-4">
|
|
86
|
-
\t\t\t\t\t\t\t\t\t\t\t\t\t\t<input type="hidden" name="id" value="\${String((row as any).id)}" />
|
|
87
|
-
\t\t\t\t\t\t\t\t\t\t\t\t\t\t<input type="hidden" name="page" value="\${page}" />
|
|
88
|
-
\t\t\t\t\t\t\t\t\t\t\t\t\t\t<input type="hidden" name="search" value="\${search}" />
|
|
89
|
-
\t\t\t\t\t\t\t\t\t\t\t\t\t\t<input type="hidden" name="sort" value="\${sort}" />
|
|
90
|
-
\t\t\t\t\t\t\t\t\t\t\t\t\t\t<input type="hidden" name="order" value="\${order}" />
|
|
91
|
-
\t\t\t\t\t\t\t\t\t\t\t\t\t\t<div class="form-control">
|
|
92
|
-
\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<label class="label"><span class="label-text text-sm font-medium">Name</span></label>
|
|
93
|
-
\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<input name="name" type="text" value="\${String((row as any).name ?? '')}" class="input input-bordered text-sm" required />
|
|
94
|
-
\t\t\t\t\t\t\t\t\t\t\t\t\t\t</div>
|
|
95
|
-
\t\t\t\t\t\t\t\t\t\t\t\t\t\t<div class="form-control">
|
|
96
|
-
\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<label class="label"><span class="label-text text-sm font-medium">Email</span></label>
|
|
97
|
-
\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<input name="email" type="email" value="\${String((row as any).email ?? '')}" class="input input-bordered text-sm" required />
|
|
98
|
-
\t\t\t\t\t\t\t\t\t\t\t\t\t\t</div>
|
|
99
|
-
\t\t\t\t\t\t\t\t\t\t\t\t\t\t<div class="form-control">
|
|
100
|
-
\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<label class="label"><span class="label-text text-sm font-medium">Role</span></label>
|
|
101
|
-
\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<select name="role" class="select select-bordered text-sm" required>
|
|
102
|
-
\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\${String((row as any).role ?? '') === 'admin' ? html\`<option value="admin" selected>admin</option><option value="user">user</option>\` : html\`<option value="admin">admin</option><option value="user" selected>user</option>\`}
|
|
103
|
-
\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t</select>
|
|
104
|
-
\t\t\t\t\t\t\t\t\t\t\t\t\t\t</div>
|
|
105
|
-
\t\t\t\t\t\t\t\t\t\t\t\t\t\t<button class="btn btn-primary btn-sm mt-2" type="submit">Save changes</button>
|
|
106
|
-
\t\t\t\t\t\t\t\t\t\t\t\t\t</form>
|
|
107
|
-
\t\t\t\t\t\t\t\t\t\t\t\t</div>
|
|
108
|
-
\t\t\t\t\t\t\t\t\t\t\t</div>
|
|
109
|
-
\t\t\t\t\t\t\t\t\t\t</div>
|
|
110
|
-
${buildBanUserModal()}
|
|
111
|
-
${buildDeleteUserModal()}
|
|
112
|
-
\t\t\t\t\t\t\t\t\t</td>
|
|
113
|
-
\t\t\t\t\t\t\t\t</tr>
|
|
114
|
-
\t\t\t\t\t\t\t\`)}
|
|
115
|
-
\t\t\t\t\t\t\t\${data.length === 0 ? html\`<tr><td colspan="7" class="text-center py-12">
|
|
116
|
-
\t\t\t\t\t\t\t\t<div class="flex flex-col items-center gap-3">
|
|
117
|
-
\t\t\t\t\t\t\t\t\t<iconify-icon icon="mdi:account-off-outline" width="40" height="40" class="opacity-20"></iconify-icon>
|
|
118
|
-
\t\t\t\t\t\t\t\t\t<p class="text-sm text-base-content/40">No users found matching your query</p>
|
|
119
|
-
\t\t\t\t\t\t\t\t</div>
|
|
120
|
-
\t\t\t\t\t\t\t</td></tr>\` : ''}
|
|
121
|
-
\t\t\t\t\t\t</tbody>
|
|
122
|
-
\t\t\t\t\t</table>
|
|
123
|
-
\t\t\t\t</div>
|
|
124
|
-
\t\t\t\t${paginationHtml}
|
|
125
|
-
\t\t\t</div>
|
|
126
|
-
\t\t\`;
|
|
127
|
-
`;
|
|
128
|
-
}
|
|
1
|
+
import { buildBanUserModal, buildDeleteUserModal } from "./modals";
|
|
2
|
+
import { buildPaginationHtml } from "../../common/pagination";
|
|
3
|
+
|
|
4
|
+
const USER_SORT_COLUMNS = [
|
|
5
|
+
"id",
|
|
6
|
+
"name",
|
|
7
|
+
"email",
|
|
8
|
+
"role",
|
|
9
|
+
"createdAt",
|
|
10
|
+
"banned",
|
|
11
|
+
] as const;
|
|
12
|
+
type UserSortColumn = (typeof USER_SORT_COLUMNS)[number];
|
|
13
|
+
|
|
14
|
+
/** Column type icon mapping for users table */
|
|
15
|
+
const USER_COLUMN_ICONS: Record<UserSortColumn, string> = {
|
|
16
|
+
id: "mdi:pound",
|
|
17
|
+
name: "mdi:format-text",
|
|
18
|
+
email: "mdi:at",
|
|
19
|
+
role: "mdi:shield-account-outline",
|
|
20
|
+
createdAt: "mdi:calendar",
|
|
21
|
+
banned: "mdi:toggle-switch-outline",
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Builds the sortable column header anchor for a single user column.
|
|
26
|
+
*/
|
|
27
|
+
function buildUserColumnHeader(column: UserSortColumn): string {
|
|
28
|
+
const icon = USER_COLUMN_ICONS[column] || "mdi:format-text";
|
|
29
|
+
return `<th><a href="#" hx-get="/admin/users?page=\${page}&search=\${search}&sort=${column}&order=\${sort === '${column}' && order === 'asc' ? 'desc' : 'asc'}" hx-target="#main-content" hx-push-url="true" class="hover:text-primary flex items-center gap-1.5 transition-colors whitespace-nowrap"><iconify-icon icon="${icon}" width="14" height="14" class="opacity-40"></iconify-icon>${column} <span class="text-[10px] opacity-30">\${sort === '${column}' ? (order === 'asc' ? '▲' : '▼') : ''}</span></a></th>`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Builds the complete users data table HTML block (runtime template string).
|
|
34
|
+
* PocketBase-style clean table with icon headers and subtle actions.
|
|
35
|
+
*/
|
|
36
|
+
export function buildUsersTableHtml(): string {
|
|
37
|
+
const headers = USER_SORT_COLUMNS.map(buildUserColumnHeader).join(
|
|
38
|
+
"\n\t\t\t\t\t\t\t",
|
|
39
|
+
);
|
|
40
|
+
const paginationHtml = buildPaginationHtml("/admin/users");
|
|
41
|
+
|
|
42
|
+
return `
|
|
43
|
+
\t\tconst tableHtml = html\`
|
|
44
|
+
\t\t\t<div class="bg-base-100 rounded-xl border border-base-200 overflow-hidden">
|
|
45
|
+
\t\t\t\t<div class="overflow-x-auto">
|
|
46
|
+
\t\t\t\t\t<table class="table table-sm md:table-md w-full">
|
|
47
|
+
\t\t\t\t\t\t<thead>
|
|
48
|
+
\t\t\t\t\t\t\t<tr class="border-b border-base-200">
|
|
49
|
+
\t\t\t\t\t\t\t\t${headers}
|
|
50
|
+
\t\t\t\t\t\t\t\t<th class="text-right">
|
|
51
|
+
\t\t\t\t\t\t\t\t\t<iconify-icon icon="mdi:dots-horizontal" width="16" height="16" class="opacity-30"></iconify-icon>
|
|
52
|
+
\t\t\t\t\t\t\t\t</th>
|
|
53
|
+
\t\t\t\t\t\t\t</tr>
|
|
54
|
+
\t\t\t\t\t\t</thead>
|
|
55
|
+
\t\t\t\t\t\t<tbody>
|
|
56
|
+
\t\t\t\t\t\t\t\${data.map((row) => html\`
|
|
57
|
+
\t\t\t\t\t\t\t\t<tr class="hover:bg-base-200/30 transition-colors">
|
|
58
|
+
\t\t\t\t\t\t\t\t\t<td><button type="button" class="truncate max-w-[220px] text-sm font-mono text-xs opacity-70 hover:opacity-100 cursor-copy text-left" title="Click to copy: \${String((row as any).id ?? '')}" data-copy-value="\${String((row as any).id ?? '')}" onclick="navigator.clipboard?.writeText(this.dataset.copyValue || '')">\${String((row as any).id ?? '')}</button></td>
|
|
59
|
+
\t\t\t\t\t\t\t\t\t<td><div class="truncate max-w-[220px] text-sm" title="\${String((row as any).name ?? '')}">\${String((row as any).name ?? '')}</div></td>
|
|
60
|
+
\t\t\t\t\t\t\t\t\t<td><div class="truncate max-w-[260px] text-sm" title="\${String((row as any).email ?? '')}">\${String((row as any).email ?? '')}</div></td>
|
|
61
|
+
\t\t\t\t\t\t\t\t\t<td><span class="badge badge-sm \${String((row as any).role ?? '') === 'admin' ? 'badge-primary' : 'badge-ghost'}">\${String((row as any).role ?? '')}</span></td>
|
|
62
|
+
\t\t\t\t\t\t\t\t\t<td><div class="truncate max-w-[180px] text-xs opacity-50" title="\${String((row as any).createdAt ?? '')}">\${String((row as any).createdAt ?? '')}</div></td>
|
|
63
|
+
\t\t\t\t\t\t\t\t\t<td>\${(row as any).banned ? html\`<span class="badge badge-sm badge-warning gap-1"><iconify-icon icon="mdi:block-helper" width="10" height="10"></iconify-icon>banned</span>\` : html\`<span class="text-xs opacity-30">—</span>\`}</td>
|
|
64
|
+
\t\t\t\t\t\t\t\t\t<td class="text-right">
|
|
65
|
+
\t\t\t\t\t\t\t\t\t\t<div class="drawer drawer-end">
|
|
66
|
+
\t\t\t\t\t\t\t\t\t\t\t<input id="edit-user-drawer-\${String((row as any).id)}" type="checkbox" class="drawer-toggle" />
|
|
67
|
+
\t\t\t\t\t\t\t\t\t\t\t<div class="drawer-content">
|
|
68
|
+
\t\t\t\t\t\t\t\t\t\t\t\t<div class="flex justify-end gap-1">
|
|
69
|
+
\t\t\t\t\t\t\t\t\t\t\t\t\t<label for="edit-user-drawer-\${String((row as any).id)}" class="btn btn-ghost btn-xs btn-square" title="Edit">
|
|
70
|
+
\t\t\t\t\t\t\t\t\t\t\t\t\t\t<iconify-icon icon="mdi:pencil-outline" width="15" height="15" class="opacity-50"></iconify-icon>
|
|
71
|
+
\t\t\t\t\t\t\t\t\t\t\t\t\t</label>
|
|
72
|
+
\t\t\t\t\t\t\t\t\t\t\t\t\t\${(row as any).id === currentUserId ? html\`<button class="btn btn-ghost btn-xs btn-square btn-disabled" title="Ban"><iconify-icon icon="mdi:block-helper" width="15" height="15" class="opacity-20"></iconify-icon></button>\` : html\`<label for="ban-user-modal-\${String((row as any).id)}" class="btn btn-ghost btn-xs btn-square" title="\${(row as any).banned ? 'Unban' : 'Ban'}"><iconify-icon icon="\${(row as any).banned ? 'mdi:lock-open-outline' : 'mdi:block-helper'}" width="15" height="15" class="opacity-50"></iconify-icon></label>\`}
|
|
73
|
+
\t\t\t\t\t\t\t\t\t\t\t\t\t\${(row as any).id === currentUserId ? html\`<button class="btn btn-ghost btn-xs btn-square btn-disabled" title="Delete"><iconify-icon icon="mdi:delete-outline" width="15" height="15" class="opacity-20"></iconify-icon></button>\` : html\`<label for="delete-user-modal-\${String((row as any).id)}" class="btn btn-ghost btn-xs btn-square" title="Delete"><iconify-icon icon="mdi:delete-outline" width="15" height="15" class="opacity-50 hover:text-error"></iconify-icon></label>\`}
|
|
74
|
+
\t\t\t\t\t\t\t\t\t\t\t\t</div>
|
|
75
|
+
\t\t\t\t\t\t\t\t\t\t\t</div>
|
|
76
|
+
\t\t\t\t\t\t\t\t\t\t\t<div class="drawer-side z-50">
|
|
77
|
+
\t\t\t\t\t\t\t\t\t\t\t\t<label for="edit-user-drawer-\${String((row as any).id)}" aria-label="close sidebar" class="drawer-overlay"></label>
|
|
78
|
+
\t\t\t\t\t\t\t\t\t\t\t\t<div class="w-full max-w-md min-h-full bg-base-100 p-6 border-l border-base-200 overflow-y-auto shadow-lg">
|
|
79
|
+
\t\t\t\t\t\t\t\t\t\t\t\t\t<div class="flex justify-between items-center mb-5">
|
|
80
|
+
\t\t\t\t\t\t\t\t\t\t\t\t\t\t<h3 class="text-base font-semibold">Edit user</h3>
|
|
81
|
+
\t\t\t\t\t\t\t\t\t\t\t\t\t\t<label for="edit-user-drawer-\${String((row as any).id)}" class="btn btn-sm btn-ghost btn-square">
|
|
82
|
+
\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<iconify-icon icon="mdi:close" width="18" height="18"></iconify-icon>
|
|
83
|
+
\t\t\t\t\t\t\t\t\t\t\t\t\t\t</label>
|
|
84
|
+
\t\t\t\t\t\t\t\t\t\t\t\t\t</div>
|
|
85
|
+
\t\t\t\t\t\t\t\t\t\t\t\t\t<form hx-post="/admin/users/edit" hx-target="#main-content" hx-swap="outerHTML" class="flex flex-col gap-4">
|
|
86
|
+
\t\t\t\t\t\t\t\t\t\t\t\t\t\t<input type="hidden" name="id" value="\${String((row as any).id)}" />
|
|
87
|
+
\t\t\t\t\t\t\t\t\t\t\t\t\t\t<input type="hidden" name="page" value="\${page}" />
|
|
88
|
+
\t\t\t\t\t\t\t\t\t\t\t\t\t\t<input type="hidden" name="search" value="\${search}" />
|
|
89
|
+
\t\t\t\t\t\t\t\t\t\t\t\t\t\t<input type="hidden" name="sort" value="\${sort}" />
|
|
90
|
+
\t\t\t\t\t\t\t\t\t\t\t\t\t\t<input type="hidden" name="order" value="\${order}" />
|
|
91
|
+
\t\t\t\t\t\t\t\t\t\t\t\t\t\t<div class="form-control">
|
|
92
|
+
\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<label class="label"><span class="label-text text-sm font-medium">Name</span></label>
|
|
93
|
+
\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<input name="name" type="text" value="\${String((row as any).name ?? '')}" class="input input-bordered text-sm" required />
|
|
94
|
+
\t\t\t\t\t\t\t\t\t\t\t\t\t\t</div>
|
|
95
|
+
\t\t\t\t\t\t\t\t\t\t\t\t\t\t<div class="form-control">
|
|
96
|
+
\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<label class="label"><span class="label-text text-sm font-medium">Email</span></label>
|
|
97
|
+
\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<input name="email" type="email" value="\${String((row as any).email ?? '')}" class="input input-bordered text-sm" required />
|
|
98
|
+
\t\t\t\t\t\t\t\t\t\t\t\t\t\t</div>
|
|
99
|
+
\t\t\t\t\t\t\t\t\t\t\t\t\t\t<div class="form-control">
|
|
100
|
+
\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<label class="label"><span class="label-text text-sm font-medium">Role</span></label>
|
|
101
|
+
\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<select name="role" class="select select-bordered text-sm" required>
|
|
102
|
+
\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\${String((row as any).role ?? '') === 'admin' ? html\`<option value="admin" selected>admin</option><option value="user">user</option>\` : html\`<option value="admin">admin</option><option value="user" selected>user</option>\`}
|
|
103
|
+
\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t</select>
|
|
104
|
+
\t\t\t\t\t\t\t\t\t\t\t\t\t\t</div>
|
|
105
|
+
\t\t\t\t\t\t\t\t\t\t\t\t\t\t<button class="btn btn-primary btn-sm mt-2" type="submit">Save changes</button>
|
|
106
|
+
\t\t\t\t\t\t\t\t\t\t\t\t\t</form>
|
|
107
|
+
\t\t\t\t\t\t\t\t\t\t\t\t</div>
|
|
108
|
+
\t\t\t\t\t\t\t\t\t\t\t</div>
|
|
109
|
+
\t\t\t\t\t\t\t\t\t\t</div>
|
|
110
|
+
${buildBanUserModal()}
|
|
111
|
+
${buildDeleteUserModal()}
|
|
112
|
+
\t\t\t\t\t\t\t\t\t</td>
|
|
113
|
+
\t\t\t\t\t\t\t\t</tr>
|
|
114
|
+
\t\t\t\t\t\t\t\`)}
|
|
115
|
+
\t\t\t\t\t\t\t\${data.length === 0 ? html\`<tr><td colspan="7" class="text-center py-12">
|
|
116
|
+
\t\t\t\t\t\t\t\t<div class="flex flex-col items-center gap-3">
|
|
117
|
+
\t\t\t\t\t\t\t\t\t<iconify-icon icon="mdi:account-off-outline" width="40" height="40" class="opacity-20"></iconify-icon>
|
|
118
|
+
\t\t\t\t\t\t\t\t\t<p class="text-sm text-base-content/40">No users found matching your query</p>
|
|
119
|
+
\t\t\t\t\t\t\t\t</div>
|
|
120
|
+
\t\t\t\t\t\t\t</td></tr>\` : ''}
|
|
121
|
+
\t\t\t\t\t\t</tbody>
|
|
122
|
+
\t\t\t\t\t</table>
|
|
123
|
+
\t\t\t\t</div>
|
|
124
|
+
\t\t\t\t${paginationHtml}
|
|
125
|
+
\t\t\t</div>
|
|
126
|
+
\t\t\`;
|
|
127
|
+
`;
|
|
128
|
+
}
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import { buildUsersRedirectHelper } from "./redirect";
|
|
2
|
-
import { buildUsersGetRoute } from "./get-route";
|
|
3
|
-
import { buildUsersPostRoutes } from "./post-routes";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Builds the complete users route code string, including:
|
|
7
|
-
* - Runtime helper: buildUsersRedirect
|
|
8
|
-
* - Runtime helper: requireAdminSession
|
|
9
|
-
* - GET /admin/users
|
|
10
|
-
* - POST /admin/users/edit
|
|
11
|
-
* - POST /admin/users/ban
|
|
12
|
-
* - POST /admin/users/unban
|
|
13
|
-
* - POST /admin/users/delete
|
|
14
|
-
*/
|
|
15
|
-
export function buildUsersRoute(): string {
|
|
16
|
-
return `
|
|
17
|
-
\t${buildUsersRedirectHelper()}
|
|
18
|
-
|
|
19
|
-
\tconst requireAdminSession = async (c: any) => {
|
|
20
|
-
\t\tconst auth = createAuth({ DATABASE: c.env[options.databaseBinding] } as any, c.req.raw.cf as any);
|
|
21
|
-
\t\tconst session = await auth.api.getSession({ headers: c.req.raw.headers });
|
|
22
|
-
\t\tif (!session?.user || (session.user as any).role !== 'admin') {
|
|
23
|
-
\t\t\treturn null;
|
|
24
|
-
\t\t}
|
|
25
|
-
\t\treturn session;
|
|
26
|
-
\t};
|
|
27
|
-
|
|
28
|
-
\t${buildUsersGetRoute()}
|
|
29
|
-
|
|
30
|
-
\t${buildUsersPostRoutes()}
|
|
31
|
-
\t`;
|
|
32
|
-
}
|
|
1
|
+
import { buildUsersRedirectHelper } from "./redirect";
|
|
2
|
+
import { buildUsersGetRoute } from "./get-route";
|
|
3
|
+
import { buildUsersPostRoutes } from "./post-routes";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Builds the complete users route code string, including:
|
|
7
|
+
* - Runtime helper: buildUsersRedirect
|
|
8
|
+
* - Runtime helper: requireAdminSession
|
|
9
|
+
* - GET /admin/users
|
|
10
|
+
* - POST /admin/users/edit
|
|
11
|
+
* - POST /admin/users/ban
|
|
12
|
+
* - POST /admin/users/unban
|
|
13
|
+
* - POST /admin/users/delete
|
|
14
|
+
*/
|
|
15
|
+
export function buildUsersRoute(): string {
|
|
16
|
+
return `
|
|
17
|
+
\t${buildUsersRedirectHelper()}
|
|
18
|
+
|
|
19
|
+
\tconst requireAdminSession = async (c: any) => {
|
|
20
|
+
\t\tconst auth = createAuth({ DATABASE: c.env[options.databaseBinding] } as any, c.req.raw.cf as any);
|
|
21
|
+
\t\tconst session = await auth.api.getSession({ headers: c.req.raw.headers });
|
|
22
|
+
\t\tif (!session?.user || (session.user as any).role !== 'admin') {
|
|
23
|
+
\t\t\treturn null;
|
|
24
|
+
\t\t}
|
|
25
|
+
\t\treturn session;
|
|
26
|
+
\t};
|
|
27
|
+
|
|
28
|
+
\t${buildUsersGetRoute()}
|
|
29
|
+
|
|
30
|
+
\t${buildUsersPostRoutes()}
|
|
31
|
+
\t`;
|
|
32
|
+
}
|