Commit 7d4e5740 authored by Antony Le Courtes's avatar Antony Le Courtes
Browse files

Finalisation vuejs pour les pièces justificatives

parent 2806b80a
Loading
Loading
Loading
Loading
Loading
+1 −13
Original line number Diff line number Diff line
@@ -32,19 +32,7 @@ return [
            'default'     => null,
            'position'    => 1,
            'commentaire' => null,
        ],
        'VALIDATION_ID'         => [
            'name'        => 'VALIDATION_ID',
            'type'        => 'int',
            'bdd-type'    => 'NUMBER',
            'length'      => 0,
            'scale'       => null,
            'precision'   => null,
            'nullable'    => true,
            'default'     => null,
            'position'    => 9,
            'commentaire' => null,
        ],
        ]
    ],
];

+7 −8
Original line number Diff line number Diff line
<template>
    <div>
        <h1>Liste pieces jointes</h1>

    <pieceJointe v-for="(pieceJointe, key) in datasPiecesJointes"
                 :datas="pieceJointe"
                 :intervenant="intervenant"
                 @refresh="getPiecesJointes"></pieceJointe>

    </div>

</template>

<script>
+189 −86
Original line number Diff line number Diff line
<template>
    <div class="tpj tpj-obligatoire tpj-1 card bg-success  upload-container">
    <div :class="[
        'tpj',
        'card',
        'upload-container',
        datas.pieceJointe?.validation ? 'bg-success' : 'bg-default',
        datas.pieceJointe?.id ? 'tpj-' + datas.pieceJointe.id : ''
    ]">
        <div class="card-header card-header-h3 ">
            <h5>
                <div class="validation-bar float-end" data-url="">
                    <div v-if="this.datas.pieceJointe">
                    <div v-if="datas.pieceJointe">
                        <!-- actions de validation de la pièce jointe entière -->
                        <button v-if="!this.datas.pieceJointe.validation" :id="'valider-' + this.datas.pieceJointe.id"
                                class="btn btn-success"
                        <button v-if="!datas.pieceJointe.validation" :id="'valider-' + datas.pieceJointe.id"
                                class="btn btn-success me-2"
                                type="button"
                                :title="'Valider la pièce justificative \'' +  this.datas.typePieceJointe.libelle + '\''"
                                :title="'Valider la pièce justificative \'' +  datas.typePieceJointe.libelle + '\''"
                                @click="actionPieceJointe($event)"
                                :data-url="this.urlValiderPiecesJointes">
                                :data-url="urlValiderPiecesJointes">

                            <u-icon id="action" name="thumbs-up"
                                    style="color:black;"/>
                            Valider
                            <!--                        <u-icon id="waiting" name="spin" rotate="right"
                                                            style="color:white;display:none;"/>-->
                        </button>
                        <button v-if="!this.datas.pieceJointe.validation" :id="'refuser-' + this.datas.pieceJointe.id"
                        <button v-if="!datas.pieceJointe.validation" :id="'refuser-' + datas.pieceJointe.id"
                                class="btn btn-danger"
                                type="button"
                                :title="'Refuser la pièce justificative \'' +  this.datas.typePieceJointe.libelle + '\''"
                                :title="'Refuser la pièce justificative \'' +  datas.typePieceJointe.libelle + '\''"
                                @click="actionPieceJointe($event, true)" title="Refuser la pièce jointe"
                                :data-url="this.urlRefuserPiecesJointes">
                                :data-url="urlRefuserPiecesJointes">
                            <u-icon id="action" name="trash"
                                    style="color:black;"/>
                            Refuser
                            <!--                        <u-icon id="waiting" name="spin" rotate="right"
                                                            style="color:white;display:none;"/>-->
                        </button>
                        <button v-if="this.datas.pieceJointe.validation" :id="'devalider-' + this.datas.pieceJointe.id"
                        <button v-if="this.datas.pieceJointe.validation" :id="'devalider-' + datas.pieceJointe.id"
                                class="btn btn-danger"
                                type="button"
                                :title="'Dévalider la pièce justificative \'' +  this.datas.typePieceJointe.libelle + '\''"
                                :title="'Dévalider la pièce justificative \'' +  datas.typePieceJointe.libelle + '\''"
                                @click="actionPieceJointe($event)"
                                :data-url="this.urlDevaliderPiecesJointes">
                                :data-url="urlDevaliderPiecesJointes">
                            <u-icon id="action" name="thumbs-up"
                                    style="color:black;"/>
                            Dévalider
                            <!--                        <u-icon id="waiting" name="spin" rotate="right"
                                                            style="color:white;display:none;"/>-->
                        </button>
                    </div>

