@conduction/nextcloud-vue 0.1.0-beta.3 → 0.1.0-beta.4

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 (152) hide show
  1. package/README.md +226 -226
  2. package/dist/nextcloud-vue.cjs.js +60455 -8755
  3. package/dist/nextcloud-vue.cjs.js.map +1 -1
  4. package/dist/nextcloud-vue.css +2062 -528
  5. package/dist/nextcloud-vue.esm.js +60411 -8731
  6. package/dist/nextcloud-vue.esm.js.map +1 -1
  7. package/package.json +75 -62
  8. package/src/components/CnActionsBar/CnActionsBar.vue +235 -225
  9. package/src/components/CnActionsBar/index.js +1 -1
  10. package/src/components/CnAdvancedFormDialog/CnAdvancedFormDialog.vue +579 -0
  11. package/src/components/CnAdvancedFormDialog/CnDataTab.vue +217 -0
  12. package/src/components/CnAdvancedFormDialog/CnMetadataTab.vue +121 -0
  13. package/src/components/CnAdvancedFormDialog/CnPropertiesTab.vue +418 -0
  14. package/src/components/CnAdvancedFormDialog/CnPropertyValueCell.vue +247 -0
  15. package/src/components/CnAdvancedFormDialog/index.js +1 -0
  16. package/src/components/CnCardGrid/CnCardGrid.vue +152 -152
  17. package/src/components/CnCardGrid/index.js +1 -1
  18. package/src/components/CnCellRenderer/CnCellRenderer.vue +132 -132
  19. package/src/components/CnCellRenderer/index.js +1 -1
  20. package/src/components/CnChartWidget/CnChartWidget.vue +320 -0
  21. package/src/components/CnChartWidget/index.js +1 -0
  22. package/src/components/CnConfigurationCard/CnConfigurationCard.vue +77 -77
  23. package/src/components/CnConfigurationCard/index.js +1 -1
  24. package/src/components/CnDashboardGrid/CnDashboardGrid.vue +225 -0
  25. package/src/components/CnDashboardGrid/index.js +1 -0
  26. package/src/components/CnDashboardPage/CnDashboardPage.vue +390 -0
  27. package/src/components/CnDashboardPage/index.js +1 -0
  28. package/src/components/CnDataTable/CnDataTable.vue +349 -349
  29. package/src/components/CnDataTable/index.js +1 -1
  30. package/src/components/CnDetailCard/CnDetailCard.vue +214 -0
  31. package/src/components/CnDetailCard/index.js +1 -0
  32. package/src/components/CnDetailPage/CnDetailPage.vue +281 -0
  33. package/src/components/CnDetailPage/index.js +1 -0
  34. package/src/components/CnFacetSidebar/CnFacetSidebar.vue +231 -223
  35. package/src/components/CnFacetSidebar/index.js +1 -1
  36. package/src/components/CnFilterBar/CnFilterBar.vue +152 -152
  37. package/src/components/CnFilterBar/index.js +1 -1
  38. package/src/components/CnIcon/CnIcon.vue +89 -89
  39. package/src/components/CnIcon/index.js +1 -1
  40. package/src/components/CnIndexPage/CnIndexPage.vue +874 -816
  41. package/src/components/CnIndexPage/index.js +1 -1
  42. package/src/components/CnIndexSidebar/CnIndexSidebar.vue +503 -484
  43. package/src/components/CnIndexSidebar/index.js +1 -1
  44. package/src/components/CnItemCard/CnItemCard.vue +132 -0
  45. package/src/components/CnItemCard/index.js +1 -0
  46. package/src/components/CnKpiGrid/CnKpiGrid.vue +89 -89
  47. package/src/components/CnKpiGrid/index.js +1 -1
  48. package/src/components/CnMassActionBar/CnMassActionBar.vue +160 -160
  49. package/src/components/CnMassActionBar/index.js +1 -1
  50. package/src/components/CnMassCopyDialog/CnMassCopyDialog.vue +320 -320
  51. package/src/components/CnMassCopyDialog/index.js +1 -1
  52. package/src/components/CnMassDeleteDialog/CnMassDeleteDialog.vue +238 -238
  53. package/src/components/CnMassDeleteDialog/index.js +1 -1
  54. package/src/components/CnMassExportDialog/CnMassExportDialog.vue +190 -190
  55. package/src/components/CnMassExportDialog/index.js +1 -1
  56. package/src/components/CnMassImportDialog/CnMassImportDialog.vue +491 -491
  57. package/src/components/CnMassImportDialog/index.js +1 -1
  58. package/src/components/CnNoteCard/CnNoteCard.vue +149 -0
  59. package/src/components/CnNoteCard/index.js +1 -0
  60. package/src/components/CnNotesCard/CnNotesCard.vue +413 -0
  61. package/src/components/CnNotesCard/index.js +1 -0
  62. package/src/components/CnObjectCard/CnObjectCard.vue +292 -292
  63. package/src/components/CnObjectCard/index.js +1 -1
  64. package/src/components/CnObjectSidebar/CnObjectSidebar.vue +876 -0
  65. package/src/components/CnObjectSidebar/index.js +1 -0
  66. package/src/components/CnPageHeader/CnPageHeader.vue +57 -57
  67. package/src/components/CnPageHeader/index.js +1 -1
  68. package/src/components/CnPagination/CnPagination.vue +252 -252
  69. package/src/components/CnPagination/index.js +1 -1
  70. package/src/components/CnRowActions/CnRowActions.vue +73 -73
  71. package/src/components/CnRowActions/index.js +1 -1
  72. package/src/components/CnSchemaFormDialog/CnSchemaConfigurationTab.vue +226 -0
  73. package/src/components/CnSchemaFormDialog/CnSchemaFormDialog.vue +787 -0
  74. package/src/components/CnSchemaFormDialog/CnSchemaPropertiesTab.vue +305 -0
  75. package/src/components/CnSchemaFormDialog/CnSchemaPropertyActions.vue +1398 -0
  76. package/src/components/CnSchemaFormDialog/CnSchemaSecurityTab.vue +236 -0
  77. package/src/components/CnSchemaFormDialog/index.js +1 -0
  78. package/src/components/CnSettingsCard/CnSettingsCard.vue +92 -92
  79. package/src/components/CnSettingsCard/index.js +1 -1
  80. package/src/components/CnSettingsSection/CnSettingsSection.vue +266 -266
  81. package/src/components/CnSettingsSection/index.js +1 -1
  82. package/src/components/CnStatsBlock/CnStatsBlock.vue +420 -366
  83. package/src/components/CnStatsBlock/index.js +1 -1
  84. package/src/components/CnStatusBadge/CnStatusBadge.vue +77 -77
  85. package/src/components/CnStatusBadge/index.js +1 -1
  86. package/src/components/CnTabbedFormDialog/CnTabbedFormDialog.vue +540 -0
  87. package/src/components/CnTabbedFormDialog/index.js +1 -0
  88. package/src/components/CnTasksCard/CnTasksCard.vue +373 -0
  89. package/src/components/CnTasksCard/index.js +1 -0
  90. package/src/components/CnTileWidget/CnTileWidget.vue +159 -0
  91. package/src/components/CnTileWidget/index.js +1 -0
  92. package/src/components/CnTimelineStages/CnTimelineStages.vue +292 -0
  93. package/src/components/CnTimelineStages/index.js +1 -0
  94. package/src/components/CnUserActionMenu/CnUserActionMenu.vue +435 -0
  95. package/src/components/CnUserActionMenu/index.js +1 -0
  96. package/src/components/CnVersionInfoCard/CnVersionInfoCard.vue +312 -312
  97. package/src/components/CnVersionInfoCard/index.js +1 -1
  98. package/src/components/CnWidgetRenderer/CnWidgetRenderer.vue +180 -0
  99. package/src/components/CnWidgetRenderer/index.js +1 -0
  100. package/src/components/CnWidgetWrapper/CnWidgetWrapper.vue +211 -0
  101. package/src/components/CnWidgetWrapper/index.js +1 -0
  102. package/src/components/index.js +43 -29
  103. package/src/composables/index.js +4 -3
  104. package/src/composables/useDashboardView.js +240 -0
  105. package/src/composables/useDetailView.js +289 -132
  106. package/src/composables/useListView.js +363 -362
  107. package/src/composables/useSubResource.js +142 -142
  108. package/src/constants/metadata.js +30 -30
  109. package/src/css/CnSchemaFormDialog.css +546 -0
  110. package/src/css/__sample_nextcloud_tokens.css +110 -0
  111. package/src/css/actions-bar.css +48 -48
  112. package/src/css/badge.css +51 -51
  113. package/src/css/card.css +128 -128
  114. package/src/css/dashboard.css +70 -0
  115. package/src/css/detail-page.css +168 -0
  116. package/src/css/detail.css +68 -68
  117. package/src/css/index-page.css +44 -32
  118. package/src/css/index-sidebar.css +193 -187
  119. package/src/css/index.css +16 -12
  120. package/src/css/layout.css +90 -90
  121. package/src/css/page-header.css +33 -33
  122. package/src/css/pagination.css +72 -72
  123. package/src/css/table.css +142 -142
  124. package/src/css/timeline-stages.css +218 -0
  125. package/src/css/utilities.css +46 -46
  126. package/src/index.js +72 -53
  127. package/src/store/createSubResourcePlugin.js +135 -135
  128. package/src/store/index.js +3 -3
  129. package/src/store/plugins/auditTrails.js +17 -17
  130. package/src/store/plugins/files.js +250 -186
  131. package/src/store/plugins/index.js +7 -5
  132. package/src/store/plugins/lifecycle.js +180 -180
  133. package/src/store/plugins/relations.js +68 -68
  134. package/src/store/plugins/search.js +372 -0
  135. package/src/store/plugins/selection.js +104 -0
  136. package/src/store/useObjectStore.js +829 -686
  137. package/src/types/auditTrail.d.ts +32 -32
  138. package/src/types/file.d.ts +23 -23
  139. package/src/types/index.d.ts +35 -35
  140. package/src/types/notification.d.ts +36 -36
  141. package/src/types/object.d.ts +40 -40
  142. package/src/types/organisation.d.ts +41 -41
  143. package/src/types/register.d.ts +25 -25
  144. package/src/types/schema.d.ts +39 -39
  145. package/src/types/shared.d.ts +79 -79
  146. package/src/types/source.d.ts +14 -14
  147. package/src/types/task.d.ts +31 -31
  148. package/src/utils/errors.js +96 -96
  149. package/src/utils/headers.js +68 -50
  150. package/src/utils/id.js +13 -0
  151. package/src/utils/index.js +3 -3
  152. package/src/utils/schema.js +422 -419
