Skip to content
Snippets Groups Projects
Commit 66a65080 authored by Timothee P's avatar Timothee P :sunflower:
Browse files

Merge branch 'develop' into redmine-issues/11850

parents 5ca69c7e 37c38559
No related branches found
No related tags found
No related merge requests found
...@@ -44,7 +44,7 @@ server { ...@@ -44,7 +44,7 @@ server {
location / { location / {
root /usr/share/nginx/html; root /usr/share/nginx/html;
index index.html; index index.html;
try_files $uri$args $uri/ /index.html; try_files $uri $uri/ /index.html;
} }
......
This diff is collapsed.
...@@ -86,6 +86,8 @@ ...@@ -86,6 +86,8 @@
/> />
</div> </div>
</div> </div>
</div>
<div class="ui styled accordion">
<div <div
@click="toggleShowImport" @click="toggleShowImport"
:class="['title', { active: !showImport }]" :class="['title', { active: !showImport }]"
......
...@@ -212,6 +212,7 @@ ...@@ -212,6 +212,7 @@
</div> </div>
<div class="nouveau-type-signalement"> <div class="nouveau-type-signalement">
<a <a
v-if="permissions && permissions.can_update_project"
class=" class="
ui ui
compact compact
......
<template> <template>
<div class="fourteen wide column"> <div class="fourteen wide column">
<div
:class="{active: loading}"
class="ui inverted dimmer"
>
<div class="ui text loader">
Projet en cours de création. Vous allez être redirigé.
</div>
</div>
<form id="form-project-edit" class="ui form"> <form id="form-project-edit" class="ui form">
<h1> <h1>
<span v-if="action === 'edit'" <span v-if="action === 'edit'"
...@@ -206,6 +214,7 @@ export default { ...@@ -206,6 +214,7 @@ export default {
data() { data() {
return { return {
loading: false,
action: "create", action: "create",
levelPermissions: [ levelPermissions: [
{ name: "Utilisateur anonyme", value: "anonymous" }, { name: "Utilisateur anonyme", value: "anonymous" },
...@@ -276,17 +285,44 @@ export default { ...@@ -276,17 +285,44 @@ export default {
return filename + "." + ext; return filename + "." + ext;
}, },
validateImgFile(files, handleFile) {
let url = window.URL || window.webkitURL;
let image = new Image();
image.onload = function () {
handleFile(true);
};
image.onerror = function () {
handleFile(false);
};
image.src = url.createObjectURL(files);
URL.revokeObjectURL(image.src);
},
onFileChange(e) { onFileChange(e) {
// * read image file // * read image file
const files = e.target.files || e.dataTransfer.files; const files = e.target.files || e.dataTransfer.files;
if (!files.length) return; //* abort if no file
this.fileToImport = files[0]; //* stock the file to post later const _this = this; //* 'this' is different in onload function
let reader = new FileReader(); //* read the file to display in the page function handleFile(isValid) {
let _this = this; //* 'this' is different in onload function if (isValid) {
reader.onload = function (e) { _this.fileToImport = files[0]; //* store the file to post later
_this.thumbnailFileSrc = e.target.result; let reader = new FileReader(); //* read the file to display in the page
}; reader.onload = function (e) {
reader.readAsDataURL(this.fileToImport); _this.thumbnailFileSrc = e.target.result;
};
reader.readAsDataURL(_this.fileToImport);
_this.errorThumbnail = [];
} else {
_this.errorThumbnail.push(
"Transférez une image valide. Le fichier que vous avez transféré n'est pas une image, ou il est corrompu."
);
}
}
if (files.length) {
//* check if file is an image and pass callback to handle file
this.validateImgFile(files[0], handleFile);
}
}, },
checkEmpty() { checkEmpty() {
...@@ -310,31 +346,33 @@ export default { ...@@ -310,31 +346,33 @@ export default {
postProjectThumbnail(projectSlug) { postProjectThumbnail(projectSlug) {
//* send img to the backend when feature_type is created //* send img to the backend when feature_type is created
let formData = new FormData(); if (this.isValidImage(this.fileToImport)) {
formData.append("file", this.fileToImport); let formData = new FormData();
const url = formData.append("file", this.fileToImport);
this.$store.state.configuration.VUE_APP_DJANGO_API_BASE + const url =
"projects/" + this.$store.state.configuration.VUE_APP_DJANGO_API_BASE +
projectSlug + "projects/" +
"/thumbnail/"; projectSlug +
return axios "/thumbnail/";
.put(url, formData, { return axios
headers: { .put(url, formData, {
"Content-Type": "multipart/form-data", headers: {
}, "Content-Type": "multipart/form-data",
}) },
.then((response) => { })
if (response && response.status === 200) { .then((response) => {
this.goBackNrefresh(projectSlug); if (response && response.status === 200) {
} this.goBackNrefresh(projectSlug);
}) }
.catch((error) => { })
let err_msg = .catch((error) => {
"Transférez une image valide. Le fichier que vous avez transféré n'est pas une image, ou il est corrompu."; let err_msg =
if (error.response.data[0]) err_msg = error.response.data[0]; "Transférez une image valide. Le fichier que vous avez transféré n'est pas une image, ou il est corrompu.";
this.errorThumbnail.push(err_msg); if (error.response.data[0]) err_msg = error.response.data[0];
throw error; this.errorThumbnail.push(err_msg);
}); throw error;
});
}
}, },
checkForm() { checkForm() {
...@@ -376,6 +414,7 @@ export default { ...@@ -376,6 +414,7 @@ export default {
}; };
if (this.action === "create" || this.action === "duplicate") { if (this.action === "create" || this.action === "duplicate") {
this.loading = true;
await axios await axios
.post( .post(
`${this.$store.state.configuration.VUE_APP_DJANGO_API_BASE}projects/`, `${this.$store.state.configuration.VUE_APP_DJANGO_API_BASE}projects/`,
...@@ -390,11 +429,13 @@ export default { ...@@ -390,11 +429,13 @@ export default {
this.goBackNrefresh(response.data.slug); this.goBackNrefresh(response.data.slug);
} }
} }
this.loading = false;
}) })
.catch((error) => { .catch((error) => {
if (error.response.data.title[0]) { if (error.response.data.title[0]) {
this.errors.title.push(error.response.data.title[0]); this.errors.title.push(error.response.data.title[0]);
} }
this.loading = false;
throw error; throw error;
}); });
} else if (this.action === "edit") { } else if (this.action === "edit") {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment