@live-change/frontend-auto-form 0.9.6 → 0.9.7

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.
@@ -1,17 +1,48 @@
1
1
  <template>
2
-
2
+ <div class="flex flex-row justify-content-between align-items-center mt-3">
3
+ <div class="flex flex-column">
4
+ <div v-if="draftChanged" class="text-sm text-500 mr-2">
5
+ Draft changed
6
+ </div>
7
+ <div v-if="savingDraft" class="text-500 mr-2">
8
+ <i class="pi pi-spin pi-spinner" style="font-size: 2rem"></i>
9
+ <span>Saving draft...</span>
10
+ </div>
11
+ <div v-if="validationResult" class="font-semibold p-error mr-2">
12
+ Before saving, please correct the errors above.
13
+ </div>
14
+ </div>
15
+ <div class="flex flex-row">
16
+ <slot name="submit" v-if="!validationResult">
17
+ <div v-if="changed" class="ml-2">
18
+ <Button type="submit" label="Save" class="" icon="pi pi-save" />
19
+ </div>
20
+ <div v-else class="flex flex-row align-items-center ml-2">
21
+ <div class="mr-2">
22
+ No changes to save.
23
+ </div>
24
+ <Button type="submit" label="Save" class="" icon="pi pi-save" disabled />
25
+ </div>
26
+ </slot>
27
+ <slot name="reset" v-if="resetButton">
28
+ <div v-if="changed">
29
+ <Button label="Reset" class="ml-2" icon="pi pi-eraser" @click="editor.reset" />
30
+ </div>
31
+ </slot>
32
+ </div>
33
+ </div>
3
34
  </template>
4
35
 
5
36
  <script setup>
6
37
 
7
- import { ref, computed, onMounted, defineProps, defineEmits, toRefs } from 'vue'
38
+ import { ref, computed, onMounted, defineProps, defineEmits, toRefs, getCurrentInstance } from 'vue'
8
39
 
9
40
  const props = defineProps({
10
41
  editor: {
11
42
  type: Object,
12
43
  required: true,
13
44
  },
14
- discardDraft: {
45
+ resetButton: {
15
46
  type: Boolean,
16
47
  required: true,
17
48
  },
@@ -24,9 +55,29 @@
24
55
  default: ''
25
56
  }
26
57
  })
27
- const { editor, discardDraft, options, i18n } = toRefs(props)
58
+ const { editor, resetButton, options, i18n } = toRefs(props)
59
+
60
+ const draftEnabled = computed(() => !!editor.value.discardDraft)
61
+ const model = computed(() => editor.value.model)
62
+
63
+ const changed = computed(() => editor.value.changed.value)
28
64
 
65
+ const draftChanged = computed(() => editor.value.draftChanged?.value)
66
+ const savingDraft = computed(() => editor.value.savingDraft?.value)
67
+ const sourceChanged = computed(() => editor.value.sourceChanged?.value)
68
+ const saving = computed(() => editor.value.saving?.value)
29
69
 
70
+ const appContext = getCurrentInstance().appContext
71
+
72
+ import { validateData } from "@live-change/vue3-components"
73
+ const validationResult = computed(() => {
74
+ const currentValue = editor.value.value.value
75
+ const validationResult = validateData(model.value, currentValue, 'validation', appContext,
76
+ props.propName, props.rootValue, true)
77
+ const softValidationResult = validateData(model.value, currentValue, 'softValidation', appContext,
78
+ props.propName, props.rootValue, true)
79
+ return validationResult || softValidationResult
80
+ })
30
81
 
31
82
  </script>
32
83
 
@@ -6,7 +6,7 @@
6
6
  v-model="editor.value.value"
7
7
  :rootValue="editor.value.value"
8
8
  :i18n="i18n" />
9
- <EditorButtons :editor="editor" discard-draft />
9
+ <EditorButtons :editor="editor" reset-button />
10
10
  </div>
11
11
  </div>
12
12
  </template>
@@ -24,10 +24,12 @@ export default function editorData(options) {
24
24
  discardedDraftToast = "Draft discarded",
25
25
  saveDraftErrorToast = "Error saving draft",
26
26
  saveErrorToast = "Error saving",
27
+ resetToast = "Reset done",
27
28
 
28
29
  onSaved = () => {},
29
30
  onDraftSaved = () => {},
30
31
  onDraftDiscarded = () => {},
32
+ onReset = () => {},
31
33
  onSaveError = () => {},
32
34
  onCreated = (createResult) => {},
33
35
 
@@ -151,7 +153,7 @@ export default function editorData(options) {
151
153
  })
152
154
 
