mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
add the current location of the user as API point + add it in the activity location list
This commit is contained in:
parent
1e99ca2ca5
commit
82c027fe2a
@ -17,6 +17,14 @@ const getLocations = () => fetchResults('/api/1.0/main/location.json');
|
|||||||
|
|
||||||
const getLocationTypes = () => fetchResults('/api/1.0/main/location-type.json');
|
const getLocationTypes = () => fetchResults('/api/1.0/main/location-type.json');
|
||||||
|
|
||||||
|
const getUserCurrentLocation =
|
||||||
|
() => fetch('/api/1.0/main/user-current-location.json')
|
||||||
|
.then(response => {
|
||||||
|
if (response.ok) { return response.json(); }
|
||||||
|
throw Error('Error with request resource response');
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Load Location Type by defaultFor
|
* Load Location Type by defaultFor
|
||||||
* @param {string} entity - can be "person" or "thirdparty"
|
* @param {string} entity - can be "person" or "thirdparty"
|
||||||
@ -48,5 +56,6 @@ export {
|
|||||||
getLocations,
|
getLocations,
|
||||||
getLocationTypes,
|
getLocationTypes,
|
||||||
getLocationTypeByDefaultFor,
|
getLocationTypeByDefaultFor,
|
||||||
postLocation
|
postLocation,
|
||||||
|
getUserCurrentLocation
|
||||||
};
|
};
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
import { mapState, mapGetters } from "vuex";
|
import { mapState, mapGetters } 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, getLocationTypeByDefaultFor } from "../api.js";
|
import { getLocations, getLocationTypeByDefaultFor, getUserCurrentLocation } from "../api.js";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "Location",
|
name: "Location",
|
||||||
@ -60,46 +60,54 @@ export default {
|
|||||||
mounted() {
|
mounted() {
|
||||||
getLocations().then(
|
getLocations().then(
|
||||||
(results) => {
|
(results) => {
|
||||||
getLocationTypeByDefaultFor('person').then(
|
getUserCurrentLocation().then(
|
||||||
(personLocationType) => {
|
userCurrentLocation => {
|
||||||
if (personLocationType) {
|
getLocationTypeByDefaultFor('person').then(
|
||||||
const personLocation = this.makeAccompanyingPeriodLocation(personLocationType);
|
(personLocationType) => {
|
||||||
const concernedPersonsLocation =
|
if (personLocationType) {
|
||||||
this.makeConcernedPersonsLocation(personLocationType);
|
const personLocation = this.makeAccompanyingPeriodLocation(personLocationType);
|
||||||
getLocationTypeByDefaultFor('thirdparty').then(
|
const concernedPersonsLocation =
|
||||||
thirdpartyLocationType => {
|
this.makeConcernedPersonsLocation(personLocationType);
|
||||||
const concernedThirdPartiesLocation =
|
getLocationTypeByDefaultFor('thirdparty').then(
|
||||||
this.makeConcernedThirdPartiesLocation(thirdpartyLocationType);
|
thirdpartyLocationType => {
|
||||||
|
const concernedThirdPartiesLocation =
|
||||||
|
this.makeConcernedThirdPartiesLocation(thirdpartyLocationType);
|
||||||
|
this.locations = [
|
||||||
|
{
|
||||||
|
locationGroup: 'Ma localisation',
|
||||||
|
locations: [userCurrentLocation]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
locationGroup: 'Localisation du parcours',
|
||||||
|
locations: [personLocation]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
locationGroup: 'Parties concernées',
|
||||||
|
locations: [...concernedPersonsLocation, ...concernedThirdPartiesLocation]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
locationGroup: 'Autres localisations',
|
||||||
|
locations: results
|
||||||
|
}
|
||||||
|
];
|
||||||
|
}
|
||||||
|
)
|
||||||
|
} else {
|
||||||
this.locations = [
|
this.locations = [
|
||||||
{
|
{
|
||||||
locationGroup: 'Localisation du parcours',
|
locationGroup: 'Localisations',
|
||||||
locations: [personLocation]
|
locations: response.results
|
||||||
},
|
|
||||||
{
|
|
||||||
locationGroup: 'Parties concernées',
|
|
||||||
locations: [...concernedPersonsLocation, ...concernedThirdPartiesLocation]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
locationGroup: 'Autres localisations',
|
|
||||||
locations: results
|
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
)
|
if (window.default_location_id) {
|
||||||
} else {
|
let location = this.locations.filter(
|
||||||
this.locations = [
|
(l) => l.id === window.default_location_id
|
||||||
{
|
);
|
||||||
locationGroup: 'Localisations',
|
this.$store.dispatch("updateLocation", location);
|
||||||
locations: response.results
|
|
||||||
}
|
}
|
||||||
];
|
}
|
||||||
}
|
)
|
||||||
if (window.default_location_id) {
|
|
||||||
let location = this.locations.filter(
|
|
||||||
(l) => l.id === window.default_location_id
|
|
||||||
);
|
|
||||||
this.$store.dispatch("updateLocation", location);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
@ -37,4 +37,25 @@ class UserApiController extends ApiController
|
|||||||
['groups' => ['read']]
|
['groups' => ['read']]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Route(
|
||||||
|
* "/api/1.0/main/user-current-location.{_format}",
|
||||||
|
* name="chill_main_user_current_location",
|
||||||
|
* requirements={
|
||||||
|
* "_format": "json"
|
||||||
|
* }
|
||||||
|
* )
|
||||||
|
*
|
||||||
|
* @param mixed $_format
|
||||||
|
*/
|
||||||
|
public function currentLocation($_format): JsonResponse
|
||||||
|
{
|
||||||
|
return $this->json(
|
||||||
|
$this->getUser()->getCurrentLocation(),
|
||||||
|
JsonResponse::HTTP_OK,
|
||||||
|
[],
|
||||||
|
['groups' => ['read']]
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,6 +61,14 @@ final class UserApiControllerTest extends WebTestCase
|
|||||||
|
|
||||||
$client->request(Request::METHOD_GET, '/api/1.0/main/whoami.json');
|
$client->request(Request::METHOD_GET, '/api/1.0/main/whoami.json');
|
||||||
|
|
||||||
|
$this->assertResponseIsSuccessful();
|
||||||
|
}
|
||||||
|
public function testUserCurrentLocation()
|
||||||
|
{
|
||||||
|
$client = $this->getClientAuthenticated();
|
||||||
|
|
||||||
|
$client->request(Request::METHOD_GET, '/api/1.0/main/user-current-location.json');
|
||||||
|
|
||||||
$this->assertResponseIsSuccessful();
|
$this->assertResponseIsSuccessful();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -546,6 +546,14 @@ paths:
|
|||||||
responses:
|
responses:
|
||||||
200:
|
200:
|
||||||
description: "ok"
|
description: "ok"
|
||||||
|
/1.0/main/user-current-location.json:
|
||||||
|
get:
|
||||||
|
tags:
|
||||||
|
- user
|
||||||
|
summary: Return the current location of the currently authenticated user
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: "ok"
|
||||||
/1.0/main/user/{id}.json:
|
/1.0/main/user/{id}.json:
|
||||||
get:
|
get:
|
||||||
tags:
|
tags:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user