@conduction/nextcloud-vue 2.174.0 → 2.176.1
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.
- package/dist/esm/components/CnActionDialog/CnActionDialog.vue.js +1 -1
- package/dist/esm/components/CnActionDialog/CnActionDialog.vue2.js +114 -11
- package/dist/esm/components/CnActionDialog/CnActionDialog.vue2.js.map +1 -1
- package/dist/esm/components/CnActionDialog/CnActionDialog.vue3.js +67 -17
- package/dist/esm/components/CnActionDialog/CnActionDialog.vue3.js.map +1 -1
- package/dist/esm/components/CnBlockListEditor/CnBlockListEditor.vue.js +9 -0
- package/dist/esm/components/CnBlockListEditor/CnBlockListEditor.vue.js.map +1 -0
- package/dist/esm/components/CnBlockListEditor/CnBlockListEditor.vue2.js +352 -0
- package/dist/esm/components/CnBlockListEditor/CnBlockListEditor.vue2.js.map +1 -0
- package/dist/esm/components/CnBlockListEditor/CnBlockListEditor.vue3.js +266 -0
- package/dist/esm/components/CnBlockListEditor/CnBlockListEditor.vue3.js.map +1 -0
- package/dist/esm/components/CnChecklistRunWidget/CnChecklistRunWidget.vue.js +1 -1
- package/dist/esm/components/CnChecklistRunWidget/CnChecklistRunWidget.vue2.js +323 -7
- package/dist/esm/components/CnChecklistRunWidget/CnChecklistRunWidget.vue2.js.map +1 -1
- package/dist/esm/components/CnChecklistRunWidget/CnChecklistRunWidget.vue3.js +113 -59
- package/dist/esm/components/CnChecklistRunWidget/CnChecklistRunWidget.vue3.js.map +1 -1
- package/dist/esm/components/CnChildRecordsField/CnChildRecordsField.vue.js +1 -1
- package/dist/esm/components/CnChildRecordsField/CnChildRecordsField.vue2.js +210 -5
- package/dist/esm/components/CnChildRecordsField/CnChildRecordsField.vue2.js.map +1 -1
- package/dist/esm/components/CnChildRecordsField/CnChildRecordsField.vue3.js +134 -46
- package/dist/esm/components/CnChildRecordsField/CnChildRecordsField.vue3.js.map +1 -1
- package/dist/esm/components/CnChoiceMatrix/CnChoiceMatrix.vue.js +9 -0
- package/dist/esm/components/CnChoiceMatrix/CnChoiceMatrix.vue.js.map +1 -0
- package/dist/esm/components/CnChoiceMatrix/CnChoiceMatrix.vue2.js +385 -0
- package/dist/esm/components/CnChoiceMatrix/CnChoiceMatrix.vue2.js.map +1 -0
- package/dist/esm/components/CnChoiceMatrix/CnChoiceMatrix.vue3.js +277 -0
- package/dist/esm/components/CnChoiceMatrix/CnChoiceMatrix.vue3.js.map +1 -0
- package/dist/esm/components/CnCountdownWidget/CnCountdownWidget.vue.js +1 -1
- package/dist/esm/components/CnCountdownWidget/CnCountdownWidget.vue2.js +175 -20
- package/dist/esm/components/CnCountdownWidget/CnCountdownWidget.vue2.js.map +1 -1
- package/dist/esm/components/CnCountdownWidget/CnCountdownWidget.vue3.js +30 -8
- package/dist/esm/components/CnCountdownWidget/CnCountdownWidget.vue3.js.map +1 -1
- package/dist/esm/components/CnCreateFormWidget/CnCreateFormWidget.vue.js +1 -1
- package/dist/esm/components/CnCreateFormWidget/CnCreateFormWidget.vue2.js +72 -6
- package/dist/esm/components/CnCreateFormWidget/CnCreateFormWidget.vue2.js.map +1 -1
- package/dist/esm/components/CnCreateFormWidget/CnCreateFormWidget.vue3.js +48 -14
- package/dist/esm/components/CnCreateFormWidget/CnCreateFormWidget.vue3.js.map +1 -1
- package/dist/esm/components/CnDataMatrix/CnDataMatrix.vue.js +1 -1
- package/dist/esm/components/CnDataMatrix/CnDataMatrix.vue2.js +255 -10
- package/dist/esm/components/CnDataMatrix/CnDataMatrix.vue2.js.map +1 -1
- package/dist/esm/components/CnDataMatrix/CnDataMatrix.vue3.js +70 -28
- package/dist/esm/components/CnDataMatrix/CnDataMatrix.vue3.js.map +1 -1
- package/dist/esm/components/CnDetailPage/CnDetailPage.vue2.js +55 -6
- package/dist/esm/components/CnDetailPage/CnDetailPage.vue2.js.map +1 -1
- package/dist/esm/components/CnDetailPage/CnDetailPage.vue3.js.map +1 -1
- package/dist/esm/components/CnDisplayScreen/CnDisplayScreen.vue.js +9 -0
- package/dist/esm/components/CnDisplayScreen/CnDisplayScreen.vue.js.map +1 -0
- package/dist/esm/components/CnDisplayScreen/CnDisplayScreen.vue2.js +175 -0
- package/dist/esm/components/CnDisplayScreen/CnDisplayScreen.vue2.js.map +1 -0
- package/dist/esm/components/CnDisplayScreen/CnDisplayScreen.vue3.js +114 -0
- package/dist/esm/components/CnDisplayScreen/CnDisplayScreen.vue3.js.map +1 -0
- package/dist/esm/components/CnDurationField/CnDurationField.vue.js +1 -1
- package/dist/esm/components/CnDurationField/CnDurationField.vue2.js +218 -4
- package/dist/esm/components/CnDurationField/CnDurationField.vue2.js.map +1 -1
- package/dist/esm/components/CnDurationField/CnDurationField.vue3.js +133 -44
- package/dist/esm/components/CnDurationField/CnDurationField.vue3.js.map +1 -1
- package/dist/esm/components/CnFormDialog/CnFormDialog.vue.js +1 -1
- package/dist/esm/components/CnFormDialog/CnFormDialog.vue2.js.map +1 -1
- package/dist/esm/components/CnFormDialog/CnFormDialog.vue3.js +5 -1
- package/dist/esm/components/CnFormDialog/CnFormDialog.vue3.js.map +1 -1
- package/dist/esm/components/CnGeoCaptureField/CnGeoCaptureField.vue.js +9 -0
- package/dist/esm/components/CnGeoCaptureField/CnGeoCaptureField.vue.js.map +1 -0
- package/dist/esm/components/CnGeoCaptureField/CnGeoCaptureField.vue2.js +113 -0
- package/dist/esm/components/CnGeoCaptureField/CnGeoCaptureField.vue2.js.map +1 -0
- package/dist/esm/components/CnGeoCaptureField/CnGeoCaptureField.vue3.js +43 -0
- package/dist/esm/components/CnGeoCaptureField/CnGeoCaptureField.vue3.js.map +1 -0
- package/dist/esm/components/CnIndexPage/CnIndexPage.vue2.js +40 -1
- package/dist/esm/components/CnIndexPage/CnIndexPage.vue2.js.map +1 -1
- package/dist/esm/components/CnIndexPage/CnIndexPage.vue3.js.map +1 -1
- package/dist/esm/components/CnMarkdownEditor/CnMarkdownEditor.vue.js +1 -1
- package/dist/esm/components/CnMarkdownEditor/CnMarkdownEditor.vue2.js +110 -1
- package/dist/esm/components/CnMarkdownEditor/CnMarkdownEditor.vue2.js.map +1 -1
- package/dist/esm/components/CnMarkdownEditor/CnMarkdownEditor.vue3.js +60 -18
- package/dist/esm/components/CnMarkdownEditor/CnMarkdownEditor.vue3.js.map +1 -1
- package/dist/esm/components/CnMenuTreeNode/CnMenuTreeNode.vue2.js +2 -2
- package/dist/esm/components/CnMenuTreeNode/CnMenuTreeNode.vue2.js.map +1 -1
- package/dist/esm/components/CnObjectKanban/CnObjectKanban.vue2.js +2 -2
- package/dist/esm/components/CnObjectKanban/CnObjectKanban.vue2.js.map +1 -1
- package/dist/esm/components/CnPageTreeNode/CnPageTreeNode.vue2.js +2 -2
- package/dist/esm/components/CnPageTreeNode/CnPageTreeNode.vue2.js.map +1 -1
- package/dist/esm/components/CnQrCode/CnQrCode.vue.js +9 -0
- package/dist/esm/components/CnQrCode/CnQrCode.vue.js.map +1 -0
- package/dist/esm/components/CnQrCode/CnQrCode.vue2.js +241 -0
- package/dist/esm/components/CnQrCode/CnQrCode.vue2.js.map +1 -0
- package/dist/esm/components/CnQrCode/CnQrCode.vue3.js +75 -0
- package/dist/esm/components/CnQrCode/CnQrCode.vue3.js.map +1 -0
- package/dist/esm/components/CnReadinessChecklist/CnReadinessChecklist.vue.js +1 -1
- package/dist/esm/components/CnReadinessChecklist/CnReadinessChecklist.vue2.js +34 -3
- package/dist/esm/components/CnReadinessChecklist/CnReadinessChecklist.vue2.js.map +1 -1
- package/dist/esm/components/CnReadinessChecklist/CnReadinessChecklist.vue3.js +81 -19
- package/dist/esm/components/CnReadinessChecklist/CnReadinessChecklist.vue3.js.map +1 -1
- package/dist/esm/components/CnRecordListWidget/CnRecordListWidget.vue.js +1 -1
- package/dist/esm/components/CnRecordListWidget/CnRecordListWidget.vue2.js +11 -0
- package/dist/esm/components/CnRecordListWidget/CnRecordListWidget.vue2.js.map +1 -1
- package/dist/esm/components/CnRecordListWidget/CnRecordListWidget.vue3.js +112 -88
- package/dist/esm/components/CnRecordListWidget/CnRecordListWidget.vue3.js.map +1 -1
- package/dist/esm/components/CnRevealField/CnRevealField.vue.js +9 -0
- package/dist/esm/components/CnRevealField/CnRevealField.vue.js.map +1 -0
- package/dist/esm/components/CnRevealField/CnRevealField.vue2.js +157 -0
- package/dist/esm/components/CnRevealField/CnRevealField.vue2.js.map +1 -0
- package/dist/esm/components/CnRevealField/CnRevealField.vue3.js +116 -0
- package/dist/esm/components/CnRevealField/CnRevealField.vue3.js.map +1 -0
- package/dist/esm/components/CnStorePage/CnStorePage.vue.js +1 -1
- package/dist/esm/components/CnStorePage/CnStorePage.vue2.js +3 -3
- package/dist/esm/components/CnStorePage/CnStorePage.vue2.js.map +1 -1
- package/dist/esm/components/CnStorePage/CnStorePage.vue3.js +5 -5
- package/dist/esm/components/CnStorePage/CnStorePage.vue3.js.map +1 -1
- package/dist/esm/components/CnStorePage/CnStorePublishDialog.vue.js +1 -1
- package/dist/esm/components/CnStorePage/CnStorePublishDialog.vue2.js +6 -6
- package/dist/esm/components/CnStorePage/CnStorePublishDialog.vue2.js.map +1 -1
- package/dist/esm/components/CnStorePage/CnStorePublishDialog.vue3.js +1 -1
- package/dist/esm/components/CnStorePage/CnStorePublishDialog.vue3.js.map +1 -1
- package/dist/esm/components/CnTextWidget/CnTextWidget.vue.js +1 -1
- package/dist/esm/components/CnTextWidget/CnTextWidget.vue2.js +43 -3
- package/dist/esm/components/CnTextWidget/CnTextWidget.vue2.js.map +1 -1
- package/dist/esm/components/CnTextWidget/CnTextWidget.vue3.js +19 -12
- package/dist/esm/components/CnTextWidget/CnTextWidget.vue3.js.map +1 -1
- package/dist/esm/components/CnTransferCard/CnTransferCard.vue.js +9 -0
- package/dist/esm/components/CnTransferCard/CnTransferCard.vue.js.map +1 -0
- package/dist/esm/components/CnTransferCard/CnTransferCard.vue2.js +87 -0
- package/dist/esm/components/CnTransferCard/CnTransferCard.vue2.js.map +1 -0
- package/dist/esm/components/CnTransferCard/CnTransferCard.vue3.js +126 -0
- package/dist/esm/components/CnTransferCard/CnTransferCard.vue3.js.map +1 -0
- package/dist/esm/components/CnTreeView/CnTreeNode.vue.js +1 -1
- package/dist/esm/components/CnTreeView/CnTreeNode.vue2.js +66 -1
- package/dist/esm/components/CnTreeView/CnTreeNode.vue2.js.map +1 -1
- package/dist/esm/components/CnTreeView/CnTreeNode.vue3.js +129 -29
- package/dist/esm/components/CnTreeView/CnTreeNode.vue3.js.map +1 -1
- package/dist/esm/components/CnTreeView/CnTreeView.vue.js +1 -1
- package/dist/esm/components/CnTreeView/CnTreeView.vue2.js +158 -6
- package/dist/esm/components/CnTreeView/CnTreeView.vue2.js.map +1 -1
- package/dist/esm/components/CnTreeView/CnTreeView.vue3.js +100 -39
- package/dist/esm/components/CnTreeView/CnTreeView.vue3.js.map +1 -1
- package/dist/esm/index.js +8 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/l10n/en.json.js +79 -14
- package/dist/esm/l10n/en.json.js.map +1 -1
- package/dist/esm/l10n/nl.json.js +79 -14
- package/dist/esm/l10n/nl.json.js.map +1 -1
- package/dist/esm/library-style.js +1 -1
- package/dist/esm/nextcloud-vue.css +1162 -523
- package/dist/esm/node_modules/vuedraggable/dist/vuedraggable.umd.js +2 -2
- package/dist/esm/utils/captureLocation.js +32 -0
- package/dist/esm/utils/captureLocation.js.map +1 -0
- package/dist/esm/utils/childRecordTotals.js +157 -0
- package/dist/esm/utils/childRecordTotals.js.map +1 -0
- package/dist/esm/utils/isoDuration.js +51 -1
- package/dist/esm/utils/isoDuration.js.map +1 -1
- package/dist/esm/utils/parentCrumb.js +86 -0
- package/dist/esm/utils/parentCrumb.js.map +1 -0
- package/dist/esm/utils/qr.js +649 -0
- package/dist/esm/utils/qr.js.map +1 -0
- package/dist/esm/utils/schema.js +3 -0
- package/dist/esm/utils/schema.js.map +1 -1
- package/dist/esm/utils/templateVariables.js +54 -0
- package/dist/esm/utils/templateVariables.js.map +1 -0
- package/dist/nextcloud-vue.cjs.js +21125 -15025
- package/dist/nextcloud-vue.cjs.js.map +2 -2
- package/dist/nextcloud-vue.css +1162 -523
- package/l10n/en.json +79 -14
- package/l10n/nl.json +79 -14
- package/package.json +1 -1
- package/src/components/CnActionDialog/CnActionDialog.vue +156 -9
- package/src/components/CnBlockListEditor/CnBlockListEditor.vue +615 -0
- package/src/components/CnBlockListEditor/index.js +9 -0
- package/src/components/CnChecklistRunWidget/CnChecklistRunWidget.vue +377 -10
- package/src/components/CnChildRecordsField/CnChildRecordsField.vue +306 -15
- package/src/components/CnChoiceMatrix/CnChoiceMatrix.vue +710 -0
- package/src/components/CnChoiceMatrix/index.js +9 -0
- package/src/components/CnCountdownWidget/CnCountdownWidget.vue +223 -28
- package/src/components/CnCreateFormWidget/CnCreateFormWidget.vue +97 -6
- package/src/components/CnDataMatrix/CnDataMatrix.vue +304 -17
- package/src/components/CnDetailPage/CnDetailPage.vue +55 -6
- package/src/components/CnDisplayScreen/CnDisplayScreen.vue +308 -0
- package/src/components/CnDisplayScreen/index.js +9 -0
- package/src/components/CnDurationField/CnDurationField.vue +330 -5
- package/src/components/CnFormDialog/CnFormDialog.vue +4 -0
- package/src/components/CnGeoCaptureField/CnGeoCaptureField.vue +148 -0
- package/src/components/CnGeoCaptureField/index.js +9 -0
- package/src/components/CnIndexPage/CnIndexPage.vue +40 -1
- package/src/components/CnMarkdownEditor/CnMarkdownEditor.vue +139 -1
- package/src/components/CnQrCode/CnQrCode.vue +321 -0
- package/src/components/CnQrCode/index.js +9 -0
- package/src/components/CnReadinessChecklist/CnReadinessChecklist.vue +80 -3
- package/src/components/CnRecordListWidget/CnRecordListWidget.vue +34 -1
- package/src/components/CnRevealField/CnRevealField.vue +273 -0
- package/src/components/CnRevealField/index.js +9 -0
- package/src/components/CnStorePage/CnStorePage.vue +8 -8
- package/src/components/CnStorePage/CnStorePublishDialog.vue +7 -7
- package/src/components/CnTextWidget/CnTextWidget.vue +62 -3
- package/src/components/CnTransferCard/CnTransferCard.vue +205 -0
- package/src/components/CnTransferCard/index.js +9 -0
- package/src/components/CnTreeView/CnTreeNode.vue +145 -2
- package/src/components/CnTreeView/CnTreeView.vue +210 -6
- package/src/components/index.js +7 -0
- package/src/index.js +8 -0
- package/src/utils/captureLocation.js +29 -0
- package/src/utils/childRecordTotals.js +153 -0
- package/src/utils/isoDuration.js +50 -0
- package/src/utils/parentCrumb.js +83 -0
- package/src/utils/qr.js +681 -0
- package/src/utils/schema.js +3 -0
- package/src/utils/templateVariables.js +51 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SPDX-FileCopyrightText: 2026 Conduction B.V.
|
|
3
|
+
* SPDX-License-Identifier: EUPL-1.2
|
|
4
|
+
*
|
|
5
|
+
* Arithmetic for the rows of `CnChildRecordsField`: computed columns per row,
|
|
6
|
+
* totals over all rows, and the values a picked source record gives a new row.
|
|
7
|
+
* Formulas go through `evalFormula`, so no `eval` runs.
|
|
8
|
+
*
|
|
9
|
+
* @module utils/childRecordTotals
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { evalFormula } from './evalFormula.js'
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The identifiers a formula names.
|
|
16
|
+
*
|
|
17
|
+
* @param {string} formula The formula.
|
|
18
|
+
* @return {string[]} The identifiers.
|
|
19
|
+
*/
|
|
20
|
+
function identifiersOf(formula) {
|
|
21
|
+
return String(formula || '').match(/[A-Za-z_][A-Za-z0-9_]*/g) || []
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The variables for a formula: every identifier it names, as a number, 0 when
|
|
26
|
+
* the value is empty or no number, so a half-filled row still computes.
|
|
27
|
+
*
|
|
28
|
+
* @param {string} formula The formula.
|
|
29
|
+
* @param {object} values The named values.
|
|
30
|
+
* @return {Object<string, number>} The variables.
|
|
31
|
+
*/
|
|
32
|
+
function varsFor(formula, values) {
|
|
33
|
+
const vars = {}
|
|
34
|
+
for (const id of identifiersOf(formula)) {
|
|
35
|
+
const n = Number(values?.[id])
|
|
36
|
+
vars[id] = Number.isFinite(n) ? n : 0
|
|
37
|
+
}
|
|
38
|
+
return vars
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Evaluate a formula over named values.
|
|
43
|
+
*
|
|
44
|
+
* @param {string} formula The formula (`quantity * price`).
|
|
45
|
+
* @param {object} values The named values.
|
|
46
|
+
* @return {number|null} The result, or null on an invalid formula or a division by zero.
|
|
47
|
+
* @spec openspec/changes/child-records-totals/tasks.md#task-1
|
|
48
|
+
*/
|
|
49
|
+
export function evalOver(formula, values) {
|
|
50
|
+
if (typeof formula !== 'string' || formula.trim() === '') {
|
|
51
|
+
return null
|
|
52
|
+
}
|
|
53
|
+
return evalFormula(formula, varsFor(formula, values))
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The computed values of one row, in order, so a later computed column can
|
|
58
|
+
* name an earlier one.
|
|
59
|
+
*
|
|
60
|
+
* @param {object} row The row.
|
|
61
|
+
* @param {Array<{key: string, formula: string}>} computed The computed columns.
|
|
62
|
+
* @return {Object<string, number|null>} Computed value per key.
|
|
63
|
+
* @spec openspec/changes/child-records-totals/tasks.md#task-1
|
|
64
|
+
*/
|
|
65
|
+
export function computeRow(row, computed) {
|
|
66
|
+
const out = {}
|
|
67
|
+
const scope = { ...(row || {}) }
|
|
68
|
+
for (const col of Array.isArray(computed) ? computed : []) {
|
|
69
|
+
if (!col || !col.key) {
|
|
70
|
+
continue
|
|
71
|
+
}
|
|
72
|
+
const value = evalOver(col.formula, scope)
|
|
73
|
+
out[col.key] = value
|
|
74
|
+
scope[col.key] = value
|
|
75
|
+
}
|
|
76
|
+
return out
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* The row with every computed column marked `store` written into it.
|
|
81
|
+
*
|
|
82
|
+
* @param {object} row The row.
|
|
83
|
+
* @param {Array<{key: string, formula: string, store?: boolean}>} computed The computed columns.
|
|
84
|
+
* @return {object} The row, a new object when something was written.
|
|
85
|
+
* @spec openspec/changes/child-records-totals/tasks.md#task-1
|
|
86
|
+
*/
|
|
87
|
+
export function storeComputed(row, computed) {
|
|
88
|
+
const stored = (Array.isArray(computed) ? computed : []).filter((c) => c && c.key && c.store)
|
|
89
|
+
if (stored.length === 0) {
|
|
90
|
+
return row
|
|
91
|
+
}
|
|
92
|
+
const values = computeRow(row, computed)
|
|
93
|
+
const next = { ...row }
|
|
94
|
+
for (const col of stored) {
|
|
95
|
+
next[col.key] = values[col.key]
|
|
96
|
+
}
|
|
97
|
+
return next
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* The totals over all rows. A total with `sum` adds that formula over every
|
|
102
|
+
* row (a column key is a formula too); a total with `formula` computes over
|
|
103
|
+
* the totals before it (`subtotal + tax`).
|
|
104
|
+
*
|
|
105
|
+
* @param {object[]} rows The rows.
|
|
106
|
+
* @param {Array<{key: string, sum?: string, formula?: string}>} totals The totals.
|
|
107
|
+
* @param {Array<{key: string, formula: string}>} [computed] The computed columns, which `sum` may name.
|
|
108
|
+
* @return {Object<string, number|null>} Total per key.
|
|
109
|
+
* @spec openspec/changes/child-records-totals/tasks.md#task-2
|
|
110
|
+
*/
|
|
111
|
+
export function computeTotals(rows, totals, computed = []) {
|
|
112
|
+
const list = Array.isArray(rows) ? rows : []
|
|
113
|
+
const scoped = list.map((row) => ({ ...(row || {}), ...computeRow(row, computed) }))
|
|
114
|
+
const out = {}
|
|
115
|
+
for (const total of Array.isArray(totals) ? totals : []) {
|
|
116
|
+
if (!total || !total.key) {
|
|
117
|
+
continue
|
|
118
|
+
}
|
|
119
|
+
if (typeof total.sum === 'string' && total.sum !== '') {
|
|
120
|
+
let sum = 0
|
|
121
|
+
let valid = true
|
|
122
|
+
for (const row of scoped) {
|
|
123
|
+
const value = evalOver(total.sum, row)
|
|
124
|
+
if (value === null) {
|
|
125
|
+
valid = false
|
|
126
|
+
break
|
|
127
|
+
}
|
|
128
|
+
sum += value
|
|
129
|
+
}
|
|
130
|
+
out[total.key] = valid ? sum : null
|
|
131
|
+
} else {
|
|
132
|
+
out[total.key] = evalOver(total.formula, out)
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return out
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* The values a picked source record gives a new row. `map` names, per row
|
|
140
|
+
* key, the source key to copy; `@id` copies the source's id (or uuid).
|
|
141
|
+
*
|
|
142
|
+
* @param {object} source The picked record.
|
|
143
|
+
* @param {Object<string, string>} map Row key to source key.
|
|
144
|
+
* @return {object} The new row.
|
|
145
|
+
* @spec openspec/changes/child-records-totals/tasks.md#task-3
|
|
146
|
+
*/
|
|
147
|
+
export function rowFromSource(source, map) {
|
|
148
|
+
const row = {}
|
|
149
|
+
for (const [rowKey, sourceKey] of Object.entries(map || {})) {
|
|
150
|
+
row[rowKey] = sourceKey === '@id' ? (source?.id ?? source?.uuid ?? null) : (source?.[sourceKey] ?? null)
|
|
151
|
+
}
|
|
152
|
+
return row
|
|
153
|
+
}
|
package/src/utils/isoDuration.js
CHANGED
|
@@ -95,3 +95,53 @@ export function durationSeconds(value) {
|
|
|
95
95
|
}
|
|
96
96
|
return Object.keys(p).reduce((sum, k) => sum + p[k] * SECONDS[k], 0)
|
|
97
97
|
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Write a number of seconds as the canonical hours, minutes and seconds.
|
|
101
|
+
*
|
|
102
|
+
* @param {number} seconds The length; negative or fractional parts are dropped.
|
|
103
|
+
* @return {string} `PT1H4M23S`, `PT6M`, `PT0S`.
|
|
104
|
+
*/
|
|
105
|
+
export function secondsToDuration(seconds) {
|
|
106
|
+
const total = Math.max(0, Math.trunc(Number(seconds) || 0))
|
|
107
|
+
const h = Math.floor(total / 3600)
|
|
108
|
+
const m = Math.floor((total % 3600) / 60)
|
|
109
|
+
const s = total % 60
|
|
110
|
+
if (total === 0) {
|
|
111
|
+
return 'PT0S'
|
|
112
|
+
}
|
|
113
|
+
return `PT${h ? `${h}H` : ''}${m ? `${m}M` : ''}${s ? `${s}S` : ''}`
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Show a number of seconds as a clock: `04:23`, or `1:04:23` from an hour.
|
|
118
|
+
*
|
|
119
|
+
* @param {number} seconds The length.
|
|
120
|
+
* @return {string}
|
|
121
|
+
*/
|
|
122
|
+
export function formatClock(seconds) {
|
|
123
|
+
const total = Math.max(0, Math.trunc(Number(seconds) || 0))
|
|
124
|
+
const h = Math.floor(total / 3600)
|
|
125
|
+
const m = String(Math.floor((total % 3600) / 60)).padStart(2, '0')
|
|
126
|
+
const s = String(total % 60).padStart(2, '0')
|
|
127
|
+
return h ? `${h}:${m}:${s}` : `${m}:${s}`
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Read what a user typed as a length: `6` is minutes, `04:23` is minutes and
|
|
132
|
+
* seconds, `1:04:23` adds hours.
|
|
133
|
+
*
|
|
134
|
+
* @param {string} text The typed text.
|
|
135
|
+
* @return {number|null} Seconds, or null when the text is no length.
|
|
136
|
+
*/
|
|
137
|
+
export function parseClock(text) {
|
|
138
|
+
const trimmed = String(text ?? '').trim()
|
|
139
|
+
if (/^\d+$/.test(trimmed)) {
|
|
140
|
+
return Number(trimmed) * 60
|
|
141
|
+
}
|
|
142
|
+
const m = trimmed.match(/^(?:(\d+):)?(\d{1,3}):([0-5]\d)$/)
|
|
143
|
+
if (!m) {
|
|
144
|
+
return null
|
|
145
|
+
}
|
|
146
|
+
return Number(m[1] || 0) * 3600 + Number(m[2]) * 60 + Number(m[3])
|
|
147
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SPDX-FileCopyrightText: 2026 Conduction B.V.
|
|
3
|
+
* SPDX-License-Identifier: EUPL-1.2
|
|
4
|
+
*
|
|
5
|
+
* parentCrumb: the breadcrumb entry for the record a sub-record belongs to.
|
|
6
|
+
*
|
|
7
|
+
* A crumb that carries `parent` names a `visibilityContext` entry of the
|
|
8
|
+
* detail page. The page reads that record beside the loaded one; this
|
|
9
|
+
* helper turns it into a crumb with the parent's label and a link to its
|
|
10
|
+
* page.
|
|
11
|
+
*
|
|
12
|
+
* @module utils/parentCrumb
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Read a dotted path from an object.
|
|
17
|
+
*
|
|
18
|
+
* @param {object|null} obj The object to read.
|
|
19
|
+
* @param {string} path A dotted path, e.g. `identifier` or `@self.name`.
|
|
20
|
+
* @return {unknown} The value, or undefined.
|
|
21
|
+
*/
|
|
22
|
+
function readPath(obj, path) {
|
|
23
|
+
return path.split('.').reduce((o, part) => (o === null || o === undefined ? undefined : o[part]), obj)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* A non-empty string for a value, or ''.
|
|
28
|
+
*
|
|
29
|
+
* @param {unknown} value Any value.
|
|
30
|
+
* @return {string} The text.
|
|
31
|
+
*/
|
|
32
|
+
function text(value) {
|
|
33
|
+
if (typeof value === 'number') {
|
|
34
|
+
return String(value)
|
|
35
|
+
}
|
|
36
|
+
return typeof value === 'string' ? value.trim() : ''
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The crumb for a record's parent.
|
|
41
|
+
*
|
|
42
|
+
* The crumb is dropped (null) when the record holds no reference to a
|
|
43
|
+
* parent. Its label is the parent's `labelField` value, else the parent's
|
|
44
|
+
* name or title, else the crumb's own `label` (translated); without any of
|
|
45
|
+
* those it is dropped too. The link goes to `route` with the parent's id in
|
|
46
|
+
* `param` (default `id`), or to `href` with `{id}` filled in.
|
|
47
|
+
*
|
|
48
|
+
* @param {object} crumb `{ parent, labelField?, label?, route?, params?, param?, href?, icon? }`.
|
|
49
|
+
* @param {Array<{key: string, id: string}>} refs The page's context references.
|
|
50
|
+
* @param {object} rows The context records read so far, by name.
|
|
51
|
+
* @param {(key: string) => string} translate The host translate function.
|
|
52
|
+
* @return {{label: string, to?: object, href?: string, icon?: string}|null} The crumb, or null.
|
|
53
|
+
* @spec openspec/changes/detail-parent-crumb/specs/detail-page/spec.md#requirement-a-sub-record-trail-can-show-its-parent-record
|
|
54
|
+
*/
|
|
55
|
+
export function parentCrumb(crumb, refs, rows, translate) {
|
|
56
|
+
const ref = (refs || []).find((r) => r.key === crumb.parent)
|
|
57
|
+
if (!ref || !ref.id) {
|
|
58
|
+
return null
|
|
59
|
+
}
|
|
60
|
+
const row = rows && rows[crumb.parent] && typeof rows[crumb.parent] === 'object' ? rows[crumb.parent] : null
|
|
61
|
+
let label = ''
|
|
62
|
+
if (row) {
|
|
63
|
+
label = (typeof crumb.labelField === 'string' && crumb.labelField !== '' ? text(readPath(row, crumb.labelField)) : '')
|
|
64
|
+
|| text(readPath(row, '@self.name')) || text(row.name) || text(row.title)
|
|
65
|
+
}
|
|
66
|
+
if (label === '' && typeof crumb.label === 'string' && crumb.label !== '') {
|
|
67
|
+
label = translate(crumb.label)
|
|
68
|
+
}
|
|
69
|
+
if (label === '') {
|
|
70
|
+
return null
|
|
71
|
+
}
|
|
72
|
+
const entry = { label }
|
|
73
|
+
if (typeof crumb.icon === 'string' && crumb.icon !== '') {
|
|
74
|
+
entry.icon = crumb.icon
|
|
75
|
+
}
|
|
76
|
+
if (crumb.route) {
|
|
77
|
+
const param = typeof crumb.param === 'string' && crumb.param !== '' ? crumb.param : 'id'
|
|
78
|
+
entry.to = { name: crumb.route, params: { ...(crumb.params || {}), [param]: ref.id } }
|
|
79
|
+
} else if (typeof crumb.href === 'string' && crumb.href !== '') {
|
|
80
|
+
entry.href = crumb.href.split('{id}').join(encodeURIComponent(ref.id))
|
|
81
|
+
}
|
|
82
|
+
return entry
|
|
83
|
+
}
|