|
|
|
@ -6,7 +6,7 @@ import {
|
|
|
|
|
FormGroup,
|
|
|
|
|
ReactiveFormsModule,
|
|
|
|
|
} from '@angular/forms';
|
|
|
|
|
import { of } from 'rxjs';
|
|
|
|
|
import { forkJoin, of, Subscription } from 'rxjs';
|
|
|
|
|
import {
|
|
|
|
|
catchError,
|
|
|
|
|
debounceTime,
|
|
|
|
@ -18,6 +18,9 @@ import { ExifService } from '../../services/exif/exif.service';
|
|
|
|
|
import { MapReloadService } from '../../services/map-reload/map-reload.service';
|
|
|
|
|
import { PinService } from '../../services/pin/pin.service';
|
|
|
|
|
import { DragDropComponent } from '../drag-drop/drag-drop.component';
|
|
|
|
|
import { ModalService } from '../../services/modal/modal.service';
|
|
|
|
|
import { ImageService } from '../../services/image/image.service';
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-add-pin-popup',
|
|
|
|
|
standalone: true,
|
|
|
|
@ -31,13 +34,17 @@ export class AddPinPopupComponent implements OnInit {
|
|
|
|
|
@Input() isHomePage: boolean = false;
|
|
|
|
|
files: any[] = [];
|
|
|
|
|
isPinModalOpen: boolean = false;
|
|
|
|
|
modalId: string = 'add-pin-modal';
|
|
|
|
|
private modalSub!: Subscription;
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
|
private fb: FormBuilder,
|
|
|
|
|
private autocompleteService: AutocompleteService,
|
|
|
|
|
private pinService: PinService,
|
|
|
|
|
private exifService: ExifService,
|
|
|
|
|
private mapReloadService: MapReloadService
|
|
|
|
|
private modalService: ModalService,
|
|
|
|
|
private mapReloadService: MapReloadService,
|
|
|
|
|
private imageService: ImageService
|
|
|
|
|
) {
|
|
|
|
|
this.form = this.fb.group({
|
|
|
|
|
title: new FormControl(''),
|
|
|
|
@ -58,6 +65,20 @@ export class AddPinPopupComponent implements OnInit {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
|
this.modalSub = this.modalService
|
|
|
|
|
.getModalState(this.modalId)
|
|
|
|
|
.subscribe((open) => {
|
|
|
|
|
this.isPinModalOpen = open;
|
|
|
|
|
|
|
|
|
|
if (open) {
|
|
|
|
|
const images = this.modalService.getImageFiles().getValue();
|
|
|
|
|
if (images && images.length > 0) {
|
|
|
|
|
this.files = images;
|
|
|
|
|
this.form.patchValue({ files: images });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.form
|
|
|
|
|
.get('location')
|
|
|
|
|
?.valueChanges.pipe(
|
|
|
|
@ -110,21 +131,44 @@ export class AddPinPopupComponent implements OnInit {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnDestroy() {
|
|
|
|
|
this.modalSub.unsubscribe();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
submitForm(): void {
|
|
|
|
|
// if (this.form.valid) {
|
|
|
|
|
// this.files = this.files.map((file) => {
|
|
|
|
|
// // return file.name; //TODO: Mettre le hash du fichier
|
|
|
|
|
// this.imageService.postImage(file).subscribe((response) => {
|
|
|
|
|
// // console.log('Image uploaded:', response);
|
|
|
|
|
// let imageId = response.json();
|
|
|
|
|
// return imageId.id;
|
|
|
|
|
// });
|
|
|
|
|
// });
|
|
|
|
|
// console.log('Files : ' + JSON.stringify(this.files));
|
|
|
|
|
|
|
|
|
|
if (this.form.valid) {
|
|
|
|
|
this.files = this.files.map((file) => {
|
|
|
|
|
return file.name; //TODO: Mettre le hash du fichier
|
|
|
|
|
});
|
|
|
|
|
const uploadObservables = this.files.map((file) =>
|
|
|
|
|
this.imageService.postImage(file)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
const pinData = {
|
|
|
|
|
...this.form.value,
|
|
|
|
|
files: this.files,
|
|
|
|
|
};
|
|
|
|
|
const pinData = {
|
|
|
|
|
...this.form.value,
|
|
|
|
|
files: this.files,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
this.pinService.addPin(pinData).subscribe(() => {
|
|
|
|
|
this.mapReloadService.requestReload(); // Demander le rechargement de la carte
|
|
|
|
|
this.closePinModal();
|
|
|
|
|
this.form.reset(); // Réinitialiser le formulaire après soumission
|
|
|
|
|
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();
|
|
|
|
|
this.form.reset(); // Réinitialiser le formulaire après soumission
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
console.error('Le formulaire est invalide');
|
|
|
|
@ -132,10 +176,16 @@ export class AddPinPopupComponent implements OnInit {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
openPinModal() {
|
|
|
|
|
this.isPinModalOpen = true;
|
|
|
|
|
// this.isPinModalOpen = true;
|
|
|
|
|
this.modalService.openModal(this.modalId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
closePinModal() {
|
|
|
|
|
this.isPinModalOpen = false;
|
|
|
|
|
// this.isPinModalOpen = false;
|
|
|
|
|
this.modalService.closeModal(this.modalId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getImagePreview(file: File): string {
|
|
|
|
|
return URL.createObjectURL(file);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|