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

wip

parent d53ca048
No related branches found
No related tags found
No related merge requests found
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
:src=" :src="
project.thumbnail.includes('default') project.thumbnail.includes('default')
? require('@/assets/img/default.png') ? require('@/assets/img/default.png')
: DJANGO_BASE_URL + project.thumbnail : DJANGO_BASE_URL + project.thumbnail + refreshId()
" "
/> />
<div class="ui hidden divider"></div> <div class="ui hidden divider"></div>
...@@ -500,6 +500,10 @@ export default { ...@@ -500,6 +500,10 @@ export default {
}, },
methods: { methods: {
refreshId() {
return "?ver="+ Math.random()
},
toNewFeatureType() { toNewFeatureType() {
this.$router.push({ this.$router.push({
name: "ajouter-type-signalement", name: "ajouter-type-signalement",
...@@ -546,7 +550,7 @@ export default { ...@@ -546,7 +550,7 @@ export default {
document document
.getElementById("message") .getElementById("message")
.scrollIntoView({ block: "end", inline: "nearest" }); .scrollIntoView({ block: "end", inline: "nearest" });
setTimeout(() => { setTimeout(() => { //* hide message after 5 seconds
this.tempMessage = null; this.tempMessage = null;
}, 5000); }, 5000);
} }
......
...@@ -31,9 +31,12 @@ ...@@ -31,9 +31,12 @@
v-if="form.thumbnail" v-if="form.thumbnail"
class="ui small image" class="ui small image"
id="form-input-file-logo" id="form-input-file-logo"
:src="form.thumbnail" :src="
thumbnailFileSrc
? thumbnailFileSrc
: DJANGO_BASE_URL + form.thumbnail
"
/> />
<!-- @click.prevent="selectImg" -->
<label class="ui icon button" for="thumbnail" <label class="ui icon button" for="thumbnail"
><!-- // todo : send image to the backend and display it after --> ><!-- // todo : send image to the backend and display it after -->
<i class="file icon"></i> <i class="file icon"></i>
...@@ -101,7 +104,7 @@ ...@@ -101,7 +104,7 @@
>Visibilité des signalements publiés</label >Visibilité des signalements publiés</label
> >
<Dropdown <Dropdown
:options="level_permissions_choices" :options="levelPermissions"
:selected="form.access_level_pub_feature.name" :selected="form.access_level_pub_feature.name"
:selection.sync="form.access_level_pub_feature" :selection.sync="form.access_level_pub_feature"
/> />
...@@ -111,7 +114,7 @@ ...@@ -111,7 +114,7 @@
Visibilité des signalements archivés Visibilité des signalements archivés
</label> </label>
<Dropdown <Dropdown
:options="level_permissions_choices" :options="levelPermissions"
:selected="form.access_level_arch_feature.name" :selected="form.access_level_arch_feature.name"
:selection.sync="form.access_level_arch_feature" :selection.sync="form.access_level_arch_feature"
/> />
...@@ -168,7 +171,7 @@ export default { ...@@ -168,7 +171,7 @@ export default {
data() { data() {
return { return {
action: "create", action: "create",
level_permissions_choices: [ levelPermissions: [
{ name: "Utilisateur anonyme", value: "anonymous" }, { name: "Utilisateur anonyme", value: "anonymous" },
{ name: "Utilisateur connecté", value: "logged_user" }, { name: "Utilisateur connecté", value: "logged_user" },
{ name: "Contributeur", value: "contributor" }, { name: "Contributeur", value: "contributor" },
...@@ -198,11 +201,13 @@ export default { ...@@ -198,11 +201,13 @@ export default {
nb_contributors: 0, nb_contributors: 0,
is_project_type: false, is_project_type: false,
}, },
thumbnailFileSrc: null,
}; };
}, },
computed: { computed: {
...mapGetters(["project"]), ...mapGetters(["project"]),
DJANGO_BASE_URL: () => process.env.VUE_APP_DJANGO_BASE,
}, },
methods: { methods: {
...@@ -225,33 +230,39 @@ export default { ...@@ -225,33 +230,39 @@ export default {
return filename + "." + ext; return filename + "." + ext;
}, },
goBackNrefresh() {
let _this = this;
this.$router.push("/", function () { // * go back and
_this.$store.dispatch("GET_ALL_PROJECTS"); //* refresh project list
});
},
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 if (!files.length) return; //* abort if no file
this.fileToImport = files[0]; //* stock the file to post later this.fileToImport = files[0]; //* stock the file to post later
let reader = new FileReader(); //* read the file to display in the page let reader = new FileReader(); //* read the file to display in the page
let _this = this; //* this will be different in onload function let _this = this; //* 'this' is different in onload function
reader.onload = function (e) { reader.onload = function (e) {
_this.form.thumbnail = e.target.result; _this.thumbnailFileSrc = e.target.result;
}; };
reader.readAsDataURL(this.fileToImport); reader.readAsDataURL(this.fileToImport);
}, },
// todo : send file to the back goBackNrefresh(slug) {
let _this = this;
// * go back to project list
this.$router.push(
{
name: "project_detail",
params: { slug },
},
function () {
_this.$store.dispatch("GET_ALL_PROJECTS"); //* & refresh project list
}
);
},
postProjectThumbnail(projectSlug) { postProjectThumbnail(projectSlug) {
//* send img to the backend when feature_type is created //* send img to the backend when feature_type is created
if (this.fileToImport.size > 0) { if (this.fileToImport.size > 0) {
let formData = new FormData(); let formData = new FormData();
formData.append("file", this.fileToImport); formData.append("file", this.fileToImport);
let url = const url =
process.env.VUE_APP_DJANGO_API_BASE + process.env.VUE_APP_DJANGO_API_BASE +
"projects/" + "projects/" +
projectSlug + projectSlug +
...@@ -265,7 +276,7 @@ export default { ...@@ -265,7 +276,7 @@ export default {
.then((response) => { .then((response) => {
if (response && response.status === 200) { if (response && response.status === 200) {
//dispatch("GET_IMPORTS", feature_type_slug); // ? Besoin de vérifier le statut de l'import ? //dispatch("GET_IMPORTS", feature_type_slug); // ? Besoin de vérifier le statut de l'import ?
this.goBackNrefresh(); this.goBackNrefresh(projectSlug);
} }
}) })
.catch((error) => { .catch((error) => {
...@@ -275,9 +286,8 @@ export default { ...@@ -275,9 +286,8 @@ export default {
}, },
async postForm() { async postForm() {
//const data = JSON.stringify(this.project);
//* create project
// todo: check form // todo: check form
//let url = `${process.env.VUE_APP_DJANGO_API_BASE}projects/`;
const projectData = { const projectData = {
title: this.form.title, title: this.form.title,
description: this.form.description, description: this.form.description,
...@@ -289,21 +299,40 @@ export default { ...@@ -289,21 +299,40 @@ export default {
moderation: this.form.moderation, moderation: this.form.moderation,
}; };
await axios if (this.action === "create" || this.action === "duplicate") {
.post(`${process.env.VUE_APP_DJANGO_API_BASE}projects/`, projectData) await axios
.then((response) => { .post(`${process.env.VUE_APP_DJANGO_API_BASE}projects/`, projectData)
if (response && response.status === 201 && response.data) { .then((response) => {
this.$store.commit("ADD_PROJECT", response.data); if (response && response.status === 201 && response.data) {
//* send thumbnail after feature_type was created //* send thumbnail after feature_type was created
if (this.fileToImport) if (this.fileToImport)
this.postProjectThumbnail(response.data.slug); this.postProjectThumbnail(response.data.slug);
} else { } else {
this.goBackNrefresh(); this.goBackNrefresh(response.data.slug);
} }
}) })
.catch((error) => { .catch((error) => {
throw error; throw error;
}); });
} else if (this.action === "edit") {
await axios
.put(
`${process.env.VUE_APP_DJANGO_API_BASE}projects/${this.project.slug}/`,
projectData
)
.then((response) => {
if (response && response.status === 200) {
//* send thumbnail after feature_type was created
if (this.fileToImport)
this.postProjectThumbnail(this.project.slug);
} else {
this.goBackNrefresh(this.project.slug);
}
})
.catch((error) => {
throw error;
});
}
}, },
}, },
...@@ -312,10 +341,23 @@ export default { ...@@ -312,10 +341,23 @@ export default {
if (this.action !== "create") { if (this.action !== "create") {
if (!this.project) { if (!this.project) {
this.$store.dispatch("GET_PROJECT_INFO", this.$route.params.slug); this.$store.dispatch("GET_PROJECT_INFO", this.$route.params.slug);
this.form = this.project;
} else {
this.form = this.project;
} }
this.form = this.project;
/* this.form.thumbnail = //* add api base to display image src
process.env.VUE_APP_DJANGO_BASE + this.form.thumbnail; */
//* transform string values to objects for dropdowns display (could be in a computed)
this.form.access_level_pub_feature = {
name: this.project.access_level_pub_feature,
value: this.levelPermissions.find(
(el) => (el.name = this.project.access_level_pub_feature)
).value,
};
this.form.access_level_arch_feature = {
name: this.project.access_level_arch_feature,
value: this.levelPermissions.find(
(el) => (el.name = this.project.access_level_arch_feature)
).value,
};
} }
}, },
}; };
......
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