153
155
  const changed = computed(() =>
154
- JSON.stringify(editableSavedData.value) !== JSON.stringify(synchronizedData.value.value))
156
+ JSON.stringify(editableSavedData.value ?? {}) !== JSON.stringify(synchronizedData.value.value))
155
157
  const sourceChanged = computed(() =>
156
158
  JSON.stringify(draftData.value.from) !== JSON.stringify(editableSavedData.value))
157
159
 
@@ -171,11 +173,22 @@ export default function editorData(options) {
171
173
  if(toast && discardedDraftToast) toast.add({ severity: 'info', summary: discardedDraftToast, life: 1500 })
172
174
  }
173
175
 
176
+ async function reset() {
177
+ const discardPromise = removeDraftAction(draftIdentifiers)
178
+ if(workingZone)
179
+ workingZone.addPromise('discardDraft:'+serviceName+':'+modelName, discardPromise)
180
+ await discardPromise
181
+ synchronizedData.value.value = editableSavedData.value || defaultData(model)
182
+ if(toast && discardedDraftToast) toast.add({ severity: 'info', summary: resetToast, life: 1500 })
183
+ onReset()
184
+ }
185
+
174
186
  return {
175
187
  value: synchronizedData.value,
176
188
  changed,
177
189
  save,
178
190
  saving,
191
+ reset,
179
192
  discardDraft,
180
193
  model,
181
194
  resetOnError: false,
@@ -207,12 +220,19 @@ export default function editorData(options) {
207
220
  }
208
221
  })
209
222
 
223
+ async function reset() {
224
+ synchronizedData.value.value = editableSavedData.value || defaultData(model)
225
+ if(toast && discardedDraftToast) toast.add({ severity: 'info', summary: resetToast, life: 1500 })
226
+ onReset()
227
+ }
228
+
210
229
  return {
211
230
  value: synchronizedData.value,
212
231
  changed: synchronizedData.changed,
213
232
  save: synchronizedData.save,
214
233
  saving: synchronizedData.saving,
215
234
  saved: savedData,
235
+ reset,
216
236
  model,
217
237
  }
218
238
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-change/frontend-auto-form",
3
- "version": "0.9.6",
3
+ "version": "0.9.7",
4
4
  "scripts": {
5
5
  "memDev": "node server/start.js memDev --enableSessions --initScript ./init.js --dbAccess",
6
6
  "localDevInit": "rm tmp.db; lcli localDev --enableSessions --initScript ./init.js",
@@ -22,16 +22,16 @@
22
22
  "type": "module",
23
23
  "dependencies": {
24
24
  "@fortawesome/fontawesome-free": "^6.5.2",
25
- "@live-change/cli": "^0.9.6",
26
- "@live-change/dao": "^0.9.6",
27
- "@live-change/dao-vue3": "^0.9.6",
28
- "@live-change/dao-websocket": "^0.9.6",
29
- "@live-change/framework": "^0.9.6",
30
- "@live-change/image-frontend": "^0.9.6",
31
- "@live-change/image-service": "^0.9.6",
32
- "@live-change/session-service": "^0.9.6",
33
- "@live-change/vue3-components": "^0.9.6",
34
- "@live-change/vue3-ssr": "^0.9.6",
25
+ "@live-change/cli": "^0.9.7",
26
+ "@live-change/dao": "^0.9.7",
27
+ "@live-change/dao-vue3": "^0.9.7",
28
+ "@live-change/dao-websocket": "^0.9.7",
29
+ "@live-change/framework": "^0.9.7",
30
+ "@live-change/image-frontend": "^0.9.7",
31
+ "@live-change/image-service": "^0.9.7",
32
+ "@live-change/session-service": "^0.9.7",
33
+ "@live-change/vue3-components": "^0.9.7",
34
+ "@live-change/vue3-ssr": "^0.9.7",
35
35
  "@vueuse/core": "^10.11.0",
36
36
  "codeceptjs-assert": "^0.0.5",
37
37
  "compression": "^1.7.4",
@@ -52,7 +52,7 @@
52
52
  "vue3-scroll-border": "0.1.6"
53
53
  },
54
54
  "devDependencies": {
55
- "@live-change/codeceptjs-helper": "^0.9.6",
55
+ "@live-change/codeceptjs-helper": "^0.9.7",
56
56
  "codeceptjs": "^3.6.5",
57
57
  "generate-password": "1.7.1",
58
58
  "playwright": "1.48.1",
@@ -63,5 +63,5 @@
63
63
  "author": "Michał Łaszczewski <michal@laszczewski.pl>",
64
64
  "license": "ISC",
65
65
  "description": "",
66
- "gitHead": "96dafb43cced09c59326ee3318d6f45b1b614d6f"
66
+ "gitHead": "f936468bf39ea3c5b07ce14666f4b3a4a4a9287d"
67
67
  }