@conduction/nextcloud-vue 0.1.0-beta.11 → 0.1.0-beta.12

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 (78) hide show
  1. package/dist/nextcloud-vue.cjs +67614 -0
  2. package/dist/nextcloud-vue.cjs.js +13518 -13617
  3. package/dist/nextcloud-vue.cjs.js.map +1 -1
  4. package/dist/nextcloud-vue.cjs.map +1 -0
  5. package/dist/nextcloud-vue.css +1796 -1800
  6. package/dist/nextcloud-vue.esm.js +13518 -13617
  7. package/dist/nextcloud-vue.esm.js.map +1 -1
  8. package/package.json +3 -2
  9. package/src/components/CnActionsBar/CnActionsBar.vue +254 -254
  10. package/src/components/CnAdvancedFormDialog/CnAdvancedFormDialog.vue +570 -570
  11. package/src/components/CnAdvancedFormDialog/CnDataTab.vue +217 -217
  12. package/src/components/CnAdvancedFormDialog/CnMetadataTab.vue +121 -121
  13. package/src/components/CnAdvancedFormDialog/CnPropertiesTab.vue +422 -422
  14. package/src/components/CnAdvancedFormDialog/CnPropertyValueCell.vue +247 -247
  15. package/src/components/CnCard/CnCard.vue +415 -415
  16. package/src/components/CnCardGrid/CnCardGrid.vue +156 -156
  17. package/src/components/CnCellRenderer/CnCellRenderer.vue +132 -132
  18. package/src/components/CnChartWidget/CnChartWidget.vue +346 -346
  19. package/src/components/CnConfigurationCard/CnConfigurationCard.vue +77 -77
  20. package/src/components/CnContextMenu/CnContextMenu.vue +142 -142
  21. package/src/components/CnCopyDialog/CnCopyDialog.vue +266 -266
  22. package/src/components/CnDashboardGrid/CnDashboardGrid.vue +229 -229
  23. package/src/components/CnDashboardPage/CnDashboardPage.vue +397 -397
  24. package/src/components/CnDataTable/CnDataTable.vue +362 -362
  25. package/src/components/CnDeleteDialog/CnDeleteDialog.vue +177 -177
  26. package/src/components/CnDetailCard/CnDetailCard.vue +225 -225
  27. package/src/components/CnDetailGrid/CnDetailGrid.vue +256 -256
  28. package/src/components/CnDetailPage/CnDetailPage.vue +432 -432
  29. package/src/components/CnFacetSidebar/CnFacetSidebar.vue +234 -234
  30. package/src/components/CnFilterBar/CnFilterBar.vue +153 -153
  31. package/src/components/CnFormDialog/CnFormDialog.vue +1047 -1047
  32. package/src/components/CnIcon/CnIcon.vue +89 -89
  33. package/src/components/CnIndexPage/CnIndexPage.vue +981 -980
  34. package/src/components/CnIndexSidebar/CnIndexSidebar.vue +536 -536
  35. package/src/components/CnInfoWidget/CnInfoWidget.vue +219 -219
  36. package/src/components/CnItemCard/CnItemCard.vue +134 -134
  37. package/src/components/CnJsonViewer/CnJsonViewer.vue +312 -312
  38. package/src/components/CnKpiGrid/CnKpiGrid.vue +93 -93
  39. package/src/components/CnMassActionBar/CnMassActionBar.vue +161 -161
  40. package/src/components/CnMassCopyDialog/CnMassCopyDialog.vue +327 -327
  41. package/src/components/CnMassDeleteDialog/CnMassDeleteDialog.vue +245 -245
  42. package/src/components/CnMassExportDialog/CnMassExportDialog.vue +191 -191
  43. package/src/components/CnMassImportDialog/CnMassImportDialog.vue +494 -494
  44. package/src/components/CnNoteCard/CnNoteCard.vue +149 -149
  45. package/src/components/CnNotesCard/CnNotesCard.vue +416 -416
  46. package/src/components/CnObjectCard/CnObjectCard.vue +294 -294
  47. package/src/components/CnObjectDataWidget/CnObjectDataWidget.vue +854 -854
  48. package/src/components/CnObjectMetadataWidget/CnObjectMetadataWidget.vue +289 -289
  49. package/src/components/CnObjectSidebar/CnAuditTrailTab.vue +369 -369
  50. package/src/components/CnObjectSidebar/CnFilesTab.vue +287 -287
  51. package/src/components/CnObjectSidebar/CnNotesTab.vue +250 -250
  52. package/src/components/CnObjectSidebar/CnObjectSidebar.vue +255 -255
  53. package/src/components/CnObjectSidebar/CnTagsTab.vue +259 -259
  54. package/src/components/CnObjectSidebar/CnTasksTab.vue +483 -483
  55. package/src/components/CnPageHeader/CnPageHeader.vue +61 -61
  56. package/src/components/CnPagination/CnPagination.vue +253 -253
  57. package/src/components/CnProgressBar/CnProgressBar.vue +262 -262
  58. package/src/components/CnRegisterMapping/CnRegisterMapping.vue +793 -793
  59. package/src/components/CnRowActions/CnRowActions.vue +95 -95
  60. package/src/components/CnSchemaFormDialog/CnSchemaConfigurationTab.vue +226 -226
  61. package/src/components/CnSchemaFormDialog/CnSchemaFormDialog.vue +788 -788
  62. package/src/components/CnSchemaFormDialog/CnSchemaPropertiesTab.vue +305 -305
  63. package/src/components/CnSchemaFormDialog/CnSchemaPropertyActions.vue +1398 -1398
  64. package/src/components/CnSchemaFormDialog/CnSchemaSecurityTab.vue +236 -236
  65. package/src/components/CnSettingsCard/CnSettingsCard.vue +92 -92
  66. package/src/components/CnSettingsSection/CnSettingsSection.vue +267 -267
  67. package/src/components/CnStatsBlock/CnStatsBlock.vue +437 -437
  68. package/src/components/CnStatsPanel/CnStatsPanel.vue +321 -321
  69. package/src/components/CnStatusBadge/CnStatusBadge.vue +90 -90
  70. package/src/components/CnTabbedFormDialog/CnTabbedFormDialog.vue +545 -545
  71. package/src/components/CnTableWidget/CnTableWidget.vue +333 -333
  72. package/src/components/CnTasksCard/CnTasksCard.vue +374 -374
  73. package/src/components/CnTileWidget/CnTileWidget.vue +159 -159
  74. package/src/components/CnTimelineStages/CnTimelineStages.vue +294 -294
  75. package/src/components/CnUserActionMenu/CnUserActionMenu.vue +436 -436
  76. package/src/components/CnVersionInfoCard/CnVersionInfoCard.vue +313 -313
  77. package/src/components/CnWidgetRenderer/CnWidgetRenderer.vue +180 -180
  78. package/src/components/CnWidgetWrapper/CnWidgetWrapper.vue +248 -248
