Skip to content
Snippets Groups Projects
Unverified Commit 11c93122 authored by BITARD Michaël's avatar BITARD Michaël Committed by GitHub
Browse files

feat(ui): les utilisateurs peuvent glisser/déposer les documents pour les uploader (#643)

parent 0378f8e9
No related branches found
No related tags found
No related merge requests found
...@@ -8,13 +8,13 @@ ...@@ -8,13 +8,13 @@
</div> </div>
</div> </div>
<div v-else> <div v-else>
<InputFile class="btn-border small p-s full-x rnd-xs mb-s" accept="application/pdf" @change="fileChange" /> <InputFile class="btn-border small p-s full-x rnd-xs mb-s" :accept="documents" :uploadFile="fileChange" />
<p class="h5 italic">30 Mo max.</p> <p class="h5 italic">30 Mo max.</p>
</div> </div>
</template> </template>
<script> <script>
import InputFile from '../_ui/input-file.vue' import { InputFile } from '../_ui/dsfr-input-file'
import { ButtonIcon } from '@/components/_ui/button-icon' import { ButtonIcon } from '@/components/_ui/button-icon'
export default { export default {
...@@ -24,6 +24,11 @@ export default { ...@@ -24,6 +24,11 @@ export default {
contenu: { type: [Object], required: true }, contenu: { type: [Object], required: true },
elementId: { type: String, required: true }, elementId: { type: String, required: true },
}, },
data: function () {
return {
documents: ['pdf'],
}
},
computed: { computed: {
contenuElement() { contenuElement() {
...@@ -32,13 +37,8 @@ export default { ...@@ -32,13 +37,8 @@ export default {
}, },
methods: { methods: {
fileChange({ fileChange(file) {
target: { if (file) {
validity,
files: [file],
},
}) {
if (file && validity.valid) {
this.contenu[this.elementId] = file this.contenu[this.elementId] = file
} }
}, },
......
<template>
<label v-bind="$attrs">
Choisir un fichier…
<input type="file" class="p-xs mb-0" :accept="accept" @change="$emit('change', $event)" />
</label>
</template>
<script lang="ts">
import { defineComponent } from 'vue'
export default defineComponent({
props: {
accept: {
type: String,
default: '',
},
},
emits: ['change'],
})
</script>
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
</div> </div>
</div> </div>
<div v-else> <div v-else>
<InputFile class="btn-border small p-s full-x rnd-xs mb-s" @change="fileChange" /> <InputFile class="btn-border small p-s full-x rnd-xs mb-s" :accept="fichiersTypesIds" :uploadFile="fileChange" />
<p class="h5 italic">30 Mo max.</p> <p class="h5 italic">30 Mo max.</p>
</div> </div>
</div> </div>
...@@ -141,7 +141,7 @@ ...@@ -141,7 +141,7 @@
<script> <script>
import { InputDate } from '../_ui/input-date' import { InputDate } from '../_ui/input-date'
import InputFile from '../_ui/input-file.vue' import { InputFile } from '../_ui/dsfr-input-file'
import { Messages } from '../_ui/messages' import { Messages } from '../_ui/messages'
import { ButtonIcon } from '@/components/_ui/button-icon' import { ButtonIcon } from '@/components/_ui/button-icon'
import { isAdministrationAdmin, isAdministrationEditeur, isBureauDEtudes, isEntreprise, isSuper } from 'camino-common/src/roles' import { isAdministrationAdmin, isAdministrationEditeur, isBureauDEtudes, isEntreprise, isSuper } from 'camino-common/src/roles'
...@@ -209,20 +209,11 @@ export default { ...@@ -209,20 +209,11 @@ export default {
dateChanged(date) { dateChanged(date) {
this.document.date = date this.document.date = date
}, },
fileChange({ fileChange(file) {
target: { this.warnings = []
validity, this.document.fichierNouveau = file
files: [file], this.document.fichier = true
}, this.document.fichierTypeId = 'pdf'
}) {
if (file && validity.valid && file.type === 'application/pdf') {
this.warnings = []
this.document.fichierNouveau = file
this.document.fichier = true
this.document.fichierTypeId = 'pdf'
} else {
this.warnings = [{ type: 'warning', value: 'seuls les fichiers pdf sont acceptés' }]
}
}, },
fileRemove() { fileRemove() {
......
...@@ -2,9 +2,8 @@ import { caminoDefineComponent, isEventWithTarget } from '@/utils/vue-tsx-utils' ...@@ -2,9 +2,8 @@ import { caminoDefineComponent, isEventWithTarget } from '@/utils/vue-tsx-utils'
import { HelpTooltip } from '../_ui/help-tooltip' import { HelpTooltip } from '../_ui/help-tooltip'
import { dateFormat } from '@/utils' import { dateFormat } from '@/utils'
import { Tag } from '../_ui/tag' import { Tag } from '../_ui/tag'
import { Icon } from '@/components/_ui/icon'
import { computed, onMounted, ref, watch } from 'vue' import { computed, onMounted, ref, watch } from 'vue'
import { EntrepriseDocumentId, EntrepriseId, EtapeEntrepriseDocument, entrepriseDocumentIdValidator, isEntrepriseId } from 'camino-common/src/entreprise' import { EntrepriseDocumentId, EntrepriseId, entrepriseDocumentIdValidator, isEntrepriseId } from 'camino-common/src/entreprise'
import { DocumentsTypes, EntrepriseDocumentType, EntrepriseDocumentTypeId } from 'camino-common/src/static/documentsTypes' import { DocumentsTypes, EntrepriseDocumentType, EntrepriseDocumentTypeId } from 'camino-common/src/static/documentsTypes'
import { getEntries, getKeys } from 'camino-common/src/typescript-tools' import { getEntries, getKeys } from 'camino-common/src/typescript-tools'
import { AddEntrepriseDocumentPopup } from '../entreprise/add-entreprise-document-popup' import { AddEntrepriseDocumentPopup } from '../entreprise/add-entreprise-document-popup'
......
...@@ -16,8 +16,7 @@ ...@@ -16,8 +16,7 @@
</div> </div>
<div v-if="geoSystemeId"> <div v-if="geoSystemeId">
<InputFile class="btn-border small bg-alt p-s full-x rnd-xs mb-s" accept=".shp,.geojson" @change="fileChange" /> <InputFile class="btn-border small bg-alt p-s full-x rnd-xs mb-s" :accept="documents" :uploadFile="fileChange" />
<p class="h6 italic mt-0">Seul les fichiers Shape (.shp) et GeoJson (.geojson) sont acceptés.</p>
</div> </div>
<template #footer> <template #footer>
<div v-if="!loading" class="tablet-blobs"> <div v-if="!loading" class="tablet-blobs">
...@@ -31,7 +30,7 @@ ...@@ -31,7 +30,7 @@
</template> </template>
<script> <script>
import InputFile from '../_ui/input-file.vue' import { InputFile } from '../_ui/dsfr-input-file'
import Popup from '../_ui/popup.vue' import Popup from '../_ui/popup.vue'
import { sortedGeoSystemes } from 'camino-common/src/static/geoSystemes' import { sortedGeoSystemes } from 'camino-common/src/static/geoSystemes'
...@@ -44,6 +43,7 @@ export default { ...@@ -44,6 +43,7 @@ export default {
data: function () { data: function () {
return { return {
geoSystemeId: null, geoSystemeId: null,
documents: ['geojson', 'shp'],
} }
}, },
...@@ -70,11 +70,7 @@ export default { ...@@ -70,11 +70,7 @@ export default {
}, },
methods: { methods: {
async fileChange({ async fileChange(file) {
target: {
files: [file],
},
}) {
await this.$store.dispatch('titreEtapeEdition/pointsImport', { await this.$store.dispatch('titreEtapeEdition/pointsImport', {
file, file,
geoSystemeId: this.geoSystemeId, geoSystemeId: this.geoSystemeId,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment