inicontent 1.0.0

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.
Files changed (205) hide show
  1. package/.github/pull_request.yml +18 -0
  2. package/CONTRIBUTING.md +67 -0
  3. package/LICENSE +21 -0
  4. package/README.md +142 -0
  5. package/app/app.vue +106 -0
  6. package/app/assets/main.css +974 -0
  7. package/app/components/Api/EndpointCard.vue +169 -0
  8. package/app/components/Api/SchemaDocsTable.vue +208 -0
  9. package/app/components/Asset/Card.vue +1363 -0
  10. package/app/components/Asset/Grid.vue +295 -0
  11. package/app/components/Asset/Icon.vue +38 -0
  12. package/app/components/Asset/Preview.vue +486 -0
  13. package/app/components/Asset/Scanner.vue +700 -0
  14. package/app/components/Asset/Thumb.vue +708 -0
  15. package/app/components/Auth/Reset.vue +99 -0
  16. package/app/components/Auth/index.vue +346 -0
  17. package/app/components/ChatInterface.vue +2326 -0
  18. package/app/components/ChatPagePreview.vue +34 -0
  19. package/app/components/Column/Array.vue +29 -0
  20. package/app/components/Column/Asset.vue +21 -0
  21. package/app/components/Column/Boolean.vue +12 -0
  22. package/app/components/Column/Color.vue +9 -0
  23. package/app/components/Column/Date.vue +57 -0
  24. package/app/components/Column/Edit.vue +215 -0
  25. package/app/components/Column/Email.vue +9 -0
  26. package/app/components/Column/Html.vue +27 -0
  27. package/app/components/Column/Id.vue +20 -0
  28. package/app/components/Column/Locale.vue +32 -0
  29. package/app/components/Column/Object.vue +18 -0
  30. package/app/components/Column/Password.vue +7 -0
  31. package/app/components/Column/Role.vue +15 -0
  32. package/app/components/Column/S.vue +14 -0
  33. package/app/components/Column/Table/Single.vue +49 -0
  34. package/app/components/Column/Table/index.vue +42 -0
  35. package/app/components/Column/Tags.vue +31 -0
  36. package/app/components/Column/Text.vue +9 -0
  37. package/app/components/Column/Url.vue +9 -0
  38. package/app/components/Column/index.vue +41 -0
  39. package/app/components/Dashboard/Editor.vue +221 -0
  40. package/app/components/Dashboard/Grid.vue +270 -0
  41. package/app/components/Dashboard/View.vue +131 -0
  42. package/app/components/Dashboard/Widget/BarChart.vue +73 -0
  43. package/app/components/Dashboard/Widget/Counter.vue +51 -0
  44. package/app/components/Dashboard/Widget/LineChart.vue +76 -0
  45. package/app/components/Dashboard/Widget/PieChart.vue +75 -0
  46. package/app/components/Dashboard/Widget/Table.vue +94 -0
  47. package/app/components/Dashboard/WidgetEditor.vue +274 -0
  48. package/app/components/Data/Array.vue +102 -0
  49. package/app/components/Data/Html.vue +9 -0
  50. package/app/components/Data/Icon.vue +9 -0
  51. package/app/components/Data/Object.vue +10 -0
  52. package/app/components/Data/S.vue +16 -0
  53. package/app/components/Data/Table.vue +53 -0
  54. package/app/components/Data/Value.vue +34 -0
  55. package/app/components/Data/index.vue +14 -0
  56. package/app/components/Field/Array.vue +324 -0
  57. package/app/components/Field/Asset/Actions.vue +97 -0
  58. package/app/components/Field/Asset/index.vue +639 -0
  59. package/app/components/Field/Boolean.vue +26 -0
  60. package/app/components/Field/Checkbox.vue +48 -0
  61. package/app/components/Field/Color.vue +27 -0
  62. package/app/components/Field/Date.vue +30 -0
  63. package/app/components/Field/Email.vue +51 -0
  64. package/app/components/Field/EmailTemplate.vue +420 -0
  65. package/app/components/Field/Html/ColorPicker.vue +127 -0
  66. package/app/components/Field/Html/Editor.vue +544 -0
  67. package/app/components/Field/Html/index.vue +25 -0
  68. package/app/components/Field/Icon.vue +114 -0
  69. package/app/components/Field/JSON.vue +113 -0
  70. package/app/components/Field/Mention.vue +36 -0
  71. package/app/components/Field/Number.vue +27 -0
  72. package/app/components/Field/Object.vue +92 -0
  73. package/app/components/Field/Password.vue +55 -0
  74. package/app/components/Field/Radio.vue +47 -0
  75. package/app/components/Field/S.vue +44 -0
  76. package/app/components/Field/Select.vue +49 -0
  77. package/app/components/Field/Table.vue +348 -0
  78. package/app/components/Field/Tags.vue +113 -0
  79. package/app/components/Field/Text.vue +31 -0
  80. package/app/components/Field/Textarea.vue +33 -0
  81. package/app/components/Field/Url.vue +40 -0
  82. package/app/components/Field/Wrapper.vue +128 -0
  83. package/app/components/Field/index.vue +68 -0
  84. package/app/components/FloatingChatbot.vue +73 -0
  85. package/app/components/Form/Card.vue +151 -0
  86. package/app/components/Form/Drawer.vue +195 -0
  87. package/app/components/Form/index.vue +621 -0
  88. package/app/components/Header.vue +328 -0
  89. package/app/components/Offline/ConflictModal.vue +200 -0
  90. package/app/components/Offline/SyncStatus.vue +249 -0
  91. package/app/components/PlatformFeatureLanding.vue +65 -0
  92. package/app/components/Table/Backups.vue +638 -0
  93. package/app/components/Table/Flows.vue +814 -0
  94. package/app/components/Table/Grid.vue +296 -0
  95. package/app/components/Table/Icon.vue +36 -0
  96. package/app/components/Table/Logs.vue +181 -0
  97. package/app/components/Table/Schedules.vue +722 -0
  98. package/app/components/Table/Search/Button.vue +256 -0
  99. package/app/components/Table/Search/Items.vue +286 -0
  100. package/app/components/Table/Search/index.vue +87 -0
  101. package/app/components/Table/Settings/Schema.vue +801 -0
  102. package/app/components/Table/Settings/index.vue +631 -0
  103. package/app/components/Table/TranslateDrawer.vue +526 -0
  104. package/app/components/Table/Views/Kanban.vue +289 -0
  105. package/app/components/Table/Views/Table.vue +1273 -0
  106. package/app/components/Table/index.vue +890 -0
  107. package/app/composables/Translation/define.ts +41 -0
  108. package/app/composables/Translation/fetch.ts +107 -0
  109. package/app/composables/Translation/languages.ts +1 -0
  110. package/app/composables/Translation/loadCoreTranslations.ts +38 -0
  111. package/app/composables/Translation/translate.ts +250 -0
  112. package/app/composables/databaseCookies.ts +79 -0
  113. package/app/composables/fieldValidator.ts +72 -0
  114. package/app/composables/fieldsList.ts +301 -0
  115. package/app/composables/formatDatabase.ts +101 -0
  116. package/app/composables/index.ts +444 -0
  117. package/app/composables/openDrawer.ts +118 -0
  118. package/app/composables/optimizeFile.ts +287 -0
  119. package/app/composables/renderLabel.ts +88 -0
  120. package/app/composables/schemaClipboard.ts +95 -0
  121. package/app/composables/search.ts +353 -0
  122. package/app/composables/setThemeConfig.ts +48 -0
  123. package/app/composables/translationValue.ts +169 -0
  124. package/app/composables/useAssetPreview.ts +84 -0
  125. package/app/composables/useAssetUploader.ts +56 -0
  126. package/app/composables/useDashboardData.ts +310 -0
  127. package/app/composables/useDocumentThumbnail.ts +351 -0
  128. package/app/composables/useEcharts.ts +33 -0
  129. package/app/composables/useLocalDatabaseConfig.ts +51 -0
  130. package/app/composables/useOcr.ts +300 -0
  131. package/app/composables/useOfflineFetch.ts +194 -0
  132. package/app/composables/useOfflineItem.ts +107 -0
  133. package/app/composables/useOfflineQueue.ts +302 -0
  134. package/app/composables/useOfflineSync.ts +235 -0
  135. package/app/composables/usePasskeyAuth.ts +156 -0
  136. package/app/composables/usePdfCompressor.ts +180 -0
  137. package/app/composables/usePlatformRedirect.ts +72 -0
  138. package/app/composables/useRealtimeSync.ts +233 -0
  139. package/app/composables/useReferencedItems.ts +180 -0
  140. package/app/composables/useScanner.ts +664 -0
  141. package/app/composables/useSubscription.ts +650 -0
  142. package/app/composables/useThumbnailCache.ts +136 -0
  143. package/app/composables/useVideoCompressor.ts +194 -0
  144. package/app/error.vue +112 -0
  145. package/app/layouts/api.vue +188 -0
  146. package/app/layouts/dashboard.vue +91 -0
  147. package/app/layouts/default.vue +228 -0
  148. package/app/layouts/table.vue +471 -0
  149. package/app/locales/ar.ts +996 -0
  150. package/app/locales/en.ts +655 -0
  151. package/app/locales/es.ts +996 -0
  152. package/app/locales/fr.ts +997 -0
  153. package/app/middleware/dashboard.ts +33 -0
  154. package/app/middleware/database.ts +83 -0
  155. package/app/middleware/global.ts +1 -0
  156. package/app/middleware/sid-ingest.global.ts +29 -0
  157. package/app/middleware/table.ts +54 -0
  158. package/app/middleware/user.ts +26 -0
  159. package/app/pages/[[database]]/admin/api/auth/index.vue +306 -0
  160. package/app/pages/[[database]]/admin/api/index.vue +18 -0
  161. package/app/pages/[[database]]/admin/api/tables/[table]/index.vue +497 -0
  162. package/app/pages/[[database]]/admin/api/tables/index.vue +87 -0
  163. package/app/pages/[[database]]/admin/billing/index.vue +16 -0
  164. package/app/pages/[[database]]/admin/dashboards/[id]/edit.vue +66 -0
  165. package/app/pages/[[database]]/admin/dashboards/[id]/index.vue +117 -0
  166. package/app/pages/[[database]]/admin/dashboards/index.vue +20 -0
  167. package/app/pages/[[database]]/admin/index.vue +28 -0
  168. package/app/pages/[[database]]/admin/settings.vue +526 -0
  169. package/app/pages/[[database]]/admin/tables/[table]/[id]/edit.vue +143 -0
  170. package/app/pages/[[database]]/admin/tables/[table]/[id]/index.vue +146 -0
  171. package/app/pages/[[database]]/admin/tables/[table]/flows.vue +10 -0
  172. package/app/pages/[[database]]/admin/tables/[table]/index.vue +10 -0
  173. package/app/pages/[[database]]/admin/tables/[table]/new.vue +12 -0
  174. package/app/pages/[[database]]/admin/tables/[table]/schedules.vue +10 -0
  175. package/app/pages/[[database]]/admin/tables/[table]/settings.vue +30 -0
  176. package/app/pages/[[database]]/admin/tables/assets/[...path].vue +24 -0
  177. package/app/pages/[[database]]/admin/tables/assets/flows.vue +10 -0
  178. package/app/pages/[[database]]/admin/tables/backups/index.vue +10 -0
  179. package/app/pages/[[database]]/admin/tables/blocks/index.vue +16 -0
  180. package/app/pages/[[database]]/admin/tables/index.vue +20 -0
  181. package/app/pages/[[database]]/admin/tables/pages/index.vue +16 -0
  182. package/app/pages/[[database]]/admin/tables/templates/index.vue +16 -0
  183. package/app/pages/[[database]]/api/index.vue +120 -0
  184. package/app/pages/[[database]]/auth/index.vue +12 -0
  185. package/app/pages/[[database]]/auth/reset.vue +10 -0
  186. package/app/pages/[[database]]/index.vue +10 -0
  187. package/app/plugins/offline-warmup.client.ts +53 -0
  188. package/app/plugins/template-globals.ts +9 -0
  189. package/app/spa-loading-template.html +93 -0
  190. package/biome.json +53 -0
  191. package/index.d.ts +380 -0
  192. package/modules/naiveui.ts +41 -0
  193. package/nuxt.config.ts +269 -0
  194. package/package.json +56 -0
  195. package/pnpm-workspace.yaml +5 -0
  196. package/public/apple-touch-icon.png +0 -0
  197. package/public/favicon-16x16.png +0 -0
  198. package/public/favicon-32x32.png +0 -0
  199. package/public/favicon.ico +0 -0
  200. package/public/pwa-192x192.png +0 -0
  201. package/public/pwa-512x512.png +0 -0
  202. package/public/pwa-maskable-192x192.png +0 -0
  203. package/public/pwa-maskable-512x512.png +0 -0
  204. package/public/vendor/opencv.js +48 -0
  205. package/tsconfig.json +9 -0
