@conduction/nextcloud-vue 2.183.0 → 2.185.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.
@@ -122,6 +122,7 @@ import { subscribe, unsubscribe } from '@nextcloud/event-bus'
122
122
  import CnStatsBlock from '../CnStatsBlock/CnStatsBlock.vue'
123
123
  import CnStatWidget from '../CnStatWidget/CnStatWidget.vue'
124
124
  import { useDataSource } from '../../composables/useDataSource.js'
125
+ import widgetData from '../../mixins/widgetData.js'
125
126
  import { aggFilterParam } from '../../utils/fetchAggregate.js'
126
127
  import { formatMetricValue, normalizeMetricFormat, unwrapAppConfig } from '../../utils/formatMetric.js'
127
128
  import { followLinkClick, resolveHref } from '../../utils/linkNavigation.js'
@@ -203,6 +204,8 @@ export default {
203
204
 
204
205
  components: { CnStatsBlock, CnStatWidget },
205
206
 
207
+ mixins: [widgetData],
208
+
206
209
  inject: {
207
210
  /**
208
211
  * Detail-page object context provided by CnDetailPage — enables
@@ -668,6 +671,23 @@ export default {
668
671
  })))
669
672
  },
670
673
 
674
+ /**
675
+ * What the widget shows, for the `data` event: the count of a single
676
+ * source, or every entry's count; null until a count is known.
677
+ *
678
+ * @return {{count: number}|{counts: Array<number|null>}|null}
679
+ * @spec openspec/changes/widget-data-event/specs/widget-data-event/spec.md#requirement-a-self-fetching-widget-tells-its-host-what-it-shows
680
+ */
681
+ widgetData() {
682
+ if (this.hasEntries) {
683
+ return this.entryFetching.some(Boolean) || this.entryCounts.length === 0 ? null : { counts: [...this.entryCounts] }
684
+ }
685
+ if (typeof this.restCount === 'number' || this.dsData?.count !== undefined) {
686
+ return { count: this.resolvedCount }
687
+ }
688
+ return null
689
+ },
690
+
671
691
  resolvedCount() {
672
692
  if (typeof this.restCount === 'number') {
673
693
  return this.restCount
@@ -31,6 +31,22 @@
31
31
  </select>
32
32
  </div>
33
33
 
34
+ <!-- Notices about the widget being edited, from the host: a finding
35
+ the host made about its configuration (non-fatal), above the form. -->
36
+ <div
37
+ v-if="notices.length > 0 || $slots.notices"
38
+ class="cn-add-widget-modal__notices"
39
+ data-testid="cn-add-widget-modal-notices">
40
+ <!-- @slot Extra notices above the form; replaces nothing, follows the `notices` prop. -->
41
+ <NcNoteCard
42
+ v-for="(notice, index) in notices"
43
+ :key="notice.id || index"
44
+ :type="noticeType(notice)"
45
+ :text="notice.text"
46
+ data-testid="cn-add-widget-modal-notice" />
47
+ <slot name="notices" />
48
+ </div>
49
+
34
50
  <!-- Active per-type sub-form. Driven by `<component :is>` from the
35
51
  shared registry; sub-forms expose `validate()` and either an
36
52
  `assembledContent` getter or `@update:content` events. -->
@@ -111,7 +127,7 @@
111
127
 
112
128
  <script>
113
129
  import { translate as t } from '@nextcloud/l10n'
114
- import { NcButton, NcCheckboxRadioSwitch, NcDialog, NcTextField } from '@nextcloud/vue'
130
+ import { NcButton, NcCheckboxRadioSwitch, NcDialog, NcNoteCard, NcTextField } from '@nextcloud/vue'
115
131
  import { computed, provide } from 'vue'
116
132
  import CnColorPicker from '../components/CnColorPicker/CnColorPicker.vue'
117
133
  import CnIconBrowser from '../components/CnIconBrowser/CnIconBrowser.vue'
@@ -143,6 +159,7 @@ export default {
143
159
  NcButton,
144
160
  NcTextField,
145
161
  NcCheckboxRadioSwitch,
162
+ NcNoteCard,
146
163
  CnIconBrowser,
147
164
  CnColorPicker,
148
165
  },
@@ -221,6 +238,20 @@ export default {
221
238
  default: null,
222
239
  },
223
240
 
241
+ /**
242
+ * Non-fatal notices about the widget, shown above its form: what the
243
+ * host found about its configuration, e.g. a filter dimension the
244
+ * dashboard does not publish. Each is `{ text, type?, id? }`, `type`
245
+ * one of `warning` (default), `info`, `error`, `success`.
246
+ *
247
+ * @type {Array<{text: string, type?: string, id?: string}>}
248
+ * @spec openspec/changes/add-widget-modal-notices/specs/add-widget-modal-notices/spec.md#requirement-the-widget-dialog-can-show-the-hosts-notices
249
+ */
250
+ notices: {
251
+ type: Array,
252
+ default: () => [],
253
+ },
254
+
224
255
  /**
225
256
  * The surface the picker offers types for. `'detail-page'` surfaces
226
257
  * detail-only types (e.g. a second `data` widget) alongside the universal
@@ -535,6 +566,17 @@ export default {
535
566
  },
536
567
 
537
568
  methods: {
569
+ /**
570
+ * The note card type of a notice: its own when known, else `warning`.
571
+ *
572
+ * @param {{type?: string}} notice The notice.
573
+ * @return {string}
574
+ * @spec openspec/changes/add-widget-modal-notices/specs/add-widget-modal-notices/spec.md#requirement-the-widget-dialog-can-show-the-hosts-notices
575
+ */
576
+ noticeType(notice) {
577
+ return ['warning', 'info', 'error', 'success'].includes(notice && notice.type) ? notice.type : 'warning'
578
+ },
579
+
538
580
  t,
539
581
 
540
582
  /**
@@ -815,4 +857,11 @@ export default {
815
857
  font-size: 13px;
816
858
  color: var(--color-text-maxcontrast);
817
859
  }
860
+
861
+ .cn-add-widget-modal__notices {
862
+ display: flex;
863
+ flex-direction: column;
864
+ gap: 4px;
865
+ margin-block-end: 12px;
866
+ }
818
867
  </style>
@@ -0,0 +1,66 @@
1
+ /*
2
+ * SPDX-FileCopyrightText: 2026 Conduction B.V.
3
+ * SPDX-License-Identifier: EUPL-1.2
4
+ */
5
+
6
+ /**
7
+ * widgetData — a self-fetching widget tells its host what it shows.
8
+ *
9
+ * A widget that fetches its own data (CnChartWidget, CnStatsBlockWidget)
10
+ * keeps that data to itself, so a host that derives values from it (a
11
+ * dashboard's calculated fields, an export) has nothing to read. A widget
12
+ * using this mixin defines a `widgetData` computed returning a plain,
13
+ * serialisable summary of what it shows, or null while there is nothing yet;
14
+ * the mixin emits `data` with that summary whenever it changes, including the
15
+ * first time it is known.
16
+ *
17
+ * @spec openspec/changes/widget-data-event/specs/widget-data-event/spec.md#requirement-a-self-fetching-widget-tells-its-host-what-it-shows
18
+ */
19
+ export default {
20
+ emits: ['data'],
21
+
22
+ watch: {
23
+ widgetData: {
24
+ immediate: true,
25
+ /**
26
+ * Emit the summary once it is known, and on every change.
27
+ *
28
+ * @param {object|null} summary The widget's data summary.
29
+ * @return {void}
30
+ */
31
+ handler(summary) {
32
+ if (summary !== null && summary !== undefined) {
33
+ /**
34
+ * What the widget shows, as a plain summary.
35
+ *
36
+ * @event data
37
+ * @type {object}
38
+ */
39
+ this.$emit('data', summary)
40
+ }
41
+ },
42
+ },
43
+ },
44
+ }
45
+
46
+ /**
47
+ * The sum of the numbers in a chart series: a list of numbers (a pie or
48
+ * donut) or the `data` of its first named series. Non-numbers count as 0.
49
+ *
50
+ * @param {Array<number|object>|undefined} series The series.
51
+ * @return {number|null} The total, or null for no series.
52
+ * @spec openspec/changes/widget-data-event/specs/widget-data-event/spec.md#requirement-a-self-fetching-widget-tells-its-host-what-it-shows
53
+ */
54
+ export function seriesTotal(series) {
55
+ if (!Array.isArray(series) || series.length === 0) {
56
+ return null
57
+ }
58
+ const values = typeof series[0] === 'object' && series[0] !== null ? series[0].data : series
59
+ if (!Array.isArray(values)) {
60
+ return null
61
+ }
62
+ return values.reduce((sum, value) => {
63
+ const number = typeof value === 'object' && value !== null ? Number(value.y) : Number(value)
64
+ return Number.isFinite(number) ? sum + number : sum
65
+ }, 0)
66
+ }