@@ -1,436 +1,436 @@
1
- <!--
2
- CnUserActionMenu — Popover menu triggered by clicking a user name.
3
-
4
- Shows avatar, display name, and contextual actions (message, chat, email, meeting)
5
- based on which Nextcloud apps are installed (Talk, Mail, Calendar).
6
- -->
7
- <template>
8
- <span class="cn-user-action-menu">
9
- <span
10
- ref="trigger"
11
- class="cn-user-action-menu__trigger"
12
- :class="{ 'cn-user-action-menu__trigger--interactive': interactive }"
13
- role="button"
14
- :tabindex="interactive ? 0 : -1"
15
- :aria-haspopup="interactive ? 'menu' : undefined"
16
- @click="interactive && openMenu()"
17
- @keydown.enter.prevent="interactive && openMenu()"
18
- @keydown.space.prevent="interactive && openMenu()">
19
- <slot>{{ displayName }}</slot>
20
- </span>
21
-
22
- <NcPopover
23
- v-if="interactive"
24
- :shown.sync="isOpen"
25
- :trigger="triggerElements"
26
- placement="bottom-start"
27
- @after-hide="onClose">
28
- <div
29
- class="cn-user-action-menu__popover"
30
- role="menu"
31
- :aria-label="'Actions for ' + displayName"
32
- @keydown.escape.prevent="closeMenu">
33
- <!-- User info header -->
34
- <div class="cn-user-action-menu__header">
35
- <NcAvatar
36
- :user="userId"
37
- :display-name="displayName"
38
- :size="36"
39
- :show-user-status="false" />
40
- <div class="cn-user-action-menu__user-info">
41
- <span class="cn-user-action-menu__display-name">{{ displayName }}</span>
42
- <span v-if="userEmail" class="cn-user-action-menu__email">{{ userEmail }}</span>
43
- </div>
44
- </div>
45
-
46
- <!-- Action buttons -->
47
- <div class="cn-user-action-menu__actions">
48
- <NcActionButton
49
- v-if="hasTalk"
50
- role="menuitem"
51
- @click="sendMessage">
52
- <template #icon>
53
- <MessageTextOutline :size="20" />
54
- </template>
55
- {{ sendMessageLabel }}
56
- </NcActionButton>
57
-
58
- <NcActionButton
59
- v-if="hasTalk"
60
- role="menuitem"
61
- @click="startChat">
62
- <template #icon>
63
- <ChatOutline :size="20" />
64
- </template>
65
- {{ startChatLabel }}
66
- </NcActionButton>
67
-
68
- <NcActionButton
69
- v-if="showEmailAction"
70
- role="menuitem"
71
- @click="sendEmail">
72
- <template #icon>
73
- <EmailOutline :size="20" />
74
- </template>
75
- {{ sendEmailLabel }}
76
- </NcActionButton>
77
-
78
- <NcActionButton
79
- v-if="hasCalendar"
80
- role="menuitem"
81
- @click="planMeeting">
82
- <template #icon>
83
- <CalendarOutline :size="20" />
84
- </template>
85
- {{ planMeetingLabel }}
86
- </NcActionButton>
87
-
88
- <div
89
- v-if="!hasTalk && !showEmailAction && !hasCalendar"
90
- class="cn-user-action-menu__no-actions">
91
- {{ noActionsLabel }}
92
- </div>
93
- </div>
94
- </div>
95
- </NcPopover>
96
- </span>
97
- </template>
98
-
99
- <script>
100
- import { translate as t } from '@nextcloud/l10n'
101
- import { NcPopover, NcActionButton, NcAvatar } from '@nextcloud/vue'
102
-
103
- import MessageTextOutline from 'vue-material-design-icons/MessageTextOutline.vue'
104
- import ChatOutline from 'vue-material-design-icons/ChatOutline.vue'
105
- import EmailOutline from 'vue-material-design-icons/EmailOutline.vue'
106
- import CalendarOutline from 'vue-material-design-icons/CalendarOutline.vue'
107
-
108
- import { buildHeaders } from '../../utils/index.js'
109
-
110
- // Module-level capabilities cache (shared across all instances, fetched once per session)
111
- let _capabilitiesCache = null
112
- let _capabilitiesPromise = null
113
-
114
- /**
115
- * CnUserActionMenu — Popover with user communication actions.
116
- *
117
- * Shows contextual actions based on installed Nextcloud apps (Talk, Mail, Calendar).
118
- * Uses @nextcloud/capabilities when available, falls back to OCS API.
119
- *
120
- * @example Usage in notes/tasks cards
121
- * <CnUserActionMenu
122
- * :user-id="note.actorId || note.author"
123
- * :display-name="note.actorDisplayName || note.author || 'Unknown'" />
124
- */
125
- export default {
126
- name: 'CnUserActionMenu',
127
-
128
- components: {
129
- NcPopover,
130
- NcActionButton,
131
- NcAvatar,
132
- MessageTextOutline,
133
- ChatOutline,
134
- EmailOutline,
135
- CalendarOutline,
136
- },
137
-
138
- props: {
139
- /** The Nextcloud user ID */
140
- userId: {
141
- type: String,
142
- required: true,
143
- },
144
- /** The user's display name */
145
- displayName: {
146
- type: String,
147
- default: () => t('nextcloud-vue', 'Unknown'),
148
- },
149
- /** Whether the menu is interactive (false for current user or system accounts) */
150
- interactive: {
151
- type: Boolean,
152
- default: true,
153
- },
154
-
155
- // --- Pre-translated labels ---
156
- sendMessageLabel: { type: String, default: () => t('nextcloud-vue', 'Send message') },
157
- startChatLabel: { type: String, default: () => t('nextcloud-vue', 'Start chat') },
158
- sendEmailLabel: { type: String, default: () => t('nextcloud-vue', 'Send email') },
159
- planMeetingLabel: { type: String, default: () => t('nextcloud-vue', 'Schedule meeting') },
160
- noActionsLabel: { type: String, default: () => t('nextcloud-vue', 'No communication apps available') },
161
- },
162
-
163
- emits: ['action'],
164
-
165
- data() {
166
- return {
167
- isOpen: false,
168
- hasTalk: false,
169
- hasMail: false,
170
- hasCalendar: false,
171
- userEmail: '',
172
- emailResolved: false,
173
- triggerElements: [],
174
- }
175
- },
176
-
177
- computed: {
178
- showEmailAction() {
179
- return !!this.userEmail
180
- },
181
- },
182
-
183
- mounted() {
184
- this.triggerElements = [this.$refs.trigger]
185
- this.detectCapabilities()
186
- },
187
-
188
- methods: {
189
- openMenu() {
190
- if (!this.interactive) return
191
- this.isOpen = true
192
- // Resolve email on first open if not yet done
193
- if (!this.emailResolved) {
194
- this.resolveUserEmail()
195
- }
196
- },
197
-
198
- closeMenu() {
199
- this.isOpen = false
200
- },
201
-
202
- onClose() {
203
- this.isOpen = false
204
- // Return focus to trigger
205
- if (this.$refs.trigger) {
206
- this.$refs.trigger.focus()
207
- }
208
- },
209
-
210
- async detectCapabilities() {
211
- if (_capabilitiesCache) {
212
- this.applyCapabilities(_capabilitiesCache)
213
- return
214
- }
215
-
216
- // Try @nextcloud/capabilities first (synchronous, from initial state)
217
- try {
218
- // eslint-disable-next-line n/no-missing-import
219
- const { getCapabilities } = await import('@nextcloud/capabilities')
220
- const caps = getCapabilities()
221
- if (caps) {
222
- _capabilitiesCache = caps
223
- this.applyCapabilities(caps)
224
- return
225
- }
226
- } catch {
227
- // Package not available, fall back to API
228
- }
229
-
230
- // Fallback: fetch from OCS API (once per session)
231
- if (!_capabilitiesPromise) {
232
- _capabilitiesPromise = this.fetchCapabilities()
233
- }
234
- const caps = await _capabilitiesPromise
235
- if (caps) {
236
- _capabilitiesCache = caps
237
- this.applyCapabilities(caps)
238
- }
239
- },
240
-
241
- async fetchCapabilities() {
242
- try {
243
- const response = await fetch('/ocs/v2.php/cloud/capabilities?format=json', {
244
- headers: buildHeaders(),
245
- })
246
- if (response.ok) {
247
- const data = await response.json()
248
- return data?.ocs?.data?.capabilities || {}
249
- }
250
- } catch (err) {
251
- console.error('CnUserActionMenu: Failed to fetch capabilities', err)
252
- }
253
- return {}
254
- },
255
-
256
- applyCapabilities(caps) {
257
- this.hasTalk = !!caps?.spreed
258
- this.hasCalendar = !!caps?.dav
259
- this.hasMail = !!caps?.mail
260
- },
261
-
262
- async resolveUserEmail() {
263
- this.emailResolved = true
264
- try {
265
- const response = await fetch(
266
- `/ocs/v2.php/cloud/users/${encodeURIComponent(this.userId)}?format=json`,
267
- {
268
- headers: {
269
- ...buildHeaders(),
270
- 'OCS-APIREQUEST': 'true',
271
- },
272
- },
273
- )
274
- if (response.ok) {
275
- const data = await response.json()
276
- this.userEmail = data?.ocs?.data?.email || ''
277
- }
278
- } catch (err) {
279
- console.error('CnUserActionMenu: Failed to resolve user email', err)
280
- this.userEmail = ''
281
- }
282
- },
283
-
284
- async sendMessage() {
285
- try {
286
- const response = await fetch('/ocs/v2.php/apps/spreed/api/v4/room', {
287
- method: 'POST',
288
- headers: {
289
- ...buildHeaders(),
290
- 'OCS-APIREQUEST': 'true',
291
- 'Content-Type': 'application/json',
292
- },
293
- body: JSON.stringify({ roomType: 1, invite: this.userId }),
294
- })
295
- if (response.ok) {
296
- const data = await response.json()
297
- const token = data?.ocs?.data?.token
298
- if (token) {
299
- window.location.href = `/apps/spreed/#/call/${token}`
300
- }
301
- } else {
302
- this.showActionError('Failed to create conversation')
303
- }
304
- } catch (err) {
305
- console.error('CnUserActionMenu: Failed to send message', err)
306
- this.showActionError('Failed to create conversation')
307
- }
308
- this.$emit('action', { type: 'message', userId: this.userId })
309
- },
310
-
311
- async startChat() {
312
- try {
313
- const response = await fetch('/ocs/v2.php/apps/spreed/api/v4/room', {
314
- method: 'POST',
315
- headers: {
316
- ...buildHeaders(),
317
- 'OCS-APIREQUEST': 'true',
318
- 'Content-Type': 'application/json',
319
- },
320
- body: JSON.stringify({ roomType: 1, invite: this.userId }),
321
- })
322
- if (response.ok) {
323
- const data = await response.json()
324
- const token = data?.ocs?.data?.token
325
- if (token) {
326
- window.open(`/apps/spreed/#/call/${token}`, '_blank')
327
- }
328
- } else {
329
- this.showActionError('Failed to create conversation')
330
- }
331
- } catch (err) {
332
- console.error('CnUserActionMenu: Failed to start chat', err)
333
- this.showActionError('Failed to create conversation')
334
- }
335
- this.$emit('action', { type: 'chat', userId: this.userId })
336
- },
337
-
338
- sendEmail() {
339
- if (!this.userEmail) return
340
- if (this.hasMail) {
341
- window.location.href = `/apps/mail/compose?to=${encodeURIComponent(this.userEmail)}`
342
- } else {
343
- window.location.href = `mailto:${this.userEmail}`
344
- }
345
- this.closeMenu()
346
- this.$emit('action', { type: 'email', userId: this.userId })
347
- },
348
-
349
- planMeeting() {
350
- window.location.href = `/apps/calendar/new?attendees=${encodeURIComponent(this.userId)}&title=Meeting`
351
- this.closeMenu()
352
- this.$emit('action', { type: 'meeting', userId: this.userId })
353
- },
354
-
355
- showActionError(message) {
356
- try {
357
- // eslint-disable-next-line n/no-missing-import
358
- import('@nextcloud/dialogs').then(({ showError }) => {
359
- showError(message)
360
- })
361
- } catch {
362
- console.error(message)
363
- }
364
- },
365
- },
366
- }
367
- </script>
368
-
369
- <style scoped>
370
- .cn-user-action-menu {
371
- display: inline;
372
- }
373
-
374
- .cn-user-action-menu__trigger--interactive {
375
- cursor: pointer;
376
- color: var(--color-primary-element);
377
- font-weight: 600;
378
- }
379
-
380
- .cn-user-action-menu__trigger--interactive:hover {
381
- text-decoration: underline;
382
- }
383
-
384
- .cn-user-action-menu__trigger--interactive:focus-visible {
385
- outline: 2px solid var(--color-primary-element);
386
- outline-offset: 2px;
387
- border-radius: var(--border-radius);
388
- }
389
-
390
- .cn-user-action-menu__popover {
391
- min-width: 220px;
392
- padding: 8px 0;
393
- }
394
-
395
- .cn-user-action-menu__header {
396
- display: flex;
397
- align-items: center;
398
- gap: 10px;
399
- padding: 8px 12px 12px;
400
- border-bottom: 1px solid var(--color-border);
401
- margin-bottom: 4px;
402
- }
403
-
404
- .cn-user-action-menu__user-info {
405
- display: flex;
406
- flex-direction: column;
407
- min-width: 0;
408
- }
409
-
410
- .cn-user-action-menu__display-name {
411
- font-weight: 600;
412
- font-size: 14px;
413
- white-space: nowrap;
414
- overflow: hidden;
415
- text-overflow: ellipsis;
416
- }
417
-
418
- .cn-user-action-menu__email {
419
- font-size: 12px;
420
- color: var(--color-text-maxcontrast);
421
- white-space: nowrap;
422
- overflow: hidden;
423
- text-overflow: ellipsis;
424
- }
425
-
426
- .cn-user-action-menu__actions {
427
- padding: 4px 0;
428
- }
429
-
430
- .cn-user-action-menu__no-actions {
431
- padding: 12px 16px;
432
- text-align: center;
433
- color: var(--color-text-maxcontrast);
434
- font-size: 13px;
435
- }
436
- </style>
1
+ <!--
2
+ CnUserActionMenu — Popover menu triggered by clicking a user name.
3
+
4
+ Shows avatar, display name, and contextual actions (message, chat, email, meeting)
5
+ based on which Nextcloud apps are installed (Talk, Mail, Calendar).
6
+ -->
7
+ <template>
8
+ <span class="cn-user-action-menu">
9
+ <span
10
+ ref="trigger"
11
+ class="cn-user-action-menu__trigger"
12
+ :class="{ 'cn-user-action-menu__trigger--interactive': interactive }"
13
+ role="button"
14
+ :tabindex="interactive ? 0 : -1"
15
+ :aria-haspopup="interactive ? 'menu' : undefined"
16
+ @click="interactive && openMenu()"
17
+ @keydown.enter.prevent="interactive && openMenu()"
18
+ @keydown.space.prevent="interactive && openMenu()">
19
+ <slot>{{ displayName }}</slot>
20
+ </span>
21
+
22
+ <NcPopover
23
+ v-if="interactive"
24
+ :shown.sync="isOpen"
25
+ :trigger="triggerElements"
26
+ placement="bottom-start"
27
+ @after-hide="onClose">
28
+ <div
29
+ class="cn-user-action-menu__popover"
30
+ role="menu"
31
+ :aria-label="'Actions for ' + displayName"
32
+ @keydown.escape.prevent="closeMenu">
33
+ <!-- User info header -->
34
+ <div class="cn-user-action-menu__header">
35
+ <NcAvatar
36
+ :user="userId"
37
+ :display-name="displayName"
38
+ :size="36"
39
+ :show-user-status="false" />
40
+ <div class="cn-user-action-menu__user-info">
41
+ <span class="cn-user-action-menu__display-name">{{ displayName }}</span>
42
+ <span v-if="userEmail" class="cn-user-action-menu__email">{{ userEmail }}</span>
43
+ </div>
44
+ </div>
45
+
46
+ <!-- Action buttons -->
47
+ <div class="cn-user-action-menu__actions">
48
+ <NcActionButton
49
+ v-if="hasTalk"
50
+ role="menuitem"
51
+ @click="sendMessage">
52
+ <template #icon>
53
+ <MessageTextOutline :size="20" />
54
+ </template>
55
+ {{ sendMessageLabel }}
56
+ </NcActionButton>
57
+
58
+ <NcActionButton
59
+ v-if="hasTalk"
60
+ role="menuitem"
61
+ @click="startChat">
62
+ <template #icon>
63
+ <ChatOutline :size="20" />
64
+ </template>
65
+ {{ startChatLabel }}
66
+ </NcActionButton>
67
+
68
+ <NcActionButton
69
+ v-if="showEmailAction"
70
+ role="menuitem"
71
+ @click="sendEmail">
72
+ <template #icon>
73
+ <EmailOutline :size="20" />
74
+ </template>
75
+ {{ sendEmailLabel }}
76
+ </NcActionButton>
77
+
78
+ <NcActionButton
79
+ v-if="hasCalendar"
80
+ role="menuitem"
81
+ @click="planMeeting">
82
+ <template #icon>
83
+ <CalendarOutline :size="20" />
84
+ </template>
85
+ {{ planMeetingLabel }}
86
+ </NcActionButton>
87
+
88
+ <div
89
+ v-if="!hasTalk && !showEmailAction && !hasCalendar"
90
+ class="cn-user-action-menu__no-actions">
91
+ {{ noActionsLabel }}
92
+ </div>
93
+ </div>
94
+ </div>
95
+ </NcPopover>
96
+ </span>
97
+ </template>
98
+
99
+ <script>
100
+ import { translate as t } from '@nextcloud/l10n'
101
+ import { NcPopover, NcActionButton, NcAvatar } from '@nextcloud/vue'
102
+
103
+ import MessageTextOutline from 'vue-material-design-icons/MessageTextOutline.vue'
104
+ import ChatOutline from 'vue-material-design-icons/ChatOutline.vue'
105
+ import EmailOutline from 'vue-material-design-icons/EmailOutline.vue'
106
+ import CalendarOutline from 'vue-material-design-icons/CalendarOutline.vue'
107
+
108
+ import { buildHeaders } from '../../utils/index.js'
109
+
110
+ // Module-level capabilities cache (shared across all instances, fetched once per session)
111
+ let _capabilitiesCache = null
112
+ let _capabilitiesPromise = null
113
+
114
+ /**
115
+ * CnUserActionMenu — Popover with user communication actions.
116
+ *
117
+ * Shows contextual actions based on installed Nextcloud apps (Talk, Mail, Calendar).
118
+ * Uses @nextcloud/capabilities when available, falls back to OCS API.
119
+ *
120
+ * @example Usage in notes/tasks cards
121
+ * <CnUserActionMenu
122
+ * :user-id="note.actorId || note.author"
123
+ * :display-name="note.actorDisplayName || note.author || 'Unknown'" />
124
+ */
125
+ export default {
126
+ name: 'CnUserActionMenu',
127
+
128
+ components: {
129
+ NcPopover,
130
+ NcActionButton,
131
+ NcAvatar,
132
+ MessageTextOutline,
133
+ ChatOutline,
134
+ EmailOutline,
135
+ CalendarOutline,
136
+ },
137
+
138
+ props: {
139
+ /** The Nextcloud user ID */
140
+ userId: {
141
+ type: String,
142
+ required: true,
143
+ },
144
+ /** The user's display name */
145
+ displayName: {
146
+ type: String,
147
+ default: () => t('nextcloud-vue', 'Unknown'),
148
+ },
149
+ /** Whether the menu is interactive (false for current user or system accounts) */
150
+ interactive: {
151
+ type: Boolean,
152
+ default: true,
153
+ },
154
+
155
+ // --- Pre-translated labels ---
156
+ sendMessageLabel: { type: String, default: () => t('nextcloud-vue', 'Send message') },
157
+ startChatLabel: { type: String, default: () => t('nextcloud-vue', 'Start chat') },
158
+ sendEmailLabel: { type: String, default: () => t('nextcloud-vue', 'Send email') },
159
+ planMeetingLabel: { type: String, default: () => t('nextcloud-vue', 'Schedule meeting') },
160
+ noActionsLabel: { type: String, default: () => t('nextcloud-vue', 'No communication apps available') },
161
+ },
162
+
163
+ emits: ['action'],
164
+
165
+ data() {
166
+ return {
167
+ isOpen: false,
168
+ hasTalk: false,
169
+ hasMail: false,
170
+ hasCalendar: false,
171
+ userEmail: '',
172
+ emailResolved: false,
173
+ triggerElements: [],
174
+ }
175
+ },
176
+
177
+ computed: {
178
+ showEmailAction() {
179
+ return !!this.userEmail
180
+ },
181
+ },
182
+
183
+ mounted() {
184
+ this.triggerElements = [this.$refs.trigger]
185
+ this.detectCapabilities()
186
+ },
187
+
188
+ methods: {
189
+ openMenu() {
190
+ if (!this.interactive) return
191
+ this.isOpen = true
192
+ // Resolve email on first open if not yet done
193
+ if (!this.emailResolved) {
194
+ this.resolveUserEmail()
195
+ }
196
+ },
197
+
198
+ closeMenu() {
199
+ this.isOpen = false
200
+ },
201
+
202
+ onClose() {
203
+ this.isOpen = false
204
+ // Return focus to trigger
205
+ if (this.$refs.trigger) {
206
+ this.$refs.trigger.focus()
207
+ }
208
+ },
209
+
210
+ async detectCapabilities() {
211
+ if (_capabilitiesCache) {
212
+ this.applyCapabilities(_capabilitiesCache)
213
+ return
214
+ }
215
+
216
+ // Try @nextcloud/capabilities first (synchronous, from initial state)
217
+ try {
218
+ // eslint-disable-next-line n/no-missing-import
219
+ const { getCapabilities } = await import('@nextcloud/capabilities')
220
+ const caps = getCapabilities()
221
+ if (caps) {
222
+ _capabilitiesCache = caps
223
+ this.applyCapabilities(caps)
224
+ return
225
+ }
226
+ } catch {
227
+ // Package not available, fall back to API
228
+ }
229
+
230
+ // Fallback: fetch from OCS API (once per session)
231
+ if (!_capabilitiesPromise) {
232
+ _capabilitiesPromise = this.fetchCapabilities()
233
+ }
234
+ const caps = await _capabilitiesPromise
235
+ if (caps) {
236
+ _capabilitiesCache = caps
237
+ this.applyCapabilities(caps)
238
+ }
239
+ },
240
+
241
+ async fetchCapabilities() {
242
+ try {
243
+ const response = await fetch('/ocs/v2.php/cloud/capabilities?format=json', {
244
+ headers: buildHeaders(),
245
+ })
246
+ if (response.ok) {
247
+ const data = await response.json()
248
+ return data?.ocs?.data?.capabilities || {}
249
+ }
250
+ } catch (err) {
251
+ console.error('CnUserActionMenu: Failed to fetch capabilities', err)
252
+ }
253
+ return {}
254
+ },
255
+
256
+ applyCapabilities(caps) {
257
+ this.hasTalk = !!caps?.spreed
258
+ this.hasCalendar = !!caps?.dav
259
+ this.hasMail = !!caps?.mail
260
+ },
261
+
262
+ async resolveUserEmail() {
263
+ this.emailResolved = true
264
+ try {
265
+ const response = await fetch(
266
+ `/ocs/v2.php/cloud/users/${encodeURIComponent(this.userId)}?format=json`,
267
+ {
268
+ headers: {
269
+ ...buildHeaders(),
270
+ 'OCS-APIREQUEST': 'true',
271
+ },
272
+ },
273
+ )
274
+ if (response.ok) {
275
+ const data = await response.json()
276
+ this.userEmail = data?.ocs?.data?.email || ''
277
+ }
278
+ } catch (err) {
279
+ console.error('CnUserActionMenu: Failed to resolve user email', err)
280
+ this.userEmail = ''
281
+ }
282
+ },
283
+
284
+ async sendMessage() {
285
+ try {
286
+ const response = await fetch('/ocs/v2.php/apps/spreed/api/v4/room', {
287
+ method: 'POST',
288
+ headers: {
289
+ ...buildHeaders(),
290
+ 'OCS-APIREQUEST': 'true',
291
+ 'Content-Type': 'application/json',
292
+ },
293
+ body: JSON.stringify({ roomType: 1, invite: this.userId }),
294
+ })
295
+ if (response.ok) {
296
+ const data = await response.json()
297
+ const token = data?.ocs?.data?.token
298
+ if (token) {
299
+ window.location.href = `/apps/spreed/#/call/${token}`
300
+ }
301
+ } else {
302
+ this.showActionError('Failed to create conversation')
303
+ }
304
+ } catch (err) {
305
+ console.error('CnUserActionMenu: Failed to send message', err)
306
+ this.showActionError('Failed to create conversation')
307
+ }
308
+ this.$emit('action', { type: 'message', userId: this.userId })
309
+ },
310
+
311
+ async startChat() {
312
+ try {
313
+ const response = await fetch('/ocs/v2.php/apps/spreed/api/v4/room', {
314
+ method: 'POST',
315
+ headers: {
316
+ ...buildHeaders(),
317
+ 'OCS-APIREQUEST': 'true',
318
+ 'Content-Type': 'application/json',
319
+ },
320
+ body: JSON.stringify({ roomType: 1, invite: this.userId }),
321
+ })
322
+ if (response.ok) {
323
+ const data = await response.json()
324
+ const token = data?.ocs?.data?.token
325
+ if (token) {
326
+ window.open(`/apps/spreed/#/call/${token}`, '_blank')
327
+ }
328
+ } else {
329
+ this.showActionError('Failed to create conversation')
330
+ }
331
+ } catch (err) {
332
+ console.error('CnUserActionMenu: Failed to start chat', err)
333
+ this.showActionError('Failed to create conversation')
334
+ }
335
+ this.$emit('action', { type: 'chat', userId: this.userId })
336
+ },
337
+
338
+ sendEmail() {
339
+ if (!this.userEmail) return
340
+ if (this.hasMail) {
341
+ window.location.href = `/apps/mail/compose?to=${encodeURIComponent(this.userEmail)}`
342
+ } else {
343
+ window.location.href = `mailto:${this.userEmail}`
344
+ }
345
+ this.closeMenu()
346
+ this.$emit('action', { type: 'email', userId: this.userId })
347
+ },
348
+
349
+ planMeeting() {
350
+ window.location.href = `/apps/calendar/new?attendees=${encodeURIComponent(this.userId)}&title=Meeting`
351
+ this.closeMenu()
352
+ this.$emit('action', { type: 'meeting', userId: this.userId })
353
+ },
354
+
355
+ showActionError(message) {
356
+ try {
357
+ // eslint-disable-next-line n/no-missing-import
358
+ import('@nextcloud/dialogs').then(({ showError }) => {
359
+ showError(message)
360
+ })
361
+ } catch {
362
+ console.error(message)
363
+ }
364
+ },
365
+ },
366
+ }
367
+ </script>
368
+
369
+ <style scoped>
370
+ .cn-user-action-menu {
371
+ display: inline;
372
+ }
373
+
374
+ .cn-user-action-menu__trigger--interactive {
375
+ cursor: pointer;
376
+ color: var(--color-primary-element);
377
+ font-weight: 600;
378
+ }
379
+
380
+ .cn-user-action-menu__trigger--interactive:hover {
381
+ text-decoration: underline;
382
+ }
383
+
384
+ .cn-user-action-menu__trigger--interactive:focus-visible {
385
+ outline: 2px solid var(--color-primary-element);
386
+ outline-offset: 2px;
387
+ border-radius: var(--border-radius);
388
+ }
389
+
390
+ .cn-user-action-menu__popover {
391
+ min-width: 220px;
392
+ padding: 8px 0;
393
+ }
394
+
395
+ .cn-user-action-menu__header {
396
+ display: flex;
397
+ align-items: center;
398
+ gap: 10px;
399
+ padding: 8px 12px 12px;
400
+ border-bottom: 1px solid var(--color-border);
401
+ margin-bottom: 4px;
402
+ }
403
+
404
+ .cn-user-action-menu__user-info {
405
+ display: flex;
406
+ flex-direction: column;
407
+ min-width: 0;
408
+ }
409
+
410
+ .cn-user-action-menu__display-name {
411
+ font-weight: 600;
412
+ font-size: 14px;
413
+ white-space: nowrap;
414
+ overflow: hidden;
415
+ text-overflow: ellipsis;
416
+ }
417
+
418
+ .cn-user-action-menu__email {
419
+ font-size: 12px;
420
+ color: var(--color-text-maxcontrast);
421
+ white-space: nowrap;
422
+ overflow: hidden;
423
+ text-overflow: ellipsis;
424
+ }
425
+
426
+ .cn-user-action-menu__actions {
427
+ padding: 4px 0;
428
+ }
429
+
430
+ .cn-user-action-menu__no-actions {
431
+ padding: 12px 16px;
432
+ text-align: center;
433
+ color: var(--color-text-maxcontrast);
434
+ font-size: 13px;
435
+ }
436
+ </style>