Skip to content

Commit

Permalink
finition upload / download
Browse files Browse the repository at this point in the history
creation typeTraitement
  • Loading branch information
SamuelQuetin committed Jul 1, 2024
1 parent bd58481 commit 956fc72
Show file tree
Hide file tree
Showing 9 changed files with 215 additions and 41 deletions.
18 changes: 0 additions & 18 deletions src/components/DownloadFile.vue

This file was deleted.

21 changes: 11 additions & 10 deletions src/components/TypeExemp.vue → src/components/Exemp/TypeExemp.vue
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
<template>
<v-card elevation="1" :loading="isLoading">
<v-card flat :loading="isLoading">
<v-card-title style="background-color: #295494; color: white" class="d-flex justify-space-between">
<span>Choix du type d'exemplarisation</span>
<v-btn depressed variant="text" @click="deleted()" prepend-icon="mdi-delete">Supprimer</v-btn>
</v-card-title>
<v-card-text class="pa-0 ma-0">
<div class="btn-perso elevation-1 pa-8 d-flex justify-space-between" @click="onClick(exemp)"
v-for="exemp in listExemp" :key="exemp.numTypeExemp">
<v-row class="align-center">
<v-col cols="12" sm="3" class="d-flex justify-center">
<v-icon size="x-large" dark color="primary">{{ getIcon(exemp) }}</v-icon>
</v-col>
<v-col cols="12" sm="9" class="d-flex justify-start"><span class="group">{{ exemp.libelle }}</span></v-col>
</v-row>
</div>
<v-hover v-slot="{ isHovering, props }" v-for="exemp in listExemp" :key="exemp.numTypeExemp">
<div v-bind="props" :class="`btn-perso elevation-${isHovering ? 6 : 2} pa-5 ma-1 d-flex justify-space-between`" @click="onClick(exemp)">
<v-row class="align-center">
<v-col cols="12" sm="3" class="d-flex justify-center">
<v-icon size="x-large" dark color="primary">{{ getIcon(exemp) }}</v-icon>
</v-col>
<v-col cols="12" sm="9" class="d-flex justify-start"><span class="group">{{ exemp.libelle }}</span></v-col>
</v-row>
</div>
</v-hover>
</v-card-text>
</v-card>
</template>
Expand Down
56 changes: 56 additions & 0 deletions src/components/Modif/DownloadFile.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<template>
<v-card elevation="0">
<v-card-title style="background-color: #295494; color: white" class="d-flex justify-space-between">
<span><slot></slot></span>
<v-btn depressed variant="text" @click="deleted()" prepend-icon="mdi-delete">Supprimer</v-btn>
</v-card-title>
<v-card-actions class="py-6">
<v-spacer></v-spacer>
<v-btn
rounded
x-large
variant="flat"
color="#295494"
ref="fileLinkBtn"
:href="fileLink"
:disabled="isDisabled"
@click="clicked()"
append-icon="mdi-cloud-download"
:download="fileName">Télécharger le fichier de correspondances PPN/EPN
</v-btn>
<v-spacer></v-spacer>
</v-card-actions>
</v-card>
</template>
<script setup>
const emits = defineEmits(['deleted','clicked']);
const props = defineProps({
fileName: {
required: true,
type: String
},
fileLink: {
required: true,
type: String
},
isDisabled: {
type: Boolean,
default: false
}
})
function clicked(){
emits('clicked');
}
function deleted() {
emits('deleted');
}
</script>
<style scoped>
v-btn{
color: red !important;
}
</style>
63 changes: 63 additions & 0 deletions src/components/Modif/TypeTraitement.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<template>
<v-card flat :loading="isLoading">
<v-card-title style="background-color: #295494; color: white" class="d-flex justify-space-between">
<span>Choix du type de traitement</span>
<v-btn depressed variant="text" @click="deleted()" prepend-icon="mdi-delete">Supprimer</v-btn>
</v-card-title>

<v-card-text class="pa-0 ma-0">
<v-hover v-slot="{ isHovering, props }" v-for="traitement in listTraitement" :key="traitement.id">
<div v-bind="props" :class="`btn-perso elevation-${isHovering ? 6 : 2} pa-5 ma-1 d-flex justify-space-between`" @click="onClick(traitement)">
<v-row class="align-center">
<v-col cols="12" sm="3" class="d-flex justify-center">
<v-icon size="xx-large" dark color="primary">{{ getIcon(traitement) }}</v-icon>
</v-col>
<v-col cols="12" sm="9" class="d-flex justify-start"><p class="group" >{{ traitement.libelle }}</p></v-col>
</v-row>
</div>
</v-hover>
</v-card-text>
</v-card>
</template>

