@conduction/nextcloud-vue 2.182.0 → 2.184.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 (27) hide show
  1. package/dist/esm/components/CnChartWidget/CnChartWidget.vue.js +1 -1
  2. package/dist/esm/components/CnChartWidget/CnChartWidget2.vue.js +21 -0
  3. package/dist/esm/components/CnChartWidget/CnChartWidget2.vue.js.map +1 -1
  4. package/dist/esm/components/CnChartWidget/CnChartWidget3.vue.js.map +1 -1
  5. package/dist/esm/components/CnMapWidget/CnMapWidget.vue.js +1 -1
  6. package/dist/esm/components/CnMapWidget/CnMapWidget2.vue.js +36 -7
  7. package/dist/esm/components/CnMapWidget/CnMapWidget2.vue.js.map +1 -1
  8. package/dist/esm/components/CnMapWidget/CnMapWidget3.vue.js.map +1 -1
  9. package/dist/esm/components/CnMapWidget/spatialFilter.js +136 -0
  10. package/dist/esm/components/CnMapWidget/spatialFilter.js.map +1 -0
  11. package/dist/esm/components/CnStatsBlockWidget/CnStatsBlockWidget.vue.js +1 -1
  12. package/dist/esm/components/CnStatsBlockWidget/CnStatsBlockWidget2.vue.js +20 -0
  13. package/dist/esm/components/CnStatsBlockWidget/CnStatsBlockWidget2.vue.js.map +1 -1
  14. package/dist/esm/components/CnStatsBlockWidget/CnStatsBlockWidget3.vue.js.map +1 -1
  15. package/dist/esm/library-style.js +1 -1
  16. package/dist/esm/mixins/widgetData.js +69 -0
  17. package/dist/esm/mixins/widgetData.js.map +1 -0
  18. package/dist/esm/nextcloud-vue.css +112 -112
  19. package/dist/nextcloud-vue.cjs.js +275 -10
  20. package/dist/nextcloud-vue.cjs.js.map +2 -2
  21. package/dist/nextcloud-vue.css +112 -112
  22. package/package.json +1 -1
  23. package/src/components/CnChartWidget/CnChartWidget.vue +21 -0
  24. package/src/components/CnMapWidget/CnMapWidget.vue +41 -7
  25. package/src/components/CnMapWidget/spatialFilter.js +132 -0
  26. package/src/components/CnStatsBlockWidget/CnStatsBlockWidget.vue +20 -0
  27. package/src/mixins/widgetData.js +66 -0
@@ -177,6 +177,7 @@ import { inject, markRaw, ref } from 'vue'
177
177
  import VueApexCharts from 'vue3-apexcharts'
178
178
  import { useDataSource } from '../../composables/useDataSource.js'
179
179
  import { getByPath, useEndpointSource } from '../../composables/useEndpointSource.js'
180
+ import widgetData, { seriesTotal } from '../../mixins/widgetData.js'
180
181
  import { useObjectStore } from '../../store/useObjectStore.js'
181
182
  import { resolveObjectOpType } from '../../utils/actionsDispatcher.js'
182
183
  import { fetchReferenceObjects } from '../../utils/boardReferenceColumns.js'
