Commit 837571f5 authored by Theo Lecolley's avatar Theo Lecolley
Browse files

#68182 Affichage de la zone "Liens avec le systeme d'information" en fonction du privilège.

Afichage du N° Personnel dans la recherche d'intervenant en fonction du privilege.
Passage de la page Recherche intervenant en vue.js .
parent 308f1cbe
Loading
Loading
Loading
Loading
Loading
+268 −87
Changes for front/Intervenant/Recherche.vue: 268 added lines, 87 removed lines.
Original line number Diff line number Diff line
```vue
<template>
    <h3>Saisissez le nom suivi éventuellement du prénom (2 lettres minimum)</h3>
    <h1 class="page-header">Rechercher un intervenant</h1>
    <div class="p-3">

        <h3>
            Saisissez le nom suivi éventuellement du prénom (2 lettres minimum)
        </h3>

        <div class="intervenant-recherche">
            <div class="critere">
                <div>
                <input id="term" autofocus class="form-control input" placeholder="votre recherche..." type="text"
                       v-on:keyup="rechercher"/><br/>
                    <input
                        id="term"
                        ref="inputRecherche"
                        v-model="searchTerm"
                        autofocus
                        class="form-control input"
                        placeholder="votre recherche..."
                        type="text"
                        @keyup="rechercher"
                    />
                    <br />
                </div>

                <div>
                    <span class="fw-bold">Types d'intervenant : </span>
                <input v-model="checkedTypes" checked="checked" name="type[]" type="checkbox" value="permanent" v-on:change="reload()">

                    <label class="px-1">
                        <input
                            v-model="checkedTypes"
                            name="type[]"
                            type="checkbox"
                            value="permanent"
                            @change="reload"
                        />
                        Permanent
                <input v-model="checkedTypes" checked="checked" name="type[]" type="checkbox" value="vacataire" v-on:change="reload()"> Vacataire
                <input v-model="checkedTypes" checked="checked" name="type[]" type="checkbox" value="etudiant" v-on:change="reload()"> Etudiant
                    </label>

                    <label class="px-1">
                        <input
                            v-model="checkedTypes"
                            name="type[]"
                            type="checkbox"
                            value="vacataire"
                            @change="reload"
                        />
                        Vacataire
                    </label>

                    <label class="px-1">
                        <input
                            v-model="checkedTypes"
                            name="type[]"
                            type="checkbox"
                            value="etudiant"
                            @change="reload"
                        />
                        Etudiant
                    </label>
                </div>

                <br />
            </div>
        </div>

        <div v-if="loading" class="text-center my-3" role="status">
            <div class="spinner-border">
                <span class="visually-hidden">Chargement...</span>
            </div>
        </div>

    <table v-if="intervenants.length > 0" class="table table-bordered table-hover">
        <table
            v-if="intervenants.length > 0"
            class="table table-bordered table-hover"
        >
            <thead>
            <tr>
                <th style="width: 90px"></th>
@@ -30,30 +83,43 @@
                <th>Structure</th>
                <th>Statut</th>
                <th>Date de naissance</th>
            <th>N° Personnel</th>
                <th v-if="numeroPersonnel">N° Personnel</th>
            </tr>
            </thead>

            <tbody>
        <tr v-for="(intervenant,code) in intervenants" :class="{'bg-danger': intervenant.destruction!==null}"
            :title="(intervenant.destruction!==null) ? 'Fiche historisé' : ''">
            <td style="">
                <a :href="urlFiche(intervenant['code'])"><i class="fas fa-eye"></i> Fiche</a>
            <tr
                v-for="intervenant in intervenants"
                :key="intervenant.code"
                :class="{ 'bg-danger': intervenant.destruction !== null }"
                :title=" intervenant.destruction !== null  ? 'Fiche historisé' : ''"
            >
                <td>
                    <a :href="urlFiche(intervenant.code)">
                        <i class="fas fa-eye"></i>
                        Fiche
                    </a>
                </td>
            <td>{{ intervenant['civilite'] }}</td>
            <td>{{ intervenant['nom'] }}</td>
            <td>{{ intervenant['prenom'] }}</td>
            <td>{{ intervenant['structure'] }}</td>
            <td>{{ intervenant['statut'] }}</td>

                <td>{{ intervenant.civilite }}</td>
                <td>{{ intervenant.nom }}</td>
                <td>{{ intervenant.prenom }}</td>
                <td>{{ intervenant.structure }}</td>
                <td>{{ intervenant.statut }}</td>

                <td>
                    <u-date :value="intervenant['date-naissance']" />
                </td>
            <td>{{ intervenant['numero-personnel'] }}</td>
        </tr>

                <td v-if="intervenant['numero-personnel']">{{ intervenant['numero-personnel'] }}</td>
            </tr>
            </tbody>
        </table>

    <table v-if="intervenants.length == 0 && noResult == 1" class="table table-bordered table-hover">
        <table
            v-else-if="intervenants.length === 0 && noResult === 1"
            class="table table-bordered table-hover"
        >
            <thead>
            <tr>
                <th style="width: 90px"></th>
@@ -66,111 +132,226 @@
                <th>N° Personnel</th>
            </tr>
            </thead>

            <tbody>
            <tr>
            <td colspan="8" style="text-align:center">Aucun intervenant trouvé</td>
                <td colspan="8" style="text-align: center">
                    Aucun intervenant trouvé
                </td>
            </tr>

            </tbody>
        </table>
</template>

        <div class="mb-3">
            <a
                v-if="canAddIntervenant"
                :href="urlCreation"
                class="btn btn-primary"
            >
                Ajout d'un nouvel intervenant
            </a>
        </div>

<script>
        <div>
            <h3 v-if="recents.length > 0">
                Intervenants récemment consultés :
            </h3>
            <table
                v-if="recents.length > 0"
                class="table table-bordered table-hover"
            >
                <thead>
                <tr>
                    <th style="width: 90px"></th>
                    <th>Civilité</th>
                    <th>Nom</th>
                    <th>Prenom</th>
                    <th>Structure</th>
                    <th>Statut</th>
                    <th>Date de naissance</th>
                    <th v-if="numeroPersonnel">N° Personnel</th>
                </tr>
                </thead>

                <tbody>
                <tr
                    v-for="recent in recents"
                    :key="recent.code"
                    :title=" recent.destruction !== null  ? 'Fiche historisé' : ''"
                >
                    <td>
                        <a :href="urlFiche(recent.code)">
                            <i class="fas fa-eye"></i>
                            Fiche
                        </a>
                    </td>

export default {
    name: 'Recherche',
                    <td>{{ recent.civilite }}</td>
                    <td>{{ recent.nom }}</td>
                    <td>{{ recent.prenom }}</td>
                    <td>{{ recent.structure }}</td>
                    <td>{{ recent.statut }}</td>

    data()
    {
        return {
            searchTerm: '',
            noResult: 0,
            intervenants: [],
            checkedTypes: ['vacataire', 'permanent', 'etudiant'],
        };
                    <td>
                        <u-date :value="recent['date-naissance']" />
                    </td>

                    <td v-if="numeroPersonnel">{{ recent['numero-personnel'] }}</td>
                </tr>
                </tbody>
            </table>
        </div>

    </div>
</template>

<script setup>
import { ref, onBeforeUnmount } from 'vue';

const props = defineProps({
    canAddIntervenant: {
        type: Boolean,
        default: false,
    },
    mixins: [Util],
    methods: {
        rechercher: function (event)
        {
            this.searchTerm = event.currentTarget.value;
            if (this.searchTerm == '') {
                this.noResult = 0;
            }
            if (this.searchTerm != '') {
                this.reload();
            }
    urlCreation: {
        type: String,
        default: '',
    },
});

        urlFiche(code)
        {
            return unicaenVue.url('intervenant/code:' + code + '/voir');
        },
const loading = ref(false);
const searchTerm = ref('');
const noResult = ref(0);
const intervenants = ref([]);
const recents = ref([]);
const checkedTypes = ref(['vacataire', 'permanent', 'etudiant',]);
let timer = null;
const inputRecherche = ref(null);
const numeroPersonnel = ref(false);

        reload()
        {
            var inputRecherche = document.getElementById('term');
            inputRecherche.focus();
loadRecent()

            if (this.timer) {
                clearTimeout(this.timer);
                this.timer = null;
function rechercher() {
    if (searchTerm.value === '') {
        noResult.value = 0;
        intervenants.value = [];
        return;
    }
            this.timer = setTimeout(() => {

                unicaenVue.axios.post(
                    unicaenVue.url("intervenant/recherche-json"), {
                        term: this.searchTerm,
                        types: this.checkedTypes,
    reload();
}
                )
                    .then(response => {
                        let datas = response.data;
                        let datasFiltered = [];

                        for (const intervenant in datas) {
                            if (datas[intervenant].typeIntervenantCode == 'E' && this.checkedTypes.includes('vacataire')) {
                                datasFiltered.push(datas[intervenant]);
                                continue;

function urlFiche(code) {
    return unicaenVue.url(
        'intervenant/code:' + code + '/voir'
    );
}
                            if (datas[intervenant].typeIntervenantCode == 'P' && this.checkedTypes.includes('permanent')) {
                                datasFiltered.push(datas[intervenant]);
                                continue;

function loadRecent() {
    if (timer) {
        clearTimeout(timer);
        timer = null;
    }
                            if (datas[intervenant].typeIntervenantCode == 'S' && this.checkedTypes.includes('etudiant')) {
                                datasFiltered.push(datas[intervenant]);
                                continue;

    timer = setTimeout(async () => {
        try {
            const response = await unicaenVue.axios.get(
                unicaenVue.url('intervenant/rechercher-json')
            );

            const datas = response.data;

            // Convertit l'objet en tableau d'intervenants
            recents.value = Array.isArray(datas)
                ? datas
                : Object.values(datas);

            numeroPersonnel.value = recents.value.some(
                recent => Boolean(recent['numero-personnel'])
            );

        } catch (error) {
            console.error(error);
        }
    }, 300);
}


function reload() {
    inputRecherche.value?.focus();

    if (timer) {
        clearTimeout(timer);
        timer = null;
    }
                        this.intervenants = datasFiltered;

                        if (this.intervenants.length == 0) {
                            this.noResult = 1;
                        } else {
                            this.noResult = 0;
    timer = setTimeout(async () => {
        loading.value = true;

        try {
            const response = await unicaenVue.axios.post(
                unicaenVue.url('intervenant/recherche-json'),
                {
                    term: searchTerm.value,
                    types: checkedTypes.value,
                }
            );

            const datas = response.data;
            const datasFiltered = [];

            for (const intervenant of datas) {
                if (
                    intervenant.typeIntervenantCode === 'E' &&
                    checkedTypes.value.includes('vacataire')
                ) {
                    datasFiltered.push(intervenant);
                    continue;
                }

                    })
                    .catch(response => {
                        console.log(response.message);
                    });
            }, 800);
                if (
                    intervenant.typeIntervenantCode === 'P' &&
                    checkedTypes.value.includes('permanent')
                ) {
                    datasFiltered.push(intervenant);
                    continue;
                }

                if (
                    intervenant.typeIntervenantCode === 'S' &&
                    checkedTypes.value.includes('etudiant')
                ) {
                    datasFiltered.push(intervenant);
                    continue;
                }
            }

            intervenants.value = datasFiltered;

            numeroPersonnel.value = datas.some(
                intervenant => Boolean(intervenant['numero-personnel'])
            );

            noResult.value =
                intervenants.value.length === 0 ? 1 : 0;

        } catch (error) {
            console.error(error);
        } finally {
            loading.value = false;
        }
    }, 800);
}


onBeforeUnmount(() => {
    if (timer) {
        clearTimeout(timer);
    }
});

</script>

<style scoped>

</style>
+6 −1
Changes for module/Intervenant/config/intervenant.config.php: 6 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -19,6 +19,11 @@ return [
                    'controller' => Controller\IntervenantController::class,
                    'action'     => 'rechercher',
                ],
                'rechercher-json'            => [
                    'route'      => '/rechercher-json',
                    'controller' => Controller\IntervenantController::class,
                    'action'     => 'rechercher-json',
                ],
                'recherche-intervenant' => [
                    'route'      => '/recherche-intervenant',
                    'controller' => Controller\IntervenantController::class,
@@ -161,7 +166,7 @@ return [
    'guards' => [
        [
            'controller' => Controller\IntervenantController::class,
            'action'     => ['rechercher', 'recherche', 'recherche-json', 'recherche-intervenant'],
            'action'     => ['rechercher','rechercher-json', 'recherche', 'recherche-json', 'recherche-intervenant'],
            'privileges' => [
                Privileges::INTERVENANT_RECHERCHE,
            ],
+28 −2
Changes for module/Intervenant/src/Controller/IntervenantController.php: 28 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -89,6 +89,13 @@ class IntervenantController extends AbstractController
        return compact('recents');
    }

    public function rechercherJsonAction()
    {
        $recents = $this->getIntervenantsRecents();

        return new AxiosModel($recents);
    }



    /**
@@ -97,6 +104,7 @@ class IntervenantController extends AbstractController
     */
    protected function getIntervenantsRecents()
    {
        $affichageNumeroPerso = $this->isAllowed(Privileges::getResourceId(Privileges::INTERVENANT_ADRESSE));
        $container = $this->getSessionContainer();
        //$container->recents = [];
        if (isset($container->recents)) {
@@ -110,6 +118,13 @@ class IntervenantController extends AbstractController
                if (!$intervenant) {
                    unset($recents[$i]);
                    unset($container->recents[$i]);

                }
                if (!$affichageNumeroPerso && array_key_exists('numero-personnel', $recent)) {
                    unset($recents[$i]['numero-personnel']);
                    unset($container->recents[$i]['numero-personnel']);
                }elseif ($affichageNumeroPerso && !array_key_exists('numero-personnel', $recent)) {
                    $recents[$i]['numero-personnel'] = $intervenant->getCodeRh();
                }
            }

@@ -121,11 +136,14 @@ class IntervenantController extends AbstractController





    public function rechercheJsonAction()
    {
        $recherche = $this->getProcessusIntervenant()->recherche();
        $canShowHistorises = $this->isAllowed(Privileges::getResourceId(Privileges::INTERVENANT_VISUALISATION_HISTORISES));
        $recherche->setShowHisto($canShowHistorises);
        $affichageNumeroPerso = $this->isAllowed(Privileges::getResourceId(Privileges::INTERVENANT_ADRESSE));
        $intervenants = [];
        $term = $this->axios()->fromPost('term');
        $requestedTypes = (array)$this->axios()->fromPost('types', []);
@@ -143,7 +161,7 @@ class IntervenantController extends AbstractController

        if (!empty($term)) {
            $intervenants = array_values(
                $recherche->rechercher($term, 40, ':CODE', $typeCodes)
                $recherche->rechercher($term, 40, ':CODE', $typeCodes, $affichageNumeroPerso)
            );
        }

@@ -223,6 +241,11 @@ class IntervenantController extends AbstractController
    protected function addIntervenantRecent(Intervenant $intervenant)
    {
        $container = $this->getSessionContainer();

        $affichageNumeroPerso = $this->isAllowed(
            Privileges::getResourceId(Privileges::INTERVENANT_ADRESSE)
        );

        if (!isset($container->recents)) {
            $container->recents = [];
        }
@@ -252,9 +275,12 @@ class IntervenantController extends AbstractController
                'structure'        => (string)$intervenant->getStructure(),
                'statut'           => (string)$intervenant->getStatut(),
                'code'             => $intervenant->getCode(),
                'numero-personnel' => $intervenant->getCodeRh(),
                '__horo_ajout__'   => (int)date('U'),
            ];

            if ($affichageNumeroPerso) {
                $container->recents[$intervenant->getCode()]['numero-personnel'] = $intervenant->getCodeRh();
            }
        } else {
            if (!isset($container->recents[$intervenant->getCode()]['statut'])) {
                $container->recents[$intervenant->getCode()]['statut'] = [$container->recents[$intervenant->getCode()]['statut']];
+14 −5
Changes for module/Intervenant/src/Processus/RechercheProcessus.php: 14 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -6,12 +6,15 @@ namespace Intervenant\Processus;
use Application\Service\Traits\ContextServiceAwareTrait;
use UnicaenApp\Service\EntityManagerAwareTrait;
use UnicaenApp\Util;
use Application\Provider\Privilege\Privileges;


class RechercheProcessus
{
    use EntityManagerAwareTrait;
    use ContextServiceAwareTrait;


    /**
     * @var bool
     */
@@ -25,12 +28,14 @@ class RechercheProcessus
     *
     * @return array
     */
    public function rechercher ($critere, $limit = 50, string $key = ':CODE', array $typeIntervenantCodes = [])


    public function rechercher ($critere, $limit = 50, string $key = ':CODE', array $typeIntervenantCodes = [],bool $affichageNumeroPerso)
    {
        try {
            return $this->rechercheGenerique($critere, $limit, $key, false, $typeIntervenantCodes);
            return $this->rechercheGenerique($critere, $limit, $key, false, $typeIntervenantCodes, $affichageNumeroPerso);
        } catch (\Exception $e) {
            return $this->rechercheGenerique($critere, $limit, $key, true, $typeIntervenantCodes);
            return $this->rechercheGenerique($critere, $limit, $key, true, $typeIntervenantCodes, $affichageNumeroPerso);
        }
    }

@@ -41,8 +46,10 @@ class RechercheProcessus
        $limit = 50,
        string $key = ':CODE',
        $onlyLocale = false,
        array $typeIntervenantCodes = []
        array $typeIntervenantCodes = [],
        bool $affichageNumeroPerso
    )

    {
        if (strlen($critere) < 2) return [];

@@ -108,11 +115,13 @@ class RechercheProcessus
                    'statut'                 => $r['STATUT'],
                    'typeIntervenantCode'    => $r['TYPE_INTERVENANT_CODE'],
                    'typeIntervenantLibelle' => $r['TYPE_INTERVENANT_LIBELLE'],
                    'numero-personnel'       => $r['CODE_RH'],
                    'destruction'            => $r['HISTO_DESTRUCTION'],
                    'code'                   => $r['CODE'],

                ];
                if ($affichageNumeroPerso == true) {
                    $intervenants[$k]['numero-personnel'] = $r['CODE_RH'];
                }
            } else {
                if ($intervenants[$k]['destruction'] && !$r['HISTO_DESTRUCTION']) {
                    $intervenants[$k]['destruction'] = null;
+7 −1
Changes for module/Intervenant/view/intervenant/intervenant/liste.phtml: 7 added lines, 1 removed line.
Original line number Diff line number Diff line
<?php
/* @var $intervenants array */
?>

<table class="table table-bordered table-sm">
    <thead>
    <tr>
@@ -11,7 +12,10 @@
        <th style="width:15%">Structure</th>
        <th style="width:15%">Statut</th>
        <th style="width:15%">Date de naissance</th>
        <?php if (isset($intervenants) && !empty($intervenants)
                && array_filter($intervenants, fn($i) => isset($i['numero-personnel']))): ?>
            <th style="width:10%">N° personnel</th>
        <?php endif; ?>
    </tr>
    </thead>
    <tbody class="table-hover">
@@ -35,7 +39,9 @@
            <?php endif; ?>
        </td>
        <td><?= $intervenant['date-naissance']->format(\Application\Constants::DATE_FORMAT) ?></td>
        <td><?= $intervenant['numero-personnel'] ?></td>
        <?php if (isset($intervenant['numero-personnel'])): ?>
            <td><?= $this->escapeHtml($intervenant['numero-personnel']) ?></td>
        <?php endif; ?>
    </tr>
    </tbody>
    <?php endforeach; ?>
Loading