|
| 1 | +<template> |
| 2 | + <q-table |
| 3 | + flat bordered |
| 4 | + title="Identités doubles" |
| 5 | + dense |
| 6 | + :rows="rows1" |
| 7 | + :columns="fieldsName" |
| 8 | + row-key="k" |
| 9 | + :rows-per-page-options="[20,50,0]" |
| 10 | + rows-per-page-label="Lignes par page" |
| 11 | + no-data-label="Aucune donnée" |
| 12 | + loading-label="Chargement..." |
| 13 | + no-results-label="Aucun résultat" |
| 14 | + > |
| 15 | + <template v-slot:body="props"> |
| 16 | + <q-tr :props="props"> |
| 17 | + <q-td |
| 18 | + v-for="col in props.cols" |
| 19 | + :key="col.name" |
| 20 | + :props="props" |
| 21 | + > |
| 22 | + <template v-if="col.name === 'id1'" > |
| 23 | + <q-btn round size="sm" color="green" icon="mdi-account-edit" @click="edit(col.value,'text-positive')"> |
| 24 | + <q-tooltip class="text-body2">Editer l'identité</q-tooltip> |
| 25 | + </q-btn> |
| 26 | + <q-btn round size="sm" color="green" icon="mdi-account-multiple" @click="fusion1(props.cols[0].value,props.cols[5].value)"> |
| 27 | + <q-tooltip class="text-body2">fusionner les deux identités</q-tooltip> |
| 28 | + </q-btn> |
| 29 | + <q-btn round size="sm" color="green" icon="mdi-account-remove"> |
| 30 | + <q-tooltip class="text-body2">supprimer l'identité</q-tooltip> |
| 31 | + </q-btn> |
| 32 | + </template> |
| 33 | + <template v-else-if="col.name === 'id2'"> |
| 34 | + <q-btn round size="sm" color="red" icon="mdi-account-edit" @click="edit(col.value,'text-negative')"> |
| 35 | + <q-tooltip class="text-body2">Editer l'identité</q-tooltip> |
| 36 | + </q-btn> |
| 37 | + <q-btn round size="sm" color="red" icon="mdi-account-multiple" @click="fusion1(props.cols[5].value,props.cols[0].value)"> |
| 38 | + <q-tooltip class="text-body2">fusionner les deux identités</q-tooltip> |
| 39 | + </q-btn> |
| 40 | + <q-btn round size="sm" color="red" icon="mdi-account-remove"> |
| 41 | + <q-tooltip class="text-body2">supprimer l'identité</q-tooltip> |
| 42 | + </q-btn> |
| 43 | + </template> |
| 44 | + <template v-else> |
| 45 | + {{ col.value }} |
| 46 | + </template> |
| 47 | + |
| 48 | + </q-td> |
| 49 | + </q-tr> |
| 50 | + </template> |
| 51 | + </q-table> |
| 52 | + <q-dialog v-model="editForm" full-width full-height persistent> |
| 53 | + <q-card> |
| 54 | + <q-card-section class="row items-center q-pb-none"> |
| 55 | + <h6 :class="cnColor">{{ cn }}</h6> |
| 56 | + <q-space></q-space> |
| 57 | + <q-btn class="q-mx-xs" icon="mdi-check" color="positive" @click="submit"> |
| 58 | + <q-tooltip>Enregistrer</q-tooltip> |
| 59 | + </q-btn> |
| 60 | + <q-btn class="q-mx-xs" icon="mdi-close" color="negative" @click="closeModal" > |
| 61 | + <q-tooltip>Quitter</q-tooltip> |
| 62 | + </q-btn> |
| 63 | + </q-card-section> |
| 64 | + <q-card-section> |
| 65 | + <sesame-identity-form |
| 66 | + :identity="identity" |
| 67 | + ref="form" |
| 68 | + @submit="submit($event)" |
| 69 | + > |
| 70 | + </sesame-identity-form> |
| 71 | + </q-card-section> |
| 72 | + </q-card> |
| 73 | + </q-dialog> |
| 74 | +</template> |
| 75 | +<script setup> |
| 76 | +import {ref} from "vue"; |
| 77 | +import {useQuasar} from "quasar"; |
| 78 | +import { useRouter } from 'vue-router' |
| 79 | +const router=useRouter() |
| 80 | +const $q=useQuasar() |
| 81 | +const editForm=ref(false) |
| 82 | +const identity=ref(null) |
| 83 | +const cn=ref("") |
| 84 | +const cnColor=ref("text-positive") |
| 85 | +const refreshWindows=ref(false) |
| 86 | +const rows=[] |
| 87 | +const form=ref(null) |
| 88 | +//attention si l'ordre des colonnes changent changer le @click des boutons fusion |
| 89 | +const fieldsName=[ |
| 90 | + {name:'id1',label:'action',field:'id1', align: 'center',classes:"leftidlight"}, |
| 91 | + {name:'uid1',label:'identité 1',field:'uid1', align: 'left',classes:"leftid"}, |
| 92 | + {name:'cn1',label:'Nom Prenom 1',field:'cn1', align: 'left',classes:"leftidlight"}, |
| 93 | + {name:'employeeNumber1',label:'Numero',field:'employeeNumber1', align: 'left',classes:"leftidlight"}, |
| 94 | + {name:'departmentNumber1',label:'Departement',field:'departmentNumber1', align: 'left',classes:"leftidlight"}, |
| 95 | + {name:'id2',label:'action',field:'id2', align: 'center',classes:"rightidlight"}, |
| 96 | + {name:'uid2',label:'identité 2',field:'uid2', align: 'left',classes:"rightid"}, |
| 97 | + {name:'cn2',label:'Nom Prenom 2',field:'cn2', align: 'left',classes:"rightidlight"}, |
| 98 | + {name:'employeeNumber2',label:'Numero',field:'employeeNumber2', align: 'left',classes:"rightidlight"}, |
| 99 | + {name:'departmentNumber2',label:'Departement',field:'departmentNumber2', align: 'left',classes:"rightidlight"}, |
| 100 | +] |
| 101 | +const actions = { |
| 102 | + read: async (id) => { |
| 103 | + const data = await $http.get(`/management/identities/` + id , { |
| 104 | + method: 'get', |
| 105 | + }) |
| 106 | + return {...data._data?.data} |
| 107 | + } |
| 108 | +} |
| 109 | +
|
| 110 | +const { data: rows1, pending, error, refresh } = await useHttp('/management/identities/duplicates', { |
| 111 | + method: 'GET', |
| 112 | + transform: (result)=>{ |
| 113 | +
|
| 114 | + const allFields=result.data.map((enr)=>{ |
| 115 | + return { |
| 116 | + k:enr.k, |
| 117 | + id1:enr.data.at(0)._id, |
| 118 | + uid1:enr.data.at(0).uid, |
| 119 | + cn1:enr.data.at(0).cn, |
| 120 | + employeeNumber1:enr.data.at(0).employeeNumber, |
| 121 | + departmentNumber1:enr.data.at(0).departmentNumber.join(','), |
| 122 | + id2:enr.data.at(1)._id, |
| 123 | + uid2:enr.data.at(1).uid, |
| 124 | + cn2:enr.data.at(1).cn, |
| 125 | + employeeNumber2:enr.data.at(1).employeeNumber, |
| 126 | + departmentNumber2:enr.data.at(1).departmentNumber.join(','), |
| 127 | + } |
| 128 | + //return { k: enr.k, uid1: enr.data[Ø].uid, cn1:enr.data[0].cn, uid2: enr.data[1].uid, cn2:enr.data[1].cn,} |
| 129 | + }) |
| 130 | + console.log("RESULT " + allFields) |
| 131 | + return allFields |
| 132 | + } |
| 133 | +}); |
| 134 | +async function edit(id,colorClass){ |
| 135 | + identity.value=await actions.read(id) |
| 136 | + cnColor.value=colorClass |
| 137 | + cn.value=identity.value.inetOrgPerson.cn |
| 138 | + editForm.value=true |
| 139 | +} |
| 140 | +
|
| 141 | +async function fusion1(id1,id2){ |
| 142 | + $q.dialog({ |
| 143 | + title: 'Fusion des deux identités', |
| 144 | + message: 'Voulez-vous fusionner ces deux identités ?', |
| 145 | + persistent: true, |
| 146 | + html: true, |
| 147 | + ok: { |
| 148 | + push: true, |
| 149 | + color: 'positive', |
| 150 | + label: 'Fusionner', |
| 151 | + }, |
| 152 | + cancel: { |
| 153 | + push: true, |
| 154 | + color: 'negative', |
| 155 | + label: 'Annuler', |
| 156 | + }, |
| 157 | + }).onOk(async () => { |
| 158 | + const requestOptions={method: 'POST', |
| 159 | + body:JSON.stringify({id1:id1,id2:id2})} |
| 160 | + const data=await $http.post('/management/identities/fusion', requestOptions) |
| 161 | + .catch(error => { |
| 162 | + console.error('There was an error!', error); |
| 163 | + }) |
| 164 | + edit(data._data.newId,"dark") |
| 165 | + }) |
| 166 | +} |
| 167 | +
|
| 168 | +async function submit() { |
| 169 | + form.value.submit() |
| 170 | + refreshWindows.value=true |
| 171 | +} |
| 172 | +function closeModal(){ |
| 173 | + editForm.value=false |
| 174 | + refresh() |
| 175 | +} |
| 176 | +</script> |
| 177 | +<style> |
| 178 | +.leftid { |
| 179 | + color:white; |
| 180 | + background:green !important; |
| 181 | +} |
| 182 | +.leftidlight { |
| 183 | + color:black; |
| 184 | + background: #cfe4d4 !important; |
| 185 | +} |
| 186 | +.rightid { |
| 187 | + color:white; |
| 188 | + background:darkred !important; |
| 189 | +} |
| 190 | +.rightidlight { |
| 191 | + color:black; |
| 192 | + background: #ecd6d6 !important; |
| 193 | +} |
| 194 | +</style> |
0 commit comments