<script setup>
import { onMounted, ref } from 'vue';
import DemandesService from '@/service/DemandesService';
const typeTraitement = defineModel();
const emits = defineEmits(['clicked', 'deleted']);
const props = defineProps({ isLoading: { type: Boolean } });
const listTraitement = ref([]);
onMounted(() => {
DemandesService.getTypeTraitement()
.then(response => {
listTraitement.value = response.data;
});
});
function getIcon(traitement) {
if (traitement.id === 1) return 'mdi-plus';
if (traitement.id === 2) return 'mdi-pencil';
if (traitement.id === 3) return 'mdi-redo';
if (traitement.id === 4) return 'mdi-close';
if (traitement.id === 5) return 'mdi-delete';
return 'mdi-nuke';
}
function onClick(traitement) {
typeTraitement.value = traitement;
emits('clicked');
}
function deleted() {
emits('deleted');
}
</script>

<style scoped>
.group {
font-size: x-large;
}
</style>
File renamed without changes.
12 changes: 12 additions & 0 deletions src/service/DemandesService.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ export class DemandesService {
return this.client.patch(`demandes/EXEMP/${id}?typeExemp=${typeExemp}`);
}

modifierTypeTraitementModifDemande(id, typeTraitement){
return this.client.patch(`demandes/MODIF/${id}?traitement=${typeTraitement}`);
}

