@conduction/nextcloud-vue 2.97.0 → 2.99.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 (160) hide show
  1. package/dist/esm/components/CnActionsMenu/CnActionsMenu.vue2.js +12 -0
  2. package/dist/esm/components/CnActionsMenu/CnActionsMenu.vue2.js.map +1 -1
  3. package/dist/esm/components/CnActionsMenu/CnActionsMenu.vue3.js +11 -2
  4. package/dist/esm/components/CnActionsMenu/CnActionsMenu.vue3.js.map +1 -1
  5. package/dist/esm/components/CnAppRoot/CnAppRoot.vue2.js +17 -0
  6. package/dist/esm/components/CnAppRoot/CnAppRoot.vue2.js.map +1 -1
  7. package/dist/esm/components/CnAppRoot/CnAppRoot.vue3.js.map +1 -1
  8. package/dist/esm/components/CnBreadcrumbs/CnBreadcrumbs.vue.js +1 -1
  9. package/dist/esm/components/CnBreadcrumbs/CnBreadcrumbs.vue2.js.map +1 -1
  10. package/dist/esm/components/CnBreadcrumbs/CnBreadcrumbs.vue3.js +1 -1
  11. package/dist/esm/components/CnBreadcrumbs/CnBreadcrumbs.vue3.js.map +1 -1
  12. package/dist/esm/components/CnChartWidget/CnChartWidget.vue.js +1 -1
  13. package/dist/esm/components/CnChartWidget/CnChartWidget.vue2.js +106 -2
  14. package/dist/esm/components/CnChartWidget/CnChartWidget.vue2.js.map +1 -1
  15. package/dist/esm/components/CnChartWidget/CnChartWidget.vue3.js.map +1 -1
  16. package/dist/esm/components/CnChecklistRunWidget/CnChecklistRunWidget.vue.js +9 -0
  17. package/dist/esm/components/CnChecklistRunWidget/CnChecklistRunWidget.vue.js.map +1 -0
  18. package/dist/esm/components/CnChecklistRunWidget/CnChecklistRunWidget.vue2.js +964 -0
  19. package/dist/esm/components/CnChecklistRunWidget/CnChecklistRunWidget.vue2.js.map +1 -0
  20. package/dist/esm/components/CnChecklistRunWidget/CnChecklistRunWidget.vue3.js +282 -0
  21. package/dist/esm/components/CnChecklistRunWidget/CnChecklistRunWidget.vue3.js.map +1 -0
  22. package/dist/esm/components/CnChecklistRunWidget/index.js +28 -0
  23. package/dist/esm/components/CnChecklistRunWidget/index.js.map +1 -0
  24. package/dist/esm/components/CnDashboardPage/CnDashboardPage.vue.js +1 -1
  25. package/dist/esm/components/CnDashboardPage/CnDashboardPage.vue2.js +1 -0
  26. package/dist/esm/components/CnDashboardPage/CnDashboardPage.vue2.js.map +1 -1
  27. package/dist/esm/components/CnDashboardPage/CnDashboardPage.vue3.js.map +1 -1
  28. package/dist/esm/components/CnDataTable/CnDataTable.vue2.js +26 -8
  29. package/dist/esm/components/CnDataTable/CnDataTable.vue2.js.map +1 -1
  30. package/dist/esm/components/CnDataTable/CnDataTable.vue3.js.map +1 -1
  31. package/dist/esm/components/CnDetailPage/CnDetailPage.vue2.js +188 -5
  32. package/dist/esm/components/CnDetailPage/CnDetailPage.vue2.js.map +1 -1
  33. package/dist/esm/components/CnDetailPage/CnDetailPage.vue3.js +2 -1
  34. package/dist/esm/components/CnDetailPage/CnDetailPage.vue3.js.map +1 -1
  35. package/dist/esm/components/CnFeaturesAndRoadmapView/CnFeaturesAndRoadmapView.vue.js +1 -1
  36. package/dist/esm/components/CnFeaturesAndRoadmapView/CnFeaturesAndRoadmapView.vue2.js +3 -3
  37. package/dist/esm/components/CnFeaturesAndRoadmapView/CnFeaturesAndRoadmapView.vue2.js.map +1 -1
  38. package/dist/esm/components/CnFeaturesAndRoadmapView/CnFeaturesAndRoadmapView.vue3.js.map +1 -1
  39. package/dist/esm/components/CnFeaturesBoard/CnFeaturesBoard.vue.js +1 -1
  40. package/dist/esm/components/CnFeaturesBoard/CnFeaturesBoard.vue2.js +27 -0
  41. package/dist/esm/components/CnFeaturesBoard/CnFeaturesBoard.vue2.js.map +1 -1
  42. package/dist/esm/components/CnFeaturesBoard/CnFeaturesBoard.vue3.js +16 -2
  43. package/dist/esm/components/CnFeaturesBoard/CnFeaturesBoard.vue3.js.map +1 -1
  44. package/dist/esm/components/CnIndexPage/CnIndexPage.vue2.js +43 -3
  45. package/dist/esm/components/CnIndexPage/CnIndexPage.vue2.js.map +1 -1
  46. package/dist/esm/components/CnIndexPage/CnIndexPage.vue3.js.map +1 -1
  47. package/dist/esm/components/CnOrderedListField/CnOrderedListField.vue.js +9 -0
  48. package/dist/esm/components/CnOrderedListField/CnOrderedListField.vue.js.map +1 -0
  49. package/dist/esm/components/CnOrderedListField/CnOrderedListField.vue2.js +239 -0
  50. package/dist/esm/components/CnOrderedListField/CnOrderedListField.vue2.js.map +1 -0
  51. package/dist/esm/components/CnOrderedListField/CnOrderedListField.vue3.js +182 -0
  52. package/dist/esm/components/CnOrderedListField/CnOrderedListField.vue3.js.map +1 -0
  53. package/dist/esm/components/CnSettingsField/CnSettingsField.vue.js +9 -0
  54. package/dist/esm/components/CnSettingsField/CnSettingsField.vue.js.map +1 -0
  55. package/dist/esm/components/CnSettingsField/CnSettingsField.vue2.js +265 -0
  56. package/dist/esm/components/CnSettingsField/CnSettingsField.vue2.js.map +1 -0
  57. package/dist/esm/components/CnSettingsField/CnSettingsField.vue3.js +191 -0
  58. package/dist/esm/components/CnSettingsField/CnSettingsField.vue3.js.map +1 -0
  59. package/dist/esm/components/CnSettingsFieldsSection/CnSettingsFieldsSection.vue.js +9 -0
  60. package/dist/esm/components/CnSettingsFieldsSection/CnSettingsFieldsSection.vue.js.map +1 -0
  61. package/dist/esm/components/CnSettingsFieldsSection/CnSettingsFieldsSection.vue2.js +508 -0
  62. package/dist/esm/components/CnSettingsFieldsSection/CnSettingsFieldsSection.vue2.js.map +1 -0
  63. package/dist/esm/components/CnSettingsFieldsSection/CnSettingsFieldsSection.vue3.js +99 -0
  64. package/dist/esm/components/CnSettingsFieldsSection/CnSettingsFieldsSection.vue3.js.map +1 -0
  65. package/dist/esm/components/CnSettingsPage/CnSettingsPage.vue.js +1 -1
  66. package/dist/esm/components/CnSettingsPage/CnSettingsPage.vue2.js +18 -70
  67. package/dist/esm/components/CnSettingsPage/CnSettingsPage.vue2.js.map +1 -1
  68. package/dist/esm/components/CnSettingsPage/CnSettingsPage.vue3.js +6 -44
  69. package/dist/esm/components/CnSettingsPage/CnSettingsPage.vue3.js.map +1 -1
  70. package/dist/esm/components/CnUserSettingsDialog/CnUserSettingsDialog.vue.js +1 -1
  71. package/dist/esm/components/CnUserSettingsDialog/CnUserSettingsDialog.vue2.js +83 -9
  72. package/dist/esm/components/CnUserSettingsDialog/CnUserSettingsDialog.vue2.js.map +1 -1
  73. package/dist/esm/components/CnUserSettingsDialog/CnUserSettingsDialog.vue3.js +80 -11
  74. package/dist/esm/components/CnUserSettingsDialog/CnUserSettingsDialog.vue3.js.map +1 -1
  75. package/dist/esm/components/CnWidgetGrid/registerDashboardWidgets.js +2 -0
  76. package/dist/esm/components/CnWidgetGrid/registerDashboardWidgets.js.map +1 -1
  77. package/dist/esm/components/CnWorkingCalendarWidget/CnWorkingCalendarWidget.vue.js +9 -0
  78. package/dist/esm/components/CnWorkingCalendarWidget/CnWorkingCalendarWidget.vue.js.map +1 -0
  79. package/dist/esm/components/CnWorkingCalendarWidget/CnWorkingCalendarWidget.vue2.js +472 -0
  80. package/dist/esm/components/CnWorkingCalendarWidget/CnWorkingCalendarWidget.vue2.js.map +1 -0
  81. package/dist/esm/components/CnWorkingCalendarWidget/CnWorkingCalendarWidget.vue3.js +231 -0
  82. package/dist/esm/components/CnWorkingCalendarWidget/CnWorkingCalendarWidget.vue3.js.map +1 -0
  83. package/dist/esm/components/CnWorkingCalendarWidget/index.js +27 -0
  84. package/dist/esm/components/CnWorkingCalendarWidget/index.js.map +1 -0
  85. package/dist/esm/composables/indexSources.js +238 -2
  86. package/dist/esm/composables/indexSources.js.map +1 -1
  87. package/dist/esm/composables/useFlowStore.js +2 -1
  88. package/dist/esm/composables/useFlowStore.js.map +1 -1
  89. package/dist/esm/composables/useOrganisationStore.js +115 -0
  90. package/dist/esm/composables/useOrganisationStore.js.map +1 -0
  91. package/dist/esm/index.js +5 -0
  92. package/dist/esm/index.js.map +1 -1
  93. package/dist/esm/l10n/en.json.js +109 -1
  94. package/dist/esm/l10n/en.json.js.map +1 -1
  95. package/dist/esm/l10n/nl.json.js +138 -1
  96. package/dist/esm/l10n/nl.json.js.map +1 -1
  97. package/dist/esm/library-style.js +1 -1
  98. package/dist/esm/nextcloud-vue.css +1071 -274
  99. package/dist/esm/utils/builtInFormatters.js +34 -1
  100. package/dist/esm/utils/builtInFormatters.js.map +1 -1
  101. package/dist/esm/utils/libraryWidgetKeys.js +2 -0
  102. package/dist/esm/utils/libraryWidgetKeys.js.map +1 -1
  103. package/dist/esm/utils/matrixCells.js +158 -0
  104. package/dist/esm/utils/matrixCells.js.map +1 -0
  105. package/dist/esm/utils/nextcloudDirectory.js +121 -0
  106. package/dist/esm/utils/nextcloudDirectory.js.map +1 -0
  107. package/dist/esm/utils/validateManifestV2.compiled.js +3 -3
  108. package/dist/esm/utils/validateManifestV2.compiled.js.map +1 -1
  109. package/dist/esm/utils/workingCalendarMonth.js +85 -0
  110. package/dist/esm/utils/workingCalendarMonth.js.map +1 -0
  111. package/dist/nextcloud-vue.cjs.js +14888 -10014
  112. package/dist/nextcloud-vue.cjs.js.map +2 -2
  113. package/dist/nextcloud-vue.css +1071 -274
  114. package/l10n/en.json +109 -1
  115. package/l10n/nl.json +138 -1
  116. package/package.json +2 -2
  117. package/scripts/merge-l10n.js +196 -0
  118. package/src/components/CnActionsMenu/CnActionsMenu.vue +14 -1
  119. package/src/components/CnAppRoot/CnAppRoot.md +1 -0
  120. package/src/components/CnAppRoot/CnAppRoot.vue +17 -0
  121. package/src/components/CnBreadcrumbs/CnBreadcrumbs.vue +1 -0
  122. package/src/components/CnChartWidget/CnChartWidget.md +2 -1
  123. package/src/components/CnChartWidget/CnChartWidget.vue +106 -2
  124. package/src/components/CnChecklistRunWidget/CnChecklistRunWidget.vue +1269 -0
  125. package/src/components/CnChecklistRunWidget/index.js +27 -0
  126. package/src/components/CnDashboardPage/CnDashboardPage.vue +1 -0
  127. package/src/components/CnDataTable/CnDataTable.vue +26 -8
  128. package/src/components/CnDetailPage/CnDetailPage.md +48 -0
  129. package/src/components/CnDetailPage/CnDetailPage.vue +189 -5
  130. package/src/components/CnFeaturesAndRoadmapView/CnFeaturesAndRoadmapView.vue +3 -3
  131. package/src/components/CnFeaturesBoard/CnFeaturesBoard.vue +38 -2
  132. package/src/components/CnIndexPage/CnIndexPage.md +28 -0
  133. package/src/components/CnIndexPage/CnIndexPage.vue +43 -3
  134. package/src/components/CnOrderedListField/CnOrderedListField.vue +458 -0
  135. package/src/components/CnOrderedListField/index.js +7 -0
  136. package/src/components/CnSettingsField/CnSettingsField.vue +449 -0
  137. package/src/components/CnSettingsField/index.js +4 -0
  138. package/src/components/CnSettingsFieldsSection/CnSettingsFieldsSection.vue +613 -0
  139. package/src/components/CnSettingsFieldsSection/index.js +4 -0
  140. package/src/components/CnSettingsPage/CnSettingsPage.vue +6 -86
  141. package/src/components/CnUserSettingsDialog/CnUserSettingsDialog.vue +139 -10
  142. package/src/components/CnWidgetGrid/registerDashboardWidgets.js +2 -0
  143. package/src/components/CnWorkingCalendarWidget/CnWorkingCalendarWidget.vue +725 -0
  144. package/src/components/CnWorkingCalendarWidget/index.js +26 -0
  145. package/src/components/index.js +5 -0
  146. package/src/composables/indexSources.js +237 -1
  147. package/src/composables/useFlowStore.js +2 -1
  148. package/src/composables/useOrganisationStore.js +111 -0
  149. package/src/css/badge.css +32 -16
  150. package/src/css/look-board-detail.css +80 -8
  151. package/src/css/look-board-index.css +52 -8
  152. package/src/css/look-board.css +219 -1
  153. package/src/index.js +5 -0
  154. package/src/schemas/app-manifest-v2.schema.json +33 -3
  155. package/src/utils/builtInFormatters.js +33 -0
  156. package/src/utils/libraryWidgetKeys.js +2 -0
  157. package/src/utils/matrixCells.js +154 -0
  158. package/src/utils/nextcloudDirectory.js +117 -0
  159. package/src/utils/validateManifestV2.compiled.js +3 -3
  160. package/src/utils/workingCalendarMonth.js +82 -0
