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,9 @@
1
+ <template>
2
+ <NA :href="value" target="_blank">
3
+ {{ value }}
4
+ </NA>
5
+ </template>
6
+
7
+ <script lang="ts" setup>
8
+ defineProps<{ value?: string }>()
9
+ </script>
@@ -0,0 +1,41 @@
1
+ <template>
2
+ <div v-if="value === null || value === undefined || (Array.isArray(value) && value.length === 0)">
3
+ <ColumnBoolean v-if="detectedFieldType === 'boolean'" />
4
+ <NText :depth="3" v-else>--</NText>
5
+ </div>
6
+ <div v-else>
7
+ <ColumnRole v-if="detectedFieldType === 'role'" :value />
8
+ <ColumnId v-else-if="['id', 'ip'].includes(detectedFieldType)" :value />
9
+ <NScrollbar v-else-if="field.table === 'assets'" x-scrollable>
10
+ <ColumnAsset :value />
11
+ </NScrollbar>
12
+ <ColumnTable v-else-if="detectedFieldType === 'table'" :value :field />
13
+ <ColumnTags v-else-if="['tags', 'select', 'radio', 'checkbox'].includes(detectedFieldType)" :value :field />
14
+ <ColumnLocale v-else-if="detectedFieldType === 'locale'" :value />
15
+ <ColumnColor v-else-if="detectedFieldType === 'color'" :value />
16
+ <ColumnUrl v-else-if="detectedFieldType === 'url'" :value />
17
+ <ColumnEmail v-else-if="detectedFieldType === 'email'" :value />
18
+ <ColumnHtml v-else-if="detectedFieldType === 'html'" :value :field :item-label="itemLabel" />
19
+ <ColumnPassword v-else-if="detectedFieldType === 'password'" :value />
20
+ <ColumnBoolean v-else-if="detectedFieldType === 'boolean'" :value />
21
+ <ColumnDate v-else-if="detectedFieldType === 'date'" :value :field />
22
+ <ColumnObject v-else-if="detectedFieldType === 'object'" :value :field />
23
+ <ColumnArray v-else-if="detectedFieldType === 'array'" :value :field />
24
+ <ColumnText
25
+ v-else-if="['string', 'text', 'textarea', 'number', 'radio', 'multiple'].includes(detectedFieldType)"
26
+ :value />
27
+ </div>
28
+ </template>
29
+
30
+ <script lang="ts" setup>
31
+ const { field, value, itemLabel } = defineProps<{
32
+ field: Field;
33
+ value?: any;
34
+ itemLabel?: string;
35
+ }>();
36
+
37
+ let detectedFieldType = (field.subType ?? field.type) as
38
+ | DB_FieldType
39
+ | CMS_FieldType;
40
+ if (Array.isArray(detectedFieldType)) detectedFieldType = getField(field).key;
41
+ </script>
@@ -0,0 +1,221 @@
1
+ <template>
2
+ <NFlex vertical :size="24">
3
+ <NCard :title="t('dashboardSettings')">
4
+ <NForm label-placement="left" label-width="120">
5
+ <NFormItem :label="t('name')">
6
+ <NInput v-model:value="model.name" :placeholder="t('dashboardName')" />
7
+ </NFormItem>
8
+ <NFormItem :label="t('description')">
9
+ <NInput
10
+ v-model:value="model.description"
11
+ type="textarea"
12
+ :placeholder="t('description')"
13
+ :rows="2"
14
+ />
15
+ </NFormItem>
16
+ <LazyFieldIcon v-model="model.icon" :field="{ key: 'icon', type: 'string', subType: 'icon' }" />
17
+ </NForm>
18
+ </NCard>
19
+
20
+ <NCard :title="t('widgets')">
21
+ <template #header-extra>
22
+ <NButton size="small" @click="addWidget" type="primary" secondary>
23
+ <template #icon>
24
+ <NIcon>
25
+ <Icon name="tabler:plus" />
26
+ </NIcon>
27
+ </template>
28
+ {{ t("addWidget") }}
29
+ </NButton>
30
+ </template>
31
+
32
+ <VueDraggable
33
+ :model-value="model.widgets as any[]"
34
+ item-key="id"
35
+ handle=".drag-handle"
36
+ :animation="200"
37
+ >
38
+ <template v-for="(widget,index) in model.widgets">
39
+ <NCard
40
+ size="small"
41
+ :style="{ marginBottom: '12px' }"
42
+ :title="widget.title || t('untitledWidget')"
43
+ >
44
+ <template #header-extra>
45
+ <NFlex :size="4">
46
+ <span
47
+ class="drag-handle"
48
+ style="cursor: grab; display: inline-flex; align-items: center; padding: 4px"
49
+ >
50
+ <NIcon :size="16">
51
+ <Icon name="tabler:grip-vertical" />
52
+ </NIcon>
53
+ </span>
54
+ <NButton
55
+ size="tiny"
56
+ quaternary
57
+ @click="editingWidgetIndex = index"
58
+ >
59
+ <template #icon>
60
+ <NIcon>
61
+ <Icon name="tabler:edit" />
62
+ </NIcon>
63
+ </template>
64
+ </NButton>
65
+ <NButton
66
+ size="tiny"
67
+ quaternary
68
+ type="error"
69
+ @click="removeWidget(index)"
70
+ >
71
+ <template #icon>
72
+ <NIcon>
73
+ <Icon name="tabler:trash" />
74
+ </NIcon>
75
+ </template>
76
+ </NButton>
77
+ </NFlex>
78
+ </template>
79
+ <NFlex :size="8">
80
+ <NTag size="small" :bordered="false" type="info">{{
81
+ t(widget.type)
82
+ }}</NTag>
83
+ <NTag size="small" :bordered="false">{{ widget.table || "—" }}</NTag>
84
+ <NTag v-if="widget.size" size="small" :bordered="false" type="warning">{{
85
+ t(widget.size)
86
+ }}</NTag>
87
+ </NFlex>
88
+ </NCard>
89
+ </template>
90
+ </VueDraggable>
91
+
92
+ <NEmpty v-if="!model.widgets?.length" :description="t('noWidgets')" />
93
+ </NCard>
94
+
95
+ <NFlex justify="end">
96
+ <NButton @click="$router.back()">{{ t("cancel") }}</NButton>
97
+ <NButton type="primary" :loading="saving" @click="save">
98
+ {{ t("save") }}
99
+ </NButton>
100
+ </NFlex>
101
+
102
+ <NDrawer
103
+ v-model:show="showWidgetDrawer"
104
+ :width="420"
105
+ placement="right"
106
+ >
107
+ <NDrawerContent :title="t('editWidget')" closable>
108
+ <DashboardWidgetEditor
109
+ v-if="editingWidget"
110
+ v-model="editingWidget"
111
+ />
112
+ <template #footer>
113
+ <NButton type="primary" @click="showWidgetDrawer = false">
114
+ {{ t("confirm") }}
115
+ </NButton>
116
+ </template>
117
+ </NDrawerContent>
118
+ </NDrawer>
119
+ </NFlex>
120
+ </template>
121
+
122
+ <script lang="ts" setup>
123
+ import { VueDraggable } from "vue-draggable-plus";
124
+
125
+ const props = defineProps<{
126
+ dashboard: Dashboard;
127
+ }>();
128
+
129
+ const emit = defineEmits<{
130
+ saved: [dashboard: Dashboard];
131
+ }>();
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 model = ref<Dashboard>({ ...props.dashboard, widgets: [...(props.dashboard.widgets ?? [])] });
139
+ const saving = ref(false);
140
+ const editingWidgetIndex = ref<number | null>(null);
141
+ const showWidgetDrawer = ref(false);
142
+
143
+ const editingWidget = computed({
144
+ get: () =>
145
+ editingWidgetIndex.value !== null
146
+ ? model.value.widgets?.[editingWidgetIndex.value] ?? null
147
+ : null,
148
+ set: (v) => {
149
+ if (editingWidgetIndex.value !== null && v && model.value.widgets) {
150
+ model.value.widgets[editingWidgetIndex.value] = v;
151
+ }
152
+ },
153
+ });
154
+
155
+ watch(editingWidgetIndex, (v) => {
156
+ showWidgetDrawer.value = v !== null;
157
+ });
158
+
159
+ watch(showWidgetDrawer, (v) => {
160
+ if (!v) editingWidgetIndex.value = null;
161
+ });
162
+
163
+ function addWidget() {
164
+ if (!model.value.widgets) model.value.widgets = [];
165
+ const newWidget: Widget = {
166
+ id: `w_${Date.now()}`,
167
+ type: "counter",
168
+ title: "",
169
+ table: "",
170
+ operation: "count",
171
+ size: "small",
172
+ dateRange: "all",
173
+ searchArray: { and: [[null, "=", null]] },
174
+ };
175
+ model.value.widgets.push(newWidget);
176
+ editingWidgetIndex.value = model.value.widgets.length - 1;
177
+ }
178
+
179
+ function removeWidget(index: number) {
180
+ model.value.widgets?.splice(index, 1);
181
+ }
182
+
183
+ async function save() {
184
+ if (!model.value.name) {
185
+ window.$message.error(t("inputsAreInvalid"));
186
+ return;
187
+ }
188
+ saving.value = true;
189
+ try {
190
+ const isUpdate = !!props.dashboard.id;
191
+ const url = isUpdate
192
+ ? `${config.public.apiBase}${database.value.slug}/dashboards/${props.dashboard.id}`
193
+ : `${config.public.apiBase}${database.value.slug}/dashboards`;
194
+
195
+ const res = await $fetch<apiResponse<Dashboard>>(url, {
196
+ method: isUpdate ? "PUT" : "POST",
197
+ body: {
198
+ name: model.value.name,
199
+ description: model.value.description,
200
+ icon: model.value.icon,
201
+ widgets: model.value.widgets,
202
+ },
203
+ params: {
204
+ locale: Language.value,
205
+ [`${database.value.slug}_sid`]: sessionID.value,
206
+ },
207
+ credentials: "include",
208
+ });
209
+
210
+ if (res.result) {
211
+ window.$message.success(res.message);
212
+ emit("saved", res.result);
213
+ } else {
214
+ window.$message.error(res.message ?? t("error"));
215
+ }
216
+ } catch {
217
+ window.$message.error(t("error"));
218
+ }
219
+ saving.value = false;
220
+ }
221
+ </script>
@@ -0,0 +1,270 @@
1
+ <template>
2
+ <NGrid :x-gap="12" :y-gap="12" cols="1 500:2 800:4">
3
+ <NGridItem v-for="dashboard in dashboards" :key="dashboard.id">
4
+ <NCard hoverable>
5
+ <template #header>
6
+ <NuxtLink :to="getDashboardUrl(dashboard.id)">
7
+ <NFlex align="center">
8
+ <NIconWrapper :border-radius="50" style="font-style: normal">
9
+ <NIcon size="20">
10
+ <Icon :name="dashboard.icon ? `tabler:${dashboard.icon}` : 'tabler:chart-bar'" />
11
+ </NIcon>
12
+ </NIconWrapper>
13
+ <NH4 style="margin: 0">{{ dashboard.name }}</NH4>
14
+ </NFlex>
15
+ </NuxtLink>
16
+ </template>
17
+ <template #header-extra>
18
+ <NDropdown
19
+ :options="getDropdownOptions(dashboard)"
20
+ :renderLabel="renderDropdownLabel"
21
+ >
22
+ <NButton secondary size="small">
23
+ <template #icon>
24
+ <NIcon>
25
+ <Icon name="tabler:dots" />
26
+ </NIcon>
27
+ </template>
28
+ </NButton>
29
+ </NDropdown>
30
+ </template>
31
+ <NText depth="3">
32
+ {{
33
+ dashboard.description ||
34
+ t("widgetCount", { count: dashboard.widgets?.length ?? 0 })
35
+ }}
36
+ </NText>
37
+ </NCard>
38
+ </NGridItem>
39
+
40
+ <NGridItem v-if="user?.role === config.public.idOne">
41
+ <NPopover trigger="click" v-model:show="showPopover">
42
+ <template #trigger>
43
+ <NCard
44
+ style="cursor: pointer"
45
+ content-style="padding: 36.5px 0px"
46
+ hoverable
47
+ @click="showPopover = !showPopover"
48
+ >
49
+ <NFlex justify="center" align="center">
50
+ <NIcon size="36">
51
+ <Icon name="tabler:plus" />
52
+ </NIcon>
53
+ </NFlex>
54
+ </NCard>
55
+ </template>
56
+ <NInputGroup>
57
+ <NInput
58
+ v-model:value="newDashboardName"
59
+ @keydown.enter.prevent="createDashboard"
60
+ :placeholder="t('dashboardName')"
61
+ >
62
+ <template #suffix>
63
+ <NIcon>
64
+ <Icon name="tabler:chart-bar" />
65
+ </NIcon>
66
+ </template>
67
+ </NInput>
68
+ <NButton @click="createDashboard" :loading="Loading.Dashboard">
69
+ <template #icon>
70
+ <NIcon>
71
+ <Icon name="tabler:chevron-right" />
72
+ </NIcon>
73
+ </template>
74
+ </NButton>
75
+ </NInputGroup>
76
+ </NPopover>
77
+ </NGridItem>
78
+ </NGrid>
79
+ </template>
80
+
81
+ <script lang="ts" setup>
82
+ import { type DropdownOption, NIcon } from "naive-ui";
83
+ import { Icon, NuxtLink } from "#components";
84
+
85
+ const modelValue = defineModel<Database>({ required: true });
86
+
87
+ const showPopover = ref(false);
88
+ const newDashboardName = ref("");
89
+
90
+ const config = useRuntimeConfig();
91
+ const Loading = useState<Record<string, boolean>>("Loading", () => ({}));
92
+ const user = useState<User>("user");
93
+ const route = useRoute();
94
+ const database = useState<Database>("database");
95
+
96
+ const Language = useScopedCookie<LanguagesType>("language", database.value?.slug);
97
+ const sessionID = useScopedCookie<string>("sid", database.value?.slug);
98
+
99
+ const dashboards = ref<Dashboard[]>([]);
100
+
101
+ const hasDashboardsTable = computed(() =>
102
+ modelValue.value.tables?.some((t) => t.slug === "dashboards"),
103
+ );
104
+
105
+ const ensureDashboardsTable = async () => {
106
+ if (hasDashboardsTable.value) return true;
107
+ if (user.value?.role !== config.public.idOne) return false;
108
+ try {
109
+ const res = await $fetch<apiResponse<Table>>(
110
+ `${config.public.apiBase}inicontent/databases/${modelValue.value.slug}/dashboards`,
111
+ {
112
+ method: "POST",
113
+ body: {
114
+ schema: [
115
+ { key: "name", type: "string", required: true },
116
+ { key: "description", type: "string" },
117
+ { key: "icon", type: "string" },
118
+ { key: "widgets", type: "json" },
119
+ ],
120
+ show: false,
121
+ onRequest: [
122
+ [
123
+ ["@user.4", "!=", 1],
124
+ ["@method", "!=", "GET"],
125
+ ["error", "accessDenied"],
126
+ ],
127
+ ],
128
+ },
129
+ params: {
130
+ locale: Language.value,
131
+ [`${database.value.slug}_sid`]: sessionID.value,
132
+ },
133
+ credentials: "include",
134
+ },
135
+ );
136
+ if (res.result) {
137
+ modelValue.value.tables?.push(res.result);
138
+ return true;
139
+ }
140
+ } catch {}
141
+ return false;
142
+ };
143
+
144
+ const fetchDashboards = async () => {
145
+ if (!hasDashboardsTable.value) {
146
+ const created = await ensureDashboardsTable();
147
+ if (!created) return;
148
+ }
149
+ try {
150
+ const res = await $fetch<apiResponse<Dashboard[]>>(
151
+ `${config.public.apiBase}${modelValue.value.slug}/dashboards`,
152
+ {
153
+ params: {
154
+ locale: Language.value,
155
+ [`${modelValue.value.slug}_sid`]: sessionID.value,
156
+ },
157
+ credentials: "include",
158
+ },
159
+ );
160
+ dashboards.value = res.result ?? [];
161
+ } catch {
162
+ dashboards.value = [];
163
+ }
164
+ };
165
+
166
+ onMounted(fetchDashboards);
167
+
168
+ function getDashboardUrl(id?: string | number) {
169
+ return `/${route.params.database || (database.value?.slug === "inicontent" && route.path === "/admin") ? `${modelValue.value.slug}/` : ""}admin/dashboards/${id}`
170
+ }
171
+
172
+ const createDashboard = async () => {
173
+ if (!newDashboardName.value) {
174
+ window.$message.error(t("inputsAreInvalid"));
175
+ return;
176
+ }
177
+ Loading.value.Dashboard = true;
178
+ try {
179
+ const res = await $fetch<apiResponse<Dashboard>>(
180
+ `${config.public.apiBase}${modelValue.value.slug}/dashboards`,
181
+ {
182
+ method: "POST",
183
+ body: {
184
+ name: newDashboardName.value,
185
+ widgets: [],
186
+ },
187
+ params: {
188
+ locale: Language.value,
189
+ [`${modelValue.value.slug}_sid`]: sessionID.value,
190
+ },
191
+ credentials: "include",
192
+ },
193
+ );
194
+ if (res.result) {
195
+ dashboards.value.push(res.result);
196
+ window.$message.success(res.message);
197
+ newDashboardName.value = "";
198
+ showPopover.value = false;
199
+ } else {
200
+ window.$message.error(res.message ?? t("error"));
201
+ }
202
+ } catch {
203
+ window.$message.error(t("error"));
204
+ }
205
+ Loading.value.Dashboard = false;
206
+ };
207
+
208
+ const deleteDashboard = async (id: string | number) => {
209
+ try {
210
+ const res = await $fetch<apiResponse<any>>(
211
+ `${config.public.apiBase}${modelValue.value.slug}/dashboards/${id}`,
212
+ {
213
+ method: "DELETE",
214
+ params: {
215
+ locale: Language.value,
216
+ [`${modelValue.value.slug}_sid`]: sessionID.value,
217
+ },
218
+ credentials: "include",
219
+ },
220
+ );
221
+ if (res.result) {
222
+ dashboards.value = dashboards.value.filter((d) => d.id !== id);
223
+ window.$message.success(res.message);
224
+ } else {
225
+ window.$message.error(res.message ?? t("error"));
226
+ }
227
+ } catch {
228
+ window.$message.error(t("error"));
229
+ }
230
+ };
231
+
232
+ const getDropdownOptions = (dashboard: Dashboard) => {
233
+ const url = getDashboardUrl(dashboard.id);
234
+ return [
235
+ {
236
+ key: url,
237
+ label: t("view"),
238
+ icon: () => h(NIcon, () => h(Icon, { name: "tabler:eye" })),
239
+ },
240
+ {
241
+ key: `${url}/edit`,
242
+ label: t("edit"),
243
+ icon: () => h(NIcon, () => h(Icon, { name: "tabler:edit" })),
244
+ show: user.value?.role === config.public.idOne,
245
+ },
246
+ {
247
+ key: `delete-${dashboard.id}`,
248
+ label: t("delete"),
249
+ icon: () => h(NIcon, () => h(Icon, { name: "tabler:trash" })),
250
+ show: user.value?.role === config.public.idOne,
251
+ },
252
+ ];
253
+ };
254
+
255
+ function renderDropdownLabel(option: DropdownOption) {
256
+ const key = String(option.key);
257
+ if (key.startsWith("delete-")) {
258
+ const id = key.replace("delete-", "");
259
+ return h(
260
+ "span",
261
+ {
262
+ style: "color: var(--error-color); cursor: pointer;",
263
+ onClick: () => deleteDashboard(id),
264
+ },
265
+ () => option.label,
266
+ );
267
+ }
268
+ return h(NuxtLink, { to: key }, () => option.label);
269
+ }
270
+ </script>
@@ -0,0 +1,131 @@
1
+ <template>
2
+ <NGrid v-if="dashboard.widgets?.length" :x-gap="12" :y-gap="12" :cols="24" responsive="screen">
3
+ <NGridItem
4
+ v-for="widget in dashboard.widgets"
5
+ :key="widget.id + dateRangeKey"
6
+ :span="getSpan(widget)"
7
+ >
8
+ <NCard
9
+ :title="widget.title"
10
+ size="small"
11
+ :style="widget.color ? `border-left: 3px solid ${widget.color}` : ''"
12
+ >
13
+ <template #header-extra>
14
+ <NTag size="small" :bordered="false" type="info">
15
+ {{ t(widget.type) }}
16
+ </NTag>
17
+ </template>
18
+ <DashboardWidgetCounter
19
+ v-if="widget.type === 'counter'"
20
+ :widget="widget"
21
+ :database-slug="databaseSlug"
22
+ :date-range-override="dateRangeOverride"
23
+ />
24
+ <DashboardWidgetLineChart
25
+ v-else-if="widget.type === 'line'"
26
+ :widget="widget"
27
+ :database-slug="databaseSlug"
28
+ :date-range-override="dateRangeOverride"
29
+ />
30
+ <DashboardWidgetBarChart
31
+ v-else-if="widget.type === 'bar'"
32
+ :widget="widget"
33
+ :database-slug="databaseSlug"
34
+ :date-range-override="dateRangeOverride"
35
+ />
36
+ <DashboardWidgetPieChart
37
+ v-else-if="widget.type === 'pie'"
38
+ :widget="widget"
39
+ :database-slug="databaseSlug"
40
+ :date-range-override="dateRangeOverride"
41
+ />
42
+ <DashboardWidgetTable
43
+ v-else-if="widget.type === 'table'"
44
+ :widget="widget"
45
+ :database-slug="databaseSlug"
46
+ :date-range-override="dateRangeOverride"
47
+ />
48
+ </NCard>
49
+ </NGridItem>
50
+ </NGrid>
51
+ <NEmpty v-if="!(dashboard.widgets?.length)" :description="t('noWidgets')" />
52
+ </template>
53
+
54
+ <script lang="ts" setup>
55
+ const props = defineProps<{
56
+ dashboard: Dashboard;
57
+ databaseSlug: string;
58
+ dateRangeOverride?: WidgetDateRange;
59
+ }>();
60
+
61
+ const dateRangeKey = computed(() => props.dateRangeOverride ?? "default");
62
+
63
+ const windowWidth = ref(0);
64
+
65
+ const smallWidgetsCount = computed(
66
+ () =>
67
+ (props.dashboard.widgets ?? []).filter(
68
+ (widget) => widget.size === "small" || !widget.size,
69
+ ).length,
70
+ );
71
+
72
+ const desktopSmallWidgetsPerLine = computed(() => {
73
+ if (windowWidth.value < 1024) {
74
+ return 2;
75
+ }
76
+
77
+ let maxPerLine = 3;
78
+
79
+ if (windowWidth.value >= 2160) {
80
+ maxPerLine = 8;
81
+ } else if (windowWidth.value >= 1920) {
82
+ maxPerLine = 7;
83
+ } else if (windowWidth.value >= 1600) {
84
+ maxPerLine = 6;
85
+ } else if (windowWidth.value >= 1366) {
86
+ maxPerLine = 5;
87
+ } else if (windowWidth.value >= 1200) {
88
+ maxPerLine = 4;
89
+ }
90
+
91
+ if (smallWidgetsCount.value === 0) {
92
+ return 3;
93
+ }
94
+
95
+ if (smallWidgetsCount.value < 3) {
96
+ return smallWidgetsCount.value;
97
+ }
98
+
99
+ return Math.min(maxPerLine, smallWidgetsCount.value);
100
+ });
101
+
102
+ const smallWidgetSpan = computed(() =>
103
+ Math.max(3, Math.floor(24 / Math.max(1, desktopSmallWidgetsPerLine.value))),
104
+ );
105
+
106
+ function updateWindowWidth() {
107
+ windowWidth.value = window.innerWidth;
108
+ }
109
+
110
+ onMounted(() => {
111
+ updateWindowWidth();
112
+ window.addEventListener("resize", updateWindowWidth);
113
+ });
114
+
115
+ onBeforeUnmount(() => {
116
+ window.removeEventListener("resize", updateWindowWidth);
117
+ });
118
+
119
+ function getSpan(widget: Widget): number {
120
+ // Tables always get the full row so columns can breathe.
121
+ if (widget.type === "table") return 24;
122
+ switch (widget.size) {
123
+ case "large":
124
+ return 24;
125
+ case "medium":
126
+ return 12;
127
+ default:
128
+ return smallWidgetSpan.value;
129
+ }
130
+ }
131
+ </script>