mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
adding an API GET Location endpoint, fetch locations and list them in vue multiselect
This commit is contained in:
parent
342c462ed7
commit
48f3c440a2
@ -3,16 +3,29 @@ import { getSocialIssues } from 'ChillPersonAssets/vuejs/AccompanyingCourse/api.
|
|||||||
/*
|
/*
|
||||||
* Load socialActions by socialIssue (id)
|
* Load socialActions by socialIssue (id)
|
||||||
*/
|
*/
|
||||||
const getSocialActionByIssue = (id) => {
|
const getSocialActionByIssue = (id) => {
|
||||||
const url = `/api/1.0/person/social/social-action/by-social-issue/${id}.json`;
|
const url = `/api/1.0/person/social/social-action/by-social-issue/${id}.json`;
|
||||||
return fetch(url)
|
return fetch(url)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (response.ok) { return response.json(); }
|
if (response.ok) { return response.json(); }
|
||||||
throw Error('Error with request resource response');
|
throw Error('Error with request resource response');
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Load Locations
|
||||||
|
*/
|
||||||
|
const getLocations = () => {
|
||||||
|
const url = `/api/1.0/main/location.json`;
|
||||||
|
return fetch(url)
|
||||||
|
.then(response => {
|
||||||
|
if (response.ok) { return response.json(); }
|
||||||
|
throw Error('Error with request resource response');
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
export {
|
export {
|
||||||
getSocialIssues,
|
getSocialIssues,
|
||||||
getSocialActionByIssue
|
getSocialActionByIssue,
|
||||||
|
getLocations
|
||||||
};
|
};
|
||||||
|
@ -5,11 +5,19 @@
|
|||||||
Localisation
|
Localisation
|
||||||
</label>
|
</label>
|
||||||
<div class="col-sm-8">
|
<div class="col-sm-8">
|
||||||
<!--
|
|
||||||
<VueMultiselect
|
<VueMultiselect
|
||||||
name="chooseLocation"
|
name="selectLocation"
|
||||||
placeholder="Choisissez une localisation">
|
track-by="id"
|
||||||
|
:multiple="false"
|
||||||
|
:searchable="true"
|
||||||
|
placeholder="Choisissez une localisation"
|
||||||
|
label="name"
|
||||||
|
:custom-label="customLabel"
|
||||||
|
v-model="location"
|
||||||
|
:options="locations">
|
||||||
</VueMultiselect>
|
</VueMultiselect>
|
||||||
|
<!--
|
||||||
-->
|
-->
|
||||||
<new-location></new-location>
|
<new-location></new-location>
|
||||||
</div>
|
</div>
|
||||||
@ -18,9 +26,10 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import {mapState} from "vuex";
|
import { mapState } from "vuex";
|
||||||
import VueMultiselect from 'vue-multiselect';
|
import VueMultiselect from 'vue-multiselect';
|
||||||
import NewLocation from './Location/NewLocation.vue';
|
import NewLocation from './Location/NewLocation.vue';
|
||||||
|
import { getLocations } from '../api.js';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "Location",
|
name: "Location",
|
||||||
@ -28,10 +37,36 @@ export default {
|
|||||||
NewLocation,
|
NewLocation,
|
||||||
VueMultiselect
|
VueMultiselect
|
||||||
},
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
locations: []
|
||||||
|
}
|
||||||
|
},
|
||||||
computed: {
|
computed: {
|
||||||
...mapState(['activity']),
|
...mapState(['activity']),
|
||||||
|
location: {
|
||||||
|
get() {
|
||||||
|
return this.activity.location;
|
||||||
|
},
|
||||||
|
set(value) {
|
||||||
|
this.$store.commit('updateLocation', value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
mounted() {
|
||||||
|
this.getLocationsList();
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
getLocationsList() {
|
||||||
|
getLocations().then(response => new Promise(resolve => {
|
||||||
|
console.log('getLocations', response);
|
||||||
|
this.locations = response.results;
|
||||||
|
resolve();
|
||||||
|
}))
|
||||||
|
},
|
||||||
|
customLabel(value) {
|
||||||
|
return `${value.type.title.fr} ${value.name}`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
@ -114,6 +114,10 @@ const store = createStore({
|
|||||||
state.activity.users = state.activity.users.filter(user => user !== payload);
|
state.activity.users = state.activity.users.filter(user => user !== payload);
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
|
},
|
||||||
|
updateLocation(state, value) {
|
||||||
|
console.log('### mutation: updateLocation', value);
|
||||||
|
state.activity.location = value;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
|
@ -445,6 +445,27 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface,
|
|||||||
],
|
],
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'class' => \Chill\MainBundle\Entity\Location::class,
|
||||||
|
'name' => 'location',
|
||||||
|
'base_path' => '/api/1.0/main/location',
|
||||||
|
'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,
|
||||||
|
]
|
||||||
|
],
|
||||||
|
|
||||||
|
]
|
||||||
|
]
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
@ -537,3 +537,14 @@ paths:
|
|||||||
description: "ok"
|
description: "ok"
|
||||||
401:
|
401:
|
||||||
description: "Unauthorized"
|
description: "Unauthorized"
|
||||||
|
|
||||||
|
/1.0/main/location.json:
|
||||||
|
get:
|
||||||
|
tags:
|
||||||
|
- location
|
||||||
|
summary: Return a list of locations
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: "ok"
|
||||||
|
401:
|
||||||
|
description: "Unauthorized"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user