uploadDemande(id, file, typeDemande){
const config = { headers: {
'Content-Type': 'multipart/form-data',
Expand Down Expand Up @@ -180,6 +184,14 @@ export class DemandesService {
deleteDemande(id, typeDemande) {
return this.client.delete(`demandes/${typeDemande}/${id}`);
}

getFilePreparer(id, typeDemande){
return this.client.get(`/files/${typeDemande}/${id}/fichier_prepare_${id}.csv`);
}

getTypeTraitement(){
return this.client.get('traitements');
}
}

export default new DemandesService()
6 changes: 3 additions & 3 deletions src/views/Exemplarisation/ExempSteps.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
</v-container>
</v-stepper-window-item>
<v-stepper-window-item>
<upload-file v-model="fileSelected" :is-loading="isLoading" @deleted="deleteDemande()">Charger le fichier des exemplaires à traiter</upload-file>
<select-file v-model="fileSelected" :is-loading="isLoading" @deleted="deleteDemande()">Charger le fichier des exemplaires à traiter</select-file>
<v-alert
v-if="alertMessage"
:type="alertType"
Expand Down Expand Up @@ -105,9 +105,9 @@
import { onMounted, ref } from 'vue';
import DemandesService from '@/service/DemandesService';
import router from '@/router';
import UploadFile from '@/components/UploadFile.vue';
import SelectFile from '@/components/SelectFile.vue';
import Rcr from '@/components/Rcr.vue';
import TypeExemp from '@/components/TypeExemp.vue';
import TypeExemp from '@/components/Exemp/TypeExemp.vue';
import Simulation from "@/components/Simulation.vue";
import DialogLancerTraitement from '@/components/DialogLancerTraitement.vue';
Expand Down
76 changes: 68 additions & 8 deletions src/views/Modification/ModifSteps.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<v-container :class="(currentStep === 3) ? '' : 'fill-height'" fluid>
<v-row align="center" justify="center">
<v-col :md="(currentStep === 3) ? '' : '7'">
<v-stepper v-model="currentStep" alt-labels>
<v-stepper v-model="currentStep" @update:model-value="changeEtape()" alt-labels>
<v-stepper-header>
<v-stepper-item
:color="currentStep >= 0 ? '#295494' : ''"
Expand Down Expand Up @@ -30,7 +30,7 @@
:editable="currentStep > 2"
icon="mdi-numeric-3"
title="Choix traitement"
subtitle="à effectuer"
:subtitle="typeTraitementSelected ? typeTraitementSelected.libelle : 'à effectuer'"
>
</v-stepper-item>
<v-divider></v-divider>
Expand Down Expand Up @@ -65,11 +65,12 @@
</v-container>
</v-stepper-window-item>
<v-stepper-window-item>
<upload-file v-if="!isLoaded" v-model="fileSelected" :is-loading="isLoading" @deleted="deleteDemande()">test</upload-file>
<!-- <download-file v-else v-model="fileSelected"></download-file>-->
<select-file v-if="!isLoaded" v-model="fileSelected" :is-loading="isLoading" @deleted="deleteDemande()"></select-file>
<download-file v-else :file-link="fileLink" :file-name="fileName" @clicked="downloaded">Récupération du fichier de correspondances PPN / EPN</download-file>
<v-alert
v-if="alertMessage"
:type="alertType"

>
<span v-html="alertMessage"></span>
</v-alert>
Expand All @@ -80,13 +81,26 @@
<v-btn
:disabled="!fileSelected"
@click="uploadFile()"
v-if="!isLoaded"
>
Envoyé
</v-btn>
<v-btn
v-else
:disabled="!isDownloaded"
@click="razBeforeNext()"
>
Lancer le traitement en simulation
Suivant
</v-btn>
</v-container>
</v-stepper-window-item>
<v-stepper-window-item>

<type-traitement v-model="typeTraitementSelected" :is-loading="isLoading" @clicked="modifierTypeTraitementModifDemande()"></type-traitement>
<v-container class="d-flex justify-space-between">
<v-btn @click="prev">
précédent
</v-btn>
</v-container>
</v-stepper-window-item>
<v-stepper-window-item>

Expand All @@ -106,8 +120,10 @@ import { ref } from 'vue';
import router from '@/router';
import demandesService from '@/service/DemandesService';
import Rcr from '@/components/Rcr.vue';
import UploadFile from '@/components/UploadFile.vue';
import DownloadFile from '@/components/DownloadFile.vue';
import SelectFile from '@/components/SelectFile.vue';
import DownloadFile from '@/components/Modif/DownloadFile.vue';
import TypeTraitement from '@/components/Modif/TypeTraitement.vue';
const currentStep = ref(0);
const demande = ref();
Expand All @@ -117,6 +133,11 @@ const alertMessage = ref();
const alertType = ref();
const isLoaded = ref(false);
const isLoading = ref(false);
const isDownloaded = ref(false);
const fileLink = ref('');
const fileName = ref('');
const typeTraitementSelected = ref();
const emits = defineEmits(['backendError'])
function createDemande() {
Expand Down Expand Up @@ -155,6 +176,12 @@ function uploadFile() {
.then(() => {
alertMessage.value = "Fichier envoyé";
isLoaded.value = true;
demandesService.getFilePreparer(demande.value.id, 'MODIF')
.then(response => {
let blob = new Blob([response.data], { type: 'application/csv' });
fileLink.value = window.URL.createObjectURL(blob);
fileName.value = `fichier_demande_${demande.value.id}.csv`;
})
})
.catch(err => {
alertMessage.value = err.response.data.message;
Expand All @@ -164,6 +191,22 @@ function uploadFile() {
isLoading.value = false;
});
}
function modifierTypeTraitementModifDemande(){
isLoading.value = true;
demandesService.modifierTypeTraitementModifDemande(demande.value.id, typeTraitementSelected.value.id)
.then(response => {
demande.value = response.data;
next()
}).catch(err => {
emits('backendError', err);
}).finally(() => {
isLoading.value = false;
});
}
function downloaded(){
isDownloaded.value = true;
}
function deleteDemande(){
demandesService.deleteDemande(demande.value.id, 'MODIF')
.then(()=>{
Expand All @@ -172,11 +215,28 @@ function deleteDemande(){
emits('backendError', err);
})
}
function razBeforeNext(){
isLoaded.value = false;
isLoading.value = false;
isDownloaded.value = false;
next();
}
function next(){
currentStep.value++;
}
function prev(){
currentStep.value--;
changeEtape();
}
function changeEtape() {
if((currentStep.value + 1) <= 2) { //Changement d'etat pour le chargement du fichier car le back est perdu sinon
demandesService.choixEtape(demande.value.id, 2, 'MODIF')
.then(response => {
demande.value = response.data;
});
}
}
</script>
4 changes: 2 additions & 2 deletions src/views/Recouvrement/RecouvSteps.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
</v-container>
</v-stepper-window-item>
<v-stepper-window-item>
<upload-file v-model="fileSelected" :is-loading="isLoading" @deleted="deleteDemande()">Charger le fichier du taux de recouvrement</upload-file>
<select-file v-model="fileSelected" :is-loading="isLoading" @deleted="deleteDemande()">Charger le fichier du taux de recouvrement</select-file>
<v-alert
v-if="alertMessage"
:type="alertType"
Expand Down Expand Up @@ -86,7 +86,7 @@

<script setup>
import Rcr from '@/components/Rcr.vue';
import UploadFile from '@/components/UploadFile.vue';
import SelectFile from '@/components/SelectFile.vue';
import { onMounted, ref } from 'vue';
import DemandesService from '@/service/DemandesService';
import router from '@/router';
Expand Down

0 comments on commit 956fc72

Please sign in to comment.