Skip to content

Commit 6691725

Browse files
authored
Merge pull request #3 from Libertech-FR/wip-ui-array
Wip UI array
2 parents 562e2e5 + 01f247a commit 6691725

29 files changed

+641
-302
lines changed

src/components/2pan/btns/add.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
q-btn(flat icon="mdi-plus" @click="add" color="primary")
33
q-tooltip.text-body2(transition-show="scale" transition-hide="scale") {{ tooltip }}
44
</template>
5-
5+
66
<script lang="ts" setup>
77
import type { PropType } from 'vue'
88
const props = defineProps({
@@ -16,4 +16,4 @@ const emit = defineEmits(['add'])
1616
function add() {
1717
emit('add')
1818
}
19-
</script>
19+
</script>
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<template lang="pug">
2-
q-btn(flat icon="mdi-refresh" @click="refresh" color="primary")
2+
q-btn(flat icon="mdi-refresh" @click="refresh" color="info")
33
q-tooltip.text-body2(transition-show="scale" transition-hide="scale") Rafraichir
44
</template>
5-
5+
66
<script lang="ts" setup>
77
import type { PropType } from 'vue'
88
const emit = defineEmits(['refresh'])
99
function refresh() {
1010
emit('refresh')
1111
}
12-
</script>
12+
</script>

src/components/2pan/btns/remove.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<template lang="pug">
22
q-btn(flat icon="mdi-delete" @click="remove" size="sm" color="negative")
3-
q-tooltip.text-body2(transition-show="scale" transition-hide="scale") {{ tooltip }}
3+
q-tooltip.text-body2(transition-show="scale" transition-hide="scale") {{ tooltip }}
44
</template>
5-
5+
66
<script lang="ts" setup>
77
import type { PropType } from 'vue'
88
const props = defineProps({
@@ -16,4 +16,4 @@ const emit = defineEmits(['remove'])
1616
function remove() {
1717
emit('remove')
1818
}
19-
</script>
19+
</script>

src/components/2pan/index.vue

Lines changed: 61 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -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...
@@ -84,20 +84,20 @@ 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")
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")
87+
slot(name="right-panel-actions-content" v-if="defaultRightPanelButton" :target="target" :isNew="isNew" :crud="crud")
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
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")
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'
113113
import { crush, pick } from 'radash'
114114
import { routerKey } from 'vue-router'
115115
116+
const NEW_ID = '000000000000000000000000'
117+
116118
defineOptions({
117119
name: '2pan',
118120
})
@@ -190,6 +192,7 @@ const props = defineProps({
190192
update: <T>(r: T) => Promise<T>
191193
delete: <T>(r: T) => Promise<T>
192194
cancel: () => Promise<void>
195+
add: <T>() => Promise<T>
193196
onMounted: <T = object>() => Promise<T | null>
194197
}>,
195198
default: {
@@ -207,6 +210,7 @@ const props = defineProps({
207210
},
208211
209212
cancel: async () => { },
213+
add: async () => { return {} },
210214
onMounted: async () => { },
211215
},
212216
},
@@ -222,6 +226,10 @@ watch(simple, (v) => {
222226
})
223227
const splitterModel = ref(isSimple.value ? 100 : 50)
224228
229+
const leftBtnHidden = computed(() => {
230+
return isSimple.value || splitterModel.value > 40
231+
})
232+
225233
const visibleColumnsInternal = ref(props.visibleColumns)
226234
const visibleColumnsComputed = computed({
227235
get() {
@@ -246,11 +254,12 @@ const { pagination, onRequest, initializePagination } = usePagination()
246254
initializePagination(props.total)
247255
248256
const emit = defineEmits(['create', 'refresh', 'read', 'update', 'delete'])
249-
const debug = process.env.NODE_ENV === 'development'
257+
const { debug } = useDebug()
250258
251259
const selected = ref([])
252260
const tab = ref('')
253-
const target = ref<null | object>(null)
261+
const targetId = ref<null | string>(route.query?.read ? `${route.query?.read}` : null)
262+
const target = ref<object>({})
254263
const daysjs = useDayjs()
255264
256265
watch(target, (t) => {
@@ -275,39 +284,59 @@ async function refresh() {
275284
276285
async function cancel() {
277286
await props.actions.cancel()
278-
target.value = null
287+
targetId.value = null
288+
target.value = {}
279289
selected.value = []
280-
router.push({ query: { ...route.query, read: undefined } })
290+
await router.push({ query: { ...route.query, read: null } })
281291
}
282292
async function read(row) {
293+
targetId.value = row?._id
283294
const response = await props.actions.read(row)
284-
target.value = response
295+
target.value = { ...response }
285296
emit('read', response)
286297
}
287298
299+
async function add() {
300+
const read = NEW_ID
301+
targetId.value = read
302+
target.value = await props.actions.add() || {}
303+
await router.push({ query: { ...route.query, read } })
304+
}
305+
288306
async function create(row) {
307+
console.log('create', row)
289308
const response = await props.actions.create(row)
290-
target.value = response
309+
console.log('response', response)
310+
// target.value = response
311+
// targetId.value = response?._id
291312
emit('create', response)
313+
if (response) cancel()
292314
}
293315
294316
async function update(row) {
317+
targetId.value = row?._id
295318
const response = await props.actions.update(row)
296-
target.value = response
319+
target.value = { ...response }
297320
emit('update', response)
298321
}
299322
300323
async function remove(row) {
324+
// targetId.value = row?._id
301325
const response = await props.actions.delete(row)
302326
target.value = response
327+
// target.value = response
303328
emit('delete', response)
304329
}
305330
331+
const isNew = computed(() => {
332+
return targetId.value === NEW_ID
333+
})
334+
306335
const getTitle = computed(() => {
307336
const keys = Array.isArray(props.titleKey) ? props.titleKey : [props.titleKey]
308337
if (!target.value) return ''
309338
const crushed = crush(target.value)
310-
const valuesList = target.value ? pick(crushed, keys) : {}
339+
const valuesList = target.value ? pick(crushed, keys as any) : {}
311340
return Object.values(valuesList).join(' ')
312341
})
313342
@@ -327,9 +356,15 @@ defineExpose({
327356
})
328357
329358
onMounted(async () => {
359+
if (isNew.value) {
360+
await add()
361+
return
362+
}
330363
const newTarget = await props.actions.onMounted()
364+
// console.log('newTarget', newTarget)
331365
if (newTarget) {
332-
target.value = newTarget
366+
target.value = { ...newTarget }
367+
targetId.value = (newTarget as any)?._id
333368
}
334369
})
335370
</script>

src/components/appbar/Menu.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ q-btn(flat icon="mdi-dots-grid" size="20px" square)
88
q-icon(:name="app.icon.name" :color="app.icon.color" size="xl")
99
q-badge(v-if="app.badge" :color="app.badge.color" floating) {{ app.badge.value }}
1010
div.text-center(:class="`text-${app.title.color}`") {{ app.title.name }}
11-
1211
</template>
1312

1413
<script lang="ts" setup>

src/components/appbar/RightButtons.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ div
33
//q-btn(v-for="button in buttons" :key="button.icon" round flat :icon="button.icon" size="md").q-mx-sm
44
q-tooltip.text-body2(transition-show="scale" transition-hide="scale") {{ button.name }}
55
q-btn(v-if="badgesValues.TO_SYNC > 0" icon="mdi-sync" square color="amber-9" size="md" :label="badgesValues.TO_SYNC +' items à Synchroniser'" @click="syncAll")
6+
q-btn(v-if="debug" @click="$q.dark.toggle()" flat size="md" icon="mdi-theme-light-dark")
67
q-btn-dropdown(icon="mdi-account-circle-outline" :label="auth?.user?.displayName" round flat size="md")
78
q-list
89
q-item.q-pa-none(v-for="button in buttons" :key="button.name")
@@ -28,7 +29,8 @@ const badgesValues = ref({
2829
})
2930
3031
const auth = useAuth()
31-
console.log(auth)
32+
const { debug } = useDebug()
33+
// console.log(auth)
3234
const buttons = [
3335
// {
3436
// icon: 'mdi-cog',

src/components/appbar/index.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<template lang="pug">
22
q-header
33
q-toolbar.bg-primary.text-white(style={ height: '32px' })
4-
q-btn(flat @click="closeDrawer()" icon="mdi-menu")
5-
q-separator(vertical dark inset).q-mx-md
6-
7-
q-btn(flat @click="backToIndex()")
4+
//- div.desktop-hidden
5+
//- q-btn(flat @click="closeDrawer()" icon="mdi-menu")
6+
//- q-separator(vertical dark inset).q-mx-md
7+
q-btn.q-pl-none(flat @click="backToIndex()")
88
q-avatar(square)
99
q-img(src="/config/logo.png" error-src="/default.png" alt="Sesame logo")
1010
q-toolbar-title SESAME

src/components/genericForm/index.vue

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
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"
6-
v-model:validations="validations"
6+
v-model:validations="validationsInternal"
77
:schema="schema"
88
:uischema="uischema"
99
)
10+
//- pre(v-html="JSON.stringify(payload.target, null, 2)")
1011
</template>
1112

1213
<script lang="ts" setup>
@@ -32,6 +33,13 @@ const props = defineProps(
3233
payload: {
3334
type: Object,
3435
required: true,
36+
// default: {
37+
// target: {},
38+
// }
39+
},
40+
validations: {
41+
type: Object || null,
42+
default: {},
3543
},
3644
}
3745
)
@@ -42,7 +50,12 @@ const { getStateColor, getStateName } = useIdentityStates()
4250
const { handleError } = useErrorHandling()
4351
4452
45-
const validations = ref([])
53+
const validationsInternal = ref(props.validations)
54+
55+
watch(() => props.validations, () => {
56+
validationsInternal.value = props.validations
57+
})
58+
4659
const error = ref(null)
4760
4861
// defineExpose({

0 commit comments

Comments
 (0)