@sfxcode/nuxt-ui-mongocamp 1.3.5 → 1.4.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 (201) hide show
  1. package/dist/module.d.mts +8 -0
  2. package/dist/module.json +1 -1
  3. package/dist/module.mjs +6 -0
  4. package/dist/runtime/components/MongocampAggregationBuilder.vue +302 -3
  5. package/dist/runtime/components/MongocampAggregationChart.d.vue.ts +6 -0
  6. package/dist/runtime/components/MongocampAggregationChart.vue +93 -0
  7. package/dist/runtime/components/MongocampAggregationChart.vue.d.ts +6 -0
  8. package/dist/runtime/components/MongocampAggregationStagePreview.d.vue.ts +9 -0
  9. package/dist/runtime/components/MongocampAggregationStagePreview.vue +148 -0
  10. package/dist/runtime/components/MongocampAggregationStagePreview.vue.d.ts +9 -0
  11. package/dist/runtime/components/MongocampBucketFiles.vue +169 -48
  12. package/dist/runtime/components/MongocampBulkDelete.d.vue.ts +19 -0
  13. package/dist/runtime/components/MongocampBulkDelete.vue +118 -23
  14. package/dist/runtime/components/MongocampBulkDelete.vue.d.ts +19 -0
  15. package/dist/runtime/components/MongocampBulkEdit.d.vue.ts +6 -0
  16. package/dist/runtime/components/MongocampBulkEdit.vue +23 -2
  17. package/dist/runtime/components/MongocampBulkEdit.vue.d.ts +6 -0
  18. package/dist/runtime/components/MongocampChart.d.vue.ts +29 -0
  19. package/dist/runtime/components/MongocampChart.vue +129 -0
  20. package/dist/runtime/components/MongocampChart.vue.d.ts +29 -0
  21. package/dist/runtime/components/MongocampCollectionCharts.d.vue.ts +15 -0
  22. package/dist/runtime/components/MongocampCollectionCharts.vue +199 -0
  23. package/dist/runtime/components/MongocampCollectionCharts.vue.d.ts +15 -0
  24. package/dist/runtime/components/MongocampCollectionCopy.d.vue.ts +23 -0
  25. package/dist/runtime/components/MongocampCollectionCopy.vue +445 -0
  26. package/dist/runtime/components/MongocampCollectionCopy.vue.d.ts +23 -0
  27. package/dist/runtime/components/MongocampCollectionData.d.vue.ts +4 -0
  28. package/dist/runtime/components/MongocampCollectionData.vue +342 -137
  29. package/dist/runtime/components/MongocampCollectionData.vue.d.ts +4 -0
  30. package/dist/runtime/components/MongocampCollectionInfos.vue +106 -238
  31. package/dist/runtime/components/MongocampCollections.vue +62 -0
  32. package/dist/runtime/components/MongocampCommandPalette.d.vue.ts +40 -0
  33. package/dist/runtime/components/MongocampCommandPalette.vue +135 -0
  34. package/dist/runtime/components/MongocampCommandPalette.vue.d.ts +40 -0
  35. package/dist/runtime/components/MongocampConfirmByName.vue +2 -2
  36. package/dist/runtime/components/MongocampDashboard.d.vue.ts +3 -1
  37. package/dist/runtime/components/MongocampDashboard.vue +21 -2
  38. package/dist/runtime/components/MongocampDashboard.vue.d.ts +3 -1
  39. package/dist/runtime/components/MongocampDatabases.vue +22 -0
  40. package/dist/runtime/components/MongocampDocumentCompare.d.vue.ts +20 -0
  41. package/dist/runtime/components/MongocampDocumentCompare.vue +146 -0
  42. package/dist/runtime/components/MongocampDocumentCompare.vue.d.ts +20 -0
  43. package/dist/runtime/components/MongocampDocumentView.d.vue.ts +22 -0
  44. package/dist/runtime/components/MongocampDocumentView.vue +202 -0
  45. package/dist/runtime/components/MongocampDocumentView.vue.d.ts +22 -0
  46. package/dist/runtime/components/MongocampErrorAlert.vue +12 -4
  47. package/dist/runtime/components/MongocampExportAll.d.vue.ts +18 -0
  48. package/dist/runtime/components/MongocampExportAll.vue +204 -0
  49. package/dist/runtime/components/MongocampExportAll.vue.d.ts +18 -0
  50. package/dist/runtime/components/MongocampFilePreview.d.vue.ts +16 -0
  51. package/dist/runtime/components/MongocampFilePreview.vue +162 -0
  52. package/dist/runtime/components/MongocampFilePreview.vue.d.ts +16 -0
  53. package/dist/runtime/components/MongocampFilterBuilder.vue +11 -0
  54. package/dist/runtime/components/MongocampImport.vue +2 -10
  55. package/dist/runtime/components/MongocampIndexes.d.vue.ts +18 -0
  56. package/dist/runtime/components/MongocampIndexes.vue +455 -0
  57. package/dist/runtime/components/MongocampIndexes.vue.d.ts +18 -0
  58. package/dist/runtime/components/MongocampJobs.d.vue.ts +6 -1
  59. package/dist/runtime/components/MongocampJobs.vue +23 -3
  60. package/dist/runtime/components/MongocampJobs.vue.d.ts +6 -1
  61. package/dist/runtime/components/MongocampPermissionMatrix.d.vue.ts +12 -0
  62. package/dist/runtime/components/MongocampPermissionMatrix.vue +301 -0
  63. package/dist/runtime/components/MongocampPermissionMatrix.vue.d.ts +12 -0
  64. package/dist/runtime/components/MongocampQueryBar.d.vue.ts +26 -0
  65. package/dist/runtime/components/MongocampQueryBar.vue +398 -0
  66. package/dist/runtime/components/MongocampQueryBar.vue.d.ts +26 -0
  67. package/dist/runtime/components/MongocampRoleGrants.vue +2 -2
  68. package/dist/runtime/components/MongocampRoles.vue +3 -3
  69. package/dist/runtime/components/MongocampServerOverview.d.vue.ts +20 -0
  70. package/dist/runtime/components/MongocampServerOverview.vue +443 -0
  71. package/dist/runtime/components/MongocampServerOverview.vue.d.ts +20 -0
  72. package/dist/runtime/components/MongocampSettings.d.vue.ts +25 -1
  73. package/dist/runtime/components/MongocampSettings.vue +70 -9
  74. package/dist/runtime/components/MongocampSettings.vue.d.ts +25 -1
  75. package/dist/runtime/components/MongocampUsers.vue +3 -3
  76. package/dist/runtime/composables/useMongocampAdmin.d.ts +2 -1
  77. package/dist/runtime/composables/useMongocampAdmin.js +6 -1
  78. package/dist/runtime/composables/useMongocampAggregation.d.ts +12 -1
  79. package/dist/runtime/composables/useMongocampAggregation.js +33 -25
  80. package/dist/runtime/composables/useMongocampAutoRefresh.d.ts +26 -0
  81. package/dist/runtime/composables/useMongocampAutoRefresh.js +78 -0
  82. package/dist/runtime/composables/useMongocampBucket.d.ts +13 -1
  83. package/dist/runtime/composables/useMongocampBucket.js +34 -0
  84. package/dist/runtime/composables/useMongocampClientApi.js +2 -1
  85. package/dist/runtime/composables/useMongocampCollectionCopy.d.ts +85 -0
  86. package/dist/runtime/composables/useMongocampCollectionCopy.js +105 -0
  87. package/dist/runtime/composables/useMongocampCollectionStats.d.ts +10 -0
  88. package/dist/runtime/composables/useMongocampCollectionStats.js +17 -0
  89. package/dist/runtime/composables/useMongocampError.d.ts +2 -1
  90. package/dist/runtime/composables/useMongocampError.js +16 -1
  91. package/dist/runtime/composables/useMongocampExportAll.d.ts +47 -0
  92. package/dist/runtime/composables/useMongocampExportAll.js +27 -0
  93. package/dist/runtime/composables/useMongocampExtendedJson.d.ts +5 -1
  94. package/dist/runtime/composables/useMongocampExtendedJson.js +12 -6
  95. package/dist/runtime/composables/useMongocampFetchAll.d.ts +25 -0
  96. package/dist/runtime/composables/useMongocampFetchAll.js +27 -0
  97. package/dist/runtime/composables/useMongocampPermissions.d.ts +14 -0
  98. package/dist/runtime/composables/useMongocampPermissions.js +21 -0
  99. package/dist/runtime/composables/useMongocampPersistedState.d.ts +15 -0
  100. package/dist/runtime/composables/useMongocampPersistedState.js +21 -0
  101. package/dist/runtime/composables/useMongocampProxyApi.js +2 -1
  102. package/dist/runtime/composables/useMongocampQuery.d.ts +48 -0
  103. package/dist/runtime/composables/useMongocampQuery.js +72 -1
  104. package/dist/runtime/composables/useMongocampSavedPipelines.d.ts +25 -0
  105. package/dist/runtime/composables/useMongocampSavedPipelines.js +23 -0
  106. package/dist/runtime/composables/useMongocampSavedQueries.d.ts +37 -0
  107. package/dist/runtime/composables/useMongocampSavedQueries.js +50 -0
  108. package/dist/runtime/composables/useMongocampServerOverview.d.ts +42 -0
  109. package/dist/runtime/composables/useMongocampServerOverview.js +61 -0
  110. package/dist/runtime/composables/useMongocampSession.d.ts +2 -0
  111. package/dist/runtime/composables/useMongocampSession.js +16 -2
  112. package/dist/runtime/composables/useMongocampSystem.d.ts +7 -2
  113. package/dist/runtime/composables/useMongocampSystem.js +6 -2
  114. package/dist/runtime/locales/de.json +495 -9
  115. package/dist/runtime/locales/en.json +495 -9
  116. package/dist/runtime/plugin.js +6 -3
  117. package/dist/runtime/utils/aggregationPipeline.d.ts +5 -4
  118. package/dist/runtime/utils/aggregationPipeline.js +23 -9
  119. package/dist/runtime/utils/aggregationPreview.d.ts +13 -0
  120. package/dist/runtime/utils/aggregationPreview.js +10 -0
  121. package/dist/runtime/utils/aggregationResult.d.ts +5 -0
  122. package/dist/runtime/utils/aggregationResult.js +4 -0
  123. package/dist/runtime/utils/aggregationTemplates.d.ts +34 -0
  124. package/dist/runtime/utils/aggregationTemplates.js +47 -0
  125. package/dist/runtime/utils/analyzeSamples.d.ts +1 -0
  126. package/dist/runtime/utils/analyzeSamples.js +1 -1
  127. package/dist/runtime/utils/autoRefresh.d.ts +14 -0
  128. package/dist/runtime/utils/autoRefresh.js +15 -0
  129. package/dist/runtime/utils/bigIntJson.d.ts +15 -0
  130. package/dist/runtime/utils/bigIntJson.js +55 -0
  131. package/dist/runtime/utils/bulkDelete.d.ts +9 -1
  132. package/dist/runtime/utils/bulkDelete.js +15 -3
  133. package/dist/runtime/utils/bulkEdit.d.ts +6 -0
  134. package/dist/runtime/utils/bulkEdit.js +7 -0
  135. package/dist/runtime/utils/chartData.d.ts +11 -0
  136. package/dist/runtime/utils/chartData.js +9 -0
  137. package/dist/runtime/utils/collectionChart.d.ts +36 -0
  138. package/dist/runtime/utils/collectionChart.js +73 -0
  139. package/dist/runtime/utils/collectionCopy.d.ts +26 -0
  140. package/dist/runtime/utils/collectionCopy.js +38 -0
  141. package/dist/runtime/utils/collectionStats.d.ts +31 -0
  142. package/dist/runtime/utils/collectionStats.js +42 -0
  143. package/dist/runtime/utils/commandPalette.d.ts +48 -0
  144. package/dist/runtime/utils/commandPalette.js +39 -0
  145. package/dist/runtime/utils/documentCompare.d.ts +31 -0
  146. package/dist/runtime/utils/documentCompare.js +70 -0
  147. package/dist/runtime/utils/documentDiff.d.ts +19 -0
  148. package/dist/runtime/utils/documentDiff.js +71 -0
  149. package/dist/runtime/utils/documentPaths.d.ts +44 -0
  150. package/dist/runtime/utils/documentPaths.js +144 -0
  151. package/dist/runtime/utils/documentTree.d.ts +40 -0
  152. package/dist/runtime/utils/documentTree.js +94 -0
  153. package/dist/runtime/utils/exportDocuments.d.ts +35 -0
  154. package/dist/runtime/utils/exportDocuments.js +54 -0
  155. package/dist/runtime/utils/exportRows.js +1 -1
  156. package/dist/runtime/utils/filePreview.d.ts +27 -0
  157. package/dist/runtime/utils/filePreview.js +50 -0
  158. package/dist/runtime/utils/filterBuilder.d.ts +6 -1
  159. package/dist/runtime/utils/filterBuilder.js +6 -5
  160. package/dist/runtime/utils/formatBytes.d.ts +2 -0
  161. package/dist/runtime/utils/formatBytes.js +11 -0
  162. package/dist/runtime/utils/grantMatching.d.ts +8 -0
  163. package/dist/runtime/utils/grantMatching.js +15 -0
  164. package/dist/runtime/utils/importRows.js +12 -2
  165. package/dist/runtime/utils/indexCopy.d.ts +26 -0
  166. package/dist/runtime/utils/indexCopy.js +22 -0
  167. package/dist/runtime/utils/indexForm.d.ts +69 -0
  168. package/dist/runtime/utils/indexForm.js +63 -0
  169. package/dist/runtime/utils/limitedMap.d.ts +17 -0
  170. package/dist/runtime/utils/limitedMap.js +19 -0
  171. package/dist/runtime/utils/luceneExpression.d.ts +15 -0
  172. package/dist/runtime/utils/luceneExpression.js +74 -0
  173. package/dist/runtime/utils/pagedFetch.d.ts +46 -0
  174. package/dist/runtime/utils/pagedFetch.js +58 -0
  175. package/dist/runtime/utils/paginationHeaders.d.ts +4 -0
  176. package/dist/runtime/utils/paginationHeaders.js +4 -0
  177. package/dist/runtime/utils/permissionDenied.d.ts +10 -0
  178. package/dist/runtime/utils/permissionDenied.js +23 -0
  179. package/dist/runtime/utils/permissionMatrix.d.ts +55 -0
  180. package/dist/runtime/utils/permissionMatrix.js +85 -0
  181. package/dist/runtime/utils/persistedState.d.ts +25 -0
  182. package/dist/runtime/utils/persistedState.js +47 -0
  183. package/dist/runtime/utils/queryState.d.ts +45 -0
  184. package/dist/runtime/utils/queryState.js +75 -0
  185. package/dist/runtime/utils/requestLimits.d.ts +2 -0
  186. package/dist/runtime/utils/requestLimits.js +4 -0
  187. package/dist/runtime/utils/resultChart.d.ts +32 -0
  188. package/dist/runtime/utils/resultChart.js +59 -0
  189. package/dist/runtime/utils/savedPipelines.d.ts +22 -0
  190. package/dist/runtime/utils/savedPipelines.js +46 -0
  191. package/dist/runtime/utils/savedQueries.d.ts +60 -0
  192. package/dist/runtime/utils/savedQueries.js +143 -0
  193. package/dist/runtime/utils/schemaAnalysis.d.ts +16 -0
  194. package/dist/runtime/utils/schemaAnalysis.js +57 -0
  195. package/dist/runtime/utils/serverError.d.ts +19 -0
  196. package/dist/runtime/utils/serverError.js +19 -0
  197. package/dist/runtime/utils/serverOverview.d.ts +47 -0
  198. package/dist/runtime/utils/serverOverview.js +40 -0
  199. package/dist/runtime/utils/sessionGuard.d.ts +3 -0
  200. package/dist/runtime/utils/sessionGuard.js +18 -1
  201. package/package.json +12 -11
