|
|
@ -1,10 +1,5 @@
|
|
|
|
import { CommonModule } from '@angular/common';
|
|
|
|
import { CommonModule } from '@angular/common';
|
|
|
|
import {
|
|
|
|
import { Component, Input, OnInit, ViewChild } from '@angular/core';
|
|
|
|
Component,
|
|
|
|
|
|
|
|
Input,
|
|
|
|
|
|
|
|
OnInit,
|
|
|
|
|
|
|
|
ViewChild,
|
|
|
|
|
|
|
|
} from '@angular/core';
|
|
|
|
|
|
|
|
import {
|
|
|
|
import {
|
|
|
|
FormBuilder,
|
|
|
|
FormBuilder,
|
|
|
|
FormControl,
|
|
|
|
FormControl,
|
|
|
@ -55,8 +50,14 @@ export class AddPinPopupComponent implements OnInit {
|
|
|
|
private imageService: ImageService
|
|
|
|
private imageService: ImageService
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
this.form = this.fb.group({
|
|
|
|
this.form = this.fb.group({
|
|
|
|
title: new FormControl('', [Validators.required, Validators.minLength(3)]),
|
|
|
|
title: new FormControl('', [
|
|
|
|
description: new FormControl('', [Validators.required, Validators.minLength(3)]),
|
|
|
|
Validators.required,
|
|
|
|
|
|
|
|
Validators.minLength(3),
|
|
|
|
|
|
|
|
]),
|
|
|
|
|
|
|
|
description: new FormControl('', [
|
|
|
|
|
|
|
|
Validators.required,
|
|
|
|
|
|
|
|
Validators.minLength(3),
|
|
|
|
|
|
|
|
]),
|
|
|
|
location: new FormControl('', [Validators.required]),
|
|
|
|
location: new FormControl('', [Validators.required]),
|
|
|
|
complete_address: new FormControl('', [Validators.required]),
|
|
|
|
complete_address: new FormControl('', [Validators.required]),
|
|
|
|
coordinates: new FormControl<number[]>([]),
|
|
|
|
coordinates: new FormControl<number[]>([]),
|
|
|
@ -109,7 +110,7 @@ export class AddPinPopupComponent implements OnInit {
|
|
|
|
debounceTime(200), // Attendre 200ms après la dernière frappe
|
|
|
|
debounceTime(200), // Attendre 200ms après la dernière frappe
|
|
|
|
distinctUntilChanged(), // Ignorer si la nouvelle valeur est la même que la précédente
|
|
|
|
distinctUntilChanged(), // Ignorer si la nouvelle valeur est la même que la précédente
|
|
|
|
switchMap((query) => {
|
|
|
|
switchMap((query) => {
|
|
|
|
if(query === null) {
|
|
|
|
if (query === null) {
|
|
|
|
return of([]);
|
|
|
|
return of([]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const trimmedQuery = query.trim();
|
|
|
|
const trimmedQuery = query.trim();
|
|
|
@ -154,11 +155,17 @@ export class AddPinPopupComponent implements OnInit {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const data = await this.exifService.getLocation(files[0]);
|
|
|
|
const data = await this.exifService.getLocation(files[0]);
|
|
|
|
if (data.latitude !== undefined && data.longitude !== undefined) {
|
|
|
|
if (data.latitude !== undefined && data.longitude !== undefined) {
|
|
|
|
this.autocompleteService.getAddressFromCoordinates(data.latitude, data.longitude).subscribe((address) => {
|
|
|
|
this.autocompleteService
|
|
|
|
|
|
|
|
.getAddressFromCoordinates(data.latitude, data.longitude)
|
|
|
|
|
|
|
|
.subscribe((address) => {
|
|
|
|
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
|
|
|
|
this.form.get('coordinates')?.setValue([data.latitude, data.longitude]);
|
|
|
|
.get('complete_address')
|
|
|
|
|
|
|
|
?.setValue(address.display_name);
|
|
|
|
|
|
|
|
this.form
|
|
|
|
|
|
|
|
.get('coordinates')
|
|
|
|
|
|
|
|
?.setValue([data.latitude, data.longitude]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -178,14 +185,15 @@ export class AddPinPopupComponent implements OnInit {
|
|
|
|
|
|
|
|
|
|
|
|
async submitForm(): Promise<void> {
|
|
|
|
async submitForm(): Promise<void> {
|
|
|
|
// Marquer tous les champs comme touched pour afficher les erreurs
|
|
|
|
// Marquer tous les champs comme touched pour afficher les erreurs
|
|
|
|
Object.keys(this.form.controls).forEach(key => {
|
|
|
|
Object.keys(this.form.controls).forEach((key) => {
|
|
|
|
const control = this.form.get(key);
|
|
|
|
const control = this.form.get(key);
|
|
|
|
control?.markAsTouched();
|
|
|
|
control?.markAsTouched();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (this.form.valid) {
|
|
|
|
if (this.form.valid) {
|
|
|
|
const uploadObservables = await Promise.all(this.files.map(async (file) => {
|
|
|
|
const uploadObservables = await Promise.all(
|
|
|
|
if(file.size === 0) {
|
|
|
|
this.files.map(async (file) => {
|
|
|
|
|
|
|
|
if (file.size === 0) {
|
|
|
|
this.uploadError = file.name + ' : ' + 'Image vide';
|
|
|
|
this.uploadError = file.name + ' : ' + 'Image vide';
|
|
|
|
return of(null);
|
|
|
|
return of(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -193,19 +201,22 @@ export class AddPinPopupComponent implements OnInit {
|
|
|
|
const pictureExifDate = await this.exifService.getDateTime(file);
|
|
|
|
const pictureExifDate = await this.exifService.getDateTime(file);
|
|
|
|
|
|
|
|
|
|
|
|
return this.imageService.postImage(file, pictureExifDate).pipe(
|
|
|
|
return this.imageService.postImage(file, pictureExifDate).pipe(
|
|
|
|
catchError(error => {
|
|
|
|
catchError((error) => {
|
|
|
|
this.uploadError = file.name + ' : ' + error.error.detail || 'Erreur lors de l\'upload de l\'image';
|
|
|
|
this.uploadError =
|
|
|
|
|
|
|
|
file.name + ' : ' + error.error.detail ||
|
|
|
|
|
|
|
|
"Erreur lors de l'upload de l'image";
|
|
|
|
if (this.dragDropComponent) {
|
|
|
|
if (this.dragDropComponent) {
|
|
|
|
this.dragDropComponent.errorMessage = this.uploadError;
|
|
|
|
this.dragDropComponent.errorMessage = this.uploadError;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return of(null);
|
|
|
|
return of(null);
|
|
|
|
})
|
|
|
|
})
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}));
|
|
|
|
})
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
forkJoin(uploadObservables).subscribe((responses) => {
|
|
|
|
forkJoin(uploadObservables).subscribe((responses) => {
|
|
|
|
// Vérifier si toutes les réponses sont valides
|
|
|
|
// Vérifier si toutes les réponses sont valides
|
|
|
|
if (responses.some(response => response === null)) {
|
|
|
|
if (responses.some((response) => response === null)) {
|
|
|
|
return; // Ne pas continuer si une erreur s'est produite
|
|
|
|
return; // Ne pas continuer si une erreur s'est produite
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -217,7 +228,9 @@ export class AddPinPopupComponent implements OnInit {
|
|
|
|
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
|
|
|
|
location: coordinates || [0, 0], // Utiliser les coordonnées pour location
|
|
|
|
complete_address: this.form.get('complete_address')?.value || this.form.get('location')?.value,
|
|
|
|
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
|
|
|
|
// Supprimer le champ coordinates qui n'est pas dans le modèle Pin
|
|
|
@ -236,17 +249,15 @@ export class AddPinPopupComponent implements OnInit {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
openPinModal() {
|
|
|
|
|
|
|
|
this.modalService.openModal(this.modalId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
closePinModal() {
|
|
|
|
closePinModal() {
|
|
|
|
this.modalService.closeModal(this.modalId);
|
|
|
|
this.modalService.closeModal(this.modalId);
|
|
|
|
this.form.reset();
|
|
|
|
this.form.reset();
|
|
|
|
this.files = [];
|
|
|
|
this.files = [];
|
|
|
|
this.uploadError = '';
|
|
|
|
this.uploadError = '';
|
|
|
|
if (this.dragDropComponent) {
|
|
|
|
if (this.dragDropComponent) {
|
|
|
|
this.dragDropComponent.updateFileNamesFromFileList(new DataTransfer().files);
|
|
|
|
this.dragDropComponent.updateFileNamesFromFileList(
|
|
|
|
|
|
|
|
new DataTransfer().files
|
|
|
|
|
|
|
|
);
|
|
|
|
this.dragDropComponent.errorMessage = '';
|
|
|
|
this.dragDropComponent.errorMessage = '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|