|
| 1 | +<template lang="pug"> |
| 2 | + div.flex |
| 3 | + div |
| 4 | + q-btn.q-mx-xs(@click="submit" color="positive" icon="mdi-check" v-show="!isNew" v-if="crud.update") |
| 5 | + q-tooltip.text-body2(slot="trigger") Enregistrer les modifications |
| 6 | + q-btn.q-mx-xs(v-if="props.identity?._id" @click="sync" color="orange-8" :disabled="props.identity.state != IdentityState.TO_VALIDATE" icon="mdi-sync") |
| 7 | + q-tooltip.text-body2(slot="trigger" v-if="props.identity.state == IdentityState.TO_VALIDATE") Synchroniser l'identité |
| 8 | + q-tooltip.text-body2(slot="trigger" v-else) L'état de l'identité ne permet pas de la synchroniser |
| 9 | + q-btn.q-mx-xs(v-if="props.identity?._id" @click="logs" color="grey-8" icon="mdi-file-document" :href="'/jobs?filters[:concernedTo.id]=' + props.identity?._id") |
| 10 | + q-tooltip.text-body2(slot="trigger") Voir les logs de l'identité |
| 11 | +</template> |
| 12 | + |
| 13 | +<script lang="ts" setup> |
| 14 | +import { computed, ref, type Prop } from 'vue' |
| 15 | +import { IdentityState } from '~/constants' |
| 16 | +import { useQuasar } from 'quasar' |
| 17 | +import type { components, operations } from '#build/types/service-api' |
| 18 | +import { useRouter } from 'vue-router' |
| 19 | +import { useFetch } from 'nuxt/app' |
| 20 | +import { useIdentityStates } from '~/composables' |
| 21 | +import { useErrorHandling } from '#imports' |
| 22 | +
|
| 23 | +
|
| 24 | +type IdentityResponse = operations['IdentitiesController_search']['responses']['200']['content']['application/json'] |
| 25 | +type Identity = components['schemas']['IdentitiesDto'] |
| 26 | +const activation=ref(true) |
| 27 | +const props = defineProps({ |
| 28 | + identity: { |
| 29 | + type: Object as PropType<Identity>, |
| 30 | + required: true, |
| 31 | + }, |
| 32 | + crud: { |
| 33 | + type: Object, |
| 34 | + default: {}, |
| 35 | + }, |
| 36 | + isNew: { |
| 37 | + type: Boolean, |
| 38 | + required: true, |
| 39 | + }, |
| 40 | +}) |
| 41 | +const $q = useQuasar() |
| 42 | +const router = useRouter() |
| 43 | +const { getStateColor, getStateName } = useIdentityStates() |
| 44 | +const { handleError } = useErrorHandling() |
| 45 | +
|
| 46 | +const emits = defineEmits(['submit', 'sync', 'logs', 'create', 'delete']) |
| 47 | +
|
| 48 | +async function submit() { |
| 49 | + // console.log('submit from actions') |
| 50 | + emits('submit') |
| 51 | +} |
| 52 | +
|
| 53 | +async function create() { |
| 54 | + // console.log('submit from actions') |
| 55 | + emits('create') |
| 56 | +} |
| 57 | +function setActivateColor(){ |
| 58 | + if (props.identity.lastBackendSync != ""){ |
| 59 | + return "green" |
| 60 | + }else{ |
| 61 | + return "grey" |
| 62 | + } |
| 63 | +} |
| 64 | +function showActivate(){ |
| 65 | + if (props.identity.lastBackendSync != ""){ |
| 66 | + return true |
| 67 | + }else{ |
| 68 | + return false |
| 69 | + } |
| 70 | +} |
| 71 | +async function activate(){ |
| 72 | +
|
| 73 | +
|
| 74 | + let message="" |
| 75 | + let bouton = "" |
| 76 | + let initialStatus=0 |
| 77 | + if (props.identity.dataStatus === 0){ |
| 78 | + message="Voulez vous vraiment désactiver l'identité" |
| 79 | + bouton="Désactiver" |
| 80 | + initialStatus=1 |
| 81 | + }else{ |
| 82 | + message="Voulez vous vraiment activer l'identité" |
| 83 | + bouton="Activer" |
| 84 | + initialStatus=0 |
| 85 | + } |
| 86 | + debugger |
| 87 | + if (showActivate() === false){ |
| 88 | + props.identity.dataStatus = initialStatus |
| 89 | + return |
| 90 | + } |
| 91 | +
|
| 92 | + $q.dialog({ |
| 93 | + title: 'Confirmation', |
| 94 | + message: message, |
| 95 | + persistent: true, |
| 96 | + ok: { |
| 97 | + push: true, |
| 98 | + color: 'positive', |
| 99 | + label: bouton, |
| 100 | + }, |
| 101 | + cancel: { |
| 102 | + push: true, |
| 103 | + color: 'negative', |
| 104 | + label: 'Annuler', |
| 105 | + }, |
| 106 | + }).onOk(async() => { |
| 107 | + const requestOptions={method: 'POST', |
| 108 | + body:JSON.stringify({id:props.identity._id,status:props.identity.dataStatus === 1 ?true:false})} |
| 109 | + try{ |
| 110 | + const data=await $http.post('/management/identities/activation', requestOptions) |
| 111 | + $q.notify({ |
| 112 | + message: 'Le statut a été mis à jour : ', |
| 113 | + color: 'positive', |
| 114 | + position: 'top-right', |
| 115 | + icon: 'mdi-check-circle-outline', |
| 116 | + }) |
| 117 | + }catch(error){ |
| 118 | + props.identity.dataStatus = initialStatus |
| 119 | + $q.notify({ |
| 120 | + message: 'Impossible de modifier le statut : ' + error.response._data.message, |
| 121 | + color: 'negative', |
| 122 | + position: 'top-right', |
| 123 | + icon: 'mdi-alert-circle-outline', |
| 124 | + }) |
| 125 | + } |
| 126 | +
|
| 127 | + }).onCancel(() =>{ |
| 128 | + props.identity.dataStatus=initialStatus |
| 129 | + }) |
| 130 | +
|
| 131 | +} |
| 132 | +
|
| 133 | +
|
| 134 | +async function deleteIdentity() { |
| 135 | + $q.dialog({ |
| 136 | + title: 'Confirmation', |
| 137 | + message: 'Voulez-vous vraiment supprimer cette identité ?', |
| 138 | + persistent: true, |
| 139 | + ok: { |
| 140 | + push: true, |
| 141 | + color: 'positive', |
| 142 | + label: 'Supprimer', |
| 143 | + }, |
| 144 | + cancel: { |
| 145 | + push: true, |
| 146 | + color: 'negative', |
| 147 | + label: 'Annuler', |
| 148 | + }, |
| 149 | + }).onOk(() => { |
| 150 | + emits('delete') |
| 151 | + }) |
| 152 | +} |
| 153 | +
|
| 154 | +const stateName = computed(() => { |
| 155 | + const state = props.identity?.state |
| 156 | + return getStateName(state) |
| 157 | +}) |
| 158 | +
|
| 159 | +const stateColor = computed(() => { |
| 160 | + const state = props.identity?.state |
| 161 | + return getStateColor(state) |
| 162 | +}) |
| 163 | +
|
| 164 | +async function sync() { |
| 165 | + emits('sync') |
| 166 | +} |
| 167 | +
|
| 168 | +async function sendInit(){ |
| 169 | + //envoi le mail |
| 170 | +
|
| 171 | + const { data: result, pending, error, refresh } = await useHttp(`/management/passwd/init`, { |
| 172 | + method: 'POST', |
| 173 | + body: { uid: props.identity.inetOrgPerson.uid }, |
| 174 | + }); |
| 175 | + if (error.value) { |
| 176 | + handleError({ |
| 177 | + error: error.value, |
| 178 | + message: 'Erreur lors de l\'envoi du mail' |
| 179 | + }) |
| 180 | + } else { |
| 181 | + $q.notify({ |
| 182 | + message: 'Le mail a été envoyé', |
| 183 | + color: 'positive', |
| 184 | + position: 'top-right', |
| 185 | + icon: 'mdi-check-circle-outline', |
| 186 | + }) |
| 187 | + } |
| 188 | +} |
| 189 | +
|
| 190 | +function logs() { |
| 191 | + router.push(`/jobs?filters[:concernedTo.id]=${(props.identity as any)._id}`) |
| 192 | +} |
| 193 | +
|
| 194 | +function back() { |
| 195 | + router.push('/identities') |
| 196 | +} |
| 197 | +</script> |
0 commit comments