@@ -9,7 +9,7 @@ q-splitter(
99 :style ='{ "padding": isSimple ? "6px 0" : "0" }'
1010)
1111 template( #before )
12- q-card.full-height.q-pa-sm ( bordered :class ='{"hidden": isSimple && target }' )
12+ q-card.full-height.q-pa-sm ( bordered :class ='{"hidden": isSimple && targetId }' )
1313 q-table.sesame-sticky-last-column-table.full-height (
1414 v-bind ="$attrs"
1515 selection ="multiple"
@@ -33,18 +33,18 @@ q-splitter(
3333 template( v-for ="(_, name) in $slots" v-slot:[name] ="slotData" )
3434 slot( :name ="name" v-bind ="slotData" )
3535 template( v-slot:top-left )
36- q-btn-group( rounded flat )
36+ q-btn-group( v-if = "leftBtnHidden" rounded flat )
3737 slot( name ="top-left-btn-grp" : selectedValues= "selected" )
3838 slot( name ="top-left-btn-grp-content-before" )
3939 slot( name ="top-left-btn-grp-content-after" )
4040 template( v-slot:top-right )
4141 q-btn-group( rounded flat )
4242 slot( name ="top-right-btn-grp" )
4343 slot( name ="top-right-btn-grp-content-before" )
44- sesame-2pan-btns-add( @add ="create " v-if ="crud.create" )
45- q-btn.desktop-only ( flat :icon ="isSimple ? 'mdi-table-border' : 'mdi-table-merge-cells'" color ="primary " @click ="simple = !simple" )
44+ sesame-2pan-btns-add( @add ="add " v-if ="crud.create" )
45+ q-btn.desktop-only ( flat :icon ="isSimple ? 'mdi-table-border' : 'mdi-table-merge-cells'" color ="info " @click ="simple = !simple" )
4646 q-tooltip.text-body2 ( transition-show ="scale" transition-hide ="scale" ) Mode simple/double panneaux
47- q-btn( flat icon ="mdi-table-headers-eye" color ="primary " )
47+ q-btn( flat icon ="mdi-table-headers-eye" color ="info " )
4848 q-tooltip.text-body2 ( transition-show ="scale" transition-hide ="scale" ) Afficher/cacher des colonnes
4949 q-menu( max-width ="350px" max-height ="350px" ) .q-pa-md
5050 .row
@@ -53,21 +53,21 @@ q-splitter(
5353 sesame-2pan-btns-refresh( @refresh ="refresh" )
5454 slot( name ="top-right-btn-grp-content-after" )
5555
56- template( v-slot:body-cell-actions ="props" )
56+ template( v-slot:body-cell-actions ="props" )
5757 q-td( :props ="props" )
5858 q-btn-group( flat rounded )
5959 slot( name ="body-cell-actions" : props= "props" )
6060 slot( name ="body-cell-actions-content-before" )
6161 sesame-2pan-btns-read( @read ="read(props.row)" v-if ="crud.read" )
62- sesame-2pan-btns-remove( @remove ="remove(props.row)" v-if ="crud.delete" )
62+ sesame-2pan-btns-remove( @remove ="remove(props.row)" v-if ="crud.delete" )
6363 slot( name ="body-cell-actions-content-after" )
6464
6565 template( #separator )
6666 q-avatar( v-if ='!isSimple' size ="sm" color ="primary" icon ="mdi-unfold-more-vertical" class ="text-white" )
6767
6868 template( #after )
69- q-card.full-height.q-pa-sm ( bordered :class ='{"hidden": isSimple && !target }' )
70- q-card-section.q-pa-none.flex.items-center.full-height.justify-center ( v-if ='!target ' )
69+ q-card.full-height.q-pa-sm ( bordered :class ='{"hidden": isSimple && !targetId }' )
70+ q-card-section.q-pa-none.flex.items-center.full-height.justify-center ( v-if ='!targetId ' )
7171 slot( name ="right-panel-empty" )
7272 slot( name ="right-panel-empty-content-before" )
7373 p Selectionnez une entrée pour afficher son contenu...
@@ -85,19 +85,19 @@ q-splitter(
8585 q-tooltip.text-body2 Retour
8686 q-separator.q-mx-sm ( vertical )
8787 slot( name ="right-panel-actions-content" v-if ="defaultRightPanelButton" : target= "target" )
88- q-btn( color ="positive" icon ='mdi-content-save-plus' @click ="create(target)" v-if ="crud.create" )
89- q-tooltip.text-body2 Enregistrer
90- q-btn( color ="positive" icon ='mdi-content-save' @click ="update(target)" v-if ="crud.update" )
88+ q-btn( color ="positive" icon ='mdi-content-save-plus' @click ="create(target)" v-show = "isNew" v- if ="crud.create" )
89+ q-tooltip.text-body2 Créer
90+ q-btn( color ="positive" icon ='mdi-content-save' @click ="update(target)" v-show = "!isNew" v- if ="crud.update" )
9191 q-tooltip.text-body2 Enregistrer
92- q-btn( color ="negative" icon ='mdi-delete' @click ="remove(target)" v-if ="crud.delete" )
92+ q-btn( color ="negative" icon ='mdi-delete' @click ="remove(target)" v-show = "!isNew" v- if ="crud.delete" )
9393 q-tooltip.text-body2 Supprimer
9494 slot( name ="right-panel-actions-content-after" : target= "target" )
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" )
9898 slot( name ="right-panel-content-after" )
99- q-expansion-item.bg-blue-grey-10 ( v-if ='debug' label ='Debug' icon ='mdi-bug' dense )
100- q-card.overflow-auto.bg-blue-grey-8 ( :style ='{maxHeight: "250px", height: "250px"}' )
99+ q-expansion-item.bg-blue-grey-10 ( v-if ='debug' label ='Debug' icon ='mdi-bug' dark dense )
100+ q-card.overflow-auto.bg-blue-grey-8.text-white ( :style ='{maxHeight: "250px", height: "250px"}' )
101101 q-card-section.q-pa-xs
102102 pre.q-ma-none ( v-html ='JSON.stringify(target, null, 2)' )
103103</template >
@@ -113,6 +113,8 @@ import type { PropType } from 'vue'
113113import { crush , pick } from ' radash'
114114import { routerKey } from ' vue-router'
115115
116+ const NEW_ID = ' 000000000000000000000000'
117+
116118defineOptions ({
117119 name: ' 2pan' ,
118120})
@@ -222,6 +224,10 @@ watch(simple, (v) => {
222224})
223225const splitterModel = ref (isSimple .value ? 100 : 50 )
224226
227+ const leftBtnHidden = computed (() => {
228+ return isSimple .value || splitterModel .value > 40
229+ })
230+
225231const visibleColumnsInternal = ref (props .visibleColumns )
226232const visibleColumnsComputed = computed ({
227233 get() {
@@ -246,10 +252,11 @@ const { pagination, onRequest, initializePagination } = usePagination()
246252initializePagination (props .total )
247253
248254const emit = defineEmits ([' create' , ' refresh' , ' read' , ' update' , ' delete' ])
249- const debug = process . env . NODE_ENV === ' development '
255+ const { debug } = useDebug ()
250256
251257const selected = ref ([])
252258const tab = ref (' ' )
259+ const targetId = ref <null | string >(route .query ?.read ? ` ${route .query ?.read } ` : null )
253260const target = ref <null | object >(null )
254261const daysjs = useDayjs ()
255262
@@ -275,39 +282,57 @@ async function refresh() {
275282
276283async function cancel() {
277284 await props .actions .cancel ()
285+ targetId .value = null
278286 target .value = null
279287 selected .value = []
280288 router .push ({ query: { ... route .query , read: undefined } })
281289}
282290async function read(row ) {
291+ targetId .value = row ?._id
283292 const response = await props .actions .read (row )
284293 target .value = response
285294 emit (' read' , response )
286295}
287296
297+ async function add() {
298+ const read = NEW_ID
299+ targetId .value = read
300+ target .value = {}
301+ router .push ({ query: { ... route .query , read } })
302+ }
303+
288304async function create(row ) {
305+ console .log (' create' , row )
289306 const response = await props .actions .create (row )
290- target .value = response
307+ // target.value = response
308+ // targetId.value = response?._id
291309 emit (' create' , response )
292310}
293311
294312async function update(row ) {
313+ targetId .value = row ?._id
295314 const response = await props .actions .update (row )
296315 target .value = response
297316 emit (' update' , response )
298317}
299318
300319async function remove(row ) {
320+ // targetId.value = row?._id
301321 const response = await props .actions .delete (row )
302322 target .value = response
323+ // target.value = response
303324 emit (' delete' , response )
304325}
305326
327+ const isNew = computed (() => {
328+ return targetId .value === NEW_ID
329+ })
330+
306331const getTitle = computed (() => {
307332 const keys = Array .isArray (props .titleKey ) ? props .titleKey : [props .titleKey ]
308333 if (! target .value ) return ' '
309334 const crushed = crush (target .value )
310- const valuesList = target .value ? pick (crushed , keys ) : {}
335+ const valuesList = target .value ? pick (crushed , keys as any ) : {}
311336 return Object .values (valuesList ).join (' ' )
312337})
313338
@@ -327,9 +352,14 @@ defineExpose({
327352})
328353
329354onMounted (async () => {
355+ if (isNew .value ) {
356+ await add ()
357+ return
358+ }
330359 const newTarget = await props .actions .onMounted ()
331360 if (newTarget ) {
332- target .value = newTarget
361+ target .value = { ... newTarget }
362+ targetId .value = (newTarget as any )?._id
333363 }
334364})
335365 </script >
0 commit comments