package/dist/module.d.mts CHANGED
@@ -25,6 +25,14 @@ interface ModuleOptions {
25
25
  * server proxy mode (there is no login).
26
26
  */
27
27
  sessionGuard?: boolean;
28
+ /**
29
+ * Opt-in, on top of `sessionGuard`: also ask the server (`GET /auth/authenticated`) whether a token that
30
+ * still looks valid is accepted, so a session invalidated server-side (e.g. by a logout elsewhere) is
31
+ * cleared on navigation instead of on the first failing request. One extra request per navigation, at most
32
+ * once per 30 s per token; only a readable 401 counts, a network failure never logs anyone out. Needs
33
+ * `sessionGuard`; no effect in server proxy mode.
34
+ */
35
+ sessionGuardVerify?: boolean;
28
36
  /**
29
37
  * Path the session guard navigates to after clearing an expired session — e.g. '/login'. Always
30
38
  * treated as allowed by the middleware itself, so it can never cause a redirect loop.
package/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=3.16.0"
6
6
  },
7
- "version": "1.3.5",
7
+ "version": "1.4.0",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.3",
10
10
  "unbuild": "3.6.1"
package/dist/module.mjs CHANGED
@@ -14,6 +14,11 @@ function optionWarnings(options) {
14
14
  "[nuxt-ui-mongocamp] `sessionGuard` has no effect together with `useServerProxy`: server proxy mode has no login, token or session to guard."
15
15
  );
16
16
  }
17
+ if (options.sessionGuardVerify && !options.sessionGuard) {
18
+ warnings.push(
19
+ "[nuxt-ui-mongocamp] `sessionGuardVerify` has no effect without `sessionGuard`: the server check runs inside the session guard middleware."
20
+ );
21
+ }
17
22
  return warnings;
18
23
  }
19
24
 
@@ -34,6 +39,7 @@ const module$1 = defineNuxtModule({
34
39
  logoutRedirectPath: "/",
35
40
  logoutPath: "/logout",
36
41
  sessionGuard: false,
42
+ sessionGuardVerify: false,
37
43
  loginPath: "/",
38
44
  managerRoles: [],
39
45
  securedRouteParts: [],
@@ -2,6 +2,7 @@
2
2
  import { computed, h, ref, watch } from "vue";
3
3
  import { useI18n } from "#imports";
4
4
  import { useMongocampAggregation } from "../composables/useMongocampAggregation";
5
+ import { useMongocampSavedPipelines } from "../composables/useMongocampSavedPipelines";
5
6
  import {
6
7
  VISUAL_STAGE_TYPES,
7
8
  buildPipeline,
@@ -11,6 +12,8 @@ import {
11
12
  toVisualStages,
12
13
  validateStages
13
14
  } from "../utils/aggregationPipeline";
15
+ import { previewPipeline } from "../utils/aggregationPreview";
16
+ import { DEFAULT_TOP, MAX_TOP, templateStages, TEMPLATES, validateTemplateInput } from "../utils/aggregationTemplates";
14
17
  import { formatCell, resultColumns } from "../utils/aggregationResult";
15
18
  import { downloadTextFile, rowsToCsv } from "../utils/exportRows";
16
19
  const props = defineProps({
@@ -23,10 +26,15 @@ const DEFAULT_TEXT = {
23
26
  $group: '{ "_id": "$field", "count": { "$sum": 1 } }',
24
27
  $sort: '{ "count": -1 }',
25
28
  $project: "{}",
26
- $limit: "10"
29
+ $limit: "10",
30
+ $unwind: '"$field"',
31
+ $addFields: '{ "newField": "$field" }',
32
+ $count: '"count"',
33
+ $bucketAuto: '{ "groupBy": "$field", "buckets": 5 }'
27
34
  };
28
35
  const { t } = useI18n();
29
- const { runAggregation, describeAggregationError } = useMongocampAggregation();
36
+ const { runAggregation, describeAggregationError, listFieldNames } = useMongocampAggregation();
37
+ const { saved: savedPipelines, save: savePipeline, remove: removeSavedPipeline } = useMongocampSavedPipelines(() => props.collectionName);
30
38
  let idCounter = 0;
31
39
  function newId() {
32
40
  return `stage-${idCounter++}`;
@@ -40,6 +48,7 @@ const rowsPerPage = ref(20);
40
48
  const page = ref(1);
41
49
  const running = ref(false);
42
50
  const result = ref(null);
51
+ const resultView = ref("table");
43
52
  const runError = ref(null);
44
53
  let lastPipeline = null;
45
54
  let runCounter = 0;
@@ -74,6 +83,83 @@ function moveStage(index, offset) {
74
83
  [next[index], next[target]] = [next[target], next[index]];
75
84
  drafts.value = next;
76
85
  }
86
+ const openPreviews = ref(/* @__PURE__ */ new Set());
87
+ function togglePreview(id) {
88
+ const next = new Set(openPreviews.value);
89
+ if (!next.delete(id)) next.add(id);
90
+ openPreviews.value = next;
91
+ }
92
+ function previewFor(index) {
93
+ if (draftStates.value.slice(0, index + 1).some((state) => state.error)) return void 0;
94
+ return previewPipeline(draftStates.value.map((state) => state.stage), index);
95
+ }
96
+ const fieldNames = ref([]);
97
+ watch(() => props.collectionName, async (name) => {
98
+ fieldNames.value = [];
99
+ try {
100
+ const names = await listFieldNames(name);
101
+ if (name === props.collectionName) fieldNames.value = names;
102
+ } catch {
103
+ }
104
+ }, { immediate: true });
105
+ const templateKey = ref("count-by-field");
106
+ const templateField = ref("");
107
+ const templateValueField = ref("");
108
+ const templateTop = ref(DEFAULT_TOP);
109
+ const templateUnit = ref("month");
110
+ const templateProblem = ref("");
111
+ const TEMPLATE_LABEL_KEYS = {
112
+ "count-by-field": "templateCountByField",
113
+ "top-values": "templateTopValues",
114
+ "date-histogram": "templateDateHistogram",
115
+ "sum-avg-by-group": "templateSumAvg"
116
+ };
117
+ const templateItems = computed(() => TEMPLATES.map((info) => ({ value: info.key, label: t(`nuxtUiMongocamp.aggregation.${TEMPLATE_LABEL_KEYS[info.key]}`) })));
118
+ const templateInfo = computed(() => TEMPLATES.find((info) => info.key === templateKey.value));
119
+ const unitItems = computed(() => [{ value: "year", label: t("nuxtUiMongocamp.aggregation.unitYear") }, { value: "month", label: t("nuxtUiMongocamp.aggregation.unitMonth") }, { value: "day", label: t("nuxtUiMongocamp.aggregation.unitDay") }]);
120
+ const templateFieldLabel = computed(() => t(templateKey.value === "date-histogram" ? "nuxtUiMongocamp.aggregation.templateFieldDate" : templateInfo.value.needsValueField ? "nuxtUiMongocamp.aggregation.templateFieldGroup" : "nuxtUiMongocamp.aggregation.templateField"));
121
+ function isUntouched() {
122
+ return drafts.value.length === 1 && drafts.value[0].type === "$match" && drafts.value[0].text.trim() === DEFAULT_TEXT.$match;
123
+ }
124
+ function addTemplate() {
125
+ const input = { field: templateField.value, valueField: templateValueField.value, top: templateInfo.value.needsTop ? Number(templateTop.value) : void 0, unit: templateUnit.value };
126
+ const problem = validateTemplateInput(templateKey.value, input);
127
+ if (problem) {
128
+ templateProblem.value = t({ "field": "nuxtUiMongocamp.aggregation.templateProblemField", "value-field": "nuxtUiMongocamp.aggregation.templateProblemValue", "top": "nuxtUiMongocamp.aggregation.templateProblemTop" }[problem]);
129
+ return;
130
+ }
131
+ templateProblem.value = "";
132
+ const added = templateStages(templateKey.value, input).map((stage) => ({ id: newId(), type: stage.type, text: JSON.stringify(stage.value, null, 2) }));
133
+ drafts.value = [...isUntouched() ? [] : drafts.value, ...added];
134
+ }
135
+ const saveName = ref("");
136
+ const saveError = ref("");
137
+ function saveCurrent() {
138
+ saveError.value = "";
139
+ const pipeline = pipelineState.value.pipeline;
140
+ if (!pipeline || pipeline.length === 0) {
141
+ saveError.value = t("nuxtUiMongocamp.aggregation.saveFailedPipeline");
142
+ return;
143
+ }
144
+ const result2 = savePipeline(saveName.value, pipeline);
145
+ if (result2.ok) {
146
+ saveName.value = "";
147
+ return;
148
+ }
149
+ saveError.value = t({ "invalid-name": "nuxtUiMongocamp.aggregation.saveFailedName", "invalid-pipeline": "nuxtUiMongocamp.aggregation.saveFailedPipeline", "limit": "nuxtUiMongocamp.aggregation.saveFailedLimit", "too-large": "nuxtUiMongocamp.aggregation.saveFailedSize" }[result2.reason]);
150
+ }
151
+ function applySaved(entry) {
152
+ modeError.value = "";
153
+ openPreviews.value = /* @__PURE__ */ new Set();
154
+ const stages = toVisualStages(entry.pipeline, () => newId());
155
+ if (stages) {
156
+ drafts.value = stages.map((stage) => ({ id: stage.id, type: stage.type, text: JSON.stringify(stage.value, null, 2) }));
157
+ mode.value = "visual";
158
+ return;
159
+ }
160
+ rawText.value = pipelineToText(entry.pipeline);
161
+ mode.value = "json";
162
+ }
77
163
  function pipelineErrorText(error) {
78
164
  const n = (error.stageIndex ?? 0) + 1;
79
165
  return t(`nuxtUiMongocamp.aggregation.pipelineErrors.${error.code}`, { n, operator: error.operator ?? "" });
@@ -208,6 +294,177 @@ const exportMenuItems = computed(() => [
208
294
  />
209
295
  </div>
210
296
 
297
+ <div class="flex flex-wrap items-center gap-2">
298
+ <UPopover
299
+ v-if="mode === 'visual'"
300
+ :content="{ align: 'start' }"
301
+ >
302
+ <UButton
303
+ icon="i-lucide-wand-sparkles"
304
+ color="neutral"
305
+ variant="soft"
306
+ size="sm"
307
+ :label="t('nuxtUiMongocamp.aggregation.templatesButton')"
308
+ />
309
+ <template #content>
310
+ <form
311
+ class="flex w-80 flex-col gap-3 p-3"
312
+ data-test="templates-panel"
313
+ @submit.prevent="addTemplate"
314
+ >
315
+ <USelect
316
+ v-model="templateKey"
317
+ :items="templateItems"
318
+ :aria-label="t('nuxtUiMongocamp.aggregation.templateLabel')"
319
+ />
320
+ <UFormField :label="templateFieldLabel">
321
+ <UInput
322
+ v-model="templateField"
323
+ class="w-full"
324
+ list="aggregation-fields"
325
+ :aria-label="templateFieldLabel"
326
+ />
327
+ </UFormField>
328
+ <UFormField
329
+ v-if="templateInfo.needsValueField"
330
+ :label="t('nuxtUiMongocamp.aggregation.templateValueField')"
331
+ >
332
+ <UInput
333
+ v-model="templateValueField"
334
+ class="w-full"
335
+ list="aggregation-fields"
336
+ :aria-label="t('nuxtUiMongocamp.aggregation.templateValueField')"
337
+ />
338
+ </UFormField>
339
+ <UFormField
340
+ v-if="templateInfo.needsTop"
341
+ :label="t('nuxtUiMongocamp.aggregation.templateTop')"
342
+ >
343
+ <UInput
344
+ v-model.number="templateTop"
345
+ type="number"
346
+ :min="1"
347
+ :max="MAX_TOP"
348
+ class="w-full"
349
+ :aria-label="t('nuxtUiMongocamp.aggregation.templateTop')"
350
+ />
351
+ </UFormField>
352
+ <UFormField
353
+ v-if="templateInfo.needsUnit"
354
+ :label="t('nuxtUiMongocamp.aggregation.templateUnit')"
355
+ >
356
+ <USelect
357
+ v-model="templateUnit"
358
+ :items="unitItems"
359
+ class="w-full"
360
+ :aria-label="t('nuxtUiMongocamp.aggregation.templateUnit')"
361
+ />
362
+ </UFormField>
363
+ <datalist id="aggregation-fields">
364
+ <option
365
+ v-for="name in fieldNames"
366
+ :key="name"
367
+ :value="name"
368
+ />
369
+ </datalist>
370
+ <p
371
+ v-if="templateProblem"
372
+ class="text-sm text-error"
373
+ role="alert"
374
+ >
375
+ {{ templateProblem }}
376
+ </p>
377
+ <p class="text-xs text-dimmed">
378
+ {{ t("nuxtUiMongocamp.aggregation.templatesHelp") }}
379
+ </p>
380
+ <UButton
381
+ type="submit"
382
+ icon="i-lucide-plus"
383
+ :label="t('nuxtUiMongocamp.aggregation.addTemplate')"
384
+ />
385
+ </form>
386
+ </template>
387
+ </UPopover>
388
+
389
+ <UPopover :content="{ align: 'start' }">
390
+ <UButton
391
+ icon="i-lucide-bookmark"
392
+ color="neutral"
393
+ variant="soft"
394
+ size="sm"
395
+ :label="t('nuxtUiMongocamp.aggregation.savedButton')"
396
+ />
397
+ <template #content>
398
+ <div
399
+ class="flex w-96 max-w-[90vw] flex-col gap-2 p-3"
400
+ data-test="saved-panel"
401
+ >
402
+ <h3 class="text-sm font-semibold">
403
+ {{ t("nuxtUiMongocamp.aggregation.savedTitle") }}
404
+ </h3>
405
+ <p
406
+ v-if="savedPipelines.length === 0"
407
+ class="text-sm text-dimmed"
408
+ >
409
+ {{ t("nuxtUiMongocamp.aggregation.savedEmpty") }}
410
+ </p>
411
+ <div
412
+ v-for="entry in savedPipelines"
413
+ :key="entry.name"
414
+ class="flex items-center gap-1"
415
+ >
416
+ <UButton
417
+ color="neutral"
418
+ variant="ghost"
419
+ size="sm"
420
+ class="min-w-0 flex-1 justify-start"
421
+ :label="entry.name"
422
+ @click="applySaved(entry)"
423
+ />
424
+ <UButton
425
+ icon="i-lucide-trash-2"
426
+ color="error"
427
+ variant="ghost"
428
+ size="sm"
429
+ :aria-label="t('nuxtUiMongocamp.aggregation.deleteSaved', { name: entry.name })"
430
+ @click="removeSavedPipeline(entry.name)"
431
+ />
432
+ </div>
433
+ <form
434
+ class="mt-1 flex items-center gap-1"
435
+ @submit.prevent="saveCurrent"
436
+ >
437
+ <UInput
438
+ v-model="saveName"
439
+ size="sm"
440
+ class="min-w-0 flex-1"
441
+ maxlength="80"
442
+ :placeholder="t('nuxtUiMongocamp.aggregation.saveNamePlaceholder')"
443
+ :aria-label="t('nuxtUiMongocamp.aggregation.saveName')"
444
+ />
445
+ <UButton
446
+ type="submit"
447
+ icon="i-lucide-save"
448
+ size="sm"
449
+ :label="t('nuxtUiMongocamp.aggregation.save')"
450
+ :disabled="saveName.trim() === ''"
451
+ />
452
+ </form>
453
+ <p
454
+ v-if="saveError"
455
+ class="text-xs text-error"
456
+ role="alert"
457
+ >
458
+ {{ saveError }}
459
+ </p>
460
+ <p class="text-xs text-dimmed">
461
+ {{ t("nuxtUiMongocamp.aggregation.savedNote") }}
462
+ </p>
463
+ </div>
464
+ </template>
465
+ </UPopover>
466
+ </div>
467
+
211
468
  <UAlert
212
469
  v-if="modeError"
213
470
  color="warning"
@@ -261,7 +518,7 @@ const exportMenuItems = computed(() => [
261
518
  </div>
262
519
  <UTextarea
263
520
  v-model="draft.text"
264
- :rows="draft.type === '$limit' ? 1 : 3"
521
+ :rows="['$limit', '$count', '$unwind'].includes(draft.type) ? 1 : 3"
265
522
  :color="draftStates[index]?.error ? 'error' : void 0"
266
523
  class="w-full font-mono"
267
524
  :aria-label="t('nuxtUiMongocamp.aggregation.stageValue', { type: draft.type })"
@@ -272,6 +529,24 @@ const exportMenuItems = computed(() => [
272
529
  >
273
530
  {{ draftStates[index]?.error }}
274
531
  </p>
532
+ <div class="flex flex-col gap-2">
533
+ <UButton
534
+ :icon="openPreviews.has(draft.id) ? 'i-lucide-eye-off' : 'i-lucide-eye'"
535
+ color="neutral"
536
+ variant="ghost"
537
+ size="xs"
538
+ class="self-start"
539
+ :aria-pressed="openPreviews.has(draft.id)"
540
+ :label="openPreviews.has(draft.id) ? t('nuxtUiMongocamp.aggregation.previewHide') : t('nuxtUiMongocamp.aggregation.previewShow')"
541
+ @click="togglePreview(draft.id)"
542
+ />
543
+ <MongocampAggregationStagePreview
544
+ v-if="openPreviews.has(draft.id)"
545
+ :collection-name="collectionName"
546
+ :pipeline="previewFor(index)"
547
+ :stage-number="index + 1"
548
+ />
549
+ </div>
275
550
  </div>
276
551
  <div class="flex flex-wrap items-center gap-2">
277
552
  <USelect
@@ -346,6 +621,25 @@ const exportMenuItems = computed(() => [
346
621
  {{ t("nuxtUiMongocamp.aggregation.resultsCount", { count: result.total }, result.total) }}
347
622
  </span>
348
623
  <div class="flex flex-wrap items-center gap-2">
624
+ <UFieldGroup size="sm">
625
+ <UButton
626
+ icon="i-lucide-table"
627
+ color="neutral"
628
+ :variant="resultView === 'table' ? 'subtle' : 'ghost'"
629
+ :label="t('nuxtUiMongocamp.aggregationChart.viewTable')"
630
+ data-testid="view-table"
631
+ @click="resultView = 'table'"
632
+ />
633
+ <UButton
634
+ icon="i-lucide-chart-column"
635
+ color="neutral"
636
+ :variant="resultView === 'chart' ? 'subtle' : 'ghost'"
637
+ :label="t('nuxtUiMongocamp.aggregationChart.viewChart')"
638
+ :disabled="result.rows.length === 0"
639
+ data-testid="view-chart"
640
+ @click="resultView = 'chart'"
641
+ />
642
+ </UFieldGroup>
349
643
  <UDropdownMenu :items="exportMenuItems">
350
644
  <UButton
351
645
  icon="i-lucide-download"
@@ -373,7 +667,12 @@ const exportMenuItems = computed(() => [
373
667
  </div>
374
668
  </div>
375
669
 
670
+ <MongocampAggregationChart
671
+ v-if="resultView === 'chart'"
672
+ :rows="result.rows"
673
+ />
376
674
  <UTable
675
+ v-else
377
676
  :data="result.rows"
378
677
  :columns="tableColumns"
379
678
  :loading="running"
@@ -0,0 +1,6 @@
1
+ type __VLS_Props = {
2
+ rows: Record<string, unknown>[];
3
+ };
4
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
5
+ declare const _default: typeof __VLS_export;
6
+ export default _default;
@@ -0,0 +1,93 @@
1
+ <script setup>
2
+ import { computed, ref, watch } from "vue";
3
+ import { useI18n } from "#imports";
4
+ import { resultColumns } from "../utils/aggregationResult";
5
+ import { buildResultChart, LABEL_KEY, MAX_CHART_ROWS, MAX_SERIES, valueColumns } from "../utils/resultChart";
6
+ const props = defineProps({
7
+ rows: { type: Array, required: true }
8
+ });
9
+ const { t } = useI18n();
10
+ const columns = computed(() => resultColumns(props.rows));
11
+ const labelKey = ref(void 0);
12
+ const valueKeys = ref([]);
13
+ const kind = ref(void 0);
14
+ watch(() => props.rows, () => {
15
+ labelKey.value = void 0;
16
+ valueKeys.value = [];
17
+ kind.value = void 0;
18
+ });
19
+ const chart = computed(() => buildResultChart(props.rows, columns.value, { labelKey: labelKey.value, valueKeys: valueKeys.value, kind: kind.value }));
20
+ const numberColumns = computed(() => valueColumns(props.rows, columns.value, chart.value?.labelKey));
21
+ const kinds = computed(() => ["bar", "area", "donut"].map((value) => ({ value, label: t(`nuxtUiMongocamp.aggregationChart.kind.${value}`) })));
22
+ const categories = computed(() => (chart.value?.valueKeys ?? []).map((key) => ({ key, label: key })));
23
+ </script>
24
+
25
+ <template>
26
+ <div
27
+ class="flex flex-col gap-3"
28
+ data-testid="aggregation-chart"
29
+ >
30
+ <UAlert
31
+ v-if="!chart"
32
+ color="neutral"
33
+ variant="subtle"
34
+ icon="i-lucide-chart-no-axes-column"
35
+ :title="t('nuxtUiMongocamp.aggregationChart.nothing')"
36
+ data-testid="chart-nothing"
37
+ />
38
+ <template v-else>
39
+ <div class="flex flex-wrap items-end gap-3">
40
+ <UFormField :label="t('nuxtUiMongocamp.aggregationChart.labelColumn')">
41
+ <USelect
42
+ :model-value="chart.labelKey"
43
+ :items="columns"
44
+ size="sm"
45
+ class="w-40"
46
+ @update:model-value="labelKey = $event;
47
+ valueKeys = []"
48
+ />
49
+ </UFormField>
50
+ <UFormField :label="t('nuxtUiMongocamp.aggregationChart.valueColumns', { max: MAX_SERIES })">
51
+ <USelect
52
+ :model-value="chart.valueKeys"
53
+ :items="numberColumns"
54
+ multiple
55
+ size="sm"
56
+ class="w-48"
57
+ @update:model-value="valueKeys = $event"
58
+ />
59
+ </UFormField>
60
+ <UFormField :label="t('nuxtUiMongocamp.aggregationChart.type')">
61
+ <USelect
62
+ :model-value="chart.kind"
63
+ :items="kinds"
64
+ size="sm"
65
+ class="w-28"
66
+ @update:model-value="kind = $event"
67
+ />
68
+ </UFormField>
69
+ </div>
70
+ <MongocampChart
71
+ :type="chart.kind"
72
+ :data="chart.data"
73
+ :index="LABEL_KEY"
74
+ :categories="categories"
75
+ :index-label="chart.labelKey"
76
+ :chart-label="t('nuxtUiMongocamp.aggregationChart.ariaLabel', { values: chart.valueKeys.join(', '), label: chart.labelKey })"
77
+ :chart-description="t('nuxtUiMongocamp.aggregationChart.ariaDescription', { count: chart.data.length })"
78
+ />
79
+ <p
80
+ v-if="chart.cut || chart.skipped"
81
+ class="text-xs text-dimmed"
82
+ data-testid="chart-note"
83
+ >
84
+ <template v-if="chart.cut">
85
+ {{ t("nuxtUiMongocamp.aggregationChart.cut", { max: MAX_CHART_ROWS }) }}
86
+ </template>
87
+ <template v-if="chart.skipped">
88
+ {{ t("nuxtUiMongocamp.aggregationChart.skipped", { count: chart.skipped }) }}
89
+ </template>
90
+ </p>
91
+ </template>
92
+ </div>
93
+ </template>
@@ -0,0 +1,6 @@
1
+ type __VLS_Props = {
2
+ rows: Record<string, unknown>[];
3
+ };
4
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
5
+ declare const _default: typeof __VLS_export;
6
+ export default _default;
@@ -0,0 +1,9 @@
1
+ import type { RequestStage } from '../utils/aggregationPipeline.js';
2
+ type __VLS_Props = {
3
+ collectionName: string;
4
+ pipeline: RequestStage[] | undefined;
5
+ stageNumber: number;
6
+ };
7
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
8
+ declare const _default: typeof __VLS_export;
9
+ export default _default;