@@ -1,491 +1,491 @@
1
- <template>
2
- <NcDialog
3
- :name="dialogTitle"
4
- size="large"
5
- :can-close="!loading"
6
- @closing="$emit('close')">
7
- <!-- Success/error messages -->
8
- <NcNoteCard v-if="result && result.success && !hasErrors" type="success">
9
- {{ successText }}
10
- </NcNoteCard>
11
- <NcNoteCard v-if="result && result.success && hasErrors" type="warning">
12
- {{ partialSuccessText }}
13
- </NcNoteCard>
14
- <NcNoteCard v-if="result && result.error" type="error">
15
- {{ result.error }}
16
- </NcNoteCard>
17
-
18
- <!-- Results summary table -->
19
- <div v-if="result && result.summary" class="cn-mass-import__results">
20
- <h3>{{ summaryTitle }}</h3>
21
- <table class="cn-mass-import__summary-table">
22
- <thead>
23
- <tr>
24
- <th>{{ sheetLabel }}</th>
25
- <th>{{ foundLabel }}</th>
26
- <th>{{ createdLabel }}</th>
27
- <th>{{ updatedLabel }}</th>
28
- <th>{{ unchangedLabel }}</th>
29
- <th>{{ errorsLabel }}</th>
30
- </tr>
31
- </thead>
32
- <tbody>
33
- <template v-for="(sheet, key) in result.summary">
34
- <tr :key="key">
35
- <td class="cn-mass-import__sheet-name">{{ key }}</td>
36
- <td class="cn-mass-import__stat cn-mass-import__stat--found">
37
- {{ sheet.found || 0 }}
38
- </td>
39
- <td class="cn-mass-import__stat cn-mass-import__stat--created">
40
- {{ getCount(sheet.created) }}
41
- </td>
42
- <td class="cn-mass-import__stat cn-mass-import__stat--updated">
43
- {{ getCount(sheet.updated) }}
44
- </td>
45
- <td class="cn-mass-import__stat cn-mass-import__stat--unchanged">
46
- {{ getCount(sheet.unchanged) }}
47
- </td>
48
- <td class="cn-mass-import__stat cn-mass-import__stat--errors">
49
- <span>{{ getCount(sheet.errors) }}</span>
50
- <button
51
- v-if="getCount(sheet.errors) > 0"
52
- class="cn-mass-import__expand"
53
- :class="{ 'cn-mass-import__expand--open': expandedErrors[key] }"
54
- @click="toggleErrors(key)">
55
- <ChevronDown :size="16" />
56
- </button>
57
- </td>
58
- </tr>
59
- <!-- Error details row -->
60
- <tr
61
- v-if="expandedErrors[key] && sheet.errors && sheet.errors.length"
62
- :key="`${key}-errors`"
63
- class="cn-mass-import__error-row">
64
- <td colspan="6">
65
- <table class="cn-mass-import__error-table">
66
- <thead>
67
- <tr>
68
- <th>Row</th>
69
- <th>Type</th>
70
- <th>Message</th>
71
- </tr>
72
- </thead>
73
- <tbody>
74
- <tr v-for="(err, idx) in sheet.errors" :key="idx">
75
- <td>{{ err.row || '—' }}</td>
76
- <td>{{ err.type || 'Unknown' }}</td>
77
- <td>{{ err.error || err.message || '—' }}</td>
78
- </tr>
79
- </tbody>
80
- </table>
81
- </td>
82
- </tr>
83
- </template>
84
- </tbody>
85
- </table>
86
- </div>
87
-
88
- <!-- Upload form -->
89
- <div v-if="!result" class="cn-mass-import__form">
90
- <input
91
- ref="fileInput"
92
- type="file"
93
- :accept="acceptedTypes"
94
- style="display: none"
95
- @change="handleFileSelect">
96
-
97
- <div class="cn-mass-import__file-row">
98
- <NcButton @click="$refs.fileInput.click()">
99
- <template #icon>
100
- <Upload :size="20" />
101
- </template>
102
- {{ selectFileLabel }}
103
- </NcButton>
104
- <div v-if="selectedFile" class="cn-mass-import__file-info">
105
- <span class="cn-mass-import__file-name">{{ selectedFile.name }}</span>
106
- <span class="cn-mass-import__file-size">({{ formatFileSize(selectedFile.size) }})</span>
107
- </div>
108
- </div>
109
-
110
- <!-- Additional fields slot (e.g., register/schema selectors) -->
111
- <slot name="fields" :file="selectedFile" />
112
-
113
- <!-- File type help text -->
114
- <div v-if="fileTypeHelp" class="cn-mass-import__help">
115
- <p><strong>{{ supportedFormatsLabel }}</strong></p>
116
- <ul>
117
- <li v-for="(help, idx) in fileTypeHelp" :key="idx">
118
- <strong>{{ help.label }}</strong> — {{ help.description }}
119
- </li>
120
- </ul>
121
- </div>
122
-
123
- <!-- Import options -->
124
- <div v-if="options.length > 0" class="cn-mass-import__options">
125
- <NcCheckboxRadioSwitch
126
- v-for="opt in options"
127
- :key="opt.key"
128
- :checked="optionValues[opt.key]"
129
- type="switch"
130
- @update:checked="setOption(opt.key, $event)">
131
- {{ opt.label }}
132
- <template v-if="opt.description" #helper>
133
- {{ opt.description }}
134
- </template>
135
- </NcCheckboxRadioSwitch>
136
- </div>
137
- </div>
138
-
139
- <!-- Loading indicator -->
140
- <NcNoteCard v-if="loading" type="info">
141
- {{ loadingText }}
142
- </NcNoteCard>
143
-
144
- <template #actions>
145
- <NcButton @click="$emit('close')">
146
- {{ result ? closeLabel : cancelLabel }}
147
- </NcButton>
148
- <NcButton
149
- v-if="!result"
150
- type="primary"
151
- :disabled="loading || !selectedFile || !canSubmit"
152
- @click="executeImport">
153
- <template #icon>
154
- <NcLoadingIcon v-if="loading" :size="20" />
155
- <ImportIcon v-else :size="20" />
156
- </template>
157
- {{ confirmLabel }}
158
- </NcButton>
159
- </template>
160
- </NcDialog>
161
- </template>
162
-
163
- <script>
164
- import { NcDialog, NcButton, NcNoteCard, NcLoadingIcon, NcCheckboxRadioSwitch } from '@nextcloud/vue'
165
- import Upload from 'vue-material-design-icons/Upload.vue'
166
- import ImportIcon from 'vue-material-design-icons/Import.vue'
167
- import ChevronDown from 'vue-material-design-icons/ChevronDown.vue'
168
-
169
- /**
170
- * CnMassImportDialog — File import dialog with options and results summary.
171
- *
172
- * Supports file upload (JSON, Excel, CSV), configurable import options via
173
- * toggle switches, and a results summary table showing created/updated/error
174
- * counts per sheet. Based on the OpenRegister ImportRegister pattern.
175
- *
176
- * The dialog does NOT perform the import itself — it emits a `confirm` event
177
- * with the file and options. The parent handles the API call and calls
178
- * `setResult()` via a ref.
179
- *
180
- * @example
181
- * <CnMassImportDialog
182
- * v-if="showImportDialog"
183
- * ref="importDialog"
184
- * :options="importOptions"
185
- * @confirm="onImportConfirm"
186
- * @close="showImportDialog = false">
187
- * <template #fields="{ file }">
188
- * <NcSelect v-if="file" :options="schemas" @input="selectedSchema = $event" />
189
- * </template>
190
- * </CnMassImportDialog>
191
- *
192
- * // In data:
193
- * importOptions: [
194
- * { key: 'validation', label: 'Enable validation', description: 'Validate against schema', default: true },
195
- * { key: 'publish', label: 'Auto-publish', description: 'Set published date', default: false },
196
- * ]
197
- *
198
- * // In methods:
199
- * async onImportConfirm({ file, options }) {
200
- * try {
201
- * const formData = new FormData()
202
- * formData.append('file', file)
203
- * const result = await axios.post('/api/import', formData, { params: options })
204
- * this.$refs.importDialog.setResult({ success: true, summary: result.data.summary })
205
- * } catch (e) {
206
- * this.$refs.importDialog.setResult({ error: e.message })
207
- * }
208
- * }
209
- */
210
- export default {
211
- name: 'CnMassImportDialog',
212
-
213
- components: {
214
- NcDialog,
215
- NcButton,
216
- NcNoteCard,
217
- NcLoadingIcon,
218
- NcCheckboxRadioSwitch,
219
- Upload,
220
- ImportIcon,
221
- ChevronDown,
222
- },
223
-
224
- props: {
225
- /** Dialog title */
226
- dialogTitle: {
227
- type: String,
228
- default: 'Import Data',
229
- },
230
- /** Accepted file types (input accept attribute) */
231
- acceptedTypes: {
232
- type: String,
233
- default: '.json,.xlsx,.xls,.csv',
234
- },
235
- /** Import option definitions */
236
- options: {
237
- type: Array,
238
- default: () => [],
239
- },
240
- /** File type help entries */
241
- fileTypeHelp: {
242
- type: Array,
243
- default: () => [
244
- { label: 'JSON', description: 'Configuration and objects.' },
245
- { label: 'Excel (.xlsx, .xls)', description: 'Tabular objects data with multiple sheets.' },
246
- { label: 'CSV', description: 'Single table of objects data.' },
247
- ],
248
- },
249
- /** Whether the form is ready to submit (parent can control via slot logic) */
250
- canSubmit: {
251
- type: Boolean,
252
- default: true,
253
- },
254
- /** Success text when all rows imported without errors */
255
- successText: {
256
- type: String,
257
- default: 'Import completed successfully!',
258
- },
259
- /** Text when import partially succeeded */
260
- partialSuccessText: {
261
- type: String,
262
- default: 'Import completed with errors. Check the details below.',
263
- },
264
- /** Text shown while importing */
265
- loadingText: {
266
- type: String,
267
- default: 'Importing data — this may take a moment for large files...',
268
- },
269
- summaryTitle: { type: String, default: 'Import Summary' },
270
- supportedFormatsLabel: { type: String, default: 'Supported file types:' },
271
- selectFileLabel: { type: String, default: 'Select File' },
272
- cancelLabel: { type: String, default: 'Cancel' },
273
- closeLabel: { type: String, default: 'Close' },
274
- confirmLabel: { type: String, default: 'Import' },
275
- sheetLabel: { type: String, default: 'Sheet' },
276
- foundLabel: { type: String, default: 'Found' },
277
- createdLabel: { type: String, default: 'Created' },
278
- updatedLabel: { type: String, default: 'Updated' },
279
- unchangedLabel: { type: String, default: 'Unchanged' },
280
- errorsLabel: { type: String, default: 'Errors' },
281
- },
282
-
283
- data() {
284
- const optionValues = {}
285
- this.options.forEach((opt) => {
286
- optionValues[opt.key] = opt.default !== undefined ? opt.default : false
287
- })
288
- return {
289
- selectedFile: null,
290
- loading: false,
291
- result: null,
292
- optionValues,
293
- expandedErrors: {},
294
- }
295
- },
296
-
297
- computed: {
298
- hasErrors() {
299
- if (!this.result || !this.result.summary) return false
300
- return Object.values(this.result.summary).some(
301
- (sheet) => sheet.errors && sheet.errors.length > 0,
302
- )
303
- },
304
- },
305
-
306
- methods: {
307
- handleFileSelect(event) {
308
- const file = event.target.files[0]
309
- this.selectedFile = file || null
310
- },
311
-
312
- setOption(key, value) {
313
- this.$set(this.optionValues, key, value)
314
- },
315
-
316
- formatFileSize(bytes) {
317
- if (bytes === 0) return '0 B'
318
- const k = 1024
319
- const sizes = ['B', 'KB', 'MB', 'GB']
320
- const i = Math.floor(Math.log(bytes) / Math.log(k))
321
- return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]
322
- },
323
-
324
- getCount(val) {
325
- if (Array.isArray(val)) return val.length
326
- if (typeof val === 'number') return val
327
- return 0
328
- },
329
-
330
- toggleErrors(key) {
331
- this.$set(this.expandedErrors, key, !this.expandedErrors[key])
332
- },
333
-
334
- executeImport() {
335
- this.loading = true
336
- this.$emit('confirm', {
337
- file: this.selectedFile,
338
- options: { ...this.optionValues },
339
- })
340
- },
341
-
342
- /**
343
- * Set the result of the import operation.
344
- * @param {{ success?: boolean, error?: string, summary?: object }} resultData
345
- * @public
346
- */
347
- setResult(resultData) {
348
- this.loading = false
349
- this.result = resultData
350
- },
351
- },
352
- }
353
- </script>
354
-
355
- <style scoped>
356
- .cn-mass-import__form {
357
- display: flex;
358
- flex-direction: column;
359
- gap: 16px;
360
- }
361
-
362
- .cn-mass-import__file-row {
363
- display: flex;
364
- align-items: center;
365
- gap: 12px;
366
- }
367
-
368
- .cn-mass-import__file-info {
369
- display: flex;
370
- align-items: center;
371
- gap: 6px;
372
- }
373
-
374
- .cn-mass-import__file-name {
375
- font-weight: 500;
376
- }
377
-
378
- .cn-mass-import__file-size {
379
- color: var(--color-text-maxcontrast);
380
- font-size: 0.9em;
381
- }
382
-
383
- .cn-mass-import__help {
384
- padding: 12px;
385
- background: var(--color-background-hover);
386
- border-radius: var(--border-radius);
387
- }
388
-
389
- .cn-mass-import__help p {
390
- margin: 0 0 8px;
391
- }
392
-
393
- .cn-mass-import__help ul {
394
- margin: 0;
395
- padding-left: 20px;
396
- }
397
-
398
- .cn-mass-import__options {
399
- display: flex;
400
- flex-direction: column;
401
- gap: 12px;
402
- }
403
-
404
- /* Summary table */
405
- .cn-mass-import__results h3 {
406
- margin: 0 0 12px;
407
- font-size: 1.1rem;
408
- }
409
-
410
- .cn-mass-import__summary-table {
411
- width: 100%;
412
- border-collapse: collapse;
413
- border-radius: var(--border-radius);
414
- overflow: hidden;
415
- box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
416
- }
417
-
418
- .cn-mass-import__summary-table th,
419
- .cn-mass-import__summary-table td {
420
- padding: 8px 12px;
421
- text-align: left;
422
- border-bottom: 1px solid var(--color-border);
423
- }
424
-
425
- .cn-mass-import__summary-table th {
426
- background: var(--color-background-dark);
427
- font-weight: 600;
428
- font-size: 0.85rem;
429
- text-transform: uppercase;
430
- }
431
-
432
- .cn-mass-import__sheet-name {
433
- font-weight: 600;
434
- }
435
-
436
- .cn-mass-import__stat {
437
- text-align: center;
438
- font-weight: 600;
439
- }
440
-
441
- .cn-mass-import__stat--found { color: var(--color-primary-element); }
442
- .cn-mass-import__stat--created { color: var(--color-success); }
443
- .cn-mass-import__stat--updated { color: var(--color-warning); }
444
- .cn-mass-import__stat--unchanged { color: var(--color-text-maxcontrast); }
445
- .cn-mass-import__stat--errors { color: var(--color-error); }
446
-
447
- .cn-mass-import__expand {
448
- background: none;
449
- border: none;
450
- cursor: pointer;
451
- padding: 2px;
452
- border-radius: var(--border-radius-small, 4px);
453
- color: var(--color-error);
454
- transition: transform 0.2s ease;
455
- vertical-align: middle;
456
- margin-left: 4px;
457
- }
458
-
459
- .cn-mass-import__expand:hover {
460
- background: var(--color-background-hover);
461
- }
462
-
463
- .cn-mass-import__expand--open {
464
- transform: rotate(180deg);
465
- }
466
-
467
- /* Error details */
468
- .cn-mass-import__error-row td {
469
- padding: 8px 12px;
470
- background: var(--color-background-hover);
471
- }
472
-
473
- .cn-mass-import__error-table {
474
- width: 100%;
475
- border-collapse: collapse;
476
- font-size: 0.9em;
477
- }
478
-
479
- .cn-mass-import__error-table th,
480
- .cn-mass-import__error-table td {
481
- padding: 6px 10px;
482
- text-align: left;
483
- border-bottom: 1px solid var(--color-border);
484
- }
485
-
486
- .cn-mass-import__error-table th {
487
- background: var(--color-background-dark);
488
- font-weight: 600;
489
- font-size: 0.85rem;
490
- }
491
- </style>
1
+ <template>
2
+ <NcDialog
3
+ :name="dialogTitle"
4
+ size="large"
5
+ :can-close="!loading"
6
+ @closing="$emit('close')">
7
+ <!-- Success/error messages -->
8
+ <NcNoteCard v-if="result && result.success && !hasErrors" type="success">
9
+ {{ successText }}
10
+ </NcNoteCard>
11
+ <NcNoteCard v-if="result && result.success && hasErrors" type="warning">
12
+ {{ partialSuccessText }}
13
+ </NcNoteCard>
14
+ <NcNoteCard v-if="result && result.error" type="error">
15
+ {{ result.error }}
16
+ </NcNoteCard>
17
+
18
+ <!-- Results summary table -->
19
+ <div v-if="result && result.summary" class="cn-mass-import__results">
20
+ <h3>{{ summaryTitle }}</h3>
21
+ <table class="cn-mass-import__summary-table">
22
+ <thead>
23
+ <tr>
24
+ <th>{{ sheetLabel }}</th>
25
+ <th>{{ foundLabel }}</th>
26
+ <th>{{ createdLabel }}</th>
27
+ <th>{{ updatedLabel }}</th>
28
+ <th>{{ unchangedLabel }}</th>
29
+ <th>{{ errorsLabel }}</th>
30
+ </tr>
31
+ </thead>
32
+ <tbody>
33
+ <template v-for="(sheet, key) in result.summary">
34
+ <tr :key="key">
35
+ <td class="cn-mass-import__sheet-name">{{ key }}</td>
36
+ <td class="cn-mass-import__stat cn-mass-import__stat--found">
37
+ {{ sheet.found || 0 }}
38
+ </td>
39
+ <td class="cn-mass-import__stat cn-mass-import__stat--created">
40
+ {{ getCount(sheet.created) }}
41
+ </td>
42
+ <td class="cn-mass-import__stat cn-mass-import__stat--updated">
43
+ {{ getCount(sheet.updated) }}
44
+ </td>
45
+ <td class="cn-mass-import__stat cn-mass-import__stat--unchanged">
46
+ {{ getCount(sheet.unchanged) }}
47
+ </td>
48
+ <td class="cn-mass-import__stat cn-mass-import__stat--errors">
49
+ <span>{{ getCount(sheet.errors) }}</span>
50
+ <button
51
+ v-if="getCount(sheet.errors) > 0"
52
+ class="cn-mass-import__expand"
53
+ :class="{ 'cn-mass-import__expand--open': expandedErrors[key] }"
54
+ @click="toggleErrors(key)">
55
+ <ChevronDown :size="16" />
56
+ </button>
57
+ </td>
58
+ </tr>
59
+ <!-- Error details row -->
60
+ <tr
61
+ v-if="expandedErrors[key] && sheet.errors && sheet.errors.length"
62
+ :key="`${key}-errors`"
63
+ class="cn-mass-import__error-row">
64
+ <td colspan="6">
65
+ <table class="cn-mass-import__error-table">
66
+ <thead>
67
+ <tr>
68
+ <th>Row</th>
69
+ <th>Type</th>
70
+ <th>Message</th>
71
+ </tr>
72
+ </thead>
73
+ <tbody>
74
+ <tr v-for="(err, idx) in sheet.errors" :key="idx">
75
+ <td>{{ err.row || '—' }}</td>
76
+ <td>{{ err.type || 'Unknown' }}</td>
77
+ <td>{{ err.error || err.message || '—' }}</td>
78
+ </tr>
79
+ </tbody>
80
+ </table>
81
+ </td>
82
+ </tr>
83
+ </template>
84
+ </tbody>
85
+ </table>
86
+ </div>
87
+
88
+ <!-- Upload form -->
89
+ <div v-if="!result" class="cn-mass-import__form">
90
+ <input
91
+ ref="fileInput"
92
+ type="file"
93
+ :accept="acceptedTypes"
94
+ style="display: none"
95
+ @change="handleFileSelect">
96
+
97
+ <div class="cn-mass-import__file-row">
98
+ <NcButton @click="$refs.fileInput.click()">
99
+ <template #icon>
100
+ <Upload :size="20" />
101
+ </template>
102
+ {{ selectFileLabel }}
103
+ </NcButton>
104
+ <div v-if="selectedFile" class="cn-mass-import__file-info">
105
+ <span class="cn-mass-import__file-name">{{ selectedFile.name }}</span>
106
+ <span class="cn-mass-import__file-size">({{ formatFileSize(selectedFile.size) }})</span>
107
+ </div>
108
+ </div>
109
+
110
+ <!-- Additional fields slot (e.g., register/schema selectors) -->
111
+ <slot name="fields" :file="selectedFile" />
112
+
113
+ <!-- File type help text -->
114
+ <div v-if="fileTypeHelp" class="cn-mass-import__help">
115
+ <p><strong>{{ supportedFormatsLabel }}</strong></p>
116
+ <ul>
117
+ <li v-for="(help, idx) in fileTypeHelp" :key="idx">
118
+ <strong>{{ help.label }}</strong> — {{ help.description }}
119
+ </li>
120
+ </ul>
121
+ </div>
122
+
123
+ <!-- Import options -->
124
+ <div v-if="options.length > 0" class="cn-mass-import__options">
125
+ <NcCheckboxRadioSwitch
126
+ v-for="opt in options"
127
+ :key="opt.key"
128
+ :checked="optionValues[opt.key]"
129
+ type="switch"
130
+ @update:checked="setOption(opt.key, $event)">
131
+ {{ opt.label }}
132
+ <template v-if="opt.description" #helper>
133
+ {{ opt.description }}
134
+ </template>
135
+ </NcCheckboxRadioSwitch>
136
+ </div>
137
+ </div>
138
+
139
+ <!-- Loading indicator -->
140
+ <NcNoteCard v-if="loading" type="info">
141
+ {{ loadingText }}
142
+ </NcNoteCard>
143
+
144
+ <template #actions>
145
+ <NcButton @click="$emit('close')">
146
+ {{ result ? closeLabel : cancelLabel }}
147
+ </NcButton>
148
+ <NcButton
149
+ v-if="!result"
150
+ type="primary"
151
+ :disabled="loading || !selectedFile || !canSubmit"
152
+ @click="executeImport">
153
+ <template #icon>
154
+ <NcLoadingIcon v-if="loading" :size="20" />
155
+ <ImportIcon v-else :size="20" />
156
+ </template>
157
+ {{ confirmLabel }}
158
+ </NcButton>
159
+ </template>
160
+ </NcDialog>
161
+ </template>
162
+
163
+ <script>
164
+ import { NcDialog, NcButton, NcNoteCard, NcLoadingIcon, NcCheckboxRadioSwitch } from '@nextcloud/vue'
165
+ import Upload from 'vue-material-design-icons/Upload.vue'
166
+ import ImportIcon from 'vue-material-design-icons/Import.vue'
167
+ import ChevronDown from 'vue-material-design-icons/ChevronDown.vue'
168
+
169
+ /**
170
+ * CnMassImportDialog — File import dialog with options and results summary.
171
+ *
172
+ * Supports file upload (JSON, Excel, CSV), configurable import options via
173
+ * toggle switches, and a results summary table showing created/updated/error
174
+ * counts per sheet. Based on the OpenRegister ImportRegister pattern.
175
+ *
176
+ * The dialog does NOT perform the import itself — it emits a `confirm` event
177
+ * with the file and options. The parent handles the API call and calls
178
+ * `setResult()` via a ref.
179
+ *
180
+ * @example
181
+ * <CnMassImportDialog
182
+ * v-if="showImportDialog"
183
+ * ref="importDialog"
184
+ * :options="importOptions"
185
+ * @confirm="onImportConfirm"
186
+ * @close="showImportDialog = false">
187
+ * <template #fields="{ file }">
188
+ * <NcSelect v-if="file" :options="schemas" @input="selectedSchema = $event" />
189
+ * </template>
190
+ * </CnMassImportDialog>
191
+ *
192
+ * // In data:
193
+ * importOptions: [
194
+ * { key: 'validation', label: 'Enable validation', description: 'Validate against schema', default: true },
195
+ * { key: 'publish', label: 'Auto-publish', description: 'Set published date', default: false },
196
+ * ]
197
+ *
198
+ * // In methods:
199
+ * async onImportConfirm({ file, options }) {
200
+ * try {
201
+ * const formData = new FormData()
202
+ * formData.append('file', file)
203
+ * const result = await axios.post('/api/import', formData, { params: options })
204
+ * this.$refs.importDialog.setResult({ success: true, summary: result.data.summary })
205
+ * } catch (e) {
206
+ * this.$refs.importDialog.setResult({ error: e.message })
207
+ * }
208
+ * }
209
+ */
210
+ export default {
211
+ name: 'CnMassImportDialog',
212
+
213
+ components: {
214
+ NcDialog,
215
+ NcButton,
216
+ NcNoteCard,
217
+ NcLoadingIcon,
218
+ NcCheckboxRadioSwitch,
219
+ Upload,
220
+ ImportIcon,
221
+ ChevronDown,
222
+ },
223
+
224
+ props: {
225
+ /** Dialog title */
226
+ dialogTitle: {
227
+ type: String,
228
+ default: 'Import Data',
229
+ },
230
+ /** Accepted file types (input accept attribute) */
231
+ acceptedTypes: {
232
+ type: String,
233
+ default: '.json,.xlsx,.xls,.csv',
234
+ },
235
+ /** Import option definitions */
236
+ options: {
237
+ type: Array,
238
+ default: () => [],
239
+ },
240
+ /** File type help entries */
241
+ fileTypeHelp: {
242
+ type: Array,
243
+ default: () => [
244
+ { label: 'JSON', description: 'Configuration and objects.' },
245
+ { label: 'Excel (.xlsx, .xls)', description: 'Tabular objects data with multiple sheets.' },
246
+ { label: 'CSV', description: 'Single table of objects data.' },
247
+ ],
248
+ },
249
+ /** Whether the form is ready to submit (parent can control via slot logic) */
250
+ canSubmit: {
251
+ type: Boolean,
252
+ default: true,
253
+ },
254
+ /** Success text when all rows imported without errors */
255
+ successText: {
256
+ type: String,
257
+ default: 'Import completed successfully!',
258
+ },
259
+ /** Text when import partially succeeded */
260
+ partialSuccessText: {
261
+ type: String,
262
+ default: 'Import completed with errors. Check the details below.',
263
+ },
264
+ /** Text shown while importing */
265
+ loadingText: {
266
+ type: String,
267
+ default: 'Importing data — this may take a moment for large files...',
268
+ },
269
+ summaryTitle: { type: String, default: 'Import Summary' },
270
+ supportedFormatsLabel: { type: String, default: 'Supported file types:' },
271
+ selectFileLabel: { type: String, default: 'Select File' },
272
+ cancelLabel: { type: String, default: 'Cancel' },
273
+ closeLabel: { type: String, default: 'Close' },
274
+ confirmLabel: { type: String, default: 'Import' },
275
+ sheetLabel: { type: String, default: 'Sheet' },
276
+ foundLabel: { type: String, default: 'Found' },
277
+ createdLabel: { type: String, default: 'Created' },
278
+ updatedLabel: { type: String, default: 'Updated' },
279
+ unchangedLabel: { type: String, default: 'Unchanged' },
280
+ errorsLabel: { type: String, default: 'Errors' },
281
+ },
282
+
283
+ data() {
284
+ const optionValues = {}
285
+ this.options.forEach((opt) => {
286
+ optionValues[opt.key] = opt.default !== undefined ? opt.default : false
287
+ })
288
+ return {
289
+ selectedFile: null,
290
+ loading: false,
291
+ result: null,
292
+ optionValues,
293
+ expandedErrors: {},
294
+ }
295
+ },
296
+
297
+ computed: {
298
+ hasErrors() {
299
+ if (!this.result || !this.result.summary) return false
300
+ return Object.values(this.result.summary).some(
301
+ (sheet) => sheet.errors && sheet.errors.length > 0,
302
+ )
303
+ },
304
+ },
305
+
306
+ methods: {
307
+ handleFileSelect(event) {
308
+ const file = event.target.files[0]
309
+ this.selectedFile = file || null
310
+ },
311
+
312
+ setOption(key, value) {
313
+ this.$set(this.optionValues, key, value)
314
+ },
315
+
316
+ formatFileSize(bytes) {
317
+ if (bytes === 0) return '0 B'
318
+ const k = 1024
319
+ const sizes = ['B', 'KB', 'MB', 'GB']
320
+ const i = Math.floor(Math.log(bytes) / Math.log(k))
321
+ return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]
322
+ },
323
+
324
+ getCount(val) {
325
+ if (Array.isArray(val)) return val.length
326
+ if (typeof val === 'number') return val
327
+ return 0
328
+ },
329
+
330
+ toggleErrors(key) {
331
+ this.$set(this.expandedErrors, key, !this.expandedErrors[key])
332
+ },
333
+
334
+ executeImport() {
335
+ this.loading = true
336
+ this.$emit('confirm', {
337
+ file: this.selectedFile,
338
+ options: { ...this.optionValues },
339
+ })
340
+ },
341
+
342
+ /**
343
+ * Set the result of the import operation.
344
+ * @param {{ success?: boolean, error?: string, summary?: object }} resultData
345
+ * @public
346
+ */
347
+ setResult(resultData) {
348
+ this.loading = false
349
+ this.result = resultData
350
+ },
351
+ },
352
+ }
353
+ </script>
354
+
355
+ <style scoped>
356
+ .cn-mass-import__form {
357
+ display: flex;
358
+ flex-direction: column;
359
+ gap: 16px;
360
+ }
361
+
362
+ .cn-mass-import__file-row {
363
+ display: flex;
364
+ align-items: center;
365
+ gap: 12px;
366
+ }
367
+
368
+ .cn-mass-import__file-info {
369
+ display: flex;
370
+ align-items: center;
371
+ gap: 6px;
372
+ }
373
+
374
+ .cn-mass-import__file-name {
375
+ font-weight: 500;
376
+ }
377
+
378
+ .cn-mass-import__file-size {
379
+ color: var(--color-text-maxcontrast);
380
+ font-size: 0.9em;
381
+ }
382
+
383
+ .cn-mass-import__help {
384
+ padding: 12px;
385
+ background: var(--color-background-hover);
386
+ border-radius: var(--border-radius);
387
+ }
388
+
389
+ .cn-mass-import__help p {
390
+ margin: 0 0 8px;
391
+ }
392
+
393
+ .cn-mass-import__help ul {
394
+ margin: 0;
395
+ padding-left: 20px;
396
+ }
397
+
398
+ .cn-mass-import__options {
399
+ display: flex;
400
+ flex-direction: column;
401
+ gap: 12px;
402
+ }
403
+
404
+ /* Summary table */
405
+ .cn-mass-import__results h3 {
406
+ margin: 0 0 12px;
407
+ font-size: 1.1rem;
408
+ }
409
+
410
+ .cn-mass-import__summary-table {
411
+ width: 100%;
412
+ border-collapse: collapse;
413
+ border-radius: var(--border-radius);
414
+ overflow: hidden;
415
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
416
+ }
417
+
418
+ .cn-mass-import__summary-table th,
419
+ .cn-mass-import__summary-table td {
420
+ padding: 8px 12px;
421
+ text-align: left;
422
+ border-bottom: 1px solid var(--color-border);
423
+ }
424
+
425
+ .cn-mass-import__summary-table th {
426
+ background: var(--color-background-dark);
427
+ font-weight: 600;
428
+ font-size: 0.85rem;
429
+ text-transform: uppercase;
430
+ }
431
+
432
+ .cn-mass-import__sheet-name {
433
+ font-weight: 600;
434
+ }
435
+
436
+ .cn-mass-import__stat {
437
+ text-align: center;
438
+ font-weight: 600;
439
+ }
440
+
441
+ .cn-mass-import__stat--found { color: var(--color-primary-element); }
442
+ .cn-mass-import__stat--created { color: var(--color-success); }
443
+ .cn-mass-import__stat--updated { color: var(--color-warning); }
444
+ .cn-mass-import__stat--unchanged { color: var(--color-text-maxcontrast); }
445
+ .cn-mass-import__stat--errors { color: var(--color-error); }
446
+
447
+ .cn-mass-import__expand {
448
+ background: none;
449
+ border: none;
450
+ cursor: pointer;
451
+ padding: 2px;
452
+ border-radius: var(--border-radius-small, 4px);
453
+ color: var(--color-error);
454
+ transition: transform 0.2s ease;
455
+ vertical-align: middle;
456
+ margin-left: 4px;
457
+ }
458
+
459
+ .cn-mass-import__expand:hover {
460
+ background: var(--color-background-hover);
461
+ }
462
+
463
+ .cn-mass-import__expand--open {
464
+ transform: rotate(180deg);
465
+ }
466
+
467
+ /* Error details */
468
+ .cn-mass-import__error-row td {
469
+ padding: 8px 12px;
470
+ background: var(--color-background-hover);
471
+ }
472
+
473
+ .cn-mass-import__error-table {
474
+ width: 100%;
475
+ border-collapse: collapse;
476
+ font-size: 0.9em;
477
+ }
478
+
479
+ .cn-mass-import__error-table th,
480
+ .cn-mass-import__error-table td {
481
+ padding: 6px 10px;
482
+ text-align: left;
483
+ border-bottom: 1px solid var(--color-border);
484
+ }
485
+
486
+ .cn-mass-import__error-table th {
487
+ background: var(--color-background-dark);
488
+ font-weight: 600;
489
+ font-size: 0.85rem;
490
+ }
491
+ </style>