11<template lang="pug">
22q-page
33 q-toolbar
4- q-toolbar-title {{ agent.username }} | {{ agent.email }}
4+ q-toolbar-title {{ agent.displayName }}
55 q-space
66
77 q-btn.q-mx-xs ( @click ="submit" label ="Enregistrer" color ="primary" icon ="mdi-check" )
@@ -11,66 +11,92 @@ q-page
1111
1212 q-btn.q-mx-xs ( @click ="refresh" color ="primary" icon ="mdi-refresh" )
1313 q-tooltip.text-body2 ( slot ="trigger" ) Rafraichir les données
14- q-btn.q-mx-xs ( to = "/agents " label ="Retour" color ="primary" icon ="mdi-arrow-left" )
14+ q-btn.q-mx-xs ( @click = "back " label ="Retour" color ="primary" icon ="mdi-arrow-left" )
1515 q-tooltip.text-body2 ( slot ="trigger" ) Retour à la liste des identités
1616
17- q-card-section
18- q-form
19- div.row.items-start
20- .col-4.q-pa-sm
21- q-input( v-model ="agent.username" label ="Username" filled )
22- .col-4.q-pa-sm
23- q-input( v-model ="agent.displayName" label ="Display Name" filled )
24- .col-4.q-pa-sm
25- q-input( v-model ="agent.email" label ="Email" type ="email" filled )
26- .col-4.q-pa-sm
27- q-input( v-model ="agent.password" label ="Password" type ="password" filled )
28- .col-4.q-pa-sm
29- q-input( v-model ="agent.thirdPartyAuth" label ="Third Party Auth" filled )
30- .col-4.q-pa-sm
31- q-select( v-model ="agent.state.current" : options= "stateOptions" label ="Current State" filled )
32- .col-4.q-pa-sm
33- q-input( v-model ="agent.baseURL" label ="Base URL" filled )
34- .col-4.q-pa-sm
35- q-select( v-model ="agent.roles" : options= "rolesOptions" label ="Roles" multiple filled )
17+ sesame-json-form-renderer(
18+ v-model:data ="agent"
19+ v-model:validations ="validations"
20+ :schema ="schema"
21+ :uischema ="uischema"
22+ )
23+
3624</template >
3725
3826<script lang="ts" setup>
3927import { computed , defineComponent , ref , shallowRef } from ' vue'
4028import { useQuasar } from ' quasar' ;
4129import type { components , operations } from ' #build/types/service-api'
4230import { routerKey , useRoute , useRouter } from ' vue-router' ;
43- import { useHttp } from ' nuxt/app' ;
31+ import { useFetch } from ' nuxt/app' ;
32+ import { useErrorHandling } from ' #imports' ;
4433
45- type AgentsResponse = operations [' AgentsController_search' ][' responses' ][' 200' ][' content' ][' application/json' ]
46- type Agents = components [' schemas' ][' AgentsDto' ]
34+ type AgentResponse = operations [' AgentsController_search' ][' responses' ][' 200' ][' content' ][' application/json' ]
35+ type Agent = components [' schemas' ][' AgentsDto' ]
4736
4837
4938const route = useRoute ()
5039const router = useRouter ()
5140const $q = useQuasar ()
5241const id = shallowRef (route .params .id )
42+ const { handleError } = useErrorHandling ()
43+
44+ const schema = ref ({
45+ " $schema" : " http://json-schema.org/draft-07/schema#" ,
46+ " type" : " object" ,
47+ " properties" : {
48+ " displayName" : {
49+ " type" : " string" ,
50+ " description" : " Common name of the inetOrgPerson."
51+ },
52+ },
53+ " required" : [" cn" , " sn" , " uid" ]
54+ })
55+ const uischema = ref ({
56+ " type" : " Group" ,
57+ " label" : " inetOrgPerson" ,
58+ " elements" : [
59+ {
60+ " type" : " HorizontalLayout" ,
61+ " elements" : [
62+ {
63+ " type" : " Control" ,
64+ " label" : " Display Name" ,
65+ " scope" : " #/properties/displayName" ,
66+ " options" : {
67+ " required" : true
68+ }
69+ },
70+ ]
71+ },
72+ ]
73+ })
74+
75+ const { data : result, pending, error, refresh } = await useHttp <AgentResponse >(` /core/agents/${id .value } ` );
76+ if (error .value ) {
77+ handleError ({
78+ error: error .value ,
79+ redirect: true ,
80+ message: error .value .message
81+ })
82+ }
5383
54- const { data : result, pending, error, refresh } = await useHttp < AgentsResponse >( ` /core/agents/${ id .value } ` );
55- const agent = ref < Agents >( result .value ?.data )
84+ const agent = ref < Agent >( result .value ?. data )
85+ const validations = ref ( agent .value ?.additionalFields ?. validations )
5686
5787async function submit() {
5888 const sanitizedAgent = { ... agent .value }
5989 delete sanitizedAgent .metadata
6090
61-
6291 const { data : result, pending, error, refresh } = await useHttp (` /core/agents/${id .value } ` , {
6392 method: ' PATCH' ,
6493 body: sanitizedAgent ,
6594 });
6695 if (error .value ) {
67- $q .notify ({
68- message: ' Erreur lors de la sauvegarde' ,
69- color: ' negative' ,
70- position: ' top-right' ,
71- icon: ' mdi-alert-circle-outline' ,
96+ handleError ({
97+ error: error .value ,
98+ message: ' Erreur lors de la sauvegarde'
7299 })
73- console .log (error )
74100 validations .value = error .value .data .validations
75101 } else {
76102 $q .notify ({
@@ -79,8 +105,17 @@ async function submit() {
79105 position: ' top-right' ,
80106 icon: ' mdi-check-circle-outline' ,
81107 })
108+ agent .value = result .value .data
82109 }
83110}
111+
112+ function logs() {
113+ console .log (' logs' )
114+ }
115+
116+ function back() {
117+ router .push (' /agents' )
118+ }
84119 </script >
85120
86121<style scoped>
0 commit comments