Merge branch 'nominatim_fix'
continuous-integration/drone/push Build is passing Details

timeline
Alix JEUDI--LEMOINE 2 weeks ago
commit dc0d9b0f14

@ -57,6 +57,8 @@ export class AddPinPopupComponent implements OnInit {
title: new FormControl(''), title: new FormControl(''),
description: new FormControl(''), description: new FormControl(''),
location: new FormControl(''), location: new FormControl(''),
complete_address: new FormControl(''),
coordinates: new FormControl<number[]>([]),
files: new FormControl(null), files: new FormControl(null),
date: new FormControl(''), date: new FormControl(''),
}); });
@ -120,6 +122,8 @@ export class AddPinPopupComponent implements OnInit {
const locationControl = this.form.get('location'); const locationControl = this.form.get('location');
if (locationControl instanceof FormControl) { if (locationControl instanceof FormControl) {
locationControl.setValue(suggestion.display_name); locationControl.setValue(suggestion.display_name);
this.form.get('complete_address')?.setValue(suggestion.display_name);
this.form.get('coordinates')?.setValue([suggestion.lat, suggestion.lon]);
} }
this.suggestions = []; this.suggestions = [];
} }
@ -142,6 +146,8 @@ export class AddPinPopupComponent implements OnInit {
.toPromise(); .toPromise();
if (address) { if (address) {
this.form.get('location')?.setValue(address.display_name); this.form.get('location')?.setValue(address.display_name);
this.form.get('complete_address')?.setValue(address.display_name);
this.form.get('coordinates')?.setValue([data.latitude, data.longitude]);
break; break;
} }
} }
@ -169,15 +175,23 @@ export class AddPinPopupComponent implements OnInit {
); );
forkJoin(uploadObservables).subscribe((responses) => { forkJoin(uploadObservables).subscribe((responses) => {
// responses est un tableau de réponses API this.files = responses.map((res: any) => res.id);
this.files = responses.map((res: any) => res.id); // ou res.json().id si nécessaire
const coordinates = this.form.get('coordinates')?.value;
const pinData = { const pinData = {
...this.form.value, ...this.form.value,
files: this.files, files: this.files,
date: this.form.get('date')?.value || null, date: this.form.get('date')?.value || null,
location: coordinates || [0, 0], // Utiliser les coordonnées pour location
complete_address: this.form.get('complete_address')?.value || this.form.get('location')?.value,
}; };
// Supprimer le champ coordinates qui n'est pas dans le modèle Pin
delete pinData.coordinates;
console.log('Files : ' + JSON.stringify(this.files));
console.log('Pin Data : ' + JSON.stringify(pinData));
this.pinService.addPin(pinData)?.subscribe(() => { this.pinService.addPin(pinData)?.subscribe(() => {
this.mapReloadService.requestReload(); // Demander le rechargement de la carte this.mapReloadService.requestReload(); // Demander le rechargement de la carte
this.closePinModal(); this.closePinModal();

@ -67,6 +67,8 @@ export class EditPinPopupComponent implements OnInit, AfterViewInit, OnDestroy {
title: new FormControl(''), title: new FormControl(''),
description: new FormControl(''), description: new FormControl(''),
location: new FormControl(''), location: new FormControl(''),
complete_address: new FormControl(''),
coordinates: new FormControl<number[]>([]),
files: new FormControl(null), files: new FormControl(null),
date: new FormControl(''), date: new FormControl(''),
}); });
@ -87,7 +89,9 @@ export class EditPinPopupComponent implements OnInit, AfterViewInit, OnDestroy {
this.form.patchValue({ this.form.patchValue({
title: this.pin?.title || '', title: this.pin?.title || '',
description: this.pin?.description || '', description: this.pin?.description || '',
location: "Chargement de l'adresse...", location: this.pin?.complete_address || '',
complete_address: this.pin?.complete_address || '',
coordinates: this.pin?.location || [],
files: this.pin?.files || [], files: this.pin?.files || [],
date: this.pin?.date date: this.pin?.date
? new Date(this.pin.date).toISOString().split('T')[0] ? new Date(this.pin.date).toISOString().split('T')[0]
@ -97,39 +101,6 @@ export class EditPinPopupComponent implements OnInit, AfterViewInit, OnDestroy {
// Initialiser les fichiers existants // Initialiser les fichiers existants
this.files = this.pin?.files || []; this.files = this.pin?.files || [];
// Vérifier si nous avons des coordonnées valides dans pin.location
if (
this.pin?.location &&
Array.isArray(this.pin.location) &&
this.pin.location.length >= 2
) {
const lat = this.pin.location[0];
const lon = this.pin.location[1];
if (lat !== undefined && lon !== undefined) {
// Récupérer l'adresse à partir des coordonnées
this.locationSubscription = this.autocompleteService
.getAddressFromCoordinates(lat, lon)
.pipe(take(1))
.subscribe(
(address) => {
if (address && address.display_name) {
this.form.patchValue({ location: address.display_name });
} else {
this.form.patchValue({ location: `${lat}, ${lon}` });
}
},
(error) => {
console.error(
"Erreur lors de la récupération de l'adresse:",
error
);
this.form.patchValue({ location: `${lat}, ${lon}` });
}
);
}
}
// S'abonner aux changements d'état du modal // S'abonner aux changements d'état du modal
this.modalOpenSubscription = this.modalService this.modalOpenSubscription = this.modalService
.getModalState(this.modalId) .getModalState(this.modalId)
@ -212,6 +183,8 @@ export class EditPinPopupComponent implements OnInit, AfterViewInit, OnDestroy {
const locationControl = this.form.get('location'); const locationControl = this.form.get('location');
if (locationControl instanceof FormControl) { if (locationControl instanceof FormControl) {
locationControl.setValue(suggestion.display_name); locationControl.setValue(suggestion.display_name);
this.form.get('complete_address')?.setValue(suggestion.display_name);
this.form.get('coordinates')?.setValue([suggestion.lat, suggestion.lon]);
} }
this.suggestions = []; this.suggestions = [];
} }
@ -232,16 +205,16 @@ export class EditPinPopupComponent implements OnInit, AfterViewInit, OnDestroy {
if (address) { if (address) {
this.form.get('location')?.setValue(address.display_name); this.form.get('location')?.setValue(address.display_name);
this.form.get('complete_address')?.setValue(address.display_name);
this.form.get('coordinates')?.setValue([data.latitude, data.longitude]);
break; break;
} }
} catch (addressError) { } catch (addressError) {
console.error( console.error("Erreur lors de la récupération de l'adresse:", addressError);
"Erreur lors de la récupération de l'adresse:", // Utiliser les coordonnées brutes en cas d'échec
addressError this.form.get('location')?.setValue(`${data.latitude}, ${data.longitude}`);
); this.form.get('complete_address')?.setValue(`${data.latitude}, ${data.longitude}`);
this.form this.form.get('coordinates')?.setValue([data.latitude, data.longitude]);
.get('location')
?.setValue(`${data.latitude}, ${data.longitude}`);
} }
} }
} catch (error) { } catch (error) {
@ -252,6 +225,17 @@ export class EditPinPopupComponent implements OnInit, AfterViewInit, OnDestroy {
submitForm(): void { submitForm(): void {
if (this.form.valid) { if (this.form.valid) {
const coordinates = this.form.get('coordinates')?.value;
const pinData = {
...this.form.value,
files: this.files,
date: this.form.get('date')?.value || null,
location: coordinates || this.pin.location, // Utiliser les coordonnées pour location
complete_address: this.form.get('complete_address')?.value || this.form.get('location')?.value,
};
// Supprimer le champ coordinates qui n'est pas dans le modèle Pin
delete pinData.coordinates;
// Filtrer les fichiers qui sont déjà des IDs (images existantes) // Filtrer les fichiers qui sont déjà des IDs (images existantes)
const existingFiles = this.files.filter( const existingFiles = this.files.filter(
(file) => typeof file === 'string' (file) => typeof file === 'string'
@ -282,6 +266,8 @@ export class EditPinPopupComponent implements OnInit, AfterViewInit, OnDestroy {
files: allFileIds, files: allFileIds,
user_id: this.pin.user_id, user_id: this.pin.user_id,
date: formattedDate, date: formattedDate,
location: coordinates || this.pin.location, // Utiliser les coordonnées pour location
complete_address: this.form.get('complete_address')?.value || this.form.get('location')?.value,
}; };
this.pinService.updatePin(this.pin.id, pinData).subscribe(() => { this.pinService.updatePin(this.pin.id, pinData).subscribe(() => {
@ -296,6 +282,8 @@ export class EditPinPopupComponent implements OnInit, AfterViewInit, OnDestroy {
files: existingFiles, files: existingFiles,
user_id: this.pin.user_id, user_id: this.pin.user_id,
date: formattedDate, date: formattedDate,
location: coordinates || this.pin.location, // Utiliser les coordonnées pour location
complete_address: this.form.get('complete_address')?.value || this.form.get('location')?.value,
}; };
this.pinService.updatePin(this.pin.id, pinData).subscribe(() => { this.pinService.updatePin(this.pin.id, pinData).subscribe(() => {
@ -303,9 +291,6 @@ export class EditPinPopupComponent implements OnInit, AfterViewInit, OnDestroy {
this.closePinModal(); this.closePinModal();
}); });
} }
} else {
console.error('Le formulaire est invalide');
}
} }
openPinModal() { openPinModal() {

@ -91,28 +91,13 @@ export class LeafletMapComponent implements OnInit {
private loadCountriesForFiltrers(pins: Pin[]): void { private loadCountriesForFiltrers(pins: Pin[]): void {
const countrySet = new Set<string>(); const countrySet = new Set<string>();
const requests = pins.map((pin) => const requests = pins.map((pin: Pin) => {
this.autocompleteService const country = this.extractLastFromDisplayName(pin.complete_address);
.getAddressFromCoordinates(pin.location[0], pin.location[1])
.toPromise()
.then((res: any) => {
const address = res?.address;
const country =
address?.country ||
this.extractLastFromDisplayName(res?.display_name);
if (country) { if (country) {
this.pinCountries[pin.id] = country; this.pinCountries[pin.id] = country;
countrySet.add(country); countrySet.add(country);
} }
}) });
.catch((err: any) => {
console.error(
'Erreur lors de la récupération du pays pour le pin',
pin.id,
err
);
})
);
Promise.all(requests).then(() => { Promise.all(requests).then(() => {
this.availableCountries = Array.from(countrySet).sort(); this.availableCountries = Array.from(countrySet).sort();

@ -1,6 +1,7 @@
export interface Pin { export interface Pin {
id: string; id: string;
location: number[]; location: number[];
complete_address: string;
title: string; title: string;
files: string[]; files: string[];
description: string; description: string;

@ -29,47 +29,20 @@ export class PinService {
return this.http.get<any>(url, { headers }); return this.http.get<any>(url, { headers });
} }
addPin(pin: { addPin(pin: Pin) {
title: string;
description: string;
location: string;
files: string[];
date: string;
}) {
const url = `${this.apiURL}/pin/add`; const url = `${this.apiURL}/pin/add`;
const headers = new HttpHeaders({ const headers = new HttpHeaders({
'Content-Type': 'application/json', 'Content-Type': 'application/json',
Authorization: 'Bearer ' + localStorage.getItem('auth_token'), Authorization: 'Bearer ' + localStorage.getItem('auth_token'),
}); });
return this.autoCompleteService.getAdressCoordinates(pin.location).pipe(
switchMap((response: any) => {
const coords: [string, string] = [response[0].lat, response[0].lon];
return this.http.post<any>( return this.http.post<any>(
url, url, pin, { headers }
{
title: pin.title,
description: pin.description,
location: coords,
files: pin.files,
user_id: '',
date: pin.date,
},
{ headers }
);
})
); );
} }
updatePin( updatePin(
id: string, id: string,
pin: { pin: Pin
title: string;
description: string;
location: string;
files: any[];
user_id: string;
date: string;
}
) { ) {
const url = `${this.apiURL}/pin/${id}`; const url = `${this.apiURL}/pin/${id}`;
const headers = new HttpHeaders({ const headers = new HttpHeaders({
@ -78,22 +51,8 @@ export class PinService {
}); });
// Obtenir les coordonnées GPS à partir de l'adresse // Obtenir les coordonnées GPS à partir de l'adresse
return this.autoCompleteService.getAdressCoordinates(pin.location).pipe(
switchMap((response: any) => {
const coords: [string, string] = [response[0].lat, response[0].lon];
return this.http.patch<any>( return this.http.patch<any>(
url, url, pin, { headers }
{
title: pin.title,
description: pin.description,
location: coords,
files: pin.files,
user_id: pin.user_id,
date: pin.date,
},
{ headers }
);
})
); );
} }

Loading…
Cancel
Save