@ -24,6 +24,25 @@ export default {
/ / f e t c h ( " l o c a l h o s t / a p i / v 1 / s c i e n t i f i q u e s " , { m e t h o d : " P U T " , b o d y : J S O N . s t r i n g i f y ( d o n n e e s ) } )
console . log ( this . champs )
this . changerModeEdition ( )
} ,
typeDeChamp : function ( champ ) {
switch ( typeof champ ) {
case 'number' :
case 'bigint' :
return "number"
case 'string' :
return this . estUneDate ( champ ) ? "date" : "text"
case 'boolean' :
return "checkbox"
case 'symbol' :
case 'undefined' :
case 'object' :
case 'function' :
return "hidden" / / T O D O : i m p l e m e n t e r l e r e s t e
}
} ,
estUneDate : function ( date ) {
return new Date ( date ) != "Invalid Date" ;
}
}
}
@ -32,8 +51,8 @@ export default {
< template >
< tr v-if ="!this.modeEdition" >
< td v-for =" item in champs">
< p > { { item } } < / p >
< td v-for =" champ in champs">
< p > { { this . typeDeChamp ( champ ) == "date" ? new Date ( champ ) . toLocaleString ( ) : champ } } < / p >
< / td >
< td >
< button class = "btn-outline-secondary btn" v -on :click ="changerModeEdition()" > Modifier < / button >
@ -44,7 +63,7 @@ export default {
<!-- TODO : changer le type si c 'est un nombre, date (voir si on peut parse la date), objet (bouton qui ouvre une popup qui propose de changer les champs de l' objet ) -- >
< td v-for ="cleChamp in Object.keys(champs)" >
<!-- TODO : aria label , comment trouver les noms des colonnes depuis Liste . vue -- >
< input class = "form-control" type = "text" v-model ="champs[cleChamp]" >
< input class = "form-control" :type ="typeDeChamp(champs[cleChamp])" v -model = " champs [ cleChamp ] " >
< / td >
< td >
< button class = "btn btn-success" v -on :click ="sauverScientifique()" > Sauvegarder < / button >