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(''),
description: new FormControl(''),
location: new FormControl(''),
complete_address: new FormControl(''),
coordinates: new FormControl<number[]>([]),
files: new FormControl(null),
date: new FormControl(''),
});
@ -120,6 +122,8 @@ export class AddPinPopupComponent implements OnInit {
const locationControl = this.form.get('location');
if (locationControl instanceof FormControl) {
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 = [];
}
@ -142,6 +146,8 @@ export class AddPinPopupComponent implements OnInit {
.toPromise();
if (address) {
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;
}
}
@ -169,15 +175,23 @@ export class AddPinPopupComponent implements OnInit {
);
forkJoin(uploadObservables).subscribe((responses) => {
// responses est un tableau de réponses API
this.files = responses.map((res: any) => res.id); // ou res.json().id si nécessaire
this.files = responses.map((res: any) => res.id);
const coordinates = this.form.get('coordinates')?.value;
const pinData = {
...this.form.value,
files: this.files,
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.mapReloadService.requestReload(); // Demander le rechargement de la carte
this.closePinModal();

@ -67,6 +67,8 @@ export class EditPinPopupComponent implements OnInit, AfterViewInit, OnDestroy {
title: new FormControl(''),
description: new FormControl(''),
location: new FormControl(''),
complete_address: new FormControl(''),
coordinates: new FormControl<number[]>([]),
files: new FormControl(null),
date: new FormControl(''),
});
@ -87,7 +89,9 @@ export class EditPinPopupComponent implements OnInit, AfterViewInit, OnDestroy {
this.form.patchValue({
title: this.pin?.title || '',
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 || [],
date: this.pin?.date
? new Date(this.pin.date).toISOString().split('T')[0]
@ -97,39 +101,6 @@ export class EditPinPopupComponent implements OnInit, AfterViewInit, OnDestroy {
// Initialiser les fichiers existants
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
this.modalOpenSubscription = this.modalService
.getModalState(this.modalId)
@ -155,7 +126,7 @@ export class EditPinPopupComponent implements OnInit, AfterViewInit, OnDestroy {
debounceTime(300), // Attendre 300ms après la dernière frappe
distinctUntilChanged(), // Ignorer si la nouvelle valeur est la même que la précédente
switchMap((query) => {
// Vérifier que query est une chaîne de caractères
// Vérifier que query est une chaîne de caractères
if (typeof query !== 'string') {
return of([]);
}
@ -212,6 +183,8 @@ export class EditPinPopupComponent implements OnInit, AfterViewInit, OnDestroy {
const locationControl = this.form.get('location');
if (locationControl instanceof FormControl) {
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 = [];
}
@ -232,16 +205,16 @@ export class EditPinPopupComponent implements OnInit, AfterViewInit, OnDestroy {
if (address) {
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;
}
} catch (addressError) {
console.error(
"Erreur lors de la récupération de l'adresse:",
addressError
);
this.form
.get('location')
?.setValue(`${data.latitude}, ${data.longitude}`);
console.error("Erreur lors de la récupération de l'adresse:", addressError);
// Utiliser les coordonnées brutes en cas d'échec
this.form.get('location')?.setValue(`${data.latitude}, ${data.longitude}`);
this.form.get('complete_address')?.setValue(`${data.latitude}, ${data.longitude}`);
this.form.get('coordinates')?.setValue([data.latitude, data.longitude]);
}
}
} catch (error) {
@ -252,6 +225,17 @@ export class EditPinPopupComponent implements OnInit, AfterViewInit, OnDestroy {
submitForm(): void {
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)
const existingFiles = this.files.filter(
(file) => typeof file === 'string'
@ -282,6 +266,8 @@ export class EditPinPopupComponent implements OnInit, AfterViewInit, OnDestroy {
files: allFileIds,
user_id: this.pin.user_id,
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(() => {
@ -296,15 +282,14 @@ export class EditPinPopupComponent implements OnInit, AfterViewInit, OnDestroy {
files: existingFiles,
user_id: this.pin.user_id,
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.mapReloadService.requestReload();
this.closePinModal();
});
}
} else {
console.error('Le formulaire est invalide');
this.pinService.updatePin(this.pin.id, pinData).subscribe(() => {
this.mapReloadService.requestReload();
this.closePinModal();
});
}
}

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

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

@ -29,47 +29,20 @@ export class PinService {
return this.http.get<any>(url, { headers });
}
addPin(pin: {
title: string;
description: string;
location: string;
files: string[];
date: string;
}) {
addPin(pin: Pin) {
const url = `${this.apiURL}/pin/add`;
const headers = new HttpHeaders({
'Content-Type': 'application/json',
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>(
url,
{
title: pin.title,
description: pin.description,
location: coords,
files: pin.files,
user_id: '',
date: pin.date,
},
{ headers }
);
})
return this.http.post<any>(
url, pin, { headers }
);
}
updatePin(
id: string,
pin: {
title: string;
description: string;
location: string;
files: any[];
user_id: string;
date: string;
}
pin: Pin
) {
const url = `${this.apiURL}/pin/${id}`;
const headers = new HttpHeaders({
@ -78,22 +51,8 @@ export class PinService {
});
// 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>(
url,
{
title: pin.title,
description: pin.description,
location: coords,
files: pin.files,
user_id: pin.user_id,
date: pin.date,
},
{ headers }
);
})
return this.http.patch<any>(
url, pin, { headers }
);
}

Loading…
Cancel
Save