@@ -0,0 +1,613 @@
1
+ <!--
2
+ - SPDX-FileCopyrightText: 2026 Conduction B.V.
3
+ - SPDX-License-Identifier: EUPL-1.2
4
+ -->
5
+
6
+ <template>
7
+ <CnSettingsSection
8
+ :name="name"
9
+ :description="description"
10
+ :docUrl="docUrl"
11
+ :wide="wide"
12
+ :loading="loading"
13
+ :error="loadError !== ''"
14
+ :errorMessage="loadError"
15
+ :onRetry="load"
16
+ data-testid="cn-settings-fields-section">
17
+ <form v-if="!loading && loadError === ''"
18
+ class="cn-settings-fields"
19
+ novalidate
20
+ @submit.prevent="save">
21
+ <div class="cn-settings-fields__grid" :class="`cn-settings-fields__grid--${columnCount}`">
22
+ <CnSettingsField
23
+ v-for="field in resolvedFields"
24
+ :key="field.key"
25
+ class="cn-settings-fields__field"
26
+ :class="{ 'cn-settings-fields__field--wide': field.wide }"
27
+ :field="field"
28
+ :modelValue="form[field.key]"
29
+ :error="errors[field.key] || unreadable[field.key] || ''"
30
+ :hint="field.hint"
31
+ @update:modelValue="setValue(field, $event)"
32
+ @uploaded="onUploaded(field, $event)" />
33
+ </div>
34
+
35
+ <NcNoteCard v-if="notice"
36
+ :type="notice.type"
37
+ :role="notice.type === 'error' ? 'alert' : 'status'"
38
+ data-testid="cn-settings-fields-notice">
39
+ {{ notice.text }}
40
+ </NcNoteCard>
41
+
42
+ <div class="cn-settings-section__save cn-settings-fields__save">
43
+ <span v-if="dirty" class="cn-settings-fields__dirty" data-testid="cn-settings-fields-dirty">
44
+ {{ t('nextcloud-vue', 'Unsaved changes') }}
45
+ </span>
46
+ <NcButton
47
+ variant="primary"
48
+ type="submit"
49
+ :disabled="saving || !dirty"
50
+ data-testid="cn-settings-fields-save">
51
+ <template v-if="saving" #icon>
52
+ <NcLoadingIcon :size="20" />
53
+ </template>
54
+ {{ resolvedSaveLabel }}
55
+ </NcButton>
56
+ </div>
57
+ </form>
58
+ </CnSettingsSection>
59
+ </template>
60
+
61
+ <script>
62
+ import axios from '@nextcloud/axios'
63
+ import { translate as t } from '@nextcloud/l10n'
64
+ import { NcButton, NcLoadingIcon, NcNoteCard } from '@nextcloud/vue'
65
+ import { prefixUrl } from '../../utils/headers.js'
66
+ import { readPath } from '../../utils/readPath.js'
67
+ import { serverErrorMessage } from '../../utils/serverErrorMessage.js'
68
+ import { CnSettingsField } from '../CnSettingsField/index.js'
69
+ import { CnSettingsSection } from '../CnSettingsSection/index.js'
70
+
71
+ /**
72
+ * Up to two initials of a name, for an image field without an image.
73
+ *
74
+ * @param {unknown} name The name.
75
+ * @return {string}
76
+ */
77
+ function initialsOf(name) {
78
+ return String(name || '').trim().split(/\s+/).filter(Boolean).slice(0, 2).map((word) => word[0].toUpperCase()).join('')
79
+ }
80
+
81
+ /**
82
+ * CnSettingsFieldsSection - a settings section declared as fields: it reads
83
+ * the app's settings, draws the fields in one to three columns, and saves
84
+ * them with ONE Save button for the section.
85
+ *
86
+ * It reads `GET url` (default `/apps/<appId>/api/settings`) and writes the
87
+ * section's fields with `PUT saveUrl` (default the same url). The Save button
88
+ * is on while something changed ("Unsaved changes"); a save checks the
89
+ * fields first (required, pattern, min, max) and marks each failing field,
90
+ * then says it saved or why it did not. A `secret` field never shows the
91
+ * stored value: it says a value is stored, and is sent only when something
92
+ * was typed.
93
+ *
94
+ * It renders inside CnAdminSettingsShell and CnSettingsPage, in the default
95
+ * and the board look.
96
+ *
97
+ * ```vue
98
+ * <CnSettingsFieldsSection
99
+ * app-id="myapp"
100
+ * name="Connection"
101
+ * :columns="2"
102
+ * :fields="[
103
+ * { key: 'baseUrl', label: 'Server address', required: true, pattern: '^https://', patternMessage: 'Starts with https://' },
104
+ * { key: 'apiKey', label: 'API key', type: 'secret' },
105
+ * { key: 'mode', label: 'Mode', type: 'select', options: [{ value: 'live', label: 'Live' }, { value: 'test', label: 'Test' }] },
106
+ * { key: 'enabled', label: 'Enabled', type: 'switch', hint: 'Off stops every call.' },
107
+ * ]" />
108
+ * ```
109
+ */
110
+ export default {
111
+ name: 'CnSettingsFieldsSection',
112
+
113
+ components: { CnSettingsField, CnSettingsSection, NcButton, NcLoadingIcon, NcNoteCard },
114
+
115
+ inject: {
116
+ /** The app's translate function; identity outside CnAppRoot. */
117
+ cnTranslate: { default: () => (key) => key },
118
+ },
119
+
120
+ props: {
121
+ /** The section title. */
122
+ name: {
123
+ type: String,
124
+ required: true,
125
+ },
126
+
127
+ /** The line under the title. */
128
+ description: {
129
+ type: String,
130
+ default: '',
131
+ },
132
+
133
+ /** A documentation link beside the title. */
134
+ docUrl: {
135
+ type: String,
136
+ default: '',
137
+ },
138
+
139
+ /** Span the whole settings grid in the board look. */
140
+ wide: {
141
+ type: Boolean,
142
+ default: false,
143
+ },
144
+
145
+ /**
146
+ * The fields: `[{ key, label, type?, hint?, placeholder?, required?,
147
+ * pattern?, patternMessage?, min?, max?, rows?, options?, optionsUrl?,
148
+ * optionsPath?, optionLabel?, optionValue?, default?, readOnly?, wide?,
149
+ * url?, valuePath?, saveUrl?, saveMethod?, saveKey?, uploadUrl?,
150
+ * uploadField?, uploadParams?, uploadValuePath?, initials?, initialsFrom? }]`.
151
+ * `type` is `text` (default), `textarea`, `number`, `switch`, `select`,
152
+ * `secret` or `image`. `key` names the setting; a dotted key reads a
153
+ * nested value and is written as written. A field with its own `url`
154
+ * is read there (at `valuePath`, default its key) and saved to its
155
+ * `saveUrl` (default that `url`) with `saveMethod` (default POST) under
156
+ * `saveKey` (default its key), so one section can hold the settings of
157
+ * several apps. An `image` uploads at once to `uploadUrl`. Labels,
158
+ * hints, placeholders and messages go through the app's translate
159
+ * function.
160
+ *
161
+ * @type {Array<object>}
162
+ * @spec openspec/changes/settings-fields-section/specs/settings-fields-section/spec.md#requirement-a-section-declared-as-fields-reads-and-saves-the-apps-settings
163
+ */
164
+ fields: {
165
+ type: Array,
166
+ required: true,
167
+ },
168
+
169
+ /** Columns of the field grid: 1, 2 or 3. A narrow card stacks them. */
170
+ columns: {
171
+ type: Number,
172
+ default: 1,
173
+ validator: (value) => [1, 2, 3].includes(value),
174
+ },
175
+
176
+ /** The app id, for the default url `/apps/<appId>/api/settings`. */
177
+ appId: {
178
+ type: String,
179
+ default: '',
180
+ },
181
+
182
+ /** Where the settings are read (`GET`); app-absolute or a full URL. */
183
+ url: {
184
+ type: String,
185
+ default: '',
186
+ },
187
+
188
+ /** Where the section saves; defaults to `url`. */
189
+ saveUrl: {
190
+ type: String,
191
+ default: '',
192
+ },
193
+
194
+ /** The method of the save request. */
195
+ saveMethod: {
196
+ type: String,
197
+ default: 'PUT',
198
+ validator: (value) => ['PUT', 'POST', 'PATCH'].includes(String(value).toUpperCase()),
199
+ },
200
+
201
+ /** A dotted path to the values in the GET answer; empty reads the answer itself. */
202
+ valuesPath: {
203
+ type: String,
204
+ default: '',
205
+ },
206
+
207
+ /** The Save button's label. Defaults to "Save". */
208
+ saveLabel: {
209
+ type: String,
210
+ default: '',
211
+ },
212
+ },
213
+
214
+ emits: ['saved', 'save-error'],
215
+
216
+ data() {
217
+ return {
218
+ form: {},
219
+ baseline: {},
220
+ storedSecrets: {},
221
+ // Field key to the message of a read target that failed.
222
+ unreadable: {},
223
+ errors: {},
224
+ loading: true,
225
+ loadError: '',
226
+ saving: false,
227
+ notice: null,
228
+ }
229
+ },
230
+
231
+ computed: {
232
+ /** @return {number} The column count, 1 to 3. */
233
+ columnCount() {
234
+ return [1, 2, 3].includes(this.columns) ? this.columns : 1
235
+ },
236
+
237
+ /** @return {string} Where the settings are read: `url`, else the app's settings endpoint. */
238
+ readTarget() {
239
+ return this.url || (this.appId ? `/apps/${this.appId}/api/settings` : '')
240
+ },
241
+
242
+ /** @return {string} Where the section saves: `saveUrl`, else the read target. */
243
+ writeTarget() {
244
+ return this.saveUrl || this.readTarget
245
+ },
246
+
247
+ /**
248
+ * The declared fields with their text translated and a secret's stored state.
249
+ *
250
+ * @return {Array<object>}
251
+ */
252
+ resolvedFields() {
253
+ return (Array.isArray(this.fields) ? this.fields : [])
254
+ .filter((field) => field && typeof field.key === 'string' && field.key !== '')
255
+ .map((field) => ({
256
+ ...field,
257
+ label: this.tr(field.label || field.key),
258
+ hint: this.tr(field.hint || ''),
259
+ placeholder: this.tr(field.placeholder || ''),
260
+ secretSet: field.type === 'secret' ? !!this.storedSecrets[field.key] : undefined,
261
+ initials: field.type === 'image' ? initialsOf(field.initialsFrom ? this.form[field.initialsFrom] : field.initials) : undefined,
262
+ readOnly: field.readOnly || !!this.unreadable[field.key],
263
+ }))
264
+ },
265
+
266
+ /**
267
+ * Whether something changed since the last load or save.
268
+ *
269
+ * @return {boolean}
270
+ * @spec openspec/changes/settings-fields-section/specs/settings-fields-section/spec.md#requirement-one-save-per-section-with-a-dirty-state
271
+ */
272
+ dirty() {
273
+ return this.resolvedFields.some((field) => field.type !== 'image' && !this.same(this.form[field.key], this.baseline[field.key]))
274
+ },
275
+
276
+ /** @return {string} The Save button's label. */
277
+ resolvedSaveLabel() {
278
+ return this.saveLabel ? this.tr(this.saveLabel) : t('nextcloud-vue', 'Save')
279
+ },
280
+ },
281
+
282
+ mounted() {
283
+ this.load()
284
+ },
285
+
286
+ methods: {
287
+ t,
288
+
289
+ /**
290
+ * @param {string} value A declared string.
291
+ * @return {string} It through the app's translate function.
292
+ */
293
+ tr(value) {
294
+ return typeof value === 'string' && value !== '' ? this.cnTranslate(value) : (value || '')
295
+ },
296
+
297
+ /**
298
+ * @param {unknown} a A value.
299
+ * @param {unknown} b Another.
300
+ * @return {boolean} Whether they count as the same setting.
301
+ */
302
+ same(a, b) {
303
+ const empty = (v) => v === null || v === undefined || v === ''
304
+ if (empty(a) && empty(b)) {
305
+ return true
306
+ }
307
+ return JSON.stringify(a) === JSON.stringify(b)
308
+ },
309
+
310
+ /**
311
+ * Change a field's value; its error goes until the next save.
312
+ *
313
+ * @param {object} field The field.
314
+ * @param {unknown} value The value.
315
+ * @return {void}
316
+ */
317
+ setValue(field, value) {
318
+ this.form = { ...this.form, [field.key]: value }
319
+ if (this.errors[field.key]) {
320
+ const { [field.key]: _gone, ...rest } = this.errors
321
+ this.errors = rest
322
+ }
323
+ this.notice = null
324
+ },
325
+
326
+ /**
327
+ * Read the settings and fill the fields; a secret's value is never put
328
+ * in the form, only whether one is stored.
329
+ *
330
+ * @return {Promise<void>}
331
+ */
332
+ async load() {
333
+ this.loading = true
334
+ this.loadError = ''
335
+ try {
336
+ // One GET per distinct read target; the section's own target must
337
+ // answer, a field's own target may fail on its own.
338
+ const targets = [...new Set(this.fields
339
+ .filter((field) => field && field.key)
340
+ .map((field) => this.readUrlOf(field))
341
+ .filter(Boolean))]
342
+ const answers = {}
343
+ const failures = {}
344
+ await Promise.all(targets.map(async (target) => {
345
+ try {
346
+ const response = await axios.get(prefixUrl(target))
347
+ answers[target] = response?.data ?? {}
348
+ } catch (error) {
349
+ failures[target] = error
350
+ }
351
+ }))
352
+ if (this.readTarget && failures[this.readTarget]) {
353
+ throw failures[this.readTarget]
354
+ }
355
+ const form = {}
356
+ const stored = {}
357
+ const unreadable = {}
358
+ for (const field of this.fields || []) {
359
+ if (!field || !field.key) {
360
+ continue
361
+ }
362
+ const target = this.readUrlOf(field)
363
+ if (target && failures[target]) {
364
+ unreadable[field.key] = t('nextcloud-vue', 'This value could not be loaded: {reason}', { reason: serverErrorMessage(failures[target]) })
365
+ }
366
+ const raw = this.readValue(field, target ? answers[target] : null)
367
+ if (field.type === 'secret') {
368
+ stored[field.key] = raw !== null && raw !== undefined && raw !== '' && raw !== false
369
+ form[field.key] = ''
370
+ continue
371
+ }
372
+ form[field.key] = raw === undefined ? (field.default ?? (field.type === 'switch' ? false : '')) : raw
373
+ }
374
+ this.form = form
375
+ this.baseline = { ...form }
376
+ this.storedSecrets = stored
377
+ this.unreadable = unreadable
378
+ this.errors = {}
379
+ } catch (error) {
380
+ this.loadError = t('nextcloud-vue', 'The settings could not be loaded: {reason}', { reason: serverErrorMessage(error) })
381
+ } finally {
382
+ this.loading = false
383
+ }
384
+ },
385
+
386
+ /**
387
+ * Where a field is read: its own `url`, else the section's.
388
+ *
389
+ * @param {object} field The field.
390
+ * @return {string}
391
+ * @spec openspec/changes/settings-fields-section/specs/settings-fields-section/spec.md#requirement-a-field-can-read-and-save-elsewhere
392
+ */
393
+ readUrlOf(field) {
394
+ return field.url || this.readTarget
395
+ },
396
+
397
+ /**
398
+ * A field's value in its read answer: at its `valuePath` (a field with its
399
+ * own `url`), else at the section's `valuesPath`, then its `key`.
400
+ *
401
+ * @param {object} field The field.
402
+ * @param {object|null} data The answer of the field's read target.
403
+ * @return {unknown}
404
+ */
405
+ readValue(field, data) {
406
+ if (!data || typeof data !== 'object') {
407
+ return undefined
408
+ }
409
+ if (field.url) {
410
+ return readPath(data, field.valuePath || field.key)
411
+ }
412
+ const values = (this.valuesPath ? readPath(data, this.valuesPath) : data) || {}
413
+ return Object.hasOwn(values, field.key) ? values[field.key] : readPath(values, field.key)
414
+ },
415
+
416
+ /**
417
+ * Check the fields: required, pattern, and a number's min and max.
418
+ *
419
+ * @return {object} Field key to message; empty when all pass.
420
+ * @spec openspec/changes/settings-fields-section/specs/settings-fields-section/spec.md#requirement-a-failing-field-says-why
421
+ */
422
+ validate() {
423
+ const errors = {}
424
+ for (const field of this.resolvedFields) {
425
+ const value = this.form[field.key]
426
+ const empty = value === null || value === undefined || value === ''
427
+ if (field.type === 'switch' || field.type === 'image' || this.unreadable[field.key]) {
428
+ continue
429
+ }
430
+ if (field.required && empty && !(field.type === 'secret' && field.secretSet)) {
431
+ errors[field.key] = t('nextcloud-vue', '{field} is required.', { field: field.label })
432
+ continue
433
+ }
434
+ if (empty) {
435
+ continue
436
+ }
437
+ if (field.pattern && !new RegExp(field.pattern).test(String(value))) {
438
+ errors[field.key] = field.patternMessage ? this.tr(field.patternMessage) : t('nextcloud-vue', '{field} is not in the right form.', { field: field.label })
439
+ continue
440
+ }
441
+ if (field.type === 'number') {
442
+ const number = Number(value)
443
+ if (Number.isNaN(number)) {
444
+ errors[field.key] = t('nextcloud-vue', '{field} must be a number.', { field: field.label })
445
+ } else if (field.min !== undefined && number < field.min) {
446
+ errors[field.key] = t('nextcloud-vue', '{field} must be at least {min}.', { field: field.label, min: field.min })
447
+ } else if (field.max !== undefined && number > field.max) {
448
+ errors[field.key] = t('nextcloud-vue', '{field} must be at most {max}.', { field: field.label, max: field.max })
449
+ }
450
+ }
451
+ }
452
+ return errors
453
+ },
454
+
455
+ /**
456
+ * Save the section's fields in one request, after checking them. A
457
+ * secret is sent only when something was typed.
458
+ *
459
+ * @return {Promise<void>}
460
+ * @spec openspec/changes/settings-fields-section/specs/settings-fields-section/spec.md#requirement-one-save-per-section-with-a-dirty-state
461
+ */
462
+ async save() {
463
+ if (this.saving) {
464
+ return
465
+ }
466
+ this.errors = this.validate()
467
+ const failing = Object.keys(this.errors)
468
+ if (failing.length > 0) {
469
+ this.notice = { type: 'error', text: t('nextcloud-vue', 'Check the marked fields.') }
470
+ this.$nextTick(() => {
471
+ const el = this.$el?.querySelector?.('[aria-invalid="true"], .cn-settings-field__error')
472
+ const control = el?.closest?.('.cn-settings-field')?.querySelector?.('input, textarea, [role="combobox"]')
473
+ control?.focus?.()
474
+ })
475
+ return
476
+ }
477
+ // The changed fields, one request per save target, each carrying its
478
+ // own fields under their `saveKey`. A secret goes only when typed; an
479
+ // image is uploaded on its own; a field that could not be read is left out.
480
+ const groups = new Map()
481
+ for (const field of this.resolvedFields) {
482
+ const value = this.form[field.key]
483
+ if (field.type === 'image' || this.unreadable[field.key] || this.same(value, this.baseline[field.key])) {
484
+ continue
485
+ }
486
+ if (field.type === 'secret' && (value === '' || value === null || value === undefined)) {
487
+ continue
488
+ }
489
+ const url = field.saveUrl || (field.url ? field.url : this.writeTarget)
490
+ const method = String(field.saveMethod || (field.saveUrl || field.url ? 'POST' : this.saveMethod)).toLowerCase()
491
+ const id = `${method} ${url}`
492
+ if (!groups.has(id)) {
493
+ groups.set(id, { url, method, fields: [], data: {} })
494
+ }
495
+ const group = groups.get(id)
496
+ group.fields.push(field)
497
+ group.data[field.saveKey || field.key] = value
498
+ }
499
+ this.saving = true
500
+ this.notice = null
501
+ const failed = []
502
+ const sent = {}
503
+ for (const group of groups.values()) {
504
+ try {
505
+ await axios.request({ url: prefixUrl(group.url), method: group.method, data: group.data })
506
+ Object.assign(sent, group.data)
507
+ this.acceptSaved(group.fields)
508
+ } catch (error) {
509
+ failed.push({ group, error })
510
+ }
511
+ }
512
+ this.saving = false
513
+ if (failed.length === 0) {
514
+ this.notice = { type: 'success', text: t('nextcloud-vue', 'Saved.') }
515
+ /**
516
+ * @event saved The section saved. Payload: what was sent, by save key.
517
+ */
518
+ this.$emit('saved', sent)
519
+ return
520
+ }
521
+ const reasons = failed.map(({ group, error }) => (groups.size > 1
522
+ ? t('nextcloud-vue', '{fields}: {reason}', { fields: group.fields.map((field) => field.label).join(', '), reason: serverErrorMessage(error) })
523
+ : serverErrorMessage(error)))
524
+ this.notice = { type: 'error', text: t('nextcloud-vue', 'The settings could not be saved: {reason}', { reason: reasons.join('; ') }) }
525
+ /**
526
+ * @event save-error A save request failed. Payload: the first error.
527
+ */
528
+ this.$emit('save-error', failed[0].error)
529
+ },
530
+
531
+ /**
532
+ * Take saved fields as the new baseline; a saved secret reads as stored.
533
+ *
534
+ * @param {Array<object>} fields The fields that saved.
535
+ * @return {void}
536
+ */
537
+ acceptSaved(fields) {
538
+ const form = { ...this.form }
539
+ const baseline = { ...this.baseline }
540
+ const stored = { ...this.storedSecrets }
541
+ for (const field of fields) {
542
+ if (field.type === 'secret') {
543
+ stored[field.key] = true
544
+ form[field.key] = ''
545
+ }
546
+ baseline[field.key] = form[field.key]
547
+ }
548
+ this.form = form
549
+ this.baseline = baseline
550
+ this.storedSecrets = stored
551
+ },
552
+
553
+ /**
554
+ * An image field uploaded a file: its new value is the baseline too.
555
+ *
556
+ * @param {object} field The field.
557
+ * @param {string} value The new image url.
558
+ * @return {void}
559
+ */
560
+ onUploaded(field, value) {
561
+ this.form = { ...this.form, [field.key]: value }
562
+ this.baseline = { ...this.baseline, [field.key]: value }
563
+ this.notice = { type: 'success', text: t('nextcloud-vue', 'Saved.') }
564
+ },
565
+ },
566
+ }
567
+ </script>
568
+
569
+ <style scoped>
570
+ .cn-settings-fields {
571
+ display: flex;
572
+ flex-direction: column;
573
+ gap: 16px;
574
+ container-type: inline-size;
575
+ }
576
+
577
+ .cn-settings-fields__grid {
578
+ display: grid;
579
+ grid-template-columns: minmax(0, 1fr);
580
+ gap: 16px 20px;
581
+ }
582
+
583
+ /* Two or three columns where the card is wide enough; stacked otherwise. */
584
+ @container (min-width: 520px) {
585
+ .cn-settings-fields__grid--2,
586
+ .cn-settings-fields__grid--3 {
587
+ grid-template-columns: repeat(2, minmax(0, 1fr));
588
+ }
589
+ }
590
+
591
+ @container (min-width: 780px) {
592
+ .cn-settings-fields__grid--3 {
593
+ grid-template-columns: repeat(3, minmax(0, 1fr));
594
+ }
595
+ }
596
+
597
+ .cn-settings-fields__field--wide {
598
+ grid-column: 1 / -1;
599
+ }
600
+
601
+ .cn-settings-fields__save {
602
+ display: flex;
603
+ flex-wrap: wrap;
604
+ align-items: center;
605
+ justify-content: flex-end;
606
+ gap: 12px;
607
+ }
608
+
609
+ .cn-settings-fields__dirty {
610
+ font-size: 14px;
611
+ color: var(--color-text-maxcontrast);
612
+ }
613
+ </style>
@@ -0,0 +1,4 @@
1
+ import CnSettingsFieldsSection from './CnSettingsFieldsSection.vue'
2
+
3
+ export default CnSettingsFieldsSection
4
+ export { CnSettingsFieldsSection }