@@ -52,95 +52,198 @@
        <div class="card-body">
            <div class="row">
                <div class="col-md-6">
                    <!-- fichier déposé -->
                    <label>Fichiers déposés :</label>
                    <div class="uploaded-files-div" id="uploaded-files-div-6851831280ff7"
                         data-url="/piece-jointe/intervenant/1011799/fichier/lister/1/105492" style="">
                    <p v-if="!this.datas.pieceJointe">Aucun</p>
                    <div class="uploaded-files-div" id="uploaded-files-div-6851831280ff7">
                        <ul>
                            <li class="fichier-pj">
                            <li v-for="(fichier, key) in datas.pieceJointe?.fichier" class="fichier-pj">
                                <div class="d-flex">
                                    <div>
                                        <a class="download-file"
                                   href="/piece-jointe/intervenant/1011799/fichier/telecharger/153250/CV%20.pdf"
                                   title="Télécharger le fichier déposé 'CV .pdf'">
                                    <span class="icon icon-file"></span> CV .pdf (<abbr title="706703 octets">690,1
                                    ko</abbr>)</a>
                                           :href="'/piece-jointe/intervenant/' + intervenant + '/fichier/telecharger/' + fichier.id + '/' + fichier.nom"
                                           :title="'Télécharger le fichier déposé \'' + fichier.nom + '\''">
                                            <span class="icon icon-file"></span> {{ truncate(fichier.nom, 15) }} (<abbr
                                            :title="fichier.poids">{{ fichier.poids }}</abbr>)</a>


                                        <!-- date de dépôt éventuelle du fichier -->
                                <br><span class="upload-date">le 04/09/2024 à 15:08</span>

                                        <span class="d-block small upload-date"><i>Déposé le {{
                                                fichier.date
                                            }}</i></span>

                                        <span class="d-block small" v-if="fichier.validation"><i>Validé le {{
                                                fichier.validation?.date
                                            }}</i></span>
                                    </div>
                                    <div>
                                        <!-- lien de suppression du fichier -->
                                <a id="a-68518314b2c5f" class="delete-file btn btn-sm btn-danger"
                                   href="/piece-jointe/intervenant/1011799/fichier/supprimer/105492/153250"
                                   title="Supprimer le fichier déposé 'CV .pdf'"><span
                                    class="icon iconly icon-supprimer"></span></a>
                                        <button v-if="!fichier.validation"
                                                :id="'supprimer-fichier-' + fichier.id"
                                                class="delete-file btn btn-sm btn-danger ms-2 p-1 py-0"
                                                type="button"
                                                :title="'Supprimer le fichier déposé \'' + fichier.nom + '\''"
                                                @click="actionPieceJointe($event)"
                                                :data-url="'/piece-jointe/intervenant/' + intervenant + '/fichier/supprimer/' + datas.pieceJointe.id + '/' + fichier.id">

                                            <u-icon id="action" name="trash"
                                                    style="color:black;"/>
                                        </button>
                                        <!-- lien de validation du fichier -->
                                        <button v-if="!fichier.validation"
                                                :id="'valider-fichier-' + fichier.id"
                                                class="validate-file btn btn-sm btn-success ms-2 p-1 py-0"
                                                type="button"
                                                :title="'Valider le fichier déposé \'' + fichier.nom + '\''"
                                                @click="actionPieceJointe($event)"
                                                :data-url="'/piece-jointe/intervenant/' + intervenant + '/fichier/valider/' + datas.pieceJointe.id + '/' + fichier.id">

                                            <u-icon id="action" name="thumbs-up"
                                                    style="color:black;"/>
                                        </button>
                                    </div>
                                </div>

                            </li>
                        </ul>
                    </div>
                </div>
                <div class="col-md-6">
                    <!--Form upload-->
                    <div class="row">
                        <!-- Formulaire sur 4 colonnes -->
                        <div class="col-md-8">
                            <form :id="formId" action=""
                                  enctype="multipart/form-data" method="post">
                                <div>
                                    <label class="form-label" for="importFile">Choisissez le fichier à déposer :</label>
                                    <input class="form-control form-control-sm" name="importFile" type="file"
                                           @change="handleFileUpload" multiple>
                                </div>
                            </form>
                        </div>
                        <div class="col-md-4 d-flex align-items-end">
                            <button :id="buttonId"
                                    class="btn btn-primary btn-sm w-100" disabled type="button"
                                    @click="importFile($event)"
                                    @change="handleFileUpload"
                                    :data-url="urlDeposerFichier">

                                <u-icon id="action" name="upload"/>
                                Déposer
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
<script setup>