@@ -0,0 +1,117 @@
1
+ <template>
2
+ <NSpin :show="loading">
3
+ <NCard :title="dashboard?.name ?? t('dashboard')" style="background:none" :bordered="false">
4
+ <template #header-extra>
5
+ <NFlex :size="8" align="center">
6
+ <NPopover v-if="dashboard?.widgets?.length" trigger="click" placement="bottom-end">
7
+ <template #trigger>
8
+ <NButton size="small" secondary :type="dateRangeOverride ? 'primary' : 'default'">
9
+ <template #icon>
10
+ <NIcon>
11
+ <Icon name="tabler:calendar" />
12
+ </NIcon>
13
+ </template>
14
+ {{ t('dateRange') }}
15
+ </NButton>
16
+ </template>
17
+ <NSelect
18
+ v-model:value="dateRangeOverride"
19
+ :options="dateRangeOptions"
20
+ :placeholder="t('dateRange')"
21
+ clearable
22
+ style="width: 200px"
23
+ />
24
+ </NPopover>
25
+ <NButton
26
+ v-if="user?.role === config.public.idOne"
27
+ size="small"
28
+ type="primary"
29
+ secondary
30
+ @click="navigateTo(`${routeBase}/admin/dashboards/${route.params.id}/edit`)"
31
+ >
32
+ <template #icon>
33
+ <NIcon>
34
+ <Icon name="tabler:edit" />
35
+ </NIcon>
36
+ </template>
37
+ {{ t("edit") }}
38
+ </NButton>
39
+ </NFlex>
40
+ </template>
41
+ <LazyDashboardView
42
+ v-if="dashboard"
43
+ :dashboard="dashboard"
44
+ :database-slug="databaseSlug"
45
+ :date-range-override="dateRangeOverride"
46
+ />
47
+ </NCard>
48
+ </NSpin>
49
+ </template>
50
+
51
+ <script setup lang="ts">
52
+ definePageMeta({
53
+ layout: "table",
54
+ middleware: ["database", "user", "dashboard", "global"],
55
+ });
56
+
57
+ const route = useRoute();
58
+ const config = useRuntimeConfig();
59
+ const user = useState<User>("user");
60
+ const database = useState<Database>("database");
61
+
62
+ const databaseSlug = computed(() =>
63
+ (route.params.database as string) || database.value?.slug || "",
64
+ );
65
+
66
+ const routeBase = computed(() =>
67
+ route.params.database ? `/${route.params.database}` : "",
68
+ );
69
+
70
+ const Language = useScopedCookie<LanguagesType>("language", database.value?.slug);
71
+ const sessionID = useScopedCookie<string>("sid", database.value?.slug);
72
+
73
+ const dashboard = ref<Dashboard | null>(null);
74
+ const currentDashboard = useState<Dashboard | null>("currentDashboard", () => null);
75
+ const loading = ref(true);
76
+ const dateRangeOverride = ref<WidgetDateRange | undefined>(undefined);
77
+
78
+ const dateRangeOptions = [
79
+ { label: t("last7Days"), value: "7d" },
80
+ { label: t("last30Days"), value: "30d" },
81
+ { label: t("last90Days"), value: "90d" },
82
+ { label: t("lastYear"), value: "1y" },
83
+ { label: t("allTime"), value: "all" },
84
+ ];
85
+
86
+ onMounted(async () => {
87
+ try {
88
+ const slug = databaseSlug.value ? `${databaseSlug.value}/` : "";
89
+ const res = await $fetch<apiResponse<Dashboard>>(
90
+ `${config.public.apiBase}${slug}dashboards/${route.params.id}`,
91
+ {
92
+ params: {
93
+ locale: Language.value,
94
+ [`${databaseSlug.value}_sid`]: sessionID.value,
95
+ },
96
+ credentials: "include",
97
+ },
98
+ );
99
+ dashboard.value = res.result;
100
+ currentDashboard.value = res.result;
101
+ if (dashboard.value) {
102
+ if (typeof dashboard.value.widgets === "string") {
103
+ try {
104
+ dashboard.value.widgets = JSON.parse(dashboard.value.widgets);
105
+ } catch {}
106
+ }
107
+ }
108
+ } catch {
109
+ window.$message.error(t("error"));
110
+ }
111
+ loading.value = false;
112
+ });
113
+
114
+ useHead({
115
+ title: computed(() => `${dashboard.value?.name ?? t("dashboard")} | ${t("dashboards")}`),
116
+ });
117
+ </script>
@@ -0,0 +1,20 @@
1
+ <template>
2
+ <NCard :title="t('dashboards')" style="background:none" :bordered="false">
3
+ <LazyDashboardGrid v-model="database" />
4
+ </NCard>
5
+ </template>
6
+
7
+ <script setup lang="ts">
8
+ definePageMeta({
9
+ layout: "table",
10
+ middleware: ["database", "user", "dashboard", "global"],
11
+ })
12
+
13
+ const database = useState<Database>("database")
14
+ useHead({
15
+ title: `${t(database.value.slug)} | ${t("dashboards")}`,
16
+ link: [
17
+ { rel: "icon", href: database.value?.icon?.publicURL ?? "/favicon.ico" },
18
+ ],
19
+ })
20
+ </script>
@@ -0,0 +1,28 @@
1
+ <template>
2
+ <NFlex style="width: 100%;" vertical :size="24">
3
+ <NCard :title="t('tables')" style="background:none" :bordered="false">
4
+ <LazyTableGrid v-model="database" />
5
+ </NCard>
6
+ <NCard v-if="user?.role === config.public.idOne" :title="t('dashboards')" style="background:none" :bordered="false">
7
+ <LazyDashboardGrid v-model="database" />
8
+ </NCard>
9
+ </NFlex>
10
+ </template>
11
+
12
+ <script setup lang="ts">
13
+ definePageMeta({
14
+ layout: "dashboard",
15
+ middleware: ["database", "user", "dashboard", "global"],
16
+ })
17
+
18
+ const database = useState<Database>("database")
19
+ const user = useState<User>("user");
20
+ const config = useRuntimeConfig();
21
+
22
+ useHead({
23
+ title: `${t(database.value.slug)} | ${t("dashboard")}`,
24
+ link: [
25
+ { rel: "icon", href: database.value?.icon?.publicURL ?? "/favicon.ico" },
26
+ ],
27
+ })
28
+ </script>
@@ -0,0 +1,526 @@
1
+ <template>
2
+ <NGrid x-gap="12" cols="12" layout-shift-disabled>
3
+ <NGridItem :span="!$device.isMobile ? 10 : 12">
4
+ <NCard
5
+ :title="t('settings')" style="background-color: transparent;"
6
+ :header-style="{ paddingRight: 0, paddingLeft: 0 }" content-style="padding: 0" :bordered="false" embedded>
7
+ <template #header-extra>
8
+ <NFlex>
9
+ <NTooltip :delay="1500">
10
+ <template #trigger>
11
+ <NPopconfirm :show-icon="false" @positive-click="deleteDatabase">
12
+ <template #trigger>
13
+ <NButton type="error" tertiary round :loading="Loading.deleteDatabase">
14
+ <template #icon>
15
+ <NIcon>
16
+ <Icon name="tabler:trash" />
17
+ </NIcon>
18
+ </template>
19
+ </NButton>
20
+ </template>
21
+ {{ t("theFollowingActionIsIrreversible") }}
22
+ </NPopconfirm>
23
+ </template>
24
+ {{ t("deleteDatabase") }}
25
+ </NTooltip>
26
+ <NButton @click="() => updateDatabase()" type="primary" secondary round
27
+ :loading="Loading.updateDatabase">
28
+ <template #icon>
29
+ <NIcon>
30
+ <Icon name="tabler:device-floppy" />
31
+ </NIcon>
32
+ </template>
33
+ {{ t("save") }}
34
+ </NButton>
35
+ </NFlex>
36
+ </template>
37
+ <NCard v-show="$device.isMobile || activeSection === 'general'" id="general" :title="t('generalSettings')" hoverable>
38
+ <NForm ref="generalRef" :model="databaseCopy">
39
+ <FieldS v-model="databaseCopy" :schema="databaseSchema" />
40
+ </NForm>
41
+ </NCard>
42
+ <NCard v-show="$device.isMobile || activeSection === 'translation'" id="translation" :title="t('translationSettings')" hoverable>
43
+ <NForm ref="translationRef" :model="databaseCopy">
44
+ <FieldS v-model="databaseCopy" :schema="translationSchema" />
45
+ </NForm>
46
+ </NCard>
47
+ <NCard v-if="canExportDatabase" v-show="$device.isMobile || activeSection === 'database-export'"
48
+ id="database-export" :title="t('databaseExport')" hoverable>
49
+ <template #header-extra>
50
+ <NButton v-if="exportStatus?.state === 'completed'" type="primary" secondary
51
+ :loading="Loading.downloadDatabaseExport" @click="downloadDatabaseExport">
52
+ <template #icon><NIcon><Icon name="tabler:download" /></NIcon></template>
53
+ {{ t("download") }}
54
+ </NButton>
55
+ <NButton v-else type="primary" secondary :disabled="exportIsActive"
56
+ :loading="Loading.databaseExport" @click="startDatabaseExport">
57
+ <template #icon><NIcon><Icon name="tabler:database-export" /></NIcon></template>
58
+ {{ t("startDatabaseExport") }}
59
+ </NButton>
60
+ </template>
61
+ <NFlex vertical>
62
+ <NText depth="3">{{ t("databaseExportDescription") }}</NText>
63
+ <NProgress v-if="exportIsActive" type="line" :percentage="exportStatus?.progress ?? 0"
64
+ indicator-placement="inside" processing />
65
+ <NText v-if="exportStatus" depth="3">
66
+ {{ t(`databaseExportState.${exportStatus.state}`) }}
67
+ <template v-if="exportStatus.totalBytes">
68
+ · {{ formatBytes(exportStatus.processedBytes) }} / {{ formatBytes(exportStatus.totalBytes) }}
69
+ </template>
70
+ </NText>
71
+ <NText v-if="exportStatus?.state === 'completed'" depth="3">
72
+ {{ t("databaseExportExpires", { date: new Date(exportStatus.expiresAt).toLocaleString() }) }}
73
+ </NText>
74
+ <NText v-if="exportStatus?.state === 'failed'" type="error">
75
+ {{ exportStatus.error || t("databaseExportFailed") }}
76
+ </NText>
77
+ </NFlex>
78
+ </NCard>
79
+ <NCard v-show="$device.isMobile || activeSection === 'email'" id="email" :title="t('emailSettings')" hoverable>
80
+ <NFlex align="center" :wrap="false" style="margin-bottom: 12px;">
81
+ <NSwitch v-model:value="useCustomSmtp" />
82
+ <span>{{ t("emailConfig.use_custom_smtp") }}</span>
83
+ </NFlex>
84
+ <NForm ref="emailRef" :model="emailForm">
85
+ <FieldS :key="emailFormKey" v-model="emailForm" :schema="emailSchema" />
86
+ </NForm>
87
+ <n-divider />
88
+ <NFlex align="center" justify="end">
89
+ <NInput v-model:value="testRecipient" :placeholder="t('testEmailRecipient')"
90
+ clearable style="max-width: 360px" />
91
+ <NButton type="primary" secondary :disabled="!isEmail(testRecipient)"
92
+ :loading="Loading.testEmail" @click="sendTestEmail">
93
+ <template #icon>
94
+ <NIcon><Icon name="tabler:send" /></NIcon>
95
+ </template>
96
+ {{ t("sendTestEmail") }}
97
+ </NButton>
98
+ </NFlex>
99
+ </NCard>
100
+ </NCard>
101
+ </NGridItem>
102
+ <NGridItem v-if="!$device.isMobile" span="2" style="padding-top: 58px;">
103
+ <div class="settings-tabs-affix">
104
+ <NTabs v-model:value="activeSection" type="line" :placement="isRTL ? 'left' : 'right'"
105
+ @update:value="changeSection">
106
+ <NTab name="general">{{ t('generalSettings') }}</NTab>
107
+ <NTab name="translation">{{ t('translationSettings') }}</NTab>
108
+ <NTab v-if="canExportDatabase" name="database-export">
109
+ {{ t('databaseExport') }}
110
+ </NTab>
111
+ <NTab name="email">{{ t('emailSettings') }}</NTab>
112
+ </NTabs>
113
+ </div>
114
+ </NGridItem>
115
+ </NGrid>
116
+ </template>
117
+
118
+ <script lang="ts" setup>
119
+ import { isEmail } from "inibase/utils";
120
+ import type { FormInst } from "naive-ui";
121
+
122
+ definePageMeta({
123
+ middleware: ["database", "user", "dashboard", "global"],
124
+ layout: "table",
125
+ });
126
+
127
+ onMounted(() => {
128
+ document.onkeydown = (e) => {
129
+ if (
130
+ !(
131
+ (e.ctrlKey || e.metaKey) &&
132
+ (e.key.toLowerCase() === "s" || e.key === "س")
133
+ )
134
+ )
135
+ return;
136
+ e.preventDefault();
137
+ updateDatabase();
138
+ };
139
+ });
140
+
141
+ const config = useRuntimeConfig();
142
+ const Loading = useState<Record<string, boolean>>("Loading", () => ({}));
143
+ const route = useRoute();
144
+ const router = useRouter();
145
+ const database = useState<Database>("database");
146
+ const user = useState<User>("user");
147
+ const Language = useScopedCookie<LanguagesType>("language", database.value?.slug);
148
+ const isRTL = computed(() => Language.value === "ar");
149
+ const generalRef = ref<FormInst>();
150
+ const translationRef = ref<FormInst>();
151
+ const emailRef = ref<FormInst>();
152
+ type SettingsSection = "general" | "translation" | "database-export" | "email";
153
+ const activeSection = ref<SettingsSection>("general");
154
+ const databaseCopy = ref<Database>(JSON.parse(JSON.stringify(database.value)));
155
+ databaseCopy.value.email ??= {};
156
+ const emailForm = ref<NonNullable<Database["email"]>>({
157
+ ...databaseCopy.value.email,
158
+ smtp_port: databaseCopy.value.email.smtp_port ?? 587,
159
+ smtp_secure: databaseCopy.value.email.smtp_secure ?? false,
160
+ smtp_pass: "",
161
+ });
162
+ // UI-only toggle — not persisted, derived from/collapsed into smtp_host presence
163
+ const useCustomSmtp = ref(!!databaseCopy.value.email.smtp_host);
164
+ const emailFormKey = ref(0);
165
+ const testRecipient = ref(
166
+ user.value?.email ?? databaseCopy.value.email.from_email ?? "",
167
+ );
168
+ const exportStatus = ref<DatabaseExportStatus>();
169
+ let exportPollTimer: ReturnType<typeof setTimeout> | undefined;
170
+ const canExportDatabase = computed(
171
+ () => user.value?.role === config.public.idOne,
172
+ );
173
+ const exportIsActive = computed(() =>
174
+ ["queued", "running"].includes(exportStatus.value?.state ?? ""),
175
+ );
176
+
177
+ function sectionFromHash(hash: string): SettingsSection | undefined {
178
+ const section = hash.replace(/^#/, "") as SettingsSection;
179
+ if (
180
+ ["general", "translation", "database-export", "email"].includes(section) &&
181
+ (section !== "database-export" || canExportDatabase.value)
182
+ )
183
+ return section;
184
+ }
185
+
186
+ watch(
187
+ () => route.hash,
188
+ (hash) => {
189
+ const section = sectionFromHash(hash);
190
+ if (section) activeSection.value = section;
191
+ },
192
+ { immediate: true },
193
+ );
194
+
195
+ function changeSection(value: string | number) {
196
+ const section = value as SettingsSection;
197
+ if (section === "database-export" && !canExportDatabase.value) return;
198
+ activeSection.value = section;
199
+ if (route.hash !== `#${section}`) router.replace({ hash: `#${section}` });
200
+ }
201
+
202
+ const databaseSchema: Schema = [
203
+ {
204
+ key: "slug",
205
+ type: "string",
206
+ required: true,
207
+ },
208
+ {
209
+ key: "icon",
210
+ type: "table",
211
+ table: "assets",
212
+ accept: ["image"],
213
+ suffix: "?format=avif&fit=94",
214
+ },
215
+ {
216
+ key: "primaryColor",
217
+ type: "string",
218
+ subType: "color",
219
+ },
220
+ {
221
+ key: "primaryDarkColor",
222
+ type: "string",
223
+ subType: "color",
224
+ },
225
+ {
226
+ key: "roles",
227
+ type: "array",
228
+ children: [
229
+ {
230
+ key: "id",
231
+ type: "id",
232
+ inputProps: {
233
+ disabled: true,
234
+ },
235
+ },
236
+ {
237
+ key: "name",
238
+ type: "string",
239
+ },
240
+ ],
241
+ onCreate: () => ({ id: `temp-${randomID()}` }),
242
+ inputProps: (index: number) =>
243
+ [0, 1, 2].includes(index) ? { disabled: true } : {},
244
+ required: false,
245
+ },
246
+ ];
247
+
248
+ const translationSchema = computed<Schema>(() => [
249
+ {
250
+ key: "primaryLanguage",
251
+ type: "string",
252
+ subType: "locale",
253
+ required: true,
254
+ width: 2,
255
+ },
256
+ {
257
+ key: "secondaryLanguages",
258
+ type: "array",
259
+ children: "string",
260
+ subType: "select",
261
+ options: translationLanguages
262
+ .filter((l) => l !== databaseCopy.value.primaryLanguage)
263
+ .map((l) => ({ label: t(`languages.${l}`), value: l })),
264
+ width: 2,
265
+ },
266
+ ]);
267
+
268
+ const emailSchema = computed<Schema>(() => [
269
+ {
270
+ key: "from_email",
271
+ type: "email",
272
+ label: t("emailConfig.from_email"),
273
+ width: 2,
274
+ inputProps: { placeholder: t("emailConfig.from_email") },
275
+ },
276
+ {
277
+ key: "from_name",
278
+ type: "string",
279
+ label: t("emailConfig.from_name"),
280
+ width: 2,
281
+ inputProps: { placeholder: t("emailConfig.from_name") },
282
+ },
283
+ ...(useCustomSmtp.value
284
+ ? ([
285
+ {
286
+ key: "smtp_host",
287
+ type: "string",
288
+ label: t("emailConfig.smtp_host"),
289
+ width: 2,
290
+ required: true,
291
+ inputProps: { placeholder: t("emailConfig.smtp_host") },
292
+ },
293
+ {
294
+ key: "smtp_port",
295
+ type: "number",
296
+ label: t("emailConfig.smtp_port"),
297
+ width: 2,
298
+ inputProps: { min: 1, max: 65535 },
299
+ },
300
+ {
301
+ key: "smtp_user",
302
+ type: "string",
303
+ label: t("emailConfig.smtp_user"),
304
+ width: 2,
305
+ inputProps: { placeholder: t("emailConfig.smtp_user") },
306
+ },
307
+ {
308
+ key: "smtp_pass",
309
+ type: "password",
310
+ label: t("emailConfig.smtp_pass"),
311
+ width: 2,
312
+ inputProps: { placeholder: t("smtpPasswordUnchanged") },
313
+ },
314
+ {
315
+ key: "smtp_secure",
316
+ type: "boolean",
317
+ label: t("emailConfig.smtp_secure"),
318
+ },
319
+ ] as Schema)
320
+ : []),
321
+ ]);
322
+
323
+ const sessionID = useScopedCookie<string>("sid", database.value?.slug);
324
+
325
+ function exportRequestOptions() {
326
+ return {
327
+ credentials: "include" as const,
328
+ query: {
329
+ [`${database.value.slug}_sid`]: sessionID.value,
330
+ _t: Date.now(),
331
+ },
332
+ };
333
+ }
334
+
335
+ function formatBytes(bytes: number) {
336
+ if (!bytes) return "0 B";
337
+ const units = ["B", "KB", "MB", "GB", "TB"];
338
+ const index = Math.min(
339
+ Math.floor(Math.log(bytes) / Math.log(1024)),
340
+ units.length - 1,
341
+ );
342
+ return `${(bytes / 1024 ** index).toFixed(index ? 1 : 0)} ${units[index]}`;
343
+ }
344
+
345
+ function scheduleExportPoll() {
346
+ if (exportPollTimer) clearTimeout(exportPollTimer);
347
+ if (!exportIsActive.value) return;
348
+ exportPollTimer = setTimeout(async () => {
349
+ await loadDatabaseExportStatus();
350
+ scheduleExportPoll();
351
+ }, 1500);
352
+ }
353
+
354
+ async function loadDatabaseExportStatus() {
355
+ if (!canExportDatabase.value) return;
356
+ try {
357
+ const response = await $fetch<apiResponse<DatabaseExportStatus | null>>(
358
+ `${config.public.apiBase}inicontent/databases/${database.value.slug}/export`,
359
+ exportRequestOptions(),
360
+ );
361
+ exportStatus.value = response.result ?? undefined;
362
+ } catch {
363
+ exportStatus.value = undefined;
364
+ }
365
+ }
366
+
367
+ async function startDatabaseExport() {
368
+ Loading.value.databaseExport = true;
369
+ try {
370
+ const response = await $fetch<apiResponse<DatabaseExportStatus>>(
371
+ `${config.public.apiBase}inicontent/databases/${database.value.slug}/export`,
372
+ { ...exportRequestOptions(), method: "POST" },
373
+ );
374
+ if (!response.result) throw new Error(response.message);
375
+ exportStatus.value = response.result;
376
+ scheduleExportPoll();
377
+ } catch (error: unknown) {
378
+ const message = error as { data?: { message?: string }; message?: string };
379
+ window.$message.error(
380
+ message.data?.message || message.message || t("databaseExportFailed"),
381
+ );
382
+ } finally {
383
+ Loading.value.databaseExport = false;
384
+ }
385
+ }
386
+
387
+ async function downloadDatabaseExport() {
388
+ Loading.value.downloadDatabaseExport = true;
389
+ try {
390
+ const response = await $fetch<apiResponse<{ url: string }>>(
391
+ `${config.public.apiBase}inicontent/databases/${database.value.slug}/export/download`,
392
+ exportRequestOptions(),
393
+ );
394
+ if (!response.result?.url) throw new Error(response.message);
395
+ window.location.assign(response.result.url);
396
+ } catch (error: unknown) {
397
+ const message = error as { data?: { message?: string }; message?: string };
398
+ window.$message.error(
399
+ message.data?.message || message.message || t("databaseExportFailed"),
400
+ );
401
+ } finally {
402
+ Loading.value.downloadDatabaseExport = false;
403
+ }
404
+ }
405
+
406
+ onMounted(async () => {
407
+ await loadDatabaseExportStatus();
408
+ scheduleExportPoll();
409
+ });
410
+ onBeforeUnmount(() => {
411
+ if (exportPollTimer) clearTimeout(exportPollTimer);
412
+ });
413
+
414
+ async function updateDatabase(showSuccess = true) {
415
+ try {
416
+ await Promise.all([
417
+ generalRef.value?.validate(),
418
+ translationRef.value?.validate(),
419
+ emailRef.value?.validate(),
420
+ ]);
421
+ } catch {
422
+ window.$message.error(t("inputsAreInvalid"));
423
+ return false;
424
+ }
425
+
426
+ const bodyContent = JSON.parse(
427
+ JSON.stringify(databaseCopy.value),
428
+ ) as Database;
429
+ bodyContent.email = JSON.parse(JSON.stringify(emailForm.value));
430
+ // Toggling off custom SMTP clears smtp_host so the API falls back to the default Inicontent SMTP
431
+ if (!useCustomSmtp.value && bodyContent.email) {
432
+ bodyContent.email.smtp_host = "";
433
+ bodyContent.email.smtp_user = "";
434
+ bodyContent.email.smtp_pass = "";
435
+ bodyContent.email.smtp_secure = false;
436
+ }
437
+ if (!bodyContent.email?.smtp_pass) delete bodyContent.email?.smtp_pass;
438
+
439
+ Loading.value.updateDatabase = true;
440
+ try {
441
+ const data = await $fetch<apiResponse<Database>>(
442
+ `${config.public.apiBase}inicontent/databases/${database.value.slug}`,
443
+ {
444
+ method: "PUT",
445
+ body: bodyContent,
446
+ credentials: "include",
447
+ query: {
448
+ [`${database.value.slug}_sid`]: sessionID.value,
449
+ },
450
+ },
451
+ );
452
+ if (!data.result) {
453
+ window.$message.error(data.message);
454
+ return false;
455
+ }
456
+
457
+ database.value = { ...database.value, ...data.result };
458
+ emailForm.value.smtp_pass = "";
459
+ emailFormKey.value++;
460
+ if (route.params.database !== database.value.slug)
461
+ await router.replace({ params: { database: database.value.slug } });
462
+ setThemeConfig();
463
+ if (showSuccess) window.$message.success(data.message);
464
+ return true;
465
+ } catch (error: unknown) {
466
+ const message = (error as { data?: { message?: string } })?.data?.message;
467
+ window.$message.error(message ?? t("error"));
468
+ return false;
469
+ } finally {
470
+ Loading.value.updateDatabase = false;
471
+ }
472
+ }
473
+
474
+ async function sendTestEmail() {
475
+ if (!isEmail(testRecipient.value) || !(await updateDatabase(false))) return;
476
+
477
+ Loading.value.testEmail = true;
478
+ try {
479
+ const data = await $fetch<apiResponse<boolean>>(
480
+ `${config.public.apiBase}inicontent/databases/${database.value.slug}/email/test`,
481
+ {
482
+ method: "POST",
483
+ body: { email: testRecipient.value },
484
+ credentials: "include",
485
+ query: { [`${database.value.slug}_sid`]: sessionID.value },
486
+ },
487
+ );
488
+ if (data.result) window.$message.success(data.message);
489
+ else window.$message.error(data.message);
490
+ } catch (error: unknown) {
491
+ const message = (error as { data?: { message?: string } })?.data?.message;
492
+ window.$message.error(message ?? t("emailSendFailed"));
493
+ } finally {
494
+ Loading.value.testEmail = false;
495
+ }
496
+ }
497
+ async function deleteDatabase() {
498
+ Loading.value.deleteDatabase = true;
499
+ const data = await $fetch<apiResponse>(
500
+ `${config.public.apiBase}inicontent/databases/${database.value.slug}`,
501
+ {
502
+ method: "DELETE",
503
+ credentials: "include",
504
+ query: {
505
+ [`${database.value.slug}_sid`]: sessionID.value,
506
+ },
507
+ },
508
+ );
509
+ if (data.result) {
510
+ Loading.value.deleteDatabase = false;
511
+ window.$message.success(data.message);
512
+ setTimeout(async () => {
513
+ clearNuxtState("database");
514
+ await navigateTo("/admin");
515
+ }, 800);
516
+ } else window.$message.error(data.message);
517
+ Loading.value.deleteDatabase = false;
518
+ }
519
+
520
+ useHead({
521
+ title: `${t(database.value.slug)} | ${t("settings")}`,
522
+ link: [
523
+ { rel: "icon", href: database.value?.icon?.publicURL ?? "/favicon.ico" },
524
+ ],
525
+ });
526
+ </script>