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

add post project

parent 28603455
No related branches found
No related tags found
No related merge requests found
...@@ -47,7 +47,7 @@ export default { ...@@ -47,7 +47,7 @@ export default {
props: ["options", "selected", "disabled", "search", "placeholder"], props: ["options", "selected", "disabled", "search", "placeholder"],
computed: { computed: {
processedOptions: function () { processedOptions: function () { //* si un objet {name, value}
let options = this.options.map((el) => let options = this.options.map((el) =>
el.constructor == Object ? el.name : el el.constructor == Object ? el.name : el
); );
......
...@@ -242,7 +242,7 @@ export default { ...@@ -242,7 +242,7 @@ export default {
}; };
this.$store.commit("feature_type/UPDATE_CUSTOM_FORM", data); this.$store.commit("feature_type/UPDATE_CUSTOM_FORM", data);
}, },
updateOptions() { updateOptions() { // TODO : supprimer les espaces pour chaque option au début et à la fin QUE à la validation
this.form.options.value[0] = this.form.options.value[0].replace( this.form.options.value[0] = this.form.options.value[0].replace(
/\s*,\s*/gi, /\s*,\s*/gi,
"," ","
......
...@@ -45,6 +45,9 @@ export default new Vuex.Store({ ...@@ -45,6 +45,9 @@ export default new Vuex.Store({
SET_PROJECTS(state, projects) { SET_PROJECTS(state, projects) {
state.projects = projects; state.projects = projects;
}, },
ADD_PROJECT(state, project) {
state.projects = [project, ...state.projects];
},
SET_PROJECT_SLUG(state, slug) { SET_PROJECT_SLUG(state, slug) {
state.project_slug = slug; state.project_slug = slug;
}, },
...@@ -178,23 +181,23 @@ export default new Vuex.Store({ ...@@ -178,23 +181,23 @@ export default new Vuex.Store({
}); });
}, },
/* GET_PROJECT_FEATURES({ commit }, project_slug) { GET_PROJECT_FEATURE_TYPES({ commit }, project_slug) {
axios axios
.get(`${DJANGO_API_BASE}projects/${project_slug}/feature`) .get(`${DJANGO_API_BASE}projects/${project_slug}/feature-types`)
.then((response) => commit("feature/SET_FEATURES", response.data.features)) .then((response) => commit("feature_type/SET_FEATURE_TYPES", response.data.feature_types))
.catch((error) => { .catch((error) => {
throw error; throw error;
}); });
}, */ },
GET_PROJECT_FEATURE_TYPES({ commit }, project_slug) { /* GET_PROJECT_FEATURES({ commit }, project_slug) {
axios axios
.get(`${DJANGO_API_BASE}projects/${project_slug}/feature-types`) .get(`${DJANGO_API_BASE}projects/${project_slug}/feature`)
.then((response) => commit("feature_type/SET_FEATURE_TYPES", response.data.feature_types)) .then((response) => commit("feature/SET_FEATURES", response.data.features))
.catch((error) => { .catch((error) => {
throw error; throw error;
}); });
}, }, */
/* GET_PROJECT({ commit }, project_slug) { /* GET_PROJECT({ commit }, project_slug) {
axios axios
.get(`${DJANGO_API_BASE}projects/${project_slug}/project`) .get(`${DJANGO_API_BASE}projects/${project_slug}/project`)
......
...@@ -85,8 +85,8 @@ const feature_type = { ...@@ -85,8 +85,8 @@ const feature_type = {
return { feature_type_slug, status }; return { feature_type_slug, status };
} }
}) })
.catch((/* error */) => { .catch((error) => {
//console.error(error); throw(error);
}); });
} else if (requestType === "put") { } else if (requestType === "put") {
return axios return axios
...@@ -98,8 +98,8 @@ const feature_type = { ...@@ -98,8 +98,8 @@ const feature_type = {
return { feature_type_slug, status }; return { feature_type_slug, status };
} }
}) })
.catch((/* error */) => { .catch((error) => {
//console.error(error); throw(error);
}); });
} }
}, },
...@@ -123,13 +123,12 @@ const feature_type = { ...@@ -123,13 +123,12 @@ const feature_type = {
.then((response) => { .then((response) => {
if (response && response.status === 200) { if (response && response.status === 200) {
dispatch("GET_IMPORTS", feature_type_slug); dispatch("GET_IMPORTS", feature_type_slug);
// TODO : RELOAD DERNIER SIGNALEMENTS // TODO : reload dernier signalements
} }
return response return response
}) })
.catch((/* err */) => { .catch((error) => {
// TODO : HANDLER ERROR throw(error);
//console.log(err);
}); });
} }
}, },
......
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
<!-- // ? récupérer l'image sur serveur front (et non back) ? --> <!-- // ? récupérer l'image sur serveur front (et non back) ? -->
<img <img
:src=" :src="
project.thumbnail.includes('default') !project.thumbnail
? require('@/assets/img/default.png') ? require('@/assets/img/default.png')
: DJANGO_BASE_URL + project.thumbnail : DJANGO_BASE_URL + project.thumbnail
" "
......
...@@ -106,8 +106,8 @@ ...@@ -106,8 +106,8 @@
>Visibilité des signalements publiés</label >Visibilité des signalements publiés</label
> >
<Dropdown <Dropdown
:options="access_level_pub_feature_choices" :options="level_permissions_choices"
:selected="form.access_level_pub_feature" :selected="form.access_level_pub_feature.name"
:selection.sync="form.access_level_pub_feature" :selection.sync="form.access_level_pub_feature"
/> />
</div> </div>
...@@ -116,8 +116,8 @@ ...@@ -116,8 +116,8 @@
Visibilité des signalements archivés Visibilité des signalements archivés
</label> </label>
<Dropdown <Dropdown
:options="access_level_arch_feature_choices" :options="level_permissions_choices"
:selected="form.access_level_arch_feature" :selected="form.access_level_arch_feature.name"
:selection.sync="form.access_level_arch_feature" :selection.sync="form.access_level_arch_feature"
/> />
</div> </div>
...@@ -159,6 +159,7 @@ ...@@ -159,6 +159,7 @@
</template> </template>
<script> <script>
const axios = require("axios");
import Dropdown from "@/components/Dropdown.vue"; import Dropdown from "@/components/Dropdown.vue";
import { mapGetters } from "vuex"; import { mapGetters } from "vuex";
...@@ -172,15 +173,10 @@ export default { ...@@ -172,15 +173,10 @@ export default {
data() { data() {
return { return {
action: "create", action: "create",
access_level_pub_feature_choices: [ level_permissions_choices: [
"Utilisateur anonyme", {name: "Utilisateur anonyme", value: "anonymous"},
"Utilisateur connecté", {name: "Utilisateur connecté", value: "logged_user"},
"Contributeur", {name: "Contributeur", value: "contributor"},
],
access_level_arch_feature_choices: [
"Utilisateur anonyme",
"Utilisateur connecté",
"Contributeur",
], ],
form: { form: {
title: "", title: "",
...@@ -192,8 +188,8 @@ export default { ...@@ -192,8 +188,8 @@ export default {
thumbnail: require("@/assets/img/default.png"), // todo : utiliser l'image par défaut thumbnail: require("@/assets/img/default.png"), // todo : utiliser l'image par défaut
thumbnail_name: "", // todo: delete after getting image in jpg or png instead of data64 (require post to django) thumbnail_name: "", // todo: delete after getting image in jpg or png instead of data64 (require post to django)
creator: null, creator: null,
access_level_pub_feature: "", access_level_pub_feature: {name: "", value: ""},
access_level_arch_feature: "", access_level_arch_feature: {name: "", value: ""},
archive_feature: 0, archive_feature: 0,
delete_feature: 0, delete_feature: 0,
nb_features: 0, nb_features: 0,
...@@ -255,9 +251,36 @@ export default { ...@@ -255,9 +251,36 @@ export default {
this.$router.push(routerHistory[routerHistory.length - 1] || "/"); this.$router.push(routerHistory[routerHistory.length - 1] || "/");
}, },
postForm() { async postForm() {
/* const data = JSON.stringify(this.project); //const data = JSON.stringify(this.project);
console.log("POST this data : ", data); */ //* create project
// todo: check form
const projectData = {
title: this.form.title,
description: this.form.description,
access_level_arch_feature: this.form.access_level_arch_feature.value,
access_level_pub_feature: this.form.access_level_pub_feature.value,
archive_feature: this.form.archive_feature,
delete_feature: this.form.delete_feature,
is_project_type: this.form.is_project_type,
moderation: this.form.moderation,
};
await axios
.post(`${process.env.VUE_APP_DJANGO_API_BASE}projects/`, projectData)
.then((response) => {
console.log(response);
if (response && response.status === 201) {
this.$store.commit("ADD_PROJECT", response.data)
this.$router.push("/")
// todo : send thumbnail after
//postProjectThumbnail()
}
})
.catch((error) => {
throw error;
});
console.log("POST this data : ", projectData);
}, },
}, },
created() { created() {
......
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