export default {
    name: "PieceJointe.vue",
    props: {
        datas: {required: true},
        intervenant: {required: true},
    },
    data()
    {
        return {
            urlValiderPiecesJointes: unicaenVue.url('piece-jointe/intervenant/:intervenant/valider/:pieceJointe', {
                intervenant: this.intervenant,
                pieceJointe: this.datas.pieceJointe ? this.datas.pieceJointe.id : 0
            }),
            urlDevaliderPiecesJointes: unicaenVue.url('piece-jointe/intervenant/:intervenant/devalider/:pieceJointe', {
                intervenant: this.intervenant,
                pieceJointe: this.datas.pieceJointe ? this.datas.pieceJointe.id : 0
            }),
            urlRefuserPiecesJointes: unicaenVue.url('piece-jointe/intervenant/:intervenant/refuser/:pieceJointe', {
                intervenant: this.intervenant,
                pieceJointe: this.datas.pieceJointe ? this.datas.pieceJointe.id : 0
            }),


        };
    },
    methods: {

        refuserPieceJointe(event)
        {
import {ref, computed} from 'vue'

        },
        actionPieceJointe(event, ajax = false)
        {
            if (ajax) {
                modAjax(event.currentTarget, (widget) => {
                    this.$emit('refresh');
const props = defineProps(['intervenant', 'datas']);

// Emits
const emit = defineEmits(['refresh'])

// Références réactives
const selectedFiles = ref(null)

// Computed URLs
const urlValiderPiecesJointes = computed(() =>
    unicaenVue.url('piece-jointe/intervenant/:intervenant/valider/:pieceJointe', {
        intervenant: props.intervenant,
        pieceJointe: props.datas.pieceJointe ? props.datas.pieceJointe.id : 0
    })
)

const urlDevaliderPiecesJointes = computed(() =>
    unicaenVue.url('piece-jointe/intervenant/:intervenant/devalider/:pieceJointe', {
        intervenant: props.intervenant,
        pieceJointe: props.datas.pieceJointe ? props.datas.pieceJointe.id : 0
    })
)

const urlRefuserPiecesJointes = computed(() =>
    unicaenVue.url('piece-jointe/intervenant/:intervenant/refuser/:pieceJointe', {
        intervenant: props.intervenant,
        pieceJointe: props.datas.pieceJointe ? props.datas.pieceJointe.id : 0
    })
)

const urlDeposerFichier = computed(() =>
    unicaenVue.url('piece-jointe/intervenant/:intervenant/fichier/televerser/:typePieceJointe', {
        intervenant: props.intervenant,
        typePieceJointe: props.datas.typePieceJointe ? props.datas.typePieceJointe.id : 0
    })
)

// Computed pour les IDs dynamiques
const formId = computed(() => {
    const id = props.datas.typePieceJointe?.id ?? 'unknown';
    return `form-import-${id}`;
});
const buttonId = computed(() => {
    const id = props.datas.typePieceJointe?.id ?? 'unknown';
    return `btn-import-${id}`;
});
            } else {
                var url = event.currentTarget.dataset.url;

                unicaenVue.axios.get(url).then(response => {
                    this.$emit('refresh');
// Méthodes
function handleFileUpload(event)
{
    console.log(buttonId.value);
    selectedFiles.value = event.target.files
    const btn = document.getElementById(buttonId.value)
    if (btn) btn.disabled = false
}

function importFile(event)
{
    event.preventDefault()

    const btnImport = document.getElementById(buttonId.value)
    const btnImportInProgress = document.getElementById('btn-import-inprogress')

    btnImport.disabled = true
    const form = document.getElementById(formId.value)
    const formData = new FormData(form)
    const url = event.currentTarget.dataset.url
    unicaenVue.axios.post(url, formData, {
        headers: {
            'Content-Type': 'multipart/form-data'
        }
    }).then(response => {
        emit('refresh');
    }).catch(error => {
                    this.$emit('refresh');
        console.error('Error uploading');
    })
            }


}

function actionPieceJointe(event, ajax = false)
{
    if (ajax) {
        modAjax(event.currentTarget, () => {
            emit('refresh')
        })
    } else {
        const url = event.currentTarget.dataset.url
        unicaenVue.axios.get(url).then(() => emit('refresh')).catch(() => emit('refresh'))
    }
}

function truncate(str, maxLength)
{
    if (!str) return '';
    return str.length > maxLength ? str.slice(0, maxLength) + '' : str;
}

</script>


<style scoped>

</style>
 No newline at end of file
+13 −12
Original line number Diff line number Diff line
@@ -29,8 +29,6 @@ class FichierService extends AbstractEntityService
    use ValidationServiceAwareTrait;




    const STOCKAGE_BDD  = 'bdd';
    const STOCKAGE_FILE = 'file';

@@ -112,7 +110,6 @@ class FichierService extends AbstractEntityService




    public function isValide(Fichier $fichier): bool
    {
        $exts = [
@@ -280,6 +277,7 @@ class FichierService extends AbstractEntityService
    }



    /**
     * Validation d'un fichier
     *
@@ -293,10 +291,13 @@ class FichierService extends AbstractEntityService
    public function devalider(Fichier $fichier): void
    {
        $validation = $fichier->getValidation();
        $this->getServiceValidation()->delete($fichier->getValidation(), true);
        if ($validation instanceof Validation) {
            $this->getServiceValidation()->delete($validation, true);
            $fichier->setValidation(null);
            $this->getEntityManager()->persist($fichier);
            $this->getEntityManager()->flush();
        }


    }

+13 −24
Original line number Diff line number Diff line
@@ -244,21 +244,18 @@ class PieceJointeController extends \Application\Controller\AbstractController



    public function validerFichierAction()
    public function validerFichierAction(): bool
    {
        $this->initFilters();

        /** @var PieceJointe $pj */

        $pj          = $this->getEvent()->getParam('pieceJointe');
        $fichier     = $this->getEvent()->getParam('fichier');
        $intervenant = $pj->getIntervenant();
        $this->getServiceFichier()->valider($fichier, $intervenant);
        $this->updateTableauxBord($pj->getIntervenant(), true);

        $viewModel = new ViewModel();


        return $viewModel;
        return true;
    }


@@ -324,26 +321,22 @@ class PieceJointeController extends \Application\Controller\AbstractController



    public function televerserAction()
    public function televerserAction(): AxiosModel
    {
        $intervenant     = $this->getEvent()->getParam('intervenant');
        $typePieceJointe = $this->getEvent()->getParam('typePieceJointe');
        $errors          = [];

        $result = $this->uploader()->upload();

        if ($result instanceof JsonModel) {
            return $result;
        }
        if (is_array($result)) {
            $errors = $this->getServicePieceJointe()->ajouterFichiers($result['files'], $intervenant, $typePieceJointe);
            if (!empty($errors)) {
                return new JsonModel(['errors' => $errors]);
            }
        if ($this->getRequest()->isPost()) {
            $files  = $this->getRequest()->getFiles()->toArray();
            $errors = $this->getServicePieceJointe()->ajouterFichiers($files, $intervenant, $typePieceJointe);
        }

        $this->updateTableauxBord($intervenant);
        $this->updateTableauxBord($intervenant, true);


        return new AxiosModel($errors);

        return new JsonModel();
    }


@@ -371,11 +364,7 @@ class PieceJointeController extends \Application\Controller\AbstractController

    public function supprimerAction()
    {
        if (!$this->getRequest()->isPost()) {
            return $this->redirect()->toRoute('home');
        }

        /** @var PieceJointe $pj */
        $pj      = $this->getEvent()->getParam('pieceJointe');
        $fichier = $this->getEvent()->getParam('fichier');

@@ -391,7 +380,7 @@ class PieceJointeController extends \Application\Controller\AbstractController

        $this->updateTableauxBord($pj->getIntervenant());

        return new JsonModel();
        return true;
    }


Loading