|
| 1 | +import type { QTableProps } from 'quasar' |
| 2 | +import type { components } from '#build/types/service-api' |
| 3 | + |
| 4 | +type Identity = components['schemas']['IdentitiesDto'] |
| 5 | + |
| 6 | +interface ColumnConfig { |
| 7 | + name: string; |
| 8 | + label: string; |
| 9 | + field: string | ((row: any) => any); |
| 10 | + required?: boolean; |
| 11 | + align?: "left" | "right" | "center"; |
| 12 | + sortable?: boolean; |
| 13 | + sort?: (a: any, b: any, rowA: any, rowB: any) => number; |
| 14 | + rawSort?: (a: any, b: any, rowA: any, rowB: any) => number; |
| 15 | + sortOrder?: "ad" | "da"; |
| 16 | + format?: (val: any, row: any) => any; |
| 17 | + style?: string | ((row: any) => string); |
| 18 | + classes?: string | ((row: any) => string); |
| 19 | + headerStyle?: string; |
| 20 | + headerClasses?: string; |
| 21 | +} |
| 22 | + |
| 23 | +const config = useAppConfig() |
| 24 | +const daysjs = useDayjs() |
| 25 | + |
| 26 | +function processFieldValue(row: any, field: any) { |
| 27 | + if (field.type === 'function') { |
| 28 | + return eval(field.value); |
| 29 | + } |
| 30 | + return row[field]; |
| 31 | +} |
| 32 | + |
| 33 | +function processFormat(value: any, format: any) { |
| 34 | + if (format && format.type === 'function') { |
| 35 | + return eval(format.value); |
| 36 | + } |
| 37 | + return value; |
| 38 | +} |
| 39 | + |
| 40 | +export function useColumnsIdentites() { |
| 41 | + const columns = ref<QTableProps['columns']>( |
| 42 | + [ |
| 43 | + { |
| 44 | + name: 'states', |
| 45 | + label: 'Etats', |
| 46 | + field: 'states', |
| 47 | + align: 'left', |
| 48 | + }, |
| 49 | + ...config?.identitiesColumns?.entries || [], |
| 50 | + { |
| 51 | + name: 'metadata.lastUpdatedAt', |
| 52 | + label: 'Date de modification', |
| 53 | + field: (row: Identity) => row?.metadata?.lastUpdatedAt, |
| 54 | + format: (val: string) => daysjs(val).format('DD/MM/YYYY HH:mm'), |
| 55 | + align: 'left', |
| 56 | + sortable: true, |
| 57 | + }, |
| 58 | + { |
| 59 | + name: 'metadata.createdAt', |
| 60 | + label: 'Date de création', |
| 61 | + field: (row: Identity) => row?.metadata?.createdAt, |
| 62 | + format: (val: string) => daysjs(val).format('DD/MM/YYYY HH:mm'), |
| 63 | + align: 'left', |
| 64 | + sortable: true, |
| 65 | + }, |
| 66 | + { |
| 67 | + name: 'actions', |
| 68 | + label: 'Actions', |
| 69 | + field: 'actions', |
| 70 | + align: 'left', |
| 71 | + }, |
| 72 | + ].map((col: any) => ({ |
| 73 | + ...col, |
| 74 | + field: typeof col.field === 'function' ? col.field : (row: Identity) => processFieldValue(row, col.field), |
| 75 | + format: typeof col.format === 'function' ? col.format : (val: any) => processFormat(val, col.format), |
| 76 | + })) as ColumnConfig[] |
| 77 | + ); |
| 78 | + |
| 79 | + // const columns = ref<QTableProps['columns']>([ |
| 80 | + // { |
| 81 | + // name: 'inetOrgPerson.uid', |
| 82 | + // label: 'ID', |
| 83 | + // field: (row: Identity) => row?.inetOrgPerson?.uid, |
| 84 | + // align: 'left', |
| 85 | + // sortable: true, |
| 86 | + // }, |
| 87 | + // { |
| 88 | + // name: 'inetOrgPerson.employeeNumber', |
| 89 | + // label: 'EmployeeNumber', |
| 90 | + // field: (row: Identity) => row?.inetOrgPerson?.employeeNumber, |
| 91 | + // align: 'left', |
| 92 | + // sortable: true, |
| 93 | + // }, |
| 94 | + // { |
| 95 | + // name: 'additionalFields.attributes.supannPerson.supannTypeEntiteAffectation', |
| 96 | + // label: 'Affectation', |
| 97 | + // field: (row: Identity) => row.additionalFields?.attributes?.supannPerson?.supannTypeEntiteAffectation, |
| 98 | + // align: 'left', |
| 99 | + // sortable: true, |
| 100 | + // }, |
| 101 | + // { |
| 102 | + // name: 'inetOrgPerson.cn', |
| 103 | + // label: 'Nom', |
| 104 | + // field: (row: Identity) => row?.inetOrgPerson?.cn, |
| 105 | + // align: 'left', |
| 106 | + // sortable: true, |
| 107 | + // }, |
| 108 | + // { |
| 109 | + // name: 'inetOrgPerson.givenName', |
| 110 | + // label: 'Prénom', |
| 111 | + // field: (row: Identity) => row?.inetOrgPerson?.givenName, |
| 112 | + // align: 'left', |
| 113 | + // sortable: false, |
| 114 | + // }, |
| 115 | + // { |
| 116 | + // name: 'metadata.lastUpdatedAt', |
| 117 | + // label: 'Date de modification', |
| 118 | + // field: (row: Identity) => row?.metadata?.lastUpdatedAt, |
| 119 | + // format: (val: string) => daysjs(val).format('DD/MM/YYYY HH:mm'), |
| 120 | + // align: 'left', |
| 121 | + // sortable: true, |
| 122 | + // }, |
| 123 | + // { |
| 124 | + // name: 'metadata.createdAt', |
| 125 | + // label: 'Date de création', |
| 126 | + // field: (row: Identity) => row?.metadata?.createdAt, |
| 127 | + // format: (val: string) => daysjs(val).format('DD/MM/YYYY HH:mm'), |
| 128 | + // align: 'left', |
| 129 | + // sortable: true, |
| 130 | + // }, |
| 131 | + // { |
| 132 | + // name: 'actions', |
| 133 | + // label: 'Actions', |
| 134 | + // field: 'actions', |
| 135 | + // align: 'left', |
| 136 | + // }, |
| 137 | + // ]) |
| 138 | + |
| 139 | + return { |
| 140 | + columns, |
| 141 | + } |
| 142 | +} |
0 commit comments