Skip to content

Commit 01f247a

Browse files
committed
fix: Handle object values correctly in QStringControlRenderer setup function
1 parent 226b9dc commit 01f247a

File tree

13 files changed

+179
-70
lines changed

13 files changed

+179
-70
lines changed

src/components/2pan/index.vue

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,14 @@ q-splitter(
8484
q-btn(color="primary", icon="mdi-chevron-left" @click="cancel" tooltip="Retour")
8585
q-tooltip.text-body2 Retour
8686
q-separator.q-mx-sm(vertical)
87-
slot(name="right-panel-actions-content" v-if="defaultRightPanelButton" :target="target")
87+
slot(name="right-panel-actions-content" v-if="defaultRightPanelButton" :target="target" :isNew="isNew" :crud="crud")
8888
q-btn(color="positive" icon='mdi-content-save-plus' @click="create(target)" v-show="isNew" v-if="crud.create")
8989
q-tooltip.text-body2 Créer
9090
q-btn(color="positive" icon='mdi-content-save' @click="update(target)" v-show="!isNew" v-if="crud.update")
9191
q-tooltip.text-body2 Enregistrer
9292
q-btn(color="negative" icon='mdi-delete' @click="remove(target)" v-show="!isNew" v-if="crud.delete")
9393
q-tooltip.text-body2 Supprimer
94-
slot(name="right-panel-actions-content-after" :target="target")
94+
slot(name="right-panel-actions-content-after" :target="target" :isNew="isNew" :crud="crud")
9595
q-card-section.q-pa-none.fit.flex(style='flex-flow: column; overflow: hidden;')
9696
slot(name="right-panel-content" :payload="{ target }")
9797
slot(name="right-panel-content-before")
@@ -192,6 +192,7 @@ const props = defineProps({
192192
update: <T>(r: T) => Promise<T>
193193
delete: <T>(r: T) => Promise<T>
194194
cancel: () => Promise<void>
195+
add: <T>() => Promise<T>
195196
onMounted: <T = object>() => Promise<T | null>
196197
}>,
197198
default: {
@@ -209,6 +210,7 @@ const props = defineProps({
209210
},
210211
211212
cancel: async () => { },
213+
add: async () => { return {} },
212214
onMounted: async () => { },
213215
},
214216
},
@@ -257,7 +259,7 @@ const { debug } = useDebug()
257259
const selected = ref([])
258260
const tab = ref('')
259261
const targetId = ref<null | string>(route.query?.read ? `${route.query?.read}` : null)
260-
const target = ref<null | object>(null)
262+
const target = ref<object>({})
261263
const daysjs = useDayjs()
262264
263265
watch(target, (t) => {
@@ -283,36 +285,38 @@ async function refresh() {
283285
async function cancel() {
284286
await props.actions.cancel()
285287
targetId.value = null
286-
target.value = null
288+
target.value = {}
287289
selected.value = []
288290
await router.push({ query: { ...route.query, read: null } })
289291
}
290292
async function read(row) {
291293
targetId.value = row?._id
292294
const response = await props.actions.read(row)
293-
target.value = response
295+
target.value = { ...response }
294296
emit('read', response)
295297
}
296298
297299
async function add() {
298300
const read = NEW_ID
299301
targetId.value = read
300-
target.value = {}
301-
router.push({ query: { ...route.query, read } })
302+
target.value = await props.actions.add() || {}
303+
await router.push({ query: { ...route.query, read } })
302304
}
303305
304306
async function create(row) {
305307
console.log('create', row)
306308
const response = await props.actions.create(row)
309+
console.log('response', response)
307310
// target.value = response
308311
// targetId.value = response?._id
309312
emit('create', response)
313+
if (response) cancel()
310314
}
311315
312316
async function update(row) {
313317
targetId.value = row?._id
314318
const response = await props.actions.update(row)
315-
target.value = response
319+
target.value = { ...response }
316320
emit('update', response)
317321
}
318322
@@ -357,7 +361,7 @@ onMounted(async () => {
357361
return
358362
}
359363
const newTarget = await props.actions.onMounted()
360-
console.log('newTarget', newTarget)
364+
// console.log('newTarget', newTarget)
361365
if (newTarget) {
362366
target.value = { ...newTarget }
363367
targetId.value = (newTarget as any)?._id

src/components/genericForm/index.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template lang="pug">
22
div
3-
//- pre(v-html="JSON.stringify(payload, null, 2)")
3+
pre(v-html="JSON.stringify(payload, null, 2)")
44
sesame-json-form-renderer(
55
v-model:data="payload.target"
66
v-model:validations="validationsInternal"
@@ -33,6 +33,9 @@ const props = defineProps(
3333
payload: {
3434
type: Object,
3535
required: true,
36+
// default: {
37+
// target: {},
38+
// }
3639
},
3740
validations: {
3841
type: Object || null,

src/components/identityForm/actions.vue

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
<template lang="pug">
22
div
3-
q-btn.q-mx-xs(@click="submit" color="positive" icon="mdi-check")
3+
q-btn(color="positive" icon='mdi-content-save-plus' @click="create" v-show="isNew" v-if="crud.create")
4+
q-tooltip.text-body2 Créer
5+
q-btn.q-mx-xs(@click="submit" color="positive" icon="mdi-check" v-show="!isNew" v-if="crud.update")
46
q-tooltip.text-body2(slot="trigger") Enregistrer les modifications
5-
q-btn.q-mx-xs(@click="sync" color="orange-8" v-if="identity" :disabled="props.identity.state != IdentityState.TO_VALIDATE" icon="mdi-sync")
7+
q-btn.q-mx-xs(v-if="props.identity?._id" @click="sync" color="orange-8" :disabled="props.identity.state != IdentityState.TO_VALIDATE" icon="mdi-sync")
68
q-tooltip.text-body2(slot="trigger" v-if="props.identity.state == IdentityState.TO_VALIDATE") Synchroniser l'identité
79
q-tooltip.text-body2(slot="trigger" v-else) L'état de l'identité ne permet pas de la synchroniser
8-
q-btn.q-mx-xs(@click="logs" color="grey-8" icon="mdi-file-document" :href="'/jobs?filters[:concernedTo.id]=' + props.identity?._id")
10+
q-btn.q-mx-xs(v-if="props.identity?._id" @click="logs" color="grey-8" icon="mdi-file-document" :href="'/jobs?filters[:concernedTo.id]=' + props.identity?._id")
911
q-tooltip.text-body2(slot="trigger") Voir les logs de l'identité
1012
</template>
1113

@@ -27,19 +29,32 @@ const props = defineProps({
2729
type: Object as PropType<Identity>,
2830
required: true,
2931
},
32+
crud: {
33+
type: Object,
34+
default: {},
35+
},
36+
isNew: {
37+
type: Boolean,
38+
required: true,
39+
},
3040
})
3141
const $q = useQuasar()
3242
const router = useRouter()
3343
const { getStateColor, getStateName } = useIdentityStates()
3444
const { handleError } = useErrorHandling()
3545
36-
const emits = defineEmits(['submit', 'sync', 'logs'])
46+
const emits = defineEmits(['submit', 'sync', 'logs', 'create'])
3747
3848
async function submit() {
39-
console.log('submit from actions')
49+
// console.log('submit from actions')
4050
emits('submit')
4151
}
4252
53+
async function create() {
54+
// console.log('submit from actions')
55+
emits('create')
56+
}
57+
4358
const stateName = computed(() => {
4459
const state = props.identity?.state
4560
return getStateName(state)

src/components/identityForm/index.vue

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
<template lang="pug">
22
div
3+
//- pre(v-html="JSON.stringify(identity, null, 2)")
34
q-tabs(v-model="tab" align="justify")
45
q-tab(name="inetOrgPerson" label="inetOrgPerson" :alert="getTabValidations('inetOrgPerson')" alert-icon="mdi-alert" :class="`q-mr-xs`")
56
q-tab(v-for="tab in tabs" :key="tab" :name="tab" :label="tab" :alert="getTabValidations(tab)" alert-icon="mdi-alert" :class="`q-mr-xs`")
6-
7+
q-btn-dropdown.full-height(icon="mdi-newspaper-plus" flat)
8+
q-tooltip.text-body2(anchor="top middle" self="center middle") Ajouter un schéma
9+
q-list
10+
q-item(clickable v-close-popup v-for="schema in schemas" @click="addSchema(schema)")
11+
q-item-section
12+
q-item-label(v-text="schema.name")
713
q-tab-panels(v-model="tab")
8-
q-tab-panel(name="inetOrgPerson" v-if='identity && identity.inetOrgPerson')
14+
q-tab-panel(name="inetOrgPerson")
915
sesame-json-form-renderer-api(
1016
schemaName="inetorgperson"
1117
v-model:data="identity.inetOrgPerson"
@@ -41,6 +47,12 @@ const props = defineProps(
4147
identity: {
4248
type: Object as PropType<Identity>,
4349
required: true,
50+
default: {
51+
additionalFields: {
52+
objectClasses: [],
53+
attributes: {},
54+
},
55+
},
4456
}
4557
}
4658
)
@@ -65,6 +77,23 @@ watch(() => props.identity, () => {
6577
const tab = ref('inetOrgPerson')
6678
const error = ref(null)
6779
80+
const { data: schemasResult, pending, refresh } = await useHttp<any>(`/management/identities/validation`, {
81+
method: 'GET',
82+
});
83+
84+
const schemas = computed(() => {
85+
return schemasResult.value.data.filter((schema: any) => {
86+
return !tabs.value.includes(schema.name) && `${schema.name}`.toLocaleLowerCase() !== 'inetOrgPerson'.toLocaleLowerCase()
87+
})
88+
})
89+
90+
async function addSchema(schema) {
91+
console.log('identity.value', identity.value)
92+
if (!identity.value.additionalFields) identity.value.additionalFields = { objectClasses: [], attributes: {} }
93+
identity.value.additionalFields.attributes[schema.name] = {}
94+
identity.value.additionalFields.objectClasses.push(schema.name)
95+
}
96+
6897
async function submit() {
6998
console.log('submit from form')
7099
const sanitizedIdentity = { ...props.identity }
@@ -95,6 +124,33 @@ async function submit() {
95124
}
96125
}
97126
127+
async function create() {
128+
console.log('create from form')
129+
const sanitizedIdentity = { ...props.identity }
130+
delete sanitizedIdentity.metadata
131+
132+
const { data: result, pending, error, refresh } = await useHttp(`/management/identities`, {
133+
method: 'POST',
134+
body: { ...sanitizedIdentity },
135+
});
136+
if (error.value) {
137+
handleError({
138+
error: error.value,
139+
message: 'Erreur lors de la création'
140+
})
141+
console.log('error', error.value.data.validations)
142+
validations.value = { ...error.value.data.validations }
143+
} else {
144+
$q.notify({
145+
message: 'Création effectuée',
146+
color: 'positive',
147+
position: 'top-right',
148+
icon: 'mdi-check-circle-outline',
149+
})
150+
emits('refreshTarget', {})
151+
}
152+
}
153+
98154
const stateName = computed(() => {
99155
const state = props.identity?.state
100156
return getStateName(state)
@@ -113,7 +169,7 @@ async function sync() {
113169
const { data: result, pending, error, refresh } = await useHttp<any>(`/management/identities/${props.identity._id}/state`, {
114170
method: 'PATCH',
115171
body: {
116-
state: IdentityState.TO_SYNC,
172+
state: IdentityState.TO_VALIDATE,
117173
},
118174
});
119175
@@ -141,6 +197,7 @@ function back() {
141197
142198
defineExpose({
143199
submit,
200+
create,
144201
sync,
145202
logs,
146203
back,

src/components/jsonFormRenderer.vue

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<template lang="pug">
22
div
33
json-forms(
4-
v-if="data"
54
:data="data"
65
:schema="schema"
76
:uischema="uischema"
@@ -26,6 +25,7 @@ import { QuasarJsonformRenderer } from './quasar-jsonform';
2625
import { computed, provide, ref } from 'vue';
2726
import { useFetch } from 'nuxt/app';
2827
import type { ErrorObject } from 'ajv';
28+
import { isObject } from 'radash';
2929
3030
const customStyle = mergeStyles(defaultStyles, {
3131
control: {
@@ -55,6 +55,10 @@ const props = defineProps({
5555
type: Object || null,
5656
default: {},
5757
},
58+
// data: {
59+
// type: Object,
60+
// default: {},
61+
// },
5862
});
5963
6064
const validations = defineModel('validations', {
@@ -68,10 +72,18 @@ const data = defineModel('data', {
6872
});
6973
7074
function onChange(event: JsonFormsChangeEvent) {
75+
// console.log('onchanbge', event)
76+
// data.value = event.data;
77+
// console.log('event.data', event.data)
78+
// if (isObject(event.data)) {
79+
// if (!isObject(data.value)) data.value = {}
7180
for (const key in event.data) {
7281
const evdata = event.data[key];
82+
// console.log('data.value', data.value)
7383
data.value[key] = evdata;
84+
// console.log('data.value[key]', data.value[key])
7485
}
86+
// }
7587
}
7688
7789
const getSchemaValidations = computed(() => {

src/components/quasar-jsonform/controls/QPasswordControlRenderer.vue

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import type { RendererProps } from '@jsonforms/vue';
5151
import type { ControlElement } from '@jsonforms/core';
5252
import { useQuasarControl } from '../util';
5353
import { ControlWrapper } from '@jsonforms/vue-vanilla';
54+
import { debounce } from 'quasar';
5455
5556
const QPasswordControlRenderer = defineComponent({
5657
name: 'q-password-control-renderer',
@@ -70,18 +71,20 @@ const QPasswordControlRenderer = defineComponent({
7071
password: ref(''),
7172
confirm: ref(''),
7273
}),
73-
watch: {
74-
'control.data': {
75-
deep: true,
76-
handler(val) {
77-
this.password = val
78-
},
79-
},
80-
},
74+
// watch: {
75+
// 'control.data': {
76+
// deep: true,
77+
// handler(val) {
78+
// this.password = val
79+
// },
80+
// },
81+
// },
8182
methods: {
82-
onChangeControl() {
83+
onChangeControl(val) {
8384
if (this.password === this.confirm) {
84-
this.onChange(this.password)
85+
this.onChange(val)
86+
} else {
87+
this.control.errors = 'Mot de passes non identiques'
8588
}
8689
},
8790
isIterable(obj) {

src/components/quasar-jsonform/controls/QStringControlRenderer.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template lang="pug">
22
//control-wrapper(v-bind="controlWrapper" :styles="styles" :isFocused="isFocused" :appliedOptions="appliedOptions")
33
div
4-
pre(v-html="JSON.stringify(control.data, null, 2)")
4+
//- pre(v-html="JSON.stringify(control.data, null, 2)")
55
q-select(
66
v-if="suggestions !== undefined"
77
:model-value="control.data"
@@ -82,10 +82,10 @@ const QStringControlRenderer = defineComponent({
8282
return typeof obj[Symbol.iterator] === 'function';
8383
},
8484
},
85-
mounted() {
86-
console.log('this.control', this.control)
87-
console.log('this.control.dataa', this.control.data)
88-
},
85+
// mounted() {
86+
// console.log('this.control', this.control)
87+
// console.log('this.control.dataa', this.control.data)
88+
// },
8989
computed: {
9090
suggestions() {
9191
const suggestions = this.control.uischema.options?.suggestion;

0 commit comments

Comments
 (0)