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,722 @@
1
+ <template>
2
+ <div>
3
+ <NCard
4
+ :class="`table_${table.slug}`" id="tableCard"
5
+ :title="t('tableSchedules')"
6
+ :header-style="{ paddingRight: 0, paddingLeft: 0 }" content-style="padding: 0"
7
+ :bordered="false" style="background-color: transparent;" embedded>
8
+ <template #header-extra>
9
+ <NButtonGroup>
10
+ <NTooltip :delay="1500">
11
+ <template #trigger>
12
+ <NButton secondary @click="loadSchedules">
13
+ <template #icon>
14
+ <NIcon>
15
+ <Icon name="tabler:refresh" />
16
+ </NIcon>
17
+ </template>
18
+ </NButton>
19
+ </template>
20
+ {{ t("refresh") }}
21
+ </NTooltip>
22
+ <NPopconfirm v-if="!!schedules?.length" @positive-click="runAllActiveSchedules">
23
+ <template #trigger>
24
+ <NTooltip :delay="1500">
25
+ <template #trigger>
26
+ <NButton type="success" secondary round :loading="loading">
27
+ <template #icon>
28
+ <NIcon>
29
+ <Icon name="tabler:player-play" />
30
+ </NIcon>
31
+ </template>
32
+ </NButton>
33
+ </template>
34
+ {{ t("runAllActiveSchedules") }}
35
+ </NTooltip>
36
+ </template>
37
+ {{ t("theFollowingActionIsIrreversible") }}
38
+ </NPopconfirm>
39
+ <NButton type="primary" secondary round :loading="loading" @click="openCreateModal">
40
+ <template #icon>
41
+ <NIcon>
42
+ <Icon name="tabler:plus" />
43
+ </NIcon>
44
+ </template>
45
+ {{ t("addSchedule") }}
46
+ </NButton>
47
+ </NButtonGroup>
48
+ </template>
49
+ <NDataTable
50
+ remote
51
+ :scroll-x="1800"
52
+ :columns="columns"
53
+ :data="schedules"
54
+ :loading="loading"
55
+ :pagination="tablePagination"
56
+ :single-line="false"
57
+ />
58
+ </NCard>
59
+
60
+ <NModal v-model:show="showModal" preset="card" :title="editingSchedule?.id ? t('editSchedule') : t('addSchedule')"
61
+ style="max-width: 720px; width: calc(100vw - 24px);">
62
+ <NForm label-placement="top">
63
+ <NFormItem :label="t('name')">
64
+ <NInput v-model:value="form.name" :placeholder="t('name')" />
65
+ </NFormItem>
66
+ <NFormItem :label="t('preset')">
67
+ <NSelect v-model:value="form.preset" :options="presetOptions" />
68
+ <template #feedback>
69
+ <NText depth="3" style="margin: 8px 0 20px; display: block;">{{ currentPresetDescription }}</NText>
70
+ </template>
71
+ </NFormItem>
72
+ <NFormItem :label="t('cronExpression')">
73
+ <NInput v-model:value="form.cronExpression" :disabled="form.preset !== 'custom'"
74
+ :placeholder="t('cronExpression')" />
75
+ <NText v-if="form.preset === 'custom'" depth="3" style="margin-top: 6px; display: block;">
76
+ {{ t("customCronHint") }}
77
+ </NText>
78
+ </NFormItem>
79
+ <NFormItem :label="t('excludeDays')">
80
+ <NCheckboxGroup v-model:value="form.excludeWeekdays">
81
+ <NFlex wrap>
82
+ <NCheckbox v-for="day of weekdayOptions" :key="day.value" :value="day.value" :label="day.label" />
83
+ </NFlex>
84
+ </NCheckboxGroup>
85
+ <template #feedback>
86
+ <NText depth="3" style="margin: 0 0 20px; display: block;">{{ t("excludeDaysHelp") }}</NText>
87
+ </template>
88
+ </NFormItem>
89
+ <NFormItem :label="t('payloadTemplate')">
90
+ <NInput v-model:value="form.payloadText" type="textarea" :autosize="{ minRows: 8, maxRows: 18 }"
91
+ :placeholder="t('payloadTemplate')" />
92
+ <template #feedback>
93
+ <NFlex style="margin: 8px 0 20px;" justify="space-between" align="center" wrap>
94
+ <NText depth="3">{{ t("payloadHelp") }}</NText>
95
+ <NButtonGroup size="small">
96
+ <NButton @click="formatPayloadText">{{ t("formatJSON") }}</NButton>
97
+ <NButton @click="fillPayloadExample">{{ t("fillExample") }}</NButton>
98
+ <NButton :loading="previewing" @click="previewResolvedPayload">{{ t("previewResolvedPayload") }}</NButton>
99
+ </NButtonGroup>
100
+ </NFlex>
101
+ <NText depth="3" style="display: block; margin: 0 0 8px;">{{ t("payloadTemplateVariablesHelp") }}</NText>
102
+ <pre style="margin: 0; background: var(--n-code-color); border: 1px solid var(--n-border-color); border-radius: 10px; padding: 10px; max-height: 220px; overflow: auto; font-size: 12px; line-height: 1.45;">{{ payloadTemplateExamples }}</pre>
103
+ <div v-if="resolvedPreviewText" style="margin-top: 12px;">
104
+ <NText depth="3" style="display: block; margin: 0 0 8px;">{{ t("resolvedPayloadPreview") }}</NText>
105
+ <pre style="margin: 0; background: var(--n-code-color); border: 1px solid var(--n-border-color); border-radius: 10px; padding: 10px; max-height: 240px; overflow: auto; font-size: 12px; line-height: 1.45;">{{ resolvedPreviewText }}</pre>
106
+ </div>
107
+ </template>
108
+ </NFormItem>
109
+ <NAlert type="default" :show-icon="false" style="margin: 15px 0">
110
+ {{ scheduleSummaryPreview }}
111
+ </NAlert>
112
+ <NFlex justify="space-between" align="center">
113
+ <NText depth="3">{{ t("active") }}</NText>
114
+ <NSwitch v-model:value="form.isActive" />
115
+ </NFlex>
116
+ </NForm>
117
+
118
+ <template #footer>
119
+ <NFlex justify="end">
120
+ <NButton @click="closeModal">{{ t("cancel") }}</NButton>
121
+ <NButton type="primary" :loading="saving" @click="saveSchedule">{{ t("save") }}</NButton>
122
+ </NFlex>
123
+ </template>
124
+ </NModal>
125
+ </div>
126
+ </template>
127
+
128
+ <script lang="ts" setup>
129
+ import type { DataTableColumns, SelectOption } from "naive-ui"
130
+ import Inison from "inison"
131
+ import { Icon, NButton, NButtonGroup, NIcon, NPopconfirm, NTag } from "#components"
132
+
133
+ const database = useState<Database>("database");
134
+ const config = useRuntimeConfig()
135
+ const Language = useScopedCookie<LanguagesType>("language", database.value?.slug)
136
+ const sessionID = useScopedCookie<string>("sid", database.value?.slug)
137
+
138
+ const table = useState<Table>("table")
139
+
140
+ const loading = ref(false)
141
+ const saving = ref(false)
142
+ const previewing = ref(false)
143
+ const showModal = ref(false)
144
+ const schedules = ref<Schedules[]>([])
145
+ const editingSchedule = ref<Schedules | null>(null)
146
+ const resolvedPreviewText = ref("")
147
+ const pagination = reactive({
148
+ page: 1,
149
+ pageSize: 15,
150
+ itemCount: 0,
151
+ })
152
+
153
+ const presetCronMap: Record<Exclude<SchedulesPreset, "custom">, string> = {
154
+ hourly: "0 * * * *",
155
+ daily: "0 0 * * *",
156
+ weekly: "0 0 * * 1",
157
+ monthly: "0 0 1 * *",
158
+ }
159
+
160
+ const form = reactive({
161
+ name: "",
162
+ preset: "hourly" as SchedulesPreset,
163
+ cronExpression: presetCronMap.hourly,
164
+ payloadText: "{}",
165
+ excludeWeekdays: [] as number[],
166
+ isActive: true,
167
+ })
168
+
169
+ const presetOptions = computed<SelectOption[]>(() => [
170
+ { label: t("hourly"), value: "hourly" },
171
+ { label: t("daily"), value: "daily" },
172
+ { label: t("weekly"), value: "weekly" },
173
+ { label: t("monthly"), value: "monthly" },
174
+ { label: t("custom"), value: "custom" },
175
+ ])
176
+
177
+ const weekdayOptions = computed(() => [
178
+ { label: t("sunday"), value: 0 },
179
+ { label: t("monday"), value: 1 },
180
+ { label: t("tuesday"), value: 2 },
181
+ { label: t("wednesday"), value: 3 },
182
+ { label: t("thursday"), value: 4 },
183
+ { label: t("friday"), value: 5 },
184
+ { label: t("saturday"), value: 6 },
185
+ ])
186
+
187
+ const currentPresetDescription = computed(() => {
188
+ switch (form.preset) {
189
+ case "hourly":
190
+ return t("presetDescriptionHourly")
191
+ case "daily":
192
+ return t("presetDescriptionDaily")
193
+ case "weekly":
194
+ return t("presetDescriptionWeekly")
195
+ case "monthly":
196
+ return t("presetDescriptionMonthly")
197
+ default:
198
+ return t("presetDescriptionCustom")
199
+ }
200
+ })
201
+
202
+ const payloadTemplateExamples = computed(() =>
203
+ JSON.stringify(
204
+ {
205
+ title: "Digest for {{ today|date }}",
206
+ runAt: "{{ now }}",
207
+ runAtISO: "{{ now|iso }}",
208
+ expiresAt: "{{ now + 7d }}",
209
+ meta: {
210
+ scheduleId: "{{ schedule.id }}",
211
+ database: "{{ database.slug }}",
212
+ table: "{{ table.slug }}",
213
+ note: "Generated at {{ run.iso }}",
214
+ },
215
+ },
216
+ null,
217
+ 2,
218
+ ),
219
+ )
220
+
221
+ const scheduleSummaryPreview = computed(() => {
222
+ const excluded = formatExcludedDays(form.excludeWeekdays)
223
+ return excluded === t("noExcludedDays")
224
+ ? t("scheduleSummaryNoExcluded")
225
+ : t("scheduleSummaryWithExcluded", { days: excluded })
226
+ })
227
+
228
+ const tablePagination = computed(() => ({
229
+ page: pagination.page,
230
+ pageSize: pagination.pageSize,
231
+ itemCount: pagination.itemCount,
232
+ showSizePicker: true,
233
+ pageSizes: [15, 30, 60, 100],
234
+ onChange: async (page: number) => {
235
+ pagination.page = page
236
+ await loadSchedules()
237
+ },
238
+ onUpdatePageSize: async (pageSize: number) => {
239
+ pagination.pageSize = pageSize
240
+ pagination.page = 1
241
+ await loadSchedules()
242
+ },
243
+ prefix: ({ itemCount }: { itemCount?: number }) => itemCount
244
+ }))
245
+
246
+ watch(
247
+ () => form.preset,
248
+ (preset) => {
249
+ if (preset !== "custom") form.cronExpression = presetCronMap[preset]
250
+ },
251
+ )
252
+
253
+ function getRequestParams() {
254
+ return {
255
+ locale: Language.value,
256
+ [`${database.value.slug}_sid`]: sessionID.value,
257
+ }
258
+ }
259
+
260
+ function formatDate(value?: number) {
261
+ if (!value) return "--"
262
+ return new Date(value).toLocaleString()
263
+ }
264
+
265
+ function formatExcludedDays(excludedDays?: number[]) {
266
+ if (!excludedDays?.length) return t("noExcludedDays")
267
+ return excludedDays
268
+ .map((day) => weekdayOptions.value.find((item) => item.value === day)?.label ?? String(day))
269
+ .join(", ")
270
+ }
271
+
272
+ function buildPayloadExample() {
273
+ const result: Record<string, unknown> = {}
274
+ for (const field of table.value.schema ?? []) {
275
+ if (["id", "createdAt", "updatedAt"].includes(field.key)) continue
276
+ switch (Array.isArray(field.type) ? field.type[0] : field.type) {
277
+ case "number":
278
+ result[field.key] = 0
279
+ break
280
+ case "boolean":
281
+ result[field.key] = false
282
+ break
283
+ case "date":
284
+ result[field.key] = Date.now()
285
+ break
286
+ case "array":
287
+ result[field.key] = []
288
+ break
289
+ case "object":
290
+ case "json":
291
+ result[field.key] = {}
292
+ break
293
+ case "table":
294
+ result[field.key] = "<id>"
295
+ break
296
+ default:
297
+ result[field.key] = ""
298
+ }
299
+ }
300
+ return result
301
+ }
302
+
303
+ function parsePayloadText(payloadText: string) {
304
+ const normalizedPayloadText = payloadText.trim()
305
+ if (!normalizedPayloadText) return {}
306
+
307
+ try {
308
+ return JSON.parse(normalizedPayloadText)
309
+ } catch {
310
+ return Inison.unstringify(normalizedPayloadText) as Record<string, unknown>
311
+ }
312
+ }
313
+
314
+ function formatPayloadText() {
315
+ try {
316
+ form.payloadText = JSON.stringify(parsePayloadText(form.payloadText || "{}"), null, 2)
317
+ } catch {
318
+ window.$message.error(t("invalidJSON"))
319
+ }
320
+ }
321
+
322
+ function fillPayloadExample() {
323
+ form.payloadText = JSON.stringify(buildPayloadExample(), null, 2)
324
+ }
325
+
326
+ async function previewResolvedPayload() {
327
+ let payload: Record<string, unknown>
328
+
329
+ try {
330
+ payload = parsePayloadText(form.payloadText || "{}") as Record<string, unknown>
331
+ } catch {
332
+ window.$message.error(t("invalidJSON"))
333
+ return
334
+ }
335
+
336
+ if (Array.isArray(payload) || !payload || typeof payload !== "object") {
337
+ window.$message.error(t("invalidJSON"))
338
+ return
339
+ }
340
+
341
+ previewing.value = true
342
+ try {
343
+ const response = await $fetch<apiResponse<Record<string, unknown>>>(
344
+ `${config.public.apiBase}${database.value.slug}/${table.value.slug}/schedules/preview`,
345
+ {
346
+ method: "POST",
347
+ body: {
348
+ payload,
349
+ scheduleID: editingSchedule.value?.id,
350
+ },
351
+ params: getRequestParams(),
352
+ credentials: "include",
353
+ },
354
+ )
355
+
356
+ resolvedPreviewText.value = JSON.stringify(response.result ?? {}, null, 2)
357
+ } catch (error: unknown) {
358
+ const errorMessage =
359
+ typeof error === "object" && error !== null && "message" in error
360
+ ? String((error as { message?: unknown }).message ?? t("error"))
361
+ : t("error")
362
+ window.$message.error(errorMessage)
363
+ } finally {
364
+ previewing.value = false
365
+ }
366
+ }
367
+
368
+ function resetForm() {
369
+ form.name = ""
370
+ form.preset = "hourly"
371
+ form.cronExpression = presetCronMap.hourly
372
+ form.payloadText = "{}"
373
+ form.excludeWeekdays = []
374
+ form.isActive = true
375
+ resolvedPreviewText.value = ""
376
+ editingSchedule.value = null
377
+ showModal.value = false
378
+ return true
379
+ }
380
+
381
+ function openCreateModal() {
382
+ resetForm()
383
+ showModal.value = true
384
+ }
385
+
386
+ function openEditModal(schedule: Schedules) {
387
+ editingSchedule.value = schedule
388
+ form.name = schedule.name
389
+ form.preset = schedule.preset ?? "custom"
390
+ form.cronExpression = schedule.cronExpression
391
+ form.payloadText = JSON.stringify(schedule.payload ?? {}, null, 2)
392
+ form.excludeWeekdays = [...(schedule.excludeWeekdays ?? [])]
393
+ form.isActive = schedule.isActive !== false
394
+ resolvedPreviewText.value = ""
395
+ showModal.value = true
396
+ }
397
+
398
+ function closeModal() {
399
+ showModal.value = false
400
+ }
401
+
402
+ async function loadSchedules() {
403
+ loading.value = true
404
+ try {
405
+ const response = await $fetch<apiResponse<Schedules[]>>(
406
+ `${config.public.apiBase}${database.value.slug}/${table.value.slug}/schedules`,
407
+ {
408
+ params: {
409
+ ...getRequestParams(),
410
+ options: Inison.stringify({
411
+ page: pagination.page,
412
+ perPage: pagination.pageSize,
413
+ })
414
+ },
415
+ credentials: "include",
416
+ },
417
+ )
418
+
419
+ schedules.value = response.result ?? []
420
+
421
+ if (response.options) {
422
+ pagination.page = Number(response.options.page ?? pagination.page)
423
+ // pagination.pageSize = Number(response.options.perPage ?? pagination.pageSize)
424
+ pagination.itemCount = Number(response.options.total ?? schedules.value.length)
425
+ } else {
426
+ pagination.itemCount = schedules.value.length
427
+ }
428
+
429
+ return response
430
+ } catch (error: unknown) {
431
+ const errorMessage =
432
+ typeof error === "object" && error !== null
433
+ ? (error as { data?: { message?: string }; message?: string })
434
+ : undefined
435
+ window.$message.error(errorMessage?.data?.message ?? errorMessage?.message ?? t("error"))
436
+ schedules.value = []
437
+ pagination.itemCount = 0
438
+ return null
439
+ } finally {
440
+ loading.value = false
441
+ }
442
+ }
443
+
444
+ async function saveSchedule() {
445
+ let payload: Record<string, unknown>
446
+
447
+ try {
448
+ payload = parsePayloadText(form.payloadText || "{}")
449
+ } catch {
450
+ window.$message.error(t("invalidJSON"))
451
+ return
452
+ }
453
+
454
+ if (Array.isArray(payload) || !payload || typeof payload !== "object") {
455
+ window.$message.error(t("invalidJSON"))
456
+ return
457
+ }
458
+
459
+ if (form.excludeWeekdays.length >= 7) {
460
+ window.$message.error(t("invalidExcludedDays"))
461
+ return
462
+ }
463
+
464
+ saving.value = true
465
+ try {
466
+ const requestBody = {
467
+ name: form.name,
468
+ preset: form.preset,
469
+ cronExpression: form.preset === "custom" ? form.cronExpression : undefined,
470
+ payload,
471
+ excludeWeekdays: [...form.excludeWeekdays].sort((a, b) => a - b),
472
+ isActive: form.isActive,
473
+ }
474
+
475
+ const endpoint = editingSchedule.value?.id
476
+ ? `${config.public.apiBase}${database.value.slug}/${table.value.slug}/schedules/${editingSchedule.value.id}`
477
+ : `${config.public.apiBase}${database.value.slug}/${table.value.slug}/schedules`
478
+ const method = editingSchedule.value?.id ? "PUT" : "POST"
479
+ const response = await $fetch<apiResponse<Schedules>>(endpoint, {
480
+ method,
481
+ body: requestBody,
482
+ params: getRequestParams(),
483
+ credentials: "include",
484
+ })
485
+
486
+ if (response.result) {
487
+ window.$message.success(response.message)
488
+ closeModal()
489
+ await loadSchedules()
490
+ } else window.$message.error(response.message)
491
+ } catch (error: unknown) {
492
+ const errorMessage =
493
+ typeof error === "object" && error !== null
494
+ ? (error as { data?: { message?: string }; message?: string })
495
+ : undefined
496
+ window.$message.error(errorMessage?.data?.message ?? errorMessage?.message ?? t("error"))
497
+ } finally {
498
+ saving.value = false
499
+ }
500
+ }
501
+
502
+ async function runScheduleNow(schedule: Schedules) {
503
+ loading.value = true
504
+ try {
505
+ const response = await $fetch<apiResponse<boolean>>(
506
+ `${config.public.apiBase}${database.value.slug}/${table.value.slug}/schedules/${schedule.id}/run`,
507
+ {
508
+ method: "POST",
509
+ params: getRequestParams(),
510
+ credentials: "include",
511
+ },
512
+ )
513
+
514
+ if (response.result) {
515
+ window.$message.success(response.message)
516
+ await loadSchedules()
517
+ } else window.$message.error(response.message)
518
+ } catch (error: unknown) {
519
+ const errorMessage =
520
+ typeof error === "object" && error !== null
521
+ ? (error as { data?: { message?: string }; message?: string })
522
+ : undefined
523
+ window.$message.error(errorMessage?.data?.message ?? errorMessage?.message ?? t("error"))
524
+ } finally {
525
+ loading.value = false
526
+ }
527
+ }
528
+
529
+ async function runAllActiveSchedules() {
530
+ loading.value = true
531
+ let errors = 0
532
+
533
+ try {
534
+ const response = await $fetch<apiResponse<Schedules[]>>(
535
+ `${config.public.apiBase}${database.value.slug}/${table.value.slug}/schedules`,
536
+ {
537
+ params: {
538
+ ...getRequestParams(),
539
+ where: Inison.stringify({ isActive: true }),
540
+ options: Inison.stringify({ page: 1, perPage: 1000, columns: ["id"] }),
541
+ },
542
+ credentials: "include",
543
+ },
544
+ )
545
+
546
+ const activeSchedules = response.result ?? []
547
+
548
+ if (!activeSchedules.length) {
549
+ window.$message.info(t("noActiveSchedules"))
550
+ return
551
+ }
552
+
553
+ for (const schedule of activeSchedules) {
554
+ try {
555
+ const runResponse = await $fetch<apiResponse<boolean>>(
556
+ `${config.public.apiBase}${database.value.slug}/${table.value.slug}/schedules/${schedule.id}/run`,
557
+ {
558
+ method: "POST",
559
+ params: getRequestParams(),
560
+ credentials: "include",
561
+ },
562
+ )
563
+
564
+ if (!runResponse.result) errors++
565
+ } catch {
566
+ errors++
567
+ }
568
+ }
569
+
570
+ if (errors === 0)
571
+ window.$message.success(t("allActiveSchedulesRan"))
572
+ else
573
+ window.$message.warning(t("someSchedulesFailed", { count: errors }))
574
+
575
+ await loadSchedules()
576
+ } catch (error: unknown) {
577
+ const errorMessage =
578
+ typeof error === "object" && error !== null
579
+ ? (error as { data?: { message?: string }; message?: string })
580
+ : undefined
581
+ window.$message.error(errorMessage?.data?.message ?? errorMessage?.message ?? t("error"))
582
+ } finally {
583
+ loading.value = false
584
+ }
585
+ }
586
+
587
+ async function removeSchedule(schedule: Schedules) {
588
+ loading.value = true
589
+ try {
590
+ const response = await $fetch<apiResponse<boolean>>(
591
+ `${config.public.apiBase}${database.value.slug}/${table.value.slug}/schedules/${schedule.id}`,
592
+ {
593
+ method: "DELETE",
594
+ params: getRequestParams(),
595
+ credentials: "include",
596
+ },
597
+ )
598
+
599
+ const responseCode =
600
+ typeof response === "object" && response !== null && "code" in response
601
+ ? (response as { code?: number }).code
602
+ : undefined
603
+
604
+ if (response.result || responseCode === 204) {
605
+ window.$message.success(response.message)
606
+ await loadSchedules()
607
+ } else window.$message.error(response.message)
608
+ } catch (error: unknown) {
609
+ const errorMessage =
610
+ typeof error === "object" && error !== null
611
+ ? (error as { data?: { message?: string }; message?: string })
612
+ : undefined
613
+ window.$message.error(errorMessage?.data?.message ?? errorMessage?.message ?? t("error"))
614
+ } finally {
615
+ loading.value = false
616
+ }
617
+ }
618
+
619
+ const columns = computed<DataTableColumns<Schedules>>(() => [
620
+ {
621
+ title: t("name"),
622
+ key: "name",
623
+ minWidth: 180,
624
+ },
625
+ {
626
+ title: t("status"),
627
+ key: "isActive",
628
+ width: 120,
629
+ render: (schedule) =>
630
+ h(
631
+ NTag,
632
+ { type: schedule.isActive ? "success" : "default", bordered: false, round: true },
633
+ { default: () => (schedule.isActive ? t("active") : t("inactive")) },
634
+ ),
635
+ },
636
+ {
637
+ title: t("cronExpression"),
638
+ key: "cronExpression",
639
+ minWidth: 160,
640
+ },
641
+ {
642
+ title: t("excludedDays"),
643
+ key: "excludeWeekdays",
644
+ minWidth: 180,
645
+ render: (schedule) => formatExcludedDays(schedule.excludeWeekdays),
646
+ },
647
+ {
648
+ title: t("nextRunAt"),
649
+ key: "nextRunAt",
650
+ minWidth: 170,
651
+ render: (schedule) => (schedule.isActive ? formatDate(schedule.nextRunAt) : "--"),
652
+ },
653
+ {
654
+ title: t("lastRunAt"),
655
+ key: "lastRunAt",
656
+ minWidth: 170,
657
+ render: (schedule) => formatDate(schedule.lastRunAt),
658
+ },
659
+ {
660
+ title: t("lastError"),
661
+ key: "lastError",
662
+ minWidth: 200,
663
+ render: (schedule) => schedule.lastError || "--",
664
+ },
665
+ {
666
+ title: t("actions"),
667
+ key: "actions",
668
+ width: 160,
669
+ fixed: "right",
670
+ render: (schedule) =>
671
+ h(NButtonGroup, { size: "small" }, () => [
672
+ h(
673
+ NPopconfirm,
674
+ { onPositiveClick: () => runScheduleNow(schedule) },
675
+ {
676
+ trigger: () =>
677
+ h(
678
+ NButton,
679
+ { secondary: true, type: "success", title: t("runNow") },
680
+ {
681
+ icon: () =>
682
+ h(NIcon, null, () => h(Icon, { name: "tabler:player-play" })),
683
+ },
684
+ ),
685
+ default: () => t("theFollowingActionIsIrreversible"),
686
+ },
687
+ ),
688
+ h(
689
+ NButton,
690
+ { secondary: true, type: "primary", onClick: () => openEditModal(schedule) },
691
+ {
692
+ icon: () =>
693
+ h(NIcon, null, () => h(Icon, { name: "tabler:pencil" })),
694
+ },
695
+ ),
696
+ h(
697
+ NPopconfirm,
698
+ { onPositiveClick: () => removeSchedule(schedule) },
699
+ {
700
+ trigger: () =>
701
+ h(
702
+ NButton,
703
+ { secondary: true, type: "error" },
704
+ {
705
+ icon: () =>
706
+ h(NIcon, null, () => h(Icon, { name: "tabler:trash" })),
707
+ },
708
+ ),
709
+ default: () => t("theFollowingActionIsIrreversible"),
710
+ },
711
+ ),
712
+ ]),
713
+ },
714
+ ])
715
+
716
+ onMounted(loadSchedules)
717
+
718
+ useHead({
719
+ title: `${t(database.value.slug)} | ${t(table.value.slug)} : ${t("tableSchedules")}`,
720
+ link: [{ rel: "icon", href: database.value?.icon?.publicURL ?? "/favicon.ico" }],
721
+ })
722
+ </script>