|
| 1 | +<template lang="pug"> |
| 2 | +q-page.container |
| 3 | + .q-px-md |
| 4 | + sesame-searchfilters(:fields="fieldsList") |
| 5 | + |
| 6 | + sesame-2pan( |
| 7 | + ref="twopan" |
| 8 | + :data="identities?.data" |
| 9 | + :total="identities?.total" |
| 10 | + :columns="columns" |
| 11 | + :visibleColumns="visibleColumns" |
| 12 | + :fieldsList="fieldsList" |
| 13 | + :selected="selected" |
| 14 | + :hide-selection="true" |
| 15 | + :pagination="pagination" |
| 16 | + :pending="pending" |
| 17 | + :refresh="refreshEvent" |
| 18 | + :error="error" |
| 19 | + :titleKey=["inetOrgPerson.cn"] |
| 20 | + :crud="crud" |
| 21 | + :actions="actions" |
| 22 | + hide-left-buttons="true" |
| 23 | + :defaultRightPanelButton="false" |
| 24 | + ) |
| 25 | + template(#right-panel-title-before="props") |
| 26 | + q-icon(name="mdi-circle" :color="getStateColor(props?.target?.state)" class="q-mr-xs") |
| 27 | + q-tooltip.text-body2(slot="trigger") {{ getStateName(props.target.state) }} |
| 28 | + q-icon(:name="getInitStateIcon(props?.target?.initState)" :color="getInitStateColor(props?.target?.initState)" class="q-mr-xs") |
| 29 | + q-tooltip.text-body2(slot="trigger") {{ getInitStateName(props.target.initState) }} |
| 30 | + template(#top-left-btn-grp="{selectedValues}") |
| 31 | + sesame-table-top-left( :selected="selectedValues" @refresh="refresh" @clear="clearSelected" :total="identities?.total") |
| 32 | + template(#body-cell-states="props") |
| 33 | + sesame-table-state-col(:identity="props.row") |
| 34 | + |
| 35 | + template(#right-panel-content="{payload, isNew}") |
| 36 | + sesame-identity-form( |
| 37 | + :identity="{...payload.target}" |
| 38 | + ref="form" |
| 39 | + :isNew="isNew" |
| 40 | + @refresh="refresh" |
| 41 | + @submit="submit($event)" |
| 42 | + @sync="sync" @logs="logs" |
| 43 | + @refreshTarget="refreshTarget" |
| 44 | + ) |
| 45 | +</template> |
| 46 | + |
| 47 | +<script lang="ts" setup> |
| 48 | +import usePagination from '~/composables/usePagination' |
| 49 | +import { ref, provide, watch, computed } from 'vue' |
| 50 | +import { useFetch, useRoute, useRouter } from 'nuxt/app' |
| 51 | +import { useQuasar } from 'quasar' |
| 52 | +import type { QTableProps } from 'quasar' |
| 53 | +import type { components, operations } from '#build/types/service-api' |
| 54 | +import { useErrorHandling } from '#imports' |
| 55 | +import { useIdentityStates, useIdentityInitStates } from '~/composables' |
| 56 | +import { identity } from '@vueuse/core' |
| 57 | +import { useIdentityStateStore } from "~/stores/identityState" |
| 58 | +type Identity = components['schemas']['IdentitiesDto'] |
| 59 | +type Response = operations['IdentitiesController_search']['responses']['200']['content']['application/json'] |
| 60 | +
|
| 61 | +const identityStateStore = useIdentityStateStore() |
| 62 | +
|
| 63 | +defineOptions({ |
| 64 | + name: 'Identities', |
| 65 | +}) |
| 66 | +
|
| 67 | +const twopan = ref<any>(null) |
| 68 | +const route = useRoute() |
| 69 | +const router = useRouter() |
| 70 | +const $q = useQuasar() |
| 71 | +const { handleError } = useErrorHandling() |
| 72 | +const form = ref<any>(null) |
| 73 | +const { getStateColor, getStateName } = useIdentityStates() |
| 74 | +const { getInitStateColor, getInitStateName, getInitStateIcon } = useIdentityInitStates() |
| 75 | +
|
| 76 | +onMounted(() => { |
| 77 | + initializePagination(identities.value?.total) |
| 78 | +}) |
| 79 | +
|
| 80 | +async function refreshTarget(target: Identity) { |
| 81 | + twopan.value.read(target) |
| 82 | + await identityStateStore.fetchToSyncCount() |
| 83 | + refreshEvent() |
| 84 | +} |
| 85 | +
|
| 86 | +const { pagination, onRequest, initializePagination } = usePagination() |
| 87 | +
|
| 88 | +const queryWithoutRead = computed(() => { |
| 89 | + const { read, ...rest } = route.query |
| 90 | + return { |
| 91 | + limit: pagination.value?.rowsPerPage, |
| 92 | + ...rest, |
| 93 | + } |
| 94 | +}) |
| 95 | +
|
| 96 | +const { |
| 97 | + data: identities, |
| 98 | + pending, |
| 99 | + refresh, |
| 100 | + error, |
| 101 | +} = await useHttp<Response>('/management/identities', { |
| 102 | + method: 'get', |
| 103 | + query: queryWithoutRead, |
| 104 | +}) |
| 105 | +
|
| 106 | +if (error.value) { |
| 107 | + $q.notify({ |
| 108 | + message: 'Impossible de récupérer les identités', |
| 109 | + type: 'negative', |
| 110 | + }) |
| 111 | +} |
| 112 | +
|
| 113 | +const { columns, visibleColumns, columnsType } = useColumnsIdentites() |
| 114 | +
|
| 115 | +const selected = ref([]) |
| 116 | +
|
| 117 | +function clearSelected() { |
| 118 | + (twopan as any).value.clearSelected() |
| 119 | +} |
| 120 | +
|
| 121 | +function refreshEvent() { |
| 122 | + refresh() |
| 123 | + selected.value = [] |
| 124 | +} |
| 125 | +
|
| 126 | +const crud = { |
| 127 | + create: false, |
| 128 | + read: true, |
| 129 | + update: true, |
| 130 | + delete: false, |
| 131 | +} |
| 132 | +
|
| 133 | +async function submit(identity: Identity) { |
| 134 | + console.log('submit from index') |
| 135 | + form.value.submit() |
| 136 | +} |
| 137 | +
|
| 138 | +async function create(identity: Identity) { |
| 139 | + console.log('create from index') |
| 140 | + form.value.create() |
| 141 | +} |
| 142 | +
|
| 143 | +async function sync(identity: Identity) { |
| 144 | + console.log('sync') |
| 145 | + form.value.sync() |
| 146 | +} |
| 147 | +
|
| 148 | +async function deleteIdentity(identity: Identity) { |
| 149 | + console.log('deleteIdentity') |
| 150 | + form.value.deleteIdentity() |
| 151 | +} |
| 152 | +
|
| 153 | +function logs(identity: Identity & { _id: string }) { |
| 154 | + router.push(`/logs?filters[:concernedTo.id]=${identity?._id}`) |
| 155 | +} |
| 156 | +
|
| 157 | +const actions = { |
| 158 | + cancel: async (row: Identity) => { |
| 159 | + console.log('cancel') |
| 160 | + }, |
| 161 | + read: async (row, onMounted = false) => { |
| 162 | + if (!onMounted) pushQuery({ key: 'read', value: row._id }) |
| 163 | + const data = await $http.get(`/management/identities/${row._id}`, { |
| 164 | + method: 'get', |
| 165 | + }) |
| 166 | + return { ...data._data?.data } |
| 167 | + }, |
| 168 | + add: async () => { |
| 169 | + return { |
| 170 | + state: IdentityState.TO_CREATE, |
| 171 | + additionalFields: { |
| 172 | + attributes: {}, |
| 173 | + objectClasses: [], |
| 174 | + }, |
| 175 | + } |
| 176 | + }, |
| 177 | + onMounted: async () => { |
| 178 | + if (route.query.read) { |
| 179 | + const id = route.query.read as string |
| 180 | + // const row = identities.value?.data.find((row) => row._id === id) |
| 181 | + // if (row) { |
| 182 | + // return row |
| 183 | + // } |
| 184 | + const { data } = await useHttp<Identity>(`/management/identities/${id}`, { |
| 185 | + method: 'get', |
| 186 | + }) |
| 187 | + return { ...data.value?.data } |
| 188 | + } |
| 189 | + return null |
| 190 | + }, |
| 191 | +} |
| 192 | +
|
| 193 | +const fieldsList = computed(() => { |
| 194 | + return columns.value!.reduce((acc: { name: string; label: string; type?: string }[], column) => { |
| 195 | + if (visibleColumns.value!.includes(column.name) && column.name !== 'actions' && column.name !== 'states') { |
| 196 | + const type = columnsType.value.find((type) => type.name === column.name)?.type |
| 197 | + acc.push({ |
| 198 | + name: column.name, |
| 199 | + label: column.label, |
| 200 | + type, |
| 201 | + }) |
| 202 | + } |
| 203 | + return acc |
| 204 | + }, []) |
| 205 | +}) |
| 206 | +
|
| 207 | +provide('fieldsList', fieldsList.value) |
| 208 | +</script> |
0 commit comments