@@ -433,6 +434,8 @@ export default {
433
434
 
434
435
  components: { CnEndpointNotice, NcNoteCard },
435
436
 
437
+ mixins: [widgetData],
438
+
436
439
  inject: {
437
440
  /**
438
441
  * Reactive date-range provided by an ancestor `CnDashboardPage`.
@@ -1182,6 +1185,24 @@ export default {
1182
1185
  return fromDs !== undefined ? fromDs : this.series
1183
1186
  },
1184
1187
 
1188
+ /**
1189
+ * What the chart shows, for the `data` event: its series, categories,
1190
+ * labels and the total of its first series; null until it has a series.
1191
+ *
1192
+ * @return {{series: Array, categories: Array, labels: Array, total: number|null}|null}
1193
+ * @spec openspec/changes/widget-data-event/specs/widget-data-event/spec.md#requirement-a-self-fetching-widget-tells-its-host-what-it-shows
1194
+ */
1195
+ widgetData() {
1196
+ const series = this.resolvedSeries
1197
+ if (!Array.isArray(series) || series.length === 0) {
1198
+ return null
1199
+ }
1200
+ const categories = Array.isArray(this.resolvedCategories) ? this.resolvedCategories : []
1201
+ const rest = this.aggregateData || this.bucketData || this.groupByData
1202
+ const labels = Array.isArray(rest?.labels) ? rest.labels : (Array.isArray(this.labels) ? this.labels : categories)
1203
+ return { series, categories, labels, total: seriesTotal(series) }
1204
+ },
1205
+
1185
1206
  resolvedCategories() {
1186
1207
  if (this.cellData) {
1187
1208
  return this.cellData.categories
@@ -18,6 +18,11 @@
18
18
  OpenRegister register/schema, reading each one's `@self.geo`
19
19
  (falling back to `latField` / `lngField` on the object itself).
20
20
  Objects with no usable location are skipped, not plotted at (0, 0).
21
+ `dataSource.spatialFilter` narrows them to a bbox, a radius around a
22
+ point, or a polygon, through OpenRegister's geo filters.
23
+ - `markers.detailLink` — a clicked object opens this address (with
24
+ `{id}`, `{register}`, `{schema}`, `{<property>}` tokens) in a new
25
+ tab; without it, a `url` the object carries is opened.
21
26
 
22
27
  `leaflet.markercluster`'s JS lazy-loads only when `clustering: true`
23
28
  (or `markers.clustering: true`), so a consumer without clustering does
@@ -110,6 +115,7 @@ import { resolveFilterTokens } from '../../utils/resolveFilterTokens.js'
110
115
  import { safeHref } from '../../utils/safeHref.js'
111
116
  import { SAFE_MARKDOWN_DOMPURIFY_CONFIG } from '../../utils/safeMarkdownDompurifyConfig.js'
112
117
  import { fromImagePoint, hasImagePosition, imageBounds, paddedImageBounds, toImagePoint } from './imageCoordinates.js'
118
+ import { featureDetailUrl, spatialFilterRequest } from './spatialFilter.js'
113
119
 
114
120
  // Leaflet's own stylesheet positions the map panes, tiles the tile
115
121
  // images, and places the zoom/attribution controls. The JS is lazy-loaded
@@ -314,14 +320,16 @@ export default {
314
320
 
315
321
  /**
316
322
  * Marker config. `{ features?, dataSource?, geoProperty?, latField?, lngField?, xField?, yField?,
317
- * popupField?, clustering?, iconColor?, iconUrl?, centerMarker? }`. On an image map
323
+ * popupField?, clustering?, iconColor?, iconUrl?, centerMarker?, detailLink? }`. On an image map
318
324
  * (a layer of type `image`) markers read `xField` / `yField` (default `x` / `y`,
319
325
  * pixels from the picture's top left) instead of `latField` / `lngField`. `features[]` is inline;
320
326
  * `dataSource.url` is HTTP-fetched on mount; `dataSource.{register, schema}`
321
327
  * plots the objects of an OpenRegister register/schema via `geoProperty` (a property
322
328
  * holding a GeoJSON geometry of any type, or a point) when set, else `@self.geo`.
323
329
  * `centerMarker: true` adds an extra pin at the map's `center`, alongside any
324
- * source markers.
330
+ * source markers. `dataSource.spatialFilter` (`{ bbox }`, `{ near, radius }` or
331
+ * `{ within }`) narrows a register source to an area; `detailLink` is the address
332
+ * a clicked object opens in a new tab (see spatialFilter.js).
325
333
  *
326
334
  * @type {object|null}
327
335
  */
@@ -729,14 +737,18 @@ export default {
729
737
  },
730
738
 
731
739
  /**
732
- * The data-source filter with its tokens resolved, serialised so a new
733
- * record re-reads the markers.
740
+ * The data-source filter with its tokens resolved, and the spatial
741
+ * filter, serialised so a new record or a new area re-reads the markers.
734
742
  *
735
743
  * @return {string}
744
+ * @spec openspec/changes/map-spatial-filter-and-detail-link/specs/map-spatial-filter-and-detail-link/spec.md#requirement-a-map-can-narrow-its-objects-to-an-area
736
745
  */
737
746
  filterKey() {
738
747
  const ds = this.cfg.markers && this.cfg.markers.dataSource
739
- return ds && ds.filter ? JSON.stringify(this.sourceFilter(ds)) : ''
748
+ if (!ds || (!ds.filter && !ds.spatialFilter)) {
749
+ return ''
750
+ }
751
+ return JSON.stringify([ds.filter ? this.sourceFilter(ds) : null, ds.spatialFilter || null])
740
752
  },
741
753
 
742
754
  unplottedLabel() {
@@ -1279,6 +1291,7 @@ export default {
1279
1291
  * @type {{feature: object, latlng: object}}
1280
1292
  */
1281
1293
  this.$emit('marker-click', { feature, latlng: e.latlng })
1294
+ this.openFeatureDetail(feature)
1282
1295
  })
1283
1296
  },
1284
1297
  })
@@ -1776,8 +1789,11 @@ export default {
1776
1789
  * skipped rather than dropped at (0, 0) — an invisible wrong marker is worse
1777
1790
  * than an absent one.
1778
1791
  *
1779
- * @param {{register: string, schema: string, limit?: number}} ds The data source.
1792
+ * A `spatialFilter` narrows the objects to an area (see spatialFilter.js).
1793
+ *
1794
+ * @param {{register: string, schema: string, limit?: number, spatialFilter?: object}} ds The data source.
1780
1795
  * @return {Promise<Array<object>>} GeoJSON Feature array.
1796
+ * @spec openspec/changes/map-spatial-filter-and-detail-link/specs/map-spatial-filter-and-detail-link/spec.md#requirement-a-map-can-narrow-its-objects-to-an-area
1781
1797
  */
1782
1798
  async fetchRegisterFeatures(ds) {
1783
1799
  try {
@@ -1789,7 +1805,11 @@ export default {
1789
1805
  '/apps/openregister/api/objects/{register}/{schema}',
1790
1806
  { register: ds.register, schema: ds.schema },
1791
1807
  )
1792
- const res = await axios.get(url, { params: { ...this.sourceFilter(ds), _limit: ds.limit || 500 } })
1808
+ const params = { ...this.sourceFilter(ds), _limit: ds.limit || 500 }
1809
+ const spatial = spatialFilterRequest(ds.spatialFilter, this.cfg.markers && this.cfg.markers.geoProperty)
1810
+ const res = spatial && spatial.body
1811
+ ? await axios.post(url + '/geo-search', spatial.body, { params })
1812
+ : await axios.get(url, { params: { ...params, ...(spatial ? spatial.params : {}) } })
1793
1813
  const rows = (res && res.data && res.data.results) || []
1794
1814
 
1795
1815
  const latField = this.cfg.markers && this.cfg.markers.latField
@@ -1809,6 +1829,20 @@ export default {
1809
1829
  }
1810
1830
  },
1811
1831
 
1832
+ /**
1833
+ * Open a clicked object's detail address in a new tab, when it has one.
1834
+ *
1835
+ * @param {object} feature The clicked GeoJSON feature.
1836
+ * @return {void}
1837
+ * @spec openspec/changes/map-spatial-filter-and-detail-link/specs/map-spatial-filter-and-detail-link/spec.md#requirement-a-clicked-object-opens-its-detail-page
1838
+ */
1839
+ openFeatureDetail(feature) {
1840
+ const href = featureDetailUrl(feature, this.cfg.markers && this.cfg.markers.detailLink)
1841
+ if (href !== null) {
1842
+ window.open(href, '_blank', 'noopener,noreferrer')
1843
+ }
1844
+ },
1845
+
1812
1846
  /**
1813
1847
  * Normalise a fetched payload into a GeoJSON Feature array.
1814
1848
  * Accepts FeatureCollection, raw Feature[], or flat rows that
@@ -0,0 +1,132 @@
1
+ /**
2
+ * SPDX-FileCopyrightText: 2026 Conduction B.V. <info@conduction.nl>
3
+ * SPDX-License-Identifier: EUPL-1.2
4
+ *
5
+ * Spatial filters and detail links for a map that plots OpenRegister objects.
6
+ *
7
+ * `markers.dataSource.spatialFilter` narrows the objects to an area, through
8
+ * OpenRegister's geo filters:
9
+ * - `{ bbox: [west, south, east, north] }` → `GET ?geo.bbox=w,s,e,n`
10
+ * - `{ near: [lon, lat], radius: meters }` → `GET ?geo.near=lon,lat&geo.radius=m`
11
+ * - `{ within: <GeoJSON Polygon|MultiPolygon> }` → `POST …/geo-search`
12
+ * The map's `markers.geoProperty`, when set, is sent as `geo.property` so the
13
+ * filter reads the same property the map draws.
14
+ *
15
+ * `markers.detailLink` is the address a clicked feature opens in a new tab: a
16
+ * template whose `{id}`, `{register}`, `{schema}` and `{<property>}` tokens are
17
+ * filled from the object. Without a template, a `url` the object carries (the
18
+ * address OpenRegister's deep-link registry stamps) is opened instead. An
19
+ * app-absolute path gets the instance's webroot.
20
+ */
21
+
22
+ import { prefixUrl } from '../../utils/headers.js'
23
+ import { safeHref } from '../../utils/safeHref.js'
24
+
25
+ const POLYGON_TYPES = ['Polygon', 'MultiPolygon']
26
+
27
+ /**
28
+ * Whether every entry is a finite number and there are `length` of them.
29
+ *
30
+ * @param {unknown} list The value.
31
+ * @param {number} length The expected length.
32
+ * @return {boolean}
33
+ */
34
+ function isNumberTuple(list, length) {
35
+ return Array.isArray(list) && list.length === length && list.every((n) => Number.isFinite(Number(n)) && n !== '' && n !== null)
36
+ }
37
+
38
+ /**
39
+ * The OpenRegister request a spatial filter makes, or null when there is no
40
+ * usable filter. A malformed filter is ignored rather than sent, so a typo in
41
+ * a widget's config never empties the map with a 422.
42
+ *
43
+ * @param {object|null|undefined} spatialFilter The `dataSource.spatialFilter` block.
44
+ * @param {string} [geoProperty] The property the map draws, sent as `geo.property`.
45
+ * @return {{params: object}|{body: object}|null} Query params for the listing, or a geo-search body.
46
+ * @spec openspec/changes/map-spatial-filter-and-detail-link/specs/map-spatial-filter-and-detail-link/spec.md#requirement-a-map-can-narrow-its-objects-to-an-area
47
+ */
48
+ export function spatialFilterRequest(spatialFilter, geoProperty) {
49
+ if (!spatialFilter || typeof spatialFilter !== 'object') {
50
+ return null
51
+ }
52
+ const property = typeof geoProperty === 'string' && geoProperty !== '' ? { 'geo.property': geoProperty } : {}
53
+
54
+ const within = spatialFilter.within
55
+ if (within && typeof within === 'object' && POLYGON_TYPES.includes(within.type) && Array.isArray(within.coordinates)) {
56
+ const body = { geometry: { within } }
57
+ if (property['geo.property']) {
58
+ body.property = property['geo.property']
59
+ }
60
+ return { body }
61
+ }
62
+ if (isNumberTuple(spatialFilter.bbox, 4)) {
63
+ return { params: { 'geo.bbox': spatialFilter.bbox.map(Number).join(','), ...property } }
64
+ }
65
+ if (isNumberTuple(spatialFilter.near, 2) && Number(spatialFilter.radius) > 0) {
66
+ return {
67
+ params: {
68
+ 'geo.near': spatialFilter.near.map(Number).join(','),
69
+ 'geo.radius': String(Number(spatialFilter.radius)),
70
+ ...property,
71
+ },
72
+ }
73
+ }
74
+ return null
75
+ }
76
+
77
+ /**
78
+ * The value a detail-link token reads from an object.
79
+ *
80
+ * @param {object} object The feature's properties (the OpenRegister object).
81
+ * @param {string} token The token name.
82
+ * @return {unknown}
83
+ */
84
+ function tokenValue(object, token) {
85
+ const self = object['@self'] && typeof object['@self'] === 'object' ? object['@self'] : {}
86
+ if (token === 'id') {
87
+ return self.id ?? object.id ?? object.uuid
88
+ }
89
+ if (token === 'register' || token === 'schema') {
90
+ return self[token] ?? object[token]
91
+ }
92
+ return object[token]
93
+ }
94
+
95
+ /**
96
+ * The address a clicked feature opens, or null when it has none. A template
97
+ * with a token the object cannot fill gives null, so a click never opens a
98
+ * half-built address.
99
+ *
100
+ * @param {object|null} feature The clicked GeoJSON feature.
101
+ * @param {string} [template] The `markers.detailLink` template.
102
+ * @return {string|null} A safe href, or null.
103
+ * @spec openspec/changes/map-spatial-filter-and-detail-link/specs/map-spatial-filter-and-detail-link/spec.md#requirement-a-clicked-object-opens-its-detail-page
104
+ */
105
+ export function featureDetailUrl(feature, template) {
106
+ const object = feature && feature.properties && typeof feature.properties === 'object' ? feature.properties : null
107
+ if (object === null) {
108
+ return null
109
+ }
110
+ let href = null
111
+ if (typeof template === 'string' && template !== '') {
112
+ let missing = false
113
+ href = template.replace(/\{([\w@.-]+)\}/g, (_match, token) => {
114
+ const value = tokenValue(object, token)
115
+ if (value === undefined || value === null || value === '' || typeof value === 'object') {
116
+ missing = true
117
+ return ''
118
+ }
119
+ return encodeURIComponent(String(value))
120
+ })
121
+ if (missing) {
122
+ return null
123
+ }
124
+ } else if (typeof object.url === 'string' && object.url !== '') {
125
+ href = object.url
126
+ }
127
+ if (href === null) {
128
+ return null
129
+ }
130
+ const safe = safeHref(href)
131
+ return safe === '#' ? null : prefixUrl(safe)
132
+ }
@@ -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
@@ -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
+ }