adding endpoint for LocationType. fetch types and add form fields.

This commit is contained in:
Mathieu Jaumotte 2021-10-13 19:31:48 +02:00
parent b418d13190
commit 4d4662a634
5 changed files with 98 additions and 6 deletions

View File

@ -24,8 +24,21 @@ const getLocations = () => {
});
};
/*
* Load Location Types
*/
const getLocationTypes = () => {
const url = `/api/1.0/main/location-type.json`;
return fetch(url)
.then(response => {
if (response.ok) { return response.json(); }
throw Error('Error with request resource response');
});
};
export {
getSocialIssues,
getSocialActionByIssue,
getLocations
getLocations,
getLocationTypes
};

View File

@ -8,9 +8,11 @@
<VueMultiselect
name="selectLocation"
id="selectLocation"
track-by="id"
:multiple="false"
:searchable="true"
open-direction="top"
placeholder="Choisissez une localisation"
label="name"
:custom-label="customLabel"

View File

@ -14,11 +14,9 @@
@close="modal.showModal = false">
<template v-slot:header>
<h3 class="modal-title">Ajouter une nouvelle localisation</h3>
<h3 class="modal-title">Créer une nouvelle localisation</h3>
</template>
<template v-slot:body>
* select type
* input name
<add-address
:context="addAddress.context"
@ -27,6 +25,21 @@
ref="addAddress">
</add-address>
<div class="form-floating mb-3">
<input class="form-control form-control-lg" id="name" v-model="inputName" placeholder="edit me" />
<label for="name">Nom</label>
</div>
<div class="form-floating mb-3">
<select class="form-select form-select-lg" id="type" v-model="selectType">
<option selected disabled value="">Please select one</option>
<option v-for="ltype in locationTypes" :value="ltype.id">
{{ ltype.title.fr }}
</option>
</select>
<label>Type</label>
</div>
</template>
<template v-slot:footer>
<button class="btn btn-save">Enregistrer</button>
@ -39,7 +52,8 @@
<script>
import Modal from 'ChillMainAssets/vuejs/_components/Modal.vue';
import AddAddress from "ChillMainAssets/vuejs/Address/components/AddAddress.vue";
import {mapState} from "vuex";
import { mapState } from "vuex";
import { getLocationTypes } from "../../api";
export default {
name: "NewLocation",
@ -49,6 +63,12 @@ export default {
},
data() {
return {
selected: {
type: {},
name: null,
addressId: null
},
locationTypes: [],
modal: {
showModal: false,
modalDialogClass: "modal-dialog-scrollable modal-xl"
@ -72,9 +92,34 @@ export default {
},
computed: {
...mapState(['activity']),
selectType: {
get() {
return this.selected.type;
},
set(value) {
this.selected.type = value
}
},
inputName: {
get() {
return this.selected.name;
},
set(value) {
this.selected.name = value;
}
}
},
mounted() {
this.getLocationTypesList();
},
methods: {
getLocationTypesList() {
getLocationTypes().then(response => new Promise(resolve => {
console.log('getLocationTypes', response);
this.locationTypes = response.results;
resolve();
}))
},
openModal() {
this.modal.showModal = true;
},

View File

@ -464,6 +464,27 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface,
]
],
]
],
[
'class' => \Chill\MainBundle\Entity\LocationType::class,
'name' => 'location_type',
'base_path' => '/api/1.0/main/location-type',
'base_role' => 'ROLE_USER',
'actions' => [
'_index' => [
'methods' => [
Request::METHOD_GET => true,
Request::METHOD_HEAD => true
],
],
'_entity' => [
'methods' => [
Request::METHOD_GET => true,
Request::METHOD_HEAD => true,
]
],
]
]
]

View File

@ -548,3 +548,14 @@ paths:
description: "ok"
401:
description: "Unauthorized"
/1.0/main/location-type.json:
get:
tags:
- location
summary: Return a list of location types
responses:
200:
description: "ok"
401:
description: "Unauthorized"